Completed
Branch TASK-9118-extensions-page (04eaec)
by
unknown
856:31 queued 840:33
created

Registrations_Admin_Page   F

Complexity

Total Complexity 335

Size/Duplication

Total Lines 2603
Duplicated Lines 2.46 %

Coupling/Cohesion

Components 2
Dependencies 43

Importance

Changes 0
Metric Value
wmc 335
lcom 2
cbo 43
dl 64
loc 2603
rs 0.5217
c 0
b 0
f 0

78 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B _init_page_props() 0 28 1
A clear_comment_link() 0 7 2
A _ajax_hooks() 0 4 1
A _define_page_props() 0 21 1
C _set_page_routes() 0 237 7
B _set_page_config() 0 136 3
A _add_screen_options() 0 1 1
A _add_feature_pointers() 0 1 1
A admin_init() 0 3 1
A admin_notices() 0 1 1
A admin_footer_scripts() 0 1 1
A _get_registration_status_array() 0 3 1
A _add_screen_options_default() 0 3 1
A _add_screen_options_contact_list() 6 6 1
A load_scripts_styles() 10 10 1
A load_scripts_styles_edit_attendee() 0 8 1
A load_scripts_styles_view_registration() 0 5 1
A load_scripts_styles_contact_list() 0 5 1
A load_scripts_styles_new_registration() 0 8 1
A AHEE__EE_Admin_Page__route_admin_request_resend_registration() 0 3 1
A AHEE__EE_Admin_Page__route_admin_request_approve_registration() 0 3 1
C _set_list_table_views_default() 15 84 12
A _set_list_table_views_contact_list() 0 23 2
A _registration_legend_items() 0 60 2
B _registrations_overview_list_table() 0 12 5
A _set_registration_object() 0 19 4
F get_registrations() 5 175 56
A get_registration_status_array() 0 3 1
B _registration_details() 0 49 5
B _registration_details_metaboxes() 0 13 5
B set_reg_status_buttons_metabox() 0 26 4
A _get_reg_status_buttons() 0 11 1
B _set_registration_status_from_request() 0 12 5
B _set_registration_status() 0 26 5
F _reg_status_change_return() 0 33 11
C _change_reg_status() 0 29 7
A approve_registration() 0 3 1
A decline_registration() 0 3 1
A cancel_registration() 0 3 1
A not_approve_registration() 0 3 1
A pending_registration() 0 3 1
F _reg_details_meta_box() 0 74 11
A _reg_questions_meta_box() 0 21 1
A form_before_question_group() 0 6 1
A form_after_question_group() 0 15 1
A form_form_field_label_wrap() 0 7 1
A form_form_field_input__wrap() 0 7 1
A _update_attendee_registration_form() 0 10 4
C _save_attendee_registration_form() 0 42 7
A _save_new_answer() 0 9 1
B _reg_attendees_meta_box() 0 47 6
B _reg_registrant_side_meta_box() 0 43 6
C _trash_or_restore_registrations() 5 68 16
D _delete_registrations() 0 35 9
B _delete_registration() 0 56 7
C new_registration() 0 34 7
B _get_registration_step_content() 0 44 4
A _set_reg_event() 0 12 4
A _attendee_contact_list_table() 0 5 1
A _resend_registration() 0 7 2
C process_reg_step() 12 73 12
F get_attendees() 0 76 21
B _registrations_report() 0 26 5
A _contact_list_export() 0 8 2
A _contact_list_report() 0 18 3
B _duplicate_attendee() 5 30 3
F _insert_update_cpt_item() 0 37 15
A trash_cpt_item() 0 1 1
A delete_cpt_item() 0 1 1
A restore_cpt_item() 0 1 1
A _restore_cpt_item() 0 1 1
A attendee_editor_metaboxes() 6 19 3
A attendee_contact_info() 0 6 1
B attendee_address_details() 0 43 1
A attendee_registrations_meta_box() 0 8 1
A after_title_form_fields() 0 7 2
C _trash_or_restore_attendees() 0 37 11

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 Registrations_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 Registrations_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
 * Registrations_Admin_Page class
17
 *
18
 * @package			Event Espresso
19
 * @subpackage	includes/core/admin/transactions/Registrations_Admin_Page.core.php
20
 * @author				Brent Christensen
21
 *
22
 * ------------------------------------------------------------------------
23
 */
24
class Registrations_Admin_Page extends EE_Admin_Page_CPT {
25
26
	/**
27
	 *
28
	 * @var EE_Registration
29
	 */
30
	private $_registration;
31
	private $_reg_event;
32
	private $_session;
33
	private static $_reg_status;
34
35
36
37
	/**
38
	 *        constructor
39
	 *
40
	 * @Constructor
41
	 * @access public
42
	 * @param bool $routing
43
	 * @return Registrations_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...
44
	 */
45
	public function __construct( $routing = TRUE ) {
46
		parent::__construct( $routing );
47
	}
48
49
50
51
52
53
54
	protected function _init_page_props() {
55
		$this->page_slug = REG_PG_SLUG;
56
		$this->_admin_base_url = REG_ADMIN_URL;
57
		$this->_admin_base_path = REG_ADMIN;
58
		$this->page_label = __('Registrations', 'event_espresso');
59
		$this->_cpt_routes = array(
60
			'add_new_attendee' => 'espresso_attendees',
61
			'edit_attendee' => 'espresso_attendees',
62
			'insert_attendee' => 'espresso_attendees',
63
			'update_attendee' => 'espresso_attendees'
64
			);
65
		$this->_cpt_model_names = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('add_new_attendee'...dee' => 'EEM_Attendee') of type array<string,string,{"ad...it_attendee":"string"}> is incompatible with the declared type boolean of property $_cpt_model_names.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
66
			'add_new_attendee' => 'EEM_Attendee',
67
			'edit_attendee' => 'EEM_Attendee'
68
			);
69
		$this->_cpt_edit_routes = array(
70
			'espresso_attendees' => 'edit_attendee'
71
			);
72
		$this->_pagenow_map = array(
73
				'add_new_attendee' => 'post-new.php',
74
				'edit_attendee' => 'post.php',
75
				'trash' => 'post.php'
76
			);
77
78
		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10 );
79
		//add filters so that the comment urls don't take users to a confusing 404 page
80
		add_filter('get_comment_link', array( $this, 'clear_comment_link' ), 10, 3 );
81
	}
82
83
84
	public function clear_comment_link( $link, $comment, $args ) {
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
		//gotta make sure this only happens on this route
86
		$post_type = get_post_type( $comment->comment_post_ID);
87
		if ( $post_type == 'espresso_attendees' )
88
			return '#commentsdiv';
89
		return $link;
90
	}
91
92
93
	protected function _ajax_hooks() {
94
		//todo: all hooks for registrations ajax goes in here
95
		add_action( 'wp_ajax_toggle_checkin_status', array( $this, 'toggle_checkin_status' ));
96
	}
97
98
99
100
101
102
	protected function  _define_page_props() {
103
		$this->_admin_page_title = $this->page_label;
104
		$this->_labels = array(
105
			'buttons' => array(
106
					'add-registrant' => __('Add New Registration', 'event_espresso'),
107
					'add-attendee' => __('Add Contact', 'event_espresso'),
108
					'edit' => __('Edit Contact', 'event_espresso'),
109
					'report'=>  __("Event Registrations CSV Report", "event_espresso"),
110
					'report_all' => __( 'All Registrations CSV Report', 'event_espresso' ),
111
					'contact_list_report' => __( 'Contact List Report', 'event_espresso' ),
112
					'contact_list_export'=>  __("Export Data", "event_espresso"),
113
				),
114
			'publishbox' => array(
115
				'add_new_attendee' => __("Add Contact Record", 'event_espresso'),
116
				'edit_attendee' => __("Update Contact Record", 'event_espresso')
117
				),
118
			'hide_add_button_on_cpt_route' => array(
119
				'edit_attendee' => true
120
				)
121
			);
122
	}
123
124
125
126
127
128
129
130
	/**
131
	 * 		grab url requests and route them
132
	*		@access private
133
	*		@return void
134
	*/
135
	public function _set_page_routes() {
136
137
		$this->_get_registration_status_array();
138
139
		$reg_id = ! empty( $this->_req_data['_REG_ID'] ) && ! is_array( $this->_req_data['_REG_ID'] ) ? $this->_req_data['_REG_ID'] : 0;
140
		$att_id = ! empty( $this->_req_data[ 'ATT_ID' ] ) && ! is_array( $this->_req_data['ATT_ID'] ) ? $this->_req_data['ATT_ID'] : 0;
141
		$att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] ) ? $this->_req_data['post'] : $att_id;
142
143
		$this->_page_routes = array(
144
145
				'default'	=> array(
146
					'func' => '_registrations_overview_list_table',
147
					'capability' => 'ee_read_registrations'
148
					),
149
150
				'view_registration'	=> array(
151
					'func' => '_registration_details',
152
					'capability' => 'ee_read_registration',
153
					'obj_id' => $reg_id
154
					),
155
156
				'edit_registration'	=> array(
157
						'func' => '_registration_details',
158
						'args' => array( 'edit' ),
159
						'noheader' => TRUE,
160
						'capability' => 'ee_edit_registration',
161
						'obj_id' => $reg_id
162
					),
163
164
				'trash_registrations' => array(
165
					'func' => '_trash_or_restore_registrations',
166
					'args' => array('trash' => TRUE),
167
					'noheader' => TRUE,
168
					'capability' => 'ee_delete_registrations'
169
					),
170
171
				'restore_registrations' => array(
172
					'func' => '_trash_or_restore_registrations',
173
					'args' => array( 'trash' => FALSE ),
174
					'noheader' => TRUE,
175
					'capability' => 'ee_delete_registrations'
176
					),
177
178
				'delete_registrations' => array(
179
					'func' => '_delete_registrations',
180
					'noheader' => TRUE,
181
					'capability' => 'ee_delete_registrations'
182
					),
183
184
				'update_attendee_registration_form'	=> array(
185
						'func' => '_update_attendee_registration_form',
186
						'noheader' => TRUE,
187
						'capability' => 'ee_edit_registration',
188
						'obj_id' => $reg_id
189
					),
190
191
				'new_registration' => array(
192
					'func' => 'new_registration',
193
					'capability' => 'ee_edit_registrations'
194
					),
195
196
				'process_reg_step'	=> array(
197
						'func' => 'process_reg_step',
198
						'noheader' => TRUE,
199
						'capability' => 'ee_edit_registrations'
200
					),
201
202
				'change_reg_status' => array(
203
					'func' => '_change_reg_status',
204
					'noheader' => TRUE,
205
					'capability' => 'ee_edit_registration',
206
					'obj_id' => $reg_id
207
					),
208
209
				'approve_registration'	=> array(
210
						'func' => 'approve_registration',
211
						'noheader' => TRUE,
212
						'capability' => 'ee_edit_registration',
213
						'obj_id' => $reg_id
214
					),
215
216
				'approve_and_notify_registration' => array(
217
					'func' => 'approve_registration',
218
					'noheader' => TRUE,
219
					'args' => array(TRUE),
220
					'capability' => 'ee_edit_registration',
221
					'obj_id' => $reg_id
222
					),
223
224
				'decline_registration'	=> array(
225
						'func' => 'decline_registration',
226
						'noheader' => TRUE,
227
						'capability' => 'ee_edit_registration',
228
						'obj_id' => $reg_id
229
					),
230
231
				'decline_and_notify_registration' => array(
232
					'func' => 'decline_registration',
233
					'noheader' => TRUE,
234
					'args' => array(TRUE),
235
					'capability' => 'ee_edit_registration',
236
					'obj_id' => $reg_id
237
					),
238
239
				'pending_registration'	=> array(
240
						'func' => 'pending_registration',
241
						'noheader' => TRUE,
242
						'capability' => 'ee_edit_registration',
243
						'obj_id' => $reg_id
244
					),
245
246
				'pending_and_notify_registration' => array(
247
					'func' => 'pending_registration',
248
					'noheader' => TRUE,
249
					'args' => array(TRUE),
250
					'capability' => 'ee_edit_registration',
251
					'obj_id' => $reg_id
252
					),
253
254
				'no_approve_registration' => array(
255
					'func' => 'not_approve_registration',
256
					'noheader' => TRUE,
257
					'capability' => 'ee_edit_registration',
258
					'obj_id' => $reg_id
259
					),
260
261
				'no_approve_and_notify_registration' => array(
262
					'func' => 'not_approve_registration',
263
					'noheader' => TRUE,
264
					'args' => array(TRUE),
265
					'capability' => 'ee_edit_registration',
266
					'obj_id' => $reg_id
267
					),
268
269
				'cancel_registration'	=> array(
270
						'func' => 'cancel_registration',
271
						'noheader' => TRUE,
272
						'capability' => 'ee_edit_registration',
273
						'obj_id' => $reg_id
274
					),
275
276
				'cancel_and_notify_registration' => array(
277
					'func' => 'cancel_registration',
278
					'noheader' => TRUE,
279
					'args' => array(TRUE),
280
					'capability' => 'ee_edit_registration',
281
					'obj_id' => $reg_id
282
					),
283
284
				'contact_list'	=> array(
285
					'func' => '_attendee_contact_list_table',
286
					'capability' => 'ee_read_contacts'
287
					),
288
289
290
				'add_new_attendee'	=> array(
291
					'func' => '_create_new_cpt_item',
292
					'args' => array(
293
						'new_attendee' => TRUE,
294
					'capability' => 'ee_edit_contacts'
295
					)
296
				),
297
298
				'edit_attendee'	=> array(
299
					'func' => '_edit_cpt_item',
300
					'capability' => 'ee_edit_contacts',
301
					'obj_id' => $att_id
302
				),
303
304
				'duplicate_attendee' => array(
305
					'func' => '_duplicate_attendee',
306
					'noheader' => TRUE,
307
					'capability' => 'ee_edit_contacts',
308
					'obj_id' => $att_id
309
					),
310
311
				'insert_attendee'	=> array(
312
					'func' => '_insert_or_update_attendee',
313
					'args' => array(
314
						'new_attendee' => TRUE
315
					),
316
					'noheader' => TRUE,
317
					'capability' => 'ee_edit_contacts'
318
				),
319
320
				'update_attendee'	=> array(
321
					'func' => '_insert_or_update_attendee',
322
					'args' => array(
323
						'new_attendee' => FALSE
324
					),
325
					'noheader' => TRUE,
326
					'capability' => 'ee_edit_contacts',
327
					'obj_id' => $att_id
328
				),
329
330
				'trash_attendees'	=> array(
331
					'func' => '_trash_or_restore_attendees',
332
					'args' => array(
333
						'trash' => TRUE
334
					),
335
					'noheader' => TRUE,
336
					'capability' => 'ee_delete_contacts',
337
					'obj_id' => $att_id
338
				),
339
340
				'restore_attendees'	=> array(
341
					'func' => '_trash_or_restore_attendees',
342
					'args' => array(
343
						'trash' => FALSE
344
					),
345
					'noheader' => TRUE,
346
					'capability' => 'ee_delete_contacts',
347
					'obj_id' => $att_id
348
				),
349
				'resend_registration' => array(
350
					'func' => '_resend_registration',
351
					'noheader' => TRUE,
352
					'capability' => 'ee_send_message'
353
					),
354
				'registrations_report'=>array(
355
					'func'=>'_registrations_report',
356
					'noheader'=> TRUE,
357
					'capability' => 'ee_read_registrations'
358
				),
359
				'contact_list_export'=>array(
360
					'func'=>'_contact_list_export',
361
					'noheader'=>TRUE,
362
					'capability' => 'export'
363
				),
364
				'contact_list_report' => array(
365
					'func'=> '_contact_list_report',
366
					'noheader' => TRUE,
367
					'capability' => 'ee_read_contacts',
368
				)
369
		);
