Completed
Branch BUG-8957-add-countries (49f36b)
by
unknown
33:27 queued 16:54
created

Pricing_Admin_Page   F

Complexity

Total Complexity 154

Size/Duplication

Total Lines 1392
Duplicated Lines 12.64 %

Coupling/Cohesion

Components 2
Dependencies 16

Importance

Changes 0
Metric Value
dl 176
loc 1392
rs 0.6314
c 0
b 0
f 0
wmc 154
lcom 2
cbo 16

40 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A _init_page_props() 0 6 1
A _ajax_hooks() 0 3 1
A _define_page_props() 0 13 1
B _set_page_routes() 0 115 5
B _set_page_config() 0 136 2
A _add_screen_options() 0 3 1
A _add_screen_options_default() 0 3 1
A _add_screen_options_price_types() 6 6 1
A _add_feature_pointers() 0 1 1
A load_scripts_styles() 0 16 1
A load_scripts_styles_default() 0 3 1
A admin_footer_scripts() 0 1 1
A admin_init() 0 1 1
A admin_notices() 0 1 1
B _set_list_table_views_default() 24 24 2
B _set_list_table_views_price_types() 24 24 2
A _price_overview_list_table() 11 11 1
F get_prices_overview_data() 0 61 14
C _edit_price_details() 10 60 9
A _price_details_meta_boxes() 0 3 1
A _edit_price_details_meta_box() 0 3 1
A set_price_column_values() 0 17 1
C _insert_or_update_price() 0 65 8
C _trash_or_restore_price() 37 71 18
C _delete_price() 18 32 7
C update_price_order() 0 23 7
A _price_types_overview_list_table() 11 11 1
F get_price_types_overview_data() 0 45 11
C _edit_price_type_details() 18 55 9
A _price_type_details_meta_boxes() 0 3 1
A _edit_price_type_details_meta_box() 0 3 1
B set_price_type_column_values() 9 38 6
B _insert_or_update_price_type() 0 33 4
C _trash_or_restore_price_type() 8 45 15
B _delete_price_type() 0 27 5
A _learn_more_about_pricing_link() 0 3 1
A _tax_settings() 0 6 1
A tax_settings_form() 0 48 2
B _update_tax_settings() 0 45 6

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Pricing_Admin_Page often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Pricing_Admin_Page, and based on these observations, apply Extract Interface, too.

1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
/**
3
 * Event Espresso
4
 *
5
 * Event Registration and Management Plugin for WordPress
6
 *
7
 * @ package			Event Espresso
8
 * @ author				Seth Shoultes
9
 * @ copyright		(c) 2008-2011 Event Espresso  All Rights Reserved.
10
 * @ license			{@link http://eventespresso.com/support/terms-conditions/}   * see Plugin Licensing *
11
 * @ link					{@link http://www.eventespresso.com}
12
 * @ since		 		4.0
13
 *
14
 * ------------------------------------------------------------------------
15
 *
16
 * Pricing_Admin_Page class
17
 *
18
 * @package			Event Espresso
19
 * @subpackage		includes/core/admin/pricing/Pricing_Admin_Page.core.php
20
 * @author				Brent Christensen
21
 *
22
 * ------------------------------------------------------------------------
23
 */
