@@ -27,322 +27,322 @@ |
||
27 | 27 | class EE_Brewing_Regular extends EE_BASE implements InterminableInterface |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * @var TableAnalysis $table_analysis |
|
32 | - */ |
|
33 | - protected $_table_analysis; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * EE_Brewing_Regular constructor. |
|
38 | - * |
|
39 | - * @param TableAnalysis $table_analysis |
|
40 | - */ |
|
41 | - public function __construct(TableAnalysis $table_analysis) |
|
42 | - { |
|
43 | - $this->_table_analysis = $table_analysis; |
|
44 | - if (defined('EE_CAFF_PATH')) { |
|
45 | - $this->setInitializationHooks(); |
|
46 | - $this->setApiRegistrationHooks(); |
|
47 | - $this->setSwitchHooks(); |
|
48 | - $this->setDefaultFilterHooks(); |
|
49 | - // caffeinated constructed |
|
50 | - do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * Various hooks used for extending features via registration of modules or extensions. |
|
57 | - */ |
|
58 | - private function setApiRegistrationHooks() |
|
59 | - { |
|
60 | - add_filter( |
|
61 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
62 | - array($this, 'caffeinated_modules_to_register') |
|
63 | - ); |
|
64 | - add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
65 | - add_filter( |
|
66 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
67 | - function () { |
|
68 | - EE_Register_Payment_Method::register( |
|
69 | - 'caffeinated_payment_methods', |
|
70 | - array( |
|
71 | - 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR), |
|
72 | - ) |
|
73 | - ); |
|
74 | - } |
|
75 | - ); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Various hooks used for modifying initialization or activation processes. |
|
81 | - */ |
|
82 | - private function setInitializationHooks() |
|
83 | - { |
|
84 | - // activation |
|
85 | - add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
86 | - // load caff init |
|
87 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
88 | - // load caff scripts |
|
89 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Various hooks used for switch (on/off) type filters. |
|
95 | - */ |
|
96 | - private function setSwitchHooks() |
|
97 | - { |
|
98 | - // remove the "powered by" credit link from receipts and invoices |
|
99 | - add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
100 | - // seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
101 | - add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * Various filters for affecting default configuration values in the caffeinated |
|
107 | - * context. |
|
108 | - */ |
|
109 | - private function setDefaultFilterHooks() |
|
110 | - { |
|
111 | - add_filter( |
|
112 | - 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
113 | - '__return_true' |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
120 | - * |
|
121 | - * @param array $paths original helper paths array |
|
122 | - * @return array new array of paths |
|
123 | - */ |
|
124 | - public function caf_helper_paths($paths) |
|
125 | - { |
|
126 | - $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
127 | - return $paths; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
133 | - * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
134 | - * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
135 | - * This action should only be called when EE 4.x.0.P is initially activated. |
|
136 | - * Right now the only CAF content are these global prices. If there's more in the future, then |
|
137 | - * we should probably create a caf file to contain it all instead just a function like this. |
|
138 | - * Right now, we ASSUME the only price types in the system are default ones |
|
139 | - * |
|
140 | - * @global wpdb $wpdb |
|
141 | - */ |
|
142 | - public function initialize_caf_db_content() |
|
143 | - { |
|
144 | - global $wpdb; |
|
145 | - // use same method of getting creator id as the version introducing the change |
|
146 | - $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
147 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
148 | - $price_table = $wpdb->prefix . "esp_price"; |
|
149 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
150 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types |
|
151 | - $tax_price_type_count = $wpdb->get_var($SQL); |
|
152 | - if ($tax_price_type_count <= 1) { |
|
153 | - $wpdb->insert( |
|
154 | - $price_type_table, |
|
155 | - array( |
|
156 | - 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
157 | - 'PBT_ID' => 4, |
|
158 | - 'PRT_is_percent' => true, |
|
159 | - 'PRT_order' => 60, |
|
160 | - 'PRT_deleted' => false, |
|
161 | - 'PRT_wp_user' => $default_creator_id, |
|
162 | - ), |
|
163 | - array( |
|
164 | - '%s',// PRT_name |
|
165 | - '%d',// PBT_id |
|
166 | - '%d',// PRT_is_percent |
|
167 | - '%d',// PRT_order |
|
168 | - '%d',// PRT_deleted |
|
169 | - '%d', // PRT_wp_user |
|
170 | - ) |
|
171 | - ); |
|
172 | - // federal tax |
|
173 | - $result = $wpdb->insert( |
|
174 | - $price_type_table, |
|
175 | - array( |
|
176 | - 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
177 | - 'PBT_ID' => 4, |
|
178 | - 'PRT_is_percent' => true, |
|
179 | - 'PRT_order' => 70, |
|
180 | - 'PRT_deleted' => false, |
|
181 | - 'PRT_wp_user' => $default_creator_id, |
|
182 | - ), |
|
183 | - array( |
|
184 | - '%s',// PRT_name |
|
185 | - '%d',// PBT_id |
|
186 | - '%d',// PRT_is_percent |
|
187 | - '%d',// PRT_order |
|
188 | - '%d',// PRT_deleted |
|
189 | - '%d' // PRT_wp_user |
|
190 | - ) |
|
191 | - ); |
|
192 | - if ($result) { |
|
193 | - $wpdb->insert( |
|
194 | - $price_table, |
|
195 | - array( |
|
196 | - 'PRT_ID' => $wpdb->insert_id, |
|
197 | - 'PRC_amount' => 15.00, |
|
198 | - 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
199 | - 'PRC_desc' => '', |
|
200 | - 'PRC_is_default' => true, |
|
201 | - 'PRC_overrides' => null, |
|
202 | - 'PRC_deleted' => false, |
|
203 | - 'PRC_order' => 50, |
|
204 | - 'PRC_parent' => null, |
|
205 | - 'PRC_wp_user' => $default_creator_id, |
|
206 | - ), |
|
207 | - array( |
|
208 | - '%d',// PRT_id |
|
209 | - '%f',// PRC_amount |
|
210 | - '%s',// PRC_name |
|
211 | - '%s',// PRC_desc |
|
212 | - '%d',// PRC_is_default |
|
213 | - '%d',// PRC_overrides |
|
214 | - '%d',// PRC_deleted |
|
215 | - '%d',// PRC_order |
|
216 | - '%d',// PRC_parent |
|
217 | - '%d' // PRC_wp_user |
|
218 | - ) |
|
219 | - ); |
|
220 | - } |
|
221 | - } |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * caffeinated_modules_to_register |
|
228 | - * |
|
229 | - * @access public |
|
230 | - * @param array $modules_to_register |
|
231 | - * @return array |
|
232 | - */ |
|
233 | - public function caffeinated_modules_to_register($modules_to_register = array()) |
|
234 | - { |
|
235 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
236 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
237 | - if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
238 | - $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
239 | - } |
|
240 | - } |
|
241 | - return $modules_to_register; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @throws EE_Error |
|
247 | - * @throws InvalidArgumentException |
|
248 | - * @throws ReflectionException |
|
249 | - * @throws InvalidDataTypeException |
|
250 | - * @throws InvalidInterfaceException |
|
251 | - */ |
|
252 | - public function caffeinated_init() |
|
253 | - { |
|
254 | - // Custom Post Type hooks |
|
255 | - add_filter( |
|
256 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
257 | - array($this, 'filter_taxonomies') |
|
258 | - ); |
|
259 | - add_filter( |
|
260 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes', |
|
261 | - array($this, 'filter_cpts') |
|
262 | - ); |
|
263 | - add_filter( |
|
264 | - 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', |
|
265 | - array($this, 'nav_metabox_items') |
|
266 | - ); |
|
267 | - EE_Registry::instance()->load_file( |
|
268 | - EE_CAFF_PATH, |
|
269 | - 'EE_Caf_Messages', |
|
270 | - 'class', |
|
271 | - array(), |
|
272 | - false |
|
273 | - ); |
|
274 | - // caffeinated_init__complete hook |
|
275 | - do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - public function enqueue_caffeinated_scripts() |
|
280 | - { |
|
281 | - // sound of crickets... |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * callbacks below here |
|
287 | - * |
|
288 | - * @param array $taxonomy_array |
|
289 | - * @return array |
|
290 | - */ |
|
291 | - public function filter_taxonomies(array $taxonomy_array) |
|
292 | - { |
|
293 | - $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
294 | - return $taxonomy_array; |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * @param array $cpt_array |
|
300 | - * @return mixed |
|
301 | - */ |
|
302 | - public function filter_cpts(array $cpt_array) |
|
303 | - { |
|
304 | - $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
305 | - return $cpt_array; |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * @param array $menuitems |
|
311 | - * @return array |
|
312 | - */ |
|
313 | - public function nav_metabox_items(array $menuitems) |
|
314 | - { |
|
315 | - $menuitems[] = array( |
|
316 | - 'title' => __('Venue List', 'event_espresso'), |
|
317 | - 'url' => get_post_type_archive_link('espresso_venues'), |
|
318 | - 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
319 | - ); |
|
320 | - return $menuitems; |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * Gets the injected table analyzer, or throws an exception |
|
326 | - * |
|
327 | - * @return TableAnalysis |
|
328 | - * @throws \EE_Error |
|
329 | - */ |
|
330 | - protected function _get_table_analysis() |
|
331 | - { |
|
332 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
333 | - return $this->_table_analysis; |
|
334 | - } else { |
|
335 | - throw new \EE_Error( |
|
336 | - sprintf( |
|
337 | - __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
338 | - get_class($this) |
|
339 | - ) |
|
340 | - ); |
|
341 | - } |
|
342 | - } |
|
30 | + /** |
|
31 | + * @var TableAnalysis $table_analysis |
|
32 | + */ |
|
33 | + protected $_table_analysis; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * EE_Brewing_Regular constructor. |
|
38 | + * |
|
39 | + * @param TableAnalysis $table_analysis |
|
40 | + */ |
|
41 | + public function __construct(TableAnalysis $table_analysis) |
|
42 | + { |
|
43 | + $this->_table_analysis = $table_analysis; |
|
44 | + if (defined('EE_CAFF_PATH')) { |
|
45 | + $this->setInitializationHooks(); |
|
46 | + $this->setApiRegistrationHooks(); |
|
47 | + $this->setSwitchHooks(); |
|
48 | + $this->setDefaultFilterHooks(); |
|
49 | + // caffeinated constructed |
|
50 | + do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * Various hooks used for extending features via registration of modules or extensions. |
|
57 | + */ |
|
58 | + private function setApiRegistrationHooks() |
|
59 | + { |
|
60 | + add_filter( |
|
61 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
62 | + array($this, 'caffeinated_modules_to_register') |
|
63 | + ); |
|
64 | + add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
65 | + add_filter( |
|
66 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
67 | + function () { |
|
68 | + EE_Register_Payment_Method::register( |
|
69 | + 'caffeinated_payment_methods', |
|
70 | + array( |
|
71 | + 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR), |
|
72 | + ) |
|
73 | + ); |
|
74 | + } |
|
75 | + ); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Various hooks used for modifying initialization or activation processes. |
|
81 | + */ |
|
82 | + private function setInitializationHooks() |
|
83 | + { |
|
84 | + // activation |
|
85 | + add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
86 | + // load caff init |
|
87 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
88 | + // load caff scripts |
|
89 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Various hooks used for switch (on/off) type filters. |
|
95 | + */ |
|
96 | + private function setSwitchHooks() |
|
97 | + { |
|
98 | + // remove the "powered by" credit link from receipts and invoices |
|
99 | + add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
100 | + // seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
101 | + add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * Various filters for affecting default configuration values in the caffeinated |
|
107 | + * context. |
|
108 | + */ |
|
109 | + private function setDefaultFilterHooks() |
|
110 | + { |
|
111 | + add_filter( |
|
112 | + 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
113 | + '__return_true' |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
120 | + * |
|
121 | + * @param array $paths original helper paths array |
|
122 | + * @return array new array of paths |
|
123 | + */ |
|
124 | + public function caf_helper_paths($paths) |
|
125 | + { |
|
126 | + $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
127 | + return $paths; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
133 | + * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
134 | + * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
135 | + * This action should only be called when EE 4.x.0.P is initially activated. |
|
136 | + * Right now the only CAF content are these global prices. If there's more in the future, then |
|
137 | + * we should probably create a caf file to contain it all instead just a function like this. |
|
138 | + * Right now, we ASSUME the only price types in the system are default ones |
|
139 | + * |
|
140 | + * @global wpdb $wpdb |
|
141 | + */ |
|
142 | + public function initialize_caf_db_content() |
|
143 | + { |
|
144 | + global $wpdb; |
|
145 | + // use same method of getting creator id as the version introducing the change |
|
146 | + $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
147 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
148 | + $price_table = $wpdb->prefix . "esp_price"; |
|
149 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
150 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types |
|
151 | + $tax_price_type_count = $wpdb->get_var($SQL); |
|
152 | + if ($tax_price_type_count <= 1) { |
|
153 | + $wpdb->insert( |
|
154 | + $price_type_table, |
|
155 | + array( |
|
156 | + 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
157 | + 'PBT_ID' => 4, |
|
158 | + 'PRT_is_percent' => true, |
|
159 | + 'PRT_order' => 60, |
|
160 | + 'PRT_deleted' => false, |
|
161 | + 'PRT_wp_user' => $default_creator_id, |
|
162 | + ), |
|
163 | + array( |
|
164 | + '%s',// PRT_name |
|
165 | + '%d',// PBT_id |
|
166 | + '%d',// PRT_is_percent |
|
167 | + '%d',// PRT_order |
|
168 | + '%d',// PRT_deleted |
|
169 | + '%d', // PRT_wp_user |
|
170 | + ) |
|
171 | + ); |
|
172 | + // federal tax |
|
173 | + $result = $wpdb->insert( |
|
174 | + $price_type_table, |
|
175 | + array( |
|
176 | + 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
177 | + 'PBT_ID' => 4, |
|
178 | + 'PRT_is_percent' => true, |
|
179 | + 'PRT_order' => 70, |
|
180 | + 'PRT_deleted' => false, |
|
181 | + 'PRT_wp_user' => $default_creator_id, |
|
182 | + ), |
|
183 | + array( |
|
184 | + '%s',// PRT_name |
|
185 | + '%d',// PBT_id |
|
186 | + '%d',// PRT_is_percent |
|
187 | + '%d',// PRT_order |
|
188 | + '%d',// PRT_deleted |
|
189 | + '%d' // PRT_wp_user |
|
190 | + ) |
|
191 | + ); |
|
192 | + if ($result) { |
|
193 | + $wpdb->insert( |
|
194 | + $price_table, |
|
195 | + array( |
|
196 | + 'PRT_ID' => $wpdb->insert_id, |
|
197 | + 'PRC_amount' => 15.00, |
|
198 | + 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
199 | + 'PRC_desc' => '', |
|
200 | + 'PRC_is_default' => true, |
|
201 | + 'PRC_overrides' => null, |
|
202 | + 'PRC_deleted' => false, |
|
203 | + 'PRC_order' => 50, |
|
204 | + 'PRC_parent' => null, |
|
205 | + 'PRC_wp_user' => $default_creator_id, |
|
206 | + ), |
|
207 | + array( |
|
208 | + '%d',// PRT_id |
|
209 | + '%f',// PRC_amount |
|
210 | + '%s',// PRC_name |
|
211 | + '%s',// PRC_desc |
|
212 | + '%d',// PRC_is_default |
|
213 | + '%d',// PRC_overrides |
|
214 | + '%d',// PRC_deleted |
|
215 | + '%d',// PRC_order |
|
216 | + '%d',// PRC_parent |
|
217 | + '%d' // PRC_wp_user |
|
218 | + ) |
|
219 | + ); |
|
220 | + } |
|
221 | + } |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * caffeinated_modules_to_register |
|
228 | + * |
|
229 | + * @access public |
|
230 | + * @param array $modules_to_register |
|
231 | + * @return array |
|
232 | + */ |
|
233 | + public function caffeinated_modules_to_register($modules_to_register = array()) |
|
234 | + { |
|
235 | + if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
236 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
237 | + if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
238 | + $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
239 | + } |
|
240 | + } |
|
241 | + return $modules_to_register; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @throws EE_Error |
|
247 | + * @throws InvalidArgumentException |
|
248 | + * @throws ReflectionException |
|
249 | + * @throws InvalidDataTypeException |
|
250 | + * @throws InvalidInterfaceException |
|
251 | + */ |
|
252 | + public function caffeinated_init() |
|
253 | + { |
|
254 | + // Custom Post Type hooks |
|
255 | + add_filter( |
|
256 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
257 | + array($this, 'filter_taxonomies') |
|
258 | + ); |
|
259 | + add_filter( |
|
260 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes', |
|
261 | + array($this, 'filter_cpts') |
|
262 | + ); |
|
263 | + add_filter( |
|
264 | + 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', |
|
265 | + array($this, 'nav_metabox_items') |
|
266 | + ); |
|
267 | + EE_Registry::instance()->load_file( |
|
268 | + EE_CAFF_PATH, |
|
269 | + 'EE_Caf_Messages', |
|
270 | + 'class', |
|
271 | + array(), |
|
272 | + false |
|
273 | + ); |
|
274 | + // caffeinated_init__complete hook |
|
275 | + do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + public function enqueue_caffeinated_scripts() |
|
280 | + { |
|
281 | + // sound of crickets... |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * callbacks below here |
|
287 | + * |
|
288 | + * @param array $taxonomy_array |
|
289 | + * @return array |
|
290 | + */ |
|
291 | + public function filter_taxonomies(array $taxonomy_array) |
|
292 | + { |
|
293 | + $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
294 | + return $taxonomy_array; |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * @param array $cpt_array |
|
300 | + * @return mixed |
|
301 | + */ |
|
302 | + public function filter_cpts(array $cpt_array) |
|
303 | + { |
|
304 | + $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
305 | + return $cpt_array; |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * @param array $menuitems |
|
311 | + * @return array |
|
312 | + */ |
|
313 | + public function nav_metabox_items(array $menuitems) |
|
314 | + { |
|
315 | + $menuitems[] = array( |
|
316 | + 'title' => __('Venue List', 'event_espresso'), |
|
317 | + 'url' => get_post_type_archive_link('espresso_venues'), |
|
318 | + 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
319 | + ); |
|
320 | + return $menuitems; |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * Gets the injected table analyzer, or throws an exception |
|
326 | + * |
|
327 | + * @return TableAnalysis |
|
328 | + * @throws \EE_Error |
|
329 | + */ |
|
330 | + protected function _get_table_analysis() |
|
331 | + { |
|
332 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
333 | + return $this->_table_analysis; |
|
334 | + } else { |
|
335 | + throw new \EE_Error( |
|
336 | + sprintf( |
|
337 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
338 | + get_class($this) |
|
339 | + ) |
|
340 | + ); |
|
341 | + } |
|
342 | + } |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | |
346 | 346 | $brewing = new EE_Brewing_Regular( |
347 | - EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
347 | + EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
348 | 348 | ); |
@@ -11,10 +11,10 @@ discard block |
||
11 | 11 | * define and use the hook in a specific caffeinated/whatever class or file. |
12 | 12 | */ |
13 | 13 | // defined some new constants related to caffeinated folder |
14 | -define('EE_CAF_URL', EE_PLUGIN_DIR_URL . 'caffeinated/'); |
|
15 | -define('EE_CAF_CORE', EE_CAFF_PATH . 'core' . DS); |
|
16 | -define('EE_CAF_LIBRARIES', EE_CAF_CORE . 'libraries' . DS); |
|
17 | -define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH . 'payment_methods' . DS); |
|
14 | +define('EE_CAF_URL', EE_PLUGIN_DIR_URL.'caffeinated/'); |
|
15 | +define('EE_CAF_CORE', EE_CAFF_PATH.'core'.DS); |
|
16 | +define('EE_CAF_LIBRARIES', EE_CAF_CORE.'libraries'.DS); |
|
17 | +define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH.'payment_methods'.DS); |
|
18 | 18 | |
19 | 19 | |
20 | 20 | /** |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
65 | 65 | add_filter( |
66 | 66 | 'AHEE__EE_System__load_core_configuration__complete', |
67 | - function () { |
|
67 | + function() { |
|
68 | 68 | EE_Register_Payment_Method::register( |
69 | 69 | 'caffeinated_payment_methods', |
70 | 70 | array( |
71 | - 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR), |
|
71 | + 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS.'*', GLOB_ONLYDIR), |
|
72 | 72 | ) |
73 | 73 | ); |
74 | 74 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public function caf_helper_paths($paths) |
125 | 125 | { |
126 | - $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
126 | + $paths[] = EE_CAF_CORE.'helpers'.DS; |
|
127 | 127 | return $paths; |
128 | 128 | } |
129 | 129 | |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | global $wpdb; |
145 | 145 | // use same method of getting creator id as the version introducing the change |
146 | 146 | $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
147 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
148 | - $price_table = $wpdb->prefix . "esp_price"; |
|
147 | + $price_type_table = $wpdb->prefix."esp_price_type"; |
|
148 | + $price_table = $wpdb->prefix."esp_price"; |
|
149 | 149 | if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
150 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types |
|
150 | + $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table.' WHERE PBT_ID=4'; // include trashed price types |
|
151 | 151 | $tax_price_type_count = $wpdb->get_var($SQL); |
152 | 152 | if ($tax_price_type_count <= 1) { |
153 | 153 | $wpdb->insert( |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | 'PRT_wp_user' => $default_creator_id, |
162 | 162 | ), |
163 | 163 | array( |
164 | - '%s',// PRT_name |
|
165 | - '%d',// PBT_id |
|
166 | - '%d',// PRT_is_percent |
|
167 | - '%d',// PRT_order |
|
168 | - '%d',// PRT_deleted |
|
164 | + '%s', // PRT_name |
|
165 | + '%d', // PBT_id |
|
166 | + '%d', // PRT_is_percent |
|
167 | + '%d', // PRT_order |
|
168 | + '%d', // PRT_deleted |
|
169 | 169 | '%d', // PRT_wp_user |
170 | 170 | ) |
171 | 171 | ); |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | 'PRT_wp_user' => $default_creator_id, |
182 | 182 | ), |
183 | 183 | array( |
184 | - '%s',// PRT_name |
|
185 | - '%d',// PBT_id |
|
186 | - '%d',// PRT_is_percent |
|
187 | - '%d',// PRT_order |
|
188 | - '%d',// PRT_deleted |
|
184 | + '%s', // PRT_name |
|
185 | + '%d', // PBT_id |
|
186 | + '%d', // PRT_is_percent |
|
187 | + '%d', // PRT_order |
|
188 | + '%d', // PRT_deleted |
|
189 | 189 | '%d' // PRT_wp_user |
190 | 190 | ) |
191 | 191 | ); |
@@ -205,15 +205,15 @@ discard block |
||
205 | 205 | 'PRC_wp_user' => $default_creator_id, |
206 | 206 | ), |
207 | 207 | array( |
208 | - '%d',// PRT_id |
|
209 | - '%f',// PRC_amount |
|
210 | - '%s',// PRC_name |
|
211 | - '%s',// PRC_desc |
|
212 | - '%d',// PRC_is_default |
|
213 | - '%d',// PRC_overrides |
|
214 | - '%d',// PRC_deleted |
|
215 | - '%d',// PRC_order |
|
216 | - '%d',// PRC_parent |
|
208 | + '%d', // PRT_id |
|
209 | + '%f', // PRC_amount |
|
210 | + '%s', // PRC_name |
|
211 | + '%s', // PRC_desc |
|
212 | + '%d', // PRC_is_default |
|
213 | + '%d', // PRC_overrides |
|
214 | + '%d', // PRC_deleted |
|
215 | + '%d', // PRC_order |
|
216 | + '%d', // PRC_parent |
|
217 | 217 | '%d' // PRC_wp_user |
218 | 218 | ) |
219 | 219 | ); |
@@ -232,8 +232,8 @@ discard block |
||
232 | 232 | */ |
233 | 233 | public function caffeinated_modules_to_register($modules_to_register = array()) |
234 | 234 | { |
235 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
236 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
235 | + if (is_readable(EE_CAFF_PATH.'modules')) { |
|
236 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH.'modules'.DS.'*', GLOB_ONLYDIR); |
|
237 | 237 | if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
238 | 238 | $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
239 | 239 | } |
@@ -14,68 +14,68 @@ discard block |
||
14 | 14 | class EE_DMS_4_1_0_gateways extends EE_Data_Migration_Script_Stage |
15 | 15 | { |
16 | 16 | |
17 | - private $_converted_active_gateways = false; |
|
17 | + private $_converted_active_gateways = false; |
|
18 | 18 | |
19 | - public function _migration_step($num_items = 50) |
|
20 | - { |
|
21 | - // loads existing EE_CONfig from DB, if it exists |
|
22 | - $new_gateway_config_obj = EE_Config::instance()->gateway; |
|
23 | - $items_actually_migrated = 0; |
|
24 | - // convert settings |
|
25 | - $gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone); |
|
26 | - // just do a part of them on this request |
|
27 | - $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items);// $this->_gateways_we_know_how_to_migrate; |
|
28 | - foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) { |
|
29 | - $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
|
30 | - if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
31 | - // determine the old option's name |
|
32 | - $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug); |
|
33 | - if (! $old_gateway_settings) { |
|
34 | - // no settings existed for this gateway anyways... weird... |
|
35 | - $items_actually_migrated++; |
|
36 | - continue; |
|
37 | - } |
|
38 | - // now prepare the settings to make sure they're in the 4.1 format |
|
39 | - $new_gateway_settings = $this->_convert_gateway_settings($old_gateway_settings, $new_gateway_slug); |
|
40 | - $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings; |
|
41 | - // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but |
|
42 | - // I think it's ok to do right away this time (we wont need gateway settings elsewhere) |
|
43 | - delete_option($old_gateway_wp_option_name); |
|
44 | - } else {// it must be one of the ones we mostly leave alone |
|
45 | - global $wpdb; |
|
46 | - // yeah we could do this all in one query... and if you're reading this and would liek to, go ahead. Although you'll |
|
47 | - // only be saving users 50 milliseconds the one time this runs... |
|
48 | - $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->options." SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name)); |
|
49 | - } |
|
19 | + public function _migration_step($num_items = 50) |
|
20 | + { |
|
21 | + // loads existing EE_CONfig from DB, if it exists |
|
22 | + $new_gateway_config_obj = EE_Config::instance()->gateway; |
|
23 | + $items_actually_migrated = 0; |
|
24 | + // convert settings |
|
25 | + $gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone); |
|
26 | + // just do a part of them on this request |
|
27 | + $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items);// $this->_gateways_we_know_how_to_migrate; |
|
28 | + foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) { |
|
29 | + $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
|
30 | + if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
31 | + // determine the old option's name |
|
32 | + $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug); |
|
33 | + if (! $old_gateway_settings) { |
|
34 | + // no settings existed for this gateway anyways... weird... |
|
35 | + $items_actually_migrated++; |
|
36 | + continue; |
|
37 | + } |
|
38 | + // now prepare the settings to make sure they're in the 4.1 format |
|
39 | + $new_gateway_settings = $this->_convert_gateway_settings($old_gateway_settings, $new_gateway_slug); |
|
40 | + $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings; |
|
41 | + // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but |
|
42 | + // I think it's ok to do right away this time (we wont need gateway settings elsewhere) |
|
43 | + delete_option($old_gateway_wp_option_name); |
|
44 | + } else {// it must be one of the ones we mostly leave alone |
|
45 | + global $wpdb; |
|
46 | + // yeah we could do this all in one query... and if you're reading this and would liek to, go ahead. Although you'll |
|
47 | + // only be saving users 50 milliseconds the one time this runs... |
|
48 | + $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->options." SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name)); |
|
49 | + } |
|
50 | 50 | |
51 | - $items_actually_migrated++; |
|
52 | - } |
|
53 | - // if we can keep going, and it hasn' tbeen done yet, convert active gateways |
|
54 | - if ($items_actually_migrated < $num_items && ! $this->_converted_active_gateways) { |
|
55 | - $this->_convert_active_gateways(); |
|
56 | - $this->_converted_active_gateways = true; |
|
57 | - $items_actually_migrated++; |
|
58 | - } |
|
51 | + $items_actually_migrated++; |
|
52 | + } |
|
53 | + // if we can keep going, and it hasn' tbeen done yet, convert active gateways |
|
54 | + if ($items_actually_migrated < $num_items && ! $this->_converted_active_gateways) { |
|
55 | + $this->_convert_active_gateways(); |
|
56 | + $this->_converted_active_gateways = true; |
|
57 | + $items_actually_migrated++; |
|
58 | + } |
|
59 | 59 | |
60 | - EE_Config::instance()->update_espresso_config(false, false); |
|
61 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
62 | - $this->set_completed(); |
|
63 | - } |
|
64 | - return $items_actually_migrated; |
|
65 | - } |
|
66 | - public function _count_records_to_migrate() |
|
67 | - { |
|
68 | - $count_of_gateways_to_convert = count($this->_gateways_we_know_how_to_migrate); |
|
69 | - $step_of_setting_active_gateways = 1; |
|
70 | - $count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone); |
|
71 | - // $button_images_to_update = |
|
72 | - return $count_of_gateways_to_convert + $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone; |
|
73 | - } |
|
74 | - public function __construct() |
|
75 | - { |
|
76 | - $this->_pretty_name = __("Gateways", "event_espresso"); |
|
77 | - parent::__construct(); |
|
78 | - } |
|
60 | + EE_Config::instance()->update_espresso_config(false, false); |
|
61 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
62 | + $this->set_completed(); |
|
63 | + } |
|
64 | + return $items_actually_migrated; |
|
65 | + } |
|
66 | + public function _count_records_to_migrate() |
|
67 | + { |
|
68 | + $count_of_gateways_to_convert = count($this->_gateways_we_know_how_to_migrate); |
|
69 | + $step_of_setting_active_gateways = 1; |
|
70 | + $count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone); |
|
71 | + // $button_images_to_update = |
|
72 | + return $count_of_gateways_to_convert + $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone; |
|
73 | + } |
|
74 | + public function __construct() |
|
75 | + { |
|
76 | + $this->_pretty_name = __("Gateways", "event_espresso"); |
|
77 | + parent::__construct(); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | /** |
81 | 81 | * Takes the old array of 3.1 gateway settings for this gateway and converts it |
@@ -85,148 +85,148 @@ discard block |
||
85 | 85 | * @param string $new_gateway_slug |
86 | 86 | * @return array |
87 | 87 | */ |
88 | - private function _convert_gateway_settings($old_gateway_settings, $new_gateway_slug) |
|
89 | - { |
|
90 | - $new_gateway_settings = $old_gateway_settings; |
|
91 | - switch ($new_gateway_slug) { |
|
92 | - case 'Bank': |
|
93 | - $new_gateway_settings['account_number'] = $old_gateway_settings['bank_account']; |
|
94 | - $new_gateway_settings['page_title'] = $old_gateway_settings['bank_title']; |
|
95 | - break; |
|
96 | - case 'Invoice': |
|
97 | - $new_gateway_settings['invoice_logo_url'] = $old_gateway_settings['image_url']; |
|
98 | - // Dont' migrate the old invoice payee address. It was usually given dummy data. And in EE4 |
|
99 | - // it gets used in the receipts which are available to everyone. So usually it's best to not |
|
100 | - // migrate this. |
|
101 | - unset($new_gateway_settings['payment_address']); |
|
102 | - break; |
|
103 | - case 'Paypal_Pro': |
|
104 | - $new_gateway_settings['email'] = $old_gateway_settings['paypal_pro_email']; |
|
105 | - $new_gateway_settings['username'] = $old_gateway_settings['paypal_api_username']; |
|
106 | - $new_gateway_settings['password'] = $old_gateway_settings['paypal_api_password']; |
|
107 | - $new_gateway_settings['signature'] = $old_gateway_settings['paypal_api_signature']; |
|
108 | - $new_gateway_settings['credit_cards'] = explode(",", $old_gateway_settings['paypal_api_credit_cards']); |
|
109 | - $new_gateway_settings['use_sandbox'] = $old_gateway_settings['paypal_pro_use_sandbox']; |
|
110 | - break; |
|
111 | - } |
|
112 | - return $new_gateway_settings; |
|
113 | - } |
|
88 | + private function _convert_gateway_settings($old_gateway_settings, $new_gateway_slug) |
|
89 | + { |
|
90 | + $new_gateway_settings = $old_gateway_settings; |
|
91 | + switch ($new_gateway_slug) { |
|
92 | + case 'Bank': |
|
93 | + $new_gateway_settings['account_number'] = $old_gateway_settings['bank_account']; |
|
94 | + $new_gateway_settings['page_title'] = $old_gateway_settings['bank_title']; |
|
95 | + break; |
|
96 | + case 'Invoice': |
|
97 | + $new_gateway_settings['invoice_logo_url'] = $old_gateway_settings['image_url']; |
|
98 | + // Dont' migrate the old invoice payee address. It was usually given dummy data. And in EE4 |
|
99 | + // it gets used in the receipts which are available to everyone. So usually it's best to not |
|
100 | + // migrate this. |
|
101 | + unset($new_gateway_settings['payment_address']); |
|
102 | + break; |
|
103 | + case 'Paypal_Pro': |
|
104 | + $new_gateway_settings['email'] = $old_gateway_settings['paypal_pro_email']; |
|
105 | + $new_gateway_settings['username'] = $old_gateway_settings['paypal_api_username']; |
|
106 | + $new_gateway_settings['password'] = $old_gateway_settings['paypal_api_password']; |
|
107 | + $new_gateway_settings['signature'] = $old_gateway_settings['paypal_api_signature']; |
|
108 | + $new_gateway_settings['credit_cards'] = explode(",", $old_gateway_settings['paypal_api_credit_cards']); |
|
109 | + $new_gateway_settings['use_sandbox'] = $old_gateway_settings['paypal_pro_use_sandbox']; |
|
110 | + break; |
|
111 | + } |
|
112 | + return $new_gateway_settings; |
|
113 | + } |
|
114 | 114 | /** |
115 | - * Figures out the correct 3.1 gateway settings option name for the given 4.1 gateway |
|
116 | - * @param string $new_gateway_slug |
|
117 | - * @return string |
|
118 | - */ |
|
119 | - private function _get_old_gateway_option($new_gateway_slug) |
|
120 | - { |
|
121 | - $option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
|
122 | - $settings = get_option($option_name, null); |
|
123 | - // if( ! $settings){ |
|
124 | - // $this->add_error(sprintf(__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug)); |
|
125 | - // } |
|
126 | - return $settings; |
|
127 | - } |
|
115 | + * Figures out the correct 3.1 gateway settings option name for the given 4.1 gateway |
|
116 | + * @param string $new_gateway_slug |
|
117 | + * @return string |
|
118 | + */ |
|
119 | + private function _get_old_gateway_option($new_gateway_slug) |
|
120 | + { |
|
121 | + $option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
|
122 | + $settings = get_option($option_name, null); |
|
123 | + // if( ! $settings){ |
|
124 | + // $this->add_error(sprintf(__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug)); |
|
125 | + // } |
|
126 | + return $settings; |
|
127 | + } |
|
128 | 128 | |
129 | 129 | /** |
130 | 130 | * Just gets the old gateways slug |
131 | 131 | * @param string $new_gateway_slug |
132 | 132 | * @return string |
133 | 133 | */ |
134 | - private function _get_old_gateway_option_name($new_gateway_slug) |
|
135 | - { |
|
136 | - $new_gateway_slugs_to_new = array_flip(array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone)); |
|
137 | - $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ]; |
|
138 | - $normal_option_prefix = 'event_espresso_'; |
|
139 | - $normal_option_postfix = '_settings'; |
|
140 | - switch ($new_gateway_slug) { |
|
141 | - case 'Bank': |
|
142 | - $option_name = $normal_option_prefix.'bank_deposit'.$normal_option_postfix; |
|
143 | - break; |
|
144 | - case 'Aim': |
|
145 | - $option_name = $normal_option_prefix.'authnet_aim'.$normal_option_postfix; |
|
146 | - break; |
|
147 | - case 'Check': |
|
148 | - $option_name = $normal_option_prefix.'check_payment'.$normal_option_postfix; |
|
149 | - break; |
|
150 | - case 'Ideal': |
|
151 | - $option_name = $normal_option_prefix.'ideal_mollie'.$normal_option_postfix; |
|
152 | - break; |
|
153 | - case 'Invoice': |
|
154 | - $option_name = $normal_option_prefix.'invoice_payment'.$normal_option_postfix; |
|
155 | - break; |
|
156 | - case 'Purchase_Order': |
|
157 | - $option_name = $normal_option_prefix.'purchase_order_payment'.$normal_option_postfix; |
|
158 | - break; |
|
159 | - case 'USAePay_Offsite': |
|
160 | - $option_name = 'espresso_usaepay_offsite'.$normal_option_postfix; |
|
161 | - break; |
|
162 | - case 'USAePay_Onsite': |
|
163 | - $option_name = 'espresso_usaepay_onsite'.$normal_option_postfix; |
|
164 | - break; |
|
165 | - default: |
|
166 | - $option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix.$old_gateway_slug.$normal_option_postfix); |
|
167 | - } |
|
168 | - return $option_name; |
|
169 | - } |
|
134 | + private function _get_old_gateway_option_name($new_gateway_slug) |
|
135 | + { |
|
136 | + $new_gateway_slugs_to_new = array_flip(array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone)); |
|
137 | + $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ]; |
|
138 | + $normal_option_prefix = 'event_espresso_'; |
|
139 | + $normal_option_postfix = '_settings'; |
|
140 | + switch ($new_gateway_slug) { |
|
141 | + case 'Bank': |
|
142 | + $option_name = $normal_option_prefix.'bank_deposit'.$normal_option_postfix; |
|
143 | + break; |
|
144 | + case 'Aim': |
|
145 | + $option_name = $normal_option_prefix.'authnet_aim'.$normal_option_postfix; |
|
146 | + break; |
|
147 | + case 'Check': |
|
148 | + $option_name = $normal_option_prefix.'check_payment'.$normal_option_postfix; |
|
149 | + break; |
|
150 | + case 'Ideal': |
|
151 | + $option_name = $normal_option_prefix.'ideal_mollie'.$normal_option_postfix; |
|
152 | + break; |
|
153 | + case 'Invoice': |
|
154 | + $option_name = $normal_option_prefix.'invoice_payment'.$normal_option_postfix; |
|
155 | + break; |
|
156 | + case 'Purchase_Order': |
|
157 | + $option_name = $normal_option_prefix.'purchase_order_payment'.$normal_option_postfix; |
|
158 | + break; |
|
159 | + case 'USAePay_Offsite': |
|
160 | + $option_name = 'espresso_usaepay_offsite'.$normal_option_postfix; |
|
161 | + break; |
|
162 | + case 'USAePay_Onsite': |
|
163 | + $option_name = 'espresso_usaepay_onsite'.$normal_option_postfix; |
|
164 | + break; |
|
165 | + default: |
|
166 | + $option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix.$old_gateway_slug.$normal_option_postfix); |
|
167 | + } |
|
168 | + return $option_name; |
|
169 | + } |
|
170 | 170 | |
171 | - private function _convert_active_gateways() |
|
172 | - { |
|
173 | - // just does it all one big swoop |
|
174 | - $old_active_gateways = get_option('event_espresso_active_gateways'); |
|
175 | - $new_active_gateways = EE_Config::instance()->gateway->active_gateways; |
|
176 | - foreach ($old_active_gateways as $old_gateway_slug => $filepath) { |
|
177 | - if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
178 | - $this->add_error(sprintf(__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug)); |
|
179 | - continue; |
|
180 | - } |
|
181 | - $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ]; |
|
171 | + private function _convert_active_gateways() |
|
172 | + { |
|
173 | + // just does it all one big swoop |
|
174 | + $old_active_gateways = get_option('event_espresso_active_gateways'); |
|
175 | + $new_active_gateways = EE_Config::instance()->gateway->active_gateways; |
|
176 | + foreach ($old_active_gateways as $old_gateway_slug => $filepath) { |
|
177 | + if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
178 | + $this->add_error(sprintf(__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug)); |
|
179 | + continue; |
|
180 | + } |
|
181 | + $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ]; |
|
182 | 182 | |
183 | - // in the new format we can also upload gateways to the uploads directory and |
|
184 | - $new_active_gateways[ $new_gateway_slug ] = false; |
|
185 | - } |
|
186 | - EE_Config::instance()->gateway->active_gateways = $new_active_gateways; |
|
187 | - } |
|
183 | + // in the new format we can also upload gateways to the uploads directory and |
|
184 | + $new_active_gateways[ $new_gateway_slug ] = false; |
|
185 | + } |
|
186 | + EE_Config::instance()->gateway->active_gateways = $new_active_gateways; |
|
187 | + } |
|
188 | 188 | |
189 | - protected $_gateways_we_know_how_to_migrate = array( |
|
190 | - 'aim'=>'Aim', |
|
191 | - 'bank'=>'Bank', |
|
192 | - 'check'=>'Check', |
|
193 | - 'invoice'=>'Invoice', |
|
194 | - 'paypal'=>'Paypal_Standard', |
|
195 | - 'paypal_pro'=>'Paypal_Pro', |
|
189 | + protected $_gateways_we_know_how_to_migrate = array( |
|
190 | + 'aim'=>'Aim', |
|
191 | + 'bank'=>'Bank', |
|
192 | + 'check'=>'Check', |
|
193 | + 'invoice'=>'Invoice', |
|
194 | + 'paypal'=>'Paypal_Standard', |
|
195 | + 'paypal_pro'=>'Paypal_Pro', |
|
196 | 196 | |
197 | - ); |
|
197 | + ); |
|
198 | 198 | |
199 | - protected $_gateways_we_leave_alone = array( |
|
200 | - '2checkout'=>'2checkout', |
|
201 | - 'anz'=>'Anz', |
|
202 | - 'atos'=>'Atos', |
|
203 | - 'authnet'=>'Authnet', |
|
204 | - 'beanstream'=>'Beanstream', |
|
205 | - 'evertec'=>'Evertec', |
|
206 | - 'eway'=>'Eway', |
|
207 | - 'eway_rapid3'=>'Eway_Rapid3', |
|
208 | - 'exact'=>'Exact', |
|
209 | - 'firstdata'=>'Firstdata', |
|
210 | - 'firstdat_e4'=>'Firstdata_E4', |
|
211 | - 'ideal'=>'Ideal', |
|
212 | - 'infusion_payment'=>'InfusionSoft', |
|
213 | - 'luottokunta'=>'Luottokunta', |
|
214 | - 'megasoft'=>'Megasoft', |
|
215 | - 'moneris_hpp'=>'Moneris_HPP', |
|
216 | - 'mwarrior'=>'Mwarrior', |
|
217 | - 'nab'=>'NAB', |
|
218 | - 'paychoice'=>'Paychoice', |
|
219 | - 'paytrace'=>'Paytrace', |
|
220 | - 'psigate'=>'Psigate', |
|
221 | - 'purchase_order'=>'Purchase_Order', |
|
222 | - 'qbms'=>'QBMS', |
|
223 | - 'quickpay'=>'Quickpay', |
|
224 | - 'realauth'=>'Realauth', |
|
225 | - 'securepay_aus'=>'Securepay_Aus', |
|
226 | - 'stripe'=>'Stripe', |
|
227 | - 'usaepay_offsite'=>'USAePay_Offsite', |
|
228 | - 'usaepay_onsite'=>'USAePay_Onsite', |
|
229 | - 'wepay'=>'Wepay', |
|
230 | - 'worldpay'=>'Worldpay' |
|
231 | - ); |
|
199 | + protected $_gateways_we_leave_alone = array( |
|
200 | + '2checkout'=>'2checkout', |
|
201 | + 'anz'=>'Anz', |
|
202 | + 'atos'=>'Atos', |
|
203 | + 'authnet'=>'Authnet', |
|
204 | + 'beanstream'=>'Beanstream', |
|
205 | + 'evertec'=>'Evertec', |
|
206 | + 'eway'=>'Eway', |
|
207 | + 'eway_rapid3'=>'Eway_Rapid3', |
|
208 | + 'exact'=>'Exact', |
|
209 | + 'firstdata'=>'Firstdata', |
|
210 | + 'firstdat_e4'=>'Firstdata_E4', |
|
211 | + 'ideal'=>'Ideal', |
|
212 | + 'infusion_payment'=>'InfusionSoft', |
|
213 | + 'luottokunta'=>'Luottokunta', |
|
214 | + 'megasoft'=>'Megasoft', |
|
215 | + 'moneris_hpp'=>'Moneris_HPP', |
|
216 | + 'mwarrior'=>'Mwarrior', |
|
217 | + 'nab'=>'NAB', |
|
218 | + 'paychoice'=>'Paychoice', |
|
219 | + 'paytrace'=>'Paytrace', |
|
220 | + 'psigate'=>'Psigate', |
|
221 | + 'purchase_order'=>'Purchase_Order', |
|
222 | + 'qbms'=>'QBMS', |
|
223 | + 'quickpay'=>'Quickpay', |
|
224 | + 'realauth'=>'Realauth', |
|
225 | + 'securepay_aus'=>'Securepay_Aus', |
|
226 | + 'stripe'=>'Stripe', |
|
227 | + 'usaepay_offsite'=>'USAePay_Offsite', |
|
228 | + 'usaepay_onsite'=>'USAePay_Onsite', |
|
229 | + 'wepay'=>'Wepay', |
|
230 | + 'worldpay'=>'Worldpay' |
|
231 | + ); |
|
232 | 232 | } |
@@ -7,16 +7,16 @@ discard block |
||
7 | 7 | define('EE_SUPPORT_EMAIL', '[email protected]'); |
8 | 8 | // used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
9 | 9 | if (! defined('DS')) { |
10 | - define('DS', '/'); |
|
10 | + define('DS', '/'); |
|
11 | 11 | } |
12 | 12 | if (! defined('PS')) { |
13 | - define('PS', PATH_SEPARATOR); |
|
13 | + define('PS', PATH_SEPARATOR); |
|
14 | 14 | } |
15 | 15 | if (! defined('SP')) { |
16 | - define('SP', ' '); |
|
16 | + define('SP', ' '); |
|
17 | 17 | } |
18 | 18 | if (! defined('EENL')) { |
19 | - define('EENL', "\n"); |
|
19 | + define('EENL', "\n"); |
|
20 | 20 | } |
21 | 21 | // define the plugin directory and URL |
22 | 22 | define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
@@ -70,16 +70,16 @@ discard block |
||
70 | 70 | define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
71 | 71 | // check for DOMPDF fonts in uploads |
72 | 72 | if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
73 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
73 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
74 | 74 | } |
75 | 75 | // ajax constants |
76 | 76 | define( |
77 | - 'EE_FRONT_AJAX', |
|
78 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) |
|
77 | + 'EE_FRONT_AJAX', |
|
78 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) |
|
79 | 79 | ); |
80 | 80 | define( |
81 | - 'EE_ADMIN_AJAX', |
|
82 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) |
|
81 | + 'EE_ADMIN_AJAX', |
|
82 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) |
|
83 | 83 | ); |
84 | 84 | // just a handy constant occasionally needed for finding values representing infinity in the DB |
85 | 85 | // you're better to use this than its straight value (currently -1) in case you ever |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | define('EE_INF_IN_DB', -1); |
88 | 88 | define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX); |
89 | 89 | if (! defined('EE_DEBUG')) { |
90 | - define('EE_DEBUG', false); |
|
90 | + define('EE_DEBUG', false); |
|
91 | 91 | } |
92 | 92 | // for older WP versions |
93 | 93 | if (! defined('MONTH_IN_SECONDS')) { |
94 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
94 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
95 | 95 | } |
@@ -6,71 +6,71 @@ discard block |
||
6 | 6 | define('EE_MIN_PHP_VER_RECOMMENDED', '5.6.32'); |
7 | 7 | define('EE_SUPPORT_EMAIL', '[email protected]'); |
8 | 8 | // used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
9 | -if (! defined('DS')) { |
|
9 | +if ( ! defined('DS')) { |
|
10 | 10 | define('DS', '/'); |
11 | 11 | } |
12 | -if (! defined('PS')) { |
|
12 | +if ( ! defined('PS')) { |
|
13 | 13 | define('PS', PATH_SEPARATOR); |
14 | 14 | } |
15 | -if (! defined('SP')) { |
|
15 | +if ( ! defined('SP')) { |
|
16 | 16 | define('SP', ' '); |
17 | 17 | } |
18 | -if (! defined('EENL')) { |
|
18 | +if ( ! defined('EENL')) { |
|
19 | 19 | define('EENL', "\n"); |
20 | 20 | } |
21 | 21 | // define the plugin directory and URL |
22 | 22 | define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
23 | -define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE) . DS); |
|
23 | +define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE).DS); |
|
24 | 24 | define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
25 | 25 | // main root folder paths |
26 | -define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
27 | -define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
28 | -define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
29 | -define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
30 | -define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
31 | -define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
32 | -define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
33 | -define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
26 | +define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH.'admin_pages'.DS); |
|
27 | +define('EE_CORE', EE_PLUGIN_DIR_PATH.'core'.DS); |
|
28 | +define('EE_MODULES', EE_PLUGIN_DIR_PATH.'modules'.DS); |
|
29 | +define('EE_PUBLIC', EE_PLUGIN_DIR_PATH.'public'.DS); |
|
30 | +define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH.'shortcodes'.DS); |
|
31 | +define('EE_WIDGETS', EE_PLUGIN_DIR_PATH.'widgets'.DS); |
|
32 | +define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH.'payment_methods'.DS); |
|
33 | +define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH.'caffeinated'.DS); |
|
34 | 34 | // core system paths |
35 | -define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
36 | -define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
37 | -define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
38 | -define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
39 | -define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
40 | -define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
41 | -define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
42 | -define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
43 | -define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
44 | -define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
45 | -define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
46 | -define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
35 | +define('EE_ADMIN', EE_CORE.'admin'.DS); |
|
36 | +define('EE_CPTS', EE_CORE.'CPTs'.DS); |
|
37 | +define('EE_CLASSES', EE_CORE.'db_classes'.DS); |
|
38 | +define('EE_INTERFACES', EE_CORE.'interfaces'.DS); |
|
39 | +define('EE_BUSINESS', EE_CORE.'business'.DS); |
|
40 | +define('EE_MODELS', EE_CORE.'db_models'.DS); |
|
41 | +define('EE_HELPERS', EE_CORE.'helpers'.DS); |
|
42 | +define('EE_LIBRARIES', EE_CORE.'libraries'.DS); |
|
43 | +define('EE_TEMPLATES', EE_CORE.'templates'.DS); |
|
44 | +define('EE_THIRD_PARTY', EE_CORE.'third_party_libs'.DS); |
|
45 | +define('EE_GLOBAL_ASSETS', EE_TEMPLATES.'global_assets'.DS); |
|
46 | +define('EE_FORM_SECTIONS', EE_LIBRARIES.'form_sections'.DS); |
|
47 | 47 | // gateways |
48 | -define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
49 | -define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
48 | +define('EE_GATEWAYS', EE_MODULES.'gateways'.DS); |
|
49 | +define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules'.DS.'gateways'.DS); |
|
50 | 50 | // asset URL paths |
51 | -define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
52 | -define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
53 | -define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
54 | -define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
55 | -define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
56 | -define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
51 | +define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL.'core'.DS.'templates'.DS); |
|
52 | +define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL.'global_assets'.DS); |
|
53 | +define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL.'images'.DS); |
|
54 | +define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL.'core'.DS.'third_party_libs'.DS); |
|
55 | +define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL.'core/helpers/assets/'); |
|
56 | +define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL.'core/libraries/'); |
|
57 | 57 | // define upload paths |
58 | 58 | $uploads = wp_upload_dir(); |
59 | 59 | // define the uploads directory and URL |
60 | -define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
61 | -define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
60 | +define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].DS.'espresso'.DS); |
|
61 | +define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].DS.'espresso'.DS); |
|
62 | 62 | // define the templates directory and URL |
63 | -define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
64 | -define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
63 | +define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'].DS.'espresso'.DS.'templates'.DS); |
|
64 | +define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'].DS.'espresso'.DS.'templates'.DS); |
|
65 | 65 | // define the gateway directory and URL |
66 | -define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
67 | -define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
66 | +define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'].DS.'espresso'.DS.'gateways'.DS); |
|
67 | +define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'].DS.'espresso'.DS.'gateways'.DS); |
|
68 | 68 | // languages folder/path |
69 | -define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
70 | -define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
69 | +define('EE_LANGUAGES_SAFE_LOC', '..'.DS.'uploads'.DS.'espresso'.DS.'languages'.DS); |
|
70 | +define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'languages'.DS); |
|
71 | 71 | // check for DOMPDF fonts in uploads |
72 | -if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
73 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
72 | +if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS)) { |
|
73 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS); |
|
74 | 74 | } |
75 | 75 | // ajax constants |
76 | 76 | define( |
@@ -86,10 +86,10 @@ discard block |
||
86 | 86 | // want to change its default value! or find when -1 means infinity |
87 | 87 | define('EE_INF_IN_DB', -1); |
88 | 88 | define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX); |
89 | -if (! defined('EE_DEBUG')) { |
|
89 | +if ( ! defined('EE_DEBUG')) { |
|
90 | 90 | define('EE_DEBUG', false); |
91 | 91 | } |
92 | 92 | // for older WP versions |
93 | -if (! defined('MONTH_IN_SECONDS')) { |
|
93 | +if ( ! defined('MONTH_IN_SECONDS')) { |
|
94 | 94 | define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
95 | 95 | } |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | protected function _migration_step($num_items = 1) |
53 | 53 | { |
54 | 54 | // if this isn't set then something is really wrong |
55 | - if (! EE_Config::instance()->gateway instanceof EE_Gateway_Config) { |
|
55 | + if ( ! EE_Config::instance()->gateway instanceof EE_Gateway_Config) { |
|
56 | 56 | throw new EE_Error(__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso')); |
57 | 57 | } |
58 | 58 | $invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : null; |
59 | - if (! $invoice_settings) { |
|
59 | + if ( ! $invoice_settings) { |
|
60 | 60 | $this->add_error(__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso')); |
61 | 61 | } else { |
62 | 62 | $invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions']; |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | ); |
90 | 90 | } |
91 | 91 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
92 | - $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
93 | - $overridden_receipt_body= EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
92 | + $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path.'invoice_body.template.php', null, false, false, true); |
|
93 | + $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path.'receipt_body.template.php', null, false, false, true); |
|
94 | 94 | if ($overridden_invoice_body || $overridden_receipt_body) { |
95 | 95 | new PersistentAdminNotice( |
96 | 96 | 'invoice_overriding_templates', |
@@ -15,95 +15,95 @@ |
||
15 | 15 | class EE_DMS_4_5_0_invoice_settings extends EE_Data_Migration_Script_Stage |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Just initializes the status of the migration |
|
20 | - */ |
|
21 | - public function __construct() |
|
22 | - { |
|
23 | - $this->_pretty_name = __('Update Invoice Gateway Settings', 'event_espresso'); |
|
24 | - parent::__construct(); |
|
25 | - } |
|
18 | + /** |
|
19 | + * Just initializes the status of the migration |
|
20 | + */ |
|
21 | + public function __construct() |
|
22 | + { |
|
23 | + $this->_pretty_name = __('Update Invoice Gateway Settings', 'event_espresso'); |
|
24 | + parent::__construct(); |
|
25 | + } |
|
26 | 26 | |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * _count_records_to_migrate |
|
31 | - * Counts the records to migrate; the public version may cache it |
|
32 | - * |
|
33 | - * @access protected |
|
34 | - * @return int |
|
35 | - */ |
|
36 | - protected function _count_records_to_migrate() |
|
37 | - { |
|
38 | - return 1; |
|
39 | - } |
|
29 | + /** |
|
30 | + * _count_records_to_migrate |
|
31 | + * Counts the records to migrate; the public version may cache it |
|
32 | + * |
|
33 | + * @access protected |
|
34 | + * @return int |
|
35 | + */ |
|
36 | + protected function _count_records_to_migrate() |
|
37 | + { |
|
38 | + return 1; |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * _migration_step |
|
45 | - * |
|
46 | - * @access protected |
|
47 | - * @param int $num_items |
|
48 | - * @throws EE_Error |
|
49 | - * @return int number of items ACTUALLY migrated |
|
50 | - * @throws InvalidDataTypeException |
|
51 | - */ |
|
52 | - protected function _migration_step($num_items = 1) |
|
53 | - { |
|
54 | - // if this isn't set then something is really wrong |
|
55 | - if (! EE_Config::instance()->gateway instanceof EE_Gateway_Config) { |
|
56 | - throw new EE_Error(__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso')); |
|
57 | - } |
|
58 | - $invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : null; |
|
59 | - if (! $invoice_settings) { |
|
60 | - $this->add_error(__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso')); |
|
61 | - } else { |
|
62 | - $invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions']; |
|
63 | - $invoice_settings['template_invoice_payee_name'] = $invoice_settings['payable_to']; |
|
64 | - $invoice_settings['template_invoice_address'] = $invoice_settings['payment_address']; |
|
65 | - $invoice_settings['template_invoice_email'] = ''; |
|
66 | - $invoice_settings['template_invoice_tax_number'] = ''; |
|
67 | - unset($invoice_settings['pdf_instructions']); |
|
68 | - unset($invoice_settings['payable_to']); |
|
69 | - unset($invoice_settings['payment_address']); |
|
70 | - EE_Config::instance()->gateway->payment_settings['Invoice'] = $invoice_settings; |
|
71 | - EE_Config::instance()->update_espresso_config(false, false); |
|
43 | + /** |
|
44 | + * _migration_step |
|
45 | + * |
|
46 | + * @access protected |
|
47 | + * @param int $num_items |
|
48 | + * @throws EE_Error |
|
49 | + * @return int number of items ACTUALLY migrated |
|
50 | + * @throws InvalidDataTypeException |
|
51 | + */ |
|
52 | + protected function _migration_step($num_items = 1) |
|
53 | + { |
|
54 | + // if this isn't set then something is really wrong |
|
55 | + if (! EE_Config::instance()->gateway instanceof EE_Gateway_Config) { |
|
56 | + throw new EE_Error(__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso')); |
|
57 | + } |
|
58 | + $invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : null; |
|
59 | + if (! $invoice_settings) { |
|
60 | + $this->add_error(__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso')); |
|
61 | + } else { |
|
62 | + $invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions']; |
|
63 | + $invoice_settings['template_invoice_payee_name'] = $invoice_settings['payable_to']; |
|
64 | + $invoice_settings['template_invoice_address'] = $invoice_settings['payment_address']; |
|
65 | + $invoice_settings['template_invoice_email'] = ''; |
|
66 | + $invoice_settings['template_invoice_tax_number'] = ''; |
|
67 | + unset($invoice_settings['pdf_instructions']); |
|
68 | + unset($invoice_settings['payable_to']); |
|
69 | + unset($invoice_settings['payment_address']); |
|
70 | + EE_Config::instance()->gateway->payment_settings['Invoice'] = $invoice_settings; |
|
71 | + EE_Config::instance()->update_espresso_config(false, false); |
|
72 | 72 | |
73 | - // @todo: check 'invoice_css' too because we can't easily affect that so we might need to set a persistent notice |
|
74 | - // (why is it tough to change? because we want to update the receipt and invoice message template, but |
|
75 | - // message templates are only initialized AFTER migrations and those two are new in 4.5. So if we wanted to |
|
76 | - // update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code; |
|
77 | - // also we don't want to build a dependency on the messages code because it is likely to change soon |
|
78 | - if (isset($invoice_settings['invoice_css']) |
|
79 | - && ! in_array($invoice_settings['invoice_css'], ['', 'simple.css'])) { |
|
80 | - new PersistentAdminNotice( |
|
81 | - 'invoice_css_not_updated', |
|
82 | - sprintf( |
|
83 | - esc_html__( |
|
84 | - 'You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.', |
|
85 | - 'event_espresso' |
|
86 | - ), |
|
87 | - $invoice_settings['invoice_css'] |
|
88 | - ) |
|
89 | - ); |
|
90 | - } |
|
91 | - $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
92 | - $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
93 | - $overridden_receipt_body= EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
94 | - if ($overridden_invoice_body || $overridden_receipt_body) { |
|
95 | - new PersistentAdminNotice( |
|
96 | - 'invoice_overriding_templates', |
|
97 | - esc_html__( |
|
98 | - 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
99 | - 'event_espresso' |
|
100 | - ), |
|
101 | - true |
|
102 | - ); |
|
103 | - } |
|
104 | - } |
|
105 | - // regardless of whether it worked or not, we ought to continue the migration |
|
106 | - $this->set_completed(); |
|
107 | - return 1; |
|
108 | - } |
|
73 | + // @todo: check 'invoice_css' too because we can't easily affect that so we might need to set a persistent notice |
|
74 | + // (why is it tough to change? because we want to update the receipt and invoice message template, but |
|
75 | + // message templates are only initialized AFTER migrations and those two are new in 4.5. So if we wanted to |
|
76 | + // update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code; |
|
77 | + // also we don't want to build a dependency on the messages code because it is likely to change soon |
|
78 | + if (isset($invoice_settings['invoice_css']) |
|
79 | + && ! in_array($invoice_settings['invoice_css'], ['', 'simple.css'])) { |
|
80 | + new PersistentAdminNotice( |
|
81 | + 'invoice_css_not_updated', |
|
82 | + sprintf( |
|
83 | + esc_html__( |
|
84 | + 'You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.', |
|
85 | + 'event_espresso' |
|
86 | + ), |
|
87 | + $invoice_settings['invoice_css'] |
|
88 | + ) |
|
89 | + ); |
|
90 | + } |
|
91 | + $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
92 | + $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
93 | + $overridden_receipt_body= EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
94 | + if ($overridden_invoice_body || $overridden_receipt_body) { |
|
95 | + new PersistentAdminNotice( |
|
96 | + 'invoice_overriding_templates', |
|
97 | + esc_html__( |
|
98 | + 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
99 | + 'event_espresso' |
|
100 | + ), |
|
101 | + true |
|
102 | + ); |
|
103 | + } |
|
104 | + } |
|
105 | + // regardless of whether it worked or not, we ought to continue the migration |
|
106 | + $this->set_completed(); |
|
107 | + return 1; |
|
108 | + } |
|
109 | 109 | } |
@@ -87,57 +87,57 @@ discard block |
||
87 | 87 | */ |
88 | 88 | class EE_DMS_4_1_0_prices extends EE_Data_Migration_Script_Stage_Table |
89 | 89 | { |
90 | - private $_new_price_table; |
|
91 | - private $_new_ticket_table; |
|
92 | - private $_new_ticket_price_table; |
|
93 | - private $_new_datetime_ticket_table; |
|
94 | - /** |
|
95 | - * A count of all the different tickets created, used for setting the new ones' TKT_Order |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - private $_ticket_count = 0; |
|
99 | - const price_type_base = 1; |
|
100 | - const price_type_member_discount = 3; |
|
101 | - const price_type_percent_surcharge = 4; |
|
102 | - const price_type_flat_surcharge = 5; |
|
90 | + private $_new_price_table; |
|
91 | + private $_new_ticket_table; |
|
92 | + private $_new_ticket_price_table; |
|
93 | + private $_new_datetime_ticket_table; |
|
94 | + /** |
|
95 | + * A count of all the different tickets created, used for setting the new ones' TKT_Order |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + private $_ticket_count = 0; |
|
99 | + const price_type_base = 1; |
|
100 | + const price_type_member_discount = 3; |
|
101 | + const price_type_percent_surcharge = 4; |
|
102 | + const price_type_flat_surcharge = 5; |
|
103 | 103 | |
104 | - public function __construct() |
|
105 | - { |
|
106 | - global $wpdb; |
|
107 | - $this->_pretty_name = __("Prices", "event_espresso"); |
|
108 | - $this->_old_table = $wpdb->prefix."events_prices"; |
|
109 | - $this->select_expression = 'p.*, e.event_status'; |
|
110 | - $this->_extra_where_sql = ' AS p |
|
104 | + public function __construct() |
|
105 | + { |
|
106 | + global $wpdb; |
|
107 | + $this->_pretty_name = __("Prices", "event_espresso"); |
|
108 | + $this->_old_table = $wpdb->prefix."events_prices"; |
|
109 | + $this->select_expression = 'p.*, e.event_status'; |
|
110 | + $this->_extra_where_sql = ' AS p |
|
111 | 111 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON p.event_id=e.id |
112 | 112 | WHERE e.event_status!="D"'; |
113 | - $this->_new_price_table = $wpdb->prefix."esp_price"; |
|
114 | - $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
|
115 | - $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
116 | - $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket"; |
|
117 | - parent::__construct(); |
|
118 | - } |
|
119 | - protected function _migrate_old_row($old_row) |
|
120 | - { |
|
121 | - // create the base price |
|
122 | - $new_price_id = $this->_insert_new_price($old_row); |
|
123 | - // create the member discount if there is any |
|
124 | - // commented-out because we may actually NOT be supporting this in 4.1 |
|
113 | + $this->_new_price_table = $wpdb->prefix."esp_price"; |
|
114 | + $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
|
115 | + $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
116 | + $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket"; |
|
117 | + parent::__construct(); |
|
118 | + } |
|
119 | + protected function _migrate_old_row($old_row) |
|
120 | + { |
|
121 | + // create the base price |
|
122 | + $new_price_id = $this->_insert_new_price($old_row); |
|
123 | + // create the member discount if there is any |
|
124 | + // commented-out because we may actually NOT be supporting this in 4.1 |
|
125 | 125 | // if($old_row['event_cost'] != $old_row['member_price']){ |
126 | 126 | // $member_price_discount_id = $this->_insert_new_member_price($old_row); |
127 | 127 | // }else{ |
128 | 128 | // $member_price_discount_id = 0; |
129 | 129 | // } |
130 | - // create the surcharge if there is any |
|
131 | - if (floatval($old_row['surcharge']) >= 0.01) { |
|
132 | - $surcharge_price_id = $this->_insert_new_surcharge_price($old_row); |
|
133 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id)); |
|
134 | - } else { |
|
135 | - $surcharge_price_id = 0; |
|
136 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id)); |
|
137 | - } |
|
138 | - // associate the ticket to all datetimes for event (ie, this ONE ticket grants access to ALL datetimes, not just one of the attendee's choice. |
|
139 | - // if the latter were the case, then we'd create a separate ticket for each datetime and ahve their association be one-to-one) |
|
140 | - // create ticket |
|
130 | + // create the surcharge if there is any |
|
131 | + if (floatval($old_row['surcharge']) >= 0.01) { |
|
132 | + $surcharge_price_id = $this->_insert_new_surcharge_price($old_row); |
|
133 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id)); |
|
134 | + } else { |
|
135 | + $surcharge_price_id = 0; |
|
136 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id)); |
|
137 | + } |
|
138 | + // associate the ticket to all datetimes for event (ie, this ONE ticket grants access to ALL datetimes, not just one of the attendee's choice. |
|
139 | + // if the latter were the case, then we'd create a separate ticket for each datetime and ahve their association be one-to-one) |
|
140 | + // create ticket |
|
141 | 141 | // $ticket_id = $this->_insert_new_ticket($old_row); |
142 | 142 | // if($ticket_id){ |
143 | 143 | // $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $ticket_id); |
@@ -149,62 +149,62 @@ discard block |
||
149 | 149 | // $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id); |
150 | 150 | // } |
151 | 151 | // } |
152 | - // create a ticket for each old price -old datetime combo |
|
153 | - $tickets_for_old_price = array(); |
|
154 | - foreach ($this->_get_datetime_ids_for_old_event_id($old_row['event_id']) as $new_datetime_id) { |
|
155 | - $ticket_id = $this->_insert_new_ticket($old_row); |
|
156 | - $tickets_for_old_price[] = $ticket_id; |
|
157 | - // associate to old prices |
|
158 | - $this->_insert_ticket_price_relation($ticket_id, $new_price_id); |
|
159 | - $this->_insert_ticket_price_relation($ticket_id, $surcharge_price_id); |
|
160 | - $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id); |
|
161 | - } |
|
162 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $tickets_for_old_price); |
|
163 | - } |
|
164 | - /** |
|
165 | - * Creates a 4.1 price base type |
|
166 | - * @global type $wpdb |
|
167 | - * @param type $old_price |
|
168 | - * @return int |
|
169 | - */ |
|
170 | - private function _insert_new_price($old_price) |
|
171 | - { |
|
172 | - global $wpdb; |
|
173 | - $cols_n_values = array( |
|
174 | - 'PRT_ID'=>self::price_type_base, |
|
175 | - 'PRC_amount'=>floatval($old_price['event_cost']), |
|
176 | - 'PRC_name'=>$old_price['price_type'], |
|
177 | - 'PRC_is_default'=>false, |
|
178 | - 'PRC_overrides'=>false, |
|
179 | - 'PRC_order'=>0, |
|
180 | - 'PRC_deleted'=>false, |
|
181 | - 'PRC_parent'=>null |
|
152 | + // create a ticket for each old price -old datetime combo |
|
153 | + $tickets_for_old_price = array(); |
|
154 | + foreach ($this->_get_datetime_ids_for_old_event_id($old_row['event_id']) as $new_datetime_id) { |
|
155 | + $ticket_id = $this->_insert_new_ticket($old_row); |
|
156 | + $tickets_for_old_price[] = $ticket_id; |
|
157 | + // associate to old prices |
|
158 | + $this->_insert_ticket_price_relation($ticket_id, $new_price_id); |
|
159 | + $this->_insert_ticket_price_relation($ticket_id, $surcharge_price_id); |
|
160 | + $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id); |
|
161 | + } |
|
162 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $tickets_for_old_price); |
|
163 | + } |
|
164 | + /** |
|
165 | + * Creates a 4.1 price base type |
|
166 | + * @global type $wpdb |
|
167 | + * @param type $old_price |
|
168 | + * @return int |
|
169 | + */ |
|
170 | + private function _insert_new_price($old_price) |
|
171 | + { |
|
172 | + global $wpdb; |
|
173 | + $cols_n_values = array( |
|
174 | + 'PRT_ID'=>self::price_type_base, |
|
175 | + 'PRC_amount'=>floatval($old_price['event_cost']), |
|
176 | + 'PRC_name'=>$old_price['price_type'], |
|
177 | + 'PRC_is_default'=>false, |
|
178 | + 'PRC_overrides'=>false, |
|
179 | + 'PRC_order'=>0, |
|
180 | + 'PRC_deleted'=>false, |
|
181 | + 'PRC_parent'=>null |
|
182 | 182 | |
183 | - ); |
|
184 | - $datatypes = array( |
|
185 | - '%d',// PRT_ID |
|
186 | - '%f',// PRT_amount |
|
187 | - '%s',// PRC_name |
|
188 | - '%d',// PRC_is_default |
|
189 | - '%d',// PRC_overrides |
|
190 | - '%d',// PRC_order |
|
191 | - '%d',// PRC_deleted |
|
192 | - '%d',// PRC_parent |
|
193 | - ); |
|
194 | - $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
195 | - if (! $success) { |
|
196 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
|
197 | - return 0; |
|
198 | - } |
|
199 | - $new_id = $wpdb->insert_id; |
|
200 | - return $new_id; |
|
201 | - } |
|
202 | - /** |
|
203 | - * Creates a 4.1 member price discount |
|
204 | - * @global type $wpdb |
|
205 | - * @param type $old_price |
|
206 | - * @return int |
|
207 | - */ |
|
183 | + ); |
|
184 | + $datatypes = array( |
|
185 | + '%d',// PRT_ID |
|
186 | + '%f',// PRT_amount |
|
187 | + '%s',// PRC_name |
|
188 | + '%d',// PRC_is_default |
|
189 | + '%d',// PRC_overrides |
|
190 | + '%d',// PRC_order |
|
191 | + '%d',// PRC_deleted |
|
192 | + '%d',// PRC_parent |
|
193 | + ); |
|
194 | + $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
195 | + if (! $success) { |
|
196 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
|
197 | + return 0; |
|
198 | + } |
|
199 | + $new_id = $wpdb->insert_id; |
|
200 | + return $new_id; |
|
201 | + } |
|
202 | + /** |
|
203 | + * Creates a 4.1 member price discount |
|
204 | + * @global type $wpdb |
|
205 | + * @param type $old_price |
|
206 | + * @return int |
|
207 | + */ |
|
208 | 208 | // private function _insert_new_member_price($old_price){ |
209 | 209 | // $discount_amount = floatval($old_price['event_cost']) - floatval($old_price['member_price']); |
210 | 210 | // global $wpdb; |
@@ -237,207 +237,207 @@ discard block |
||
237 | 237 | // $new_id = $wpdb->insert_id; |
238 | 238 | // return $new_id; |
239 | 239 | // } |
240 | - /** |
|
241 | - * Creates a 4.1 member price discount |
|
242 | - * @global type $wpdb |
|
243 | - * @param type $old_price |
|
244 | - * @return int |
|
245 | - */ |
|
246 | - private function _insert_new_surcharge_price($old_price) |
|
247 | - { |
|
240 | + /** |
|
241 | + * Creates a 4.1 member price discount |
|
242 | + * @global type $wpdb |
|
243 | + * @param type $old_price |
|
244 | + * @return int |
|
245 | + */ |
|
246 | + private function _insert_new_surcharge_price($old_price) |
|
247 | + { |
|
248 | 248 | |
249 | - if ($old_price['surcharge_type'] == 'flat_rate') { |
|
250 | - $price_type = self::price_type_flat_surcharge; |
|
251 | - } else { |
|
252 | - $price_type = self::price_type_percent_surcharge; |
|
253 | - } |
|
254 | - global $wpdb; |
|
255 | - $cols_n_values = array( |
|
256 | - 'PRT_ID'=>$price_type, |
|
257 | - 'PRC_amount'=>floatval($old_price['surcharge']), |
|
258 | - 'PRC_name'=> __("Surcharge", "event_espresso"), |
|
259 | - 'PRC_is_default'=>false, |
|
260 | - 'PRC_overrides'=>false, |
|
261 | - 'PRC_order'=>20, |
|
262 | - 'PRC_deleted'=>false, |
|
263 | - 'PRC_parent'=>null |
|
249 | + if ($old_price['surcharge_type'] == 'flat_rate') { |
|
250 | + $price_type = self::price_type_flat_surcharge; |
|
251 | + } else { |
|
252 | + $price_type = self::price_type_percent_surcharge; |
|
253 | + } |
|
254 | + global $wpdb; |
|
255 | + $cols_n_values = array( |
|
256 | + 'PRT_ID'=>$price_type, |
|
257 | + 'PRC_amount'=>floatval($old_price['surcharge']), |
|
258 | + 'PRC_name'=> __("Surcharge", "event_espresso"), |
|
259 | + 'PRC_is_default'=>false, |
|
260 | + 'PRC_overrides'=>false, |
|
261 | + 'PRC_order'=>20, |
|
262 | + 'PRC_deleted'=>false, |
|
263 | + 'PRC_parent'=>null |
|
264 | 264 | |
265 | - ); |
|
266 | - $datatypes = array( |
|
267 | - '%d',// PRT_ID |
|
268 | - '%f',// PRT_amount |
|
269 | - '%s',// PRC_name |
|
270 | - '%d',// PRC_is_default |
|
271 | - '%d',// PRC_overrides |
|
272 | - '%d',// PRC_order |
|
273 | - '%d',// PRC_deleted |
|
274 | - '%d',// PRC_parent |
|
275 | - ); |
|
276 | - $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
277 | - if (! $success) { |
|
278 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
|
279 | - return 0; |
|
280 | - } |
|
281 | - $new_id = $wpdb->insert_id; |
|
282 | - return $new_id; |
|
283 | - } |
|
284 | - /** |
|
285 | - * Inserts a 4.1 ticket based off the 3.1 price, and the price IDs we've already made from the 3.1 price |
|
286 | - * @param $old_price_row array where keys are columns |
|
287 | - * @param $new_base_price_id int |
|
288 | - * @param $new_member_discount_id int |
|
289 | - * @param $new_surcharge_id int |
|
290 | - * @return int new ticket id |
|
291 | - */ |
|
292 | - private function _insert_new_ticket($old_price_row) |
|
293 | - { |
|
294 | - global $wpdb; |
|
295 | - $event_row = $this->_get_event_row($old_price_row['event_id']); |
|
296 | - if ($old_price_row['surcharge_type'] == 'flat_rate') { |
|
297 | - $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']); |
|
298 | - } else {// percent surcharge |
|
299 | - $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100); |
|
300 | - } |
|
301 | - $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']); |
|
302 | - $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']); |
|
303 | - $end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']); |
|
304 | - $end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']); |
|
305 | - $cols_n_values = array( |
|
306 | - 'TTM_ID'=>0, |
|
307 | - 'TKT_name'=>$old_price_row['price_type'], |
|
308 | - 'TKT_description'=>'', |
|
309 | - 'TKT_start_date'=>$start_date_utc, |
|
310 | - 'TKT_end_date'=>$end_date_utc, |
|
311 | - 'TKT_min'=>0, |
|
312 | - 'TKT_max'=>-1, |
|
313 | - 'TKT_price'=>$final_ticket_price, |
|
314 | - 'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration |
|
315 | - 'TKT_qty'=> -1, |
|
316 | - 'TKT_uses'=> 1, |
|
317 | - 'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices |
|
318 | - 'TKT_is_default'=>false, |
|
319 | - 'TKT_order'=>$this->_get_ticket_count(), |
|
320 | - 'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways |
|
321 | - 'TKT_deleted'=>false, |
|
322 | - 'TKT_parent'=>0 |
|
265 | + ); |
|
266 | + $datatypes = array( |
|
267 | + '%d',// PRT_ID |
|
268 | + '%f',// PRT_amount |
|
269 | + '%s',// PRC_name |
|
270 | + '%d',// PRC_is_default |
|
271 | + '%d',// PRC_overrides |
|
272 | + '%d',// PRC_order |
|
273 | + '%d',// PRC_deleted |
|
274 | + '%d',// PRC_parent |
|
275 | + ); |
|
276 | + $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
277 | + if (! $success) { |
|
278 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
|
279 | + return 0; |
|
280 | + } |
|
281 | + $new_id = $wpdb->insert_id; |
|
282 | + return $new_id; |
|
283 | + } |
|
284 | + /** |
|
285 | + * Inserts a 4.1 ticket based off the 3.1 price, and the price IDs we've already made from the 3.1 price |
|
286 | + * @param $old_price_row array where keys are columns |
|
287 | + * @param $new_base_price_id int |
|
288 | + * @param $new_member_discount_id int |
|
289 | + * @param $new_surcharge_id int |
|
290 | + * @return int new ticket id |
|
291 | + */ |
|
292 | + private function _insert_new_ticket($old_price_row) |
|
293 | + { |
|
294 | + global $wpdb; |
|
295 | + $event_row = $this->_get_event_row($old_price_row['event_id']); |
|
296 | + if ($old_price_row['surcharge_type'] == 'flat_rate') { |
|
297 | + $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']); |
|
298 | + } else {// percent surcharge |
|
299 | + $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100); |
|
300 | + } |
|
301 | + $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']); |
|
302 | + $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']); |
|
303 | + $end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']); |
|
304 | + $end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']); |
|
305 | + $cols_n_values = array( |
|
306 | + 'TTM_ID'=>0, |
|
307 | + 'TKT_name'=>$old_price_row['price_type'], |
|
308 | + 'TKT_description'=>'', |
|
309 | + 'TKT_start_date'=>$start_date_utc, |
|
310 | + 'TKT_end_date'=>$end_date_utc, |
|
311 | + 'TKT_min'=>0, |
|
312 | + 'TKT_max'=>-1, |
|
313 | + 'TKT_price'=>$final_ticket_price, |
|
314 | + 'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration |
|
315 | + 'TKT_qty'=> -1, |
|
316 | + 'TKT_uses'=> 1, |
|
317 | + 'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices |
|
318 | + 'TKT_is_default'=>false, |
|
319 | + 'TKT_order'=>$this->_get_ticket_count(), |
|
320 | + 'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways |
|
321 | + 'TKT_deleted'=>false, |
|
322 | + 'TKT_parent'=>0 |
|
323 | 323 | |
324 | - ); |
|
325 | - $datatypes = array( |
|
326 | - '%d',// TTM_ID |
|
327 | - '%s',// TKT_name |
|
328 | - '%s',// TKT_description |
|
329 | - '%s',// TKT_start_date |
|
330 | - '%s',// TKT_end_date |
|
331 | - '%d',// TKT_min |
|
332 | - '%d',// TKT_max |
|
333 | - '%f',// TKT_price |
|
334 | - '%d',// TKT_sold |
|
335 | - '%d',// TKT_qty |
|
336 | - '%d',// TKT_uses |
|
337 | - '%d',// TKT_taxable |
|
338 | - '%d',// TKT_is_default |
|
339 | - '%d',// TKT_order |
|
340 | - '%d',// TKT_row |
|
341 | - '%d',// TKT_deleted |
|
342 | - '%d',// TKT_parent |
|
343 | - ); |
|
344 | - $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes); |
|
345 | - if (! $success) { |
|
346 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes)); |
|
347 | - return 0; |
|
348 | - } |
|
349 | - $new_id = $wpdb->insert_id; |
|
350 | - return $new_id; |
|
351 | - } |
|
324 | + ); |
|
325 | + $datatypes = array( |
|
326 | + '%d',// TTM_ID |
|
327 | + '%s',// TKT_name |
|
328 | + '%s',// TKT_description |
|
329 | + '%s',// TKT_start_date |
|
330 | + '%s',// TKT_end_date |
|
331 | + '%d',// TKT_min |
|
332 | + '%d',// TKT_max |
|
333 | + '%f',// TKT_price |
|
334 | + '%d',// TKT_sold |
|
335 | + '%d',// TKT_qty |
|
336 | + '%d',// TKT_uses |
|
337 | + '%d',// TKT_taxable |
|
338 | + '%d',// TKT_is_default |
|
339 | + '%d',// TKT_order |
|
340 | + '%d',// TKT_row |
|
341 | + '%d',// TKT_deleted |
|
342 | + '%d',// TKT_parent |
|
343 | + ); |
|
344 | + $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes); |
|
345 | + if (! $success) { |
|
346 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes)); |
|
347 | + return 0; |
|
348 | + } |
|
349 | + $new_id = $wpdb->insert_id; |
|
350 | + return $new_id; |
|
351 | + } |
|
352 | 352 | |
353 | - /** |
|
354 | - * Adds a join between a ticket and a price |
|
355 | - * @global type $wpdb |
|
356 | - * @param type $new_ticket_id |
|
357 | - * @param type $new_price_id |
|
358 | - * @return int |
|
359 | - */ |
|
360 | - private function _insert_ticket_price_relation($new_ticket_id, $new_price_id) |
|
361 | - { |
|
362 | - global $wpdb; |
|
363 | - $cols_n_values = array( |
|
364 | - 'TKT_ID'=>$new_ticket_id, |
|
365 | - 'PRC_ID'=>$new_price_id, |
|
366 | - ); |
|
367 | - $datatypes = array( |
|
368 | - '%d',// TKT_ID |
|
369 | - '%d',// PRC_ID |
|
370 | - ); |
|
371 | - $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes); |
|
372 | - if (! $success) { |
|
373 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes)); |
|
374 | - return 0; |
|
375 | - } |
|
376 | - $new_id = $wpdb->insert_id; |
|
377 | - return $new_id; |
|
378 | - } |
|
353 | + /** |
|
354 | + * Adds a join between a ticket and a price |
|
355 | + * @global type $wpdb |
|
356 | + * @param type $new_ticket_id |
|
357 | + * @param type $new_price_id |
|
358 | + * @return int |
|
359 | + */ |
|
360 | + private function _insert_ticket_price_relation($new_ticket_id, $new_price_id) |
|
361 | + { |
|
362 | + global $wpdb; |
|
363 | + $cols_n_values = array( |
|
364 | + 'TKT_ID'=>$new_ticket_id, |
|
365 | + 'PRC_ID'=>$new_price_id, |
|
366 | + ); |
|
367 | + $datatypes = array( |
|
368 | + '%d',// TKT_ID |
|
369 | + '%d',// PRC_ID |
|
370 | + ); |
|
371 | + $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes); |
|
372 | + if (! $success) { |
|
373 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes)); |
|
374 | + return 0; |
|
375 | + } |
|
376 | + $new_id = $wpdb->insert_id; |
|
377 | + return $new_id; |
|
378 | + } |
|
379 | 379 | |
380 | - /** |
|
381 | - * Adds a join between a ticket and a datetime |
|
382 | - * @global type $wpdb |
|
383 | - * @param type $new_ticket_id |
|
384 | - * @param type $new_price_id |
|
385 | - * @return int |
|
386 | - */ |
|
387 | - private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id) |
|
388 | - { |
|
389 | - global $wpdb; |
|
390 | - $cols_n_values = array( |
|
391 | - 'TKT_ID'=>$new_ticket_id, |
|
392 | - 'DTT_ID'=>$new_datetime_id, |
|
393 | - ); |
|
394 | - $datatypes = array( |
|
395 | - '%d',// TKT_ID |
|
396 | - '%d',// DTT_ID |
|
397 | - ); |
|
398 | - $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes); |
|
399 | - if (! $success) { |
|
400 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes)); |
|
401 | - return 0; |
|
402 | - } |
|
403 | - $new_id = $wpdb->insert_id; |
|
404 | - return $new_id; |
|
405 | - } |
|
380 | + /** |
|
381 | + * Adds a join between a ticket and a datetime |
|
382 | + * @global type $wpdb |
|
383 | + * @param type $new_ticket_id |
|
384 | + * @param type $new_price_id |
|
385 | + * @return int |
|
386 | + */ |
|
387 | + private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id) |
|
388 | + { |
|
389 | + global $wpdb; |
|
390 | + $cols_n_values = array( |
|
391 | + 'TKT_ID'=>$new_ticket_id, |
|
392 | + 'DTT_ID'=>$new_datetime_id, |
|
393 | + ); |
|
394 | + $datatypes = array( |
|
395 | + '%d',// TKT_ID |
|
396 | + '%d',// DTT_ID |
|
397 | + ); |
|
398 | + $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes); |
|
399 | + if (! $success) { |
|
400 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes)); |
|
401 | + return 0; |
|
402 | + } |
|
403 | + $new_id = $wpdb->insert_id; |
|
404 | + return $new_id; |
|
405 | + } |
|
406 | 406 | |
407 | - /** |
|
408 | - * Simply gets the 3.1 event row data |
|
409 | - * @global type $wpdb |
|
410 | - * @param type $event_id |
|
411 | - * @return array |
|
412 | - */ |
|
413 | - private function _get_event_row($event_id) |
|
414 | - { |
|
415 | - global $wpdb; |
|
416 | - $old_event_table = $wpdb->prefix."events_detail"; |
|
417 | - return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A); |
|
418 | - } |
|
419 | - /** |
|
420 | - * Gets a higher ticket count than last time it was called (and is persisted between HTTP requests). |
|
421 | - * Yes we COULD run a query joining events->datetimes->ticket_datetimes->tickets, but this should work fine too |
|
422 | - * @return int |
|
423 | - */ |
|
424 | - private function _get_ticket_count() |
|
425 | - { |
|
426 | - return $this->_ticket_count++; |
|
427 | - } |
|
407 | + /** |
|
408 | + * Simply gets the 3.1 event row data |
|
409 | + * @global type $wpdb |
|
410 | + * @param type $event_id |
|
411 | + * @return array |
|
412 | + */ |
|
413 | + private function _get_event_row($event_id) |
|
414 | + { |
|
415 | + global $wpdb; |
|
416 | + $old_event_table = $wpdb->prefix."events_detail"; |
|
417 | + return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A); |
|
418 | + } |
|
419 | + /** |
|
420 | + * Gets a higher ticket count than last time it was called (and is persisted between HTTP requests). |
|
421 | + * Yes we COULD run a query joining events->datetimes->ticket_datetimes->tickets, but this should work fine too |
|
422 | + * @return int |
|
423 | + */ |
|
424 | + private function _get_ticket_count() |
|
425 | + { |
|
426 | + return $this->_ticket_count++; |
|
427 | + } |
|
428 | 428 | |
429 | - /** |
|
430 | - * Using the 3.1 event id, gets the 4.1 datetimes for it |
|
431 | - * @param int $old_event_id |
|
432 | - * @return array where values are datetime ids |
|
433 | - */ |
|
434 | - private function _get_datetime_ids_for_old_event_id($old_event_id) |
|
435 | - { |
|
436 | - global $wpdb; |
|
437 | - $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts); |
|
438 | - $datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id)); |
|
439 | - return $datetime_ids; |
|
440 | - } |
|
429 | + /** |
|
430 | + * Using the 3.1 event id, gets the 4.1 datetimes for it |
|
431 | + * @param int $old_event_id |
|
432 | + * @return array where values are datetime ids |
|
433 | + */ |
|
434 | + private function _get_datetime_ids_for_old_event_id($old_event_id) |
|
435 | + { |
|
436 | + global $wpdb; |
|
437 | + $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts); |
|
438 | + $datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id)); |
|
439 | + return $datetime_ids; |
|
440 | + } |
|
441 | 441 | } |
442 | 442 | // @todo: tell users that in 3.1 the limit was on registration PER event,in 4.1 it's limit PER TICKET... SO, if they sell 2 different types of tickets |
443 | 443 | // |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $this->_old_table = $wpdb->prefix."events_prices"; |
109 | 109 | $this->select_expression = 'p.*, e.event_status'; |
110 | 110 | $this->_extra_where_sql = ' AS p |
111 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON p.event_id=e.id |
|
111 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON p.event_id=e.id |
|
112 | 112 | WHERE e.event_status!="D"'; |
113 | 113 | $this->_new_price_table = $wpdb->prefix."esp_price"; |
114 | 114 | $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | // create the surcharge if there is any |
131 | 131 | if (floatval($old_row['surcharge']) >= 0.01) { |
132 | 132 | $surcharge_price_id = $this->_insert_new_surcharge_price($old_row); |
133 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id)); |
|
133 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id, $surcharge_price_id)); |
|
134 | 134 | } else { |
135 | 135 | $surcharge_price_id = 0; |
136 | 136 | $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id)); |
@@ -182,17 +182,17 @@ discard block |
||
182 | 182 | |
183 | 183 | ); |
184 | 184 | $datatypes = array( |
185 | - '%d',// PRT_ID |
|
186 | - '%f',// PRT_amount |
|
187 | - '%s',// PRC_name |
|
188 | - '%d',// PRC_is_default |
|
189 | - '%d',// PRC_overrides |
|
190 | - '%d',// PRC_order |
|
191 | - '%d',// PRC_deleted |
|
192 | - '%d',// PRC_parent |
|
185 | + '%d', // PRT_ID |
|
186 | + '%f', // PRT_amount |
|
187 | + '%s', // PRC_name |
|
188 | + '%d', // PRC_is_default |
|
189 | + '%d', // PRC_overrides |
|
190 | + '%d', // PRC_order |
|
191 | + '%d', // PRC_deleted |
|
192 | + '%d', // PRC_parent |
|
193 | 193 | ); |
194 | 194 | $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
195 | - if (! $success) { |
|
195 | + if ( ! $success) { |
|
196 | 196 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
197 | 197 | return 0; |
198 | 198 | } |
@@ -264,17 +264,17 @@ discard block |
||
264 | 264 | |
265 | 265 | ); |
266 | 266 | $datatypes = array( |
267 | - '%d',// PRT_ID |
|
268 | - '%f',// PRT_amount |
|
269 | - '%s',// PRC_name |
|
270 | - '%d',// PRC_is_default |
|
271 | - '%d',// PRC_overrides |
|
272 | - '%d',// PRC_order |
|
273 | - '%d',// PRC_deleted |
|
274 | - '%d',// PRC_parent |
|
267 | + '%d', // PRT_ID |
|
268 | + '%f', // PRT_amount |
|
269 | + '%s', // PRC_name |
|
270 | + '%d', // PRC_is_default |
|
271 | + '%d', // PRC_overrides |
|
272 | + '%d', // PRC_order |
|
273 | + '%d', // PRC_deleted |
|
274 | + '%d', // PRC_parent |
|
275 | 275 | ); |
276 | 276 | $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
277 | - if (! $success) { |
|
277 | + if ( ! $success) { |
|
278 | 278 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
279 | 279 | return 0; |
280 | 280 | } |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | if ($old_price_row['surcharge_type'] == 'flat_rate') { |
297 | 297 | $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']); |
298 | 298 | } else {// percent surcharge |
299 | - $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100); |
|
299 | + $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge']) / 100); |
|
300 | 300 | } |
301 | 301 | $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']); |
302 | 302 | $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']); |
@@ -311,38 +311,38 @@ discard block |
||
311 | 311 | 'TKT_min'=>0, |
312 | 312 | 'TKT_max'=>-1, |
313 | 313 | 'TKT_price'=>$final_ticket_price, |
314 | - 'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration |
|
314 | + 'TKT_sold'=> 0, // note: this will get calculated as we actually add registrations during the migration |
|
315 | 315 | 'TKT_qty'=> -1, |
316 | 316 | 'TKT_uses'=> 1, |
317 | - 'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices |
|
317 | + 'TKT_taxable'=>false, // so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices |
|
318 | 318 | 'TKT_is_default'=>false, |
319 | 319 | 'TKT_order'=>$this->_get_ticket_count(), |
320 | - 'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways |
|
320 | + 'TKT_row'=>0, // doesn't matter because UI reset this on first save anyways |
|
321 | 321 | 'TKT_deleted'=>false, |
322 | 322 | 'TKT_parent'=>0 |
323 | 323 | |
324 | 324 | ); |
325 | 325 | $datatypes = array( |
326 | - '%d',// TTM_ID |
|
327 | - '%s',// TKT_name |
|
328 | - '%s',// TKT_description |
|
329 | - '%s',// TKT_start_date |
|
330 | - '%s',// TKT_end_date |
|
331 | - '%d',// TKT_min |
|
332 | - '%d',// TKT_max |
|
333 | - '%f',// TKT_price |
|
334 | - '%d',// TKT_sold |
|
335 | - '%d',// TKT_qty |
|
336 | - '%d',// TKT_uses |
|
337 | - '%d',// TKT_taxable |
|
338 | - '%d',// TKT_is_default |
|
339 | - '%d',// TKT_order |
|
340 | - '%d',// TKT_row |
|
341 | - '%d',// TKT_deleted |
|
342 | - '%d',// TKT_parent |
|
326 | + '%d', // TTM_ID |
|
327 | + '%s', // TKT_name |
|
328 | + '%s', // TKT_description |
|
329 | + '%s', // TKT_start_date |
|
330 | + '%s', // TKT_end_date |
|
331 | + '%d', // TKT_min |
|
332 | + '%d', // TKT_max |
|
333 | + '%f', // TKT_price |
|
334 | + '%d', // TKT_sold |
|
335 | + '%d', // TKT_qty |
|
336 | + '%d', // TKT_uses |
|
337 | + '%d', // TKT_taxable |
|
338 | + '%d', // TKT_is_default |
|
339 | + '%d', // TKT_order |
|
340 | + '%d', // TKT_row |
|
341 | + '%d', // TKT_deleted |
|
342 | + '%d', // TKT_parent |
|
343 | 343 | ); |
344 | 344 | $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes); |
345 | - if (! $success) { |
|
345 | + if ( ! $success) { |
|
346 | 346 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes)); |
347 | 347 | return 0; |
348 | 348 | } |
@@ -365,12 +365,12 @@ discard block |
||
365 | 365 | 'PRC_ID'=>$new_price_id, |
366 | 366 | ); |
367 | 367 | $datatypes = array( |
368 | - '%d',// TKT_ID |
|
369 | - '%d',// PRC_ID |
|
368 | + '%d', // TKT_ID |
|
369 | + '%d', // PRC_ID |
|
370 | 370 | ); |
371 | 371 | $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes); |
372 | - if (! $success) { |
|
373 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes)); |
|
372 | + if ( ! $success) { |
|
373 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id, 'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes)); |
|
374 | 374 | return 0; |
375 | 375 | } |
376 | 376 | $new_id = $wpdb->insert_id; |
@@ -392,12 +392,12 @@ discard block |
||
392 | 392 | 'DTT_ID'=>$new_datetime_id, |
393 | 393 | ); |
394 | 394 | $datatypes = array( |
395 | - '%d',// TKT_ID |
|
396 | - '%d',// DTT_ID |
|
395 | + '%d', // TKT_ID |
|
396 | + '%d', // DTT_ID |
|
397 | 397 | ); |
398 | 398 | $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes); |
399 | - if (! $success) { |
|
400 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes)); |
|
399 | + if ( ! $success) { |
|
400 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id, 'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes)); |
|
401 | 401 | return 0; |
402 | 402 | } |
403 | 403 | $new_id = $wpdb->insert_id; |
@@ -32,87 +32,87 @@ |
||
32 | 32 | |
33 | 33 | class EE_DMS_4_1_0_answers extends EE_Data_Migration_Script_Stage_Table |
34 | 34 | { |
35 | - private $_new_answer_table; |
|
36 | - private $_new_question_table; |
|
37 | - public function __construct() |
|
38 | - { |
|
39 | - global $wpdb; |
|
40 | - $this->_pretty_name = __("Answers", "event_espresso"); |
|
41 | - $this->_old_table = $wpdb->prefix."events_answer"; |
|
42 | - // join to attendee and then join to events table |
|
43 | - $this->select_expression = 'ans.*, e.event_status'; |
|
44 | - $this->_extra_where_sql = ' AS ans |
|
35 | + private $_new_answer_table; |
|
36 | + private $_new_question_table; |
|
37 | + public function __construct() |
|
38 | + { |
|
39 | + global $wpdb; |
|
40 | + $this->_pretty_name = __("Answers", "event_espresso"); |
|
41 | + $this->_old_table = $wpdb->prefix."events_answer"; |
|
42 | + // join to attendee and then join to events table |
|
43 | + $this->select_expression = 'ans.*, e.event_status'; |
|
44 | + $this->_extra_where_sql = ' AS ans |
|
45 | 45 | INNER JOIN ' . $wpdb->prefix . 'events_attendee AS att ON ans.attendee_id = att.id |
46 | 46 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id = e.id |
47 | 47 | WHERE e.event_status !="D"'; |
48 | - $this->_new_answer_table = $wpdb->prefix."esp_answer"; |
|
49 | - $this->_new_question_table = $wpdb->prefix."esp_question"; |
|
50 | - parent::__construct(); |
|
51 | - } |
|
52 | - protected function _migrate_old_row($old_row) |
|
53 | - { |
|
54 | - // get the new REGs for the old answer |
|
55 | - global $wpdb; |
|
56 | - $old_attendee_table = $wpdb->prefix."events_attendee"; |
|
57 | - $new_reg_table = $wpdb->prefix."esp_registration"; |
|
58 | - $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table); |
|
59 | - if (! $regs) { |
|
60 | - $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row))); |
|
61 | - return false; |
|
62 | - } |
|
63 | - // as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee) |
|
64 | - foreach ($regs as $new_reg_id) { |
|
65 | - $new_answer_id = $this->_insert_new_answer($old_row, $new_reg_id); |
|
66 | - } |
|
67 | - } |
|
68 | - /** |
|
69 | - * Creates a 4.1 price base type |
|
70 | - * @global type $wpdb |
|
71 | - * @param array $old_price |
|
72 | - * @param int $new_reg_id |
|
73 | - * @return int |
|
74 | - */ |
|
75 | - private function _insert_new_answer($old_answer, $new_reg_id) |
|
76 | - { |
|
77 | - global $wpdb; |
|
78 | - $old_question_table = $wpdb->prefix."events_question"; |
|
79 | - $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table); |
|
48 | + $this->_new_answer_table = $wpdb->prefix."esp_answer"; |
|
49 | + $this->_new_question_table = $wpdb->prefix."esp_question"; |
|
50 | + parent::__construct(); |
|
51 | + } |
|
52 | + protected function _migrate_old_row($old_row) |
|
53 | + { |
|
54 | + // get the new REGs for the old answer |
|
55 | + global $wpdb; |
|
56 | + $old_attendee_table = $wpdb->prefix."events_attendee"; |
|
57 | + $new_reg_table = $wpdb->prefix."esp_registration"; |
|
58 | + $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table); |
|
59 | + if (! $regs) { |
|
60 | + $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row))); |
|
61 | + return false; |
|
62 | + } |
|
63 | + // as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee) |
|
64 | + foreach ($regs as $new_reg_id) { |
|
65 | + $new_answer_id = $this->_insert_new_answer($old_row, $new_reg_id); |
|
66 | + } |
|
67 | + } |
|
68 | + /** |
|
69 | + * Creates a 4.1 price base type |
|
70 | + * @global type $wpdb |
|
71 | + * @param array $old_price |
|
72 | + * @param int $new_reg_id |
|
73 | + * @return int |
|
74 | + */ |
|
75 | + private function _insert_new_answer($old_answer, $new_reg_id) |
|
76 | + { |
|
77 | + global $wpdb; |
|
78 | + $old_question_table = $wpdb->prefix."events_question"; |
|
79 | + $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table); |
|
80 | 80 | |
81 | - $question_type = $this->_get_question_type($new_question_id); |
|
82 | - if (in_array($question_type, array('MULTIPLE'))) { |
|
83 | - $ans_value = serialize(explode(",", stripslashes($old_answer['answer']))); |
|
84 | - } else { |
|
85 | - $ans_value = stripslashes($old_answer['answer']); |
|
86 | - } |
|
87 | - $cols_n_values = array( |
|
88 | - 'REG_ID'=>$new_reg_id, |
|
89 | - 'QST_ID'=>$new_question_id, |
|
90 | - 'ANS_value'=>$ans_value |
|
91 | - ); |
|
92 | - $datatypes = array( |
|
93 | - '%d',// REG_ID |
|
94 | - '%d',// QST_ID |
|
95 | - '%s',// ANS_value |
|
96 | - ); |
|
97 | - $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes); |
|
98 | - if (! $success) { |
|
99 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes)); |
|
100 | - return 0; |
|
101 | - } |
|
102 | - $new_id = $wpdb->insert_id; |
|
103 | - return $new_id; |
|
104 | - } |
|
81 | + $question_type = $this->_get_question_type($new_question_id); |
|
82 | + if (in_array($question_type, array('MULTIPLE'))) { |
|
83 | + $ans_value = serialize(explode(",", stripslashes($old_answer['answer']))); |
|
84 | + } else { |
|
85 | + $ans_value = stripslashes($old_answer['answer']); |
|
86 | + } |
|
87 | + $cols_n_values = array( |
|
88 | + 'REG_ID'=>$new_reg_id, |
|
89 | + 'QST_ID'=>$new_question_id, |
|
90 | + 'ANS_value'=>$ans_value |
|
91 | + ); |
|
92 | + $datatypes = array( |
|
93 | + '%d',// REG_ID |
|
94 | + '%d',// QST_ID |
|
95 | + '%s',// ANS_value |
|
96 | + ); |
|
97 | + $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes); |
|
98 | + if (! $success) { |
|
99 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes)); |
|
100 | + return 0; |
|
101 | + } |
|
102 | + $new_id = $wpdb->insert_id; |
|
103 | + return $new_id; |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Gets the question's type |
|
108 | - * @global type $wpdb |
|
109 | - * @param type $question_id |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - private function _get_question_type($question_id) |
|
113 | - { |
|
114 | - global $wpdb; |
|
115 | - $type = $wpdb->get_var($wpdb->prepare("SELECT QST_type FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1", $question_id)); |
|
116 | - return $type; |
|
117 | - } |
|
106 | + /** |
|
107 | + * Gets the question's type |
|
108 | + * @global type $wpdb |
|
109 | + * @param type $question_id |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + private function _get_question_type($question_id) |
|
113 | + { |
|
114 | + global $wpdb; |
|
115 | + $type = $wpdb->get_var($wpdb->prepare("SELECT QST_type FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1", $question_id)); |
|
116 | + return $type; |
|
117 | + } |
|
118 | 118 | } |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | // join to attendee and then join to events table |
43 | 43 | $this->select_expression = 'ans.*, e.event_status'; |
44 | 44 | $this->_extra_where_sql = ' AS ans |
45 | - INNER JOIN ' . $wpdb->prefix . 'events_attendee AS att ON ans.attendee_id = att.id |
|
46 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id = e.id |
|
45 | + INNER JOIN ' . $wpdb->prefix.'events_attendee AS att ON ans.attendee_id = att.id |
|
46 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id = e.id |
|
47 | 47 | WHERE e.event_status !="D"'; |
48 | 48 | $this->_new_answer_table = $wpdb->prefix."esp_answer"; |
49 | 49 | $this->_new_question_table = $wpdb->prefix."esp_question"; |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | $old_attendee_table = $wpdb->prefix."events_attendee"; |
57 | 57 | $new_reg_table = $wpdb->prefix."esp_registration"; |
58 | 58 | $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table); |
59 | - if (! $regs) { |
|
59 | + if ( ! $regs) { |
|
60 | 60 | $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row))); |
61 | 61 | return false; |
62 | 62 | } |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | 'ANS_value'=>$ans_value |
91 | 91 | ); |
92 | 92 | $datatypes = array( |
93 | - '%d',// REG_ID |
|
94 | - '%d',// QST_ID |
|
95 | - '%s',// ANS_value |
|
93 | + '%d', // REG_ID |
|
94 | + '%d', // QST_ID |
|
95 | + '%s', // ANS_value |
|
96 | 96 | ); |
97 | 97 | $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes); |
98 | - if (! $success) { |
|
98 | + if ( ! $success) { |
|
99 | 99 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes)); |
100 | 100 | return 0; |
101 | 101 | } |
@@ -26,160 +26,160 @@ |
||
26 | 26 | |
27 | 27 | class EE_DMS_4_1_0_checkins extends EE_Data_Migration_Script_Stage_Table |
28 | 28 | { |
29 | - private $_new_table; |
|
30 | - public function __construct() |
|
31 | - { |
|
32 | - global $wpdb; |
|
33 | - $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
|
34 | - $this->_old_table = $wpdb->prefix."events_attendee"; |
|
35 | - $this->select_expression = 'att.*, e.event_status'; |
|
36 | - $this->_extra_where_sql = 'AS att |
|
29 | + private $_new_table; |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + global $wpdb; |
|
33 | + $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
|
34 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
35 | + $this->select_expression = 'att.*, e.event_status'; |
|
36 | + $this->_extra_where_sql = 'AS att |
|
37 | 37 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
38 | 38 | WHERE e.event_status!="D"'; |
39 | - $this->_new_table = $wpdb->prefix."esp_checkin"; |
|
40 | - parent::__construct(); |
|
41 | - } |
|
42 | - protected function _migrate_old_row($old_row) |
|
43 | - { |
|
44 | - global $wpdb; |
|
45 | - $new_reg_table = $wpdb->prefix."esp_registration"; |
|
39 | + $this->_new_table = $wpdb->prefix."esp_checkin"; |
|
40 | + parent::__construct(); |
|
41 | + } |
|
42 | + protected function _migrate_old_row($old_row) |
|
43 | + { |
|
44 | + global $wpdb; |
|
45 | + $new_reg_table = $wpdb->prefix."esp_registration"; |
|
46 | 46 | |
47 | - $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
47 | + $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
48 | 48 | |
49 | - $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
50 | - if (! $new_registrations_for_attendee) { |
|
51 | - $new_registrations_for_attendee = array(); |
|
52 | - } |
|
53 | - $new_datetime = $this->_try_to_find_datetime($old_row); |
|
49 | + $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
50 | + if (! $new_registrations_for_attendee) { |
|
51 | + $new_registrations_for_attendee = array(); |
|
52 | + } |
|
53 | + $new_datetime = $this->_try_to_find_datetime($old_row); |
|
54 | 54 | |
55 | - // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
56 | - $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
57 | - $new_checkin_ids = array(); |
|
58 | - for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
59 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
60 | - if (! $new_reg_id) { |
|
61 | - $this->add_error(sprintf( |
|
62 | - esc_html__( |
|
63 | - /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
|
55 | + // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
56 | + $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
57 | + $new_checkin_ids = array(); |
|
58 | + for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
59 | + $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
60 | + if (! $new_reg_id) { |
|
61 | + $this->add_error(sprintf( |
|
62 | + esc_html__( |
|
63 | + /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
|
64 | 64 | * %3$s number of registrations for the attendee, %4$s new registration rows represented in JSON |
65 | 65 | */ |
66 | - // @codingStandardsIgnoreStart |
|
67 | - 'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', |
|
68 | - // @codingStandardsIgnoreEnd |
|
69 | - 'event_espresso' |
|
70 | - ), |
|
71 | - $this->_json_encode($old_row), |
|
72 | - abs($num_to_checkin_at_this_time), |
|
73 | - count($new_registrations_for_attendee), |
|
74 | - $this->_json_encode($new_registrations_for_attendee) |
|
75 | - )); |
|
76 | - break; |
|
77 | - } |
|
78 | - $existing_checkin_record = $wpdb->get_var( |
|
79 | - $wpdb->prepare( |
|
80 | - "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
81 | - $new_reg_id |
|
82 | - ) |
|
83 | - ); |
|
84 | - if (! $existing_checkin_record) { |
|
85 | - $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
86 | - if ($new_id) { |
|
87 | - $new_checkin_ids[]= $new_id; |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
91 | - if ($new_checkin_ids) { |
|
92 | - $this->get_migration_script()->set_mapping( |
|
93 | - $this->_old_table, |
|
94 | - $old_row['id'], |
|
95 | - $this->_new_table, |
|
96 | - $new_checkin_ids |
|
97 | - ); |
|
98 | - } |
|
99 | - } |
|
66 | + // @codingStandardsIgnoreStart |
|
67 | + 'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', |
|
68 | + // @codingStandardsIgnoreEnd |
|
69 | + 'event_espresso' |
|
70 | + ), |
|
71 | + $this->_json_encode($old_row), |
|
72 | + abs($num_to_checkin_at_this_time), |
|
73 | + count($new_registrations_for_attendee), |
|
74 | + $this->_json_encode($new_registrations_for_attendee) |
|
75 | + )); |
|
76 | + break; |
|
77 | + } |
|
78 | + $existing_checkin_record = $wpdb->get_var( |
|
79 | + $wpdb->prepare( |
|
80 | + "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
81 | + $new_reg_id |
|
82 | + ) |
|
83 | + ); |
|
84 | + if (! $existing_checkin_record) { |
|
85 | + $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
86 | + if ($new_id) { |
|
87 | + $new_checkin_ids[]= $new_id; |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | + if ($new_checkin_ids) { |
|
92 | + $this->get_migration_script()->set_mapping( |
|
93 | + $this->_old_table, |
|
94 | + $old_row['id'], |
|
95 | + $this->_new_table, |
|
96 | + $new_checkin_ids |
|
97 | + ); |
|
98 | + } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | |
102 | - /** |
|
103 | - * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
104 | - * (because we know the attendee was for an event as a specific time, and we know |
|
105 | - * the event's OLD ID...) |
|
106 | - * @global type $wpdb |
|
107 | - * @param array $old_attendee_row |
|
108 | - * @return array row of datetime from DB |
|
109 | - */ |
|
110 | - private function _try_to_find_datetime($old_attendee) |
|
111 | - { |
|
112 | - global $wpdb; |
|
102 | + /** |
|
103 | + * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
104 | + * (because we know the attendee was for an event as a specific time, and we know |
|
105 | + * the event's OLD ID...) |
|
106 | + * @global type $wpdb |
|
107 | + * @param array $old_attendee_row |
|
108 | + * @return array row of datetime from DB |
|
109 | + */ |
|
110 | + private function _try_to_find_datetime($old_attendee) |
|
111 | + { |
|
112 | + global $wpdb; |
|
113 | 113 | |
114 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
115 | - if (! $new_event_id) { |
|
116 | - $this->add_error( |
|
117 | - sprintf( |
|
118 | - esc_html__( |
|
119 | - /* translators: 1: original event ID, 2: original attendee database row */ |
|
120 | - // @codingStandardsIgnoreStart |
|
121 | - 'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in', |
|
122 | - // @codingStandardsIgnoreEnd |
|
123 | - 'event_espresso' |
|
124 | - ), |
|
125 | - $old_attendee['event_id'], |
|
126 | - $this->_json_encode($old_attendee) |
|
127 | - ) |
|
128 | - ); |
|
129 | - return 0; |
|
130 | - } |
|
131 | - $old_att_start_date = $old_attendee['start_date']; |
|
132 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
133 | - $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
114 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
115 | + if (! $new_event_id) { |
|
116 | + $this->add_error( |
|
117 | + sprintf( |
|
118 | + esc_html__( |
|
119 | + /* translators: 1: original event ID, 2: original attendee database row */ |
|
120 | + // @codingStandardsIgnoreStart |
|
121 | + 'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in', |
|
122 | + // @codingStandardsIgnoreEnd |
|
123 | + 'event_espresso' |
|
124 | + ), |
|
125 | + $old_attendee['event_id'], |
|
126 | + $this->_json_encode($old_attendee) |
|
127 | + ) |
|
128 | + ); |
|
129 | + return 0; |
|
130 | + } |
|
131 | + $old_att_start_date = $old_attendee['start_date']; |
|
132 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
133 | + $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
134 | 134 | |
135 | - $datetime_table = $wpdb->prefix."esp_datetime"; |
|
136 | - // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
137 | - // the most important condition should be last, as it will be array_shift'ed off last |
|
138 | - $conditions = array( |
|
139 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
140 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
141 | - ); |
|
142 | - // start running queries, widening search each time by removing a condition |
|
143 | - $datetime_found = null; |
|
144 | - do { |
|
145 | - $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
146 | - $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
147 | - array_shift($conditions); |
|
148 | - } while (! $datetime_found && $conditions); |
|
149 | - return $datetime_found; |
|
150 | - } |
|
135 | + $datetime_table = $wpdb->prefix."esp_datetime"; |
|
136 | + // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
137 | + // the most important condition should be last, as it will be array_shift'ed off last |
|
138 | + $conditions = array( |
|
139 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
140 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
141 | + ); |
|
142 | + // start running queries, widening search each time by removing a condition |
|
143 | + $datetime_found = null; |
|
144 | + do { |
|
145 | + $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
146 | + $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
147 | + array_shift($conditions); |
|
148 | + } while (! $datetime_found && $conditions); |
|
149 | + return $datetime_found; |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
|
154 | - * @param int $new_reg_id |
|
155 | - * @param int $new_datetime_id |
|
156 | - * @param string $timestamp mysql datetime |
|
157 | - * @return int new Check-in id |
|
158 | - */ |
|
159 | - private function _insert_checkin_record($new_reg_id, $new_datetime) |
|
160 | - { |
|
161 | - global $wpdb; |
|
152 | + /** |
|
153 | + * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
|
154 | + * @param int $new_reg_id |
|
155 | + * @param int $new_datetime_id |
|
156 | + * @param string $timestamp mysql datetime |
|
157 | + * @return int new Check-in id |
|
158 | + */ |
|
159 | + private function _insert_checkin_record($new_reg_id, $new_datetime) |
|
160 | + { |
|
161 | + global $wpdb; |
|
162 | 162 | |
163 | 163 | |
164 | - // ok we can actually do what we set out to do: add a checkin/checkout record |
|
165 | - $cols_n_values = array( |
|
166 | - 'REG_ID'=>$new_reg_id, |
|
167 | - 'DTT_ID'=>$new_datetime['DTT_ID'], |
|
168 | - 'CHK_in'=>true, |
|
169 | - 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
|
170 | - ); |
|
171 | - $datatypes = array( |
|
172 | - '%d',// REG_ID |
|
173 | - '%d',// DTT_ID |
|
174 | - '%d',// CHK_in |
|
175 | - '%s',// CHK_timestamp |
|
176 | - ); |
|
177 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
178 | - if (! $success) { |
|
179 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
|
180 | - return 0; |
|
181 | - } |
|
182 | - $new_id = $wpdb->insert_id; |
|
183 | - return $new_id; |
|
184 | - } |
|
164 | + // ok we can actually do what we set out to do: add a checkin/checkout record |
|
165 | + $cols_n_values = array( |
|
166 | + 'REG_ID'=>$new_reg_id, |
|
167 | + 'DTT_ID'=>$new_datetime['DTT_ID'], |
|
168 | + 'CHK_in'=>true, |
|
169 | + 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
|
170 | + ); |
|
171 | + $datatypes = array( |
|
172 | + '%d',// REG_ID |
|
173 | + '%d',// DTT_ID |
|
174 | + '%d',// CHK_in |
|
175 | + '%s',// CHK_timestamp |
|
176 | + ); |
|
177 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
178 | + if (! $success) { |
|
179 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
|
180 | + return 0; |
|
181 | + } |
|
182 | + $new_id = $wpdb->insert_id; |
|
183 | + return $new_id; |
|
184 | + } |
|
185 | 185 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | $this->_old_table = $wpdb->prefix."events_attendee"; |
35 | 35 | $this->select_expression = 'att.*, e.event_status'; |
36 | 36 | $this->_extra_where_sql = 'AS att |
37 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
37 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
38 | 38 | WHERE e.event_status!="D"'; |
39 | 39 | $this->_new_table = $wpdb->prefix."esp_checkin"; |
40 | 40 | parent::__construct(); |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | global $wpdb; |
45 | 45 | $new_reg_table = $wpdb->prefix."esp_registration"; |
46 | 46 | |
47 | - $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
47 | + $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']), intval($old_row['checked_in']))); |
|
48 | 48 | |
49 | 49 | $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
50 | - if (! $new_registrations_for_attendee) { |
|
50 | + if ( ! $new_registrations_for_attendee) { |
|
51 | 51 | $new_registrations_for_attendee = array(); |
52 | 52 | } |
53 | 53 | $new_datetime = $this->_try_to_find_datetime($old_row); |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
56 | 56 | $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
57 | 57 | $new_checkin_ids = array(); |
58 | - for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
59 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
60 | - if (! $new_reg_id) { |
|
58 | + for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
|
59 | + $new_reg_id = $new_registrations_for_attendee[$i]; |
|
60 | + if ( ! $new_reg_id) { |
|
61 | 61 | $this->add_error(sprintf( |
62 | 62 | esc_html__( |
63 | 63 | /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | $new_reg_id |
82 | 82 | ) |
83 | 83 | ); |
84 | - if (! $existing_checkin_record) { |
|
84 | + if ( ! $existing_checkin_record) { |
|
85 | 85 | $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
86 | 86 | if ($new_id) { |
87 | - $new_checkin_ids[]= $new_id; |
|
87 | + $new_checkin_ids[] = $new_id; |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | global $wpdb; |
113 | 113 | |
114 | 114 | $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
115 | - if (! $new_event_id) { |
|
115 | + if ( ! $new_event_id) { |
|
116 | 116 | $this->add_error( |
117 | 117 | sprintf( |
118 | 118 | esc_html__( |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
137 | 137 | // the most important condition should be last, as it will be array_shift'ed off last |
138 | 138 | $conditions = array( |
139 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
140 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
139 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match? |
|
140 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match? |
|
141 | 141 | ); |
142 | 142 | // start running queries, widening search each time by removing a condition |
143 | 143 | $datetime_found = null; |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
146 | 146 | $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
147 | 147 | array_shift($conditions); |
148 | - } while (! $datetime_found && $conditions); |
|
148 | + }while ( ! $datetime_found && $conditions); |
|
149 | 149 | return $datetime_found; |
150 | 150 | } |
151 | 151 | |
@@ -169,13 +169,13 @@ discard block |
||
169 | 169 | 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
170 | 170 | ); |
171 | 171 | $datatypes = array( |
172 | - '%d',// REG_ID |
|
173 | - '%d',// DTT_ID |
|
174 | - '%d',// CHK_in |
|
175 | - '%s',// CHK_timestamp |
|
172 | + '%d', // REG_ID |
|
173 | + '%d', // DTT_ID |
|
174 | + '%d', // CHK_in |
|
175 | + '%s', // CHK_timestamp |
|
176 | 176 | ); |
177 | 177 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
178 | - if (! $success) { |
|
178 | + if ( ! $success) { |
|
179 | 179 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
180 | 180 | return 0; |
181 | 181 | } |
@@ -38,172 +38,172 @@ |
||
38 | 38 | */ |
39 | 39 | class EE_DMS_4_1_0_line_items extends EE_Data_Migration_Script_Stage_Table |
40 | 40 | { |
41 | - private $_new_line_table; |
|
42 | - private $_new_transaction_table; |
|
43 | - private $_new_reg_table; |
|
44 | - public function __construct() |
|
45 | - { |
|
46 | - global $wpdb; |
|
47 | - $this->_pretty_name = __("Line Items", "event_espresso"); |
|
48 | - $this->_old_table = $wpdb->prefix."events_attendee"; |
|
49 | - $this->select_expression = 'att.*, e.event_status'; |
|
50 | - $this->_extra_where_sql = ' AS att |
|
41 | + private $_new_line_table; |
|
42 | + private $_new_transaction_table; |
|
43 | + private $_new_reg_table; |
|
44 | + public function __construct() |
|
45 | + { |
|
46 | + global $wpdb; |
|
47 | + $this->_pretty_name = __("Line Items", "event_espresso"); |
|
48 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
49 | + $this->select_expression = 'att.*, e.event_status'; |
|
50 | + $this->_extra_where_sql = ' AS att |
|
51 | 51 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
52 | 52 | WHERE e.event_status!="D"'; |
53 | - $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
|
54 | - $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
|
55 | - $this->_new_reg_table = $wpdb->prefix."esp_registration"; |
|
56 | - parent::__construct(); |
|
57 | - } |
|
53 | + $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
|
54 | + $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
|
55 | + $this->_new_reg_table = $wpdb->prefix."esp_registration"; |
|
56 | + parent::__construct(); |
|
57 | + } |
|
58 | 58 | |
59 | - protected function _migrate_old_row($old_row) |
|
60 | - { |
|
61 | - // insert line items if its a primary id |
|
62 | - if (intval($old_row['is_primary'])) { |
|
63 | - $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table); |
|
64 | - if (! $txn_id) { |
|
65 | - $this->add_error(sprintf(__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"), $old_row['id'], $this->_json_encode($old_row))); |
|
66 | - return; |
|
67 | - } |
|
68 | - $txn = $this->_get_txn($txn_id); |
|
69 | - $new_line_items = $this->_insert_new_line_items($txn, $old_row); |
|
70 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_line_table, $new_line_items); |
|
71 | - } |
|
72 | - } |
|
59 | + protected function _migrate_old_row($old_row) |
|
60 | + { |
|
61 | + // insert line items if its a primary id |
|
62 | + if (intval($old_row['is_primary'])) { |
|
63 | + $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table); |
|
64 | + if (! $txn_id) { |
|
65 | + $this->add_error(sprintf(__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"), $old_row['id'], $this->_json_encode($old_row))); |
|
66 | + return; |
|
67 | + } |
|
68 | + $txn = $this->_get_txn($txn_id); |
|
69 | + $new_line_items = $this->_insert_new_line_items($txn, $old_row); |
|
70 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_line_table, $new_line_items); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - private function _get_txn($txn_id) |
|
75 | - { |
|
76 | - global $wpdb; |
|
77 | - $txn = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_transaction_table WHERE TXN_ID=%d", $txn_id), ARRAY_A); |
|
78 | - return $txn; |
|
79 | - } |
|
74 | + private function _get_txn($txn_id) |
|
75 | + { |
|
76 | + global $wpdb; |
|
77 | + $txn = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_transaction_table WHERE TXN_ID=%d", $txn_id), ARRAY_A); |
|
78 | + return $txn; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * In 4.1, we'd normally need more info than just the registrations to make the line items. Ie, we'd need |
|
83 | - * the transaction, and tax prices at the time of registration. (And probably promotions and other price factors). |
|
84 | - * But seeing how these are REGs created from 3.1 attendee data, which have |
|
85 | - * @param array $transaction |
|
86 | - * @return array new line item ids |
|
87 | - */ |
|
88 | - private function _insert_new_line_items($transaction, $old_attendee) |
|
89 | - { |
|
90 | - global $wpdb; |
|
91 | - $regs_on_this_transaction = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_new_reg_table." WHERE TXN_ID=%d", $transaction['TXN_ID']), ARRAY_A); |
|
92 | - $new_line_item_ids = array(); |
|
93 | - // create a totla line item |
|
94 | - $total_line_item_id = $this->_insert_new_line_item(array( |
|
95 | - 'LIN_code'=>'total', |
|
96 | - 'TXN_ID'=>$transaction['TXN_ID'], |
|
97 | - 'LIN_name'=> __("Total", "event_espresso"), |
|
98 | - 'LIN_total'=>$transaction['TXN_total'], |
|
99 | - 'LIN_type'=>'total', |
|
100 | - 'OBJ_ID'=>$transaction['TXN_ID'], |
|
101 | - 'OBJ_type'=>'Transaction' |
|
102 | - ), $old_attendee); |
|
103 | - $new_line_item_ids[] = $total_line_item_id; |
|
104 | - // create a subtotal line item |
|
105 | - $reg_total = 0; |
|
106 | - foreach ($regs_on_this_transaction as $new_reg) { |
|
107 | - $reg_total += floatval($new_reg['REG_final_price']); |
|
108 | - } |
|
109 | - $subtotal_line_item_id = $this->_insert_new_line_item(array( |
|
110 | - 'LIN_code'=>'sub-total', |
|
111 | - 'TXN_ID'=>$transaction['TXN_ID'], |
|
112 | - 'LIN_name'=> __("Subtotal", "event_espresso"), |
|
113 | - 'LIN_total'=>$reg_total, |
|
114 | - 'LIN_parent'=>$total_line_item_id, |
|
115 | - 'LIN_type'=>'sub-total', |
|
116 | - ), $old_attendee); |
|
117 | - $new_line_item_ids[] = $subtotal_line_item_id; |
|
118 | - // group REGs by TKT_ID |
|
119 | - $regs_by_tkt = array(); |
|
120 | - foreach ($regs_on_this_transaction as $new_reg) { |
|
121 | - $regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg; |
|
122 | - } |
|
81 | + /** |
|
82 | + * In 4.1, we'd normally need more info than just the registrations to make the line items. Ie, we'd need |
|
83 | + * the transaction, and tax prices at the time of registration. (And probably promotions and other price factors). |
|
84 | + * But seeing how these are REGs created from 3.1 attendee data, which have |
|
85 | + * @param array $transaction |
|
86 | + * @return array new line item ids |
|
87 | + */ |
|
88 | + private function _insert_new_line_items($transaction, $old_attendee) |
|
89 | + { |
|
90 | + global $wpdb; |
|
91 | + $regs_on_this_transaction = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_new_reg_table." WHERE TXN_ID=%d", $transaction['TXN_ID']), ARRAY_A); |
|
92 | + $new_line_item_ids = array(); |
|
93 | + // create a totla line item |
|
94 | + $total_line_item_id = $this->_insert_new_line_item(array( |
|
95 | + 'LIN_code'=>'total', |
|
96 | + 'TXN_ID'=>$transaction['TXN_ID'], |
|
97 | + 'LIN_name'=> __("Total", "event_espresso"), |
|
98 | + 'LIN_total'=>$transaction['TXN_total'], |
|
99 | + 'LIN_type'=>'total', |
|
100 | + 'OBJ_ID'=>$transaction['TXN_ID'], |
|
101 | + 'OBJ_type'=>'Transaction' |
|
102 | + ), $old_attendee); |
|
103 | + $new_line_item_ids[] = $total_line_item_id; |
|
104 | + // create a subtotal line item |
|
105 | + $reg_total = 0; |
|
106 | + foreach ($regs_on_this_transaction as $new_reg) { |
|
107 | + $reg_total += floatval($new_reg['REG_final_price']); |
|
108 | + } |
|
109 | + $subtotal_line_item_id = $this->_insert_new_line_item(array( |
|
110 | + 'LIN_code'=>'sub-total', |
|
111 | + 'TXN_ID'=>$transaction['TXN_ID'], |
|
112 | + 'LIN_name'=> __("Subtotal", "event_espresso"), |
|
113 | + 'LIN_total'=>$reg_total, |
|
114 | + 'LIN_parent'=>$total_line_item_id, |
|
115 | + 'LIN_type'=>'sub-total', |
|
116 | + ), $old_attendee); |
|
117 | + $new_line_item_ids[] = $subtotal_line_item_id; |
|
118 | + // group REGs by TKT_ID |
|
119 | + $regs_by_tkt = array(); |
|
120 | + foreach ($regs_on_this_transaction as $new_reg) { |
|
121 | + $regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg; |
|
122 | + } |
|
123 | 123 | |
124 | - // create individual line items |
|
124 | + // create individual line items |
|
125 | 125 | |
126 | - foreach ($regs_by_tkt as $ticket_id => $regs) { |
|
127 | - $count = count($regs); |
|
128 | - $line_total = 0; |
|
129 | - foreach ($regs as $new_reg) { |
|
130 | - $line_total += $new_reg['REG_final_price']; |
|
131 | - } |
|
132 | - $a_reg = reset($regs); |
|
133 | - $new_ticket = $this->_get_new_ticket_row($a_reg['TKT_ID']); |
|
134 | - $reg_line_item_id = $this->_insert_new_line_item(array( |
|
135 | - 'LIN_code'=> md5('Ticket' . $ticket_id . time()), |
|
136 | - 'TXN_ID'=>$transaction['TXN_ID'], |
|
137 | - 'LIN_name'=>$new_ticket['TKT_name'], |
|
138 | - 'LIN_unit_price'=>$a_reg['REG_final_price'], |
|
139 | - 'LIN_is_taxable'=>false, |
|
140 | - 'LIN_total'=>$line_total, |
|
141 | - 'LIN_quantity'=>$count, |
|
142 | - 'LIN_parent'=>$subtotal_line_item_id, |
|
143 | - 'OBJ_ID'=>$ticket_id, |
|
144 | - 'OBJ_type'=>'Ticket' |
|
145 | - ), $old_attendee); |
|
146 | - $new_line_item_ids[] = $reg_line_item_id; |
|
147 | - } |
|
126 | + foreach ($regs_by_tkt as $ticket_id => $regs) { |
|
127 | + $count = count($regs); |
|
128 | + $line_total = 0; |
|
129 | + foreach ($regs as $new_reg) { |
|
130 | + $line_total += $new_reg['REG_final_price']; |
|
131 | + } |
|
132 | + $a_reg = reset($regs); |
|
133 | + $new_ticket = $this->_get_new_ticket_row($a_reg['TKT_ID']); |
|
134 | + $reg_line_item_id = $this->_insert_new_line_item(array( |
|
135 | + 'LIN_code'=> md5('Ticket' . $ticket_id . time()), |
|
136 | + 'TXN_ID'=>$transaction['TXN_ID'], |
|
137 | + 'LIN_name'=>$new_ticket['TKT_name'], |
|
138 | + 'LIN_unit_price'=>$a_reg['REG_final_price'], |
|
139 | + 'LIN_is_taxable'=>false, |
|
140 | + 'LIN_total'=>$line_total, |
|
141 | + 'LIN_quantity'=>$count, |
|
142 | + 'LIN_parent'=>$subtotal_line_item_id, |
|
143 | + 'OBJ_ID'=>$ticket_id, |
|
144 | + 'OBJ_type'=>'Ticket' |
|
145 | + ), $old_attendee); |
|
146 | + $new_line_item_ids[] = $reg_line_item_id; |
|
147 | + } |
|
148 | 148 | |
149 | 149 | |
150 | 150 | |
151 | - return $new_line_item_ids; |
|
152 | - } |
|
153 | - /** |
|
154 | - * Gets the full ticket by ID |
|
155 | - * @global type $wpdb |
|
156 | - * @param type $new_ticket_id |
|
157 | - * @return array |
|
158 | - */ |
|
159 | - private function _get_new_ticket_row($new_ticket_id) |
|
160 | - { |
|
161 | - global $wpdb; |
|
162 | - $ticket_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."esp_ticket WHERE TKT_ID=%d", $new_ticket_id), ARRAY_A); |
|
163 | - return $ticket_row; |
|
164 | - } |
|
151 | + return $new_line_item_ids; |
|
152 | + } |
|
153 | + /** |
|
154 | + * Gets the full ticket by ID |
|
155 | + * @global type $wpdb |
|
156 | + * @param type $new_ticket_id |
|
157 | + * @return array |
|
158 | + */ |
|
159 | + private function _get_new_ticket_row($new_ticket_id) |
|
160 | + { |
|
161 | + global $wpdb; |
|
162 | + $ticket_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."esp_ticket WHERE TKT_ID=%d", $new_ticket_id), ARRAY_A); |
|
163 | + return $ticket_row; |
|
164 | + } |
|
165 | 165 | |
166 | - private function _insert_new_line_item($cols_n_values, $old_attendee) |
|
167 | - { |
|
168 | - global $wpdb; |
|
169 | - $default_cols_n_values = array( |
|
170 | - 'LIN_code'=>'', |
|
171 | - 'TXN_ID'=>0, |
|
172 | - 'LIN_name'=>'', |
|
173 | - 'LIN_desc'=>'', |
|
174 | - 'LIN_unit_price'=>0, |
|
175 | - 'LIN_percent'=>0, |
|
176 | - 'LIN_is_taxable'=>false, |
|
177 | - 'LIN_order'=>0, |
|
178 | - 'LIN_total'=>0, |
|
179 | - 'LIN_quantity'=>null, |
|
180 | - 'LIN_parent'=>0, |
|
181 | - 'LIN_type'=>'line-item', |
|
182 | - 'OBJ_ID'=>null, |
|
183 | - 'OBJ_type'=>null |
|
184 | - ); |
|
185 | - $cols_n_values = array_merge($default_cols_n_values, $cols_n_values); |
|
186 | - $datatypes = array( |
|
187 | - '%s',// LIN_code |
|
188 | - '%d',// TXN_ID |
|
189 | - '%s',// LIN_name |
|
190 | - '%s',// LIN_desc |
|
191 | - '%f',// LIN_unit_price |
|
192 | - '%f',// LIN_percent |
|
193 | - '%d',// LIN_is_taxable |
|
194 | - '%d',// LIN_order |
|
195 | - '%f',// LIN_total |
|
196 | - '%d',// LIN_quantity |
|
197 | - '%d',// LIN_parent |
|
198 | - '%s',// LIN_type |
|
199 | - '%d',// OBJ_ID |
|
200 | - '%s',// OBJ_type |
|
201 | - ); |
|
202 | - $success = $wpdb->insert($this->_new_line_table, $cols_n_values, $datatypes); |
|
203 | - if (! $success) { |
|
204 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
|
205 | - return 0; |
|
206 | - } |
|
207 | - return $wpdb->insert_id; |
|
208 | - } |
|
166 | + private function _insert_new_line_item($cols_n_values, $old_attendee) |
|
167 | + { |
|
168 | + global $wpdb; |
|
169 | + $default_cols_n_values = array( |
|
170 | + 'LIN_code'=>'', |
|
171 | + 'TXN_ID'=>0, |
|
172 | + 'LIN_name'=>'', |
|
173 | + 'LIN_desc'=>'', |
|
174 | + 'LIN_unit_price'=>0, |
|
175 | + 'LIN_percent'=>0, |
|
176 | + 'LIN_is_taxable'=>false, |
|
177 | + 'LIN_order'=>0, |
|
178 | + 'LIN_total'=>0, |
|
179 | + 'LIN_quantity'=>null, |
|
180 | + 'LIN_parent'=>0, |
|
181 | + 'LIN_type'=>'line-item', |
|
182 | + 'OBJ_ID'=>null, |
|
183 | + 'OBJ_type'=>null |
|
184 | + ); |
|
185 | + $cols_n_values = array_merge($default_cols_n_values, $cols_n_values); |
|
186 | + $datatypes = array( |
|
187 | + '%s',// LIN_code |
|
188 | + '%d',// TXN_ID |
|
189 | + '%s',// LIN_name |
|
190 | + '%s',// LIN_desc |
|
191 | + '%f',// LIN_unit_price |
|
192 | + '%f',// LIN_percent |
|
193 | + '%d',// LIN_is_taxable |
|
194 | + '%d',// LIN_order |
|
195 | + '%f',// LIN_total |
|
196 | + '%d',// LIN_quantity |
|
197 | + '%d',// LIN_parent |
|
198 | + '%s',// LIN_type |
|
199 | + '%d',// OBJ_ID |
|
200 | + '%s',// OBJ_type |
|
201 | + ); |
|
202 | + $success = $wpdb->insert($this->_new_line_table, $cols_n_values, $datatypes); |
|
203 | + if (! $success) { |
|
204 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
|
205 | + return 0; |
|
206 | + } |
|
207 | + return $wpdb->insert_id; |
|
208 | + } |
|
209 | 209 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $this->_old_table = $wpdb->prefix."events_attendee"; |
49 | 49 | $this->select_expression = 'att.*, e.event_status'; |
50 | 50 | $this->_extra_where_sql = ' AS att |
51 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
51 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
52 | 52 | WHERE e.event_status!="D"'; |
53 | 53 | $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
54 | 54 | $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | // insert line items if its a primary id |
62 | 62 | if (intval($old_row['is_primary'])) { |
63 | 63 | $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table); |
64 | - if (! $txn_id) { |
|
64 | + if ( ! $txn_id) { |
|
65 | 65 | $this->add_error(sprintf(__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"), $old_row['id'], $this->_json_encode($old_row))); |
66 | 66 | return; |
67 | 67 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | // group REGs by TKT_ID |
119 | 119 | $regs_by_tkt = array(); |
120 | 120 | foreach ($regs_on_this_transaction as $new_reg) { |
121 | - $regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg; |
|
121 | + $regs_by_tkt[$new_reg['TKT_ID']][] = $new_reg; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | // create individual line items |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | $a_reg = reset($regs); |
133 | 133 | $new_ticket = $this->_get_new_ticket_row($a_reg['TKT_ID']); |
134 | 134 | $reg_line_item_id = $this->_insert_new_line_item(array( |
135 | - 'LIN_code'=> md5('Ticket' . $ticket_id . time()), |
|
135 | + 'LIN_code'=> md5('Ticket'.$ticket_id.time()), |
|
136 | 136 | 'TXN_ID'=>$transaction['TXN_ID'], |
137 | 137 | 'LIN_name'=>$new_ticket['TKT_name'], |
138 | 138 | 'LIN_unit_price'=>$a_reg['REG_final_price'], |
@@ -184,23 +184,23 @@ discard block |
||
184 | 184 | ); |
185 | 185 | $cols_n_values = array_merge($default_cols_n_values, $cols_n_values); |
186 | 186 | $datatypes = array( |
187 | - '%s',// LIN_code |
|
188 | - '%d',// TXN_ID |
|
189 | - '%s',// LIN_name |
|
190 | - '%s',// LIN_desc |
|
191 | - '%f',// LIN_unit_price |
|
192 | - '%f',// LIN_percent |
|
193 | - '%d',// LIN_is_taxable |
|
194 | - '%d',// LIN_order |
|
195 | - '%f',// LIN_total |
|
196 | - '%d',// LIN_quantity |
|
197 | - '%d',// LIN_parent |
|
198 | - '%s',// LIN_type |
|
199 | - '%d',// OBJ_ID |
|
200 | - '%s',// OBJ_type |
|
187 | + '%s', // LIN_code |
|
188 | + '%d', // TXN_ID |
|
189 | + '%s', // LIN_name |
|
190 | + '%s', // LIN_desc |
|
191 | + '%f', // LIN_unit_price |
|
192 | + '%f', // LIN_percent |
|
193 | + '%d', // LIN_is_taxable |
|
194 | + '%d', // LIN_order |
|
195 | + '%f', // LIN_total |
|
196 | + '%d', // LIN_quantity |
|
197 | + '%d', // LIN_parent |
|
198 | + '%s', // LIN_type |
|
199 | + '%d', // OBJ_ID |
|
200 | + '%s', // OBJ_type |
|
201 | 201 | ); |
202 | 202 | $success = $wpdb->insert($this->_new_line_table, $cols_n_values, $datatypes); |
203 | - if (! $success) { |
|
203 | + if ( ! $success) { |
|
204 | 204 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
205 | 205 | return 0; |
206 | 206 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | public function ticket_status($display = false, $remaining = null) |
130 | 130 | { |
131 | 131 | $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
132 | - if (! $remaining) { |
|
132 | + if ( ! $remaining) { |
|
133 | 133 | return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
134 | 134 | } |
135 | 135 | if ($this->get('TKT_deleted')) { |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | : ''; |
248 | 248 | $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $dt_frmt) : ''; |
249 | 249 | |
250 | - return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
250 | + return $first_date && $last_date ? $first_date.$conjunction.$last_date : ''; |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | */ |
275 | 275 | public function datetimes($query_params = array()) |
276 | 276 | { |
277 | - if (! isset($query_params['order_by'])) { |
|
277 | + if ( ! isset($query_params['order_by'])) { |
|
278 | 278 | $query_params['order_by']['DTT_order'] = 'ASC'; |
279 | 279 | } |
280 | 280 | return $this->get_many_related('Datetime', $query_params); |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | if (empty($tickets_sold['datetime'])) { |
320 | 320 | return $total; |
321 | 321 | } |
322 | - if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
322 | + if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) { |
|
323 | 323 | EE_Error::add_error( |
324 | 324 | __( |
325 | 325 | 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | ); |
332 | 332 | return $total; |
333 | 333 | } |
334 | - return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
334 | + return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id]; |
|
335 | 335 | break; |
336 | 336 | default: |
337 | 337 | return $total; |
@@ -349,9 +349,9 @@ discard block |
||
349 | 349 | { |
350 | 350 | $datetimes = $this->get_many_related('Datetime'); |
351 | 351 | $tickets_sold = array(); |
352 | - if (! empty($datetimes)) { |
|
352 | + if ( ! empty($datetimes)) { |
|
353 | 353 | foreach ($datetimes as $datetime) { |
354 | - $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
354 | + $tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold'); |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | // Tickets sold |
@@ -924,7 +924,7 @@ discard block |
||
924 | 924 | 'TKT_qty', |
925 | 925 | $qty |
926 | 926 | ); |
927 | - if (! $success) { |
|
927 | + if ( ! $success) { |
|
928 | 928 | // The datetimes were successfully bumped, but not the |
929 | 929 | // ticket. So we need to manually rollback the datetimes. |
930 | 930 | $this->decreaseReservedForDatetimes($qty); |
@@ -1373,7 +1373,7 @@ discard block |
||
1373 | 1373 | foreach ($this->datetimes() as $datetime) { |
1374 | 1374 | $times[] = $datetime->start_date_and_time(); |
1375 | 1375 | } |
1376 | - return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
1376 | + return $this->name().' @ '.implode(', ', $times).' for '.$this->pretty_price(); |
|
1377 | 1377 | } |
1378 | 1378 | |
1379 | 1379 | |
@@ -1472,7 +1472,7 @@ discard block |
||
1472 | 1472 | { |
1473 | 1473 | // get one datetime to use for getting the event |
1474 | 1474 | $datetime = $this->first_datetime(); |
1475 | - if (! $datetime instanceof \EE_Datetime) { |
|
1475 | + if ( ! $datetime instanceof \EE_Datetime) { |
|
1476 | 1476 | throw new UnexpectedEntityException( |
1477 | 1477 | $datetime, |
1478 | 1478 | 'EE_Datetime', |
@@ -1483,7 +1483,7 @@ discard block |
||
1483 | 1483 | ); |
1484 | 1484 | } |
1485 | 1485 | $event = $datetime->event(); |
1486 | - if (! $event instanceof \EE_Event) { |
|
1486 | + if ( ! $event instanceof \EE_Event) { |
|
1487 | 1487 | throw new UnexpectedEntityException( |
1488 | 1488 | $event, |
1489 | 1489 | 'EE_Event', |
@@ -14,1732 +14,1732 @@ |
||
14 | 14 | class EE_Ticket extends EE_Soft_Delete_Base_Class implements EEI_Line_Item_Object, EEI_Event_Relation, EEI_Has_Icon |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * The following constants are used by the ticket_status() method to indicate whether a ticket is on sale or not. |
|
19 | - */ |
|
20 | - const sold_out = 'TKS'; |
|
21 | - |
|
22 | - /** |
|
23 | - * |
|
24 | - */ |
|
25 | - const expired = 'TKE'; |
|
26 | - |
|
27 | - /** |
|
28 | - * |
|
29 | - */ |
|
30 | - const archived = 'TKA'; |
|
31 | - |
|
32 | - /** |
|
33 | - * |
|
34 | - */ |
|
35 | - const pending = 'TKP'; |
|
36 | - |
|
37 | - /** |
|
38 | - * |
|
39 | - */ |
|
40 | - const onsale = 'TKO'; |
|
41 | - |
|
42 | - /** |
|
43 | - * extra meta key for tracking ticket reservations |
|
44 | - * |
|
45 | - * @type string |
|
46 | - */ |
|
47 | - const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
|
48 | - |
|
49 | - /** |
|
50 | - * cached result from method of the same name |
|
51 | - * |
|
52 | - * @var float $_ticket_total_with_taxes |
|
53 | - */ |
|
54 | - private $_ticket_total_with_taxes; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @param array $props_n_values incoming values |
|
59 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
60 | - * used.) |
|
61 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
62 | - * date_format and the second value is the time format |
|
63 | - * @return EE_Ticket |
|
64 | - * @throws EE_Error |
|
65 | - */ |
|
66 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
67 | - { |
|
68 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
69 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param array $props_n_values incoming values from the database |
|
75 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
76 | - * the website will be used. |
|
77 | - * @return EE_Ticket |
|
78 | - * @throws EE_Error |
|
79 | - */ |
|
80 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
81 | - { |
|
82 | - return new self($props_n_values, true, $timezone); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @return bool |
|
88 | - * @throws EE_Error |
|
89 | - */ |
|
90 | - public function parent() |
|
91 | - { |
|
92 | - return $this->get('TKT_parent'); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * return if a ticket has quantities available for purchase |
|
98 | - * |
|
99 | - * @param int $DTT_ID the primary key for a particular datetime |
|
100 | - * @return boolean |
|
101 | - * @throws EE_Error |
|
102 | - */ |
|
103 | - public function available($DTT_ID = 0) |
|
104 | - { |
|
105 | - // are we checking availability for a particular datetime ? |
|
106 | - if ($DTT_ID) { |
|
107 | - // get that datetime object |
|
108 | - $datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID))); |
|
109 | - // if ticket sales for this datetime have exceeded the reg limit... |
|
110 | - if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
111 | - return false; |
|
112 | - } |
|
113 | - } |
|
114 | - // datetime is still open for registration, but is this ticket sold out ? |
|
115 | - return $this->qty() < 1 || $this->qty() > $this->sold() ? true : false; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
121 | - * |
|
122 | - * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
|
123 | - * relevant status const |
|
124 | - * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
|
125 | - * further processing |
|
126 | - * @return mixed status int if the display string isn't requested |
|
127 | - * @throws EE_Error |
|
128 | - */ |
|
129 | - public function ticket_status($display = false, $remaining = null) |
|
130 | - { |
|
131 | - $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
132 | - if (! $remaining) { |
|
133 | - return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
|
134 | - } |
|
135 | - if ($this->get('TKT_deleted')) { |
|
136 | - return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived; |
|
137 | - } |
|
138 | - if ($this->is_expired()) { |
|
139 | - return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired; |
|
140 | - } |
|
141 | - if ($this->is_pending()) { |
|
142 | - return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending; |
|
143 | - } |
|
144 | - if ($this->is_on_sale()) { |
|
145 | - return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale; |
|
146 | - } |
|
147 | - return ''; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
|
153 | - * considering ALL the factors used for figuring that out. |
|
154 | - * |
|
155 | - * @access public |
|
156 | - * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
157 | - * @return boolean true = tickets remaining, false not. |
|
158 | - * @throws EE_Error |
|
159 | - */ |
|
160 | - public function is_remaining($DTT_ID = 0) |
|
161 | - { |
|
162 | - $num_remaining = $this->remaining($DTT_ID); |
|
163 | - if ($num_remaining === 0) { |
|
164 | - return false; |
|
165 | - } |
|
166 | - if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
167 | - return false; |
|
168 | - } |
|
169 | - return true; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * return the total number of tickets available for purchase |
|
175 | - * |
|
176 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
177 | - * set to 0 for all related datetimes |
|
178 | - * @return int |
|
179 | - * @throws EE_Error |
|
180 | - */ |
|
181 | - public function remaining($DTT_ID = 0) |
|
182 | - { |
|
183 | - return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Gets min |
|
189 | - * |
|
190 | - * @return int |
|
191 | - * @throws EE_Error |
|
192 | - */ |
|
193 | - public function min() |
|
194 | - { |
|
195 | - return $this->get('TKT_min'); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * return if a ticket is no longer available cause its available dates have expired. |
|
201 | - * |
|
202 | - * @return boolean |
|
203 | - * @throws EE_Error |
|
204 | - */ |
|
205 | - public function is_expired() |
|
206 | - { |
|
207 | - return ($this->get_raw('TKT_end_date') < time()); |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * Return if a ticket is yet to go on sale or not |
|
213 | - * |
|
214 | - * @return boolean |
|
215 | - * @throws EE_Error |
|
216 | - */ |
|
217 | - public function is_pending() |
|
218 | - { |
|
219 | - return ($this->get_raw('TKT_start_date') > time()); |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * Return if a ticket is on sale or not |
|
225 | - * |
|
226 | - * @return boolean |
|
227 | - * @throws EE_Error |
|
228 | - */ |
|
229 | - public function is_on_sale() |
|
230 | - { |
|
231 | - return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time()); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * This returns the chronologically last datetime that this ticket is associated with |
|
237 | - * |
|
238 | - * @param string $dt_frmt |
|
239 | - * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
|
240 | - * the end date ie: Jan 01 "to" Dec 31 |
|
241 | - * @return string |
|
242 | - * @throws EE_Error |
|
243 | - */ |
|
244 | - public function date_range($dt_frmt = '', $conjunction = ' - ') |
|
245 | - { |
|
246 | - $dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt; |
|
247 | - $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->get_i18n_datetime('DTT_EVT_start', $dt_frmt) |
|
248 | - : ''; |
|
249 | - $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $dt_frmt) : ''; |
|
250 | - |
|
251 | - return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * This returns the chronologically first datetime that this ticket is associated with |
|
257 | - * |
|
258 | - * @return EE_Datetime |
|
259 | - * @throws EE_Error |
|
260 | - */ |
|
261 | - public function first_datetime() |
|
262 | - { |
|
263 | - $datetimes = $this->datetimes(array('limit' => 1)); |
|
264 | - return reset($datetimes); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * Gets all the datetimes this ticket can be used for attending. |
|
270 | - * Unless otherwise specified, orders datetimes by start date. |
|
271 | - * |
|
272 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
273 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
274 | - * @throws EE_Error |
|
275 | - */ |
|
276 | - public function datetimes($query_params = array()) |
|
277 | - { |
|
278 | - if (! isset($query_params['order_by'])) { |
|
279 | - $query_params['order_by']['DTT_order'] = 'ASC'; |
|
280 | - } |
|
281 | - return $this->get_many_related('Datetime', $query_params); |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * This returns the chronologically last datetime that this ticket is associated with |
|
287 | - * |
|
288 | - * @return EE_Datetime |
|
289 | - * @throws EE_Error |
|
290 | - */ |
|
291 | - public function last_datetime() |
|
292 | - { |
|
293 | - $datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC'))); |
|
294 | - return end($datetimes); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * This returns the total tickets sold depending on the given parameters. |
|
300 | - * |
|
301 | - * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
302 | - * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
303 | - * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
304 | - * 'datetime' = total ticket sales in the datetime_ticket table. |
|
305 | - * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
306 | - * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
307 | - * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
308 | - * @return mixed (array|int) how many tickets have sold |
|
309 | - * @throws EE_Error |
|
310 | - */ |
|
311 | - public function tickets_sold($what = 'ticket', $dtt_id = null) |
|
312 | - { |
|
313 | - $total = 0; |
|
314 | - $tickets_sold = $this->_all_tickets_sold(); |
|
315 | - switch ($what) { |
|
316 | - case 'ticket': |
|
317 | - return $tickets_sold['ticket']; |
|
318 | - break; |
|
319 | - case 'datetime': |
|
320 | - if (empty($tickets_sold['datetime'])) { |
|
321 | - return $total; |
|
322 | - } |
|
323 | - if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
324 | - EE_Error::add_error( |
|
325 | - __( |
|
326 | - 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
|
327 | - 'event_espresso' |
|
328 | - ), |
|
329 | - __FILE__, |
|
330 | - __FUNCTION__, |
|
331 | - __LINE__ |
|
332 | - ); |
|
333 | - return $total; |
|
334 | - } |
|
335 | - return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
336 | - break; |
|
337 | - default: |
|
338 | - return $total; |
|
339 | - } |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
345 | - * |
|
346 | - * @return EE_Ticket[] |
|
347 | - * @throws EE_Error |
|
348 | - */ |
|
349 | - protected function _all_tickets_sold() |
|
350 | - { |
|
351 | - $datetimes = $this->get_many_related('Datetime'); |
|
352 | - $tickets_sold = array(); |
|
353 | - if (! empty($datetimes)) { |
|
354 | - foreach ($datetimes as $datetime) { |
|
355 | - $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
356 | - } |
|
357 | - } |
|
358 | - // Tickets sold |
|
359 | - $tickets_sold['ticket'] = $this->sold(); |
|
360 | - return $tickets_sold; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * This returns the base price object for the ticket. |
|
366 | - * |
|
367 | - * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
368 | - * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
369 | - * @throws EE_Error |
|
370 | - */ |
|
371 | - public function base_price($return_array = false) |
|
372 | - { |
|
373 | - $_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price); |
|
374 | - return $return_array |
|
375 | - ? $this->get_many_related('Price', array($_where)) |
|
376 | - : $this->get_first_related('Price', array($_where)); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
382 | - * |
|
383 | - * @access public |
|
384 | - * @return EE_Price[] |
|
385 | - * @throws EE_Error |
|
386 | - */ |
|
387 | - public function price_modifiers() |
|
388 | - { |
|
389 | - $query_params = array( |
|
390 | - 0 => array( |
|
391 | - 'Price_Type.PBT_ID' => array( |
|
392 | - 'NOT IN', |
|
393 | - array(EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax), |
|
394 | - ), |
|
395 | - ), |
|
396 | - ); |
|
397 | - return $this->prices($query_params); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * Gets all the prices that combine to form the final price of this ticket |
|
403 | - * |
|
404 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
405 | - * @return EE_Price[]|EE_Base_Class[] |
|
406 | - * @throws EE_Error |
|
407 | - */ |
|
408 | - public function prices($query_params = array()) |
|
409 | - { |
|
410 | - return $this->get_many_related('Price', $query_params); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
|
416 | - * |
|
417 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
418 | - * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
419 | - * @throws EE_Error |
|
420 | - */ |
|
421 | - public function datetime_tickets($query_params = array()) |
|
422 | - { |
|
423 | - return $this->get_many_related('Datetime_Ticket', $query_params); |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * Gets all the datetimes from the db ordered by DTT_order |
|
429 | - * |
|
430 | - * @param boolean $show_expired |
|
431 | - * @param boolean $show_deleted |
|
432 | - * @return EE_Datetime[] |
|
433 | - * @throws EE_Error |
|
434 | - */ |
|
435 | - public function datetimes_ordered($show_expired = true, $show_deleted = false) |
|
436 | - { |
|
437 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order( |
|
438 | - $this->ID(), |
|
439 | - $show_expired, |
|
440 | - $show_deleted |
|
441 | - ); |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * Gets ID |
|
447 | - * |
|
448 | - * @return string |
|
449 | - * @throws EE_Error |
|
450 | - */ |
|
451 | - public function ID() |
|
452 | - { |
|
453 | - return $this->get('TKT_ID'); |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - /** |
|
458 | - * get the author of the ticket. |
|
459 | - * |
|
460 | - * @since 4.5.0 |
|
461 | - * @return int |
|
462 | - * @throws EE_Error |
|
463 | - */ |
|
464 | - public function wp_user() |
|
465 | - { |
|
466 | - return $this->get('TKT_wp_user'); |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * Gets the template for the ticket |
|
472 | - * |
|
473 | - * @return EE_Ticket_Template|EE_Base_Class |
|
474 | - * @throws EE_Error |
|
475 | - */ |
|
476 | - public function template() |
|
477 | - { |
|
478 | - return $this->get_first_related('Ticket_Template'); |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * Simply returns an array of EE_Price objects that are taxes. |
|
484 | - * |
|
485 | - * @return EE_Price[] |
|
486 | - * @throws EE_Error |
|
487 | - */ |
|
488 | - public function get_ticket_taxes_for_admin() |
|
489 | - { |
|
490 | - return EE_Taxes::get_taxes_for_admin(); |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * @return float |
|
496 | - * @throws EE_Error |
|
497 | - */ |
|
498 | - public function ticket_price() |
|
499 | - { |
|
500 | - return $this->get('TKT_price'); |
|
501 | - } |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * @return mixed |
|
506 | - * @throws EE_Error |
|
507 | - */ |
|
508 | - public function pretty_price() |
|
509 | - { |
|
510 | - return $this->get_pretty('TKT_price'); |
|
511 | - } |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * @return bool |
|
516 | - * @throws EE_Error |
|
517 | - */ |
|
518 | - public function is_free() |
|
519 | - { |
|
520 | - return $this->get_ticket_total_with_taxes() === (float) 0; |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * get_ticket_total_with_taxes |
|
526 | - * |
|
527 | - * @param bool $no_cache |
|
528 | - * @return float |
|
529 | - * @throws EE_Error |
|
530 | - */ |
|
531 | - public function get_ticket_total_with_taxes($no_cache = false) |
|
532 | - { |
|
533 | - if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
534 | - $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
|
535 | - } |
|
536 | - return (float) $this->_ticket_total_with_taxes; |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - public function ensure_TKT_Price_correct() |
|
541 | - { |
|
542 | - $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
543 | - $this->save(); |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * @return float |
|
549 | - * @throws EE_Error |
|
550 | - */ |
|
551 | - public function get_ticket_subtotal() |
|
552 | - { |
|
553 | - return EE_Taxes::get_subtotal_for_admin($this); |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * Returns the total taxes applied to this ticket |
|
559 | - * |
|
560 | - * @return float |
|
561 | - * @throws EE_Error |
|
562 | - */ |
|
563 | - public function get_ticket_taxes_total_for_admin() |
|
564 | - { |
|
565 | - return EE_Taxes::get_total_taxes_for_admin($this); |
|
566 | - } |
|
567 | - |
|
568 | - |
|
569 | - /** |
|
570 | - * Sets name |
|
571 | - * |
|
572 | - * @param string $name |
|
573 | - * @throws EE_Error |
|
574 | - */ |
|
575 | - public function set_name($name) |
|
576 | - { |
|
577 | - $this->set('TKT_name', $name); |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * Gets description |
|
583 | - * |
|
584 | - * @return string |
|
585 | - * @throws EE_Error |
|
586 | - */ |
|
587 | - public function description() |
|
588 | - { |
|
589 | - return $this->get('TKT_description'); |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - /** |
|
594 | - * Sets description |
|
595 | - * |
|
596 | - * @param string $description |
|
597 | - * @throws EE_Error |
|
598 | - */ |
|
599 | - public function set_description($description) |
|
600 | - { |
|
601 | - $this->set('TKT_description', $description); |
|
602 | - } |
|
603 | - |
|
604 | - |
|
605 | - /** |
|
606 | - * Gets start_date |
|
607 | - * |
|
608 | - * @param string $dt_frmt |
|
609 | - * @param string $tm_frmt |
|
610 | - * @return string |
|
611 | - * @throws EE_Error |
|
612 | - */ |
|
613 | - public function start_date($dt_frmt = '', $tm_frmt = '') |
|
614 | - { |
|
615 | - return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt); |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * Sets start_date |
|
621 | - * |
|
622 | - * @param string $start_date |
|
623 | - * @return void |
|
624 | - * @throws EE_Error |
|
625 | - */ |
|
626 | - public function set_start_date($start_date) |
|
627 | - { |
|
628 | - $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
629 | - } |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * Gets end_date |
|
634 | - * |
|
635 | - * @param string $dt_frmt |
|
636 | - * @param string $tm_frmt |
|
637 | - * @return string |
|
638 | - * @throws EE_Error |
|
639 | - */ |
|
640 | - public function end_date($dt_frmt = '', $tm_frmt = '') |
|
641 | - { |
|
642 | - return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt); |
|
643 | - } |
|
644 | - |
|
645 | - |
|
646 | - /** |
|
647 | - * Sets end_date |
|
648 | - * |
|
649 | - * @param string $end_date |
|
650 | - * @return void |
|
651 | - * @throws EE_Error |
|
652 | - */ |
|
653 | - public function set_end_date($end_date) |
|
654 | - { |
|
655 | - $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
656 | - } |
|
657 | - |
|
658 | - |
|
659 | - /** |
|
660 | - * Sets sell until time |
|
661 | - * |
|
662 | - * @since 4.5.0 |
|
663 | - * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
664 | - * @throws EE_Error |
|
665 | - */ |
|
666 | - public function set_end_time($time) |
|
667 | - { |
|
668 | - $this->_set_time_for($time, 'TKT_end_date'); |
|
669 | - } |
|
670 | - |
|
671 | - |
|
672 | - /** |
|
673 | - * Sets min |
|
674 | - * |
|
675 | - * @param int $min |
|
676 | - * @return void |
|
677 | - * @throws EE_Error |
|
678 | - */ |
|
679 | - public function set_min($min) |
|
680 | - { |
|
681 | - $this->set('TKT_min', $min); |
|
682 | - } |
|
683 | - |
|
684 | - |
|
685 | - /** |
|
686 | - * Gets max |
|
687 | - * |
|
688 | - * @return int |
|
689 | - * @throws EE_Error |
|
690 | - */ |
|
691 | - public function max() |
|
692 | - { |
|
693 | - return $this->get('TKT_max'); |
|
694 | - } |
|
695 | - |
|
696 | - |
|
697 | - /** |
|
698 | - * Sets max |
|
699 | - * |
|
700 | - * @param int $max |
|
701 | - * @return void |
|
702 | - * @throws EE_Error |
|
703 | - */ |
|
704 | - public function set_max($max) |
|
705 | - { |
|
706 | - $this->set('TKT_max', $max); |
|
707 | - } |
|
708 | - |
|
709 | - |
|
710 | - /** |
|
711 | - * Sets price |
|
712 | - * |
|
713 | - * @param float $price |
|
714 | - * @return void |
|
715 | - * @throws EE_Error |
|
716 | - */ |
|
717 | - public function set_price($price) |
|
718 | - { |
|
719 | - $this->set('TKT_price', $price); |
|
720 | - } |
|
721 | - |
|
722 | - |
|
723 | - /** |
|
724 | - * Gets sold |
|
725 | - * |
|
726 | - * @return int |
|
727 | - * @throws EE_Error |
|
728 | - */ |
|
729 | - public function sold() |
|
730 | - { |
|
731 | - return $this->get_raw('TKT_sold'); |
|
732 | - } |
|
733 | - |
|
734 | - |
|
735 | - /** |
|
736 | - * Sets sold |
|
737 | - * |
|
738 | - * @param int $sold |
|
739 | - * @return void |
|
740 | - * @throws EE_Error |
|
741 | - */ |
|
742 | - public function set_sold($sold) |
|
743 | - { |
|
744 | - // sold can not go below zero |
|
745 | - $sold = max(0, $sold); |
|
746 | - $this->set('TKT_sold', $sold); |
|
747 | - } |
|
748 | - |
|
749 | - |
|
750 | - /** |
|
751 | - * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
752 | - * associated datetimes. |
|
753 | - * |
|
754 | - * @since 4.9.80.p |
|
755 | - * @param int $qty |
|
756 | - * @return boolean |
|
757 | - * @throws EE_Error |
|
758 | - * @throws InvalidArgumentException |
|
759 | - * @throws InvalidDataTypeException |
|
760 | - * @throws InvalidInterfaceException |
|
761 | - * @throws ReflectionException |
|
762 | - */ |
|
763 | - public function increaseSold($qty = 1) |
|
764 | - { |
|
765 | - $qty = absint($qty); |
|
766 | - // increment sold and decrement reserved datetime quantities simultaneously |
|
767 | - // don't worry about failures, because they must have already had a spot reserved |
|
768 | - $this->increaseSoldForDatetimes($qty); |
|
769 | - // Increment and decrement ticket quantities simultaneously |
|
770 | - $success = $this->adjustNumericFieldsInDb( |
|
771 | - [ |
|
772 | - 'TKT_reserved' => $qty * -1, |
|
773 | - 'TKT_sold' => $qty |
|
774 | - ] |
|
775 | - ); |
|
776 | - do_action( |
|
777 | - 'AHEE__EE_Ticket__increase_sold', |
|
778 | - $this, |
|
779 | - $qty, |
|
780 | - $this->sold(), |
|
781 | - $success |
|
782 | - ); |
|
783 | - return $success; |
|
784 | - } |
|
785 | - |
|
786 | - /** |
|
787 | - * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
788 | - * |
|
789 | - * @since 4.9.80.p |
|
790 | - * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
|
791 | - * Negative means to decreases old counts (and increase reserved counts). |
|
792 | - * @param EE_Datetime[] $datetimes |
|
793 | - * @throws EE_Error |
|
794 | - * @throws InvalidArgumentException |
|
795 | - * @throws InvalidDataTypeException |
|
796 | - * @throws InvalidInterfaceException |
|
797 | - * @throws ReflectionException |
|
798 | - */ |
|
799 | - protected function increaseSoldForDatetimes($qty, array $datetimes = []) |
|
800 | - { |
|
801 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
802 | - foreach ($datetimes as $datetime) { |
|
803 | - $datetime->increaseSold($qty); |
|
804 | - } |
|
805 | - } |
|
806 | - |
|
807 | - |
|
808 | - |
|
809 | - /** |
|
810 | - * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
811 | - * DB and then updates the model objects. |
|
812 | - * Does not affect the reserved counts. |
|
813 | - * |
|
814 | - * @since 4.9.80.p |
|
815 | - * @param int $qty |
|
816 | - * @return boolean |
|
817 | - * @throws EE_Error |
|
818 | - * @throws InvalidArgumentException |
|
819 | - * @throws InvalidDataTypeException |
|
820 | - * @throws InvalidInterfaceException |
|
821 | - * @throws ReflectionException |
|
822 | - */ |
|
823 | - public function decreaseSold($qty = 1) |
|
824 | - { |
|
825 | - $qty = absint($qty); |
|
826 | - $this->decreaseSoldForDatetimes($qty); |
|
827 | - $success = $this->adjustNumericFieldsInDb( |
|
828 | - [ |
|
829 | - 'TKT_sold' => $qty * -1 |
|
830 | - ] |
|
831 | - ); |
|
832 | - do_action( |
|
833 | - 'AHEE__EE_Ticket__decrease_sold', |
|
834 | - $this, |
|
835 | - $qty, |
|
836 | - $this->sold(), |
|
837 | - $success |
|
838 | - ); |
|
839 | - return $success; |
|
840 | - } |
|
841 | - |
|
842 | - |
|
843 | - /** |
|
844 | - * Decreases sold on related datetimes |
|
845 | - * |
|
846 | - * @since 4.9.80.p |
|
847 | - * @param int $qty |
|
848 | - * @param EE_Datetime[] $datetimes |
|
849 | - * @return void |
|
850 | - * @throws EE_Error |
|
851 | - * @throws InvalidArgumentException |
|
852 | - * @throws InvalidDataTypeException |
|
853 | - * @throws InvalidInterfaceException |
|
854 | - * @throws ReflectionException |
|
855 | - */ |
|
856 | - protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = []) |
|
857 | - { |
|
858 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
859 | - if (is_array($datetimes)) { |
|
860 | - foreach ($datetimes as $datetime) { |
|
861 | - if ($datetime instanceof EE_Datetime) { |
|
862 | - $datetime->decreaseSold($qty); |
|
863 | - } |
|
864 | - } |
|
865 | - } |
|
866 | - } |
|
867 | - |
|
868 | - |
|
869 | - /** |
|
870 | - * Gets qty of reserved tickets |
|
871 | - * |
|
872 | - * @return int |
|
873 | - * @throws EE_Error |
|
874 | - */ |
|
875 | - public function reserved() |
|
876 | - { |
|
877 | - return $this->get_raw('TKT_reserved'); |
|
878 | - } |
|
879 | - |
|
880 | - |
|
881 | - /** |
|
882 | - * Sets reserved |
|
883 | - * |
|
884 | - * @param int $reserved |
|
885 | - * @return void |
|
886 | - * @throws EE_Error |
|
887 | - */ |
|
888 | - public function set_reserved($reserved) |
|
889 | - { |
|
890 | - // reserved can not go below zero |
|
891 | - $reserved = max(0, (int) $reserved); |
|
892 | - $this->set('TKT_reserved', $reserved); |
|
893 | - } |
|
894 | - |
|
895 | - |
|
896 | - /** |
|
897 | - * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
898 | - * |
|
899 | - * @since 4.9.80.p |
|
900 | - * @param int $qty |
|
901 | - * @param string $source |
|
902 | - * @return bool whether we successfully reserved the ticket or not. |
|
903 | - * @throws EE_Error |
|
904 | - * @throws InvalidArgumentException |
|
905 | - * @throws ReflectionException |
|
906 | - * @throws InvalidDataTypeException |
|
907 | - * @throws InvalidInterfaceException |
|
908 | - */ |
|
909 | - public function increaseReserved($qty = 1, $source = 'unknown') |
|
910 | - { |
|
911 | - $qty = absint($qty); |
|
912 | - do_action( |
|
913 | - 'AHEE__EE_Ticket__increase_reserved__begin', |
|
914 | - $this, |
|
915 | - $qty, |
|
916 | - $source |
|
917 | - ); |
|
918 | - $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "{$qty} from {$source}"); |
|
919 | - $success = false; |
|
920 | - $datetimes_adjusted_successfully = $this->increaseReservedForDatetimes($qty); |
|
921 | - if ($datetimes_adjusted_successfully) { |
|
922 | - $success = $this->incrementFieldConditionallyInDb( |
|
923 | - 'TKT_reserved', |
|
924 | - 'TKT_sold', |
|
925 | - 'TKT_qty', |
|
926 | - $qty |
|
927 | - ); |
|
928 | - if (! $success) { |
|
929 | - // The datetimes were successfully bumped, but not the |
|
930 | - // ticket. So we need to manually rollback the datetimes. |
|
931 | - $this->decreaseReservedForDatetimes($qty); |
|
932 | - } |
|
933 | - } |
|
934 | - do_action( |
|
935 | - 'AHEE__EE_Ticket__increase_reserved', |
|
936 | - $this, |
|
937 | - $qty, |
|
938 | - $this->reserved(), |
|
939 | - $success |
|
940 | - ); |
|
941 | - return $success; |
|
942 | - } |
|
943 | - |
|
944 | - |
|
945 | - /** |
|
946 | - * Increases reserved counts on related datetimes |
|
947 | - * |
|
948 | - * @since 4.9.80.p |
|
949 | - * @param int $qty |
|
950 | - * @param EE_Datetime[] $datetimes |
|
951 | - * @return boolean indicating success |
|
952 | - * @throws EE_Error |
|
953 | - * @throws InvalidArgumentException |
|
954 | - * @throws InvalidDataTypeException |
|
955 | - * @throws InvalidInterfaceException |
|
956 | - * @throws ReflectionException |
|
957 | - */ |
|
958 | - protected function increaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
959 | - { |
|
960 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
961 | - $datetimes_updated = []; |
|
962 | - $limit_exceeded = false; |
|
963 | - if (is_array($datetimes)) { |
|
964 | - foreach ($datetimes as $datetime) { |
|
965 | - if ($datetime instanceof EE_Datetime) { |
|
966 | - if ($datetime->increaseReserved($qty)) { |
|
967 | - $datetimes_updated[] = $datetime; |
|
968 | - } else { |
|
969 | - $limit_exceeded = true; |
|
970 | - break; |
|
971 | - } |
|
972 | - } |
|
973 | - } |
|
974 | - // If somewhere along the way we detected a datetime whose |
|
975 | - // limit was exceeded, do a manual rollback. |
|
976 | - if ($limit_exceeded) { |
|
977 | - $this->decreaseReservedForDatetimes($qty, $datetimes_updated); |
|
978 | - return false; |
|
979 | - } |
|
980 | - } |
|
981 | - return true; |
|
982 | - } |
|
983 | - |
|
984 | - |
|
985 | - /** |
|
986 | - * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
987 | - * |
|
988 | - * @since 4.9.80.p |
|
989 | - * @param int $qty |
|
990 | - * @param bool $adjust_datetimes |
|
991 | - * @param string $source |
|
992 | - * @return boolean |
|
993 | - * @throws EE_Error |
|
994 | - * @throws InvalidArgumentException |
|
995 | - * @throws ReflectionException |
|
996 | - * @throws InvalidDataTypeException |
|
997 | - * @throws InvalidInterfaceException |
|
998 | - */ |
|
999 | - public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
1000 | - { |
|
1001 | - $qty = absint($qty); |
|
1002 | - $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "-{$qty} from {$source}"); |
|
1003 | - if ($adjust_datetimes) { |
|
1004 | - $this->decreaseReservedForDatetimes($qty); |
|
1005 | - } |
|
1006 | - $success = $this->adjustNumericFieldsInDb( |
|
1007 | - [ |
|
1008 | - 'TKT_reserved' => $qty * -1 |
|
1009 | - ] |
|
1010 | - ); |
|
1011 | - do_action( |
|
1012 | - 'AHEE__EE_Ticket__decrease_reserved', |
|
1013 | - $this, |
|
1014 | - $qty, |
|
1015 | - $this->reserved(), |
|
1016 | - $success |
|
1017 | - ); |
|
1018 | - return $success; |
|
1019 | - } |
|
1020 | - |
|
1021 | - |
|
1022 | - /** |
|
1023 | - * Decreases the reserved count on the specified datetimes. |
|
1024 | - * |
|
1025 | - * @since 4.9.80.p |
|
1026 | - * @param int $qty |
|
1027 | - * @param EE_Datetime[] $datetimes |
|
1028 | - * @throws EE_Error |
|
1029 | - * @throws InvalidArgumentException |
|
1030 | - * @throws ReflectionException |
|
1031 | - * @throws InvalidDataTypeException |
|
1032 | - * @throws InvalidInterfaceException |
|
1033 | - */ |
|
1034 | - protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
1035 | - { |
|
1036 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
1037 | - foreach ($datetimes as $datetime) { |
|
1038 | - if ($datetime instanceof EE_Datetime) { |
|
1039 | - $datetime->decreaseReserved($qty); |
|
1040 | - } |
|
1041 | - } |
|
1042 | - } |
|
1043 | - |
|
1044 | - |
|
1045 | - /** |
|
1046 | - * Gets ticket quantity |
|
1047 | - * |
|
1048 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
1049 | - * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
1050 | - * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
1051 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
1052 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
1053 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
1054 | - * @return int |
|
1055 | - * @throws EE_Error |
|
1056 | - */ |
|
1057 | - public function qty($context = '') |
|
1058 | - { |
|
1059 | - switch ($context) { |
|
1060 | - case 'reg_limit': |
|
1061 | - return $this->real_quantity_on_ticket(); |
|
1062 | - case 'saleable': |
|
1063 | - return $this->real_quantity_on_ticket('saleable'); |
|
1064 | - default: |
|
1065 | - return $this->get_raw('TKT_qty'); |
|
1066 | - } |
|
1067 | - } |
|
1068 | - |
|
1069 | - |
|
1070 | - /** |
|
1071 | - * Gets ticket quantity |
|
1072 | - * |
|
1073 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
1074 | - * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
1075 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
1076 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
1077 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
1078 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
1079 | - * set to 0 for all related datetimes |
|
1080 | - * @return int |
|
1081 | - * @throws EE_Error |
|
1082 | - */ |
|
1083 | - public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
|
1084 | - { |
|
1085 | - $raw = $this->get_raw('TKT_qty'); |
|
1086 | - // return immediately if it's zero |
|
1087 | - if ($raw === 0) { |
|
1088 | - return $raw; |
|
1089 | - } |
|
1090 | - // echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
|
1091 | - // ensure qty doesn't exceed raw value for THIS ticket |
|
1092 | - $qty = min(EE_INF, $raw); |
|
1093 | - // echo "\n . qty: " . $qty . '<br />'; |
|
1094 | - // calculate this ticket's total sales and reservations |
|
1095 | - $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
|
1096 | - // echo "\n . sold: " . $this->sold() . '<br />'; |
|
1097 | - // echo "\n . reserved: " . $this->reserved() . '<br />'; |
|
1098 | - // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
|
1099 | - // first we need to calculate the maximum number of tickets available for the datetime |
|
1100 | - // do we want data for one datetime or all of them ? |
|
1101 | - $query_params = $DTT_ID ? array(array('DTT_ID' => $DTT_ID)) : array(); |
|
1102 | - $datetimes = $this->datetimes($query_params); |
|
1103 | - if (is_array($datetimes) && ! empty($datetimes)) { |
|
1104 | - foreach ($datetimes as $datetime) { |
|
1105 | - if ($datetime instanceof EE_Datetime) { |
|
1106 | - $datetime->refresh_from_db(); |
|
1107 | - // echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
|
1108 | - // echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
|
1109 | - // initialize with no restrictions for each datetime |
|
1110 | - // but adjust datetime qty based on datetime reg limit |
|
1111 | - $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
1112 | - // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
|
1113 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
1114 | - // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
|
1115 | - // and reservations for this datetime, that do NOT include sales and reservations |
|
1116 | - // for this ticket (so we add $this->sold() and $this->reserved() back in) |
|
1117 | - if ($context === 'saleable') { |
|
1118 | - $datetime_qty = max( |
|
1119 | - $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
|
1120 | - 0 |
|
1121 | - ); |
|
1122 | - // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />'; |
|
1123 | - // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />'; |
|
1124 | - // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />'; |
|
1125 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
1126 | - $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
|
1127 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
1128 | - } |
|
1129 | - $qty = min($datetime_qty, $qty); |
|
1130 | - // echo "\n . . qty: " . $qty . '<br />'; |
|
1131 | - } |
|
1132 | - } |
|
1133 | - } |
|
1134 | - // NOW that we know the maximum number of tickets available for the datetime |
|
1135 | - // we can finally factor in the details for this specific ticket |
|
1136 | - if ($qty > 0 && $context === 'saleable') { |
|
1137 | - // and subtract the sales for THIS ticket |
|
1138 | - $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
1139 | - // echo "\n . qty: " . $qty . '<br />'; |
|
1140 | - } |
|
1141 | - // echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
|
1142 | - return $qty; |
|
1143 | - } |
|
1144 | - |
|
1145 | - |
|
1146 | - /** |
|
1147 | - * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
|
1148 | - * |
|
1149 | - * @param int $qty |
|
1150 | - * @return void |
|
1151 | - * @throws EE_Error |
|
1152 | - */ |
|
1153 | - public function set_qty($qty) |
|
1154 | - { |
|
1155 | - $datetimes = $this->datetimes(); |
|
1156 | - foreach ($datetimes as $datetime) { |
|
1157 | - if ($datetime instanceof EE_Datetime) { |
|
1158 | - $qty = min($qty, $datetime->reg_limit()); |
|
1159 | - } |
|
1160 | - } |
|
1161 | - $this->set('TKT_qty', $qty); |
|
1162 | - } |
|
1163 | - |
|
1164 | - |
|
1165 | - /** |
|
1166 | - * Gets uses |
|
1167 | - * |
|
1168 | - * @return int |
|
1169 | - * @throws EE_Error |
|
1170 | - */ |
|
1171 | - public function uses() |
|
1172 | - { |
|
1173 | - return $this->get('TKT_uses'); |
|
1174 | - } |
|
1175 | - |
|
1176 | - |
|
1177 | - /** |
|
1178 | - * Sets uses |
|
1179 | - * |
|
1180 | - * @param int $uses |
|
1181 | - * @return void |
|
1182 | - * @throws EE_Error |
|
1183 | - */ |
|
1184 | - public function set_uses($uses) |
|
1185 | - { |
|
1186 | - $this->set('TKT_uses', $uses); |
|
1187 | - } |
|
1188 | - |
|
1189 | - |
|
1190 | - /** |
|
1191 | - * returns whether ticket is required or not. |
|
1192 | - * |
|
1193 | - * @return boolean |
|
1194 | - * @throws EE_Error |
|
1195 | - */ |
|
1196 | - public function required() |
|
1197 | - { |
|
1198 | - return $this->get('TKT_required'); |
|
1199 | - } |
|
1200 | - |
|
1201 | - |
|
1202 | - /** |
|
1203 | - * sets the TKT_required property |
|
1204 | - * |
|
1205 | - * @param boolean $required |
|
1206 | - * @return void |
|
1207 | - * @throws EE_Error |
|
1208 | - */ |
|
1209 | - public function set_required($required) |
|
1210 | - { |
|
1211 | - $this->set('TKT_required', $required); |
|
1212 | - } |
|
1213 | - |
|
1214 | - |
|
1215 | - /** |
|
1216 | - * Gets taxable |
|
1217 | - * |
|
1218 | - * @return boolean |
|
1219 | - * @throws EE_Error |
|
1220 | - */ |
|
1221 | - public function taxable() |
|
1222 | - { |
|
1223 | - return $this->get('TKT_taxable'); |
|
1224 | - } |
|
1225 | - |
|
1226 | - |
|
1227 | - /** |
|
1228 | - * Sets taxable |
|
1229 | - * |
|
1230 | - * @param boolean $taxable |
|
1231 | - * @return void |
|
1232 | - * @throws EE_Error |
|
1233 | - */ |
|
1234 | - public function set_taxable($taxable) |
|
1235 | - { |
|
1236 | - $this->set('TKT_taxable', $taxable); |
|
1237 | - } |
|
1238 | - |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * Gets is_default |
|
1242 | - * |
|
1243 | - * @return boolean |
|
1244 | - * @throws EE_Error |
|
1245 | - */ |
|
1246 | - public function is_default() |
|
1247 | - { |
|
1248 | - return $this->get('TKT_is_default'); |
|
1249 | - } |
|
1250 | - |
|
1251 | - |
|
1252 | - /** |
|
1253 | - * Sets is_default |
|
1254 | - * |
|
1255 | - * @param boolean $is_default |
|
1256 | - * @return void |
|
1257 | - * @throws EE_Error |
|
1258 | - */ |
|
1259 | - public function set_is_default($is_default) |
|
1260 | - { |
|
1261 | - $this->set('TKT_is_default', $is_default); |
|
1262 | - } |
|
1263 | - |
|
1264 | - |
|
1265 | - /** |
|
1266 | - * Gets order |
|
1267 | - * |
|
1268 | - * @return int |
|
1269 | - * @throws EE_Error |
|
1270 | - */ |
|
1271 | - public function order() |
|
1272 | - { |
|
1273 | - return $this->get('TKT_order'); |
|
1274 | - } |
|
1275 | - |
|
1276 | - |
|
1277 | - /** |
|
1278 | - * Sets order |
|
1279 | - * |
|
1280 | - * @param int $order |
|
1281 | - * @return void |
|
1282 | - * @throws EE_Error |
|
1283 | - */ |
|
1284 | - public function set_order($order) |
|
1285 | - { |
|
1286 | - $this->set('TKT_order', $order); |
|
1287 | - } |
|
1288 | - |
|
1289 | - |
|
1290 | - /** |
|
1291 | - * Gets row |
|
1292 | - * |
|
1293 | - * @return int |
|
1294 | - * @throws EE_Error |
|
1295 | - */ |
|
1296 | - public function row() |
|
1297 | - { |
|
1298 | - return $this->get('TKT_row'); |
|
1299 | - } |
|
1300 | - |
|
1301 | - |
|
1302 | - /** |
|
1303 | - * Sets row |
|
1304 | - * |
|
1305 | - * @param int $row |
|
1306 | - * @return void |
|
1307 | - * @throws EE_Error |
|
1308 | - */ |
|
1309 | - public function set_row($row) |
|
1310 | - { |
|
1311 | - $this->set('TKT_row', $row); |
|
1312 | - } |
|
1313 | - |
|
1314 | - |
|
1315 | - /** |
|
1316 | - * Gets deleted |
|
1317 | - * |
|
1318 | - * @return boolean |
|
1319 | - * @throws EE_Error |
|
1320 | - */ |
|
1321 | - public function deleted() |
|
1322 | - { |
|
1323 | - return $this->get('TKT_deleted'); |
|
1324 | - } |
|
1325 | - |
|
1326 | - |
|
1327 | - /** |
|
1328 | - * Sets deleted |
|
1329 | - * |
|
1330 | - * @param boolean $deleted |
|
1331 | - * @return void |
|
1332 | - * @throws EE_Error |
|
1333 | - */ |
|
1334 | - public function set_deleted($deleted) |
|
1335 | - { |
|
1336 | - $this->set('TKT_deleted', $deleted); |
|
1337 | - } |
|
1338 | - |
|
1339 | - |
|
1340 | - /** |
|
1341 | - * Gets parent |
|
1342 | - * |
|
1343 | - * @return int |
|
1344 | - * @throws EE_Error |
|
1345 | - */ |
|
1346 | - public function parent_ID() |
|
1347 | - { |
|
1348 | - return $this->get('TKT_parent'); |
|
1349 | - } |
|
1350 | - |
|
1351 | - |
|
1352 | - /** |
|
1353 | - * Sets parent |
|
1354 | - * |
|
1355 | - * @param int $parent |
|
1356 | - * @return void |
|
1357 | - * @throws EE_Error |
|
1358 | - */ |
|
1359 | - public function set_parent_ID($parent) |
|
1360 | - { |
|
1361 | - $this->set('TKT_parent', $parent); |
|
1362 | - } |
|
1363 | - |
|
1364 | - |
|
1365 | - /** |
|
1366 | - * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
1367 | - * |
|
1368 | - * @return string |
|
1369 | - * @throws EE_Error |
|
1370 | - */ |
|
1371 | - public function name_and_info() |
|
1372 | - { |
|
1373 | - $times = array(); |
|
1374 | - foreach ($this->datetimes() as $datetime) { |
|
1375 | - $times[] = $datetime->start_date_and_time(); |
|
1376 | - } |
|
1377 | - return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
1378 | - } |
|
1379 | - |
|
1380 | - |
|
1381 | - /** |
|
1382 | - * Gets name |
|
1383 | - * |
|
1384 | - * @return string |
|
1385 | - * @throws EE_Error |
|
1386 | - */ |
|
1387 | - public function name() |
|
1388 | - { |
|
1389 | - return $this->get('TKT_name'); |
|
1390 | - } |
|
1391 | - |
|
1392 | - |
|
1393 | - /** |
|
1394 | - * Gets price |
|
1395 | - * |
|
1396 | - * @return float |
|
1397 | - * @throws EE_Error |
|
1398 | - */ |
|
1399 | - public function price() |
|
1400 | - { |
|
1401 | - return $this->get('TKT_price'); |
|
1402 | - } |
|
1403 | - |
|
1404 | - |
|
1405 | - /** |
|
1406 | - * Gets all the registrations for this ticket |
|
1407 | - * |
|
1408 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1409 | - * @return EE_Registration[]|EE_Base_Class[] |
|
1410 | - * @throws EE_Error |
|
1411 | - */ |
|
1412 | - public function registrations($query_params = array()) |
|
1413 | - { |
|
1414 | - return $this->get_many_related('Registration', $query_params); |
|
1415 | - } |
|
1416 | - |
|
1417 | - |
|
1418 | - /** |
|
1419 | - * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
1420 | - * |
|
1421 | - * @return int |
|
1422 | - * @throws EE_Error |
|
1423 | - */ |
|
1424 | - public function update_tickets_sold() |
|
1425 | - { |
|
1426 | - $count_regs_for_this_ticket = $this->count_registrations( |
|
1427 | - array( |
|
1428 | - array( |
|
1429 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
1430 | - 'REG_deleted' => 0, |
|
1431 | - ), |
|
1432 | - ) |
|
1433 | - ); |
|
1434 | - $this->set_sold($count_regs_for_this_ticket); |
|
1435 | - $this->save(); |
|
1436 | - return $count_regs_for_this_ticket; |
|
1437 | - } |
|
1438 | - |
|
1439 | - |
|
1440 | - /** |
|
1441 | - * Counts the registrations for this ticket |
|
1442 | - * |
|
1443 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1444 | - * @return int |
|
1445 | - */ |
|
1446 | - public function count_registrations($query_params = array()) |
|
1447 | - { |
|
1448 | - return $this->count_related('Registration', $query_params); |
|
1449 | - } |
|
1450 | - |
|
1451 | - |
|
1452 | - /** |
|
1453 | - * Implementation for EEI_Has_Icon interface method. |
|
1454 | - * |
|
1455 | - * @see EEI_Visual_Representation for comments |
|
1456 | - * @return string |
|
1457 | - */ |
|
1458 | - public function get_icon() |
|
1459 | - { |
|
1460 | - return '<span class="dashicons dashicons-tickets-alt"></span>'; |
|
1461 | - } |
|
1462 | - |
|
1463 | - |
|
1464 | - /** |
|
1465 | - * Implementation of the EEI_Event_Relation interface method |
|
1466 | - * |
|
1467 | - * @see EEI_Event_Relation for comments |
|
1468 | - * @return EE_Event |
|
1469 | - * @throws EE_Error |
|
1470 | - * @throws UnexpectedEntityException |
|
1471 | - */ |
|
1472 | - public function get_related_event() |
|
1473 | - { |
|
1474 | - // get one datetime to use for getting the event |
|
1475 | - $datetime = $this->first_datetime(); |
|
1476 | - if (! $datetime instanceof \EE_Datetime) { |
|
1477 | - throw new UnexpectedEntityException( |
|
1478 | - $datetime, |
|
1479 | - 'EE_Datetime', |
|
1480 | - sprintf( |
|
1481 | - __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
1482 | - $this->name() |
|
1483 | - ) |
|
1484 | - ); |
|
1485 | - } |
|
1486 | - $event = $datetime->event(); |
|
1487 | - if (! $event instanceof \EE_Event) { |
|
1488 | - throw new UnexpectedEntityException( |
|
1489 | - $event, |
|
1490 | - 'EE_Event', |
|
1491 | - sprintf( |
|
1492 | - __('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
1493 | - $this->name() |
|
1494 | - ) |
|
1495 | - ); |
|
1496 | - } |
|
1497 | - return $event; |
|
1498 | - } |
|
1499 | - |
|
1500 | - |
|
1501 | - /** |
|
1502 | - * Implementation of the EEI_Event_Relation interface method |
|
1503 | - * |
|
1504 | - * @see EEI_Event_Relation for comments |
|
1505 | - * @return string |
|
1506 | - * @throws UnexpectedEntityException |
|
1507 | - * @throws EE_Error |
|
1508 | - */ |
|
1509 | - public function get_event_name() |
|
1510 | - { |
|
1511 | - $event = $this->get_related_event(); |
|
1512 | - return $event instanceof EE_Event ? $event->name() : ''; |
|
1513 | - } |
|
1514 | - |
|
1515 | - |
|
1516 | - /** |
|
1517 | - * Implementation of the EEI_Event_Relation interface method |
|
1518 | - * |
|
1519 | - * @see EEI_Event_Relation for comments |
|
1520 | - * @return int |
|
1521 | - * @throws UnexpectedEntityException |
|
1522 | - * @throws EE_Error |
|
1523 | - */ |
|
1524 | - public function get_event_ID() |
|
1525 | - { |
|
1526 | - $event = $this->get_related_event(); |
|
1527 | - return $event instanceof EE_Event ? $event->ID() : 0; |
|
1528 | - } |
|
1529 | - |
|
1530 | - |
|
1531 | - /** |
|
1532 | - * This simply returns whether a ticket can be permanently deleted or not. |
|
1533 | - * The criteria for determining this is whether the ticket has any related registrations. |
|
1534 | - * If there are none then it can be permanently deleted. |
|
1535 | - * |
|
1536 | - * @return bool |
|
1537 | - */ |
|
1538 | - public function is_permanently_deleteable() |
|
1539 | - { |
|
1540 | - return $this->count_registrations() === 0; |
|
1541 | - } |
|
1542 | - |
|
1543 | - |
|
1544 | - /******************************************************************* |
|
17 | + /** |
|
18 | + * The following constants are used by the ticket_status() method to indicate whether a ticket is on sale or not. |
|
19 | + */ |
|
20 | + const sold_out = 'TKS'; |
|
21 | + |
|
22 | + /** |
|
23 | + * |
|
24 | + */ |
|
25 | + const expired = 'TKE'; |
|
26 | + |
|
27 | + /** |
|
28 | + * |
|
29 | + */ |
|
30 | + const archived = 'TKA'; |
|
31 | + |
|
32 | + /** |
|
33 | + * |
|
34 | + */ |
|
35 | + const pending = 'TKP'; |
|
36 | + |
|
37 | + /** |
|
38 | + * |
|
39 | + */ |
|
40 | + const onsale = 'TKO'; |
|
41 | + |
|
42 | + /** |
|
43 | + * extra meta key for tracking ticket reservations |
|
44 | + * |
|
45 | + * @type string |
|
46 | + */ |
|
47 | + const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
|
48 | + |
|
49 | + /** |
|
50 | + * cached result from method of the same name |
|
51 | + * |
|
52 | + * @var float $_ticket_total_with_taxes |
|
53 | + */ |
|
54 | + private $_ticket_total_with_taxes; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @param array $props_n_values incoming values |
|
59 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
60 | + * used.) |
|
61 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
62 | + * date_format and the second value is the time format |
|
63 | + * @return EE_Ticket |
|
64 | + * @throws EE_Error |
|
65 | + */ |
|
66 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
67 | + { |
|
68 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
69 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param array $props_n_values incoming values from the database |
|
75 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
76 | + * the website will be used. |
|
77 | + * @return EE_Ticket |
|
78 | + * @throws EE_Error |
|
79 | + */ |
|
80 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
81 | + { |
|
82 | + return new self($props_n_values, true, $timezone); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @return bool |
|
88 | + * @throws EE_Error |
|
89 | + */ |
|
90 | + public function parent() |
|
91 | + { |
|
92 | + return $this->get('TKT_parent'); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * return if a ticket has quantities available for purchase |
|
98 | + * |
|
99 | + * @param int $DTT_ID the primary key for a particular datetime |
|
100 | + * @return boolean |
|
101 | + * @throws EE_Error |
|
102 | + */ |
|
103 | + public function available($DTT_ID = 0) |
|
104 | + { |
|
105 | + // are we checking availability for a particular datetime ? |
|
106 | + if ($DTT_ID) { |
|
107 | + // get that datetime object |
|
108 | + $datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID))); |
|
109 | + // if ticket sales for this datetime have exceeded the reg limit... |
|
110 | + if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
111 | + return false; |
|
112 | + } |
|
113 | + } |
|
114 | + // datetime is still open for registration, but is this ticket sold out ? |
|
115 | + return $this->qty() < 1 || $this->qty() > $this->sold() ? true : false; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
121 | + * |
|
122 | + * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
|
123 | + * relevant status const |
|
124 | + * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
|
125 | + * further processing |
|
126 | + * @return mixed status int if the display string isn't requested |
|
127 | + * @throws EE_Error |
|
128 | + */ |
|
129 | + public function ticket_status($display = false, $remaining = null) |
|
130 | + { |
|
131 | + $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
132 | + if (! $remaining) { |
|
133 | + return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
|
134 | + } |
|
135 | + if ($this->get('TKT_deleted')) { |
|
136 | + return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived; |
|
137 | + } |
|
138 | + if ($this->is_expired()) { |
|
139 | + return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired; |
|
140 | + } |
|
141 | + if ($this->is_pending()) { |
|
142 | + return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending; |
|
143 | + } |
|
144 | + if ($this->is_on_sale()) { |
|
145 | + return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale; |
|
146 | + } |
|
147 | + return ''; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
|
153 | + * considering ALL the factors used for figuring that out. |
|
154 | + * |
|
155 | + * @access public |
|
156 | + * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
157 | + * @return boolean true = tickets remaining, false not. |
|
158 | + * @throws EE_Error |
|
159 | + */ |
|
160 | + public function is_remaining($DTT_ID = 0) |
|
161 | + { |
|
162 | + $num_remaining = $this->remaining($DTT_ID); |
|
163 | + if ($num_remaining === 0) { |
|
164 | + return false; |
|
165 | + } |
|
166 | + if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
167 | + return false; |
|
168 | + } |
|
169 | + return true; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * return the total number of tickets available for purchase |
|
175 | + * |
|
176 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
177 | + * set to 0 for all related datetimes |
|
178 | + * @return int |
|
179 | + * @throws EE_Error |
|
180 | + */ |
|
181 | + public function remaining($DTT_ID = 0) |
|
182 | + { |
|
183 | + return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * Gets min |
|
189 | + * |
|
190 | + * @return int |
|
191 | + * @throws EE_Error |
|
192 | + */ |
|
193 | + public function min() |
|
194 | + { |
|
195 | + return $this->get('TKT_min'); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * return if a ticket is no longer available cause its available dates have expired. |
|
201 | + * |
|
202 | + * @return boolean |
|
203 | + * @throws EE_Error |
|
204 | + */ |
|
205 | + public function is_expired() |
|
206 | + { |
|
207 | + return ($this->get_raw('TKT_end_date') < time()); |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * Return if a ticket is yet to go on sale or not |
|
213 | + * |
|
214 | + * @return boolean |
|
215 | + * @throws EE_Error |
|
216 | + */ |
|
217 | + public function is_pending() |
|
218 | + { |
|
219 | + return ($this->get_raw('TKT_start_date') > time()); |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * Return if a ticket is on sale or not |
|
225 | + * |
|
226 | + * @return boolean |
|
227 | + * @throws EE_Error |
|
228 | + */ |
|
229 | + public function is_on_sale() |
|
230 | + { |
|
231 | + return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time()); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * This returns the chronologically last datetime that this ticket is associated with |
|
237 | + * |
|
238 | + * @param string $dt_frmt |
|
239 | + * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
|
240 | + * the end date ie: Jan 01 "to" Dec 31 |
|
241 | + * @return string |
|
242 | + * @throws EE_Error |
|
243 | + */ |
|
244 | + public function date_range($dt_frmt = '', $conjunction = ' - ') |
|
245 | + { |
|
246 | + $dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt; |
|
247 | + $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->get_i18n_datetime('DTT_EVT_start', $dt_frmt) |
|
248 | + : ''; |
|
249 | + $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $dt_frmt) : ''; |
|
250 | + |
|
251 | + return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * This returns the chronologically first datetime that this ticket is associated with |
|
257 | + * |
|
258 | + * @return EE_Datetime |
|
259 | + * @throws EE_Error |
|
260 | + */ |
|
261 | + public function first_datetime() |
|
262 | + { |
|
263 | + $datetimes = $this->datetimes(array('limit' => 1)); |
|
264 | + return reset($datetimes); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * Gets all the datetimes this ticket can be used for attending. |
|
270 | + * Unless otherwise specified, orders datetimes by start date. |
|
271 | + * |
|
272 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
273 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
274 | + * @throws EE_Error |
|
275 | + */ |
|
276 | + public function datetimes($query_params = array()) |
|
277 | + { |
|
278 | + if (! isset($query_params['order_by'])) { |
|
279 | + $query_params['order_by']['DTT_order'] = 'ASC'; |
|
280 | + } |
|
281 | + return $this->get_many_related('Datetime', $query_params); |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * This returns the chronologically last datetime that this ticket is associated with |
|
287 | + * |
|
288 | + * @return EE_Datetime |
|
289 | + * @throws EE_Error |
|
290 | + */ |
|
291 | + public function last_datetime() |
|
292 | + { |
|
293 | + $datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC'))); |
|
294 | + return end($datetimes); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * This returns the total tickets sold depending on the given parameters. |
|
300 | + * |
|
301 | + * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
302 | + * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
303 | + * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
304 | + * 'datetime' = total ticket sales in the datetime_ticket table. |
|
305 | + * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
306 | + * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
307 | + * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
308 | + * @return mixed (array|int) how many tickets have sold |
|
309 | + * @throws EE_Error |
|
310 | + */ |
|
311 | + public function tickets_sold($what = 'ticket', $dtt_id = null) |
|
312 | + { |
|
313 | + $total = 0; |
|
314 | + $tickets_sold = $this->_all_tickets_sold(); |
|
315 | + switch ($what) { |
|
316 | + case 'ticket': |
|
317 | + return $tickets_sold['ticket']; |
|
318 | + break; |
|
319 | + case 'datetime': |
|
320 | + if (empty($tickets_sold['datetime'])) { |
|
321 | + return $total; |
|
322 | + } |
|
323 | + if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
324 | + EE_Error::add_error( |
|
325 | + __( |
|
326 | + 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
|
327 | + 'event_espresso' |
|
328 | + ), |
|
329 | + __FILE__, |
|
330 | + __FUNCTION__, |
|
331 | + __LINE__ |
|
332 | + ); |
|
333 | + return $total; |
|
334 | + } |
|
335 | + return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
336 | + break; |
|
337 | + default: |
|
338 | + return $total; |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
345 | + * |
|
346 | + * @return EE_Ticket[] |
|
347 | + * @throws EE_Error |
|
348 | + */ |
|
349 | + protected function _all_tickets_sold() |
|
350 | + { |
|
351 | + $datetimes = $this->get_many_related('Datetime'); |
|
352 | + $tickets_sold = array(); |
|
353 | + if (! empty($datetimes)) { |
|
354 | + foreach ($datetimes as $datetime) { |
|
355 | + $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
356 | + } |
|
357 | + } |
|
358 | + // Tickets sold |
|
359 | + $tickets_sold['ticket'] = $this->sold(); |
|
360 | + return $tickets_sold; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * This returns the base price object for the ticket. |
|
366 | + * |
|
367 | + * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
368 | + * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
369 | + * @throws EE_Error |
|
370 | + */ |
|
371 | + public function base_price($return_array = false) |
|
372 | + { |
|
373 | + $_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price); |
|
374 | + return $return_array |
|
375 | + ? $this->get_many_related('Price', array($_where)) |
|
376 | + : $this->get_first_related('Price', array($_where)); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
382 | + * |
|
383 | + * @access public |
|
384 | + * @return EE_Price[] |
|
385 | + * @throws EE_Error |
|
386 | + */ |
|
387 | + public function price_modifiers() |
|
388 | + { |
|
389 | + $query_params = array( |
|
390 | + 0 => array( |
|
391 | + 'Price_Type.PBT_ID' => array( |
|
392 | + 'NOT IN', |
|
393 | + array(EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax), |
|
394 | + ), |
|
395 | + ), |
|
396 | + ); |
|
397 | + return $this->prices($query_params); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * Gets all the prices that combine to form the final price of this ticket |
|
403 | + * |
|
404 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
405 | + * @return EE_Price[]|EE_Base_Class[] |
|
406 | + * @throws EE_Error |
|
407 | + */ |
|
408 | + public function prices($query_params = array()) |
|
409 | + { |
|
410 | + return $this->get_many_related('Price', $query_params); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
|
416 | + * |
|
417 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
418 | + * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
419 | + * @throws EE_Error |
|
420 | + */ |
|
421 | + public function datetime_tickets($query_params = array()) |
|
422 | + { |
|
423 | + return $this->get_many_related('Datetime_Ticket', $query_params); |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * Gets all the datetimes from the db ordered by DTT_order |
|
429 | + * |
|
430 | + * @param boolean $show_expired |
|
431 | + * @param boolean $show_deleted |
|
432 | + * @return EE_Datetime[] |
|
433 | + * @throws EE_Error |
|
434 | + */ |
|
435 | + public function datetimes_ordered($show_expired = true, $show_deleted = false) |
|
436 | + { |
|
437 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order( |
|
438 | + $this->ID(), |
|
439 | + $show_expired, |
|
440 | + $show_deleted |
|
441 | + ); |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * Gets ID |
|
447 | + * |
|
448 | + * @return string |
|
449 | + * @throws EE_Error |
|
450 | + */ |
|
451 | + public function ID() |
|
452 | + { |
|
453 | + return $this->get('TKT_ID'); |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + /** |
|
458 | + * get the author of the ticket. |
|
459 | + * |
|
460 | + * @since 4.5.0 |
|
461 | + * @return int |
|
462 | + * @throws EE_Error |
|
463 | + */ |
|
464 | + public function wp_user() |
|
465 | + { |
|
466 | + return $this->get('TKT_wp_user'); |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * Gets the template for the ticket |
|
472 | + * |
|
473 | + * @return EE_Ticket_Template|EE_Base_Class |
|
474 | + * @throws EE_Error |
|
475 | + */ |
|
476 | + public function template() |
|
477 | + { |
|
478 | + return $this->get_first_related('Ticket_Template'); |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * Simply returns an array of EE_Price objects that are taxes. |
|
484 | + * |
|
485 | + * @return EE_Price[] |
|
486 | + * @throws EE_Error |
|
487 | + */ |
|
488 | + public function get_ticket_taxes_for_admin() |
|
489 | + { |
|
490 | + return EE_Taxes::get_taxes_for_admin(); |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * @return float |
|
496 | + * @throws EE_Error |
|
497 | + */ |
|
498 | + public function ticket_price() |
|
499 | + { |
|
500 | + return $this->get('TKT_price'); |
|
501 | + } |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * @return mixed |
|
506 | + * @throws EE_Error |
|
507 | + */ |
|
508 | + public function pretty_price() |
|
509 | + { |
|
510 | + return $this->get_pretty('TKT_price'); |
|
511 | + } |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * @return bool |
|
516 | + * @throws EE_Error |
|
517 | + */ |
|
518 | + public function is_free() |
|
519 | + { |
|
520 | + return $this->get_ticket_total_with_taxes() === (float) 0; |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * get_ticket_total_with_taxes |
|
526 | + * |
|
527 | + * @param bool $no_cache |
|
528 | + * @return float |
|
529 | + * @throws EE_Error |
|
530 | + */ |
|
531 | + public function get_ticket_total_with_taxes($no_cache = false) |
|
532 | + { |
|
533 | + if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
534 | + $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
|
535 | + } |
|
536 | + return (float) $this->_ticket_total_with_taxes; |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + public function ensure_TKT_Price_correct() |
|
541 | + { |
|
542 | + $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
543 | + $this->save(); |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * @return float |
|
549 | + * @throws EE_Error |
|
550 | + */ |
|
551 | + public function get_ticket_subtotal() |
|
552 | + { |
|
553 | + return EE_Taxes::get_subtotal_for_admin($this); |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * Returns the total taxes applied to this ticket |
|
559 | + * |
|
560 | + * @return float |
|
561 | + * @throws EE_Error |
|
562 | + */ |
|
563 | + public function get_ticket_taxes_total_for_admin() |
|
564 | + { |
|
565 | + return EE_Taxes::get_total_taxes_for_admin($this); |
|
566 | + } |
|
567 | + |
|
568 | + |
|
569 | + /** |
|
570 | + * Sets name |
|
571 | + * |
|
572 | + * @param string $name |
|
573 | + * @throws EE_Error |
|
574 | + */ |
|
575 | + public function set_name($name) |
|
576 | + { |
|
577 | + $this->set('TKT_name', $name); |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * Gets description |
|
583 | + * |
|
584 | + * @return string |
|
585 | + * @throws EE_Error |
|
586 | + */ |
|
587 | + public function description() |
|
588 | + { |
|
589 | + return $this->get('TKT_description'); |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + /** |
|
594 | + * Sets description |
|
595 | + * |
|
596 | + * @param string $description |
|
597 | + * @throws EE_Error |
|
598 | + */ |
|
599 | + public function set_description($description) |
|
600 | + { |
|
601 | + $this->set('TKT_description', $description); |
|
602 | + } |
|
603 | + |
|
604 | + |
|
605 | + /** |
|
606 | + * Gets start_date |
|
607 | + * |
|
608 | + * @param string $dt_frmt |
|
609 | + * @param string $tm_frmt |
|
610 | + * @return string |
|
611 | + * @throws EE_Error |
|
612 | + */ |
|
613 | + public function start_date($dt_frmt = '', $tm_frmt = '') |
|
614 | + { |
|
615 | + return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt); |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * Sets start_date |
|
621 | + * |
|
622 | + * @param string $start_date |
|
623 | + * @return void |
|
624 | + * @throws EE_Error |
|
625 | + */ |
|
626 | + public function set_start_date($start_date) |
|
627 | + { |
|
628 | + $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
629 | + } |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * Gets end_date |
|
634 | + * |
|
635 | + * @param string $dt_frmt |
|
636 | + * @param string $tm_frmt |
|
637 | + * @return string |
|
638 | + * @throws EE_Error |
|
639 | + */ |
|
640 | + public function end_date($dt_frmt = '', $tm_frmt = '') |
|
641 | + { |
|
642 | + return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt); |
|
643 | + } |
|
644 | + |
|
645 | + |
|
646 | + /** |
|
647 | + * Sets end_date |
|
648 | + * |
|
649 | + * @param string $end_date |
|
650 | + * @return void |
|
651 | + * @throws EE_Error |
|
652 | + */ |
|
653 | + public function set_end_date($end_date) |
|
654 | + { |
|
655 | + $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
656 | + } |
|
657 | + |
|
658 | + |
|
659 | + /** |
|
660 | + * Sets sell until time |
|
661 | + * |
|
662 | + * @since 4.5.0 |
|
663 | + * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
664 | + * @throws EE_Error |
|
665 | + */ |
|
666 | + public function set_end_time($time) |
|
667 | + { |
|
668 | + $this->_set_time_for($time, 'TKT_end_date'); |
|
669 | + } |
|
670 | + |
|
671 | + |
|
672 | + /** |
|
673 | + * Sets min |
|
674 | + * |
|
675 | + * @param int $min |
|
676 | + * @return void |
|
677 | + * @throws EE_Error |
|
678 | + */ |
|
679 | + public function set_min($min) |
|
680 | + { |
|
681 | + $this->set('TKT_min', $min); |
|
682 | + } |
|
683 | + |
|
684 | + |
|
685 | + /** |
|
686 | + * Gets max |
|
687 | + * |
|
688 | + * @return int |
|
689 | + * @throws EE_Error |
|
690 | + */ |
|
691 | + public function max() |
|
692 | + { |
|
693 | + return $this->get('TKT_max'); |
|
694 | + } |
|
695 | + |
|
696 | + |
|
697 | + /** |
|
698 | + * Sets max |
|
699 | + * |
|
700 | + * @param int $max |
|
701 | + * @return void |
|
702 | + * @throws EE_Error |
|
703 | + */ |
|
704 | + public function set_max($max) |
|
705 | + { |
|
706 | + $this->set('TKT_max', $max); |
|
707 | + } |
|
708 | + |
|
709 | + |
|
710 | + /** |
|
711 | + * Sets price |
|
712 | + * |
|
713 | + * @param float $price |
|
714 | + * @return void |
|
715 | + * @throws EE_Error |
|
716 | + */ |
|
717 | + public function set_price($price) |
|
718 | + { |
|
719 | + $this->set('TKT_price', $price); |
|
720 | + } |
|
721 | + |
|
722 | + |
|
723 | + /** |
|
724 | + * Gets sold |
|
725 | + * |
|
726 | + * @return int |
|
727 | + * @throws EE_Error |
|
728 | + */ |
|
729 | + public function sold() |
|
730 | + { |
|
731 | + return $this->get_raw('TKT_sold'); |
|
732 | + } |
|
733 | + |
|
734 | + |
|
735 | + /** |
|
736 | + * Sets sold |
|
737 | + * |
|
738 | + * @param int $sold |
|
739 | + * @return void |
|
740 | + * @throws EE_Error |
|
741 | + */ |
|
742 | + public function set_sold($sold) |
|
743 | + { |
|
744 | + // sold can not go below zero |
|
745 | + $sold = max(0, $sold); |
|
746 | + $this->set('TKT_sold', $sold); |
|
747 | + } |
|
748 | + |
|
749 | + |
|
750 | + /** |
|
751 | + * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
752 | + * associated datetimes. |
|
753 | + * |
|
754 | + * @since 4.9.80.p |
|
755 | + * @param int $qty |
|
756 | + * @return boolean |
|
757 | + * @throws EE_Error |
|
758 | + * @throws InvalidArgumentException |
|
759 | + * @throws InvalidDataTypeException |
|
760 | + * @throws InvalidInterfaceException |
|
761 | + * @throws ReflectionException |
|
762 | + */ |
|
763 | + public function increaseSold($qty = 1) |
|
764 | + { |
|
765 | + $qty = absint($qty); |
|
766 | + // increment sold and decrement reserved datetime quantities simultaneously |
|
767 | + // don't worry about failures, because they must have already had a spot reserved |
|
768 | + $this->increaseSoldForDatetimes($qty); |
|
769 | + // Increment and decrement ticket quantities simultaneously |
|
770 | + $success = $this->adjustNumericFieldsInDb( |
|
771 | + [ |
|
772 | + 'TKT_reserved' => $qty * -1, |
|
773 | + 'TKT_sold' => $qty |
|
774 | + ] |
|
775 | + ); |
|
776 | + do_action( |
|
777 | + 'AHEE__EE_Ticket__increase_sold', |
|
778 | + $this, |
|
779 | + $qty, |
|
780 | + $this->sold(), |
|
781 | + $success |
|
782 | + ); |
|
783 | + return $success; |
|
784 | + } |
|
785 | + |
|
786 | + /** |
|
787 | + * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
788 | + * |
|
789 | + * @since 4.9.80.p |
|
790 | + * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
|
791 | + * Negative means to decreases old counts (and increase reserved counts). |
|
792 | + * @param EE_Datetime[] $datetimes |
|
793 | + * @throws EE_Error |
|
794 | + * @throws InvalidArgumentException |
|
795 | + * @throws InvalidDataTypeException |
|
796 | + * @throws InvalidInterfaceException |
|
797 | + * @throws ReflectionException |
|
798 | + */ |
|
799 | + protected function increaseSoldForDatetimes($qty, array $datetimes = []) |
|
800 | + { |
|
801 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
802 | + foreach ($datetimes as $datetime) { |
|
803 | + $datetime->increaseSold($qty); |
|
804 | + } |
|
805 | + } |
|
806 | + |
|
807 | + |
|
808 | + |
|
809 | + /** |
|
810 | + * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
811 | + * DB and then updates the model objects. |
|
812 | + * Does not affect the reserved counts. |
|
813 | + * |
|
814 | + * @since 4.9.80.p |
|
815 | + * @param int $qty |
|
816 | + * @return boolean |
|
817 | + * @throws EE_Error |
|
818 | + * @throws InvalidArgumentException |
|
819 | + * @throws InvalidDataTypeException |
|
820 | + * @throws InvalidInterfaceException |
|
821 | + * @throws ReflectionException |
|
822 | + */ |
|
823 | + public function decreaseSold($qty = 1) |
|
824 | + { |
|
825 | + $qty = absint($qty); |
|
826 | + $this->decreaseSoldForDatetimes($qty); |
|
827 | + $success = $this->adjustNumericFieldsInDb( |
|
828 | + [ |
|
829 | + 'TKT_sold' => $qty * -1 |
|
830 | + ] |
|
831 | + ); |
|
832 | + do_action( |
|
833 | + 'AHEE__EE_Ticket__decrease_sold', |
|
834 | + $this, |
|
835 | + $qty, |
|
836 | + $this->sold(), |
|
837 | + $success |
|
838 | + ); |
|
839 | + return $success; |
|
840 | + } |
|
841 | + |
|
842 | + |
|
843 | + /** |
|
844 | + * Decreases sold on related datetimes |
|
845 | + * |
|
846 | + * @since 4.9.80.p |
|
847 | + * @param int $qty |
|
848 | + * @param EE_Datetime[] $datetimes |
|
849 | + * @return void |
|
850 | + * @throws EE_Error |
|
851 | + * @throws InvalidArgumentException |
|
852 | + * @throws InvalidDataTypeException |
|
853 | + * @throws InvalidInterfaceException |
|
854 | + * @throws ReflectionException |
|
855 | + */ |
|
856 | + protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = []) |
|
857 | + { |
|
858 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
859 | + if (is_array($datetimes)) { |
|
860 | + foreach ($datetimes as $datetime) { |
|
861 | + if ($datetime instanceof EE_Datetime) { |
|
862 | + $datetime->decreaseSold($qty); |
|
863 | + } |
|
864 | + } |
|
865 | + } |
|
866 | + } |
|
867 | + |
|
868 | + |
|
869 | + /** |
|
870 | + * Gets qty of reserved tickets |
|
871 | + * |
|
872 | + * @return int |
|
873 | + * @throws EE_Error |
|
874 | + */ |
|
875 | + public function reserved() |
|
876 | + { |
|
877 | + return $this->get_raw('TKT_reserved'); |
|
878 | + } |
|
879 | + |
|
880 | + |
|
881 | + /** |
|
882 | + * Sets reserved |
|
883 | + * |
|
884 | + * @param int $reserved |
|
885 | + * @return void |
|
886 | + * @throws EE_Error |
|
887 | + */ |
|
888 | + public function set_reserved($reserved) |
|
889 | + { |
|
890 | + // reserved can not go below zero |
|
891 | + $reserved = max(0, (int) $reserved); |
|
892 | + $this->set('TKT_reserved', $reserved); |
|
893 | + } |
|
894 | + |
|
895 | + |
|
896 | + /** |
|
897 | + * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
898 | + * |
|
899 | + * @since 4.9.80.p |
|
900 | + * @param int $qty |
|
901 | + * @param string $source |
|
902 | + * @return bool whether we successfully reserved the ticket or not. |
|
903 | + * @throws EE_Error |
|
904 | + * @throws InvalidArgumentException |
|
905 | + * @throws ReflectionException |
|
906 | + * @throws InvalidDataTypeException |
|
907 | + * @throws InvalidInterfaceException |
|
908 | + */ |
|
909 | + public function increaseReserved($qty = 1, $source = 'unknown') |
|
910 | + { |
|
911 | + $qty = absint($qty); |
|
912 | + do_action( |
|
913 | + 'AHEE__EE_Ticket__increase_reserved__begin', |
|
914 | + $this, |
|
915 | + $qty, |
|
916 | + $source |
|
917 | + ); |
|
918 | + $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "{$qty} from {$source}"); |
|
919 | + $success = false; |
|
920 | + $datetimes_adjusted_successfully = $this->increaseReservedForDatetimes($qty); |
|
921 | + if ($datetimes_adjusted_successfully) { |
|
922 | + $success = $this->incrementFieldConditionallyInDb( |
|
923 | + 'TKT_reserved', |
|
924 | + 'TKT_sold', |
|
925 | + 'TKT_qty', |
|
926 | + $qty |
|
927 | + ); |
|
928 | + if (! $success) { |
|
929 | + // The datetimes were successfully bumped, but not the |
|
930 | + // ticket. So we need to manually rollback the datetimes. |
|
931 | + $this->decreaseReservedForDatetimes($qty); |
|
932 | + } |
|
933 | + } |
|
934 | + do_action( |
|
935 | + 'AHEE__EE_Ticket__increase_reserved', |
|
936 | + $this, |
|
937 | + $qty, |
|
938 | + $this->reserved(), |
|
939 | + $success |
|
940 | + ); |
|
941 | + return $success; |
|
942 | + } |
|
943 | + |
|
944 | + |
|
945 | + /** |
|
946 | + * Increases reserved counts on related datetimes |
|
947 | + * |
|
948 | + * @since 4.9.80.p |
|
949 | + * @param int $qty |
|
950 | + * @param EE_Datetime[] $datetimes |
|
951 | + * @return boolean indicating success |
|
952 | + * @throws EE_Error |
|
953 | + * @throws InvalidArgumentException |
|
954 | + * @throws InvalidDataTypeException |
|
955 | + * @throws InvalidInterfaceException |
|
956 | + * @throws ReflectionException |
|
957 | + */ |
|
958 | + protected function increaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
959 | + { |
|
960 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
961 | + $datetimes_updated = []; |
|
962 | + $limit_exceeded = false; |
|
963 | + if (is_array($datetimes)) { |
|
964 | + foreach ($datetimes as $datetime) { |
|
965 | + if ($datetime instanceof EE_Datetime) { |
|
966 | + if ($datetime->increaseReserved($qty)) { |
|
967 | + $datetimes_updated[] = $datetime; |
|
968 | + } else { |
|
969 | + $limit_exceeded = true; |
|
970 | + break; |
|
971 | + } |
|
972 | + } |
|
973 | + } |
|
974 | + // If somewhere along the way we detected a datetime whose |
|
975 | + // limit was exceeded, do a manual rollback. |
|
976 | + if ($limit_exceeded) { |
|
977 | + $this->decreaseReservedForDatetimes($qty, $datetimes_updated); |
|
978 | + return false; |
|
979 | + } |
|
980 | + } |
|
981 | + return true; |
|
982 | + } |
|
983 | + |
|
984 | + |
|
985 | + /** |
|
986 | + * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
987 | + * |
|
988 | + * @since 4.9.80.p |
|
989 | + * @param int $qty |
|
990 | + * @param bool $adjust_datetimes |
|
991 | + * @param string $source |
|
992 | + * @return boolean |
|
993 | + * @throws EE_Error |
|
994 | + * @throws InvalidArgumentException |
|
995 | + * @throws ReflectionException |
|
996 | + * @throws InvalidDataTypeException |
|
997 | + * @throws InvalidInterfaceException |
|
998 | + */ |
|
999 | + public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
1000 | + { |
|
1001 | + $qty = absint($qty); |
|
1002 | + $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "-{$qty} from {$source}"); |
|
1003 | + if ($adjust_datetimes) { |
|
1004 | + $this->decreaseReservedForDatetimes($qty); |
|
1005 | + } |
|
1006 | + $success = $this->adjustNumericFieldsInDb( |
|
1007 | + [ |
|
1008 | + 'TKT_reserved' => $qty * -1 |
|
1009 | + ] |
|
1010 | + ); |
|
1011 | + do_action( |
|
1012 | + 'AHEE__EE_Ticket__decrease_reserved', |
|
1013 | + $this, |
|
1014 | + $qty, |
|
1015 | + $this->reserved(), |
|
1016 | + $success |
|
1017 | + ); |
|
1018 | + return $success; |
|
1019 | + } |
|
1020 | + |
|
1021 | + |
|
1022 | + /** |
|
1023 | + * Decreases the reserved count on the specified datetimes. |
|
1024 | + * |
|
1025 | + * @since 4.9.80.p |
|
1026 | + * @param int $qty |
|
1027 | + * @param EE_Datetime[] $datetimes |
|
1028 | + * @throws EE_Error |
|
1029 | + * @throws InvalidArgumentException |
|
1030 | + * @throws ReflectionException |
|
1031 | + * @throws InvalidDataTypeException |
|
1032 | + * @throws InvalidInterfaceException |
|
1033 | + */ |
|
1034 | + protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
1035 | + { |
|
1036 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
1037 | + foreach ($datetimes as $datetime) { |
|
1038 | + if ($datetime instanceof EE_Datetime) { |
|
1039 | + $datetime->decreaseReserved($qty); |
|
1040 | + } |
|
1041 | + } |
|
1042 | + } |
|
1043 | + |
|
1044 | + |
|
1045 | + /** |
|
1046 | + * Gets ticket quantity |
|
1047 | + * |
|
1048 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
1049 | + * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
1050 | + * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
1051 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
1052 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
1053 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
1054 | + * @return int |
|
1055 | + * @throws EE_Error |
|
1056 | + */ |
|
1057 | + public function qty($context = '') |
|
1058 | + { |
|
1059 | + switch ($context) { |
|
1060 | + case 'reg_limit': |
|
1061 | + return $this->real_quantity_on_ticket(); |
|
1062 | + case 'saleable': |
|
1063 | + return $this->real_quantity_on_ticket('saleable'); |
|
1064 | + default: |
|
1065 | + return $this->get_raw('TKT_qty'); |
|
1066 | + } |
|
1067 | + } |
|
1068 | + |
|
1069 | + |
|
1070 | + /** |
|
1071 | + * Gets ticket quantity |
|
1072 | + * |
|
1073 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
1074 | + * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
1075 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
1076 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
1077 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
1078 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
1079 | + * set to 0 for all related datetimes |
|
1080 | + * @return int |
|
1081 | + * @throws EE_Error |
|
1082 | + */ |
|
1083 | + public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
|
1084 | + { |
|
1085 | + $raw = $this->get_raw('TKT_qty'); |
|
1086 | + // return immediately if it's zero |
|
1087 | + if ($raw === 0) { |
|
1088 | + return $raw; |
|
1089 | + } |
|
1090 | + // echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
|
1091 | + // ensure qty doesn't exceed raw value for THIS ticket |
|
1092 | + $qty = min(EE_INF, $raw); |
|
1093 | + // echo "\n . qty: " . $qty . '<br />'; |
|
1094 | + // calculate this ticket's total sales and reservations |
|
1095 | + $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
|
1096 | + // echo "\n . sold: " . $this->sold() . '<br />'; |
|
1097 | + // echo "\n . reserved: " . $this->reserved() . '<br />'; |
|
1098 | + // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
|
1099 | + // first we need to calculate the maximum number of tickets available for the datetime |
|
1100 | + // do we want data for one datetime or all of them ? |
|
1101 | + $query_params = $DTT_ID ? array(array('DTT_ID' => $DTT_ID)) : array(); |
|
1102 | + $datetimes = $this->datetimes($query_params); |
|
1103 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
1104 | + foreach ($datetimes as $datetime) { |
|
1105 | + if ($datetime instanceof EE_Datetime) { |
|
1106 | + $datetime->refresh_from_db(); |
|
1107 | + // echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
|
1108 | + // echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
|
1109 | + // initialize with no restrictions for each datetime |
|
1110 | + // but adjust datetime qty based on datetime reg limit |
|
1111 | + $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
1112 | + // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
|
1113 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
1114 | + // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
|
1115 | + // and reservations for this datetime, that do NOT include sales and reservations |
|
1116 | + // for this ticket (so we add $this->sold() and $this->reserved() back in) |
|
1117 | + if ($context === 'saleable') { |
|
1118 | + $datetime_qty = max( |
|
1119 | + $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
|
1120 | + 0 |
|
1121 | + ); |
|
1122 | + // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />'; |
|
1123 | + // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />'; |
|
1124 | + // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />'; |
|
1125 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
1126 | + $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
|
1127 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
1128 | + } |
|
1129 | + $qty = min($datetime_qty, $qty); |
|
1130 | + // echo "\n . . qty: " . $qty . '<br />'; |
|
1131 | + } |
|
1132 | + } |
|
1133 | + } |
|
1134 | + // NOW that we know the maximum number of tickets available for the datetime |
|
1135 | + // we can finally factor in the details for this specific ticket |
|
1136 | + if ($qty > 0 && $context === 'saleable') { |
|
1137 | + // and subtract the sales for THIS ticket |
|
1138 | + $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
1139 | + // echo "\n . qty: " . $qty . '<br />'; |
|
1140 | + } |
|
1141 | + // echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
|
1142 | + return $qty; |
|
1143 | + } |
|
1144 | + |
|
1145 | + |
|
1146 | + /** |
|
1147 | + * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
|
1148 | + * |
|
1149 | + * @param int $qty |
|
1150 | + * @return void |
|
1151 | + * @throws EE_Error |
|
1152 | + */ |
|
1153 | + public function set_qty($qty) |
|
1154 | + { |
|
1155 | + $datetimes = $this->datetimes(); |
|
1156 | + foreach ($datetimes as $datetime) { |
|
1157 | + if ($datetime instanceof EE_Datetime) { |
|
1158 | + $qty = min($qty, $datetime->reg_limit()); |
|
1159 | + } |
|
1160 | + } |
|
1161 | + $this->set('TKT_qty', $qty); |
|
1162 | + } |
|
1163 | + |
|
1164 | + |
|
1165 | + /** |
|
1166 | + * Gets uses |
|
1167 | + * |
|
1168 | + * @return int |
|
1169 | + * @throws EE_Error |
|
1170 | + */ |
|
1171 | + public function uses() |
|
1172 | + { |
|
1173 | + return $this->get('TKT_uses'); |
|
1174 | + } |
|
1175 | + |
|
1176 | + |
|
1177 | + /** |
|
1178 | + * Sets uses |
|
1179 | + * |
|
1180 | + * @param int $uses |
|
1181 | + * @return void |
|
1182 | + * @throws EE_Error |
|
1183 | + */ |
|
1184 | + public function set_uses($uses) |
|
1185 | + { |
|
1186 | + $this->set('TKT_uses', $uses); |
|
1187 | + } |
|
1188 | + |
|
1189 | + |
|
1190 | + /** |
|
1191 | + * returns whether ticket is required or not. |
|
1192 | + * |
|
1193 | + * @return boolean |
|
1194 | + * @throws EE_Error |
|
1195 | + */ |
|
1196 | + public function required() |
|
1197 | + { |
|
1198 | + return $this->get('TKT_required'); |
|
1199 | + } |
|
1200 | + |
|
1201 | + |
|
1202 | + /** |
|
1203 | + * sets the TKT_required property |
|
1204 | + * |
|
1205 | + * @param boolean $required |
|
1206 | + * @return void |
|
1207 | + * @throws EE_Error |
|
1208 | + */ |
|
1209 | + public function set_required($required) |
|
1210 | + { |
|
1211 | + $this->set('TKT_required', $required); |
|
1212 | + } |
|
1213 | + |
|
1214 | + |
|
1215 | + /** |
|
1216 | + * Gets taxable |
|
1217 | + * |
|
1218 | + * @return boolean |
|
1219 | + * @throws EE_Error |
|
1220 | + */ |
|
1221 | + public function taxable() |
|
1222 | + { |
|
1223 | + return $this->get('TKT_taxable'); |
|
1224 | + } |
|
1225 | + |
|
1226 | + |
|
1227 | + /** |
|
1228 | + * Sets taxable |
|
1229 | + * |
|
1230 | + * @param boolean $taxable |
|
1231 | + * @return void |
|
1232 | + * @throws EE_Error |
|
1233 | + */ |
|
1234 | + public function set_taxable($taxable) |
|
1235 | + { |
|
1236 | + $this->set('TKT_taxable', $taxable); |
|
1237 | + } |
|
1238 | + |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * Gets is_default |
|
1242 | + * |
|
1243 | + * @return boolean |
|
1244 | + * @throws EE_Error |
|
1245 | + */ |
|
1246 | + public function is_default() |
|
1247 | + { |
|
1248 | + return $this->get('TKT_is_default'); |
|
1249 | + } |
|
1250 | + |
|
1251 | + |
|
1252 | + /** |
|
1253 | + * Sets is_default |
|
1254 | + * |
|
1255 | + * @param boolean $is_default |
|
1256 | + * @return void |
|
1257 | + * @throws EE_Error |
|
1258 | + */ |
|
1259 | + public function set_is_default($is_default) |
|
1260 | + { |
|
1261 | + $this->set('TKT_is_default', $is_default); |
|
1262 | + } |
|
1263 | + |
|
1264 | + |
|
1265 | + /** |
|
1266 | + * Gets order |
|
1267 | + * |
|
1268 | + * @return int |
|
1269 | + * @throws EE_Error |
|
1270 | + */ |
|
1271 | + public function order() |
|
1272 | + { |
|
1273 | + return $this->get('TKT_order'); |
|
1274 | + } |
|
1275 | + |
|
1276 | + |
|
1277 | + /** |
|
1278 | + * Sets order |
|
1279 | + * |
|
1280 | + * @param int $order |
|
1281 | + * @return void |
|
1282 | + * @throws EE_Error |
|
1283 | + */ |
|
1284 | + public function set_order($order) |
|
1285 | + { |
|
1286 | + $this->set('TKT_order', $order); |
|
1287 | + } |
|
1288 | + |
|
1289 | + |
|
1290 | + /** |
|
1291 | + * Gets row |
|
1292 | + * |
|
1293 | + * @return int |
|
1294 | + * @throws EE_Error |
|
1295 | + */ |
|
1296 | + public function row() |
|
1297 | + { |
|
1298 | + return $this->get('TKT_row'); |
|
1299 | + } |
|
1300 | + |
|
1301 | + |
|
1302 | + /** |
|
1303 | + * Sets row |
|
1304 | + * |
|
1305 | + * @param int $row |
|
1306 | + * @return void |
|
1307 | + * @throws EE_Error |
|
1308 | + */ |
|
1309 | + public function set_row($row) |
|
1310 | + { |
|
1311 | + $this->set('TKT_row', $row); |
|
1312 | + } |
|
1313 | + |
|
1314 | + |
|
1315 | + /** |
|
1316 | + * Gets deleted |
|
1317 | + * |
|
1318 | + * @return boolean |
|
1319 | + * @throws EE_Error |
|
1320 | + */ |
|
1321 | + public function deleted() |
|
1322 | + { |
|
1323 | + return $this->get('TKT_deleted'); |
|
1324 | + } |
|
1325 | + |
|
1326 | + |
|
1327 | + /** |
|
1328 | + * Sets deleted |
|
1329 | + * |
|
1330 | + * @param boolean $deleted |
|
1331 | + * @return void |
|
1332 | + * @throws EE_Error |
|
1333 | + */ |
|
1334 | + public function set_deleted($deleted) |
|
1335 | + { |
|
1336 | + $this->set('TKT_deleted', $deleted); |
|
1337 | + } |
|
1338 | + |
|
1339 | + |
|
1340 | + /** |
|
1341 | + * Gets parent |
|
1342 | + * |
|
1343 | + * @return int |
|
1344 | + * @throws EE_Error |
|
1345 | + */ |
|
1346 | + public function parent_ID() |
|
1347 | + { |
|
1348 | + return $this->get('TKT_parent'); |
|
1349 | + } |
|
1350 | + |
|
1351 | + |
|
1352 | + /** |
|
1353 | + * Sets parent |
|
1354 | + * |
|
1355 | + * @param int $parent |
|
1356 | + * @return void |
|
1357 | + * @throws EE_Error |
|
1358 | + */ |
|
1359 | + public function set_parent_ID($parent) |
|
1360 | + { |
|
1361 | + $this->set('TKT_parent', $parent); |
|
1362 | + } |
|
1363 | + |
|
1364 | + |
|
1365 | + /** |
|
1366 | + * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
1367 | + * |
|
1368 | + * @return string |
|
1369 | + * @throws EE_Error |
|
1370 | + */ |
|
1371 | + public function name_and_info() |
|
1372 | + { |
|
1373 | + $times = array(); |
|
1374 | + foreach ($this->datetimes() as $datetime) { |
|
1375 | + $times[] = $datetime->start_date_and_time(); |
|
1376 | + } |
|
1377 | + return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
1378 | + } |
|
1379 | + |
|
1380 | + |
|
1381 | + /** |
|
1382 | + * Gets name |
|
1383 | + * |
|
1384 | + * @return string |
|
1385 | + * @throws EE_Error |
|
1386 | + */ |
|
1387 | + public function name() |
|
1388 | + { |
|
1389 | + return $this->get('TKT_name'); |
|
1390 | + } |
|
1391 | + |
|
1392 | + |
|
1393 | + /** |
|
1394 | + * Gets price |
|
1395 | + * |
|
1396 | + * @return float |
|
1397 | + * @throws EE_Error |
|
1398 | + */ |
|
1399 | + public function price() |
|
1400 | + { |
|
1401 | + return $this->get('TKT_price'); |
|
1402 | + } |
|
1403 | + |
|
1404 | + |
|
1405 | + /** |
|
1406 | + * Gets all the registrations for this ticket |
|
1407 | + * |
|
1408 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1409 | + * @return EE_Registration[]|EE_Base_Class[] |
|
1410 | + * @throws EE_Error |
|
1411 | + */ |
|
1412 | + public function registrations($query_params = array()) |
|
1413 | + { |
|
1414 | + return $this->get_many_related('Registration', $query_params); |
|
1415 | + } |
|
1416 | + |
|
1417 | + |
|
1418 | + /** |
|
1419 | + * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
1420 | + * |
|
1421 | + * @return int |
|
1422 | + * @throws EE_Error |
|
1423 | + */ |
|
1424 | + public function update_tickets_sold() |
|
1425 | + { |
|
1426 | + $count_regs_for_this_ticket = $this->count_registrations( |
|
1427 | + array( |
|
1428 | + array( |
|
1429 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
1430 | + 'REG_deleted' => 0, |
|
1431 | + ), |
|
1432 | + ) |
|
1433 | + ); |
|
1434 | + $this->set_sold($count_regs_for_this_ticket); |
|
1435 | + $this->save(); |
|
1436 | + return $count_regs_for_this_ticket; |
|
1437 | + } |
|
1438 | + |
|
1439 | + |
|
1440 | + /** |
|
1441 | + * Counts the registrations for this ticket |
|
1442 | + * |
|
1443 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1444 | + * @return int |
|
1445 | + */ |
|
1446 | + public function count_registrations($query_params = array()) |
|
1447 | + { |
|
1448 | + return $this->count_related('Registration', $query_params); |
|
1449 | + } |
|
1450 | + |
|
1451 | + |
|
1452 | + /** |
|
1453 | + * Implementation for EEI_Has_Icon interface method. |
|
1454 | + * |
|
1455 | + * @see EEI_Visual_Representation for comments |
|
1456 | + * @return string |
|
1457 | + */ |
|
1458 | + public function get_icon() |
|
1459 | + { |
|
1460 | + return '<span class="dashicons dashicons-tickets-alt"></span>'; |
|
1461 | + } |
|
1462 | + |
|
1463 | + |
|
1464 | + /** |
|
1465 | + * Implementation of the EEI_Event_Relation interface method |
|
1466 | + * |
|
1467 | + * @see EEI_Event_Relation for comments |
|
1468 | + * @return EE_Event |
|
1469 | + * @throws EE_Error |
|
1470 | + * @throws UnexpectedEntityException |
|
1471 | + */ |
|
1472 | + public function get_related_event() |
|
1473 | + { |
|
1474 | + // get one datetime to use for getting the event |
|
1475 | + $datetime = $this->first_datetime(); |
|
1476 | + if (! $datetime instanceof \EE_Datetime) { |
|
1477 | + throw new UnexpectedEntityException( |
|
1478 | + $datetime, |
|
1479 | + 'EE_Datetime', |
|
1480 | + sprintf( |
|
1481 | + __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
1482 | + $this->name() |
|
1483 | + ) |
|
1484 | + ); |
|
1485 | + } |
|
1486 | + $event = $datetime->event(); |
|
1487 | + if (! $event instanceof \EE_Event) { |
|
1488 | + throw new UnexpectedEntityException( |
|
1489 | + $event, |
|
1490 | + 'EE_Event', |
|
1491 | + sprintf( |
|
1492 | + __('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
1493 | + $this->name() |
|
1494 | + ) |
|
1495 | + ); |
|
1496 | + } |
|
1497 | + return $event; |
|
1498 | + } |
|
1499 | + |
|
1500 | + |
|
1501 | + /** |
|
1502 | + * Implementation of the EEI_Event_Relation interface method |
|
1503 | + * |
|
1504 | + * @see EEI_Event_Relation for comments |
|
1505 | + * @return string |
|
1506 | + * @throws UnexpectedEntityException |
|
1507 | + * @throws EE_Error |
|
1508 | + */ |
|
1509 | + public function get_event_name() |
|
1510 | + { |
|
1511 | + $event = $this->get_related_event(); |
|
1512 | + return $event instanceof EE_Event ? $event->name() : ''; |
|
1513 | + } |
|
1514 | + |
|
1515 | + |
|
1516 | + /** |
|
1517 | + * Implementation of the EEI_Event_Relation interface method |
|
1518 | + * |
|
1519 | + * @see EEI_Event_Relation for comments |
|
1520 | + * @return int |
|
1521 | + * @throws UnexpectedEntityException |
|
1522 | + * @throws EE_Error |
|
1523 | + */ |
|
1524 | + public function get_event_ID() |
|
1525 | + { |
|
1526 | + $event = $this->get_related_event(); |
|
1527 | + return $event instanceof EE_Event ? $event->ID() : 0; |
|
1528 | + } |
|
1529 | + |
|
1530 | + |
|
1531 | + /** |
|
1532 | + * This simply returns whether a ticket can be permanently deleted or not. |
|
1533 | + * The criteria for determining this is whether the ticket has any related registrations. |
|
1534 | + * If there are none then it can be permanently deleted. |
|
1535 | + * |
|
1536 | + * @return bool |
|
1537 | + */ |
|
1538 | + public function is_permanently_deleteable() |
|
1539 | + { |
|
1540 | + return $this->count_registrations() === 0; |
|
1541 | + } |
|
1542 | + |
|
1543 | + |
|
1544 | + /******************************************************************* |
|
1545 | 1545 | *********************** DEPRECATED METHODS ********************** |
1546 | 1546 | *******************************************************************/ |
1547 | 1547 | |
1548 | 1548 | |
1549 | - /** |
|
1550 | - * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
1551 | - * associated datetimes. |
|
1552 | - * |
|
1553 | - * @deprecated 4.9.80.p |
|
1554 | - * @param int $qty |
|
1555 | - * @return void |
|
1556 | - * @throws EE_Error |
|
1557 | - * @throws InvalidArgumentException |
|
1558 | - * @throws InvalidDataTypeException |
|
1559 | - * @throws InvalidInterfaceException |
|
1560 | - * @throws ReflectionException |
|
1561 | - */ |
|
1562 | - public function increase_sold($qty = 1) |
|
1563 | - { |
|
1564 | - EE_Error::doing_it_wrong( |
|
1565 | - __FUNCTION__, |
|
1566 | - esc_html__('Please use EE_Ticket::increaseSold() instead', 'event_espresso'), |
|
1567 | - '4.9.80.p', |
|
1568 | - '5.0.0.p' |
|
1569 | - ); |
|
1570 | - $this->increaseSold($qty); |
|
1571 | - } |
|
1572 | - |
|
1573 | - |
|
1574 | - /** |
|
1575 | - * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
1576 | - * |
|
1577 | - * @deprecated 4.9.80.p |
|
1578 | - * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
|
1579 | - * Negative means to decreases old counts (and increase reserved counts). |
|
1580 | - * @throws EE_Error |
|
1581 | - * @throws InvalidArgumentException |
|
1582 | - * @throws InvalidDataTypeException |
|
1583 | - * @throws InvalidInterfaceException |
|
1584 | - * @throws ReflectionException |
|
1585 | - */ |
|
1586 | - protected function _increase_sold_for_datetimes($qty) |
|
1587 | - { |
|
1588 | - EE_Error::doing_it_wrong( |
|
1589 | - __FUNCTION__, |
|
1590 | - esc_html__('Please use EE_Ticket::increaseSoldForDatetimes() instead', 'event_espresso'), |
|
1591 | - '4.9.80.p', |
|
1592 | - '5.0.0.p' |
|
1593 | - ); |
|
1594 | - $this->increaseSoldForDatetimes($qty); |
|
1595 | - } |
|
1596 | - |
|
1597 | - |
|
1598 | - /** |
|
1599 | - * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
1600 | - * DB and then updates the model objects. |
|
1601 | - * Does not affect the reserved counts. |
|
1602 | - * |
|
1603 | - * @deprecated 4.9.80.p |
|
1604 | - * @param int $qty |
|
1605 | - * @return void |
|
1606 | - * @throws EE_Error |
|
1607 | - * @throws InvalidArgumentException |
|
1608 | - * @throws InvalidDataTypeException |
|
1609 | - * @throws InvalidInterfaceException |
|
1610 | - * @throws ReflectionException |
|
1611 | - */ |
|
1612 | - public function decrease_sold($qty = 1) |
|
1613 | - { |
|
1614 | - EE_Error::doing_it_wrong( |
|
1615 | - __FUNCTION__, |
|
1616 | - esc_html__('Please use EE_Ticket::decreaseSold() instead', 'event_espresso'), |
|
1617 | - '4.9.80.p', |
|
1618 | - '5.0.0.p' |
|
1619 | - ); |
|
1620 | - $this->decreaseSold($qty); |
|
1621 | - } |
|
1622 | - |
|
1623 | - |
|
1624 | - /** |
|
1625 | - * Decreases sold on related datetimes |
|
1626 | - * |
|
1627 | - * @deprecated 4.9.80.p |
|
1628 | - * @param int $qty |
|
1629 | - * @return void |
|
1630 | - * @throws EE_Error |
|
1631 | - * @throws InvalidArgumentException |
|
1632 | - * @throws InvalidDataTypeException |
|
1633 | - * @throws InvalidInterfaceException |
|
1634 | - * @throws ReflectionException |
|
1635 | - */ |
|
1636 | - protected function _decrease_sold_for_datetimes($qty = 1) |
|
1637 | - { |
|
1638 | - EE_Error::doing_it_wrong( |
|
1639 | - __FUNCTION__, |
|
1640 | - esc_html__('Please use EE_Ticket::decreaseSoldForDatetimes() instead', 'event_espresso'), |
|
1641 | - '4.9.80.p', |
|
1642 | - '5.0.0.p' |
|
1643 | - ); |
|
1644 | - $this->decreaseSoldForDatetimes($qty); |
|
1645 | - } |
|
1646 | - |
|
1647 | - |
|
1648 | - /** |
|
1649 | - * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
1650 | - * |
|
1651 | - * @deprecated 4.9.80.p |
|
1652 | - * @param int $qty |
|
1653 | - * @param string $source |
|
1654 | - * @return bool whether we successfully reserved the ticket or not. |
|
1655 | - * @throws EE_Error |
|
1656 | - * @throws InvalidArgumentException |
|
1657 | - * @throws ReflectionException |
|
1658 | - * @throws InvalidDataTypeException |
|
1659 | - * @throws InvalidInterfaceException |
|
1660 | - */ |
|
1661 | - public function increase_reserved($qty = 1, $source = 'unknown') |
|
1662 | - { |
|
1663 | - EE_Error::doing_it_wrong( |
|
1664 | - __FUNCTION__, |
|
1665 | - esc_html__('Please use EE_Ticket::increaseReserved() instead', 'event_espresso'), |
|
1666 | - '4.9.80.p', |
|
1667 | - '5.0.0.p' |
|
1668 | - ); |
|
1669 | - return $this->increaseReserved($qty); |
|
1670 | - } |
|
1671 | - |
|
1672 | - |
|
1673 | - /** |
|
1674 | - * Increases sold on related datetimes |
|
1675 | - * |
|
1676 | - * @deprecated 4.9.80.p |
|
1677 | - * @param int $qty |
|
1678 | - * @return boolean indicating success |
|
1679 | - * @throws EE_Error |
|
1680 | - * @throws InvalidArgumentException |
|
1681 | - * @throws InvalidDataTypeException |
|
1682 | - * @throws InvalidInterfaceException |
|
1683 | - * @throws ReflectionException |
|
1684 | - */ |
|
1685 | - protected function _increase_reserved_for_datetimes($qty = 1) |
|
1686 | - { |
|
1687 | - EE_Error::doing_it_wrong( |
|
1688 | - __FUNCTION__, |
|
1689 | - esc_html__('Please use EE_Ticket::increaseReservedForDatetimes() instead', 'event_espresso'), |
|
1690 | - '4.9.80.p', |
|
1691 | - '5.0.0.p' |
|
1692 | - ); |
|
1693 | - return $this->increaseReservedForDatetimes($qty); |
|
1694 | - } |
|
1695 | - |
|
1696 | - |
|
1697 | - /** |
|
1698 | - * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
1699 | - * |
|
1700 | - * @deprecated 4.9.80.p |
|
1701 | - * @param int $qty |
|
1702 | - * @param bool $adjust_datetimes |
|
1703 | - * @param string $source |
|
1704 | - * @return void |
|
1705 | - * @throws EE_Error |
|
1706 | - * @throws InvalidArgumentException |
|
1707 | - * @throws ReflectionException |
|
1708 | - * @throws InvalidDataTypeException |
|
1709 | - * @throws InvalidInterfaceException |
|
1710 | - */ |
|
1711 | - public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
1712 | - { |
|
1713 | - EE_Error::doing_it_wrong( |
|
1714 | - __FUNCTION__, |
|
1715 | - esc_html__('Please use EE_Ticket::decreaseReserved() instead', 'event_espresso'), |
|
1716 | - '4.9.80.p', |
|
1717 | - '5.0.0.p' |
|
1718 | - ); |
|
1719 | - $this->decreaseReserved($qty); |
|
1720 | - } |
|
1721 | - |
|
1722 | - |
|
1723 | - /** |
|
1724 | - * Decreases reserved on related datetimes |
|
1725 | - * |
|
1726 | - * @deprecated 4.9.80.p |
|
1727 | - * @param int $qty |
|
1728 | - * @return void |
|
1729 | - * @throws EE_Error |
|
1730 | - * @throws InvalidArgumentException |
|
1731 | - * @throws ReflectionException |
|
1732 | - * @throws InvalidDataTypeException |
|
1733 | - * @throws InvalidInterfaceException |
|
1734 | - */ |
|
1735 | - protected function _decrease_reserved_for_datetimes($qty = 1) |
|
1736 | - { |
|
1737 | - EE_Error::doing_it_wrong( |
|
1738 | - __FUNCTION__, |
|
1739 | - esc_html__('Please use EE_Ticket::decreaseReservedForDatetimes() instead', 'event_espresso'), |
|
1740 | - '4.9.80.p', |
|
1741 | - '5.0.0.p' |
|
1742 | - ); |
|
1743 | - $this->decreaseReservedForDatetimes($qty); |
|
1744 | - } |
|
1549 | + /** |
|
1550 | + * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
1551 | + * associated datetimes. |
|
1552 | + * |
|
1553 | + * @deprecated 4.9.80.p |
|
1554 | + * @param int $qty |
|
1555 | + * @return void |
|
1556 | + * @throws EE_Error |
|
1557 | + * @throws InvalidArgumentException |
|
1558 | + * @throws InvalidDataTypeException |
|
1559 | + * @throws InvalidInterfaceException |
|
1560 | + * @throws ReflectionException |
|
1561 | + */ |
|
1562 | + public function increase_sold($qty = 1) |
|
1563 | + { |
|
1564 | + EE_Error::doing_it_wrong( |
|
1565 | + __FUNCTION__, |
|
1566 | + esc_html__('Please use EE_Ticket::increaseSold() instead', 'event_espresso'), |
|
1567 | + '4.9.80.p', |
|
1568 | + '5.0.0.p' |
|
1569 | + ); |
|
1570 | + $this->increaseSold($qty); |
|
1571 | + } |
|
1572 | + |
|
1573 | + |
|
1574 | + /** |
|
1575 | + * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
1576 | + * |
|
1577 | + * @deprecated 4.9.80.p |
|
1578 | + * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
|
1579 | + * Negative means to decreases old counts (and increase reserved counts). |
|
1580 | + * @throws EE_Error |
|
1581 | + * @throws InvalidArgumentException |
|
1582 | + * @throws InvalidDataTypeException |
|
1583 | + * @throws InvalidInterfaceException |
|
1584 | + * @throws ReflectionException |
|
1585 | + */ |
|
1586 | + protected function _increase_sold_for_datetimes($qty) |
|
1587 | + { |
|
1588 | + EE_Error::doing_it_wrong( |
|
1589 | + __FUNCTION__, |
|
1590 | + esc_html__('Please use EE_Ticket::increaseSoldForDatetimes() instead', 'event_espresso'), |
|
1591 | + '4.9.80.p', |
|
1592 | + '5.0.0.p' |
|
1593 | + ); |
|
1594 | + $this->increaseSoldForDatetimes($qty); |
|
1595 | + } |
|
1596 | + |
|
1597 | + |
|
1598 | + /** |
|
1599 | + * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
1600 | + * DB and then updates the model objects. |
|
1601 | + * Does not affect the reserved counts. |
|
1602 | + * |
|
1603 | + * @deprecated 4.9.80.p |
|
1604 | + * @param int $qty |
|
1605 | + * @return void |
|
1606 | + * @throws EE_Error |
|
1607 | + * @throws InvalidArgumentException |
|
1608 | + * @throws InvalidDataTypeException |
|
1609 | + * @throws InvalidInterfaceException |
|
1610 | + * @throws ReflectionException |
|
1611 | + */ |
|
1612 | + public function decrease_sold($qty = 1) |
|
1613 | + { |
|
1614 | + EE_Error::doing_it_wrong( |
|
1615 | + __FUNCTION__, |
|
1616 | + esc_html__('Please use EE_Ticket::decreaseSold() instead', 'event_espresso'), |
|
1617 | + '4.9.80.p', |
|
1618 | + '5.0.0.p' |
|
1619 | + ); |
|
1620 | + $this->decreaseSold($qty); |
|
1621 | + } |
|
1622 | + |
|
1623 | + |
|
1624 | + /** |
|
1625 | + * Decreases sold on related datetimes |
|
1626 | + * |
|
1627 | + * @deprecated 4.9.80.p |
|
1628 | + * @param int $qty |
|
1629 | + * @return void |
|
1630 | + * @throws EE_Error |
|
1631 | + * @throws InvalidArgumentException |
|
1632 | + * @throws InvalidDataTypeException |
|
1633 | + * @throws InvalidInterfaceException |
|
1634 | + * @throws ReflectionException |
|
1635 | + */ |
|
1636 | + protected function _decrease_sold_for_datetimes($qty = 1) |
|
1637 | + { |
|
1638 | + EE_Error::doing_it_wrong( |
|
1639 | + __FUNCTION__, |
|
1640 | + esc_html__('Please use EE_Ticket::decreaseSoldForDatetimes() instead', 'event_espresso'), |
|
1641 | + '4.9.80.p', |
|
1642 | + '5.0.0.p' |
|
1643 | + ); |
|
1644 | + $this->decreaseSoldForDatetimes($qty); |
|
1645 | + } |
|
1646 | + |
|
1647 | + |
|
1648 | + /** |
|
1649 | + * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
1650 | + * |
|
1651 | + * @deprecated 4.9.80.p |
|
1652 | + * @param int $qty |
|
1653 | + * @param string $source |
|
1654 | + * @return bool whether we successfully reserved the ticket or not. |
|
1655 | + * @throws EE_Error |
|
1656 | + * @throws InvalidArgumentException |
|
1657 | + * @throws ReflectionException |
|
1658 | + * @throws InvalidDataTypeException |
|
1659 | + * @throws InvalidInterfaceException |
|
1660 | + */ |
|
1661 | + public function increase_reserved($qty = 1, $source = 'unknown') |
|
1662 | + { |
|
1663 | + EE_Error::doing_it_wrong( |
|
1664 | + __FUNCTION__, |
|
1665 | + esc_html__('Please use EE_Ticket::increaseReserved() instead', 'event_espresso'), |
|
1666 | + '4.9.80.p', |
|
1667 | + '5.0.0.p' |
|
1668 | + ); |
|
1669 | + return $this->increaseReserved($qty); |
|
1670 | + } |
|
1671 | + |
|
1672 | + |
|
1673 | + /** |
|
1674 | + * Increases sold on related datetimes |
|
1675 | + * |
|
1676 | + * @deprecated 4.9.80.p |
|
1677 | + * @param int $qty |
|
1678 | + * @return boolean indicating success |
|
1679 | + * @throws EE_Error |
|
1680 | + * @throws InvalidArgumentException |
|
1681 | + * @throws InvalidDataTypeException |
|
1682 | + * @throws InvalidInterfaceException |
|
1683 | + * @throws ReflectionException |
|
1684 | + */ |
|
1685 | + protected function _increase_reserved_for_datetimes($qty = 1) |
|
1686 | + { |
|
1687 | + EE_Error::doing_it_wrong( |
|
1688 | + __FUNCTION__, |
|
1689 | + esc_html__('Please use EE_Ticket::increaseReservedForDatetimes() instead', 'event_espresso'), |
|
1690 | + '4.9.80.p', |
|
1691 | + '5.0.0.p' |
|
1692 | + ); |
|
1693 | + return $this->increaseReservedForDatetimes($qty); |
|
1694 | + } |
|
1695 | + |
|
1696 | + |
|
1697 | + /** |
|
1698 | + * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
1699 | + * |
|
1700 | + * @deprecated 4.9.80.p |
|
1701 | + * @param int $qty |
|
1702 | + * @param bool $adjust_datetimes |
|
1703 | + * @param string $source |
|
1704 | + * @return void |
|
1705 | + * @throws EE_Error |
|
1706 | + * @throws InvalidArgumentException |
|
1707 | + * @throws ReflectionException |
|
1708 | + * @throws InvalidDataTypeException |
|
1709 | + * @throws InvalidInterfaceException |
|
1710 | + */ |
|
1711 | + public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
1712 | + { |
|
1713 | + EE_Error::doing_it_wrong( |
|
1714 | + __FUNCTION__, |
|
1715 | + esc_html__('Please use EE_Ticket::decreaseReserved() instead', 'event_espresso'), |
|
1716 | + '4.9.80.p', |
|
1717 | + '5.0.0.p' |
|
1718 | + ); |
|
1719 | + $this->decreaseReserved($qty); |
|
1720 | + } |
|
1721 | + |
|
1722 | + |
|
1723 | + /** |
|
1724 | + * Decreases reserved on related datetimes |
|
1725 | + * |
|
1726 | + * @deprecated 4.9.80.p |
|
1727 | + * @param int $qty |
|
1728 | + * @return void |
|
1729 | + * @throws EE_Error |
|
1730 | + * @throws InvalidArgumentException |
|
1731 | + * @throws ReflectionException |
|
1732 | + * @throws InvalidDataTypeException |
|
1733 | + * @throws InvalidInterfaceException |
|
1734 | + */ |
|
1735 | + protected function _decrease_reserved_for_datetimes($qty = 1) |
|
1736 | + { |
|
1737 | + EE_Error::doing_it_wrong( |
|
1738 | + __FUNCTION__, |
|
1739 | + esc_html__('Please use EE_Ticket::decreaseReservedForDatetimes() instead', 'event_espresso'), |
|
1740 | + '4.9.80.p', |
|
1741 | + '5.0.0.p' |
|
1742 | + ); |
|
1743 | + $this->decreaseReservedForDatetimes($qty); |
|
1744 | + } |
|
1745 | 1745 | } |