370
371
	}
372
373
374
375
376
377
	protected function _set_page_config() {
378
		$this->_page_config = array(
379
380
			'default' => array(
381
				'nav' => array(
382
					'label' => __('Overview', 'event_espresso'),
383
					'order' => 5
384
					),
385
			'help_tabs' => array(
386
					'registrations_overview_help_tab' => array(
387
						'title' => __('Registrations Overview', 'event_espresso'),
388
						'filename' => 'registrations_overview'
389
					),
390
					'registrations_overview_table_column_headings_help_tab' => array(
391
						'title' => __('Registrations Table Column Headings', 'event_espresso'),
392
						'filename' => 'registrations_overview_table_column_headings'
393
					),
394
					'registrations_overview_filters_help_tab' => array(
395
						'title' => __('Registration Filters', 'event_espresso'),
396
						'filename' => 'registrations_overview_filters'
397
					),
398
					'registrations_overview_views_help_tab' => array(
399
						'title' => __('Registration Views', 'event_espresso'),
400
						'filename' => 'registrations_overview_views'
401
					),
402
					'registrations_overview_other_help_tab' => array(
403
						'title' => __('Registrations Other', 'event_espresso'),
404
						'filename' => 'registrations_overview_other'
405
					)
406
                ),
407
				'help_tour' => array( 'Registration_Overview_Help_Tour' ),
408
				'qtips' => array('Registration_List_Table_Tips'),
409
				'list_table' => 'EE_Registrations_List_Table',
410
				'require_nonce' => FALSE
411
				),
412
413
			'view_registration' => array(
414
				'nav' => array(
415
					'label' => __('REG Details', 'event_espresso'),
416
					'order' => 15,
417
					'url' => isset($this->_req_data['_REG_ID']) ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID'] ), $this->_current_page_view_url )  : $this->_admin_base_url,
418
					'persistent' => FALSE
419
					),
420
                'help_tabs' => array(
421
					'registrations_details_help_tab' => array(
422
						'title' => __('Registration Details', 'event_espresso'),
423
						'filename' => 'registrations_details'
424
						),
425
					'registrations_details_table_help_tab' => array(
426
						'title' => __('Registration Details Table', 'event_espresso'),
427
						'filename' => 'registrations_details_table'
428
						),
429
					'registrations_details_form_answers_help_tab' => array(
430
						'title' => __('Registration Form Answers', 'event_espresso'),
431
						'filename' => 'registrations_details_form_answers'
432
						),
433
					'registrations_details_registrant_details_help_tab' => array(
434
						'title' => __('Contact Details', 'event_espresso'),
435
						'filename' => 'registrations_details_registrant_details'
436
						)
437
					),
438
				'help_tour' => array( 'Registration_Details_Help_Tour' ),
439
				'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array( '_registration_details_metaboxes' ) ),
440
				'require_nonce' => FALSE
441
				),
442
443
			'new_registration' => array(
444
				'nav' => array(
445
					'label' => __('Add New Registration', 'event_espresso'),
446
					'url' => '#',
447
					'order' => 15,
448
					'persistent' => FALSE
449
					),
450
				'metaboxes' => $this->_default_espresso_metaboxes,
451
				'labels' => array(
452
					'publishbox' => __('Save Registration', 'event_espresso')
453
					),
454
				'require_nonce' => FALSE
455
				),
456
457
			'add_new_attendee' => array(
458
				'nav' => array(
459
					'label' => __('Add Contact', 'event_espresso'),
460
					'order' => 15,
461
					'persistent' => FALSE
462
					),
463
				'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_publish_post_box', 'attendee_editor_metaboxes' ) ),
464
				'require_nonce' => FALSE
465
				),
466
467
			'edit_attendee' => array(
468
				'nav' => array(
469
					'label' => __('Edit Contact', 'event_espresso'),
470
					'order' => 15,
471
					'persistent' => FALSE,
472
					'url' => isset($this->_req_data['ATT_ID']) ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID'] ), $this->_current_page_view_url )  : $this->_admin_base_url
473
					),
474
				'metaboxes' => array('attendee_editor_metaboxes'),
475
				'require_nonce' => FALSE
476
				),
477
478
			'contact_list' => array(
479
				'nav' => array(
480
					'label' => __('Contact List', 'event_espresso'),
481
					'order' => 20
482
					),
483
				'list_table' => 'EE_Attendee_Contact_List_Table',
484
                'help_tabs' => array(
485
					'registrations_contact_list_help_tab' => array(
486
						'title' => __('Registrations Contact List', 'event_espresso'),
487
						'filename' => 'registrations_contact_list'
488
					),
489
					'registrations_contact-list_table_column_headings_help_tab' => array(
490
						'title' => __('Contact List Table Column Headings', 'event_espresso'),
491
						'filename' => 'registrations_contact_list_table_column_headings'
492
					),
493
					'registrations_contact_list_views_help_tab' => array(
494
						'title' => __('Contact List Views', 'event_espresso'),
495
						'filename' => 'registrations_contact_list_views'
496
					),
497
					'registrations_contact_list_other_help_tab' => array(
498
						'title' => __('Contact List Other', 'event_espresso'),
499
						'filename' => 'registrations_contact_list_other'
500
					)
501
                ),
502
				'help_tour' => array( 'Contact_List_Help_Tour' ),
503
				'metaboxes' => array(),
504
				'require_nonce' => FALSE
505
				),
506
507
			//override default cpt routes
508
			'create_new' => '',
509
			'edit' => ''
510
511
			);
512
	}
513
514
515
	/**
516
	 * The below methods aren't used by this class currently
517
	 */
518
	protected function _add_screen_options() {}
519
	protected function _add_feature_pointers() {}
520
	public function admin_init() {
521
		EE_Registry::$i18n_js_strings[ 'update_att_qstns' ] = __( 'click "Update Registration Questions" to save your changes', 'event_espresso' );
522
	}
523
	public function admin_notices() {}
524
	public function admin_footer_scripts() {}
525
526
527
528
529
530
531
532
533
	/**
534
	 * 		get list of registration statuses
535
	*		@access private
536
	*		@return void
537
	*/
538
	private function _get_registration_status_array() {
539
		self::$_reg_status = EEM_Registration::reg_status_array( array(), TRUE);
540
	}
541
542
543
544
545
	protected function _add_screen_options_default() {
546
		$this->_per_page_screen_option();
547
	}
548
549 View Code Duplication
	protected function _add_screen_options_contact_list() {
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...
550
		$page_title = $this->_admin_page_title;
551
		$this->_admin_page_title = __("Contacts", 'event_espresso');
552
		$this->_per_page_screen_option();
553
		$this->_admin_page_title = $page_title;
554
	}
555
556
557
558
559 View Code Duplication
	public function load_scripts_styles() {
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...
560
		//style
561
		//wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION );
562
		wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'), EVENT_ESPRESSO_VERSION );
563
		wp_enqueue_style('espresso_reg');
564
565
		//script
566
		wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js', array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, TRUE);
567
		wp_enqueue_script('espresso_reg');
568
	}
569
570
571
572
	public function load_scripts_styles_edit_attendee() {
573
		//stuff to only show up on our attendee edit details page.
574
		$attendee_details_translations = array(
575
			'att_publish_text' => sprintf( __('Created on: <b>%1$s</b>', 'event_espresso'), $this->_cpt_model_obj->get_datetime('ATT_created') )
576
			);
577
		wp_localize_script( 'espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations );
578
		wp_enqueue_script('jquery-validate');
579
	}
580
581
582
	public function load_scripts_styles_view_registration() {
583
		//styles
584
		wp_enqueue_style('espresso-ui-theme');
585
		//scripts
586
	}
587
588
589
590
591
592
593
	public function load_scripts_styles_contact_list() {
594
		wp_deregister_style('espresso_reg');
595
		wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'), EVENT_ESPRESSO_VERSION );
596
		wp_enqueue_style('espresso_att');
597
	}
598
599
600
601
602
603
	public function load_scripts_styles_new_registration() {
604
		wp_register_script( 'ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'), EVENT_ESPRESSO_VERSION, TRUE );
605
		wp_enqueue_script('ee-spco-for-admin');
606
		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' );
607
		EE_Form_Section_Proper::wp_enqueue_scripts();
608
		EED_Ticket_Selector::load_tckt_slctr_assets();
609
		EE_Datepicker_Input::enqueue_styles_and_scripts();
610
	}
611
612
613
614
615
616
	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() {
617
		add_filter('FHEE_load_EE_messages', '__return_true');
618
	}
619
620
621
622
	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() {
623
		add_filter('FHEE_load_EE_messages', '__return_true');
624
	}
625
626
627
628
	protected function _set_list_table_views_default() {
629
630
		//for notification related bulk actions we need to make sure only active messengers have an option.
631
		EED_Messages::set_autoloaders();
632
		$EEMSG = EE_Registry::instance()->load_lib('messages');
633
		$active_mts = $EEMSG->get_active_message_types();
0 ignored issues
show
Bug introduced by
The method get_active_message_types cannot be called on $EEMSG (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
634
		//key= bulk_action_slug, value= message type.
635
		$match_array = array(
636
			'approve_registration' => 'registration',
637
			'decline_registration' => 'declined_registration',
638
			'pending_registration' => 'pending_approval',
639
			'no_approve_registration' => 'not_approved_registration',
640
			'cancel_registration' => 'cancelled_registration'
641
			);
642
643
		/** setup reg status bulk actions **/
644
		$def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$def_reg_status_actions was never initialized. Although not strictly required by PHP, it is generally a good practice to add $def_reg_status_actions = 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...
645 View Code Duplication
		if ( in_array( $match_array['approve_registration'], $active_mts ) && EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'batch_send_messages' ) ) {
646
			$def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations', 'event_espresso');
647
		}
648
		$def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
649 View Code Duplication
		if ( in_array( $match_array['decline_registration'], $active_mts ) && EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'batch_send_messages' ) ) {
650
			$def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations', 'event_espresso');
651
		}
652
		$def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
653 View Code Duplication
		if ( in_array( $match_array['pending_registration'], $active_mts ) && EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'batch_send_messages' ) ) {
654
			$def_reg_status_actions['pending_and_notify_registration'] = __('Set Registrations to Pending Payment and Notify', 'event_espresso');
655
		}
656
		$def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
657 View Code Duplication
		if ( in_array( $match_array['no_approve_registration'], $active_mts ) && EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'batch_send_messages' ) ) {
658
			$def_reg_status_actions['no_approve_and_notify_registration'] = __('Set Registrations to Not Approved and Notify', 'event_espresso');
659
		}
660
		$def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
661 View Code Duplication
		if ( in_array( $match_array['cancel_registration'], $active_mts ) && EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'batch_send_messages' ) ) {
662
			$def_reg_status_actions['cancel_and_notify_registration'] = __('Cancel Registrations and Notify', 'event_espresso');
663
		}
664
665
		$this->_views = array(
666
			'all' => array(
667
				'slug' => 'all',
668
				'label' => __('View All Registrations', 'event_espresso'),
669
				'count' => 0,
670
				'bulk_action' => array_merge( $def_reg_status_actions, array(
671
					'trash_registrations' => __('Trash Registrations', 'event_espresso')
672
					) )
673
				),
674
			'month' => array(
675
				'slug' => 'month',
676
				'label' => __('This Month', 'event_espresso'),
677
				'count' => 0,
678
				'bulk_action' => array_merge( $def_reg_status_actions, array(
679
					'trash_registrations' => __('Trash Registrations', 'event_espresso')
680
					))
681
				),
682
			'today' => array(
683
				'slug' => 'today',
684
				'label' => sprintf( __('Today - %s', 'event_espresso'), date('M d, Y', current_time('timestamp' ) ) ),
685
				'count' => 0,
686
				'bulk_action' => array_merge( $def_reg_status_actions,  array(
687
					'trash_registrations' => __('Trash Registrations', 'event_espresso')
688
					))
689
				)
690
			);
691
692
		if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_registrations', 'espresso_registrations_delete_registration' ) ) {
693
			$this->_views['incomplete'] = array(
694
				'slug' => 'incomplete',
695
				'label' => __('Incomplete', 'event_espresso'),
696
				'count' => 0,
697
				'bulk_action' => array(
698
					'trash_registrations' => __('Trash Registrations', 'event_espresso')
699
				)
700
			);
701
			$this->_views['trash'] = array(
702
				'slug' => 'trash',
703
				'label' => __('Trash', 'event_espresso'),
704
				'count' => 0,
705
				'bulk_action' => array(
706
					'restore_registrations' => __('Restore Registrations', 'event_espresso'),
707
					'delete_registrations' => __('Delete Registrations Permanently', 'event_espresso')
708
				)
709
			);