24
class Pricing_Admin_Page extends EE_Admin_Page {
25
26
	/**
27
	 *    constructor
28
	 *
29
	 * @Constructor
30
	 * @access public
31
	 * @param bool $routing
32
	 * @return Pricing_Admin_Page
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
33
	 */
34
	public function __construct( $routing = TRUE ) {
35
		parent::__construct( $routing );
36
	}
37
38
39
40
41
	protected function _init_page_props() {
42
		$this->page_slug = PRICING_PG_SLUG;
43
		$this->page_label = PRICING_LABEL;
44
		$this->_admin_base_url = PRICING_ADMIN_URL;
45
		$this->_admin_base_path = PRICING_ADMIN;
46
	}
47
48
49
50
51
	protected function _ajax_hooks() {
52
		add_action('wp_ajax_espresso_update_prices_order', array( $this, 'update_price_order' ));
53
	}
54
55
56
57
58
59
	protected function _define_page_props() {
60
		$this->_admin_page_title = PRICING_LABEL;
61
		$this->_labels = array(
62
			'buttons' => array(
63
				'add' => __('Add New Default Price', 'event_espresso'),
64
				'edit' => __('Edit Default Price', 'event_espresso'),
65
				'delete' => __('Delete Default Price', 'event_espresso'),
66
				'add_type' => __('Add New Default Price Type', 'event_espresso'),
67
				'edit_type' => __('Edit Price Type', 'event_espresso'),
68
				'delete_type' => __('Delete Price Type', 'event_espresso')
69
			)
70
		);
71
	}
72
73
74
75
76
77
78
79
	/**
80
	 * 		an array for storing request actions and their corresponding methods
81
	*		@access private
82
	*		@return void
83
	*/
84
	protected function _set_page_routes() {
85
		$prc_id = ! empty( $this->_req_data['PRC_ID'] ) && ! is_array( $this->_req_data['PRC_ID'] ) ? $this->_req_data['PRC_ID'] : 0;
86
		$prt_id =  ! empty( $this->_req_data['PRT_ID'] ) && ! is_array( $this->_req_data['PRT_ID'] ) ? $this->_req_data['PRT_ID'] : 0;
87
		$this->_page_routes = array(
88
			'default' => array(
89
					'func' => '_price_overview_list_table',
90
					'capability' => 'ee_read_default_prices'
91
				),
92
			'add_new_price'	=> array(
93
					'func' => '_edit_price_details',
94
					'args' => array( 'new_price' => TRUE ),
95
					'capability' => 'ee_edit_default_prices'
96
				),
97
			'edit_price'	=> array(
98
					'func' => '_edit_price_details',
99
					'args' => array( 'new_price' => FALSE ),
100
					'capability' => 'ee_edit_default_price',
101
					'obj_id' => $prc_id
102
				),
103
			'insert_price'	=> array(
104
					'func' => '_insert_or_update_price',
105
					'args' => array( 'new_price' => TRUE ),
106
					'noheader' => TRUE,
107
					'capability' => 'ee_edit_default_prices',
108
				),
109
			'update_price'	=> array(
110
					'func' => '_insert_or_update_price',
111
					'args' => array( 'new_price' => FALSE ),
112
					'noheader' => TRUE,
113
					'capability' => 'ee_edit_default_price',
114
					'obj_id' => $prc_id
115
				),
116
			'trash_price'	=> array(
117
					'func' => '_trash_or_restore_price',
118
					'args' => array( 'trash' => TRUE ),
119
					'noheader' => TRUE,
120
					'capability' => 'ee_delete_default_price',
121
					'obj_id' => $prc_id
122
				),
123
			'restore_price'	=> array(
124
					'func' => '_trash_or_restore_price',
125
					'args' => array( 'trash' => FALSE ),
126
					'noheader' => TRUE,
127
					'capability' => 'ee_delete_default_price',
128
					'obj_id' => $prc_id
129
				),
130
			'delete_price'	=> array(
131
					'func' => '_delete_price',
132
					'noheader' => TRUE,
133
					'capability' => 'ee_delete_default_price',
134
					'obj_id' => $prc_id
135
				),
136
			'espresso_update_price_order' => array(
137
				'func' => 'update_price_order',
138
				'noheader' => TRUE,
139
				'capability' => 'ee_edit_default_prices'
140
				),
141
			// price types
142
			'price_types'	=> array(
143
					'func' => '_price_types_overview_list_table',
144
					'capability' => 'ee_read_default_price_types'
145
				),
146
			'add_new_price_type'	=> array(
147
					'func' => '_edit_price_type_details',
148
					'capability' => 'ee_edit_default_price_types'
149
				),
150
			'edit_price_type'	=> array(
151
					'func' => '_edit_price_type_details',
152
					'capability' => 'ee_edit_default_price_type',
153
					'obj_id' => $prt_id
154
				),
155
			'insert_price_type'	=> array(
156
					'func' => '_insert_or_update_price_type',
157
					'args' => array( 'new_price_type' => TRUE ),
158
					'noheader' => TRUE,
159
					'capability' => 'ee_edit_default_price_types'
160
				),
161
			'update_price_type' => array(
162
					'func' => '_insert_or_update_price_type',
163
					'args' => array( 'new_price_type' => FALSE ),
164
					'noheader' => TRUE,
165
					'capability' => 'ee_edit_default_price_type',
166
					'obj_id' => $prt_id
167
				),
168
			'trash_price_type'	=> array(
169
					'func' => '_trash_or_restore_price_type',
170
					'args' => array( 'trash' => TRUE ),
171
					'noheader' => TRUE,
172
					'capability' => 'ee_delete_default_price_type',
173
					'obj_id' => $prt_id
174
				),
175
			'restore_price_type'	=> array(
176
					'func' => '_trash_or_restore_price_type',
177
					'args' => array( 'trash' => FALSE ),
178
					'noheader' => TRUE,
179
					'capability' => 'ee_delete_default_price_type',
180
					'obj_id' => $prt_id
181
				),
182
			'delete_price_type'	=> array(
183
					'func' => '_delete_price_type',
184
					'noheader' => TRUE,
185
					'capability' => 'ee_delete_default_price_type',
186
					'obj_id' => $prt_id
187
				),
188
            'tax_settings' => array(
189
                'func'       => '_tax_settings',
190
                'capability' => 'manage_options'
191
            ),
192
            'update_tax_settings' => array(
193
                'func'       => '_update_tax_settings',
194
                'capability' => 'manage_options',
195
                'noheader'   => true
196
            ),
197
        );
198
	}
199
200
201
202
203
	protected function _set_page_config() {
204
205
		$this->_page_config = array(
206
			'default' => array(
207
					'nav' => array(
208
							'label' => __('Default Pricing', 'event_espresso'),
209
							'order' => 10
210
						),
211
					'list_table' => 'Prices_List_Table',
212
                    'help_tabs' => array(
213
						'pricing_default_pricing_help_tab' => array(
214
							'title' => __('Default Pricing', 'event_espresso'),
215
							'filename' => 'pricing_default_pricing'
216
							),
217
						'pricing_default_pricing_table_column_headings_help_tab' => array(
218
							'title' => __('Default Pricing Table Column Headings', 'event_espresso'),
219
							'filename' => 'pricing_default_pricing_table_column_headings'
220
							),
221
						'pricing_default_pricing_views_bulk_actions_search_help_tab' => array(
222
							'title' => __('Default Pricing Views & Bulk Actions & Search', 'event_espresso'),
223
							'filename' => 'pricing_default_pricing_views_bulk_actions_search'
224
							)
225
						),
226
					'help_tour' => array( 'Pricing_Default_Prices_Help_Tour'),
227
					'require_nonce' => FALSE
228
				),
229
			'add_new_price' => array(
230
					'nav' => array(
231
							'label' => __('Add New Default Price', 'event_espresso'),
232
							'order' => 20,
233
							'persistent' => FALSE
234
						),
235
                    'help_tabs' => array(
236
						'add_new_default_price_help_tab' => array(
237
							'title' => __('Add New Default Price', 'event_espresso'),
238
							'filename' => 'pricing_add_new_default_price'
239
							)
240
						),
241
                    'help_tour' => array('Pricing_Add_New_Default_Price_Help_Tour'),
242
					'metaboxes' => array( '_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes' ),
243
					'require_nonce' => FALSE
244
				),
245
			'edit_price' => array(
246
					'nav' => array(
247
							'label' => __('Edit Default Price', 'event_espresso'),
248
							'order' => 20,
249
							'url' => isset($this->_req_data['id']) ? add_query_arg(array('id' => $this->_req_data['id'] ), $this->_current_page_view_url )  : $this->_admin_base_url,
250
							'persistent' => FALSE
251
						),
252
					'metaboxes' => array( '_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes' ),
253
                    'help_tabs' => array(
254
						'edit_default_price_help_tab' => array(
255
							'title' => __('Edit Default Price', 'event_espresso'),
256
							'filename' => 'pricing_edit_default_price'
257
							)
258
						),
259
					'help_tour' => array( 'Pricing_Edit_Default_Price_Help_Tour' ),
260
					'require_nonce' => FALSE
261
				),
262
			'price_types' => array(
263
					'nav' => array(
264
							'label' => __('Price Types', 'event_espresso'),
265
							'order' => 30
266
						),
267
					'list_table' => 'Price_Types_List_Table',
268
                    'help_tabs' => array(
269
						'pricing_price_types_help_tab' => array(
270
							'title' => __('Price Types', 'event_espresso'),
271
							'filename' => 'pricing_price_types'
272
							),
273
						'pricing_price_types_table_column_headings_help_tab' => array(
274
							'title' => __('Price Types Table Column Headings', 'event_espresso'),
275
							'filename' => 'pricing_price_types_table_column_headings'
276
							),
277
						'pricing_price_types_views_bulk_actions_search_help_tab' => array(
278
							'title' => __('Price Types Views & Bulk Actions & Search', 'event_espresso'),
279
							'filename' => 'pricing_price_types_views_bulk_actions_search'
280
							),
281
						),
282
					'help_tour' => array( 'Pricing_Price_Types_Default_Help_Tour' ),
283
					'metaboxes' => array('_espresso_news_post_box', '_espresso_links_post_box'),
284
					'require_nonce' => FALSE
285
				),
286
			'add_new_price_type' => array(
287
					'nav' => array(
288
							'label' => __('Add New Price Type', 'event_espresso'),
289
							'order' => 40,
290
							'persistent' => FALSE
291
						),
292
                    'help_tabs' => array(
293
						'add_new_price_type_help_tab' => array(
294
							'title' => __('Add New Price Type', 'event_espresso'),
295
							'filename' => 'pricing_add_new_price_type'
296
							)
297
						),
298
                    'help_tour' => array( 'Pricing_Add_New_Price_Type_Help_Tour' ),
299
					'metaboxes' => array( '_publish_post_box', '_espresso_news_post_box', '_price_type_details_meta_boxes' ),
300
					'require_nonce' => FALSE
301
				),
302
			'edit_price_type' => array(
303
					'nav' => array(
304
							'label' => __('Edit Price Type', 'event_espresso'),
305
							'order' => 40,
306
							'persistent' => FALSE
307
						),
308
                    'help_tabs' => array(
309
						'edit_price_type_help_tab' => array(
310
							'title' => __('Edit Price Type', 'event_espresso'),
311
							'filename' => 'pricing_edit_price_type'
312
							)
313
						),
314
                    'help_tour' => array( 'Pricing_Edit_Price_Type_Help_Tour' ),
315
					'metaboxes' => array( '_publish_post_box', '_espresso_news_post_box', '_price_type_details_meta_boxes' ),
316
317
					'require_nonce' => FALSE
318
				),
319
            'tax_settings' => array(
320
                'nav'           => array(
321
                    'label' => esc_html__('Tax Settings', 'event_espresso'),
322
                    'order' => 40
323
                ),
324
                'labels'        => array(
325
                    'publishbox' => esc_html__('Update Tax Settings', 'event_espresso')
326
                ),
327
                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
328
                // 'help_tabs'     => array(
329
                //     'registration_form_reg_form_settings_help_tab' => array(
330
                //         'title'    => esc_html__('Registration Form Settings', 'event_espresso'),
331
                //         'filename' => 'registration_form_reg_form_settings'
332
                //     ),
333
                // ),
334
                // 'help_tour'     => array('Registration_Form_Settings_Help_Tour'),
335
                'require_nonce' => true
336
            )
337
        );
338
	}
339
340
341
	protected function _add_screen_options() {
342
		//todo
343
	}
344
345
346
	protected function _add_screen_options_default() {
347
		$this->_per_page_screen_option();
348
	}
349
350
351 View Code Duplication
	protected function _add_screen_options_price_types() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
352
		$page_title = $this->_admin_page_title;
353
		$this->_admin_page_title = __('Price Types', 'event_espresso');
354
		$this->_per_page_screen_option();
355
		$this->_admin_page_title = $page_title;
356
	}
