@@ -12,1411 +12,1411 @@ |
||
12 | 12 | class Pricing_Admin_Page extends EE_Admin_Page |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * constructor |
|
17 | - * |
|
18 | - * @Constructor |
|
19 | - * @access public |
|
20 | - * @param bool $routing |
|
21 | - * @return Pricing_Admin_Page |
|
22 | - */ |
|
23 | - public function __construct($routing = true) |
|
24 | - { |
|
25 | - parent::__construct($routing); |
|
26 | - } |
|
27 | - |
|
28 | - |
|
29 | - protected function _init_page_props() |
|
30 | - { |
|
31 | - $this->page_slug = PRICING_PG_SLUG; |
|
32 | - $this->page_label = PRICING_LABEL; |
|
33 | - $this->_admin_base_url = PRICING_ADMIN_URL; |
|
34 | - $this->_admin_base_path = PRICING_ADMIN; |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - protected function _ajax_hooks() |
|
39 | - { |
|
40 | - add_action('wp_ajax_espresso_update_prices_order', array($this, 'update_price_order')); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - protected function _define_page_props() |
|
45 | - { |
|
46 | - $this->_admin_page_title = PRICING_LABEL; |
|
47 | - $this->_labels = array( |
|
48 | - 'buttons' => array( |
|
49 | - 'add' => esc_html__('Add New Default Price', 'event_espresso'), |
|
50 | - 'edit' => esc_html__('Edit Default Price', 'event_espresso'), |
|
51 | - 'delete' => esc_html__('Delete Default Price', 'event_espresso'), |
|
52 | - 'add_type' => esc_html__('Add New Default Price Type', 'event_espresso'), |
|
53 | - 'edit_type' => esc_html__('Edit Price Type', 'event_espresso'), |
|
54 | - 'delete_type' => esc_html__('Delete Price Type', 'event_espresso'), |
|
55 | - ), |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * an array for storing request actions and their corresponding methods |
|
62 | - * |
|
63 | - * @access private |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - protected function _set_page_routes() |
|
67 | - { |
|
68 | - $prc_id = ! empty($this->_req_data['PRC_ID']) && ! is_array($this->_req_data['PRC_ID']) |
|
69 | - ? $this->_req_data['PRC_ID'] : 0; |
|
70 | - $prt_id = ! empty($this->_req_data['PRT_ID']) && ! is_array($this->_req_data['PRT_ID']) |
|
71 | - ? $this->_req_data['PRT_ID'] : 0; |
|
72 | - $this->_page_routes = array( |
|
73 | - 'default' => array( |
|
74 | - 'func' => '_price_overview_list_table', |
|
75 | - 'capability' => 'ee_read_default_prices', |
|
76 | - ), |
|
77 | - 'add_new_price' => array( |
|
78 | - 'func' => '_edit_price_details', |
|
79 | - 'args' => array('new_price' => true), |
|
80 | - 'capability' => 'ee_edit_default_prices', |
|
81 | - ), |
|
82 | - 'edit_price' => array( |
|
83 | - 'func' => '_edit_price_details', |
|
84 | - 'args' => array('new_price' => false), |
|
85 | - 'capability' => 'ee_edit_default_price', |
|
86 | - 'obj_id' => $prc_id, |
|
87 | - ), |
|
88 | - 'insert_price' => array( |
|
89 | - 'func' => '_insert_or_update_price', |
|
90 | - 'args' => array('new_price' => true), |
|
91 | - 'noheader' => true, |
|
92 | - 'capability' => 'ee_edit_default_prices', |
|
93 | - ), |
|
94 | - 'update_price' => array( |
|
95 | - 'func' => '_insert_or_update_price', |
|
96 | - 'args' => array('new_price' => false), |
|
97 | - 'noheader' => true, |
|
98 | - 'capability' => 'ee_edit_default_price', |
|
99 | - 'obj_id' => $prc_id, |
|
100 | - ), |
|
101 | - 'trash_price' => array( |
|
102 | - 'func' => '_trash_or_restore_price', |
|
103 | - 'args' => array('trash' => true), |
|
104 | - 'noheader' => true, |
|
105 | - 'capability' => 'ee_delete_default_price', |
|
106 | - 'obj_id' => $prc_id, |
|
107 | - ), |
|
108 | - 'restore_price' => array( |
|
109 | - 'func' => '_trash_or_restore_price', |
|
110 | - 'args' => array('trash' => false), |
|
111 | - 'noheader' => true, |
|
112 | - 'capability' => 'ee_delete_default_price', |
|
113 | - 'obj_id' => $prc_id, |
|
114 | - ), |
|
115 | - 'delete_price' => array( |
|
116 | - 'func' => '_delete_price', |
|
117 | - 'noheader' => true, |
|
118 | - 'capability' => 'ee_delete_default_price', |
|
119 | - 'obj_id' => $prc_id, |
|
120 | - ), |
|
121 | - 'espresso_update_price_order' => array( |
|
122 | - 'func' => 'update_price_order', |
|
123 | - 'noheader' => true, |
|
124 | - 'capability' => 'ee_edit_default_prices', |
|
125 | - ), |
|
126 | - // price types |
|
127 | - 'price_types' => array( |
|
128 | - 'func' => '_price_types_overview_list_table', |
|
129 | - 'capability' => 'ee_read_default_price_types', |
|
130 | - ), |
|
131 | - 'add_new_price_type' => array( |
|
132 | - 'func' => '_edit_price_type_details', |
|
133 | - 'capability' => 'ee_edit_default_price_types', |
|
134 | - ), |
|
135 | - 'edit_price_type' => array( |
|
136 | - 'func' => '_edit_price_type_details', |
|
137 | - 'capability' => 'ee_edit_default_price_type', |
|
138 | - 'obj_id' => $prt_id, |
|
139 | - ), |
|
140 | - 'insert_price_type' => array( |
|
141 | - 'func' => '_insert_or_update_price_type', |
|
142 | - 'args' => array('new_price_type' => true), |
|
143 | - 'noheader' => true, |
|
144 | - 'capability' => 'ee_edit_default_price_types', |
|
145 | - ), |
|
146 | - 'update_price_type' => array( |
|
147 | - 'func' => '_insert_or_update_price_type', |
|
148 | - 'args' => array('new_price_type' => false), |
|
149 | - 'noheader' => true, |
|
150 | - 'capability' => 'ee_edit_default_price_type', |
|
151 | - 'obj_id' => $prt_id, |
|
152 | - ), |
|
153 | - 'trash_price_type' => array( |
|
154 | - 'func' => '_trash_or_restore_price_type', |
|
155 | - 'args' => array('trash' => true), |
|
156 | - 'noheader' => true, |
|
157 | - 'capability' => 'ee_delete_default_price_type', |
|
158 | - 'obj_id' => $prt_id, |
|
159 | - ), |
|
160 | - 'restore_price_type' => array( |
|
161 | - 'func' => '_trash_or_restore_price_type', |
|
162 | - 'args' => array('trash' => false), |
|
163 | - 'noheader' => true, |
|
164 | - 'capability' => 'ee_delete_default_price_type', |
|
165 | - 'obj_id' => $prt_id, |
|
166 | - ), |
|
167 | - 'delete_price_type' => array( |
|
168 | - 'func' => '_delete_price_type', |
|
169 | - 'noheader' => true, |
|
170 | - 'capability' => 'ee_delete_default_price_type', |
|
171 | - 'obj_id' => $prt_id, |
|
172 | - ), |
|
173 | - 'tax_settings' => array( |
|
174 | - 'func' => '_tax_settings', |
|
175 | - 'capability' => 'manage_options', |
|
176 | - ), |
|
177 | - 'update_tax_settings' => array( |
|
178 | - 'func' => '_update_tax_settings', |
|
179 | - 'capability' => 'manage_options', |
|
180 | - 'noheader' => true, |
|
181 | - ), |
|
182 | - ); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - protected function _set_page_config() |
|
187 | - { |
|
188 | - |
|
189 | - $this->_page_config = array( |
|
190 | - 'default' => array( |
|
191 | - 'nav' => array( |
|
192 | - 'label' => esc_html__('Default Pricing', 'event_espresso'), |
|
193 | - 'order' => 10, |
|
194 | - ), |
|
195 | - 'list_table' => 'Prices_List_Table', |
|
196 | - 'help_tabs' => array( |
|
197 | - 'pricing_default_pricing_help_tab' => array( |
|
198 | - 'title' => esc_html__('Default Pricing', 'event_espresso'), |
|
199 | - 'filename' => 'pricing_default_pricing', |
|
200 | - ), |
|
201 | - 'pricing_default_pricing_table_column_headings_help_tab' => array( |
|
202 | - 'title' => esc_html__('Default Pricing Table Column Headings', 'event_espresso'), |
|
203 | - 'filename' => 'pricing_default_pricing_table_column_headings', |
|
204 | - ), |
|
205 | - 'pricing_default_pricing_views_bulk_actions_search_help_tab' => array( |
|
206 | - 'title' => esc_html__('Default Pricing Views & Bulk Actions & Search', 'event_espresso'), |
|
207 | - 'filename' => 'pricing_default_pricing_views_bulk_actions_search', |
|
208 | - ), |
|
209 | - ), |
|
210 | - 'require_nonce' => false, |
|
211 | - ), |
|
212 | - 'add_new_price' => array( |
|
213 | - 'nav' => array( |
|
214 | - 'label' => esc_html__('Add New Default Price', 'event_espresso'), |
|
215 | - 'order' => 20, |
|
216 | - 'persistent' => false, |
|
217 | - ), |
|
218 | - 'help_tabs' => array( |
|
219 | - 'add_new_default_price_help_tab' => array( |
|
220 | - 'title' => esc_html__('Add New Default Price', 'event_espresso'), |
|
221 | - 'filename' => 'pricing_add_new_default_price', |
|
222 | - ), |
|
223 | - ), |
|
224 | - 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
225 | - 'require_nonce' => false, |
|
226 | - ), |
|
227 | - 'edit_price' => array( |
|
228 | - 'nav' => array( |
|
229 | - 'label' => esc_html__('Edit Default Price', 'event_espresso'), |
|
230 | - 'order' => 20, |
|
231 | - 'url' => isset($this->_req_data['id']) ? add_query_arg( |
|
232 | - array('id' => $this->_req_data['id']), |
|
233 | - $this->_current_page_view_url |
|
234 | - ) : $this->_admin_base_url, |
|
235 | - 'persistent' => false, |
|
236 | - ), |
|
237 | - 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
238 | - 'help_tabs' => array( |
|
239 | - 'edit_default_price_help_tab' => array( |
|
240 | - 'title' => esc_html__('Edit Default Price', 'event_espresso'), |
|
241 | - 'filename' => 'pricing_edit_default_price', |
|
242 | - ), |
|
243 | - ), |
|
244 | - 'require_nonce' => false, |
|
245 | - ), |
|
246 | - 'price_types' => array( |
|
247 | - 'nav' => array( |
|
248 | - 'label' => esc_html__('Price Types', 'event_espresso'), |
|
249 | - 'order' => 30, |
|
250 | - ), |
|
251 | - 'list_table' => 'Price_Types_List_Table', |
|
252 | - 'help_tabs' => array( |
|
253 | - 'pricing_price_types_help_tab' => array( |
|
254 | - 'title' => esc_html__('Price Types', 'event_espresso'), |
|
255 | - 'filename' => 'pricing_price_types', |
|
256 | - ), |
|
257 | - 'pricing_price_types_table_column_headings_help_tab' => array( |
|
258 | - 'title' => esc_html__('Price Types Table Column Headings', 'event_espresso'), |
|
259 | - 'filename' => 'pricing_price_types_table_column_headings', |
|
260 | - ), |
|
261 | - 'pricing_price_types_views_bulk_actions_search_help_tab' => array( |
|
262 | - 'title' => esc_html__('Price Types Views & Bulk Actions & Search', 'event_espresso'), |
|
263 | - 'filename' => 'pricing_price_types_views_bulk_actions_search', |
|
264 | - ), |
|
265 | - ), |
|
266 | - 'metaboxes' => array('_espresso_news_post_box', '_espresso_links_post_box'), |
|
267 | - 'require_nonce' => false, |
|
268 | - ), |
|
269 | - 'add_new_price_type' => array( |
|
270 | - 'nav' => array( |
|
271 | - 'label' => esc_html__('Add New Price Type', 'event_espresso'), |
|
272 | - 'order' => 40, |
|
273 | - 'persistent' => false, |
|
274 | - ), |
|
275 | - 'help_tabs' => array( |
|
276 | - 'add_new_price_type_help_tab' => array( |
|
277 | - 'title' => esc_html__('Add New Price Type', 'event_espresso'), |
|
278 | - 'filename' => 'pricing_add_new_price_type', |
|
279 | - ), |
|
280 | - ), |
|
281 | - 'metaboxes' => array( |
|
282 | - '_publish_post_box', |
|
283 | - '_espresso_news_post_box', |
|
284 | - '_price_type_details_meta_boxes', |
|
285 | - ), |
|
286 | - 'require_nonce' => false, |
|
287 | - ), |
|
288 | - 'edit_price_type' => array( |
|
289 | - 'nav' => array( |
|
290 | - 'label' => esc_html__('Edit Price Type', 'event_espresso'), |
|
291 | - 'order' => 40, |
|
292 | - 'persistent' => false, |
|
293 | - ), |
|
294 | - 'help_tabs' => array( |
|
295 | - 'edit_price_type_help_tab' => array( |
|
296 | - 'title' => esc_html__('Edit Price Type', 'event_espresso'), |
|
297 | - 'filename' => 'pricing_edit_price_type', |
|
298 | - ), |
|
299 | - ), |
|
300 | - 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_type_details_meta_boxes'), |
|
301 | - |
|
302 | - 'require_nonce' => false, |
|
303 | - ), |
|
304 | - 'tax_settings' => array( |
|
305 | - 'nav' => array( |
|
306 | - 'label' => esc_html__('Tax Settings', 'event_espresso'), |
|
307 | - 'order' => 40, |
|
308 | - ), |
|
309 | - 'labels' => array( |
|
310 | - 'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'), |
|
311 | - ), |
|
312 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
313 | - 'require_nonce' => true, |
|
314 | - ), |
|
315 | - ); |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - protected function _add_screen_options() |
|
320 | - { |
|
321 | - // todo |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - protected function _add_screen_options_default() |
|
326 | - { |
|
327 | - $this->_per_page_screen_option(); |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - protected function _add_screen_options_price_types() |
|
332 | - { |
|
333 | - $page_title = $this->_admin_page_title; |
|
334 | - $this->_admin_page_title = esc_html__('Price Types', 'event_espresso'); |
|
335 | - $this->_per_page_screen_option(); |
|
336 | - $this->_admin_page_title = $page_title; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - protected function _add_feature_pointers() |
|
341 | - { |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - public function load_scripts_styles() |
|
346 | - { |
|
347 | - // styles |
|
348 | - wp_enqueue_style('espresso-ui-theme'); |
|
349 | - wp_register_style( |
|
350 | - 'espresso_PRICING', |
|
351 | - PRICING_ASSETS_URL . 'espresso_pricing_admin.css', |
|
352 | - array(), |
|
353 | - EVENT_ESPRESSO_VERSION |
|
354 | - ); |
|
355 | - wp_enqueue_style('espresso_PRICING'); |
|
356 | - |
|
357 | - // scripts |
|
358 | - wp_enqueue_script('ee_admin_js'); |
|
359 | - wp_enqueue_script('jquery-ui-position'); |
|
360 | - wp_enqueue_script('jquery-ui-widget'); |
|
361 | - // wp_enqueue_script('jquery-ui-dialog'); |
|
362 | - // wp_enqueue_script('jquery-ui-draggable'); |
|
363 | - // wp_enqueue_script('jquery-ui-datepicker'); |
|
364 | - wp_register_script( |
|
365 | - 'espresso_PRICING', |
|
366 | - PRICING_ASSETS_URL . 'espresso_pricing_admin.js', |
|
367 | - array('jquery'), |
|
368 | - EVENT_ESPRESSO_VERSION, |
|
369 | - true |
|
370 | - ); |
|
371 | - wp_enqueue_script('espresso_PRICING'); |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - public function load_scripts_styles_default() |
|
376 | - { |
|
377 | - wp_enqueue_script('espresso_ajax_table_sorting'); |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - public function admin_footer_scripts() |
|
382 | - { |
|
383 | - } |
|
384 | - |
|
385 | - public function admin_init() |
|
386 | - { |
|
387 | - } |
|
388 | - |
|
389 | - public function admin_notices() |
|
390 | - { |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - protected function _set_list_table_views_default() |
|
395 | - { |
|
396 | - $this->_views = array( |
|
397 | - 'all' => array( |
|
398 | - 'slug' => 'all', |
|
399 | - 'label' => esc_html__('View All Default Pricing', 'event_espresso'), |
|
400 | - 'count' => 0, |
|
401 | - 'bulk_action' => array( |
|
402 | - 'trash_price' => esc_html__('Move to Trash', 'event_espresso'), |
|
403 | - ), |
|
404 | - ), |
|
405 | - ); |
|
406 | - |
|
407 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
408 | - $this->_views['trashed'] = array( |
|
409 | - 'slug' => 'trashed', |
|
410 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
411 | - 'count' => 0, |
|
412 | - 'bulk_action' => array( |
|
413 | - 'restore_price' => esc_html__('Restore from Trash', 'event_espresso'), |
|
414 | - 'delete_price' => esc_html__('Delete Permanently', 'event_espresso'), |
|
415 | - ), |
|
416 | - ); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - protected function _set_list_table_views_price_types() |
|
422 | - { |
|
423 | - $this->_views = array( |
|
424 | - 'all' => array( |
|
425 | - 'slug' => 'all', |
|
426 | - 'label' => esc_html__('All', 'event_espresso'), |
|
427 | - 'count' => 0, |
|
428 | - 'bulk_action' => array( |
|
429 | - 'trash_price_type' => esc_html__('Move to Trash', 'event_espresso'), |
|
430 | - ), |
|
431 | - ), |
|
432 | - ); |
|
433 | - |
|
434 | - if ( |
|
435 | - EE_Registry::instance()->CAP->current_user_can( |
|
436 | - 'ee_delete_default_price_types', |
|
437 | - 'pricing_trash_price_type' |
|
438 | - ) |
|
439 | - ) { |
|
440 | - $this->_views['trashed'] = array( |
|
441 | - 'slug' => 'trashed', |
|
442 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
443 | - 'count' => 0, |
|
444 | - 'bulk_action' => array( |
|
445 | - 'restore_price_type' => esc_html__('Restore from Trash', 'event_espresso'), |
|
446 | - 'delete_price_type' => esc_html__('Delete Permanently', 'event_espresso'), |
|
447 | - ), |
|
448 | - ); |
|
449 | - } |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * generates HTML for main Prices Admin page |
|
455 | - * |
|
456 | - * @access protected |
|
457 | - * @return void |
|
458 | - */ |
|
459 | - protected function _price_overview_list_table() |
|
460 | - { |
|
461 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
462 | - 'add_new_price', |
|
463 | - 'add', |
|
464 | - array(), |
|
465 | - 'add-new-h2' |
|
466 | - ); |
|
467 | - $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
468 | - $this->_search_btn_label = esc_html__('Default Prices', 'event_espresso'); |
|
469 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * retrieve data for Prices List table |
|
475 | - * |
|
476 | - * @access public |
|
477 | - * @param int $per_page how many prices displayed per page |
|
478 | - * @param boolean $count return the count or objects |
|
479 | - * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
480 | - * @return mixed (int|array) int = count || array of price objects |
|
481 | - */ |
|
482 | - public function get_prices_overview_data($per_page = 10, $count = false, $trashed = false) |
|
483 | - { |
|
484 | - |
|
485 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
486 | - // start with an empty array |
|
487 | - $event_pricing = array(); |
|
488 | - |
|
489 | - require_once(PRICING_ADMIN . 'Prices_List_Table.class.php'); |
|
490 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
491 | - // $PRC = EEM_Price::instance(); |
|
492 | - |
|
493 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
494 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
495 | - : 'ASC'; |
|
496 | - |
|
497 | - switch ($this->_req_data['orderby']) { |
|
498 | - case 'name': |
|
499 | - $orderby = array('PRC_name' => $order); |
|
500 | - break; |
|
501 | - case 'type': |
|
502 | - $orderby = array('Price_Type.PRT_name' => $order); |
|
503 | - break; |
|
504 | - case 'amount': |
|
505 | - $orderby = array('PRC_amount' => $order); |
|
506 | - break; |
|
507 | - default: |
|
508 | - $orderby = array('PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order); |
|
509 | - } |
|
510 | - |
|
511 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
512 | - ? $this->_req_data['paged'] : 1; |
|
513 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
514 | - ? $this->_req_data['perpage'] : $per_page; |
|
515 | - |
|
516 | - $_where = array( |
|
517 | - 'PRC_is_default' => 1, |
|
518 | - 'PRC_deleted' => $trashed, |
|
519 | - ); |
|
520 | - |
|
521 | - $offset = ($current_page - 1) * $per_page; |
|
522 | - $limit = array($offset, $per_page); |
|
523 | - |
|
524 | - if (isset($this->_req_data['s'])) { |
|
525 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
526 | - $_where['OR'] = array( |
|
527 | - 'PRC_name' => array('LIKE', $sstr), |
|
528 | - 'PRC_desc' => array('LIKE', $sstr), |
|
529 | - 'PRC_amount' => array('LIKE', $sstr), |
|
530 | - 'Price_Type.PRT_name' => array('LIKE', $sstr), |
|
531 | - ); |
|
532 | - } |
|
533 | - |
|
534 | - $query_params = array( |
|
535 | - $_where, |
|
536 | - 'order_by' => $orderby, |
|
537 | - 'limit' => $limit, |
|
538 | - 'group_by' => 'PRC_ID', |
|
539 | - ); |
|
540 | - |
|
541 | - if ($count) { |
|
542 | - return $trashed ? EEM_Price::instance()->count(array($_where)) |
|
543 | - : EEM_Price::instance()->count_deleted_and_undeleted(array($_where)); |
|
544 | - } else { |
|
545 | - return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params); |
|
546 | - } |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * _price_details |
|
552 | - * |
|
553 | - * @access protected |
|
554 | - * @return void |
|
555 | - */ |
|
556 | - protected function _edit_price_details() |
|
557 | - { |
|
558 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
559 | - // grab price ID |
|
560 | - $PRC_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
561 | - : false; |
|
562 | - // change page title based on request action |
|
563 | - switch ($this->_req_action) { |
|
564 | - case 'add_new_price': |
|
565 | - $this->_admin_page_title = esc_html__('Add New Price', 'event_espresso'); |
|
566 | - break; |
|
567 | - case 'edit_price': |
|
568 | - $this->_admin_page_title = esc_html__('Edit Price', 'event_espresso'); |
|
569 | - break; |
|
570 | - default: |
|
571 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
572 | - } |
|
573 | - // add PRC_ID to title if editing |
|
574 | - $this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title; |
|
575 | - |
|
576 | - // get prices |
|
577 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
578 | - $PRC = EEM_Price::instance(); |
|
579 | - |
|
580 | - if ($PRC_ID) { |
|
581 | - $price = $PRC->get_one_by_ID($PRC_ID); |
|
582 | - $additional_hidden_fields = array( |
|
583 | - 'PRC_ID' => array('type' => 'hidden', 'value' => $PRC_ID), |
|
584 | - ); |
|
585 | - $this->_set_add_edit_form_tags('update_price', $additional_hidden_fields); |
|
586 | - } else { |
|
587 | - $price = $PRC->get_new_price(); |
|
588 | - $this->_set_add_edit_form_tags('insert_price'); |
|
589 | - } |
|
590 | - |
|
591 | - $this->_template_args['PRC_ID'] = $PRC_ID; |
|
592 | - $this->_template_args['price'] = $price; |
|
593 | - |
|
594 | - // get price types |
|
595 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
596 | - $PRT = EEM_Price_Type::instance(); |
|
597 | - $price_types = $PRT->get_all(array(array('PBT_ID' => array('!=', 1)))); |
|
598 | - $price_type_names = array(); |
|
599 | - if (empty($price_types)) { |
|
600 | - $msg = esc_html__( |
|
601 | - 'You have no price types defined. Please add a price type before adding a price.', |
|
602 | - 'event_espresso' |
|
603 | - ); |
|
604 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
605 | - exit(); |
|
606 | - } else { |
|
607 | - foreach ($price_types as $type) { |
|
608 | - // if ($type->is_global()) { |
|
609 | - $price_type_names[] = array('id' => $type->ID(), 'text' => $type->name()); |
|
610 | - // } |
|
611 | - } |
|
612 | - } |
|
613 | - |
|
614 | - $this->_template_args['price_types'] = $price_type_names; |
|
615 | - $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
616 | - |
|
617 | - $this->_set_publish_post_box_vars('id', $PRC_ID); |
|
618 | - // the details template wrapper |
|
619 | - $this->display_admin_page_with_sidebar(); |
|
620 | - } |
|
621 | - |
|
622 | - |
|
623 | - /** |
|
624 | - * declare price details page metaboxes |
|
625 | - * |
|
626 | - * @access protected |
|
627 | - * @return void |
|
628 | - */ |
|
629 | - protected function _price_details_meta_boxes() |
|
630 | - { |
|
631 | - add_meta_box( |
|
632 | - 'edit-price-details-mbox', |
|
633 | - esc_html__('Default Price Details', 'event_espresso'), |
|
634 | - array($this, '_edit_price_details_meta_box'), |
|
635 | - $this->wp_page_slug, |
|
636 | - 'normal', |
|
637 | - 'high' |
|
638 | - ); |
|
639 | - } |
|
640 | - |
|
641 | - |
|
642 | - /** |
|
643 | - * _edit_price_details_meta_box |
|
644 | - * |
|
645 | - * @access public |
|
646 | - * @return void |
|
647 | - */ |
|
648 | - public function _edit_price_details_meta_box() |
|
649 | - { |
|
650 | - echo EEH_Template::display_template( |
|
651 | - PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php', |
|
652 | - $this->_template_args, |
|
653 | - true |
|
654 | - ); |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * set_price_column_values |
|
660 | - * |
|
661 | - * @access protected |
|
662 | - * @return array |
|
663 | - */ |
|
664 | - protected function set_price_column_values() |
|
665 | - { |
|
666 | - |
|
667 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
668 | - |
|
669 | - $set_column_values = array( |
|
670 | - 'PRT_ID' => absint($this->_req_data['PRT_ID']), |
|
671 | - 'PRC_amount' => $this->_req_data['PRC_amount'], |
|
672 | - 'PRC_name' => $this->_req_data['PRC_name'], |
|
673 | - 'PRC_desc' => $this->_req_data['PRC_desc'], |
|
674 | - 'PRC_is_default' => 1, |
|
675 | - 'PRC_overrides' => null, |
|
676 | - 'PRC_order' => 0, |
|
677 | - 'PRC_deleted' => 0, |
|
678 | - 'PRC_parent' => 0, |
|
679 | - ); |
|
680 | - return $set_column_values; |
|
681 | - } |
|
682 | - |
|
683 | - |
|
684 | - /** |
|
685 | - * insert_or_update_price |
|
686 | - * |
|
687 | - * @param boolean $insert - whether to insert or update |
|
688 | - * @access protected |
|
689 | - * @return void |
|
690 | - */ |
|
691 | - protected function _insert_or_update_price($insert = false) |
|
692 | - { |
|
693 | - |
|
694 | - // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
695 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
696 | - |
|
697 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
698 | - $PRC = EEM_Price::instance(); |
|
699 | - |
|
700 | - // why be so pessimistic ??? : ( |
|
701 | - $success = 0; |
|
702 | - |
|
703 | - $set_column_values = $this->set_price_column_values(); |
|
704 | - // is this a new Price ? |
|
705 | - if ($insert) { |
|
706 | - // run the insert |
|
707 | - if ($PRC_ID = $PRC->insert($set_column_values)) { |
|
708 | - // make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type |
|
709 | - $PR = EEM_price::instance()->get_one_by_ID($PRC_ID); |
|
710 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
711 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
712 | - $ticket->_add_relation_to($PR, 'Price'); |
|
713 | - $ticket->save(); |
|
714 | - } |
|
715 | - $success = 1; |
|
716 | - } else { |
|
717 | - $PRC_ID = false; |
|
718 | - $success = 0; |
|
719 | - } |
|
720 | - $action_desc = 'created'; |
|
721 | - } else { |
|
722 | - $PRC_ID = absint($this->_req_data['PRC_ID']); |
|
723 | - // run the update |
|
724 | - $where_cols_n_values = array('PRC_ID' => $PRC_ID); |
|
725 | - if ($PRC->update($set_column_values, array($where_cols_n_values))) { |
|
726 | - $success = 1; |
|
727 | - } |
|
728 | - |
|
729 | - $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
730 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
731 | - // if this is $PRC_ID == 1, then we need to update the default ticket attached to this price so the TKT_price value is updated. |
|
732 | - if ($PRC_ID === 1) { |
|
733 | - $ticket = $PR->get_first_related('Ticket'); |
|
734 | - if ($ticket) { |
|
735 | - $ticket->set('TKT_price', $PR->get('PRC_amount')); |
|
736 | - $ticket->set('TKT_name', $PR->get('PRC_name')); |
|
737 | - $ticket->set('TKT_description', $PR->get('PRC_desc')); |
|
738 | - $ticket->save(); |
|
739 | - } |
|
740 | - } else { |
|
741 | - // we make sure this price is attached to base ticket. but ONLY if its not a tax ticket type. |
|
742 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
743 | - $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
744 | - $ticket->save(); |
|
745 | - } |
|
746 | - } |
|
747 | - |
|
748 | - $action_desc = 'updated'; |
|
749 | - } |
|
750 | - |
|
751 | - $query_args = array('action' => 'edit_price', 'id' => $PRC_ID); |
|
752 | - |
|
753 | - $this->_redirect_after_action($success, 'Prices', $action_desc, $query_args); |
|
754 | - } |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * _trash_or_restore_price |
|
759 | - * |
|
760 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
761 | - * @access protected |
|
762 | - * @return void |
|
763 | - */ |
|
764 | - protected function _trash_or_restore_price($trash = true) |
|
765 | - { |
|
766 | - |
|
767 | - // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
768 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
769 | - |
|
770 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
771 | - $PRC = EEM_Price::instance(); |
|
772 | - |
|
773 | - $success = 1; |
|
774 | - $PRC_deleted = $trash ? true : false; |
|
775 | - |
|
776 | - // get base ticket for updating |
|
777 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
778 | - // Checkboxes |
|
779 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
780 | - // if array has more than one element than success message should be plural |
|
781 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
782 | - // cycle thru checkboxes |
|
783 | - while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
784 | - if (! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), absint($PRC_ID))) { |
|
785 | - $success = 0; |
|
786 | - } else { |
|
787 | - $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
788 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
789 | - // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
790 | - if ($PRC_deleted) { |
|
791 | - $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
792 | - } else { |
|
793 | - $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
794 | - } |
|
795 | - $ticket->save(); |
|
796 | - } |
|
797 | - } |
|
798 | - } |
|
799 | - } else { |
|
800 | - // grab single id and delete |
|
801 | - $PRC_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
802 | - if (empty($PRC_ID) || ! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), $PRC_ID)) { |
|
803 | - $success = 0; |
|
804 | - } else { |
|
805 | - $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
806 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
807 | - // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
808 | - if ($PRC_deleted) { |
|
809 | - $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
810 | - } else { |
|
811 | - $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
812 | - } |
|
813 | - $ticket->save(); |
|
814 | - } |
|
815 | - } |
|
816 | - } |
|
817 | - $query_args = array( |
|
818 | - 'action' => 'default', |
|
819 | - ); |
|
820 | - |
|
821 | - if ($success) { |
|
822 | - if ($trash) { |
|
823 | - $msg = $success == 2 |
|
824 | - ? esc_html__('The Prices have been trashed.', 'event_espresso') |
|
825 | - : esc_html__( |
|
826 | - 'The Price has been trashed.', |
|
827 | - 'event_espresso' |
|
828 | - ); |
|
829 | - } else { |
|
830 | - $msg = $success == 2 |
|
831 | - ? esc_html__('The Prices have been restored.', 'event_espresso') |
|
832 | - : esc_html__( |
|
833 | - 'The Price has been restored.', |
|
834 | - 'event_espresso' |
|
835 | - ); |
|
836 | - } |
|
837 | - |
|
838 | - EE_Error::add_success($msg); |
|
839 | - } |
|
840 | - |
|
841 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
842 | - } |
|
843 | - |
|
844 | - |
|
845 | - /** |
|
846 | - * _delete_price |
|
847 | - * |
|
848 | - * @access protected |
|
849 | - * @return void |
|
850 | - */ |
|
851 | - protected function _delete_price() |
|
852 | - { |
|
853 | - |
|
854 | - // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
855 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
856 | - |
|
857 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
858 | - $PRC = EEM_Price::instance(); |
|
859 | - |
|
860 | - $success = 1; |
|
861 | - // Checkboxes |
|
862 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
863 | - // if array has more than one element than success message should be plural |
|
864 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
865 | - // cycle thru bulk action checkboxes |
|
866 | - while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
867 | - if (! $PRC->delete_permanently_by_ID(absint($PRC_ID))) { |
|
868 | - $success = 0; |
|
869 | - } |
|
870 | - } |
|
871 | - } else { |
|
872 | - // grab single id and delete |
|
873 | - $PRC_ID = absint($this->_req_data['id']); |
|
874 | - if (! $PRC->delete_permanently_by_ID($PRC_ID)) { |
|
875 | - $success = 0; |
|
876 | - } |
|
877 | - } |
|
878 | - |
|
879 | - $this->_redirect_after_action($success, 'Prices', 'deleted', array()); |
|
880 | - } |
|
881 | - |
|
882 | - |
|
883 | - public function update_price_order() |
|
884 | - { |
|
885 | - $success = esc_html__('Price order was updated successfully.', 'event_espresso'); |
|
886 | - |
|
887 | - // grab our row IDs |
|
888 | - $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) ? explode( |
|
889 | - ',', |
|
890 | - rtrim( |
|
891 | - $this->_req_data['row_ids'], |
|
892 | - ',' |
|
893 | - ) |
|
894 | - ) : false; |
|
895 | - |
|
896 | - if (is_array($row_ids)) { |
|
897 | - for ($i = 0; $i < count($row_ids); $i++) { |
|
898 | - // Update the prices when re-ordering |
|
899 | - $id = absint($row_ids[ $i ]); |
|
900 | - if ( |
|
901 | - EEM_Price::instance()->update( |
|
902 | - array('PRC_order' => $i + 1), |
|
903 | - array(array('PRC_ID' => $id)) |
|
904 | - ) === false |
|
905 | - ) { |
|
906 | - $success = false; |
|
907 | - } |
|
908 | - } |
|
909 | - } else { |
|
910 | - $success = false; |
|
911 | - } |
|
912 | - |
|
913 | - $errors = ! $success ? esc_html__('An error occurred. The price order was not updated.', 'event_espresso') : false; |
|
914 | - |
|
915 | - echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
916 | - die(); |
|
917 | - } |
|
918 | - |
|
919 | - |
|
920 | - |
|
921 | - |
|
922 | - |
|
923 | - |
|
924 | - /************************************************************************************************************************************************************** |
|
15 | + /** |
|
16 | + * constructor |
|
17 | + * |
|
18 | + * @Constructor |
|
19 | + * @access public |
|
20 | + * @param bool $routing |
|
21 | + * @return Pricing_Admin_Page |
|
22 | + */ |
|
23 | + public function __construct($routing = true) |
|
24 | + { |
|
25 | + parent::__construct($routing); |
|
26 | + } |
|
27 | + |
|
28 | + |
|
29 | + protected function _init_page_props() |
|
30 | + { |
|
31 | + $this->page_slug = PRICING_PG_SLUG; |
|
32 | + $this->page_label = PRICING_LABEL; |
|
33 | + $this->_admin_base_url = PRICING_ADMIN_URL; |
|
34 | + $this->_admin_base_path = PRICING_ADMIN; |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + protected function _ajax_hooks() |
|
39 | + { |
|
40 | + add_action('wp_ajax_espresso_update_prices_order', array($this, 'update_price_order')); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + protected function _define_page_props() |
|
45 | + { |
|
46 | + $this->_admin_page_title = PRICING_LABEL; |
|
47 | + $this->_labels = array( |
|
48 | + 'buttons' => array( |
|
49 | + 'add' => esc_html__('Add New Default Price', 'event_espresso'), |
|
50 | + 'edit' => esc_html__('Edit Default Price', 'event_espresso'), |
|
51 | + 'delete' => esc_html__('Delete Default Price', 'event_espresso'), |
|
52 | + 'add_type' => esc_html__('Add New Default Price Type', 'event_espresso'), |
|
53 | + 'edit_type' => esc_html__('Edit Price Type', 'event_espresso'), |
|
54 | + 'delete_type' => esc_html__('Delete Price Type', 'event_espresso'), |
|
55 | + ), |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * an array for storing request actions and their corresponding methods |
|
62 | + * |
|
63 | + * @access private |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + protected function _set_page_routes() |
|
67 | + { |
|
68 | + $prc_id = ! empty($this->_req_data['PRC_ID']) && ! is_array($this->_req_data['PRC_ID']) |
|
69 | + ? $this->_req_data['PRC_ID'] : 0; |
|
70 | + $prt_id = ! empty($this->_req_data['PRT_ID']) && ! is_array($this->_req_data['PRT_ID']) |
|
71 | + ? $this->_req_data['PRT_ID'] : 0; |
|
72 | + $this->_page_routes = array( |
|
73 | + 'default' => array( |
|
74 | + 'func' => '_price_overview_list_table', |
|
75 | + 'capability' => 'ee_read_default_prices', |
|
76 | + ), |
|
77 | + 'add_new_price' => array( |
|
78 | + 'func' => '_edit_price_details', |
|
79 | + 'args' => array('new_price' => true), |
|
80 | + 'capability' => 'ee_edit_default_prices', |
|
81 | + ), |
|
82 | + 'edit_price' => array( |
|
83 | + 'func' => '_edit_price_details', |
|
84 | + 'args' => array('new_price' => false), |
|
85 | + 'capability' => 'ee_edit_default_price', |
|
86 | + 'obj_id' => $prc_id, |
|
87 | + ), |
|
88 | + 'insert_price' => array( |
|
89 | + 'func' => '_insert_or_update_price', |
|
90 | + 'args' => array('new_price' => true), |
|
91 | + 'noheader' => true, |
|
92 | + 'capability' => 'ee_edit_default_prices', |
|
93 | + ), |
|
94 | + 'update_price' => array( |
|
95 | + 'func' => '_insert_or_update_price', |
|
96 | + 'args' => array('new_price' => false), |
|
97 | + 'noheader' => true, |
|
98 | + 'capability' => 'ee_edit_default_price', |
|
99 | + 'obj_id' => $prc_id, |
|
100 | + ), |
|
101 | + 'trash_price' => array( |
|
102 | + 'func' => '_trash_or_restore_price', |
|
103 | + 'args' => array('trash' => true), |
|
104 | + 'noheader' => true, |
|
105 | + 'capability' => 'ee_delete_default_price', |
|
106 | + 'obj_id' => $prc_id, |
|
107 | + ), |
|
108 | + 'restore_price' => array( |
|
109 | + 'func' => '_trash_or_restore_price', |
|
110 | + 'args' => array('trash' => false), |
|
111 | + 'noheader' => true, |
|
112 | + 'capability' => 'ee_delete_default_price', |
|
113 | + 'obj_id' => $prc_id, |
|
114 | + ), |
|
115 | + 'delete_price' => array( |
|
116 | + 'func' => '_delete_price', |
|
117 | + 'noheader' => true, |
|
118 | + 'capability' => 'ee_delete_default_price', |
|
119 | + 'obj_id' => $prc_id, |
|
120 | + ), |
|
121 | + 'espresso_update_price_order' => array( |
|
122 | + 'func' => 'update_price_order', |
|
123 | + 'noheader' => true, |
|
124 | + 'capability' => 'ee_edit_default_prices', |
|
125 | + ), |
|
126 | + // price types |
|
127 | + 'price_types' => array( |
|
128 | + 'func' => '_price_types_overview_list_table', |
|
129 | + 'capability' => 'ee_read_default_price_types', |
|
130 | + ), |
|
131 | + 'add_new_price_type' => array( |
|
132 | + 'func' => '_edit_price_type_details', |
|
133 | + 'capability' => 'ee_edit_default_price_types', |
|
134 | + ), |
|
135 | + 'edit_price_type' => array( |
|
136 | + 'func' => '_edit_price_type_details', |
|
137 | + 'capability' => 'ee_edit_default_price_type', |
|
138 | + 'obj_id' => $prt_id, |
|
139 | + ), |
|
140 | + 'insert_price_type' => array( |
|
141 | + 'func' => '_insert_or_update_price_type', |
|
142 | + 'args' => array('new_price_type' => true), |
|
143 | + 'noheader' => true, |
|
144 | + 'capability' => 'ee_edit_default_price_types', |
|
145 | + ), |
|
146 | + 'update_price_type' => array( |
|
147 | + 'func' => '_insert_or_update_price_type', |
|
148 | + 'args' => array('new_price_type' => false), |
|
149 | + 'noheader' => true, |
|
150 | + 'capability' => 'ee_edit_default_price_type', |
|
151 | + 'obj_id' => $prt_id, |
|
152 | + ), |
|
153 | + 'trash_price_type' => array( |
|
154 | + 'func' => '_trash_or_restore_price_type', |
|
155 | + 'args' => array('trash' => true), |
|
156 | + 'noheader' => true, |
|
157 | + 'capability' => 'ee_delete_default_price_type', |
|
158 | + 'obj_id' => $prt_id, |
|
159 | + ), |
|
160 | + 'restore_price_type' => array( |
|
161 | + 'func' => '_trash_or_restore_price_type', |
|
162 | + 'args' => array('trash' => false), |
|
163 | + 'noheader' => true, |
|
164 | + 'capability' => 'ee_delete_default_price_type', |
|
165 | + 'obj_id' => $prt_id, |
|
166 | + ), |
|
167 | + 'delete_price_type' => array( |
|
168 | + 'func' => '_delete_price_type', |
|
169 | + 'noheader' => true, |
|
170 | + 'capability' => 'ee_delete_default_price_type', |
|
171 | + 'obj_id' => $prt_id, |
|
172 | + ), |
|
173 | + 'tax_settings' => array( |
|
174 | + 'func' => '_tax_settings', |
|
175 | + 'capability' => 'manage_options', |
|
176 | + ), |
|
177 | + 'update_tax_settings' => array( |
|
178 | + 'func' => '_update_tax_settings', |
|
179 | + 'capability' => 'manage_options', |
|
180 | + 'noheader' => true, |
|
181 | + ), |
|
182 | + ); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + protected function _set_page_config() |
|
187 | + { |
|
188 | + |
|
189 | + $this->_page_config = array( |
|
190 | + 'default' => array( |
|
191 | + 'nav' => array( |
|
192 | + 'label' => esc_html__('Default Pricing', 'event_espresso'), |
|
193 | + 'order' => 10, |
|
194 | + ), |
|
195 | + 'list_table' => 'Prices_List_Table', |
|
196 | + 'help_tabs' => array( |
|
197 | + 'pricing_default_pricing_help_tab' => array( |
|
198 | + 'title' => esc_html__('Default Pricing', 'event_espresso'), |
|
199 | + 'filename' => 'pricing_default_pricing', |
|
200 | + ), |
|
201 | + 'pricing_default_pricing_table_column_headings_help_tab' => array( |
|
202 | + 'title' => esc_html__('Default Pricing Table Column Headings', 'event_espresso'), |
|
203 | + 'filename' => 'pricing_default_pricing_table_column_headings', |
|
204 | + ), |
|
205 | + 'pricing_default_pricing_views_bulk_actions_search_help_tab' => array( |
|
206 | + 'title' => esc_html__('Default Pricing Views & Bulk Actions & Search', 'event_espresso'), |
|
207 | + 'filename' => 'pricing_default_pricing_views_bulk_actions_search', |
|
208 | + ), |
|
209 | + ), |
|
210 | + 'require_nonce' => false, |
|
211 | + ), |
|
212 | + 'add_new_price' => array( |
|
213 | + 'nav' => array( |
|
214 | + 'label' => esc_html__('Add New Default Price', 'event_espresso'), |
|
215 | + 'order' => 20, |
|
216 | + 'persistent' => false, |
|
217 | + ), |
|
218 | + 'help_tabs' => array( |
|
219 | + 'add_new_default_price_help_tab' => array( |
|
220 | + 'title' => esc_html__('Add New Default Price', 'event_espresso'), |
|
221 | + 'filename' => 'pricing_add_new_default_price', |
|
222 | + ), |
|
223 | + ), |
|
224 | + 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
225 | + 'require_nonce' => false, |
|
226 | + ), |
|
227 | + 'edit_price' => array( |
|
228 | + 'nav' => array( |
|
229 | + 'label' => esc_html__('Edit Default Price', 'event_espresso'), |
|
230 | + 'order' => 20, |
|
231 | + 'url' => isset($this->_req_data['id']) ? add_query_arg( |
|
232 | + array('id' => $this->_req_data['id']), |
|
233 | + $this->_current_page_view_url |
|
234 | + ) : $this->_admin_base_url, |
|
235 | + 'persistent' => false, |
|
236 | + ), |
|
237 | + 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
238 | + 'help_tabs' => array( |
|
239 | + 'edit_default_price_help_tab' => array( |
|
240 | + 'title' => esc_html__('Edit Default Price', 'event_espresso'), |
|
241 | + 'filename' => 'pricing_edit_default_price', |
|
242 | + ), |
|
243 | + ), |
|
244 | + 'require_nonce' => false, |
|
245 | + ), |
|
246 | + 'price_types' => array( |
|
247 | + 'nav' => array( |
|
248 | + 'label' => esc_html__('Price Types', 'event_espresso'), |
|
249 | + 'order' => 30, |
|
250 | + ), |
|
251 | + 'list_table' => 'Price_Types_List_Table', |
|
252 | + 'help_tabs' => array( |
|
253 | + 'pricing_price_types_help_tab' => array( |
|
254 | + 'title' => esc_html__('Price Types', 'event_espresso'), |
|
255 | + 'filename' => 'pricing_price_types', |
|
256 | + ), |
|
257 | + 'pricing_price_types_table_column_headings_help_tab' => array( |
|
258 | + 'title' => esc_html__('Price Types Table Column Headings', 'event_espresso'), |
|
259 | + 'filename' => 'pricing_price_types_table_column_headings', |
|
260 | + ), |
|
261 | + 'pricing_price_types_views_bulk_actions_search_help_tab' => array( |
|
262 | + 'title' => esc_html__('Price Types Views & Bulk Actions & Search', 'event_espresso'), |
|
263 | + 'filename' => 'pricing_price_types_views_bulk_actions_search', |
|
264 | + ), |
|
265 | + ), |
|
266 | + 'metaboxes' => array('_espresso_news_post_box', '_espresso_links_post_box'), |
|
267 | + 'require_nonce' => false, |
|
268 | + ), |
|
269 | + 'add_new_price_type' => array( |
|
270 | + 'nav' => array( |
|
271 | + 'label' => esc_html__('Add New Price Type', 'event_espresso'), |
|
272 | + 'order' => 40, |
|
273 | + 'persistent' => false, |
|
274 | + ), |
|
275 | + 'help_tabs' => array( |
|
276 | + 'add_new_price_type_help_tab' => array( |
|
277 | + 'title' => esc_html__('Add New Price Type', 'event_espresso'), |
|
278 | + 'filename' => 'pricing_add_new_price_type', |
|
279 | + ), |
|
280 | + ), |
|
281 | + 'metaboxes' => array( |
|
282 | + '_publish_post_box', |
|
283 | + '_espresso_news_post_box', |
|
284 | + '_price_type_details_meta_boxes', |
|
285 | + ), |
|
286 | + 'require_nonce' => false, |
|
287 | + ), |
|
288 | + 'edit_price_type' => array( |
|
289 | + 'nav' => array( |
|
290 | + 'label' => esc_html__('Edit Price Type', 'event_espresso'), |
|
291 | + 'order' => 40, |
|
292 | + 'persistent' => false, |
|
293 | + ), |
|
294 | + 'help_tabs' => array( |
|
295 | + 'edit_price_type_help_tab' => array( |
|
296 | + 'title' => esc_html__('Edit Price Type', 'event_espresso'), |
|
297 | + 'filename' => 'pricing_edit_price_type', |
|
298 | + ), |
|
299 | + ), |
|
300 | + 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_type_details_meta_boxes'), |
|
301 | + |
|
302 | + 'require_nonce' => false, |
|
303 | + ), |
|
304 | + 'tax_settings' => array( |
|
305 | + 'nav' => array( |
|
306 | + 'label' => esc_html__('Tax Settings', 'event_espresso'), |
|
307 | + 'order' => 40, |
|
308 | + ), |
|
309 | + 'labels' => array( |
|
310 | + 'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'), |
|
311 | + ), |
|
312 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
313 | + 'require_nonce' => true, |
|
314 | + ), |
|
315 | + ); |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + protected function _add_screen_options() |
|
320 | + { |
|
321 | + // todo |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + protected function _add_screen_options_default() |
|
326 | + { |
|
327 | + $this->_per_page_screen_option(); |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + protected function _add_screen_options_price_types() |
|
332 | + { |
|
333 | + $page_title = $this->_admin_page_title; |
|
334 | + $this->_admin_page_title = esc_html__('Price Types', 'event_espresso'); |
|
335 | + $this->_per_page_screen_option(); |
|
336 | + $this->_admin_page_title = $page_title; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + protected function _add_feature_pointers() |
|
341 | + { |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + public function load_scripts_styles() |
|
346 | + { |
|
347 | + // styles |
|
348 | + wp_enqueue_style('espresso-ui-theme'); |
|
349 | + wp_register_style( |
|
350 | + 'espresso_PRICING', |
|
351 | + PRICING_ASSETS_URL . 'espresso_pricing_admin.css', |
|
352 | + array(), |
|
353 | + EVENT_ESPRESSO_VERSION |
|
354 | + ); |
|
355 | + wp_enqueue_style('espresso_PRICING'); |
|
356 | + |
|
357 | + // scripts |
|
358 | + wp_enqueue_script('ee_admin_js'); |
|
359 | + wp_enqueue_script('jquery-ui-position'); |
|
360 | + wp_enqueue_script('jquery-ui-widget'); |
|
361 | + // wp_enqueue_script('jquery-ui-dialog'); |
|
362 | + // wp_enqueue_script('jquery-ui-draggable'); |
|
363 | + // wp_enqueue_script('jquery-ui-datepicker'); |
|
364 | + wp_register_script( |
|
365 | + 'espresso_PRICING', |
|
366 | + PRICING_ASSETS_URL . 'espresso_pricing_admin.js', |
|
367 | + array('jquery'), |
|
368 | + EVENT_ESPRESSO_VERSION, |
|
369 | + true |
|
370 | + ); |
|
371 | + wp_enqueue_script('espresso_PRICING'); |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + public function load_scripts_styles_default() |
|
376 | + { |
|
377 | + wp_enqueue_script('espresso_ajax_table_sorting'); |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + public function admin_footer_scripts() |
|
382 | + { |
|
383 | + } |
|
384 | + |
|
385 | + public function admin_init() |
|
386 | + { |
|
387 | + } |
|
388 | + |
|
389 | + public function admin_notices() |
|
390 | + { |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + protected function _set_list_table_views_default() |
|
395 | + { |
|
396 | + $this->_views = array( |
|
397 | + 'all' => array( |
|
398 | + 'slug' => 'all', |
|
399 | + 'label' => esc_html__('View All Default Pricing', 'event_espresso'), |
|
400 | + 'count' => 0, |
|
401 | + 'bulk_action' => array( |
|
402 | + 'trash_price' => esc_html__('Move to Trash', 'event_espresso'), |
|
403 | + ), |
|
404 | + ), |
|
405 | + ); |
|
406 | + |
|
407 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
408 | + $this->_views['trashed'] = array( |
|
409 | + 'slug' => 'trashed', |
|
410 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
411 | + 'count' => 0, |
|
412 | + 'bulk_action' => array( |
|
413 | + 'restore_price' => esc_html__('Restore from Trash', 'event_espresso'), |
|
414 | + 'delete_price' => esc_html__('Delete Permanently', 'event_espresso'), |
|
415 | + ), |
|
416 | + ); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + protected function _set_list_table_views_price_types() |
|
422 | + { |
|
423 | + $this->_views = array( |
|
424 | + 'all' => array( |
|
425 | + 'slug' => 'all', |
|
426 | + 'label' => esc_html__('All', 'event_espresso'), |
|
427 | + 'count' => 0, |
|
428 | + 'bulk_action' => array( |
|
429 | + 'trash_price_type' => esc_html__('Move to Trash', 'event_espresso'), |
|
430 | + ), |
|
431 | + ), |
|
432 | + ); |
|
433 | + |
|
434 | + if ( |
|
435 | + EE_Registry::instance()->CAP->current_user_can( |
|
436 | + 'ee_delete_default_price_types', |
|
437 | + 'pricing_trash_price_type' |
|
438 | + ) |
|
439 | + ) { |
|
440 | + $this->_views['trashed'] = array( |
|
441 | + 'slug' => 'trashed', |
|
442 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
443 | + 'count' => 0, |
|
444 | + 'bulk_action' => array( |
|
445 | + 'restore_price_type' => esc_html__('Restore from Trash', 'event_espresso'), |
|
446 | + 'delete_price_type' => esc_html__('Delete Permanently', 'event_espresso'), |
|
447 | + ), |
|
448 | + ); |
|
449 | + } |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * generates HTML for main Prices Admin page |
|
455 | + * |
|
456 | + * @access protected |
|
457 | + * @return void |
|
458 | + */ |
|
459 | + protected function _price_overview_list_table() |
|
460 | + { |
|
461 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
462 | + 'add_new_price', |
|
463 | + 'add', |
|
464 | + array(), |
|
465 | + 'add-new-h2' |
|
466 | + ); |
|
467 | + $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
468 | + $this->_search_btn_label = esc_html__('Default Prices', 'event_espresso'); |
|
469 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * retrieve data for Prices List table |
|
475 | + * |
|
476 | + * @access public |
|
477 | + * @param int $per_page how many prices displayed per page |
|
478 | + * @param boolean $count return the count or objects |
|
479 | + * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
480 | + * @return mixed (int|array) int = count || array of price objects |
|
481 | + */ |
|
482 | + public function get_prices_overview_data($per_page = 10, $count = false, $trashed = false) |
|
483 | + { |
|
484 | + |
|
485 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
486 | + // start with an empty array |
|
487 | + $event_pricing = array(); |
|
488 | + |
|
489 | + require_once(PRICING_ADMIN . 'Prices_List_Table.class.php'); |
|
490 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
491 | + // $PRC = EEM_Price::instance(); |
|
492 | + |
|
493 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
494 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
495 | + : 'ASC'; |
|
496 | + |
|
497 | + switch ($this->_req_data['orderby']) { |
|
498 | + case 'name': |
|
499 | + $orderby = array('PRC_name' => $order); |
|
500 | + break; |
|
501 | + case 'type': |
|
502 | + $orderby = array('Price_Type.PRT_name' => $order); |
|
503 | + break; |
|
504 | + case 'amount': |
|
505 | + $orderby = array('PRC_amount' => $order); |
|
506 | + break; |
|
507 | + default: |
|
508 | + $orderby = array('PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order); |
|
509 | + } |
|
510 | + |
|
511 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
512 | + ? $this->_req_data['paged'] : 1; |
|
513 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
514 | + ? $this->_req_data['perpage'] : $per_page; |
|
515 | + |
|
516 | + $_where = array( |
|
517 | + 'PRC_is_default' => 1, |
|
518 | + 'PRC_deleted' => $trashed, |
|
519 | + ); |
|
520 | + |
|
521 | + $offset = ($current_page - 1) * $per_page; |
|
522 | + $limit = array($offset, $per_page); |
|
523 | + |
|
524 | + if (isset($this->_req_data['s'])) { |
|
525 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
526 | + $_where['OR'] = array( |
|
527 | + 'PRC_name' => array('LIKE', $sstr), |
|
528 | + 'PRC_desc' => array('LIKE', $sstr), |
|
529 | + 'PRC_amount' => array('LIKE', $sstr), |
|
530 | + 'Price_Type.PRT_name' => array('LIKE', $sstr), |
|
531 | + ); |
|
532 | + } |
|
533 | + |
|
534 | + $query_params = array( |
|
535 | + $_where, |
|
536 | + 'order_by' => $orderby, |
|
537 | + 'limit' => $limit, |
|
538 | + 'group_by' => 'PRC_ID', |
|
539 | + ); |
|
540 | + |
|
541 | + if ($count) { |
|
542 | + return $trashed ? EEM_Price::instance()->count(array($_where)) |
|
543 | + : EEM_Price::instance()->count_deleted_and_undeleted(array($_where)); |
|
544 | + } else { |
|
545 | + return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params); |
|
546 | + } |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * _price_details |
|
552 | + * |
|
553 | + * @access protected |
|
554 | + * @return void |
|
555 | + */ |
|
556 | + protected function _edit_price_details() |
|
557 | + { |
|
558 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
559 | + // grab price ID |
|
560 | + $PRC_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
561 | + : false; |
|
562 | + // change page title based on request action |
|
563 | + switch ($this->_req_action) { |
|
564 | + case 'add_new_price': |
|
565 | + $this->_admin_page_title = esc_html__('Add New Price', 'event_espresso'); |
|
566 | + break; |
|
567 | + case 'edit_price': |
|
568 | + $this->_admin_page_title = esc_html__('Edit Price', 'event_espresso'); |
|
569 | + break; |
|
570 | + default: |
|
571 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
572 | + } |
|
573 | + // add PRC_ID to title if editing |
|
574 | + $this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title; |
|
575 | + |
|
576 | + // get prices |
|
577 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
578 | + $PRC = EEM_Price::instance(); |
|
579 | + |
|
580 | + if ($PRC_ID) { |
|
581 | + $price = $PRC->get_one_by_ID($PRC_ID); |
|
582 | + $additional_hidden_fields = array( |
|
583 | + 'PRC_ID' => array('type' => 'hidden', 'value' => $PRC_ID), |
|
584 | + ); |
|
585 | + $this->_set_add_edit_form_tags('update_price', $additional_hidden_fields); |
|
586 | + } else { |
|
587 | + $price = $PRC->get_new_price(); |
|
588 | + $this->_set_add_edit_form_tags('insert_price'); |
|
589 | + } |
|
590 | + |
|
591 | + $this->_template_args['PRC_ID'] = $PRC_ID; |
|
592 | + $this->_template_args['price'] = $price; |
|
593 | + |
|
594 | + // get price types |
|
595 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
596 | + $PRT = EEM_Price_Type::instance(); |
|
597 | + $price_types = $PRT->get_all(array(array('PBT_ID' => array('!=', 1)))); |
|
598 | + $price_type_names = array(); |
|
599 | + if (empty($price_types)) { |
|
600 | + $msg = esc_html__( |
|
601 | + 'You have no price types defined. Please add a price type before adding a price.', |
|
602 | + 'event_espresso' |
|
603 | + ); |
|
604 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
605 | + exit(); |
|
606 | + } else { |
|
607 | + foreach ($price_types as $type) { |
|
608 | + // if ($type->is_global()) { |
|
609 | + $price_type_names[] = array('id' => $type->ID(), 'text' => $type->name()); |
|
610 | + // } |
|
611 | + } |
|
612 | + } |
|
613 | + |
|
614 | + $this->_template_args['price_types'] = $price_type_names; |
|
615 | + $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
616 | + |
|
617 | + $this->_set_publish_post_box_vars('id', $PRC_ID); |
|
618 | + // the details template wrapper |
|
619 | + $this->display_admin_page_with_sidebar(); |
|
620 | + } |
|
621 | + |
|
622 | + |
|
623 | + /** |
|
624 | + * declare price details page metaboxes |
|
625 | + * |
|
626 | + * @access protected |
|
627 | + * @return void |
|
628 | + */ |
|
629 | + protected function _price_details_meta_boxes() |
|
630 | + { |
|
631 | + add_meta_box( |
|
632 | + 'edit-price-details-mbox', |
|
633 | + esc_html__('Default Price Details', 'event_espresso'), |
|
634 | + array($this, '_edit_price_details_meta_box'), |
|
635 | + $this->wp_page_slug, |
|
636 | + 'normal', |
|
637 | + 'high' |
|
638 | + ); |
|
639 | + } |
|
640 | + |
|
641 | + |
|
642 | + /** |
|
643 | + * _edit_price_details_meta_box |
|
644 | + * |
|
645 | + * @access public |
|
646 | + * @return void |
|
647 | + */ |
|
648 | + public function _edit_price_details_meta_box() |
|
649 | + { |
|
650 | + echo EEH_Template::display_template( |
|
651 | + PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php', |
|
652 | + $this->_template_args, |
|
653 | + true |
|
654 | + ); |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * set_price_column_values |
|
660 | + * |
|
661 | + * @access protected |
|
662 | + * @return array |
|
663 | + */ |
|
664 | + protected function set_price_column_values() |
|
665 | + { |
|
666 | + |
|
667 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
668 | + |
|
669 | + $set_column_values = array( |
|
670 | + 'PRT_ID' => absint($this->_req_data['PRT_ID']), |
|
671 | + 'PRC_amount' => $this->_req_data['PRC_amount'], |
|
672 | + 'PRC_name' => $this->_req_data['PRC_name'], |
|
673 | + 'PRC_desc' => $this->_req_data['PRC_desc'], |
|
674 | + 'PRC_is_default' => 1, |
|
675 | + 'PRC_overrides' => null, |
|
676 | + 'PRC_order' => 0, |
|
677 | + 'PRC_deleted' => 0, |
|
678 | + 'PRC_parent' => 0, |
|
679 | + ); |
|
680 | + return $set_column_values; |
|
681 | + } |
|
682 | + |
|
683 | + |
|
684 | + /** |
|
685 | + * insert_or_update_price |
|
686 | + * |
|
687 | + * @param boolean $insert - whether to insert or update |
|
688 | + * @access protected |
|
689 | + * @return void |
|
690 | + */ |
|
691 | + protected function _insert_or_update_price($insert = false) |
|
692 | + { |
|
693 | + |
|
694 | + // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
695 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
696 | + |
|
697 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
698 | + $PRC = EEM_Price::instance(); |
|
699 | + |
|
700 | + // why be so pessimistic ??? : ( |
|
701 | + $success = 0; |
|
702 | + |
|
703 | + $set_column_values = $this->set_price_column_values(); |
|
704 | + // is this a new Price ? |
|
705 | + if ($insert) { |
|
706 | + // run the insert |
|
707 | + if ($PRC_ID = $PRC->insert($set_column_values)) { |
|
708 | + // make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type |
|
709 | + $PR = EEM_price::instance()->get_one_by_ID($PRC_ID); |
|
710 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
711 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
712 | + $ticket->_add_relation_to($PR, 'Price'); |
|
713 | + $ticket->save(); |
|
714 | + } |
|
715 | + $success = 1; |
|
716 | + } else { |
|
717 | + $PRC_ID = false; |
|
718 | + $success = 0; |
|
719 | + } |
|
720 | + $action_desc = 'created'; |
|
721 | + } else { |
|
722 | + $PRC_ID = absint($this->_req_data['PRC_ID']); |
|
723 | + // run the update |
|
724 | + $where_cols_n_values = array('PRC_ID' => $PRC_ID); |
|
725 | + if ($PRC->update($set_column_values, array($where_cols_n_values))) { |
|
726 | + $success = 1; |
|
727 | + } |
|
728 | + |
|
729 | + $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
730 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
731 | + // if this is $PRC_ID == 1, then we need to update the default ticket attached to this price so the TKT_price value is updated. |
|
732 | + if ($PRC_ID === 1) { |
|
733 | + $ticket = $PR->get_first_related('Ticket'); |
|
734 | + if ($ticket) { |
|
735 | + $ticket->set('TKT_price', $PR->get('PRC_amount')); |
|
736 | + $ticket->set('TKT_name', $PR->get('PRC_name')); |
|
737 | + $ticket->set('TKT_description', $PR->get('PRC_desc')); |
|
738 | + $ticket->save(); |
|
739 | + } |
|
740 | + } else { |
|
741 | + // we make sure this price is attached to base ticket. but ONLY if its not a tax ticket type. |
|
742 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
743 | + $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
744 | + $ticket->save(); |
|
745 | + } |
|
746 | + } |
|
747 | + |
|
748 | + $action_desc = 'updated'; |
|
749 | + } |
|
750 | + |
|
751 | + $query_args = array('action' => 'edit_price', 'id' => $PRC_ID); |
|
752 | + |
|
753 | + $this->_redirect_after_action($success, 'Prices', $action_desc, $query_args); |
|
754 | + } |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * _trash_or_restore_price |
|
759 | + * |
|
760 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
761 | + * @access protected |
|
762 | + * @return void |
|
763 | + */ |
|
764 | + protected function _trash_or_restore_price($trash = true) |
|
765 | + { |
|
766 | + |
|
767 | + // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
768 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
769 | + |
|
770 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
771 | + $PRC = EEM_Price::instance(); |
|
772 | + |
|
773 | + $success = 1; |
|
774 | + $PRC_deleted = $trash ? true : false; |
|
775 | + |
|
776 | + // get base ticket for updating |
|
777 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
778 | + // Checkboxes |
|
779 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
780 | + // if array has more than one element than success message should be plural |
|
781 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
782 | + // cycle thru checkboxes |
|
783 | + while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
784 | + if (! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), absint($PRC_ID))) { |
|
785 | + $success = 0; |
|
786 | + } else { |
|
787 | + $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
788 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
789 | + // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
790 | + if ($PRC_deleted) { |
|
791 | + $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
792 | + } else { |
|
793 | + $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
794 | + } |
|
795 | + $ticket->save(); |
|
796 | + } |
|
797 | + } |
|
798 | + } |
|
799 | + } else { |
|
800 | + // grab single id and delete |
|
801 | + $PRC_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
802 | + if (empty($PRC_ID) || ! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), $PRC_ID)) { |
|
803 | + $success = 0; |
|
804 | + } else { |
|
805 | + $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
806 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
807 | + // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
808 | + if ($PRC_deleted) { |
|
809 | + $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
810 | + } else { |
|
811 | + $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
812 | + } |
|
813 | + $ticket->save(); |
|
814 | + } |
|
815 | + } |
|
816 | + } |
|
817 | + $query_args = array( |
|
818 | + 'action' => 'default', |
|
819 | + ); |
|
820 | + |
|
821 | + if ($success) { |
|
822 | + if ($trash) { |
|
823 | + $msg = $success == 2 |
|
824 | + ? esc_html__('The Prices have been trashed.', 'event_espresso') |
|
825 | + : esc_html__( |
|
826 | + 'The Price has been trashed.', |
|
827 | + 'event_espresso' |
|
828 | + ); |
|
829 | + } else { |
|
830 | + $msg = $success == 2 |
|
831 | + ? esc_html__('The Prices have been restored.', 'event_espresso') |
|
832 | + : esc_html__( |
|
833 | + 'The Price has been restored.', |
|
834 | + 'event_espresso' |
|
835 | + ); |
|
836 | + } |
|
837 | + |
|
838 | + EE_Error::add_success($msg); |
|
839 | + } |
|
840 | + |
|
841 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
842 | + } |
|
843 | + |
|
844 | + |
|
845 | + /** |
|
846 | + * _delete_price |
|
847 | + * |
|
848 | + * @access protected |
|
849 | + * @return void |
|
850 | + */ |
|
851 | + protected function _delete_price() |
|
852 | + { |
|
853 | + |
|
854 | + // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
855 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
856 | + |
|
857 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
858 | + $PRC = EEM_Price::instance(); |
|
859 | + |
|
860 | + $success = 1; |
|
861 | + // Checkboxes |
|
862 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
863 | + // if array has more than one element than success message should be plural |
|
864 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
865 | + // cycle thru bulk action checkboxes |
|
866 | + while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
867 | + if (! $PRC->delete_permanently_by_ID(absint($PRC_ID))) { |
|
868 | + $success = 0; |
|
869 | + } |
|
870 | + } |
|
871 | + } else { |
|
872 | + // grab single id and delete |
|
873 | + $PRC_ID = absint($this->_req_data['id']); |
|
874 | + if (! $PRC->delete_permanently_by_ID($PRC_ID)) { |
|
875 | + $success = 0; |
|
876 | + } |
|
877 | + } |
|
878 | + |
|
879 | + $this->_redirect_after_action($success, 'Prices', 'deleted', array()); |
|
880 | + } |
|
881 | + |
|
882 | + |
|
883 | + public function update_price_order() |
|
884 | + { |
|
885 | + $success = esc_html__('Price order was updated successfully.', 'event_espresso'); |
|
886 | + |
|
887 | + // grab our row IDs |
|
888 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) ? explode( |
|
889 | + ',', |
|
890 | + rtrim( |
|
891 | + $this->_req_data['row_ids'], |
|
892 | + ',' |
|
893 | + ) |
|
894 | + ) : false; |
|
895 | + |
|
896 | + if (is_array($row_ids)) { |
|
897 | + for ($i = 0; $i < count($row_ids); $i++) { |
|
898 | + // Update the prices when re-ordering |
|
899 | + $id = absint($row_ids[ $i ]); |
|
900 | + if ( |
|
901 | + EEM_Price::instance()->update( |
|
902 | + array('PRC_order' => $i + 1), |
|
903 | + array(array('PRC_ID' => $id)) |
|
904 | + ) === false |
|
905 | + ) { |
|
906 | + $success = false; |
|
907 | + } |
|
908 | + } |
|
909 | + } else { |
|
910 | + $success = false; |
|
911 | + } |
|
912 | + |
|
913 | + $errors = ! $success ? esc_html__('An error occurred. The price order was not updated.', 'event_espresso') : false; |
|
914 | + |
|
915 | + echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
916 | + die(); |
|
917 | + } |
|
918 | + |
|
919 | + |
|
920 | + |
|
921 | + |
|
922 | + |
|
923 | + |
|
924 | + /************************************************************************************************************************************************************** |
|
925 | 925 | ******************************************************************** TICKET PRICE TYPES ****************************************************************** |
926 | 926 | **************************************************************************************************************************************************************/ |
927 | 927 | |
928 | 928 | |
929 | - /** |
|
930 | - * generates HTML for main Prices Admin page |
|
931 | - * |
|
932 | - * @access protected |
|
933 | - * @return void |
|
934 | - */ |
|
935 | - protected function _price_types_overview_list_table() |
|
936 | - { |
|
937 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
938 | - 'add_new_price_type', |
|
939 | - 'add_type', |
|
940 | - array(), |
|
941 | - 'add-new-h2' |
|
942 | - ); |
|
943 | - $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
944 | - $this->_search_btn_label = esc_html__('Price Types', 'event_espresso'); |
|
945 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
946 | - } |
|
947 | - |
|
948 | - |
|
949 | - /** |
|
950 | - * retrieve data for Price Types List table |
|
951 | - * |
|
952 | - * @access public |
|
953 | - * @param int $per_page how many prices displayed per page |
|
954 | - * @param boolean $count return the count or objects |
|
955 | - * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
956 | - * @return mixed (int|array) int = count || array of price objects |
|
957 | - */ |
|
958 | - public function get_price_types_overview_data($per_page = 10, $count = false, $trashed = false) |
|
959 | - { |
|
960 | - |
|
961 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
962 | - // start with an empty array |
|
963 | - |
|
964 | - require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php'); |
|
965 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
966 | - |
|
967 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
968 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
969 | - : 'ASC'; |
|
970 | - switch ($this->_req_data['orderby']) { |
|
971 | - case 'name': |
|
972 | - $orderby = array('PRT_name' => $order); |
|
973 | - break; |
|
974 | - default: |
|
975 | - $orderby = array('PRT_order' => $order); |
|
976 | - } |
|
977 | - |
|
978 | - |
|
979 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
980 | - ? $this->_req_data['paged'] : 1; |
|
981 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
982 | - ? $this->_req_data['perpage'] : $per_page; |
|
983 | - |
|
984 | - $offset = ($current_page - 1) * $per_page; |
|
985 | - $limit = array($offset, $per_page); |
|
986 | - |
|
987 | - $_where = array('PRT_deleted' => $trashed, 'PBT_ID' => array('!=', 1)); |
|
988 | - |
|
989 | - if (isset($this->_req_data['s'])) { |
|
990 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
991 | - $_where['OR'] = array( |
|
992 | - 'PRT_name' => array('LIKE', $sstr), |
|
993 | - ); |
|
994 | - } |
|
995 | - $query_params = array( |
|
996 | - $_where, |
|
997 | - 'order_by' => $orderby, |
|
998 | - 'limit' => $limit, |
|
999 | - ); |
|
1000 | - if ($count) { |
|
1001 | - return EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params); |
|
1002 | - } else { |
|
1003 | - return EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params); |
|
1004 | - } |
|
1005 | - |
|
1006 | - // EEH_Debug_Tools::printr( $price_types, '$price_types <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
1007 | - } |
|
1008 | - |
|
1009 | - |
|
1010 | - /** |
|
1011 | - * _edit_price_type_details |
|
1012 | - * |
|
1013 | - * @access protected |
|
1014 | - * @return void |
|
1015 | - */ |
|
1016 | - protected function _edit_price_type_details() |
|
1017 | - { |
|
1018 | - |
|
1019 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1020 | - |
|
1021 | - |
|
1022 | - // grab price type ID |
|
1023 | - $PRT_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
1024 | - : false; |
|
1025 | - // change page title based on request action |
|
1026 | - switch ($this->_req_action) { |
|
1027 | - case 'add_new_price_type': |
|
1028 | - $this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso'); |
|
1029 | - break; |
|
1030 | - case 'edit_price_type': |
|
1031 | - $this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso'); |
|
1032 | - break; |
|
1033 | - default: |
|
1034 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
1035 | - } |
|
1036 | - // add PRT_ID to title if editing |
|
1037 | - $this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title; |
|
1038 | - |
|
1039 | - if ($PRT_ID) { |
|
1040 | - $price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID); |
|
1041 | - $additional_hidden_fields = array('PRT_ID' => array('type' => 'hidden', 'value' => $PRT_ID)); |
|
1042 | - $this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields); |
|
1043 | - } else { |
|
1044 | - $price_type = EEM_Price_Type::instance()->get_new_price_type(); |
|
1045 | - $this->_set_add_edit_form_tags('insert_price_type'); |
|
1046 | - } |
|
1047 | - |
|
1048 | - $this->_template_args['PRT_ID'] = $PRT_ID; |
|
1049 | - $this->_template_args['price_type'] = $price_type; |
|
1050 | - |
|
1051 | - |
|
1052 | - $base_types = EEM_Price_Type::instance()->get_base_types(); |
|
1053 | - $select_values = array(); |
|
1054 | - foreach ($base_types as $ref => $text) { |
|
1055 | - if ($ref == EEM_Price_Type::base_type_base_price) { |
|
1056 | - // do not allow creation of base_type_base_prices because that's a system only base type. |
|
1057 | - continue; |
|
1058 | - } |
|
1059 | - $values[] = array('id' => $ref, 'text' => $text); |
|
1060 | - } |
|
1061 | - |
|
1062 | - |
|
1063 | - $this->_template_args['base_type_select'] = EEH_Form_Fields::select_input( |
|
1064 | - 'base_type', |
|
1065 | - $values, |
|
1066 | - $price_type->base_type(), |
|
1067 | - 'id="price-type-base-type-slct"' |
|
1068 | - ); |
|
1069 | - $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
1070 | - $redirect_URL = add_query_arg(array('action' => 'price_types'), $this->_admin_base_url); |
|
1071 | - $this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL); |
|
1072 | - // the details template wrapper |
|
1073 | - $this->display_admin_page_with_sidebar(); |
|
1074 | - } |
|
1075 | - |
|
1076 | - |
|
1077 | - /** |
|
1078 | - * declare price type details page metaboxes |
|
1079 | - * |
|
1080 | - * @access protected |
|
1081 | - * @return void |
|
1082 | - */ |
|
1083 | - protected function _price_type_details_meta_boxes() |
|
1084 | - { |
|
1085 | - add_meta_box( |
|
1086 | - 'edit-price-details-mbox', |
|
1087 | - esc_html__('Price Type Details', 'event_espresso'), |
|
1088 | - array($this, '_edit_price_type_details_meta_box'), |
|
1089 | - $this->wp_page_slug, |
|
1090 | - 'normal', |
|
1091 | - 'high' |
|
1092 | - ); |
|
1093 | - } |
|
1094 | - |
|
1095 | - |
|
1096 | - /** |
|
1097 | - * _edit_price_type_details_meta_box |
|
1098 | - * |
|
1099 | - * @access public |
|
1100 | - * @return void |
|
1101 | - */ |
|
1102 | - public function _edit_price_type_details_meta_box() |
|
1103 | - { |
|
1104 | - echo EEH_Template::display_template( |
|
1105 | - PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php', |
|
1106 | - $this->_template_args, |
|
1107 | - true |
|
1108 | - ); |
|
1109 | - } |
|
1110 | - |
|
1111 | - |
|
1112 | - /** |
|
1113 | - * set_price_type_column_values |
|
1114 | - * |
|
1115 | - * @access protected |
|
1116 | - * @return void |
|
1117 | - */ |
|
1118 | - protected function set_price_type_column_values() |
|
1119 | - { |
|
1120 | - |
|
1121 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1122 | - |
|
1123 | - $base_type = ! empty($this->_req_data['base_type']) ? $this->_req_data['base_type'] |
|
1124 | - : EEM_Price_Type::base_type_base_price; |
|
1125 | - |
|
1126 | - switch ($base_type) { |
|
1127 | - case EEM_Price_Type::base_type_base_price: |
|
1128 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_base_price; |
|
1129 | - $this->_req_data['PRT_is_percent'] = 0; |
|
1130 | - $this->_req_data['PRT_order'] = 0; |
|
1131 | - break; |
|
1132 | - |
|
1133 | - case EEM_Price_Type::base_type_discount: |
|
1134 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_discount; |
|
1135 | - break; |
|
1136 | - |
|
1137 | - case EEM_Price_Type::base_type_surcharge: |
|
1138 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_surcharge; |
|
1139 | - break; |
|
1140 | - |
|
1141 | - case EEM_Price_Type::base_type_tax: |
|
1142 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_tax; |
|
1143 | - $this->_req_data['PRT_is_percent'] = 1; |
|
1144 | - break; |
|
1145 | - }/**/ |
|
1146 | - |
|
1147 | - $set_column_values = array( |
|
1148 | - 'PRT_name' => $this->_req_data['PRT_name'], |
|
1149 | - 'PBT_ID' => absint($this->_req_data['PBT_ID']), |
|
1150 | - 'PRT_is_percent' => absint($this->_req_data['PRT_is_percent']), |
|
1151 | - 'PRT_order' => absint($this->_req_data['PRT_order']), |
|
1152 | - 'PRT_deleted' => 0, |
|
1153 | - ); |
|
1154 | - |
|
1155 | - return $set_column_values; |
|
1156 | - } |
|
1157 | - |
|
1158 | - |
|
1159 | - /** |
|
1160 | - * _insert_or_update_price_type |
|
1161 | - * |
|
1162 | - * @param boolean $new_price_type - whether to insert or update |
|
1163 | - * @access protected |
|
1164 | - * @return void |
|
1165 | - */ |
|
1166 | - protected function _insert_or_update_price_type($new_price_type = false) |
|
1167 | - { |
|
1168 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1169 | - |
|
1170 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
1171 | - $PRT = EEM_Price_Type::instance(); |
|
1172 | - |
|
1173 | - // why be so pessimistic ??? : ( |
|
1174 | - $success = 0; |
|
1175 | - |
|
1176 | - $set_column_values = $this->set_price_type_column_values(); |
|
1177 | - // is this a new Price ? |
|
1178 | - if ($new_price_type) { |
|
1179 | - // run the insert |
|
1180 | - if ($PRT_ID = $PRT->insert($set_column_values)) { |
|
1181 | - $success = 1; |
|
1182 | - } |
|
1183 | - $action_desc = 'created'; |
|
1184 | - } else { |
|
1185 | - $PRT_ID = absint($this->_req_data['PRT_ID']); |
|
1186 | - // run the update |
|
1187 | - $where_cols_n_values = array('PRT_ID' => $PRT_ID); |
|
1188 | - if ($PRT->update($set_column_values, array($where_cols_n_values))) { |
|
1189 | - $success = 1; |
|
1190 | - } |
|
1191 | - $action_desc = 'updated'; |
|
1192 | - } |
|
1193 | - |
|
1194 | - $query_args = array('action' => 'edit_price_type', 'id' => $PRT_ID); |
|
1195 | - $this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args); |
|
1196 | - } |
|
1197 | - |
|
1198 | - |
|
1199 | - /** |
|
1200 | - * _trash_or_restore_price_type |
|
1201 | - * |
|
1202 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
1203 | - * @access protected |
|
1204 | - * @return void |
|
1205 | - */ |
|
1206 | - protected function _trash_or_restore_price_type($trash = true) |
|
1207 | - { |
|
1208 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1209 | - |
|
1210 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
1211 | - $PRT = EEM_Price_Type::instance(); |
|
1212 | - |
|
1213 | - $success = 1; |
|
1214 | - $PRT_deleted = $trash ? true : false; |
|
1215 | - // Checkboxes |
|
1216 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1217 | - // if array has more than one element than success message should be plural |
|
1218 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1219 | - $what = count($this->_req_data['checkbox']) > 1 ? 'Price Types' : 'Price Type'; |
|
1220 | - // cycle thru checkboxes |
|
1221 | - while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1222 | - if (! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
1223 | - $success = 0; |
|
1224 | - } |
|
1225 | - } |
|
1226 | - } else { |
|
1227 | - // grab single id and delete |
|
1228 | - $PRT_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
1229 | - if (empty($PRT_ID) || ! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
1230 | - $success = 0; |
|
1231 | - } |
|
1232 | - $what = 'Price Type'; |
|
1233 | - } |
|
1234 | - |
|
1235 | - $query_args = array('action' => 'price_types'); |
|
1236 | - if ($success) { |
|
1237 | - if ($trash) { |
|
1238 | - $msg = $success > 1 |
|
1239 | - ? esc_html__('The Price Types have been trashed.', 'event_espresso') |
|
1240 | - : esc_html__( |
|
1241 | - 'The Price Type has been trashed.', |
|
1242 | - 'event_espresso' |
|
1243 | - ); |
|
1244 | - } else { |
|
1245 | - $msg = $success > 1 |
|
1246 | - ? esc_html__('The Price Types have been restored.', 'event_espresso') |
|
1247 | - : esc_html__( |
|
1248 | - 'The Price Type has been restored.', |
|
1249 | - 'event_espresso' |
|
1250 | - ); |
|
1251 | - } |
|
1252 | - EE_Error::add_success($msg); |
|
1253 | - } |
|
1254 | - |
|
1255 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1256 | - } |
|
1257 | - |
|
1258 | - |
|
1259 | - /** |
|
1260 | - * _delete_price_type |
|
1261 | - * |
|
1262 | - * @access protected |
|
1263 | - * @return void |
|
1264 | - */ |
|
1265 | - protected function _delete_price_type() |
|
1266 | - { |
|
1267 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1268 | - |
|
1269 | - $PRT = EEM_Price_Type::instance(); |
|
1270 | - |
|
1271 | - $success = 1; |
|
1272 | - // Checkboxes |
|
1273 | - if (! empty($this->_req_data['checkbox'])) { |
|
1274 | - // if array has more than one element than success message should be plural |
|
1275 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1276 | - $what = $PRT->item_name($success); |
|
1277 | - // cycle thru bulk action checkboxes |
|
1278 | - while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1279 | - if (! $PRT->delete_permanently_by_ID($PRT_ID)) { |
|
1280 | - $success = 0; |
|
1281 | - } |
|
1282 | - } |
|
1283 | - } |
|
1284 | - |
|
1285 | - |
|
1286 | - $query_args = array('action' => 'price_types'); |
|
1287 | - $this->_redirect_after_action($success, $what, 'deleted', $query_args); |
|
1288 | - } |
|
1289 | - |
|
1290 | - |
|
1291 | - /** |
|
1292 | - * _learn_more_about_pricing_link |
|
1293 | - * |
|
1294 | - * @access protected |
|
1295 | - * @return string |
|
1296 | - */ |
|
1297 | - protected function _learn_more_about_pricing_link() |
|
1298 | - { |
|
1299 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . esc_html__( |
|
1300 | - 'learn more about how pricing works', |
|
1301 | - 'event_espresso' |
|
1302 | - ) . '</a>'; |
|
1303 | - } |
|
1304 | - |
|
1305 | - |
|
1306 | - protected function _tax_settings() |
|
1307 | - { |
|
1308 | - $this->_set_add_edit_form_tags('update_tax_settings'); |
|
1309 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1310 | - $this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html(); |
|
1311 | - $this->display_admin_page_with_sidebar(); |
|
1312 | - } |
|
1313 | - |
|
1314 | - |
|
1315 | - /** |
|
1316 | - * @return \EE_Form_Section_Proper |
|
1317 | - * @throws \EE_Error |
|
1318 | - */ |
|
1319 | - protected function tax_settings_form() |
|
1320 | - { |
|
1321 | - return new EE_Form_Section_Proper( |
|
1322 | - array( |
|
1323 | - 'name' => 'tax_settings_form', |
|
1324 | - 'html_id' => 'tax_settings_form', |
|
1325 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1326 | - 'subsections' => apply_filters( |
|
1327 | - 'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections', |
|
1328 | - array( |
|
1329 | - 'tax_settings' => new EE_Form_Section_Proper( |
|
1330 | - array( |
|
1331 | - 'name' => 'tax_settings_tbl', |
|
1332 | - 'html_id' => 'tax_settings_tbl', |
|
1333 | - 'html_class' => 'form-table', |
|
1334 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
1335 | - 'subsections' => array( |
|
1336 | - 'prices_displayed_including_taxes' => new EE_Yes_No_Input( |
|
1337 | - array( |
|
1338 | - 'html_label_text' => esc_html__( |
|
1339 | - "Show Prices With Taxes Included?", |
|
1340 | - 'event_espresso' |
|
1341 | - ), |
|
1342 | - 'html_help_text' => esc_html__( |
|
1343 | - 'Indicates whether or not to display prices with the taxes included', |
|
1344 | - 'event_espresso' |
|
1345 | - ), |
|
1346 | - 'default' => isset( |
|
1347 | - EE_Registry::instance() |
|
1348 | - ->CFG |
|
1349 | - ->tax_settings |
|
1350 | - ->prices_displayed_including_taxes |
|
1351 | - ) |
|
1352 | - ? EE_Registry::instance() |
|
1353 | - ->CFG |
|
1354 | - ->tax_settings |
|
1355 | - ->prices_displayed_including_taxes |
|
1356 | - : true, |
|
1357 | - 'display_html_label_text' => false, |
|
1358 | - ) |
|
1359 | - ), |
|
1360 | - ), |
|
1361 | - ) |
|
1362 | - ), |
|
1363 | - ) |
|
1364 | - ), |
|
1365 | - ) |
|
1366 | - ); |
|
1367 | - } |
|
1368 | - |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * _update_tax_settings |
|
1372 | - * |
|
1373 | - * @since 4.9.13 |
|
1374 | - * @return void |
|
1375 | - */ |
|
1376 | - public function _update_tax_settings() |
|
1377 | - { |
|
1378 | - if (! isset(EE_Registry::instance()->CFG->tax_settings)) { |
|
1379 | - EE_Registry::instance()->CFG->tax_settings = new EE_Tax_Config(); |
|
1380 | - } |
|
1381 | - try { |
|
1382 | - $tax_form = $this->tax_settings_form(); |
|
1383 | - // check for form submission |
|
1384 | - if ($tax_form->was_submitted()) { |
|
1385 | - // capture form data |
|
1386 | - $tax_form->receive_form_submission(); |
|
1387 | - // validate form data |
|
1388 | - if ($tax_form->is_valid()) { |
|
1389 | - // grab validated data from form |
|
1390 | - $valid_data = $tax_form->valid_data(); |
|
1391 | - // set data on config |
|
1392 | - EE_Registry::instance() |
|
1393 | - ->CFG |
|
1394 | - ->tax_settings |
|
1395 | - ->prices_displayed_including_taxes |
|
1396 | - = $valid_data['tax_settings']['prices_displayed_including_taxes']; |
|
1397 | - } else { |
|
1398 | - if ($tax_form->submission_error_message() !== '') { |
|
1399 | - EE_Error::add_error( |
|
1400 | - $tax_form->submission_error_message(), |
|
1401 | - __FILE__, |
|
1402 | - __FUNCTION__, |
|
1403 | - __LINE__ |
|
1404 | - ); |
|
1405 | - } |
|
1406 | - } |
|
1407 | - } |
|
1408 | - } catch (EE_Error $e) { |
|
1409 | - EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__); |
|
1410 | - } |
|
1411 | - |
|
1412 | - $what = 'Tax Settings'; |
|
1413 | - $success = $this->_update_espresso_configuration( |
|
1414 | - $what, |
|
1415 | - EE_Registry::instance()->CFG->tax_settings, |
|
1416 | - __FILE__, |
|
1417 | - __FUNCTION__, |
|
1418 | - __LINE__ |
|
1419 | - ); |
|
1420 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'tax_settings')); |
|
1421 | - } |
|
929 | + /** |
|
930 | + * generates HTML for main Prices Admin page |
|
931 | + * |
|
932 | + * @access protected |
|
933 | + * @return void |
|
934 | + */ |
|
935 | + protected function _price_types_overview_list_table() |
|
936 | + { |
|
937 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
938 | + 'add_new_price_type', |
|
939 | + 'add_type', |
|
940 | + array(), |
|
941 | + 'add-new-h2' |
|
942 | + ); |
|
943 | + $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
944 | + $this->_search_btn_label = esc_html__('Price Types', 'event_espresso'); |
|
945 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
946 | + } |
|
947 | + |
|
948 | + |
|
949 | + /** |
|
950 | + * retrieve data for Price Types List table |
|
951 | + * |
|
952 | + * @access public |
|
953 | + * @param int $per_page how many prices displayed per page |
|
954 | + * @param boolean $count return the count or objects |
|
955 | + * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
956 | + * @return mixed (int|array) int = count || array of price objects |
|
957 | + */ |
|
958 | + public function get_price_types_overview_data($per_page = 10, $count = false, $trashed = false) |
|
959 | + { |
|
960 | + |
|
961 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
962 | + // start with an empty array |
|
963 | + |
|
964 | + require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php'); |
|
965 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
966 | + |
|
967 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
968 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
969 | + : 'ASC'; |
|
970 | + switch ($this->_req_data['orderby']) { |
|
971 | + case 'name': |
|
972 | + $orderby = array('PRT_name' => $order); |
|
973 | + break; |
|
974 | + default: |
|
975 | + $orderby = array('PRT_order' => $order); |
|
976 | + } |
|
977 | + |
|
978 | + |
|
979 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
980 | + ? $this->_req_data['paged'] : 1; |
|
981 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
982 | + ? $this->_req_data['perpage'] : $per_page; |
|
983 | + |
|
984 | + $offset = ($current_page - 1) * $per_page; |
|
985 | + $limit = array($offset, $per_page); |
|
986 | + |
|
987 | + $_where = array('PRT_deleted' => $trashed, 'PBT_ID' => array('!=', 1)); |
|
988 | + |
|
989 | + if (isset($this->_req_data['s'])) { |
|
990 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
991 | + $_where['OR'] = array( |
|
992 | + 'PRT_name' => array('LIKE', $sstr), |
|
993 | + ); |
|
994 | + } |
|
995 | + $query_params = array( |
|
996 | + $_where, |
|
997 | + 'order_by' => $orderby, |
|
998 | + 'limit' => $limit, |
|
999 | + ); |
|
1000 | + if ($count) { |
|
1001 | + return EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params); |
|
1002 | + } else { |
|
1003 | + return EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params); |
|
1004 | + } |
|
1005 | + |
|
1006 | + // EEH_Debug_Tools::printr( $price_types, '$price_types <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
1007 | + } |
|
1008 | + |
|
1009 | + |
|
1010 | + /** |
|
1011 | + * _edit_price_type_details |
|
1012 | + * |
|
1013 | + * @access protected |
|
1014 | + * @return void |
|
1015 | + */ |
|
1016 | + protected function _edit_price_type_details() |
|
1017 | + { |
|
1018 | + |
|
1019 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1020 | + |
|
1021 | + |
|
1022 | + // grab price type ID |
|
1023 | + $PRT_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
1024 | + : false; |
|
1025 | + // change page title based on request action |
|
1026 | + switch ($this->_req_action) { |
|
1027 | + case 'add_new_price_type': |
|
1028 | + $this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso'); |
|
1029 | + break; |
|
1030 | + case 'edit_price_type': |
|
1031 | + $this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso'); |
|
1032 | + break; |
|
1033 | + default: |
|
1034 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
1035 | + } |
|
1036 | + // add PRT_ID to title if editing |
|
1037 | + $this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title; |
|
1038 | + |
|
1039 | + if ($PRT_ID) { |
|
1040 | + $price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID); |
|
1041 | + $additional_hidden_fields = array('PRT_ID' => array('type' => 'hidden', 'value' => $PRT_ID)); |
|
1042 | + $this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields); |
|
1043 | + } else { |
|
1044 | + $price_type = EEM_Price_Type::instance()->get_new_price_type(); |
|
1045 | + $this->_set_add_edit_form_tags('insert_price_type'); |
|
1046 | + } |
|
1047 | + |
|
1048 | + $this->_template_args['PRT_ID'] = $PRT_ID; |
|
1049 | + $this->_template_args['price_type'] = $price_type; |
|
1050 | + |
|
1051 | + |
|
1052 | + $base_types = EEM_Price_Type::instance()->get_base_types(); |
|
1053 | + $select_values = array(); |
|
1054 | + foreach ($base_types as $ref => $text) { |
|
1055 | + if ($ref == EEM_Price_Type::base_type_base_price) { |
|
1056 | + // do not allow creation of base_type_base_prices because that's a system only base type. |
|
1057 | + continue; |
|
1058 | + } |
|
1059 | + $values[] = array('id' => $ref, 'text' => $text); |
|
1060 | + } |
|
1061 | + |
|
1062 | + |
|
1063 | + $this->_template_args['base_type_select'] = EEH_Form_Fields::select_input( |
|
1064 | + 'base_type', |
|
1065 | + $values, |
|
1066 | + $price_type->base_type(), |
|
1067 | + 'id="price-type-base-type-slct"' |
|
1068 | + ); |
|
1069 | + $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
1070 | + $redirect_URL = add_query_arg(array('action' => 'price_types'), $this->_admin_base_url); |
|
1071 | + $this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL); |
|
1072 | + // the details template wrapper |
|
1073 | + $this->display_admin_page_with_sidebar(); |
|
1074 | + } |
|
1075 | + |
|
1076 | + |
|
1077 | + /** |
|
1078 | + * declare price type details page metaboxes |
|
1079 | + * |
|
1080 | + * @access protected |
|
1081 | + * @return void |
|
1082 | + */ |
|
1083 | + protected function _price_type_details_meta_boxes() |
|
1084 | + { |
|
1085 | + add_meta_box( |
|
1086 | + 'edit-price-details-mbox', |
|
1087 | + esc_html__('Price Type Details', 'event_espresso'), |
|
1088 | + array($this, '_edit_price_type_details_meta_box'), |
|
1089 | + $this->wp_page_slug, |
|
1090 | + 'normal', |
|
1091 | + 'high' |
|
1092 | + ); |
|
1093 | + } |
|
1094 | + |
|
1095 | + |
|
1096 | + /** |
|
1097 | + * _edit_price_type_details_meta_box |
|
1098 | + * |
|
1099 | + * @access public |
|
1100 | + * @return void |
|
1101 | + */ |
|
1102 | + public function _edit_price_type_details_meta_box() |
|
1103 | + { |
|
1104 | + echo EEH_Template::display_template( |
|
1105 | + PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php', |
|
1106 | + $this->_template_args, |
|
1107 | + true |
|
1108 | + ); |
|
1109 | + } |
|
1110 | + |
|
1111 | + |
|
1112 | + /** |
|
1113 | + * set_price_type_column_values |
|
1114 | + * |
|
1115 | + * @access protected |
|
1116 | + * @return void |
|
1117 | + */ |
|
1118 | + protected function set_price_type_column_values() |
|
1119 | + { |
|
1120 | + |
|
1121 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1122 | + |
|
1123 | + $base_type = ! empty($this->_req_data['base_type']) ? $this->_req_data['base_type'] |
|
1124 | + : EEM_Price_Type::base_type_base_price; |
|
1125 | + |
|
1126 | + switch ($base_type) { |
|
1127 | + case EEM_Price_Type::base_type_base_price: |
|
1128 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_base_price; |
|
1129 | + $this->_req_data['PRT_is_percent'] = 0; |
|
1130 | + $this->_req_data['PRT_order'] = 0; |
|
1131 | + break; |
|
1132 | + |
|
1133 | + case EEM_Price_Type::base_type_discount: |
|
1134 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_discount; |
|
1135 | + break; |
|
1136 | + |
|
1137 | + case EEM_Price_Type::base_type_surcharge: |
|
1138 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_surcharge; |
|
1139 | + break; |
|
1140 | + |
|
1141 | + case EEM_Price_Type::base_type_tax: |
|
1142 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_tax; |
|
1143 | + $this->_req_data['PRT_is_percent'] = 1; |
|
1144 | + break; |
|
1145 | + }/**/ |
|
1146 | + |
|
1147 | + $set_column_values = array( |
|
1148 | + 'PRT_name' => $this->_req_data['PRT_name'], |
|
1149 | + 'PBT_ID' => absint($this->_req_data['PBT_ID']), |
|
1150 | + 'PRT_is_percent' => absint($this->_req_data['PRT_is_percent']), |
|
1151 | + 'PRT_order' => absint($this->_req_data['PRT_order']), |
|
1152 | + 'PRT_deleted' => 0, |
|
1153 | + ); |
|
1154 | + |
|
1155 | + return $set_column_values; |
|
1156 | + } |
|
1157 | + |
|
1158 | + |
|
1159 | + /** |
|
1160 | + * _insert_or_update_price_type |
|
1161 | + * |
|
1162 | + * @param boolean $new_price_type - whether to insert or update |
|
1163 | + * @access protected |
|
1164 | + * @return void |
|
1165 | + */ |
|
1166 | + protected function _insert_or_update_price_type($new_price_type = false) |
|
1167 | + { |
|
1168 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1169 | + |
|
1170 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
1171 | + $PRT = EEM_Price_Type::instance(); |
|
1172 | + |
|
1173 | + // why be so pessimistic ??? : ( |
|
1174 | + $success = 0; |
|
1175 | + |
|
1176 | + $set_column_values = $this->set_price_type_column_values(); |
|
1177 | + // is this a new Price ? |
|
1178 | + if ($new_price_type) { |
|
1179 | + // run the insert |
|
1180 | + if ($PRT_ID = $PRT->insert($set_column_values)) { |
|
1181 | + $success = 1; |
|
1182 | + } |
|
1183 | + $action_desc = 'created'; |
|
1184 | + } else { |
|
1185 | + $PRT_ID = absint($this->_req_data['PRT_ID']); |
|
1186 | + // run the update |
|
1187 | + $where_cols_n_values = array('PRT_ID' => $PRT_ID); |
|
1188 | + if ($PRT->update($set_column_values, array($where_cols_n_values))) { |
|
1189 | + $success = 1; |
|
1190 | + } |
|
1191 | + $action_desc = 'updated'; |
|
1192 | + } |
|
1193 | + |
|
1194 | + $query_args = array('action' => 'edit_price_type', 'id' => $PRT_ID); |
|
1195 | + $this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args); |
|
1196 | + } |
|
1197 | + |
|
1198 | + |
|
1199 | + /** |
|
1200 | + * _trash_or_restore_price_type |
|
1201 | + * |
|
1202 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
1203 | + * @access protected |
|
1204 | + * @return void |
|
1205 | + */ |
|
1206 | + protected function _trash_or_restore_price_type($trash = true) |
|
1207 | + { |
|
1208 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1209 | + |
|
1210 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
1211 | + $PRT = EEM_Price_Type::instance(); |
|
1212 | + |
|
1213 | + $success = 1; |
|
1214 | + $PRT_deleted = $trash ? true : false; |
|
1215 | + // Checkboxes |
|
1216 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1217 | + // if array has more than one element than success message should be plural |
|
1218 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1219 | + $what = count($this->_req_data['checkbox']) > 1 ? 'Price Types' : 'Price Type'; |
|
1220 | + // cycle thru checkboxes |
|
1221 | + while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1222 | + if (! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
1223 | + $success = 0; |
|
1224 | + } |
|
1225 | + } |
|
1226 | + } else { |
|
1227 | + // grab single id and delete |
|
1228 | + $PRT_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
1229 | + if (empty($PRT_ID) || ! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
1230 | + $success = 0; |
|
1231 | + } |
|
1232 | + $what = 'Price Type'; |
|
1233 | + } |
|
1234 | + |
|
1235 | + $query_args = array('action' => 'price_types'); |
|
1236 | + if ($success) { |
|
1237 | + if ($trash) { |
|
1238 | + $msg = $success > 1 |
|
1239 | + ? esc_html__('The Price Types have been trashed.', 'event_espresso') |
|
1240 | + : esc_html__( |
|
1241 | + 'The Price Type has been trashed.', |
|
1242 | + 'event_espresso' |
|
1243 | + ); |
|
1244 | + } else { |
|
1245 | + $msg = $success > 1 |
|
1246 | + ? esc_html__('The Price Types have been restored.', 'event_espresso') |
|
1247 | + : esc_html__( |
|
1248 | + 'The Price Type has been restored.', |
|
1249 | + 'event_espresso' |
|
1250 | + ); |
|
1251 | + } |
|
1252 | + EE_Error::add_success($msg); |
|
1253 | + } |
|
1254 | + |
|
1255 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1256 | + } |
|
1257 | + |
|
1258 | + |
|
1259 | + /** |
|
1260 | + * _delete_price_type |
|
1261 | + * |
|
1262 | + * @access protected |
|
1263 | + * @return void |
|
1264 | + */ |
|
1265 | + protected function _delete_price_type() |
|
1266 | + { |
|
1267 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1268 | + |
|
1269 | + $PRT = EEM_Price_Type::instance(); |
|
1270 | + |
|
1271 | + $success = 1; |
|
1272 | + // Checkboxes |
|
1273 | + if (! empty($this->_req_data['checkbox'])) { |
|
1274 | + // if array has more than one element than success message should be plural |
|
1275 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1276 | + $what = $PRT->item_name($success); |
|
1277 | + // cycle thru bulk action checkboxes |
|
1278 | + while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1279 | + if (! $PRT->delete_permanently_by_ID($PRT_ID)) { |
|
1280 | + $success = 0; |
|
1281 | + } |
|
1282 | + } |
|
1283 | + } |
|
1284 | + |
|
1285 | + |
|
1286 | + $query_args = array('action' => 'price_types'); |
|
1287 | + $this->_redirect_after_action($success, $what, 'deleted', $query_args); |
|
1288 | + } |
|
1289 | + |
|
1290 | + |
|
1291 | + /** |
|
1292 | + * _learn_more_about_pricing_link |
|
1293 | + * |
|
1294 | + * @access protected |
|
1295 | + * @return string |
|
1296 | + */ |
|
1297 | + protected function _learn_more_about_pricing_link() |
|
1298 | + { |
|
1299 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . esc_html__( |
|
1300 | + 'learn more about how pricing works', |
|
1301 | + 'event_espresso' |
|
1302 | + ) . '</a>'; |
|
1303 | + } |
|
1304 | + |
|
1305 | + |
|
1306 | + protected function _tax_settings() |
|
1307 | + { |
|
1308 | + $this->_set_add_edit_form_tags('update_tax_settings'); |
|
1309 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1310 | + $this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html(); |
|
1311 | + $this->display_admin_page_with_sidebar(); |
|
1312 | + } |
|
1313 | + |
|
1314 | + |
|
1315 | + /** |
|
1316 | + * @return \EE_Form_Section_Proper |
|
1317 | + * @throws \EE_Error |
|
1318 | + */ |
|
1319 | + protected function tax_settings_form() |
|
1320 | + { |
|
1321 | + return new EE_Form_Section_Proper( |
|
1322 | + array( |
|
1323 | + 'name' => 'tax_settings_form', |
|
1324 | + 'html_id' => 'tax_settings_form', |
|
1325 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1326 | + 'subsections' => apply_filters( |
|
1327 | + 'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections', |
|
1328 | + array( |
|
1329 | + 'tax_settings' => new EE_Form_Section_Proper( |
|
1330 | + array( |
|
1331 | + 'name' => 'tax_settings_tbl', |
|
1332 | + 'html_id' => 'tax_settings_tbl', |
|
1333 | + 'html_class' => 'form-table', |
|
1334 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
1335 | + 'subsections' => array( |
|
1336 | + 'prices_displayed_including_taxes' => new EE_Yes_No_Input( |
|
1337 | + array( |
|
1338 | + 'html_label_text' => esc_html__( |
|
1339 | + "Show Prices With Taxes Included?", |
|
1340 | + 'event_espresso' |
|
1341 | + ), |
|
1342 | + 'html_help_text' => esc_html__( |
|
1343 | + 'Indicates whether or not to display prices with the taxes included', |
|
1344 | + 'event_espresso' |
|
1345 | + ), |
|
1346 | + 'default' => isset( |
|
1347 | + EE_Registry::instance() |
|
1348 | + ->CFG |
|
1349 | + ->tax_settings |
|
1350 | + ->prices_displayed_including_taxes |
|
1351 | + ) |
|
1352 | + ? EE_Registry::instance() |
|
1353 | + ->CFG |
|
1354 | + ->tax_settings |
|
1355 | + ->prices_displayed_including_taxes |
|
1356 | + : true, |
|
1357 | + 'display_html_label_text' => false, |
|
1358 | + ) |
|
1359 | + ), |
|
1360 | + ), |
|
1361 | + ) |
|
1362 | + ), |
|
1363 | + ) |
|
1364 | + ), |
|
1365 | + ) |
|
1366 | + ); |
|
1367 | + } |
|
1368 | + |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * _update_tax_settings |
|
1372 | + * |
|
1373 | + * @since 4.9.13 |
|
1374 | + * @return void |
|
1375 | + */ |
|
1376 | + public function _update_tax_settings() |
|
1377 | + { |
|
1378 | + if (! isset(EE_Registry::instance()->CFG->tax_settings)) { |
|
1379 | + EE_Registry::instance()->CFG->tax_settings = new EE_Tax_Config(); |
|
1380 | + } |
|
1381 | + try { |
|
1382 | + $tax_form = $this->tax_settings_form(); |
|
1383 | + // check for form submission |
|
1384 | + if ($tax_form->was_submitted()) { |
|
1385 | + // capture form data |
|
1386 | + $tax_form->receive_form_submission(); |
|
1387 | + // validate form data |
|
1388 | + if ($tax_form->is_valid()) { |
|
1389 | + // grab validated data from form |
|
1390 | + $valid_data = $tax_form->valid_data(); |
|
1391 | + // set data on config |
|
1392 | + EE_Registry::instance() |
|
1393 | + ->CFG |
|
1394 | + ->tax_settings |
|
1395 | + ->prices_displayed_including_taxes |
|
1396 | + = $valid_data['tax_settings']['prices_displayed_including_taxes']; |
|
1397 | + } else { |
|
1398 | + if ($tax_form->submission_error_message() !== '') { |
|
1399 | + EE_Error::add_error( |
|
1400 | + $tax_form->submission_error_message(), |
|
1401 | + __FILE__, |
|
1402 | + __FUNCTION__, |
|
1403 | + __LINE__ |
|
1404 | + ); |
|
1405 | + } |
|
1406 | + } |
|
1407 | + } |
|
1408 | + } catch (EE_Error $e) { |
|
1409 | + EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__); |
|
1410 | + } |
|
1411 | + |
|
1412 | + $what = 'Tax Settings'; |
|
1413 | + $success = $this->_update_espresso_configuration( |
|
1414 | + $what, |
|
1415 | + EE_Registry::instance()->CFG->tax_settings, |
|
1416 | + __FILE__, |
|
1417 | + __FUNCTION__, |
|
1418 | + __LINE__ |
|
1419 | + ); |
|
1420 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'tax_settings')); |
|
1421 | + } |
|
1422 | 1422 | } |
@@ -2,23 +2,23 @@ |
||
2 | 2 | <strong><?php esc_html_e('Default Pricing', 'event_espresso'); ?></strong> |
3 | 3 | <br /> |
4 | 4 | <?php esc_html_e( |
5 | - 'This page shows all default prices that have been created with Event Espresso. These default prices can be applied to all events that are created.', |
|
6 | - 'event_espresso' |
|
7 | - ); ?> |
|
5 | + 'This page shows all default prices that have been created with Event Espresso. These default prices can be applied to all events that are created.', |
|
6 | + 'event_espresso' |
|
7 | + ); ?> |
|
8 | 8 | </p> |
9 | 9 | <p> |
10 | 10 | <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong> |
11 | 11 | <br /> |
12 | 12 | <?php esc_html_e( |
13 | - 'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.', |
|
14 | - 'event_espresso' |
|
15 | - ); ?> |
|
13 | + 'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.', |
|
14 | + 'event_espresso' |
|
15 | + ); ?> |
|
16 | 16 | </p> |
17 | 17 | <p> |
18 | 18 | <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong> |
19 | 19 | <br /> |
20 | 20 | <?php esc_html_e( |
21 | - 'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content and even adjust the pagination for default pricing.', |
|
22 | - 'event_espresso' |
|
23 | - ); ?> |
|
21 | + 'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content and even adjust the pagination for default pricing.', |
|
22 | + 'event_espresso' |
|
23 | + ); ?> |
|
24 | 24 | </p> |
25 | 25 | \ No newline at end of file |