710
		}
711
	}
712
713
714
715
716
	protected function _set_list_table_views_contact_list() {
717
		$this->_views = array(
718
			'in_use' => array(
719
				'slug' => 'in_use',
720
				'label' => __('In Use', 'event_espresso'),
721
				'count' => 0,
722
				'bulk_action' => array(
723
					'trash_attendees' => __('Move to Trash', 'event_espresso'),
724
					)
725
				)
726
			);
727
728
		if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_contacts', 'espresso_registrations_trash_attendees' ) ) {
729
			$this->_views['trash'] = array(
730
				'slug' => 'trash',
731
				'label' => __('Trash', 'event_espresso'),
732
				'count' => 0,
733
				'bulk_action' => array(
734
					'restore_attendees' => __('Restore from Trash', 'event_espresso'),
735
				)
736
			);
737
		}
738
	}
739
740
741
742
743
744
	protected function _registration_legend_items() {
745
		$fc_items = array(
746
			'star-icon' => array(
747
				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
748
				'desc' => __('This is the Primary Registrant', 'event_espresso')
749
				),
750
			'view_details' => array(
751
				'class' => 'dashicons dashicons-clipboard',
752
				'desc' => __('View Registration Details', 'event_espresso')
753
				),
754
			'edit_attendee' => array(
755
				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
756
				'desc' => __('Edit Contact Details', 'event_espresso')
757
				),
758
			'view_transaction' => array(
759
				'class' => 'dashicons dashicons-cart',
760
				'desc' => __('View Transaction Details', 'event_espresso')
761
				),
762
			'view_invoice' => array(
763
				'class' => 'dashicons dashicons-media-spreadsheet',
764
				'desc' => __('View Transaction Invoice', 'event_espresso')
765
				),
766
 			);
767
		if ( EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'espresso_registrations_resend_registration' ) ) {
768
			$fc_items['resend_registration'] = array(
769
				'class' => 'dashicons dashicons-email-alt',
770
				'desc' => __('Resend Registration Details', 'event_espresso')
771
				);
772
		} else {
773
			$fc_items['blank'] = array( 'class' => 'blank', 'desc' => '' );
774
		}
775
776
		$sc_items = array(
777
			'approved_status' => array(
778
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
779
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_approved, FALSE, 'sentence' )
780
				),
781
			'pending_status' => array(
782
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
783
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_pending_payment, FALSE, 'sentence' )
784
				),
785
			'incomplete_status' => array(
786
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
787
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_incomplete, FALSE, 'sentence' )
788
			),
789
			'not_approved' => array(
790
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
791
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_not_approved, FALSE, 'sentence' )
792
				),
793
			'declined_status' => array(
794
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
795
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_declined, FALSE, 'sentence' )
796
				),
797
			'cancelled_status' => array(
798
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
799
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_cancelled, FALSE, 'sentence' )
800
				)
801
			);
802
		return array_merge( $fc_items, $sc_items );
803
	}
804
805
806
807
	/***************************************		REGISTRATION OVERVIEW 		***************************************/
808
809
810
811
812
813
814
	protected function _registrations_overview_list_table() {
815
		$EVT_ID = ( ! empty( $this->_req_data['event_id'] )) ? absint( $this->_req_data['event_id'] ) : FALSE;
816
		if ( $EVT_ID ) {
817
			if ( EE_Registry::instance()->CAP->current_user_can( 'ee_edit_registrations', 'espresso_registrations_new_registration', $EVT_ID ) ) {
818
				$this->_admin_page_title .= $this->get_action_link_or_button( 'new_registration', 'add-registrant', array( 'event_id' => $EVT_ID ), 'add-new-h2' );
819
			}
820
			$event = EEM_Event::instance()->get_one_by_ID( $EVT_ID );
821
			$this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf( __('%s Viewing registrations for the event: %s%s', 'event_espresso'), '<h2>', '<a href="' . EE_Admin_Page::add_query_args_and_nonce( array('action' => 'edit', 'post' => $event->ID() ), EVENTS_ADMIN_URL ) . '">' . $event->get('EVT_name') . '</a>', '</h2>' ) : '';
822
		}
823
		$this->_template_args['after_list_table'] = $this->_display_legend( $this->_registration_legend_items() );
824
		$this->display_admin_list_table_page_with_no_sidebar();
825
	}
826
827
828
829
830
	/**
831
	 * This sets the _registration property for the registration details screen
832
	 *
833
	 * @access private
834
	 * @return bool
835
	 */
836
	private function _set_registration_object() {
837
		//get out if we've already set the object
838
		if ( is_object( $this->_registration )) {
839
			return TRUE;
840
		}
841
842
	    $REG = EEM_Registration::instance();
843
844
		$REG_ID = ( ! empty( $this->_req_data['_REG_ID'] )) ? absint( $this->_req_data['_REG_ID'] ) : FALSE;
845
846
		if ( $this->_registration = $REG->get_one_by_ID( $REG_ID ))
0 ignored issues
show
Documentation Bug introduced by
It seems like $REG->get_one_by_ID($REG_ID) can also be of type object<EE_Base_Class>. However, the property $_registration is declared as type object<EE_Registration>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
847
			return TRUE;
848
		else {
849
			$error_msg = sprintf( __('An error occurred and the details for Registration ID #%s could not be retrieved.', 'event_espresso'), $REG_ID );
850
			EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ );
851
			$this->_registration = NULL;
852
			return FALSE;
853
		}
854
	}
855
856
857
858
	/**
859
	 * get registrations for given parameters (used by list table)
860
	 *
861
	 * @param  int     $per_page how many registrations displayed per page
862
	 * @param  boolean $count return the count or objects
863
	 * @param  boolean $this_month whether to return for just this month
864
	 * @param  boolean $today whether to return results for just today
865
	 * @throws \EE_Error
866
	 * @internal param bool $all whether to ignore all query params and just return ALL registrations (or count if count is set)
867
	 * @return mixed (int|array)  int = count || array of registration objects
868
	 */
869
	public function get_registrations( $per_page = 10, $count = FALSE, $this_month = FALSE, $today = FALSE ) {
870
871
		$EVT_ID = ! empty( $this->_req_data['event_id'] ) && $this->_req_data['event_id'] > 0 ? absint( $this->_req_data['event_id'] ) : FALSE;
872
		$CAT_ID = ! empty( $this->_req_data['EVT_CAT'] ) && (int) $this->_req_data['EVT_CAT'] > 0? absint( $this->_req_data['EVT_CAT'] ) : FALSE;
873
		$reg_status = ! empty( $this->_req_data['_reg_status'] ) ? sanitize_text_field( $this->_req_data['_reg_status'] ) : FALSE;
874
		$month_range = ! empty( $this->_req_data['month_range'] ) ? sanitize_text_field( $this->_req_data['month_range'] ) : FALSE;//should be like 2013-april
875
		$today_a = ! empty( $this->_req_data['status'] ) && $this->_req_data['status'] == 'today' ? TRUE : FALSE;
876
		$this_month_a = ! empty( $this->_req_data['status'] ) && $this->_req_data['status'] == 'month' ? TRUE  : FALSE;
877
		$start_date = FALSE;
878
		$end_date = FALSE;
879
		$_where = array();
880
		$trash = ! empty( $this->_req_data['status'] ) && $this->_req_data['status'] == 'trash' ? TRUE : FALSE;
881
		$incomplete = ! empty( $this->_req_data['status'] ) && $this->_req_data['status'] == 'incomplete' ? TRUE : FALSE;
882
883
		//set orderby
884
		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
885
886
887
		switch ( $this->_req_data['orderby'] ) {
888
			case '_REG_ID':
889
				$orderby = 'REG_ID';
890
				break;
891
			case '_Reg_status':
892
				$orderby = 'STS_ID';
893
				break;
894
			case 'ATT_fname':
895
				$orderby = 'Attendee.ATT_lname';
896
				break;
897
			case 'event_name':
898
				$orderby = 'Event.EVT_name';
899
				break;
900
			case 'DTT_EVT_start':
901
				$orderby = 'Event.Datetime.DTT_EVT_start';
902
				break;
903
			default: //'REG_date'
904
				$orderby = 'REG_date';
905
		}
906
907
		$sort = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'DESC';
908
		$current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1;
909
		$per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page;
910
911
912
		$offset = ($current_page-1)*$per_page;
913
		$limit = $count  ? NULL : array( $offset, $per_page );
914
915
		if($EVT_ID){
916
			$_where['EVT_ID']=$EVT_ID;
917
		}
918
		if($CAT_ID){
919
			$_where['Event.Term_Taxonomy.term_id'] = $CAT_ID;
920
		}
921
		if ( $incomplete ) {
922
			$_where['STS_ID'] = EEM_Registration::status_id_incomplete;
923
		} else if ( ! $trash) {
924
			$_where['STS_ID'] = array( '!=', EEM_Registration::status_id_incomplete );
925
		}
926
		if($reg_status){
927
			$_where['STS_ID'] = $reg_status;
928
		}
929
930
931
932
		$this_year_r = date('Y', current_time('timestamp'));
933
934
935
		$time_start = ' 00:00:00';
936
		$time_end = ' 23:59:59';
937
938
		if($today_a || $today ){
939
			$curdate = date('Y-m-d', current_time('timestamp'));
940
			$_where['REG_date']= array('BETWEEN',
941
				array(
942
					EEM_Registration::instance()->convert_datetime_for_query( 'REG_date', $curdate . $time_start, 'Y-m-d H:i:s' ),
943
					EEM_Registration::instance()->convert_datetime_for_query( 'REG_date', $curdate . $time_end, 'Y-m-d H:i:s' ),
944
			));
945
		}elseif($this_month_a || $this_month){
946
			$this_month_r = date('m', current_time('timestamp'));
947
			$days_this_month = date( 't', current_time('timestamp') );
948
			$_where['REG_date']= array('BETWEEN',
949
				array(
950
					EEM_Registration::instance()->convert_datetime_for_query( 'REG_date', $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, 'Y-m-d H:i:s' ),
951
					EEM_Registration::instance()->convert_datetime_for_query( 'REG_date', $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, 'Y-m-d H:i:s' )
952
			));
953
		}elseif($month_range){
954
			$pieces = explode(' ', $this->_req_data['month_range'], 3);
955
			$month_r = !empty($pieces[0]) ? date('m', strtotime($pieces[0])) : '';
956
			$year_r = !empty($pieces[1]) ? $pieces[1] : '';
957
			$days_in_month = date('t', strtotime($year_r .  '-' . $month_r . '-' . '01') );
958
			$_where['REG_date']= array('BETWEEN',
959
				array(  EEM_Registration::instance()->convert_datetime_for_query( 'REG_date', $year_r . '-' . $month_r . '-01 00:00:00', 'Y-m-d H:i:s'), EEM_Registration::instance()->convert_datetime_for_query( 'REG_date', $year_r . '-' . $month_r . '-' . $days_in_month .  ' 23:59:59', 'Y-m-d H:i:s' ) ) );
960
		}elseif($start_date && $end_date){
961
			throw new EE_Error("not yet supported");
962
		}elseif($start_date){
963
			throw new EE_Error("not yet supported");
964
		}elseif($end_date){
965
			throw new EE_Error("not yet supported");
966
		}
967
968
		if ( ! empty( $this->_req_data['s'] ) ) {
969
			$sstr = '%' . $this->_req_data['s'] . '%';
970
			$_where['OR'] = array(
971
				'Event.EVT_name' => array( 'LIKE', $sstr),
972
				'Event.EVT_desc' => array( 'LIKE', $sstr ),
973
				'Event.EVT_short_desc' => array( 'LIKE' , $sstr ),
974
				'Attendee.ATT_full_name' => array( 'LIKE', $sstr ),
975
				'Attendee.ATT_fname' => array( 'LIKE', $sstr ),
976
				'Attendee.ATT_lname' => array( 'LIKE', $sstr ),
977
				'Attendee.ATT_short_bio' => array( 'LIKE', $sstr ),
978
				'Attendee.ATT_email' => array('LIKE', $sstr ),
979
				'Attendee.ATT_address' => array( 'LIKE', $sstr ),
980
				'Attendee.ATT_address2' => array( 'LIKE', $sstr ),
981
				'Attendee.ATT_city' => array( 'LIKE', $sstr ),
982
				'REG_final_price' => array( 'LIKE', $sstr ),
983
				'REG_code' => array( 'LIKE', $sstr ),
984
				'REG_count' => array( 'LIKE' , $sstr ),
985
				'REG_group_size' => array( 'LIKE' , $sstr ),
986
				'Ticket.TKT_name' => array( 'LIKE', $sstr ),
987
				'Ticket.TKT_description' => array( 'LIKE', $sstr ),
988
				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array( 'LIKE', $sstr )
989
				);
990
		}
991
992
		//capability checks
993
		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'get_registrations' ) ) {
994
			$_where['AND'] = array(
995
				'Event.EVT_wp_user' => get_current_user_id()
996
				);
997
		}