357
358
359
360
361
	protected function _add_feature_pointers() {}
362
363
364
365
366
367
	public function load_scripts_styles() {
368
		//styles
369
		wp_enqueue_style('espresso-ui-theme');
370
		wp_register_style( 'espresso_PRICING', PRICING_ASSETS_URL . 'espresso_pricing_admin.css', array(), EVENT_ESPRESSO_VERSION );
371
		wp_enqueue_style('espresso_PRICING');
372
373
		//scripts
374
		wp_enqueue_script('ee_admin_js');
375
		wp_enqueue_script('jquery-ui-position');
376
		wp_enqueue_script('jquery-ui-widget');
377
		//wp_enqueue_script('jquery-ui-dialog');
378
		//wp_enqueue_script('jquery-ui-draggable');
379
		//wp_enqueue_script('jquery-ui-datepicker');
380
		wp_register_script( 'espresso_PRICING', PRICING_ASSETS_URL . 'espresso_pricing_admin.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE );
381
		wp_enqueue_script( 'espresso_PRICING' );
382
	}
383
384
385
386
387
388
	public function load_scripts_styles_default() {
389
		wp_enqueue_script( 'espresso_ajax_table_sorting' );
390
	}
391
392
393
394
395
396
	public function admin_footer_scripts() {}
397
	public function admin_init() {}
398
	public function admin_notices() {}
399
400
401
402
403
404
405 View Code Duplication
	protected function _set_list_table_views_default() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
406
		$this->_views = array(
407
			'all' => array(
408
					'slug' => 'all',
409
					'label' => __('View All Default Pricing', 'event_espresso'),
410
					'count' => 0,
411
					'bulk_action' => array(
412
							'trash_price' => __('Move to Trash', 'event_espresso')
413
						)
414
				)
415
		);
416
417
		if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_default_prices', 'pricing_trash_price' ) ) {
418
			$this->_views['trashed'] = array(
419
					'slug' => 'trashed',
420
					'label' => __('Trash', 'event_espresso'),
421
					'count' => 0,
422
					'bulk_action' => array(
423
							'restore_price' => __('Restore from Trash', 'event_espresso'),
424
							'delete_price' => __('Delete Permanently', 'event_espresso')
425
						)
426
				);
427
		}
428
	}
429
430
431
432
433
434
435 View Code Duplication
	protected function _set_list_table_views_price_types() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
436
		$this->_views = array(
437
			'all' => array(
438
					'slug' => 'all',
439
					'label' => __('All', 'event_espresso'),
440
					'count' => 0,
441
					'bulk_action' => array(
442
							'trash_price_type' => __('Move to Trash', 'event_espresso')
443
						)
444
				)
445
		);
446
447
		if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_default_price_types', 'pricing_trash_price_type' ) ) {
448
			 $this->_views['trashed'] = array(
449
					'slug' => 'trashed',
450
					'label' => __('Trash', 'event_espresso'),
451
					'count' => 0,
452
					'bulk_action' => array(
453
							'restore_price_type' => __('Restore from Trash', 'event_espresso'),
454
							'delete_price_type' => __('Delete Permanently', 'event_espresso')
455
						)
456
				);
457
		}
458
	}
459
460
461
	/**
462
	 * 		generates HTML for main Prices Admin page
463
	*		@access protected
464
	*		@return void
465
	*/
466 View Code Duplication
	protected function _price_overview_list_table() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
467
		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
468
		    'add_new_price',
469
            'add',
470
            array(),
471
            'add-new-h2'
472
        );
473
		$this->admin_page_title .= $this->_learn_more_about_pricing_link();
0 ignored issues
show
Bug introduced by
The property admin_page_title does not seem to exist. Did you mean _admin_page_title?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
474
		$this->_search_btn_label = __('Default Prices', 'event_espresso');