998
999
1000
		if( $count ){
1001
			if ( $trash ) {
1002
				return EEM_Registration::instance()->count_deleted( array( $_where ));
1003
			} else if ( $incomplete ) {
1004
				return EEM_Registration::instance()->count( array( $_where ));
1005
			} else {
1006
				return EEM_Registration::instance()->count( array( $_where, 'default_where_conditions' => 'this_model_only' ));
1007
			}
1008
		} else {
1009
			//make sure we remove default where conditions cause all registrations matching query are returned
1010
			$query_params = array( $_where, 'order_by' => array( $orderby => $sort ), 'default_where_conditions' => 'this_model_only' );
1011
			if ( $per_page !== -1 ) {
1012
				$query_params['limit'] = $limit;
1013
			}
1014
			$registrations =  $trash ? EEM_Registration::instance()->get_all_deleted($query_params) : EEM_Registration::instance()->get_all($query_params);
1015
1016
1017
			if ( $EVT_ID && isset( $registrations[0] ) && $registrations[0] instanceof EE_Registration &&  $registrations[0]->event_obj()) {
1018
				$first_registration = $registrations[0];
1019
				//EEH_Debug_Tools::printr( $registrations[0], '$registrations  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
1020
				$event_name = $first_registration->event_obj()->name();
1021
				$event_date = $first_registration->date_obj()->start_date_and_time('l F j, Y,', 'g:i:s a');// isset( $registrations[0]->DTT_EVT_start ) ? date( 'l F j, Y,    g:i:s a', $registrations[0]->DTT_EVT_start ) : '';
0 ignored issues
show
Documentation Bug introduced by
The method date_obj does not exist on object<EE_Registration>? 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...
1022
				// edit event link
1023 View Code Duplication
				if ( $event_name != '' ) {
1024
					$edit_event_url = self::add_query_args_and_nonce( array( 'action'=>'edit_event', 'EVT_ID'=>$EVT_ID ), EVENTS_ADMIN_URL );
1025
					$edit_event_lnk = '<a href="'.$edit_event_url.'" title="' . esc_attr__( 'Edit ', 'event_espresso' ) . $event_name . '">' . __( 'Edit Event', 'event_espresso' ) . '</a>';
1026
					$event_name .= ' <span class="admin-page-header-edit-lnk not-bold">' . $edit_event_lnk . '</span>' ;
1027
				}
1028
1029
				$back_2_reg_url = self::add_query_args_and_nonce( array( 'action'=>'default' ), REG_ADMIN_URL );
1030
				$back_2_reg_lnk = '<a href="'.$back_2_reg_url.'" title="' . esc_attr__( 'click to return to viewing all registrations ', 'event_espresso' ) . '">&laquo; ' . __( 'Back to All Registrations', 'event_espresso' ) . '</a>';
1031
1032
				$this->_template_args['before_admin_page_content'] = '
1033
			<div id="admin-page-header">
1034
				<h1><span class="small-text not-bold">'.__( 'Event: ', 'event_espresso' ).'</span>'. $event_name .'</h1>
1035
				<h3><span class="small-text not-bold">'.__( 'Date: ', 'event_espresso' ). '</span>'. $event_date .'</h3>
1036
				<span class="admin-page-header-go-back-lnk not-bold">' . $back_2_reg_lnk . '</span>
1037
			</div>
1038
			';
1039
1040
			}
1041
			return $registrations;
1042
		}
1043
	}
1044
1045
1046
1047
1048
1049
1050
	public function get_registration_status_array() {
1051
		return self::$_reg_status;
1052
	}
1053
1054
1055
1056
1057
	/***************************************		REGISTRATION DETAILS 		***************************************/
1058
1059
1060
1061
1062
1063
	/**
1064
	 * 		generates HTML for the View Registration Details Admin page
1065
	*		@access protected
1066
	*		@return void
1067
	*/
1068
	protected function _registration_details() {
1069
1070
		$this->_template_args = array();
1071
1072
		$this->_set_registration_object();
1073
1074
		if ( is_object( $this->_registration )) {
1075
			$transaction = $this->_registration->transaction() ? $this->_registration->transaction() : EE_Transaction::new_instance();
1076
			$this->_session = $transaction->session_data();
1077
1078
			$event_id = $this->_registration->event_ID();
1079
1080
1081
			$this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1082
			$this->_template_args['reg_nmbr']['label'] = __( 'Registration Number', 'event_espresso' );
1083
1084
			$this->_template_args['reg_datetime']['value'] =  $this->_registration->pretty_date('l F j, Y','g:i:s a') ;
1085
			$this->_template_args['reg_datetime']['label'] = __( 'Date', 'event_espresso' );
1086
1087
			$this->_template_args['grand_total'] = $transaction->total();
1088
1089
			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1090
			// link back to overview
1091
			$this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1092
			$this->_template_args['registration'] = $this->_registration;
1093
			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'default', 'event_id' => $event_id ), REG_ADMIN_URL );
1094
			$this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'default', 'EVT_ID' => $event_id, 'page' => 'espresso_transactions' ), admin_url( 'admin.php' ) );
1095
			$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( array( 'page' => 'espresso_events', 'action' => 'edit', 'post' => $event_id ), admin_url( 'admin.php' ) );
1096
1097
			//next and previous links
1098
			$next_reg = $this->_registration->next(null, array(), 'REG_ID' );
1099
			$this->_template_args['next_registration'] = $next_reg ? $this->_next_link( EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'view_registration', '_REG_ID' => $next_reg['REG_ID'] ), REG_ADMIN_URL ), 'dashicons dashicons-arrow-right ee-icon-size-22' ) : '';
1100
			$previous_reg = $this->_registration->previous( null, array(), 'REG_ID' );
1101
			$this->_template_args['previous_registration'] = $previous_reg ? $this->_previous_link( EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'view_registration', '_REG_ID' => $previous_reg['REG_ID'] ), REG_ADMIN_URL ), 'dashicons dashicons-arrow-left ee-icon-size-22' ) : '';
1102
1103
			// grab header
1104
			$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1105
			$this->_template_args['admin_page_header'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
1106
1107
		} else {
1108
1109
			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
0 ignored issues
show
Bug introduced by
The method display_espresso_notices() does not exist on Registrations_Admin_Page. Did you maybe mean _display_espresso_notices()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1110
1111
		}
1112
1113
		// the details template wrapper
1114
		$this->display_admin_page_with_sidebar();
1115
1116
	}