475
		$this->display_admin_list_table_page_with_no_sidebar();
476
	}
477
478
479
480
481
482
483
	/**
484
	*	retrieve data for Prices List table
485
	*	@access public
486
	* 	@param  int  $per_page    how many prices displayed per page
487
	* 	@param  boolean $count   return the count or objects
488
	* 	@param  boolean $trashed   whether the current view is of the trash can - eww yuck!
489
	* 	@return mixed (int|array)  int = count || array of price objects
490
	*/
491
	public function get_prices_overview_data( $per_page = 10, $count = FALSE, $trashed = FALSE ) {
492
493
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
494
		// start with an empty array
495
		$event_pricing = array();
0 ignored issues
show
Unused Code introduced by
$event_pricing is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
496
497
		require_once( PRICING_ADMIN . 'Prices_List_Table.class.php' );
498
		require_once(EE_MODELS . 'EEM_Price.model.php');
499
		//$PRC = EEM_Price::instance();
500
501
		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby'];
502
		$order = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'ASC';
503
504
		switch ($this->_req_data['orderby']) {
505
			case 'name':
506
				$orderby = array('PRC_name'=>$order);
507
				break;
508
			case 'type':
509
				$orderby = array('Price_Type.PRT_name'=>$order);
510
				break;
511
			case 'amount':
512
				$orderby = array('PRC_amount'=>$order);
513
				break;
514
			default:
515
				$orderby = array( 'PRC_order'=>$order, 'Price_Type.PRT_order'=>$order, 'PRC_ID'=>$order);
516
		}
517
518
		$current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1;
519
		$per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page;
520
521
		$_where = array(
522
				'PRC_is_default' => 1,
523
				'PRC_deleted' => $trashed
524
				);
525
526
		$offset = ($current_page-1)*$per_page;
527
		$limit = array( $offset, $per_page );
528
529
		if ( isset( $this->_req_data['s'] ) ) {
530
			$sstr = '%' . $this->_req_data['s'] . '%';
531
			$_where['OR'] = array(
532
				'PRC_name' => array('LIKE',$sstr ),
533
				'PRC_desc' => array('LIKE',$sstr ),
534
				'PRC_amount' => array( 'LIKE',$sstr ),
535
				'Price_Type.PRT_name' => array( 'LIKE', $sstr )
536
				);
537
		}
538
539
		$query_params = array(
540
			$_where,
541
			'order_by'=>$orderby,
542
			'limit'=>$limit,
543
			'group_by'=>'PRC_ID'
544
			);
545
546
		if($count){
547
			return $trashed ? EEM_Price::instance()->count( array( $_where ) ) : EEM_Price::instance()->count_deleted_and_undeleted(array($_where));
548
		}else{
549
			return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params);
550
		}
551
	}
552
553
554
555
556
557
558
	/**
559
	 * 		_price_details
560
	*		@access protected
561
	*		@return void
562
	*/
563
	protected function _edit_price_details() {
564
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
565
		// grab price ID
566
		$PRC_ID = isset( $this->_req_data['id'] ) && ! empty( $this->_req_data['id'] ) ? absint( $this->_req_data['id'] ) : FALSE;
567
		// change page title based on request action
568 View Code Duplication
		switch( $this->_req_action ) {
569
			case 'add_new_price' :
570
				$this->_admin_page_title = esc_html__( 'Add New Price', 'event_espresso' );
571
				break;
572
			case 'edit_price' :
573
				$this->_admin_page_title = esc_html__( 'Edit Price', 'event_espresso' );
574
				break;
575
			default :
576
				$this->_admin_page_title = ucwords( str_replace( '_', ' ', $this->_req_action ));
577
		}
578
		// add PRC_ID to title if editing
579
		$this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title;
580
581
		// get prices
582
		require_once(EE_MODELS . 'EEM_Price.model.php');
583
		$PRC = EEM_Price::instance();
584
585
		if ( $PRC_ID ) {
586
			$price = $PRC->get_one_by_ID( $PRC_ID );
587
			$additional_hidden_fields = array(
588
					'PRC_ID' => array( 'type' => 'hidden', 'value' => $PRC_ID )
589
				);
590
			$this->_set_add_edit_form_tags( 'update_price', $additional_hidden_fields );
591
		} else {
592
			$price = $PRC->get_new_price();
593
			$this->_set_add_edit_form_tags( 'insert_price' );
594
		}
595
596
		$this->_template_args['PRC_ID'] = $PRC_ID;
597
		$this->_template_args['price'] = $price;
598
599
		// get price types
600
		require_once(EE_MODELS . 'EEM_Price_Type.model.php');
601
		$PRT = EEM_Price_Type::instance();
602
		$price_types = $PRT->get_all( array( array('PBT_ID' => array('!=', 1 ) ) ) );
603
		$price_type_names = array();
604
		if (empty($price_types)) {
605
			$msg = __( 'You have no price types defined. Please add a price type before adding a price.', 'event_espresso' );
606
			EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
607
			exit();
608
		} else {
609
			foreach ($price_types as $type) {
610
//				if ($type->is_global()) {
611
					$price_type_names[] = array('id' => $type->ID(), 'text' => $type->name());
612
//				}
613
			}
614
		}
615
616
		$this->_template_args['price_types'] = $price_type_names;
617
		$this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
618
619
		$this->_set_publish_post_box_vars( 'id', $PRC_ID );
620
		// the details template wrapper
621
		$this->display_admin_page_with_sidebar();
622
	}
623
624
625
626
627
628
629
	/**
630
	 * 		declare price details page metaboxes
631
	*		@access protected
632
	*		@return void
633
	*/
634
	protected function _price_details_meta_boxes() {
635
		add_meta_box( 'edit-price-details-mbox', __( 'Default Price Details', 'event_espresso' ), array( $this, '_edit_price_details_meta_box' ), $this->wp_page_slug, 'normal', 'high' );
0 ignored issues
show
Bug introduced by
The property wp_page_slug does not seem to exist. Did you mean page_slug?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
636
	}
637
638
639
640
641
642
643
	/**
644
	 * 		_edit_price_details_meta_box
645
	*		@access public
646
	*		@return void
647
	*/
648
	public function _edit_price_details_meta_box() {
649
		echo EEH_Template::display_template( PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php', $this->_template_args, TRUE );
650
	}
651
652
653
654
655
656
	/**
657
	 * 		set_price_column_values
658
	*		@access protected
659
	*		@return array
660
	*/
661
	protected function set_price_column_values() {
662
663
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
664
665
		$set_column_values = array(
666
				'PRT_ID' => absint($this->_req_data['PRT_ID']),
667
				'PRC_amount' => $this->_req_data['PRC_amount'],
668
				'PRC_name' => $this->_req_data['PRC_name'],
669
				'PRC_desc' => $this->_req_data['PRC_desc'],
670
				'PRC_is_default' => 1,
671
				'PRC_overrides' => NULL,
672
				'PRC_order' => 0,
673
				'PRC_deleted' => 0,
674
				'PRC_parent' => 0
675
		);
676
		return $set_column_values;
677
	}
678
679
680
681
682
683
684
685
	/**
686
	 * 		insert_or_update_price
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
		//echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
694
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
695
696
		require_once(EE_MODELS . 'EEM_Price.model.php');
697
		$PRC = EEM_Price::instance();
698
699
		// why be so pessimistic ???  : (
700
		$success = 0;
701
702
		$set_column_values = $this->set_price_column_values();
703
		// is this a new Price ?
704
		if ( $insert ) {
705
			// run the insert
706
			if ( $PRC_ID = $PRC->insert( $set_column_values )) {
707
				//make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type
708
				$PR = EEM_price::instance()->get_one_by_ID($PRC_ID);
709
				if ( $PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax ) {
0 ignored issues
show
Documentation Bug introduced by
The method type_obj does not exist on object<EE_Base_Class>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
710
					$ticket = EEM_Ticket::instance()->get_one_by_ID(1);
711
					$ticket->_add_relation_to( $PR, 'Price' );
712
					$ticket->save();
713
				}
714
				$success = 1;
715
			} else {
716
				$PRC_ID = FALSE;
717
				$success = 0;
718
			}
719
			$action_desc = 'created';
720
		} else {
721
			$PRC_ID = absint( $this->_req_data['PRC_ID'] );
722
			// run the update
723
			$where_cols_n_values = array( 'PRC_ID' => $PRC_ID );
724
			if ( $PRC->update( $set_column_values, array($where_cols_n_values))) {
725
				$success = 1;
726
			}
727
728
			$PR = EEM_Price::instance()->get_one_by_ID($PRC_ID);
729
			if ( $PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax ) {
0 ignored issues
show
Documentation Bug introduced by
The method type_obj does not exist on object<EE_Base_Class>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
730
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
759
760
761
	/**
762
	 * 		_trash_or_restore_price
763
	*		@param boolean 		$trash - whether to move item to trash (TRUE) or restore it (FALSE)
764
	*		@access protected
765
	*		@return void
766
	*/
767
	protected function _trash_or_restore_price( $trash = TRUE ) {
768
769
		//echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
770
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
771
772
		require_once(EE_MODELS . 'EEM_Price.model.php');
773
		$PRC = EEM_Price::instance();
774
775
		$success = 1;
776
		$PRC_deleted = $trash ? TRUE : FALSE;
777
778
		//get base ticket for updating
779
		$ticket = EEM_Ticket::instance()->get_one_by_ID(1);
780
		//Checkboxes
781
		if (!empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
782
			// if array has more than one element than success message should be plural
783
			$success = count( $this->_req_data['checkbox'] ) > 1 ? 2 : 1;
784
			// cycle thru checkboxes
785
			while (list( $PRC_ID, $value ) = each($this->_req_data['checkbox'])) {
0 ignored issues
show
Unused Code introduced by
The assignment to $value is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
786 View Code Duplication
				if ( ! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), absint($PRC_ID) ) ) {
787
					$success = 0;
788
				} else {
789
					$PR = EEM_Price::instance()->get_one_by_ID($PRC_ID);
790
					if ( $PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax ) {
0 ignored issues
show
Documentation Bug introduced by
The method type_obj does not exist on object<EE_Base_Class>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
791
						//if trashing then remove relations to base default ticket.  If restoring then add back to base default ticket
792
						if ( $PRC_deleted ) {
793
							$ticket->_remove_relation_to($PRC_ID, 'Price');
794
						} else {
795
							$ticket->_add_relation_to($PRC_ID, 'Price');
796
						}
797
						$ticket->save();
798
					}
799
				}
800
			}
801
802
		} else {
803
			// grab single id and delete
804
			$PRC_ID = isset( $this->_req_data['id'] ) ? absint($this->_req_data['id']) : 0;
805 View Code Duplication
			if ( empty( $PRC_ID ) || ! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), $PRC_ID) ) {
806
				$success = 0;
807
			} else {
808
				$PR = EEM_Price::instance()->get_one_by_ID($PRC_ID);
809
				if ( $PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax ) {
0 ignored issues
show
Documentation Bug introduced by
The method type_obj does not exist on object<EE_Base_Class>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
810
					//if trashing then remove relations to base default ticket.  If restoring then add back to base default ticket
811
					if ( $PRC_deleted ) {
812
						$ticket->_remove_relation_to($PRC_ID, 'Price');
813
					} else {
814
						$ticket->_add_relation_to($PRC_ID, 'Price');
815
					}
816
					$ticket->save();
817
				}
818
			}
819
820
		}
821
		$query_args = array(
822
			'action' => 'default'
823
			);
824
825 View Code Duplication
		if ( $success ) {
826
			if ( $trash ) {
827
				$msg = $success == 2 ? __('The Prices have been trashed.', 'event_espresso') : __('The Price has been trashed.', 'event_espresso');
828
			} else {
829
				$msg = $success == 2 ? __('The Prices have been restored.', 'event_espresso') : __('The Price has been restored.', 'event_espresso');
830
			}
831
832
			EE_Error::add_success( $msg );
833
		}
834
835
		$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
0 ignored issues
show
Documentation introduced by
FALSE is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
836
837
	}
838
839
840
841
842
843
844
	/**
845
	 * 		_delete_price
846
	*		@access protected
847
	*		@return void
848
	*/
849
	protected function _delete_price() {
850
851
		//echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
852
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
853
854
		require_once(EE_MODELS . 'EEM_Price.model.php');
855
		$PRC = EEM_Price::instance();
856
857
		$success = 1;
858
		//Checkboxes
859 View Code Duplication
		if (!empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
860
			// if array has more than one element than success message should be plural
861
			$success = count( $this->_req_data['checkbox'] ) > 1 ? 2 : 1;
862
			// cycle thru bulk action checkboxes
863
			while (list( $PRC_ID, $value ) = each($this->_req_data['checkbox'])) {
0 ignored issues
show
Unused Code introduced by
The assignment to $value is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
864
				if (!$PRC->delete_permanently_by_ID(absint($PRC_ID))) {
865
					$success = 0;
866
				}
867
			}
868
869
		} else {
870
			// grab single id and delete
871
			$PRC_ID = absint($this->_req_data['id']);
872
			if ( ! $PRC->delete_permanently_by_ID($PRC_ID)) {
873
				$success = 0;
874
			}
875
876
		}
877
878
		$this->_redirect_after_action( $success, 'Prices', 'deleted', array() );
879
880
	}