1117
1118
1119
1120
1121
1122
1123
	protected function _registration_details_metaboxes() {
1124
		$this->_set_registration_object();
1125
		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1126
		add_meta_box( 'edit-reg-status-mbox', __( 'Registration Status', 'event_espresso' ), array( $this, 'set_reg_status_buttons_metabox' ), $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...
1127
		add_meta_box( 'edit-reg-details-mbox', __( 'Registration Details', 'event_espresso' ), array( $this, '_reg_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...
1128
		if ( $attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'edit-reg-questions-mbox' ) ) {
1129
			add_meta_box( 'edit-reg-questions-mbox', __( 'Registration Form Answers', 'event_espresso' ), array( $this, '_reg_questions_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...
1130
		}
1131
		add_meta_box( 'edit-reg-registrant-mbox', __( 'Contact Details', 'event_espresso' ), array( $this, '_reg_registrant_side_meta_box' ), $this->wp_page_slug, 'side', '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...
1132
		if ( $this->_registration->group_size() > 1 ) {
1133
			add_meta_box( 'edit-reg-attendees-mbox', __( 'Other Registrations in this Transaction', 'event_espresso' ), array( $this, '_reg_attendees_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...
1134
		}
1135
	}
1136
1137
1138
1139
1140
1141
1142
	/**
1143
	 * 		_set_approve_or_decline_reg_status_buttons
1144
	*		@access protected
1145
	*		@return string
1146
	*/
1147
	public function set_reg_status_buttons_metabox() {
1148
1149
		//is registration for free event OR for a completed transaction? This will determine whether the set to pending option is shown.
1150
		$is_complete = $this->_registration->transaction()->is_completed();
1151
1152
		//let's get an array of all possible buttons that we can just reference
1153
		$status_buttons = $this->_get_reg_status_buttons();
1154
		$template_args[ 'reg_status_value' ] = $this->_registration->pretty_status();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$template_args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $template_args = 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...
1155
		$template_args[ 'reg_status_class' ] = 'status-' . $this->_registration->status_ID();
1156
		$template_args['attendee'] = $this->_registration->attendee();
1157
		$template = REG_TEMPLATE_PATH . 'reg_status_change_buttons.template.php';
1158
		if ( $this->_set_registration_object() ) {
1159
			$current_status = $this->_registration->status_ID();
1160
			unset( $status_buttons[$current_status] );
1161
			if ( $current_status != EEM_Registration::status_id_pending_payment && $is_complete ) {
1162
				unset( $status_buttons[EEM_Registration::status_id_pending_payment] );
1163
			}
1164
			$template_args['status_buttons'] = implode( "\n", $status_buttons );
1165
		}
1166
		$template_args['form_url'] = REG_ADMIN_URL;
1167
		$template_args['REG_ID'] = $this->_registration->ID();
1168
		$template_args['nonce'] = wp_nonce_field( 'change_reg_status_nonce',  'change_reg_status_nonce', FALSE, FALSE );
1169
1170
		EEH_Template::display_template( $template, $template_args );
1171
1172
	}
1173
1174
1175
1176
1177
	/**
1178
	 * Returns an array of all the buttons for the various statuses and switch status actions
1179
	 * @return array
1180
	 */
1181
	private function _get_reg_status_buttons() {
1182
1183
		$buttons = array(
1184
			EEM_Registration::status_id_approved => '<input type="submit" name="_reg_status_id" class="button-secondary ee-status-strip reg-status-' . EEM_Registration::status_id_approved . '" value="' . EEH_Template::pretty_status( EEM_Registration::status_id_approved, FALSE, 'sentence' ) . '">',
1185
			EEM_Registration::status_id_pending_payment => '<input type="submit" name="_reg_status_id" class="button-secondary ee-status-strip reg-status-' . EEM_Registration::status_id_pending_payment . '" value="' . EEH_Template::pretty_status( EEM_Registration::status_id_pending_payment, FALSE, 'sentence' ) . '">',
1186
			EEM_Registration::status_id_not_approved => '<input type="submit" name="_reg_status_id" class="button-secondary ee-status-strip reg-status-' . EEM_Registration::status_id_not_approved . '" value="' . EEH_Template::pretty_status( EEM_Registration::status_id_not_approved, FALSE, 'sentence' ) . '">',
1187
			EEM_Registration::status_id_declined => '<input type="submit" name="_reg_status_id" class="button-secondary ee-status-strip reg-status-' . EEM_Registration::status_id_declined . '" value="' . EEH_Template::pretty_status( EEM_Registration::status_id_declined, FALSE, 'sentence' ) . '">',
1188
			EEM_Registration::status_id_cancelled =>'<input type="submit" name="_reg_status_id" class="button-secondary ee-status-strip reg-status-' . EEM_Registration::status_id_cancelled . '" value="' . EEH_Template::pretty_status( EEM_Registration::status_id_cancelled, FALSE, 'sentence' ) . '">',
1189
			);
1190
		return $buttons;
1191
	}
1192
1193
1194
	/**
1195
	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1196
	 *
1197
	 * @param bool $status REG status given for changing registrations to.
1198
	 * @param bool $notify Whether to send messages notifications or not.
1199
	 *
1200
	 * @return array  (array with reg_id(s) updated and whether update was successful.
1201
	 */
1202
	protected function _set_registration_status_from_request( $status = false, $notify = false ) {
1203
		$REG_ID = isset( $this->_req_data['_REG_ID'] ) ? (array) $this->_req_data['_REG_ID'] : array();
1204
1205
		$success = $this->_set_registration_status( $REG_ID, $status );
0 ignored issues
show
Documentation introduced by
$REG_ID is of type array, but the function expects a boolean.

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...
1206
1207
		//notify?
1208
		if ( $success && $notify && EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'espresso_registrations_resend_registration' ) ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $success of type array<string,array|boolean> is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1209
			$this->_process_resend_registration();
1210
		}
1211
1212
		return $success;
1213
	}
1214
1215
1216
1217
	/**
1218
	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an array).
1219
	 *
1220
	 * Note, this method does NOT take care of possible notifications.  That is required by calling code.
1221
	 *
1222
	 * @param bool $REG_ID
1223
	 * @param bool $status
1224
	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as the array of updated registrations).
1225
	 */
1226
	protected function _set_registration_status( $REG_ID, $status = false ) {
1227
		$success = true;
1228
		// set default status if none is passed
1229
		$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1230
1231
		//typecast and sanitize reg_id
1232
		$reg_ids = array_filter( (array) $REG_ID, 'absint' );
1233
1234
		//loop through REG_ID's and change status
1235
		foreach ( $reg_ids as $r_id ) {
1236
			$registration = EEM_Registration::instance()->get_one_by_ID( $r_id );
1237
			if ( $registration instanceof EE_Registration ) {
1238
				$registration->set_status( $status );
1239
				$result = $registration->save();
1240
1241
				//verifying explicit fails because update *may* just return 0 for 0 rows affected
1242
				$success = $success !== false && $result !== false;
1243
			}
1244
		}
1245
1246
		//reset _req_data['_REG_ID'] for any potential future messages notifications
1247
		$this->_req_data['_REG_ID'] = $reg_ids;
1248
1249
		//return $success and processed registrations
1250
		return array( 'REG_ID' => $reg_ids, 'success' => $success );
1251
	}
1252
1253
1254
1255
1256
	/**
1257
	 * Common logic for setting up success message and redirecting to appropriate route
1258
	 * @param  string $STS_ID  status id for the registration changed to
1259
	 * @param   bool    $notify indicates whether the _set_registration_status_from_request does notifications or not.
1260
	 * @return void
1261
	 */
1262
	protected function _reg_status_change_return( $STS_ID, $notify = false ) {
1263
1264
		$result = ! empty( $STS_ID ) ? $this->_set_registration_status_from_request( $STS_ID, $notify ) : array( 'success' => false );
0 ignored issues
show
Documentation introduced by
$STS_ID is of type string, but the function expects a boolean.

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...
1265
1266
1267
		$success = isset( $result['success'] ) && $result['success'];
1268
1269
		//setup success message
1270
		if ( $success ) {
1271
			$msg = is_array( $result['REG_ID'] ) && count( $result['REG_ID'] ) > 1  ? sprintf( __('Registration status has been set to %s', 'event_espresso'), EEH_Template::pretty_status($STS_ID, false, 'lower' ) ) :  sprintf( __('Registrations have been set to %s.', 'event_espresso'), EEH_Template::pretty_status($STS_ID, false, 'lower' ) ) ;
1272
			EE_Error::add_success( $msg );
1273
		} else {
1274
			EE_Error::add_error( __('Something went wrong, and the status was not changed', 'event_espresso' ), __FILE__, __LINE__, __FUNCTION__ );
1275
		}
1276
1277
		$route = isset( $this->_req_data['return'] ) && $this->_req_data['return'] == 'view_registration' ? array( 'action' => 'view_registration', '_REG_ID' => $result['REG_ID'][0] ) : array( 'action' => 'default' );
1278
		//unset nonces
1279
		foreach ( $this->_req_data as $ref => $value ) {
1280
			if ( strpos( $ref, 'nonce' ) !== false ) {
1281
				unset( $this->_req_data[$ref] );
1282
				continue;
1283
			}
1284
1285
			$value = is_array( $value ) ? array_map( 'urlencode', $value ) : urlencode( $value );
1286
			$this->_req_data[$ref] = $value;
1287
		}
1288
1289
		//merge request vars so that the reloaded list table contains any existing filter query params
1290
		$route = array_merge( $this->_req_data, $route );
1291
1292
		$this->_redirect_after_action( $success, '', '', $route, true );
0 ignored issues
show
Documentation introduced by
$success is of type boolean, but the function expects a false|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...
1293
1294
		}
1295
1296
1297
1298
	/**
1299
	 * incoming reg status change from reg details page.
1300
	 * @return void
1301
	 */
1302
	protected function _change_reg_status() {
1303
		$this->_req_data['return'] = 'view_registration';
1304
		//set notify based on whether the send notifications toggle is set or not
1305
		$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1306
		$this->_req_data[ '_reg_status_id' ] = isset( $this->_req_data[ '_reg_status_id' ] ) ? $this->_req_data[ '_reg_status_id' ] : '';
1307
1308
		switch ( $this->_req_data['_reg_status_id'] ) {
1309
			case EEH_Template::pretty_status( EEM_Registration::status_id_approved, false, 'sentence' ) :
1310
				$this->approve_registration( $notify );
1311
				break;
1312
			case EEH_Template::pretty_status( EEM_Registration::status_id_pending_payment, false, 'sentence' ) :
1313
				$this->pending_registration( $notify );
1314
				break;
1315
			case EEH_Template::pretty_status( EEM_Registration::status_id_not_approved, false, 'sentence' ) :
1316
				$this->not_approve_registration( $notify );
1317
				break;
1318
			case EEH_Template::pretty_status( EEM_Registration::status_id_declined, false, 'sentence' ) :
1319
				$this->decline_registration( $notify );
1320
				break;
1321
			case EEH_Template::pretty_status( EEM_Registration::status_id_cancelled, false, 'sentence' ) :
1322
				$this->cancel_registration( $notify );
1323
				break;
1324
			default :
1325
				$result['success'] = false;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = 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...
1326
				unset( $this->_req_data['return'] );
1327
				$this->_reg_status_change_return( '', false );
1328
				break;
1329
		}
1330
	}
1331
1332
1333
1334
	/**
1335
	 * 		approve_registration
1336
	*		@access protected
1337
	*		@param bool $notify whether or not to notify the registrant about their approval.
1338
	*		@return void
1339
	*/
1340
	protected function approve_registration( $notify = false ) {
1341
		$this->_reg_status_change_return( EEM_Registration::status_id_approved, $notify );
1342
	}
1343
1344
1345
1346
1347
	/**
1348
	 * 		decline_registration
1349
	*		@access protected
1350
	*		@param bool $notify whether or not to notify the registrant about their approval.
1351
	*		@return void
1352
	*/
1353
	protected function decline_registration( $notify = false ) {
1354
		$this->_reg_status_change_return( EEM_Registration::status_id_declined, $notify );
1355
	}
1356
1357
1358
1359
1360
	/**
1361
	 * 		cancel_registration
1362
	*		@access protected
1363
	*		@param bool $notify whether or not to notify the registrant about their approval.
1364
	*		@return void
1365
	*/
1366
	protected function cancel_registration( $notify = false ) {
1367
		$this->_reg_status_change_return( EEM_Registration::status_id_cancelled, $notify );
1368
	}
1369
1370
1371
1372
1373
1374
	/**
1375
	 * 		not_approve_registration
1376
	*		@access protected
1377
	*		@param bool $notify whether or not to notify the registrant about their approval.
1378
	*		@return void
1379
	*/
1380
	protected function not_approve_registration( $notify = false ) {
1381
		$this->_reg_status_change_return( EEM_Registration::status_id_not_approved, $notify );
1382
	}
1383
1384
1385
1386
	/**
1387
	 * 		decline_registration
1388
	*		@access protected
1389
	*		@param bool $notify whether or not to notify the registrant about their approval.
1390
	*		@return void
1391
	*/
1392
	protected function pending_registration( $notify = false ) {
1393
		$this->_reg_status_change_return( EEM_Registration::status_id_pending_payment, $notify );
1394
	}
1395
1396
1397
1398
1399
	/**
1400
	 * 		generates HTML for the Registration main meta box
1401
	*		@access public
1402
	*		@return void
1403
	*/
1404
	public function _reg_details_meta_box() {
1405
		EEH_Autoloader::register_line_item_display_autoloaders();
1406
		EEH_Autoloader::register_line_item_filter_autoloaders();
1407
		EE_Registry::instance()->load_Helper( 'Line_Item' );
1408
		$transaction = $this->_registration->transaction() ? $this->_registration->transaction() : EE_Transaction::new_instance();
1409
		$this->_session = $transaction->session_data();
1410
1411
		$filters = new EE_Line_Item_Filter_Collection();
1412
		$filters->add( new EE_Single_Registration_Line_Item_Filter( $this->_registration ) );
1413
		$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1414
		$line_item_filter_processor = new EE_Line_Item_Filter_Processor( $filters, $transaction->total_line_item() );
1415
		$filtered_line_item_tree = $line_item_filter_processor->process();
1416
1417
		$this->_template_args['REG_ID'] = $this->_registration->ID();
1418
		$line_item_display = new EE_Line_Item_Display( 'reg_admin_table', 'EE_Admin_Table_Registration_Line_Item_Display_Strategy' );
1419
		$this->_template_args['line_item_table'] = $line_item_display->display_line_item( $filtered_line_item_tree, array( 'EE_Registration' => $this->_registration ) );
0 ignored issues
show
Compatibility introduced by
$filtered_line_item_tree of type object<EEI_Line_Item> is not a sub-type of object<EE_Line_Item>. It seems like you assume a concrete implementation of the interface EEI_Line_Item to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
1420
1421
1422
		$attendee = $this->_registration->attendee();
1423
1424
1425
		$this->_template_args['view_transaction_button'] = EE_Registry::instance()->CAP->current_user_can( 'ee_read_transaction', 'espresso_transactions_view_transaction' ) ?EEH_Template::get_button_or_link( EE_Admin_Page::add_query_args_and_nonce( array('action'=> 'view_transaction', 'TXN_ID' => $transaction->ID() ), TXN_ADMIN_URL ), __(' View Transaction'), 'button secondary-button right', 'dashicons dashicons-cart' ) : '';
1426
		$this->_template_args['resend_registration_button'] = $attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'espresso_registrations_resend_registration' ) ?EEH_Template::get_button_or_link( EE_Admin_Page::add_query_args_and_nonce( array( 'action'=>'resend_registration', '_REG_ID'=>$this->_registration->ID(), 'redirect_to' => 'view_registration' ), REG_ADMIN_URL ), __(' Resend Registration'), 'button secondary-button right', 'dashicons dashicons-email-alt' ) : '';
1427
1428
1429
		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1430
		$payment = $transaction->get_first_related( 'Payment' );
1431
		$payment = ! $payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment;
1432
		$payment_method = $payment->get_first_related( 'Payment_Method' );
1433
		$payment_method = ! $payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance() : $payment_method;
1434
		$reg_status_class = 'status-' . $this->_registration->status_ID();
0 ignored issues
show
Unused Code introduced by
$reg_status_class 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...
1435
		$reg_details = array(
1436
			'payment_method' => $payment_method->name(),
1437
			'response_msg' => $payment->gateway_response(),
0 ignored issues
show
Bug introduced by
The method gateway_response does only exist in EE_Payment, but not in EE_Attendee.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
1438
			'registration_id' => $this->_registration->get( 'REG_code' ),
1439
			'registration_session' => $this->_registration->session_ID(),
1440
			'ip_address' => isset( $this->_session['ip_address'] ) ? $this->_session['ip_address'] : '',
1441
			'user_agent' => isset( $this->_session['user_agent'] ) ? $this->_session['user_agent'] : '',
1442
			);
1443
1444
1445
		if ( isset( $reg_details['registration_id'] )) {
1446
			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1447
			$this->_template_args['reg_details']['registration_id']['label'] = __( 'Registration ID', 'event_espresso' );
1448
			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
1449
		}
1450
1451
		if ( isset( $reg_details['payment_method'] ) ) {
1452
			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
1453
			$this->_template_args['reg_details']['payment_method']['label'] = __( 'Most Recent Payment Method', 'event_espresso' );
1454
			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
1455
			$this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
1456
			$this->_template_args['reg_details']['response_msg']['label'] = __( 'Payment method response', 'event_espresso' );
1457
			$this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
1458
		}
1459
1460
		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
1461
		$this->_template_args['reg_details']['registration_session']['label'] = __( 'Registration Session', 'event_espresso' );
1462
		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
1463
1464
		$this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
1465
		$this->_template_args['reg_details']['ip_address']['label'] = __( 'Registration placed from IP', 'event_espresso' );
1466
		$this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
1467
1468
		$this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
1469
		$this->_template_args['reg_details']['user_agent']['label'] = __( 'Registrant User Agent', 'event_espresso' );
1470
		$this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
1471
1472
		$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'default', 'event_id' => $this->_registration->event_ID()), REG_ADMIN_URL );
1473
1474
		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
1475
		echo EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
1476
1477
	}
1478
1479
1480
1481
1482
1483
1484
	/**
1485
	 * 		generates HTML for the Registration Questions meta box
1486
	*		@access public
1487
	*		@return void
1488
	*/
1489
	public function _reg_questions_meta_box() {
1490
1491
		add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array( $this, 'form_before_question_group' ), 10, 1 );
1492
		add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array( $this, 'form_after_question_group' ), 10, 1 );
1493
		add_filter( 'FHEE__EEH_Form_Fields__label_html', array( $this, 'form_form_field_label_wrap' ), 10, 1 );
1494
		add_filter( 'FHEE__EEH_Form_Fields__input_html', array( $this, 'form_form_field_input__wrap' ), 10, 1 );
1495
1496
		$question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options( $this->_registration, $this->_registration->get('EVT_ID') );
0 ignored issues
show
Documentation introduced by
$this->_registration->get('EVT_ID') 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...
1497
1498
		//EEH_Debug_Tools::printr( $question_groups, '$question_groups  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
1499
1500
		EE_Registry::instance()->load_helper( 'Form_Fields' );
1501
		$this->_template_args['att_questions'] = EEH_Form_Fields::generate_question_groups_html( $question_groups );
1502
1503
		$this->_template_args['reg_questions_form_action'] = 'update_attendee_registration_form';
1504
		$this->_template_args['REG_ID'] = $this->_registration->ID();
1505
1506
		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
1507
		echo EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
1508
1509
	}
1510
1511
1512
1513
1514
1515
	/**
1516
	 * 		form_before_question_group
1517
	 *
1518
	 * 		@access 		public
1519
	 * 		@param 		string 		$output
1520
	 * 		@return 		string
1521
	 */
1522
	public function form_before_question_group( $output ) {
0 ignored issues
show
Unused Code introduced by
The parameter $output is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1523
		return '
1524
	<table class="form-table ee-width-100">
1525
		<tbody>
1526
			';
1527
	}
1528
1529
1530
1531
1532
	/**
1533
	 * 		form_after_question_group
1534
	 *
1535
	 * 		@access 		public
1536
	 * 		@param 		string 		$output
1537
	 * 		@return 		string
1538
	 */
1539
	public function form_after_question_group( $output ) {
0 ignored issues
show
Unused Code introduced by
The parameter $output is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1540
		return  '
1541
			<tr class="hide-if-no-js">
1542
				<th> </th>
1543
				<td class="reg-admin-edit-attendee-question-td">
1544
					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="' . esc_attr__( 'click to edit question', 'event_espresso' ) . '">
1545
						<span class="reg-admin-edit-question-group-spn lt-grey-txt">' . __( 'edit the above question group', 'event_espresso' ) . '</span>
1546
						<div class="dashicons dashicons-edit"></div>
1547
					</a>
1548
				</td>
1549
			</tr>
1550
		</tbody>
1551
	</table>
1552
';
1553
	}
1554
1555
1556
1557
1558
	/**
1559
	 * 		form_form_field_label_wrap
1560
	 *
1561
	 * 		@access 		public
1562
	 * 		@param 		string 		$label
1563
	 * 		@return 		string
1564
	 */
1565
	public function form_form_field_label_wrap( $label ) {
1566
		return '
1567
			<tr>
1568
				<th>
1569
					' . $label  . '
1570
				</th>';
1571
	}
1572
1573
1574
1575
1576
	/**
1577
	 * 		form_form_field_input__wrap
1578
	 *
1579
	 * 		@access 		public
1580
	 * 		@param 		string 		$label
0 ignored issues
show
Bug introduced by
There is no parameter named $label. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1581
	 * 		@return 		string
1582
	 */
1583
	public function form_form_field_input__wrap( $input ) {
1584
		return '
1585
				<td class="reg-admin-attendee-questions-input-td disabled-input">
1586
					' . $input . '
1587
				</td>
1588
			</tr>';
1589
	}
1590
1591
1592
1593
1594
	/**
1595
	 * 		generates HTML for the Registration main meta box
1596
	*		@access protected
1597
	*		@return void
1598
	*/
1599
	protected function _update_attendee_registration_form() {
1600
		$qstns = isset( $this->_req_data['qstn'] ) ? $this->_req_data['qstn'] : FALSE;
1601
		$REG_ID = isset( $this->_req_data['_REG_ID'] ) ? absint( $this->_req_data['_REG_ID'] ) : FALSE;
1602
		$qstns = apply_filters( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns );
1603
		$success = $this->_save_attendee_registration_form( $REG_ID, $qstns );
1604
		$what = __('Registration Form', 'event_espresso');
1605
		$route = $REG_ID ? array( 'action' => 'view_registration', '_REG_ID' => $REG_ID ) : array( 'action' => 'default' );
1606
		$this->_redirect_after_action( $success, $what, __('updated', 'event_espresso'), $route );
0 ignored issues
show
Bug introduced by
It seems like $success defined by $this->_save_attendee_re...n_form($REG_ID, $qstns) on line 1603 can also be of type boolean; however, EE_Admin_Page::_redirect_after_action() does only seem to accept false|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1607
1608
	}
1609
1610
1611
1612
	/**
1613
	 *        _save_attendee_registration_form
1614
	 * @access private
1615
	 * @param bool $REG_ID
1616
	 * @param bool $qstns
1617
	 * @return bool
1618
	 */
1619
	private function _save_attendee_registration_form( $REG_ID = FALSE, $qstns = FALSE ) {
1620
1621
		if ( ! $REG_ID || ! $qstns ) {
1622
			EE_Error::add_error( __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
1623
		}
1624
		$success = TRUE;
1625
1626
		// allow others to get in on this awesome fun   :D
1627
		do_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns );
1628
		// loop thru questions... FINALLY!!!
1629
1630
		foreach ( $qstns as $QST_ID => $qstn ) {
0 ignored issues
show
Bug introduced by
The expression $qstns of type boolean is not traversable.
Loading history...
1631
			//if $qstn isn't an array then it doesn't already have an answer, so let's create the answer
1632
			if ( !is_array($qstn) ) {
1633
				$success = $this->_save_new_answer( $REG_ID, $QST_ID, $qstn);
1634
				continue;
1635
			}
1636
1637
1638
			foreach ( $qstn as $ANS_ID => $ANS_value ) {
1639
				//get answer
1640
				$query_params = array(
1641
					0 => array(
1642
						'ANS_ID' => $ANS_ID,
1643
						'REG_ID' => $REG_ID,
1644
						'QST_ID' => $QST_ID
1645
						)
1646
					);
1647
				$answer = EEM_Answer::instance()->get_one($query_params);
1648
				//this MAY be an array but NOT have an answer because its multi select.  If so then we need to create the answer
1649
				if ( ! $answer instanceof EE_Answer ) {
1650
					$success = $this->_save_new_answer( $REG_ID, $QST_ID, $qstn);
1651
					continue 2;
1652
				}
1653
1654
				$answer->set('ANS_value', $ANS_value);
1655
				$success = $answer->save();
1656
			}
1657
		}
1658
1659
		return $success;
1660
	}
1661
1662
1663
	//TODO: try changing this to use the model directly... not indirectly through creating a default object...
1664
	private function _save_new_answer( $REG_ID, $QST_ID, $ans ) {
1665
		$set_values = array(
1666
			'QST_ID' => $QST_ID,
1667
			'REG_ID' => $REG_ID,
1668
			'ANS_value' => $ans
1669
			);
1670
		$success = EEM_Answer::instance()->insert($set_values);
1671
		return $success;
1672
	}
1673
1674
1675
1676
1677
1678
	/**
1679
	 * 		generates HTML for the Registration main meta box
1680
	*		@access public
1681
	*		@return void
1682
	*/
1683
	public function _reg_attendees_meta_box() {
1684
1685
	    $REG = EEM_Registration::instance();
1686
		//get all other registrations on this transaction, and cache
1687
		//the attendees for them so we don't have to run another query using force_join
1688
		$registrations = $REG->get_all(array(
1689
			array(
1690
				'TXN_ID'=>$this->_registration->transaction_ID(),
1691
				'REG_ID'=>array('!=',$this->_registration->ID())
1692
			),
1693
			'force_join'=>array('Attendee')));
1694
1695
		$this->_template_args['attendees'] = array();
1696
		$this->_template_args['attendee_notice'] = '';
1697
		EE_Registry::instance()->load_helper('Array');
1698
		if ( empty( $registrations)  || ( is_array($registrations) &&  ! EEH_Array::get_one_item_from_array($registrations) ) ) {
1699
			EE_Error::add_error( __('There are no records attached to this registration. Something may have gone wrong with the registration', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
1700
			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
1701
		} else {
1702
1703
			$att_nmbr = 1;
1704
			foreach ( $registrations as $registration ) {
1705
				/* @var $registration EE_Registration */
1706
				$attendee = $registration->attendee() ? $registration->attendee() : EEM_Attendee::instance()->create_default_object();
1707
				$this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : '';
1708
				$this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : '';
1709
				$this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : '';
1710
				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();//( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : '';
1711
1712
				$this->_template_args['attendees'][ $att_nmbr ]['address'] = implode( ', ', $attendee->full_address_as_array() );
1713
1714
				$this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce( array( 'action'=>'edit_attendee', 'post'=>$attendee->ID() ), REG_ADMIN_URL );
1715
1716
				$att_nmbr++;
1717
			}
1718
1719
			//EEH_Debug_Tools::printr( $attendees, '$attendees  <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' );
1720
1721
			$this->_template_args['event_name'] = $this->_registration->event_obj()->name();
1722
			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1723
1724
	//			$this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees'  ), REG_ADMIN_URL );
1725
		}
1726
		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
1727
		echo EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
1728
1729
	}
1730
1731
1732
1733
1734
1735
1736
	/**
1737
	 * 		generates HTML for the Edit Registration side meta box
1738
	*		@access public
1739
	*		@return void
1740
	*/
1741
	public function _reg_registrant_side_meta_box() {
1742
1743
		/*@var $attendee EE_Attendee */
1744
		$att_check = $this->_registration->attendee();
1745
		$attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
1746
1747
		//now let's determine if this is not the primary registration.  If it isn't then we set the primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the primary registration object (that way we know if we need to show cereate button or not)
1748
		if ( ! $this->_registration->is_primary_registrant() ) {
1749
			$primary_registration = $this->_registration->get_primary_registration();
1750
			$primary_attendee = $primary_registration->attendee();
1751
1752
			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID() ) {
1753
				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own custom attendee object so let's not worry about the primary reg.
1754
				$primary_registration = NULL;
1755
			}
1756
		} else {
1757
			$primary_registration = NULL;
1758
		}
1759
1760
		$this->_template_args['ATT_ID'] = $attendee->ID();
1761
		$this->_template_args['fname'] = $attendee->fname();//$this->_registration->ATT_fname;
1762
		$this->_template_args['lname'] = $attendee->lname();//$this->_registration->ATT_lname;
1763
		$this->_template_args['email'] = $attendee->email();//$this->_registration->ATT_email;
1764
		$this->_template_args['phone'] = $attendee->phone();
1765
1766
		EE_Registry::instance()->load_helper( 'Formatter' );
1767
		$this->_template_args[ 'formatted_address' ] = EEH_Address::format( $attendee );
1768
1769
1770
		//edit link
1771
		$this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce( array( 'action'=>'edit_attendee', 'post'=>$attendee->ID() ), REG_ADMIN_URL );
1772
		$this->_template_args['att_edit_label'] = __('View/Edit Contact' );
1773
1774
		//create link
1775
		$this->_template_args['create_link'] = $primary_registration instanceof EE_Registration ? EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'duplicate_attendee',  '_REG_ID' => $this->_registration->ID() ), REG_ADMIN_URL ): '';
1776
		$this->_template_args['create_label'] = __('Create Contact', 'event_espresso');
1777
1778
		$this->_template_args['att_check'] = $att_check;
1779
1780
1781
		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
1782
		echo EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
1783
	}