881
882
883
884
885
	public function update_price_order() {
886
		$success = __( 'Price order was updated successfully.', 'event_espresso' );
887
888
		// grab our row IDs
889
		$row_ids = isset( $this->_req_data['row_ids'] ) && ! empty( $this->_req_data['row_ids'] ) ? explode( ',', rtrim( $this->_req_data['row_ids'], ',' )) : FALSE;
890
891
		if ( is_array( $row_ids )) {
892
			for ( $i = 0; $i < count( $row_ids ); $i++ ) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
893
				//Update the prices when re-ordering
894
				$id = absint($row_ids[$i]);
895
				if ( EEM_Price::instance()->update ( array( 'PRC_order' => $i+1 ), array(array( 'PRC_ID' => $id ) )) === FALSE ) {
896
					$success = FALSE;
897
				}
898
			}
899
		} else {
900
			$success = FALSE;
901
		}
902
903
		$errors = ! $success ? __( 'An error occurred. The price order was not updated.', 'event_espresso' ) : FALSE;
904
905
		echo json_encode( array( 'return_data' => FALSE, 'success' => $success, 'errors' => $errors ));
906
		die();
907
	}
908
909
910
911
912
913
914
	/**************************************************************************************************************************************************************
915
	  ********************************************************************  TICKET PRICE TYPES  ******************************************************************
916
	 **************************************************************************************************************************************************************/
917
918
919
920
921
922
923
	/**
924
	 * 		generates HTML for main Prices Admin page
925
	*		@access protected
926
	*		@return void
927
	*/
928 View Code Duplication
	protected function _price_types_overview_list_table() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
929
		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
930
		    'add_new_price_type',
931
            'add_type',
932
            array(),
933
            'add-new-h2'
934
        );
935
		$this->admin_page_title .= $this->_learn_more_about_pricing_link();
0 ignored issues
show
Bug introduced by
The property admin_page_title does not seem to exist. Did you mean _admin_page_title?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
936
		$this->_search_btn_label = __('Price Types', 'event_espresso');
937
		$this->display_admin_list_table_page_with_no_sidebar();
938
	}
939
940
941
942
943
944
945
	/**
946
	*	retrieve data for Price Types List table
947
	*	@access public
948
	* 	@param  int  $per_page    how many prices displayed per page
949
	* 	@param  boolean $count   return the count or objects
950
	* 	@param  boolean $trashed   whether the current view is of the trash can - eww yuck!
951
	* 	@return mixed (int|array)  int = count || array of price objects
952
	*/
953
	public function get_price_types_overview_data( $per_page = 10, $count = FALSE, $trashed = FALSE ) {
954
955
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
956
		// start with an empty array
957
958
		require_once( PRICING_ADMIN . 'Price_Types_List_Table.class.php' );
959
		require_once( EE_MODELS . 'EEM_Price_Type.model.php' );
960
961
		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby'];
962
		$order = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'ASC';
963
		switch ($this->_req_data['orderby']) {
964
			case 'name':
965
				$orderby = array( 'PRT_name' => $order);
966
				break;
967
			default:
968
				$orderby = array( 'PRT_order' => $order);
969
		}
970
971
972
		$current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1;
973
		$per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page;
974
975
		$offset = ($current_page-1)*$per_page;
976
		$limit = array( $offset, $per_page );
977
978
		$_where = array('PRT_deleted'=>$trashed, 'PBT_ID' => array('!=', 1 ) );
979
980
		if ( isset( $this->_req_data['s'] ) ) {
981
			$sstr = '%' . $this->_req_data['s'] . '%';
982
			$_where['OR'] = array(
983
				'PRT_name' => array( 'LIKE', $sstr )
984
				);
985
		}
986
		$query_params = array(
987
			$_where,
988
			'order_by'=>$orderby,
989
			'limit'=>$limit);
990
		if($count){
991
			return EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params);
992
		}else{
993
			return EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params);
994
		}
995
996
		//EEH_Debug_Tools::printr( $price_types, '$price_types  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
997
	}
998
999
1000
1001
1002
1003
1004
1005
	/**
1006
	 * 		_edit_price_type_details
1007
	*		@access protected
1008
	*		@return void
1009
	*/
1010
	protected function _edit_price_type_details() {
1011
1012
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1013
1014
1015
		// grab price type ID
1016
		$PRT_ID = isset( $this->_req_data['id'] ) && ! empty( $this->_req_data['id'] ) ? absint( $this->_req_data['id'] ) : FALSE;
1017
		// change page title based on request action
1018 View Code Duplication
		switch( $this->_req_action ) {
1019
			case 'add_new_price_type' :
1020
				$this->_admin_page_title = esc_html__( 'Add New Price Type', 'event_espresso' );
1021
				break;
1022
			case 'edit_price_type' :
1023
				$this->_admin_page_title = esc_html__( 'Edit Price Type', 'event_espresso' );
1024
				break;
1025
			default :
1026
				$this->_admin_page_title = ucwords( str_replace( '_', ' ', $this->_req_action ));
1027
		}
1028
		// add PRT_ID to title if editing
1029
		$this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title;
1030
1031
//		require_once(EE_MODELS . 'EEM_Price_Type.model.php');
1032
1033 View Code Duplication
		if ( $PRT_ID ) {
1034
			$price_type = EEM_Price_Type::instance()->get_one_by_ID( $PRT_ID );
1035
			$additional_hidden_fields = array( 'PRT_ID' => array( 'type' => 'hidden', 'value' => $PRT_ID ));
1036
			$this->_set_add_edit_form_tags( 'update_price_type', $additional_hidden_fields );
1037
		} else {
1038
			$price_type = EEM_Price_Type::instance()->get_new_price_type();
1039
			$this->_set_add_edit_form_tags( 'insert_price_type' );
1040
		}
1041
1042
		$this->_template_args['PRT_ID'] = $PRT_ID;
1043
		$this->_template_args['price_type'] = $price_type;
1044
1045
1046
		$base_types = EEM_Price_Type::instance()->get_base_types();
1047
		$select_values = array();
0 ignored issues
show
Unused Code introduced by
$select_values is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1048
		foreach ( $base_types as $ref => $text ) {
0 ignored issues
show
Bug introduced by
The expression $base_types of type integer is not traversable.
Loading history...
1049
			if ( $ref == EEM_Price_Type::base_type_base_price ) {
1050
				//do not allow creation of base_type_base_prices because that's a system only base type.
1051
				continue;
1052
			}
1053
			$values[] = array( 'id' => $ref, 'text' => $text );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$values was never initialized. Although not strictly required by PHP, it is generally a good practice to add $values = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1054
		}
1055
1056
1057
		$this->_template_args['base_type_select'] = EEH_Form_Fields::select_input('base_type', $values, $price_type->base_type(), 'id="price-type-base-type-slct"');
0 ignored issues
show
Bug introduced by
The variable $values does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Documentation Bug introduced by
The method base_type does not exist on object<EE_Base_Class>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1058
		$this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
1059
		$redirect_URL = add_query_arg( array( 'action' => 'price_types'), $this->_admin_base_url );
1060
		$this->_set_publish_post_box_vars( 'id', $PRT_ID, FALSE, $redirect_URL );
0 ignored issues
show
Documentation introduced by
FALSE is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1061
		// the details template wrapper
1062
		$this->display_admin_page_with_sidebar();
1063
1064
	}