1784
1785
1786
1787
1788
1789
	/**
1790
	 * trash or restore registrations
1791
	 * @param  boolean $trash whether to archive or restore
1792
	 * @access protected
1793
	 * @return void
1794
	 */
1795
	protected function _trash_or_restore_registrations( $trash = TRUE ) {
1796
		$REGM = EEM_Registration::instance();
1797
1798
		$success = 1;
1799
		$error = 0;
1800
1801
		$tickets = array();
1802
		$dtts = array();
1803
1804
		//if empty _REG_ID then get out because there's nothing to do
1805 View Code Duplication
		if ( empty( $this->_req_data['_REG_ID'] ) ) {
1806
			$msg = $trash ? __('In order to trash registrations you must select which ones you wish to trash by clicking the checkboxes.', 'event_espresso') : __('In order to restore registrations you must select which ones you wish to restore by clicking the checkboxes.', 'event_espresso');
1807
			EE_Error::add_error( $msg, __FILE__, __LINE__, __FUNCTION__ );
1808
			$this->_redirect_after_action(FALSE, '', '', array(), TRUE );
1809
		}
1810
1811
		//Checkboxes
1812
		if (!empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
1813
			// if array has more than one element than success message should be plural
1814
			$success = count( $this->_req_data['_REG_ID'] ) > 1 ? 2 : 1;
1815
			// cycle thru checkboxes
1816
			while (list( $ind, $REG_ID ) = each($this->_req_data['_REG_ID'])) {
0 ignored issues
show
Unused Code introduced by
The assignment to $ind 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...
1817
1818
				$REG = $REGM->get_one_by_ID($REG_ID);
1819
				$payment_count = $REG->get_first_related('Transaction')->count_related('Payment');
1820
				if ( $payment_count > 0 ) {
1821
					$name = $REG->attendee() instanceof EE_Attendee ? $REG->attendee()->full_name() : __( 'Unknown Attendee', 'event_espresso' );
0 ignored issues
show
Documentation Bug introduced by
The method attendee 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...
1822
					$error = 1;
1823
					$success = 0;
1824
					EE_Error::add_error( sprintf( __('The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.', 'event_espresso'), $name ), __FILE__, __FUNCTION__, __LINE__ );
1825
					continue; //can't trash this registration because it has payments.
1826
				}
1827
				$ticket = $REG->get_first_related('Ticket');
1828
				$tickets[$ticket->ID()] = $ticket;
1829
				$dtt = $ticket->get_many_related('Datetime');
1830
				$dtts = array_merge($dtts, $dtt);
1831
1832
				$updated = $trash ? $REG->delete() : $REG->restore();
0 ignored issues
show
Documentation Bug introduced by
The method restore 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...
1833
				if ( !$updated ) {
1834
					$success = 0;
1835
				} else {
1836
					$success = 2;
1837
				}/**/
1838
			}
1839
1840
		} else {
1841
			// grab single id and delete
1842
			$REG_ID = absint($this->_req_data['_REG_ID']);
1843
			$REG = $REGM->get_one_by_ID($REG_ID);
1844
			$ticket = $REG->get_first_related('Ticket');
1845
			$tickets[$ticket->ID()] = $ticket;
1846
			$dtts = $ticket->get_many_related('Datetime');
1847
			$updated = $trash ? $REG->delete() : $REG->restore();
0 ignored issues
show
Documentation Bug introduced by
The method restore 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...
1848
			if ( ! $updated ) {
1849
				$success = 0;
1850
			}
1851
1852
		}
1853
1854
		//now let's update counts
1855
		EEM_Ticket::instance()->update_tickets_sold($tickets);
1856
		EEM_Datetime::instance()->update_sold($dtts);
1857
1858
		$what = $success > 1 ? __( 'Registrations', 'event_espresso' ) : __( 'Registration', 'event_espresso' );
1859
		$action_desc = $trash ? __( 'moved to the trash', 'event_espresso' ) : __( 'restored', 'event_espresso' );
1860
		$overwrite_msgs = $error ? TRUE : FALSE;
1861
		$this->_redirect_after_action( $success, $what, $action_desc, array( 'action' => 'default' ), $overwrite_msgs );
1862
	}
1863
1864
1865
1866
1867
1868
	/**
1869
	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the registration but also.
1870
	 *
1871
	 * 1. Removing relations to EE_Attendee
1872
	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are ALSO trashed.
1873
	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
1874
	 * 4. Removing relationships between all tickets and the related registrations
1875
	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
1876
	 * 6. Deleting permanently any related Checkins.
1877
	 * @return void
1878
	 */
1879
	protected function _delete_registrations() {
1880
		$REG_MDL = EEM_Registration::instance();
1881
1882
		$success = 1;
1883
1884
		//Checkboxes
1885
		if (!empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
1886
			// if array has more than one element than success message should be plural
1887
			$success = count( $this->_req_data['_REG_ID'] ) > 1 ? 2 : 1;
1888
			// cycle thru checkboxes
1889
			while (list( $ind, $REG_ID ) = each($this->_req_data['_REG_ID'])) {
0 ignored issues
show
Unused Code introduced by
The assignment to $ind 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...
1890
				$REG = $REG_MDL->get_one_by_ID($REG_ID);
1891
				if ( ! $REG instanceof EE_Registration )
1892
					continue;
1893
				$deleted = $this->_delete_registration($REG);
1894
				if ( !$deleted ) {
1895
					$success = 0;
1896
				}
1897
			}
1898
1899
		} else {
1900
			// grab single id and delete
1901
			$REG_ID = $this->_req_data['_REG_ID'];
1902
			$REG = $REG_MDL->get_one_by_ID($REG_ID);
1903
			$deleted = $this->_delete_registration($REG);
0 ignored issues
show
Documentation introduced by
$REG is of type object<EE_Base_Class>|null, but the function expects a object<EE_Registration>.

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...
1904
			if ( ! $deleted ) {
1905
				$success = 0;
1906
			}
1907
1908
		}
1909
1910
		$what = $success > 1 ? __( 'Registrations', 'event_espresso' ) : __( 'Registration', 'event_espresso' );
1911
		$action_desc = __( 'permanently deleted.', 'event_espresso' );
1912
		$this->_redirect_after_action( $success, $what, $action_desc, array( 'action' => 'default' ), TRUE );
1913
	}
1914
1915
1916
1917
1918
1919
	/**
1920
	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what models get affected.
1921
	 * @param  EE_Registration $REG registration to be deleted permenantly
1922
	 * @return boolean              true = successful deletion, false = fail.
1923
	 */