1065
1066
1067
1068
1069
1070
1071
	/**
1072
	 * 		declare price type details page metaboxes
1073
	*		@access protected
1074
	*		@return void
1075
	*/
1076
	protected function _price_type_details_meta_boxes() {
1077
		add_meta_box( 'edit-price-details-mbox', __( 'Price Type Details', 'event_espresso' ), array( $this, '_edit_price_type_details_meta_box' ), $this->wp_page_slug, 'normal', 'high' );
0 ignored issues
show
Bug introduced by
The property wp_page_slug does not seem to exist. Did you mean page_slug?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1078
	}
1079
1080
1081
1082
1083
1084
	/**
1085
	 * 		_edit_price_type_details_meta_box
1086
	*		@access public
1087
	*		@return void
1088
	*/
1089
	public function _edit_price_type_details_meta_box() {
1090
		echo EEH_Template::display_template( PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php', $this->_template_args, TRUE );
1091
	}
1092
1093
1094
1095
1096
	/**
1097
	 * 		set_price_type_column_values
1098
	*		@access protected
1099
	*		@return void
1100
	*/
1101
	protected function set_price_type_column_values() {
1102
1103
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1104
1105
		$base_type = !empty( $this->_req_data['base_type'] ) ? $this->_req_data['base_type'] : EEM_Price_Type::base_type_base_price;
1106
1107
		switch ($base_type) {
1108
1109 View Code Duplication
			case EEM_Price_Type::base_type_base_price :
1110
				$this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_base_price;
1111
				$this->_req_data['PRT_is_percent'] = 0;
1112
				$this->_req_data['PRT_order'] = 0;
1113
				break;
1114
1115
			case EEM_Price_Type::base_type_discount :
1116
				$this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_discount;
1117
				break;
1118
1119
			case EEM_Price_Type::base_type_surcharge :
1120
				$this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_surcharge;
1121
				break;
1122
1123 View Code Duplication
			case EEM_Price_Type::base_type_tax :
1124
				$this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_tax;
1125
				$this->_req_data['PRT_is_percent'] = 1;
1126
				break;
1127
		}/**/
1128
1129
		$set_column_values = array(
1130
				'PRT_name' => $this->_req_data['PRT_name'],
1131
				'PBT_ID' => absint($this->_req_data['PBT_ID']),
1132
				'PRT_is_percent' => absint($this->_req_data['PRT_is_percent']),
1133
				'PRT_order' => absint($this->_req_data['PRT_order']),
1134
				'PRT_deleted' => 0
1135
		);
1136
1137
		return $set_column_values;
1138
	}
1139
1140
1141
1142
1143
1144
1145
1146
	/**
1147
	 * 		_insert_or_update_price_type
1148
	*		@param boolean 		$new_price_type - whether to insert or update
1149
	*		@access protected
1150
	*		@return void
1151
	*/
1152
	protected function _insert_or_update_price_type( $new_price_type = FALSE ) {
1153
1154
//		echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
1155
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1156
1157
		require_once(EE_MODELS . 'EEM_Price_Type.model.php');
1158
		$PRT = EEM_Price_Type::instance();
1159
1160
		// why be so pessimistic ???  : (
1161
		$success = 0;
1162
1163
		$set_column_values = $this->set_price_type_column_values();
1164
		// is this a new Price ?
1165
		if ( $new_price_type ) {
1166
			// run the insert
1167
			if ( $PRT_ID = $PRT->insert( $set_column_values )) {
1168
				$success = 1;
1169
			}
1170
			$action_desc = 'created';
1171
		} else {
1172
			$PRT_ID = absint($this->_req_data['PRT_ID']);
1173
			// run the update
1174
			$where_cols_n_values = array('PRT_ID' => $PRT_ID );
1175
			if ( $PRT->update( $set_column_values, array( $where_cols_n_values ))) {
1176
				$success = 1;
1177
			}
1178
			$action_desc = 'updated';
1179
		}
1180
1181
		$query_args = array( 'action'=> 'edit_price_type', 'id' => $PRT_ID );
1182
		$this->_redirect_after_action( $success, 'Price Type', $action_desc, $query_args );
1183
1184
	}
1185
1186
1187
1188
1189
1190
	/**
1191
	 * 		_trash_or_restore_price_type
1192
	*		@param boolean 		$trash - whether to move item to trash (TRUE) or restore it (FALSE)
1193
	*		@access protected
1194
	*		@return void
1195
	*/
1196
	protected function _trash_or_restore_price_type( $trash = TRUE ) {
1197
1198
		//echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
1199
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1200
1201
		require_once(EE_MODELS . 'EEM_Price_Type.model.php');
1202
		$PRT = EEM_Price_Type::instance();
1203
1204
		$success = 1;
1205
		$PRT_deleted = $trash ? TRUE : FALSE;
1206
		//Checkboxes
1207
		if (!empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1208
			// if array has more than one element than success message should be plural
1209
			$success = count( $this->_req_data['checkbox'] ) > 1 ? 2 : 1;
1210
			$what = count( $this->_req_data['checkbox'] ) > 1 ? 'Price Types' : 'Price Type';
0 ignored issues
show
Unused Code introduced by
$what is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1211
			// cycle thru checkboxes
1212
			while (list( $PRT_ID, $value ) = each($this->_req_data['checkbox'])) {
0 ignored issues
show
Unused Code introduced by
The assignment to $value is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1213
				if ( ! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID ) ) {
1214
					$success = 0;
1215
				}
1216
			}
1217
1218
		} else {
1219
			// grab single id and delete
1220
			$PRT_ID = isset( $this->_req_data['id'] ) ? absint($this->_req_data['id']) : 0;
1221
			if ( empty( $PRT_ID ) || ! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID )) {
1222
				$success = 0;
1223
			}
1224
			$what = 'Price Type';
0 ignored issues
show
Unused Code introduced by
$what is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1225
1226
		}