1924
	protected function _delete_registration( EE_Registration $REG ) {
1925
		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related registrations on the transaction that are NOT trashed.
1926
		$TXN = $REG->get_first_related('Transaction');
1927
		$REGS = $TXN->get_many_related('Registration');
1928
1929
		$all_trashed = TRUE;
1930
		foreach ( $REGS as $registration ) {
1931
			if ( ! $registration->get('REG_deleted') )
1932
				$all_trashed = FALSE;
1933
		}
1934
1935
		if ( ! $all_trashed ) {
1936
			EE_Error::add_error( __('Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
1937
			return false;
1938
		}
1939
1940
		//k made it here so that means we can delete all the related transactions and their answers (but let's do them separately from THIS one).
1941
		foreach ( $REGS as $registration ) {
1942
1943
			//delete related answers
1944
			$registration->delete_related_permanently('Answer');
1945
1946
			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
1947
			$attendee = $registration->get_first_related('Attendee');
1948
			if ( $attendee instanceof EE_Attendee ) {
1949
				$registration->_remove_relation_to($attendee, 'Attendee');
1950
			}
1951
1952
			//now remove relationships to tickets on this registration.
1953
			$registration->_remove_relations('Ticket');
1954
1955
			//now delete permanently the checkins related to this registration.
1956
			$registration->delete_related_permanently('Checkin');
1957
1958
			if ( $registration->ID() === $REG->ID() )
1959
				continue; //we don't want to delete permanently the existing registration just yet.
1960
1961
			//remove relation to transaction for these registrations if NOT the existing registrations
1962
			$registration->_remove_relations('Transaction');
1963
1964
			//now delete this registration permanently
1965
			$registration->delete_permanently();
1966
		}
1967
1968
		//now all related registrations on the transaction are handled.  So let's just handle this registration itself (the transaction and line items should be all that's left).
1969
		//delete the line items related to the transaction for this registration.
1970
		$TXN->delete_related_permanently('Line_Item');
1971
1972
		//we need to remove all the relationships on the transaction
1973
		$TXN->delete_related_permanently('Payment');
1974
		$TXN->delete_related_permanently('Extra_Meta');
1975
1976
		//now we can delete this REG permanently (and the transaction of course)
1977
		$REG->delete_related_permanently('Transaction');
1978
		return $REG->delete_permanently();
1979
	}
1980
1981
1982
1983
	/**
1984
	 * 	generates HTML for the Register New Attendee Admin page
1985
	 *
1986
	 * @access private
1987
	 * @throws \EE_Error
1988
	 * @return void
1989
	 */
1990
	public function new_registration() {
1991
		if ( ! $this->_set_reg_event() ) {
1992
			throw new EE_Error(__('Unable to continue with registering because there is no Event ID in the request', 'event_espresso') );
1993
		}
1994
		EE_Registry::instance()->REQ->set_espresso_page( TRUE );
1995
1996
		// gotta start with a clean slate if we're not coming here via ajax
1997
		if ( ! defined('DOING_AJAX' ) && ( ! isset( $this->_req_data['processing_registration'] ) || isset( $this->_req_data['step_error'] ))) {
1998
			EE_Registry::instance()->SSN->clear_session( __CLASS__, __FUNCTION__ );
1999
		}
2000
2001
		$this->_template_args['event_name'] = '' ;
2002
		// event name
2003
		if ( $this->_reg_event ) {
2004
			$this->_template_args['event_name'] = $this->_reg_event->name();
2005
			$edit_event_url = self::add_query_args_and_nonce( array( 'action'=>'edit', 'post'=>$this->_reg_event->ID() ), EVENTS_ADMIN_URL );
2006
			$edit_event_lnk = '<a href="'.$edit_event_url.'" title="' . esc_attr__( 'Edit ', 'event_espresso' ) . $this->_reg_event->name() . '">' . __( 'Edit Event', 'event_espresso' ) . '</a>';
2007
			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' . $edit_event_lnk . '</span>' ;
2008
		}
2009
2010
		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2011
2012
		if ( defined('DOING_AJAX' ) )
2013
			$this->_return_json();
2014
2015
2016
		// grab header
2017
		$template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2018
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
2019
2020
		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2021
		// the details template wrapper
2022
		$this->display_admin_page_with_sidebar();
2023
	}
2024
2025
2026
2027
2028
	/**
2029
	 * This returns the content for a registration step
2030
	 *
2031
	 * @access protected
2032
	 * @return string html
2033
	 */
2034
	protected function _get_registration_step_content() {
2035
2036
		$template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php';
2037
		$template_args = array(
2038
			'title' => '',
2039
			'content' => '',
2040
			'step_button_text' => ''
2041
			);
2042
2043
		//to indicate we're processing a new registration
2044
		$hidden_fields = array(
2045
			'processing_registration' => array(
2046
				'type' => 'hidden',
2047
				'value' => 1
2048
				),
2049
			'event_id' => array(
2050
				'type' => 'hidden',
2051
				'value' => $this->_reg_event->ID()
2052
				)
2053
			);
2054
2055
		//if the cart is empty then we know we're at step one so we'll display ticket selector
2056
		$cart = EE_Registry::instance()->SSN->get_session_data('cart');
2057
		$step = empty( $cart ) ? 'ticket' : 'questions';
2058
		switch ( $step ) {
2059
			case 'ticket' :
2060
				$template_args['title'] = __('Step One: Select the Ticket for this registration', 'event_espresso');
2061
				$template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector( $this->_reg_event );
2062
				$template_args['step_button_text'] = __('Add Tickets and Continue to Registrant Details', 'event_espresso');
2063
				$template_args['show_notification_toggle'] = FALSE;
2064
				break;
2065
			case 'questions' :
2066
				$template_args['title'] = __('Step Two: Add Registrant Details for this Registration', 'event_espresso');
2067
				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup properly by the first process_reg_step run.
2068
				$template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin();
2069
				$template_args['step_button_text'] = __('Save Registration and Continue to Details', 'event_espresso');
2070
				$template_args['show_notification_toggle'] = TRUE;
2071
				break;
2072
		}
2073
2074
		$this->_set_add_edit_form_tags( 'process_reg_step', $hidden_fields ); //we come back to the process_registration_step route.
2075
2076
		return EEH_Template::display_template( $template_path, $template_args, TRUE );
2077
	}
2078
2079
2080
2081
2082
2083
2084
	/**
2085
	 * 		set_reg_event
2086
	*		@access private
2087
	*		@return boolean
2088
	*/
2089
	private function _set_reg_event() {
2090
		if ( is_object( $this->_reg_event )) {
2091
			return TRUE;
2092
		}
2093
		$EVT_ID = ( ! empty( $this->_req_data['event_id'] )) ? absint( $this->_req_data['event_id'] ) : FALSE;
2094
		if ( ! $EVT_ID ) {
2095
			return FALSE;
2096
		}
2097
2098
		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2099
		return TRUE;
2100
	}
2101
2102
2103
2104
2105
2106
	/**
2107
	 * 		process_reg_step
2108
	 *
2109
	 * 		@access 		public
2110
	 * 		@return 		string
2111
	 */
2112
	public function process_reg_step() {
2113
2114
		$this->_set_reg_event();
2115
		EE_Registry::instance()->REQ->set_espresso_page( TRUE );
2116
2117
		//what step are we on?
2118
		$cart = EE_Registry::instance()->SSN->get_session_data( 'cart' );
2119
		$step = empty( $cart ) ? 'ticket' : 'questions';
2120
2121
		//if doing ajax then we need to verify the nonce
2122 View Code Duplication
		if ( 'DOING_AJAX' ) {
2123
			$nonce = isset( $this->_req_data[$this->_req_nonce] ) ? sanitize_text_field( $this->_req_data[$this->_req_nonce] ) : '';
2124
			$this->_verify_nonce( $nonce, $this->_req_nonce );
2125
		}
2126
2127
		switch ( $step ) {
2128
			case 'ticket' :
2129
				//process ticket selection
2130
				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2131
				if ( $success ) {
2132
					EE_Error::add_success( __('Tickets Selected. Now complete the registration.'), 'event_espresso');
2133
				} else {
2134
					$query_args['step_error'] = $this->_req_data['step_error'] = TRUE;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$query_args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $query_args = 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...
2135
				}
2136
				if ( defined('DOING_AJAX') ) {
2137
					$this->new_registration(); //display next step
2138
				} else {
2139
					$query_args['action'] = 'new_registration';
0 ignored issues
show
Bug introduced by
The variable $query_args 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...
2140
					$query_args['processing_registration'] = true;
2141
					$query_args['event_id'] = $this->_reg_event->ID();
2142
					$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
2143
				}
2144
				break;
2145
			case 'questions' :
2146
				if( ! isset( $this->_req_data[ 'txn_reg_status_change' ], $this->_req_data[ 'txn_reg_status_change' ][ 'send_notifications' ] ) ) {
2147
					add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15 );
2148
				}
2149
				//process registration
2150
				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2151
				if ( ! $transaction instanceof EE_Transaction ) {
2152
					$query_args = array(
2153
						'action' => 'new_registration',
2154
						'processing_registration' => true,
2155
						'event_id' => $this->_reg_event->ID()
2156
					);
2157
2158 View Code Duplication
					if ( defined('DOING_AJAX' )) {
2159
						//display registration form again because there are errors (maybe validation?)
2160
						$this->new_registration();
2161
						return;
2162
					} else {
2163
						$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
2164
						return;
2165
					}
2166
				}
2167
				/** @type EE_Transaction_Payments $transaction_payments */
2168
				$transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' );
2169
				// maybe update status, and make sure to save transaction if not done already
2170
				if ( ! $transaction_payments->update_transaction_status_based_on_total_paid( $transaction )) {
2171
					$transaction->save();
2172
				}
2173
				$query_args = array(
2174
					'action' => 'view_transaction',
2175
					'TXN_ID' => $transaction->ID(),
2176
					'page' => 'espresso_transactions'
2177
				);
2178
				EE_Error::add_success( __('Registration Created.  Please review the transaction and add any payments as necessary', 'event_espresso') );
2179
				$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
2180
				break;
2181
			}
2182
2183
			//what are you looking here for?  Should be nothing to do at this point.
2184
	}
2185
2186
2187
2188
2189
2190
2191
2192
2193
	/**
2194
	 * 		generates HTML for the Attendee Contact List
2195
	*		@access protected
2196
	*		@return void
2197
	*/
2198
	protected function _attendee_contact_list_table() {
2199
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
2200
		$this->_search_btn_label = __('Contacts', 'event_espresso');
2201
		$this->display_admin_list_table_page_with_no_sidebar();
2202
	}
2203
2204
2205
2206
2207
2208
	/**
2209
	 * 		get_attendees
2210
	 * 		@param bool $count whether to return count or data.
2211
	*		@access public
2212
	*		@return array
2213
	*/
2214
	public function get_attendees( $per_page, $count = FALSE, $trash = FALSE ) {
2215
2216
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
2217
		require_once( REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php' );
2218
		$ATT_MDL = EEM_Attendee::instance();
2219
2220
		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2221
2222
		switch ($this->_req_data['orderby']) {
2223
			case 'ATT_ID':
2224
				$orderby = 'ATT_ID';
2225
				break;
2226
			case 'ATT_fname':
2227
				$orderby = 'ATT_fname';
2228
				break;
2229
			case 'ATT_email':
2230
				$orderby = 'ATT_email';
2231
				break;
2232
			case 'ATT_city':
2233
				$orderby = 'ATT_city';
2234
				break;
2235
			case 'STA_ID':
2236
				$orderby = 'STA_ID';
2237
				break;
2238
			case 'CNT_ID':
2239
				$orderby = 'CNT_ID';
2240
				break;
2241
			default:
2242
				$orderby = 'ATT_lname';
2243
		}
2244
2245
		$sort = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'ASC';
2246
2247
		$current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1;
2248
		$per_page = isset( $per_page ) && !empty( $per_page ) ? $per_page : 10;
2249
		$per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page;
2250
2251
		$_where = array();
2252
2253
		if ( isset( $this->_req_data['s'] ) ) {
2254
			$sstr = '%' . $this->_req_data['s'] . '%';
2255
			$_where['OR'] = array(
2256
				'Registration.Event.EVT_name' => array( 'LIKE', $sstr),
2257
				'Registration.Event.EVT_desc' => array( 'LIKE', $sstr ),
2258
				'Registration.Event.EVT_short_desc' => array( 'LIKE' , $sstr ),
2259
				'ATT_fname' => array( 'LIKE', $sstr ),
2260
				'ATT_lname' => array( 'LIKE', $sstr ),
2261
				'ATT_short_bio' => array( 'LIKE', $sstr ),
2262
				'ATT_email' => array('LIKE', $sstr ),
2263
				'ATT_address' => array( 'LIKE', $sstr ),
2264
				'ATT_address2' => array( 'LIKE', $sstr ),
2265
				'ATT_city' => array( 'LIKE', $sstr ),
2266
				'Country.CNT_name' => array( 'LIKE', $sstr ),
2267
				'State.STA_name' => array('LIKE', $sstr ),
2268
				'ATT_phone' => array( 'LIKE', $sstr ),
2269
				'Registration.REG_final_price' => array( 'LIKE', $sstr ),
2270
				'Registration.REG_code' => array( 'LIKE', $sstr ),
2271
				'Registration.REG_count' => array( 'LIKE' , $sstr ),
2272
				'Registration.REG_group_size' => array( 'LIKE' , $sstr )
2273
				);
2274
		}
2275
2276
2277
		$offset = ($current_page-1)*$per_page;
2278
		$limit = $count ? NULL : array( $offset, $per_page );
2279
2280
		if ( $trash ) {
2281
			$_where['status'] = array( '!=', 'publish' );
2282
			$all_attendees = $count ? $ATT_MDL->count( array($_where,'order_by'=>array($orderby=>$sort), 'limit'=>$limit)): $ATT_MDL->get_all( array($_where,'order_by'=>array($orderby=>$sort), 'limit'=>$limit));
2283
		} else {
2284
			$_where['status'] = array( 'IN', array( 'publish' ) );
2285
			$all_attendees = $count ? $ATT_MDL->count( array($_where, 'order_by'=>array($orderby=>$sort),'limit'=>$limit)) : $ATT_MDL->get_all( array($_where, 'order_by'=>array($orderby=>$sort), 'limit'=>$limit) );
2286
		}
2287
2288
		return $all_attendees;
2289
	}
2290
2291
2292
2293
2294
	/**
2295
	 * This is just taking care of resending the registration confirmation
2296
	 *
2297
	 * @access protected
2298
	 * @return void
2299
	 */
2300
	protected function _resend_registration() {
2301
		$this->_process_resend_registration();
2302
		$query_args = isset($this->_req_data['redirect_to'] ) ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'] ) : array(
2303
			'action' => 'default'
2304
		);
2305
		$this->_redirect_after_action(FALSE, '', '', $query_args, TRUE );
2306
	}
2307
2308
2309
2310
2311
2312
2313
	public function _registrations_report(){
2314
		if( ! defined( 'EE_USE_OLD_CSV_REPORT_CLASS' ) ) {
2315
			wp_redirect( EE_Admin_Page::add_query_args_and_nonce( 
2316
				array(
2317
					'page' => 'espresso_support',
2318
					'action' => 'batch_file_create',
2319
					'EVT_ID' => isset( $this->_req_data[ 'EVT_ID'] ) ? $this->_req_data[ 'EVT_ID' ] : NULL,
2320
					'job_handler' => urlencode( 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' ),
2321
					'redirect_url' => urlencode( $this->_req_data[ 'return_url' ] ),
2322
				)) );
2323
		} else {
2324
			EE_Registry::instance()->load_helper( 'File' );
2325
			$new_request_args = array(
2326
				'export' => 'report',
2327
				'action' => 'registrations_report_for_event',
2328
				'EVT_ID' => isset( $this->_req_data[ 'EVT_ID'] ) ? $this->_req_data[ 'EVT_ID' ] : NULL,
2329
			);
2330
			$this->_req_data = array_merge($this->_req_data, $new_request_args);
2331
2332
			if ( is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2333
				require_once(EE_CLASSES . 'EE_Export.class.php');
2334
				$EE_Export = EE_Export::instance($this->_req_data);
2335
				$EE_Export->export();
2336
			}
2337
		}
2338
	}
2339
2340
2341
2342
	public function _contact_list_export(){
2343
		EE_Registry::instance()->load_helper( 'File' );
2344
		if ( is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2345
			require_once(EE_CLASSES . 'EE_Export.class.php');
2346
			$EE_Export = EE_Export::instance($this->_req_data);
2347
			$EE_Export->export_attendees();
2348
		}
2349
	}
2350
2351
	public function _contact_list_report(){
2352
		if( ! defined( 'EE_USE_OLD_CSV_REPORT_CLASS' ) ) {
2353
			wp_redirect( EE_Admin_Page::add_query_args_and_nonce( 
2354
				array(
2355
					'page' => 'espresso_support',
2356
					'action' => 'batch_file_create',
2357
					'job_handler' => urlencode( 'EventEspressoBatchRequest\JobHandlers\AttendeesReport' ),
2358
					'redirect_url' => urlencode( $this->_req_data[ 'return_url' ] ),
2359
				)) );
2360
		} else {
2361
			EE_Registry::instance()->load_helper( 'File' );
2362
			if ( is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2363
				require_once(EE_CLASSES . 'EE_Export.class.php');
2364
				$EE_Export = EE_Export::instance($this->_req_data);
2365
				$EE_Export->report_attendees();
2366
			}
2367
		}
2368
	}
2369
2370
2371
2372
2373
2374
2375
	/***************************************		ATTENDEE DETAILS 		***************************************/
2376
2377
2378
	/**
2379
	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
2380
	 * @return void
2381
	 */
2382
	protected function _duplicate_attendee() {
2383
		$action = !empty( $this->_req_data['return'] ) ? $this->_req_data['return'] : 'default';
2384
		//verify we have necessary info
2385 View Code Duplication
		if ( empty($this->_req_data['_REG_ID'] )  ) {
2386
			EE_Error::add_error( __('Unable to create the contact for the registration because the required paramaters are not present (_REG_ID )', 'event_espresso'),  __FILE__, __LINE__, __FUNCTION__ );
2387
			$query_args = array( 'action' => $action );
2388
			$this->_redirect_after_action('', '', '', $query_args, TRUE);
2389
		}
2390
2391
		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
2392
		$registration = EEM_Registration::instance()->get_one_by_ID( $this->_req_data['_REG_ID'] );
2393
		$attendee = $registration->attendee();
0 ignored issues
show
Documentation Bug introduced by
The method attendee 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...
2394
2395
		//remove relation of existing attendee on registration
2396
		$registration->_remove_relation_to($attendee, 'Attendee' );
2397
		//new attendee
2398
		$new_attendee = clone $attendee;
2399
		$new_attendee->set( 'ATT_ID', 0 );
2400
		$new_attendee->save();
2401
2402
		//add new attendee to reg
2403
		$registration->_add_relation_to( $new_attendee, 'Attendee');
2404
2405
		EE_Error::add_success( __('New Contact record created.  Now make any edits you wish to make for this contact.', 'event_espresso') );
2406
2407
		//redirect to edit page for attendee
2408
		$query_args = array( 'post' => $new_attendee->ID(), 'action' => 'edit_attendee' );
2409
2410
		$this->_redirect_after_action( '', '', '', $query_args, TRUE );
2411
	}
2412
2413
2414
	//related to cpt routes
2415
	protected function _insert_update_cpt_item($post_id, $post) {
2416
		$success = true;
2417
		$attendee = EEM_Attendee::instance()->get_one_by_ID( $post_id );
2418
		//for attendee updates
2419
		if ( $post->post_type = 'espresso_attendees' && !empty( $attendee ) ) {
0 ignored issues
show
Comprehensibility introduced by
Consider adding parentheses for clarity. Current Interpretation: $post->post_type = ('esp...' && !empty($attendee)), Probably Intended Meaning: ($post->post_type = 'esp...') && !empty($attendee)
Loading history...
2420
			//note we should only be UPDATING attendees at this point.
2421
			$updated_fields = array(
2422
				'ATT_fname' => $this->_req_data['ATT_fname'],
2423
				'ATT_lname' => $this->_req_data['ATT_lname'],
2424
				'ATT_full_name'=> $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
2425
				'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
2426
				'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
2427
				'ATT_city' => isset( $this->_req_data['ATT_city'] ) ? $this->_req_data['ATT_city'] : '',
2428
				'STA_ID' => isset( $this->_req_data['STA_ID'] ) ? $this->_req_data['STA_ID'] : '',
2429
				'CNT_ISO' => isset( $this->_req_data['CNT_ISO'] ) ? $this->_req_data['CNT_ISO'] : '',
2430
				'ATT_zip' => isset( $this->_req_data['ATT_zip'] ) ? $this->_req_data['ATT_zip'] : '',
2431
				'ATT_email' => isset( $this->_req_data['ATT_email'] ) ? $this->_req_data['ATT_email'] : '',
2432
				'ATT_phone' => isset( $this->_req_data['ATT_phone'] ) ? $this->_req_data['ATT_phone'] : ''
2433
				);
2434
			foreach ( $updated_fields as $field => $value ) {
2435
				$attendee->set($field, $value);
2436
			}
2437
2438
			$success = $attendee->save();
2439
2440
			$attendee_update_callbacks = apply_filters( 'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', array() );
2441
			foreach ( $attendee_update_callbacks as $a_callback ) {
2442
				if ( FALSE === call_user_func_array( $a_callback, array($attendee, $this->_req_data ) ) ) {
2443
					throw new EE_Error( sprintf( __('The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.', 'event_espresso'), $a_callback ) );
2444
				}
2445
			}
2446
		}
2447
2448
		if ( $success === FALSE )
2449
			EE_Error::add_error(__('Something went wrong with updating the meta table data for the registration.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
2450
2451
	}
2452
2453
2454
2455
2456
	public function trash_cpt_item($post_id) {}
2457
	public function delete_cpt_item($post_id) {}
2458
	public function restore_cpt_item($post_id) {}
2459
	protected function _restore_cpt_item($post_id, $revision_id) {}
2460
2461
2462
	public function attendee_editor_metaboxes() {
2463
2464
		$this->verify_cpt_object();
2465
2466
		remove_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2467
		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2468
2469 View Code Duplication
		if ( post_type_supports( 'espresso_attendees', 'excerpt') ) {
2470
			add_meta_box('postexcerpt', __('Short Biography', 'event_espresso'), 'post_excerpt_meta_box', $this->_cpt_routes[$this->_req_action], 'normal' );
2471
		}
2472
2473 View Code Duplication
		if ( post_type_supports( 'espresso_attendees', 'comments') ) {
2474
			add_meta_box('commentsdiv', __('Notes on the Contact', 'event_espresso'), 'post_comment_meta_box', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2475
		}
2476
2477
		add_meta_box('attendee_contact_info', __('Contact Info', 'event_espresso'), array( $this, 'attendee_contact_info'), $this->_cpt_routes[$this->_req_action], 'side', 'core' );
2478
		add_meta_box('attendee_details_address', __('Address Details', 'event_espresso'), array($this, 'attendee_address_details'), $this->_cpt_routes[$this->_req_action], 'normal', 'core' );
2479
		add_meta_box('attendee_registrations', __('Registrations for this Contact', 'event_espresso'), array( $this, 'attendee_registrations_meta_box'), $this->_cpt_routes[$this->_req_action], 'normal', 'high');
2480
	}
2481
2482
2483
	/**
2484
	 * Metabox for attendee contact info
2485
	 * @param  WP_Post $post wp post object
2486
	 * @return string        attendee contact info ( and form )
2487
	 */
2488
	public function attendee_contact_info( $post ) {
0 ignored issues
show
Unused Code introduced by
The parameter $post is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2489
		//get attendee object ( should already have it )
2490
		$this->_template_args['attendee'] = $this->_cpt_model_obj;
2491
		$template = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
2492
		EEH_Template::display_template($template, $this->_template_args);
2493
	}
2494
2495
2496
2497
	/**
2498
	 * Metabox for attendee details
2499
	 * @param  WP_Post $post wp post object
2500
	 * @return string        attendee address details (and form)
2501
	 */
2502
	public function attendee_address_details($post) {
0 ignored issues
show
Unused Code introduced by
The parameter $post is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2503
		//get attendee object (should already have it)
2504
		$this->_template_args['attendee'] = $this->_cpt_model_obj;
2505
		$this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
2506
				new EE_Question_Form_Input(
2507
				EE_Question::new_instance( array(
2508
					'QST_ID' => 0,
2509
					'QST_display_text' => __('State/Province', 'event_espresso'),
2510
					'QST_system' => 'admin-state'
2511
					)),
2512
				EE_Answer::new_instance( array(
2513
					'ANS_ID' => 0,
2514
					'ANS_value' => $this->_cpt_model_obj->state_ID()
0 ignored issues
show
Documentation Bug introduced by
The method state_ID does not exist on object<EE_CPT_Base>? 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...
2515
					)),
2516
				array(
2517
					'input_id' => 'STA_ID',
2518
					'input_name' => 'STA_ID',
2519
					'input_prefix' => '',
2520
					'append_qstn_id' => FALSE
2521
					)
2522
			));
2523
		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
2524
				new EE_Question_Form_Input(
2525
				EE_Question::new_instance( array(
2526
					'QST_ID' => 0,
2527
					'QST_display_text' => __('Country', 'event_espresso'),
2528
					'QST_system' => 'admin-country'
2529
					)),
2530
				EE_Answer::new_instance( array(
2531
					'ANS_ID' => 0,
2532
					'ANS_value' => $this->_cpt_model_obj->country_ID()
0 ignored issues
show
Documentation Bug introduced by
The method country_ID does not exist on object<EE_CPT_Base>? 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...
2533
					)),
2534
				array(
2535
					'input_id' => 'CNT_ISO',
2536
					'input_name' => 'CNT_ISO',
2537
					'input_prefix' => '',
2538
					'append_qstn_id' => FALSE
2539
					)
2540
				));
2541
		$template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
2542
		EEH_Template::display_template($template, $this->_template_args );
2543
2544
	}
2545
2546
2547
	/**
2548
	 * 		_attendee_details
2549
	*		@access protected
2550
	*		@return void
2551
	*/
2552
	public function attendee_registrations_meta_box( $post ) {
0 ignored issues
show
Unused Code introduced by
The parameter $post is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2553
2554
		$this->_template_args['attendee'] = $this->_cpt_model_obj;
2555
		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
2556
		$template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
2557
		EEH_Template::display_template($template, $this->_template_args);
2558
2559
	}
2560
2561
2562
2563
2564
	/**
2565
	 * add in the form fields for the attendee edit
2566
	 * @param  WP_Post $post wp post object
2567
	 * @return string        html for new form.
2568
	 */
2569
	public function after_title_form_fields($post) {
2570
		if ( $post->post_type == 'espresso_attendees' ) {
2571
			$template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
2572
			$template_args['attendee'] = $this->_cpt_model_obj;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$template_args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $template_args = 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...
2573
			EEH_Template::display_template($template, $template_args);
2574
		}
2575
	}
2576
2577
2578
2579
2580
2581
2582
	/**
2583
	 * 		_trash_or_restore_attendee
2584
	*		@param boolean 		$trash - whether to move item to trash (TRUE) or restore it (FALSE)
2585
	*		@access protected
2586
	*		@return void
2587
	*/
2588
	protected function _trash_or_restore_attendees( $trash = TRUE ) {
2589
2590
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
2591
2592
		$ATT_MDL = EEM_Attendee::instance();
2593
2594
		$success = 1;
2595
		//Checkboxes
2596
		if (!empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2597
			// if array has more than one element than success message should be plural
2598
			$success = count( $this->_req_data['checkbox'] ) > 1 ? 2 : 1;
2599
			// cycle thru checkboxes
2600
			while (list( $ATT_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...
2601
				$updated = $trash ? $ATT_MDL->update_by_ID(array( 'status' => 'trash' ), $ATT_ID) : $ATT_MDL->update_by_ID( array('status' => 'publish' ), $ATT_ID);
2602
				if ( !$updated ) {
2603
					$success = 0;
2604
				}
2605
			}
2606
2607
		} else {
2608
			// grab single id and delete
2609
			$ATT_ID = absint($this->_req_data['ATT_ID']);
2610
			//get attendee
2611
			$att = $ATT_MDL->get_one_by_ID( $ATT_ID );
2612
			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
0 ignored issues
show
Documentation Bug introduced by
The method set_status 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...
Unused Code introduced by
$updated 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...
2613
			$updated = $att->save();
2614
			if ( ! $updated ) {
2615
				$success = 0;
2616
			}
2617
2618
		}
2619
2620
		$what = $success > 1 ? __( 'Contacts', 'event_espresso' ) : __( 'Contact', 'event_espresso' );
2621
		$action_desc = $trash ? __( 'moved to the trash', 'event_espresso' ) : __( 'restored', 'event_espresso' );
2622
		$this->_redirect_after_action( $success, $what, $action_desc, array( 'action' => 'contact_list' ) );
2623
2624
	}
2625
2626
}
2627
2628
2629
2630
// end of file:  includes/core/admin/transactions/Registrations_Admin_Page.core.php
2631