1227
1228
		$query_args = array( 'action' => 'price_types' );
1229 View Code Duplication
		if ( $success ) {
1230
			if ( $trash ) {
1231
				$msg = $success > 1 ? __('The Price Types have been trashed.', 'event_espresso') : __('The Price Type has been trashed.', 'event_espresso');
1232
			} else {
1233
				$msg = $success > 1 ? __('The Price Types have been restored.', 'event_espresso') : __('The Price Type has been restored.', 'event_espresso');
1234
			}
1235
			EE_Error::add_success( $msg );
1236
		}
1237
1238
		$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
0 ignored issues
show
Documentation introduced by
FALSE is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1239
1240
	}
1241
1242
1243
1244
1245
1246
1247
	/**
1248
	 * 		_delete_price_type
1249
	*		@access protected
1250
	*		@return void
1251
	*/
1252
	protected function _delete_price_type() {
1253
1254
		//echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
1255
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1256
1257
		$PRT = EEM_Price_Type::instance();
1258
1259
		$success = 1;
1260
		//Checkboxes
1261
		if (!empty($this->_req_data['checkbox'])) {
1262
			// if array has more than one element than success message should be plural
1263
			$success = count( $this->_req_data['checkbox'] ) > 1 ? 2 : 1;
1264
			$what = $PRT->item_name($success);
1265
			// cycle thru bulk action checkboxes
1266
			while (list( $PRT_ID, $value ) = each($this->_req_data['checkbox'])) {
0 ignored issues
show
Unused Code introduced by
The assignment to $value is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1267
				if (!$PRT->delete_permanently_by_ID($PRT_ID) ) {
1268
					$success = 0;
1269
				}
1270
			}
1271
1272
		}
1273
1274
1275
		$query_args = array( 'action'=> 'price_types' );
1276
		$this->_redirect_after_action( $success, $what, 'deleted', $query_args );
0 ignored issues
show
Bug introduced by
The variable $what does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1277
1278
	}
1279
1280
1281
1282
1283
1284
1285
1286
	/**
1287
	 * 		_learn_more_about_pricing_link
1288
	*		@access protected
1289
	*		@return string
1290
	*/
1291
	protected function _learn_more_about_pricing_link() {
1292
		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how pricing works', 'event_espresso') . '</a>';
1293
	}
1294
1295
1296
1297
    protected function _tax_settings() {
1298
        $this->_set_add_edit_form_tags('update_tax_settings');
1299
        $this->_set_publish_post_box_vars(null, false, false, null, false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
false is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1300
        $this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html();
1301
        $this->display_admin_page_with_sidebar();
1302
    }
1303
1304
1305
1306
    /**
1307
     * @return \EE_Form_Section_Proper
1308
     * @throws \EE_Error
1309
     */
1310
    protected function tax_settings_form() {
1311
        return new EE_Form_Section_Proper(
1312
            array(
1313
                'name'            => 'tax_settings_form',
1314
                'html_id'         => 'tax_settings_form',
1315
                'layout_strategy' => new EE_Div_Per_Section_Layout(),
1316
                'subsections'     => apply_filters(
1317
                    'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections',
1318
                    array(
1319
                        'tax_settings'     => new EE_Form_Section_Proper(
1320
	                        array(
1321
		                        'name'            => 'tax_settings_tbl',
1322
		                        'html_id'         => 'tax_settings_tbl',
1323
		                        'html_class'      => 'form-table',
1324
		                        'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1325
		                        'subsections'     => array(
1326
			                        'prices_displayed_including_taxes' => new EE_Yes_No_Input(
1327
				                        array(
1328
					                        'html_label_text'         => __(
1329
						                        "Show Prices With Taxes Included?",
1330
						                        'event_espresso'
1331
					                        ),
1332
					                        'html_help_text'          => __(
1333
						                        'Indicates whether or not to display prices with the taxes included',
1334
						                        'event_espresso'
1335
					                        ),
1336
					                        'default'                 => isset(
1337
					                            EE_Registry::instance()
1338
							                        ->CFG
1339
							                        ->tax_settings
1340
							                        ->prices_displayed_including_taxes
1341
					                        )
1342
						                        ? EE_Registry::instance()
1343
							                        ->CFG
1344
							                        ->tax_settings
1345
							                        ->prices_displayed_including_taxes
1346
						                        : true,
1347
					                        'display_html_label_text' => false
1348
				                        )
1349
			                        ),
1350
		                        )
1351
	                        )
1352
                        )
1353
                    )
1354
                )
1355
            )
1356
        );
1357
    }
1358
1359
1360
1361
	/**
1362
	 * _update_tax_settings
1363
	 *
1364
	 * @since 4.9.13
1365
	 * @return void
1366
	 */
1367
	public function _update_tax_settings() {
1368
		if ( ! isset( EE_Registry::instance()->CFG->tax_settings ) ) {
1369
			EE_Registry::instance()->CFG->tax_settings = new EE_Tax_Config();
1370
		}
1371
		try {
1372
			$tax_form = $this->tax_settings_form();
1373
			//check for form submission
1374
			if ( $tax_form->was_submitted() ) {
1375
				//capture form data
1376
				$tax_form->receive_form_submission();
1377
				//validate form data
1378
				if ( $tax_form->is_valid() ) {
1379
					//grab validated data from form
1380
					$valid_data = $tax_form->valid_data();
1381
					//set data on config
1382
					EE_Registry::instance()
1383
						->CFG
1384
						->tax_settings
1385
						->prices_displayed_including_taxes
1386
						= $valid_data['tax_settings']['prices_displayed_including_taxes'];
1387
				} else {
1388
					if ( $tax_form->submission_error_message() !== '' ) {
1389
						EE_Error::add_error(
1390
							$tax_form->submission_error_message(),
1391
							__FILE__,
1392
							__FUNCTION__,
1393
							__LINE__
1394
						);
1395
					}
1396
				}
1397
			}
1398
		} catch ( EE_Error $e ) {
1399
			EE_Error::add_error( $e->get_error(), __FILE__, __FUNCTION__, __LINE__ );
1400
		}
1401
1402
		$what = 'Tax Settings';
1403
		$success = $this->_update_espresso_configuration(
1404
			$what,
1405
			EE_Registry::instance()->CFG->tax_settings,
1406
			__FILE__,
1407
			__FUNCTION__,
1408
			__LINE__
1409
		);
1410
		$this->_redirect_after_action( $success, $what, 'updated', array( 'action' => 'tax_settings' ) );
0 ignored issues
show
Documentation introduced by
$success is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1411
	}
1412
1413
1414
1415
}
1416
// end of file:  includes/core/admin/pricing/Pricing_Admin_Page.core.php
1417