Completed
Branch BUG-9623-config-log (1352ef)
by
unknown
373:04 queued 358:05
created

Registrations_Admin_Page   F

Complexity

Total Complexity 350

Size/Duplication

Total Lines 2713
Duplicated Lines 3.87 %

Coupling/Cohesion

Components 2
Dependencies 47
Metric Value
wmc 350
lcom 2
cbo 47
dl 105
loc 2713
rs 0.5217

80 Methods

Rating   Name   Duplication   Size   Complexity  
A clear_comment_link() 0 7 2
A _ajax_hooks() 0 4 1
A _define_page_props() 0 21 1
A _set_list_table_views_contact_list() 0 23 2
B _init_page_props() 0 28 1
A _add_screen_options() 0 1 1
A _add_feature_pointers() 0 1 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 7 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 _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 14 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
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 12 3
A form_before_question_group() 13 13 1
A form_after_question_group() 0 22 1
A form_form_field_label_wrap() 14 14 1
A form_form_field_input__wrap() 14 14 1
B _update_attendee_registration_form() 0 12 5
A _get_reg_custom_questions_form() 0 8 2
B _save_reg_custom_questions_form() 0 34 6
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
A _set_reg_event() 0 12 4
A _attendee_contact_list_table() 0 5 1
F get_attendees() 0 76 21
A _resend_registration() 0 7 2
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
A admin_init() 0 3 1
A redirect_to_txn() 0 18 3
C new_registration() 0 35 7
B _get_registration_step_content() 0 76 6
D process_reg_step() 12 84 14
A __construct() 0 4 1
B wp_loaded() 0 16 5
B _set_page_config() 0 136 3
F _reg_status_change_return() 0 32 11
C _set_page_routes() 0 237 7

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
	 * @var EE_Registration
28
	 */
29
	private $_registration;
30
31
	/**
32
	 * @var EE_Event
33
	 */
34
	private $_reg_event;
35
36
	/**
37
	 * @var EE_Session
38
	 */
39
	private $_session;
40
	private static $_reg_status;
41
42
	/**
43
	 * Form for displaying the custom questions for this registration.
44
	 * This gets used a few times throughout the request so its best to cache it
45
	 * @var EE_Registration_Custom_Questions_Form
46
	 */
47
	protected $_reg_custom_questions_form = null;
48
49
50
51
	/**
52
	 *        constructor
53
	 *
54
	 * @Constructor
55
	 * @access public
56
	 * @param bool $routing
57
	 * @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...
58
	 */
59
	public function __construct( $routing = TRUE ) {
60
		parent::__construct( $routing );
61
		add_action( 'wp_loaded', array( $this, 'wp_loaded' ));
62
	}
63
64
65
66
	public function wp_loaded() {
67
		// when adding a new registration...
68
		if ( isset( $this->_req_data[ 'action' ] ) && $this->_req_data[ 'action' ] == 'new_registration' ) {
69
			EE_System::do_not_cache();
70
			if (
71
				! isset( $this->_req_data[ 'processing_registration' ] )
72
				|| absint( $this->_req_data[ 'processing_registration' ] ) !== 1
73
			) {
74
				// and it's NOT the attendee information reg step
75
				// force cookie expiration by setting time to last week
76
				setcookie( 'ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/' );
77
				// and update the global
78
				$_COOKIE[ 'ee_registration_added' ] = 0;
79
			}
80
		}
81
	}
82
83
84
85
86
87
88
	protected function _init_page_props() {
89
		$this->page_slug = REG_PG_SLUG;
90
		$this->_admin_base_url = REG_ADMIN_URL;
91
		$this->_admin_base_path = REG_ADMIN;
92
		$this->page_label = __('Registrations', 'event_espresso');
93
		$this->_cpt_routes = array(
94
			'add_new_attendee' => 'espresso_attendees',
95
			'edit_attendee' => 'espresso_attendees',
96
			'insert_attendee' => 'espresso_attendees',
97
			'update_attendee' => 'espresso_attendees'
98
			);
99
		$this->_cpt_model_names = array(
100
			'add_new_attendee' => 'EEM_Attendee',
101
			'edit_attendee' => 'EEM_Attendee'
102
			);
103
		$this->_cpt_edit_routes = array(
104
			'espresso_attendees' => 'edit_attendee'
105
			);
106
		$this->_pagenow_map = array(
107
				'add_new_attendee' => 'post-new.php',
108
				'edit_attendee' => 'post.php',
109
				'trash' => 'post.php'
110
			);
111
112
		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10 );
113
		//add filters so that the comment urls don't take users to a confusing 404 page
114
		add_filter('get_comment_link', array( $this, 'clear_comment_link' ), 10, 3 );
115
	}
116
117
118
	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...
119
		//gotta make sure this only happens on this route
120
		$post_type = get_post_type( $comment->comment_post_ID);
121
		if ( $post_type == 'espresso_attendees' )
122
			return '#commentsdiv';
123
		return $link;
124
	}
125
126
127
	protected function _ajax_hooks() {
128
		//todo: all hooks for registrations ajax goes in here
129
		add_action( 'wp_ajax_toggle_checkin_status', array( $this, 'toggle_checkin_status' ));
130
	}
131
132
133
134
135
136
	protected function  _define_page_props() {
137
		$this->_admin_page_title = $this->page_label;
138
		$this->_labels = array(
139
			'buttons' => array(
140
				'add-registrant' => __('Add New Registration', 'event_espresso'),
141
				'add-attendee' => __('Add Contact', 'event_espresso'),
142
				'edit' => __('Edit Contact', 'event_espresso'),
143
				'report'=>  __("Event Registrations CSV Report", "event_espresso"),
144
				'report_all' => __( 'All Registrations CSV Report', 'event_espresso' ),
145
				'contact_list_report' => __( 'Contact List Report', 'event_espresso' ),
146
				'contact_list_export'=>  __("Export Data", "event_espresso"),
147
			),
148
			'publishbox' => array(
149
				'add_new_attendee' => __("Add Contact Record", 'event_espresso'),
150
				'edit_attendee' => __("Update Contact Record", 'event_espresso')
151
			),
152
			'hide_add_button_on_cpt_route' => array(
153
				'edit_attendee' => true
154
			)
155
		);
156
	}
157
158
159
160
161
162
163
164
	/**
165
	 * 		grab url requests and route them
166
	*		@access private
167
	*		@return void
168
	*/
169
	public function _set_page_routes() {
170
171
		$this->_get_registration_status_array();
172
173
		$reg_id = ! empty( $this->_req_data['_REG_ID'] ) && ! is_array( $this->_req_data['_REG_ID'] ) ? $this->_req_data['_REG_ID'] : 0;
174
		$att_id = ! empty( $this->_req_data[ 'ATT_ID' ] ) && ! is_array( $this->_req_data['ATT_ID'] ) ? $this->_req_data['ATT_ID'] : 0;
175
		$att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] ) ? $this->_req_data['post'] : $att_id;
176
177
		$this->_page_routes = array(
178
179
				'default'	=> array(
180
					'func' => '_registrations_overview_list_table',
181
					'capability' => 'ee_read_registrations'
182
					),
183
184
				'view_registration'	=> array(
185
					'func' => '_registration_details',
186
					'capability' => 'ee_read_registration',
187
					'obj_id' => $reg_id
188
					),
189
190
				'edit_registration'	=> array(
191
						'func' => '_update_attendee_registration_form',
192
						'noheader' => TRUE,
193
						'headers_sent_route'=>'view_registration',
194
						'capability' => 'ee_edit_registration',
195
						'obj_id' => $reg_id,
196
						'_REG_ID' => $reg_id,
197
					),
198
199
				'trash_registrations' => array(
200
					'func' => '_trash_or_restore_registrations',
201
					'args' => array('trash' => TRUE),
202
					'noheader' => TRUE,
203
					'capability' => 'ee_delete_registrations'
204
					),
205
206
				'restore_registrations' => array(
207
					'func' => '_trash_or_restore_registrations',
208
					'args' => array( 'trash' => FALSE ),
209
					'noheader' => TRUE,
210
					'capability' => 'ee_delete_registrations'
211
					),
212
213
				'delete_registrations' => array(
214
					'func' => '_delete_registrations',
215
					'noheader' => TRUE,
216
					'capability' => 'ee_delete_registrations'
217
					),
218
219
				'new_registration' => array(
220
					'func' => 'new_registration',
221
					'capability' => 'ee_edit_registrations'
222
					),
223
224
				'process_reg_step'	=> array(
225
					'func' => 'process_reg_step',
226
					'noheader' => TRUE,
227
					'capability' => 'ee_edit_registrations'
228
				),
229
230
				'redirect_to_txn'	=> array(
231
					'func' => 'redirect_to_txn',
232
					'noheader' => TRUE,
233
					'capability' => 'ee_edit_registrations'
234
				),
235
236
				'change_reg_status' => array(
237
					'func' => '_change_reg_status',
238
					'noheader' => TRUE,
239
					'capability' => 'ee_edit_registration',
240
					'obj_id' => $reg_id
241
					),
242
243
				'approve_registration'	=> array(
244
						'func' => 'approve_registration',
245
						'noheader' => TRUE,
246
						'capability' => 'ee_edit_registration',
247
						'obj_id' => $reg_id
248
					),
249
250
				'approve_and_notify_registration' => array(
251
					'func' => 'approve_registration',
252
					'noheader' => TRUE,
253
					'args' => array(TRUE),
254
					'capability' => 'ee_edit_registration',
255
					'obj_id' => $reg_id
256
					),
257
258
				'decline_registration'	=> array(
259
						'func' => 'decline_registration',
260
						'noheader' => TRUE,
261
						'capability' => 'ee_edit_registration',
262
						'obj_id' => $reg_id
263
					),
264
265
				'decline_and_notify_registration' => array(
266
					'func' => 'decline_registration',
267
					'noheader' => TRUE,
268
					'args' => array(TRUE),
269
					'capability' => 'ee_edit_registration',
270
					'obj_id' => $reg_id
271
					),
272
273
				'pending_registration'	=> array(
274
						'func' => 'pending_registration',
275
						'noheader' => TRUE,
276
						'capability' => 'ee_edit_registration',
277
						'obj_id' => $reg_id
278
					),
279
280
				'pending_and_notify_registration' => array(
281
					'func' => 'pending_registration',
282
					'noheader' => TRUE,
283
					'args' => array(TRUE),
284
					'capability' => 'ee_edit_registration',
285
					'obj_id' => $reg_id
286
					),
287
288
				'no_approve_registration' => array(
289
					'func' => 'not_approve_registration',
290
					'noheader' => TRUE,
291
					'capability' => 'ee_edit_registration',
292
					'obj_id' => $reg_id
293
					),
294
295
				'no_approve_and_notify_registration' => array(
296
					'func' => 'not_approve_registration',
297
					'noheader' => TRUE,
298
					'args' => array(TRUE),
299
					'capability' => 'ee_edit_registration',
300
					'obj_id' => $reg_id
301
					),
302
303
				'cancel_registration'	=> array(
304
						'func' => 'cancel_registration',
305
						'noheader' => TRUE,
306
						'capability' => 'ee_edit_registration',
307
						'obj_id' => $reg_id
308
					),
309
310
				'cancel_and_notify_registration' => array(
311
					'func' => 'cancel_registration',
312
					'noheader' => TRUE,
313
					'args' => array(TRUE),
314
					'capability' => 'ee_edit_registration',
315
					'obj_id' => $reg_id
316
					),
317
318
				'contact_list'	=> array(
319
					'func' => '_attendee_contact_list_table',
320
					'capability' => 'ee_read_contacts'
321
					),
322
323
324
				'add_new_attendee'	=> array(
325
					'func' => '_create_new_cpt_item',
326
					'args' => array(
327
						'new_attendee' => TRUE,
328
					'capability' => 'ee_edit_contacts'
329
					)
330
				),
331
332
				'edit_attendee'	=> array(
333
					'func' => '_edit_cpt_item',
334
					'capability' => 'ee_edit_contacts',
335
					'obj_id' => $att_id
336
				),
337
338
				'duplicate_attendee' => array(
339
					'func' => '_duplicate_attendee',
340
					'noheader' => TRUE,
341
					'capability' => 'ee_edit_contacts',
342
					'obj_id' => $att_id
343
					),
344
345
				'insert_attendee'	=> array(
346
					'func' => '_insert_or_update_attendee',
347
					'args' => array(
348
						'new_attendee' => TRUE
349
					),
350
					'noheader' => TRUE,
351
					'capability' => 'ee_edit_contacts'
352
				),
353
354
				'update_attendee'	=> array(
355
					'func' => '_insert_or_update_attendee',
356
					'args' => array(
357
						'new_attendee' => FALSE
358
					),
359
					'noheader' => TRUE,
360
					'capability' => 'ee_edit_contacts',
361
					'obj_id' => $att_id
362
				),
363
364
				'trash_attendees'	=> array(
365
					'func' => '_trash_or_restore_attendees',
366
					'args' => array(
367
						'trash' => TRUE
368
					),
369
					'noheader' => TRUE,
370
					'capability' => 'ee_delete_contacts',
371
					'obj_id' => $att_id
372
				),
373
374
				'restore_attendees'	=> array(
375
					'func' => '_trash_or_restore_attendees',
376
					'args' => array(
377
						'trash' => FALSE
378
					),
379
					'noheader' => TRUE,
380
					'capability' => 'ee_delete_contacts',
381
					'obj_id' => $att_id
382
				),
383
				'resend_registration' => array(
384
					'func' => '_resend_registration',
385
					'noheader' => TRUE,
386
					'capability' => 'ee_send_message'
387
					),
388
				'registrations_report'=>array(
389
					'func'=>'_registrations_report',
390
					'noheader'=> TRUE,
391
					'capability' => 'ee_read_registrations'
392
				),
393
				'contact_list_export'=>array(
394
					'func'=>'_contact_list_export',
395
					'noheader'=>TRUE,
396
					'capability' => 'export'
397
				),
398
				'contact_list_report' => array(
399
					'func'=> '_contact_list_report',
400
					'noheader' => TRUE,
401
					'capability' => 'ee_read_contacts',
402
				)
403
		);
404
405
	}
406
407
408
409
410
411
	protected function _set_page_config() {
412
		$this->_page_config = array(
413
414
			'default' => array(
415
				'nav' => array(
416
					'label' => __('Overview', 'event_espresso'),
417
					'order' => 5
418
				),
419
			'help_tabs' => array(
420
					'registrations_overview_help_tab' => array(
421
						'title' => __('Registrations Overview', 'event_espresso'),
422
						'filename' => 'registrations_overview'
423
					),
424
					'registrations_overview_table_column_headings_help_tab' => array(
425
						'title' => __('Registrations Table Column Headings', 'event_espresso'),
426
						'filename' => 'registrations_overview_table_column_headings'
427
					),
428
					'registrations_overview_filters_help_tab' => array(
429
						'title' => __('Registration Filters', 'event_espresso'),
430
						'filename' => 'registrations_overview_filters'
431
					),
432
					'registrations_overview_views_help_tab' => array(
433
						'title' => __('Registration Views', 'event_espresso'),
434
						'filename' => 'registrations_overview_views'
435
					),
436
					'registrations_overview_other_help_tab' => array(
437
						'title' => __('Registrations Other', 'event_espresso'),
438
						'filename' => 'registrations_overview_other'
439
					)
440
                ),
441
				'help_tour' => array( 'Registration_Overview_Help_Tour' ),
442
				'qtips' => array('Registration_List_Table_Tips'),
443
				'list_table' => 'EE_Registrations_List_Table',
444
				'require_nonce' => FALSE
445
			),
446
447
			'view_registration' => array(
448
				'nav' => array(
449
					'label' => __('REG Details', 'event_espresso'),
450
					'order' => 15,
451
					'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,
452
					'persistent' => FALSE
453
				),
454
                'help_tabs' => array(
455
					'registrations_details_help_tab' => array(
456
						'title' => __('Registration Details', 'event_espresso'),
457
						'filename' => 'registrations_details'
458
					),
459
					'registrations_details_table_help_tab' => array(
460
						'title' => __('Registration Details Table', 'event_espresso'),
461
						'filename' => 'registrations_details_table'
462
					),
463
					'registrations_details_form_answers_help_tab' => array(
464
						'title' => __('Registration Form Answers', 'event_espresso'),
465
						'filename' => 'registrations_details_form_answers'
466
					),
467
					'registrations_details_registrant_details_help_tab' => array(
468
						'title' => __('Contact Details', 'event_espresso'),
469
						'filename' => 'registrations_details_registrant_details'
470
					)
471
				),
472
				'help_tour' => array( 'Registration_Details_Help_Tour' ),
473
				'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array( '_registration_details_metaboxes' ) ),
474
				'require_nonce' => FALSE
475
			),
476
477
			'new_registration' => array(
478
				'nav' => array(
479
					'label' => __('Add New Registration', 'event_espresso'),
480
					'url' => '#',
481
					'order' => 15,
482
					'persistent' => FALSE
483
				),
484
				'metaboxes' => $this->_default_espresso_metaboxes,
485
				'labels' => array(
486
					'publishbox' => __('Save Registration', 'event_espresso')
487
				),
488
				'require_nonce' => FALSE
489
			),
490
491
			'add_new_attendee' => array(
492
				'nav' => array(
493
					'label' => __('Add Contact', 'event_espresso'),
494
					'order' => 15,
495
					'persistent' => FALSE
496
				),
497
				'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_publish_post_box', 'attendee_editor_metaboxes' ) ),
498
				'require_nonce' => FALSE
499
			),
500
501
			'edit_attendee' => array(
502
				'nav' => array(
503
					'label' => __('Edit Contact', 'event_espresso'),
504
					'order' => 15,
505
					'persistent' => FALSE,
506
					'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
507
				),
508
				'metaboxes' => array('attendee_editor_metaboxes'),
509
				'require_nonce' => FALSE
510
			),
511
512
			'contact_list' => array(
513
				'nav' => array(
514
					'label' => __('Contact List', 'event_espresso'),
515
					'order' => 20
516
				),
517
				'list_table' => 'EE_Attendee_Contact_List_Table',
518
                'help_tabs' => array(
519
					'registrations_contact_list_help_tab' => array(
520
						'title' => __('Registrations Contact List', 'event_espresso'),
521
						'filename' => 'registrations_contact_list'
522
					),
523
					'registrations_contact-list_table_column_headings_help_tab' => array(
524
						'title' => __('Contact List Table Column Headings', 'event_espresso'),
525
						'filename' => 'registrations_contact_list_table_column_headings'
526
					),
527
					'registrations_contact_list_views_help_tab' => array(
528
						'title' => __('Contact List Views', 'event_espresso'),
529
						'filename' => 'registrations_contact_list_views'
530
					),
531
					'registrations_contact_list_other_help_tab' => array(
532
						'title' => __('Contact List Other', 'event_espresso'),
533
						'filename' => 'registrations_contact_list_other'
534
					)
535
                ),
536
				'help_tour' => array( 'Contact_List_Help_Tour' ),
537
				'metaboxes' => array(),
538
				'require_nonce' => FALSE
539
			),
540
541
			//override default cpt routes
542
			'create_new' => '',
543
			'edit' => ''
544
545
		);
546
	}
547
548
549
	/**
550
	 * The below methods aren't used by this class currently
551
	 */
552
	protected function _add_screen_options() {}
553
	protected function _add_feature_pointers() {}
554
	public function admin_init() {
555
		EE_Registry::$i18n_js_strings[ 'update_att_qstns' ] = __( 'click "Update Registration Questions" to save your changes', 'event_espresso' );
556
	}
557
	public function admin_notices() {}
558
	public function admin_footer_scripts() {}
559
560
561
562
563
564
565
566
567
	/**
568
	 * 		get list of registration statuses
569
	*		@access private
570
	*		@return void
571
	*/
572
	private function _get_registration_status_array() {
573
		self::$_reg_status = EEM_Registration::reg_status_array( array(), TRUE);
574
	}
575
576
577
578
579
	protected function _add_screen_options_default() {
580
		$this->_per_page_screen_option();
581
	}
582
583 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...
584
		$page_title = $this->_admin_page_title;
585
		$this->_admin_page_title = __("Contacts", 'event_espresso');
586
		$this->_per_page_screen_option();
587
		$this->_admin_page_title = $page_title;
588
	}
589
590
591
592
593 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...
594
		//style
595
		//wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION );
596
		wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'), EVENT_ESPRESSO_VERSION );
597
		wp_enqueue_style('espresso_reg');
598
599
		//script
600
		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);
601
		wp_enqueue_script('espresso_reg');
602
	}
603
604
605
606
	public function load_scripts_styles_edit_attendee() {
607
		//stuff to only show up on our attendee edit details page.
608
		$attendee_details_translations = array(
609
			'att_publish_text' => sprintf( __('Created on: <b>%1$s</b>', 'event_espresso'), $this->_cpt_model_obj->get_datetime('ATT_created') )
610
			);
611
		wp_localize_script( 'espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations );
612
		wp_enqueue_script('jquery-validate');
613
	}
614
615
616
	public function load_scripts_styles_view_registration() {
617
		//styles
618
		wp_enqueue_style('espresso-ui-theme');
619
		//scripts
620
		$this->_get_reg_custom_questions_form( $this->_registration->ID() );
621
		$this->_reg_custom_questions_form->wp_enqueue_scripts( true );
622
	}
623
624
625
626
627
628
629
	public function load_scripts_styles_contact_list() {
630
		wp_deregister_style('espresso_reg');
631
		wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'), EVENT_ESPRESSO_VERSION );
632
		wp_enqueue_style('espresso_att');
633
	}
634
635
636
637
638
639
	public function load_scripts_styles_new_registration() {
640
		wp_register_script( 'ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'), EVENT_ESPRESSO_VERSION, TRUE );
641
		wp_enqueue_script('ee-spco-for-admin');
642
		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' );
643
		EE_Form_Section_Proper::wp_enqueue_scripts();
644
		EED_Ticket_Selector::load_tckt_slctr_assets();
645
		EE_Datepicker_Input::enqueue_styles_and_scripts();
646
	}
647
648
649
650
651
652
	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() {
653
		add_filter('FHEE_load_EE_messages', '__return_true');
654
	}
655
656
657
658
	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() {
659
		add_filter('FHEE_load_EE_messages', '__return_true');
660
	}
661
662
663
664
	protected function _set_list_table_views_default() {
665
666
		//for notification related bulk actions we need to make sure only active messengers have an option.
667
		EED_Messages::set_autoloaders();
668
		$EEMSG = EE_Registry::instance()->load_lib('messages');
669
		$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...
670
		//key= bulk_action_slug, value= message type.
671
		$match_array = array(
672
			'approve_registration' => 'registration',
673
			'decline_registration' => 'declined_registration',
674
			'pending_registration' => 'pending_approval',
675
			'no_approve_registration' => 'not_approved_registration',
676
			'cancel_registration' => 'cancelled_registration'
677
			);
678
679
		/** setup reg status bulk actions **/
680
		$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...
681 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' ) ) {
682
			$def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations', 'event_espresso');
683
		}
684
		$def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
685 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' ) ) {
686
			$def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations', 'event_espresso');
687
		}
688
		$def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
689 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' ) ) {
690
			$def_reg_status_actions['pending_and_notify_registration'] = __('Set Registrations to Pending Payment and Notify', 'event_espresso');
691
		}
692
		$def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
693 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' ) ) {
694
			$def_reg_status_actions['no_approve_and_notify_registration'] = __('Set Registrations to Not Approved and Notify', 'event_espresso');
695
		}
696
		$def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
697 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' ) ) {
698
			$def_reg_status_actions['cancel_and_notify_registration'] = __('Cancel Registrations and Notify', 'event_espresso');
699
		}
700
701
		$this->_views = array(
702
			'all' => array(
703
				'slug' => 'all',
704
				'label' => __('View All Registrations', 'event_espresso'),
705
				'count' => 0,
706
				'bulk_action' => array_merge( $def_reg_status_actions, array(
707
					'trash_registrations' => __('Trash Registrations', 'event_espresso')
708
					) )
709
				),
710
			'month' => array(
711
				'slug' => 'month',
712
				'label' => __('This Month', 'event_espresso'),
713
				'count' => 0,
714
				'bulk_action' => array_merge( $def_reg_status_actions, array(
715
					'trash_registrations' => __('Trash Registrations', 'event_espresso')
716
					))
717
				),
718
			'today' => array(
719
				'slug' => 'today',
720
				'label' => sprintf( __('Today - %s', 'event_espresso'), date('M d, Y', current_time('timestamp' ) ) ),
721
				'count' => 0,
722
				'bulk_action' => array_merge( $def_reg_status_actions,  array(
723
					'trash_registrations' => __('Trash Registrations', 'event_espresso')
724
					))
725
				)
726
			);
727
728
		if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_registrations', 'espresso_registrations_delete_registration' ) ) {
729
			$this->_views['incomplete'] = array(
730
				'slug' => 'incomplete',
731
				'label' => __('Incomplete', 'event_espresso'),
732
				'count' => 0,
733
				'bulk_action' => array(
734
					'trash_registrations' => __('Trash Registrations', 'event_espresso')
735
				)
736
			);
737
			$this->_views['trash'] = array(
738
				'slug' => 'trash',
739
				'label' => __('Trash', 'event_espresso'),
740
				'count' => 0,
741
				'bulk_action' => array(
742
					'restore_registrations' => __('Restore Registrations', 'event_espresso'),
743
					'delete_registrations' => __('Delete Registrations Permanently', 'event_espresso')
744
				)
745
			);
746
		}
747
	}
748
749
750
751
752
	protected function _set_list_table_views_contact_list() {
753
		$this->_views = array(
754
			'in_use' => array(
755
				'slug' => 'in_use',
756
				'label' => __('In Use', 'event_espresso'),
757
				'count' => 0,
758
				'bulk_action' => array(
759
					'trash_attendees' => __('Move to Trash', 'event_espresso'),
760
					)
761
				)
762
			);
763
764
		if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_contacts', 'espresso_registrations_trash_attendees' ) ) {
765
			$this->_views['trash'] = array(
766
				'slug' => 'trash',
767
				'label' => __('Trash', 'event_espresso'),
768
				'count' => 0,
769
				'bulk_action' => array(
770
					'restore_attendees' => __('Restore from Trash', 'event_espresso'),
771
				)
772
			);
773
		}
774
	}
775
776
777
778
779
780
	protected function _registration_legend_items() {
781
		$fc_items = array(
782
			'star-icon' => array(
783
				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
784
				'desc' => __('This is the Primary Registrant', 'event_espresso')
785
				),
786
			'view_details' => array(
787
				'class' => 'dashicons dashicons-clipboard',
788
				'desc' => __('View Registration Details', 'event_espresso')
789
				),
790
			'edit_attendee' => array(
791
				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
792
				'desc' => __('Edit Contact Details', 'event_espresso')
793
				),
794
			'view_transaction' => array(
795
				'class' => 'dashicons dashicons-cart',
796
				'desc' => __('View Transaction Details', 'event_espresso')
797
				),
798
			'view_invoice' => array(
799
				'class' => 'dashicons dashicons-media-spreadsheet',
800
				'desc' => __('View Transaction Invoice', 'event_espresso')
801
				),
802
 			);
803
		if ( EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'espresso_registrations_resend_registration' ) ) {
804
			$fc_items['resend_registration'] = array(
805
				'class' => 'dashicons dashicons-email-alt',
806
				'desc' => __('Resend Registration Details', 'event_espresso')
807
				);
808
		} else {
809
			$fc_items['blank'] = array( 'class' => 'blank', 'desc' => '' );
810
		}
811
812
		$sc_items = array(
813
			'approved_status' => array(
814
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
815
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_approved, FALSE, 'sentence' )
816
				),
817
			'pending_status' => array(
818
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
819
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_pending_payment, FALSE, 'sentence' )
820
				),
821
			'incomplete_status' => array(
822
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
823
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_incomplete, FALSE, 'sentence' )
824
			),
825
			'not_approved' => array(
826
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
827
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_not_approved, FALSE, 'sentence' )
828
				),
829
			'declined_status' => array(
830
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
831
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_declined, FALSE, 'sentence' )
832
				),
833
			'cancelled_status' => array(
834
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
835
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_cancelled, FALSE, 'sentence' )
836
				)
837
			);
838
		return array_merge( $fc_items, $sc_items );
839
	}
840
841
842
843
	/***************************************		REGISTRATION OVERVIEW 		***************************************/
844
845
846
847
848
849
850
	protected function _registrations_overview_list_table() {
851
		$EVT_ID = ( ! empty( $this->_req_data['event_id'] )) ? absint( $this->_req_data['event_id'] ) : FALSE;
852
		if ( $EVT_ID ) {
853
			if ( EE_Registry::instance()->CAP->current_user_can( 'ee_edit_registrations', 'espresso_registrations_new_registration', $EVT_ID ) ) {
854
				$this->_admin_page_title .= $this->get_action_link_or_button( 'new_registration', 'add-registrant', array( 'event_id' => $EVT_ID ), 'add-new-h2' );
855
			}
856
			$event = EEM_Event::instance()->get_one_by_ID( $EVT_ID );
857
			$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>' ) : '';
858
		}
859
		$this->_template_args['after_list_table'] = $this->_display_legend( $this->_registration_legend_items() );
860
		$this->display_admin_list_table_page_with_no_sidebar();
861
	}
862
863
864
865
866
	/**
867
	 * This sets the _registration property for the registration details screen
868
	 *
869
	 * @access private
870
	 * @return bool
871
	 */
872
	private function _set_registration_object() {
873
		//get out if we've already set the object
874
		if ( is_object( $this->_registration )) {
875
			return TRUE;
876
		}
877
878
	    $REG = EEM_Registration::instance();
879
880
		$REG_ID = ( ! empty( $this->_req_data['_REG_ID'] )) ? absint( $this->_req_data['_REG_ID'] ) : FALSE;
881
882
		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...
883
			return TRUE;
884
		else {
885
			$error_msg = sprintf( __('An error occurred and the details for Registration ID #%s could not be retrieved.', 'event_espresso'), $REG_ID );
886
			EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ );
887
			$this->_registration = NULL;
888
			return FALSE;
889
		}
890
	}
891
892
893
894
	/**
895
	 * get registrations for given parameters (used by list table)
896
	 *
897
	 * @param  int     $per_page how many registrations displayed per page
898
	 * @param  boolean $count return the count or objects
899
	 * @param  boolean $this_month whether to return for just this month
900
	 * @param  boolean $today whether to return results for just today
901
	 * @throws \EE_Error
902
	 * @internal param bool $all whether to ignore all query params and just return ALL registrations (or count if count is set)
903
	 * @return mixed (int|array)  int = count || array of registration objects
904
	 */
905
	public function get_registrations( $per_page = 10, $count = FALSE, $this_month = FALSE, $today = FALSE ) {
906
907
		$EVT_ID = ! empty( $this->_req_data['event_id'] ) && $this->_req_data['event_id'] > 0 ? absint( $this->_req_data['event_id'] ) : FALSE;
908
		$CAT_ID = ! empty( $this->_req_data['EVT_CAT'] ) && (int) $this->_req_data['EVT_CAT'] > 0? absint( $this->_req_data['EVT_CAT'] ) : FALSE;
909
		$reg_status = ! empty( $this->_req_data['_reg_status'] ) ? sanitize_text_field( $this->_req_data['_reg_status'] ) : FALSE;
910
		$month_range = ! empty( $this->_req_data['month_range'] ) ? sanitize_text_field( $this->_req_data['month_range'] ) : FALSE;//should be like 2013-april
911
		$today_a = ! empty( $this->_req_data['status'] ) && $this->_req_data['status'] == 'today' ? TRUE : FALSE;
912
		$this_month_a = ! empty( $this->_req_data['status'] ) && $this->_req_data['status'] == 'month' ? TRUE  : FALSE;
913
		$start_date = FALSE;
914
		$end_date = FALSE;
915
		$_where = array();
916
		$trash = ! empty( $this->_req_data['status'] ) && $this->_req_data['status'] == 'trash' ? TRUE : FALSE;
917
		$incomplete = ! empty( $this->_req_data['status'] ) && $this->_req_data['status'] == 'incomplete' ? TRUE : FALSE;
918
919
		//set orderby
920
		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
921
922
923
		switch ( $this->_req_data['orderby'] ) {
924
			case '_REG_ID':
925
				$orderby = 'REG_ID';
926
				break;
927
			case '_Reg_status':
928
				$orderby = 'STS_ID';
929
				break;
930
			case 'ATT_fname':
931
				$orderby = 'Attendee.ATT_lname';
932
				break;
933
			case 'event_name':
934
				$orderby = 'Event.EVT_name';
935
				break;
936
			case 'DTT_EVT_start':
937
				$orderby = 'Event.Datetime.DTT_EVT_start';
938
				break;
939
			default: //'REG_date'
940
				$orderby = 'REG_date';
941
		}
942
943
		$sort = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'DESC';
944
		$current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1;
945
		$per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page;
946
947
948
		$offset = ($current_page-1)*$per_page;
949
		$limit = $count  ? NULL : array( $offset, $per_page );
950
951
		if($EVT_ID){
952
			$_where['EVT_ID']=$EVT_ID;
953
		}
954
		if($CAT_ID){
955
			$_where['Event.Term_Taxonomy.term_id'] = $CAT_ID;
956
		}
957
		if ( $incomplete ) {
958
			$_where['STS_ID'] = EEM_Registration::status_id_incomplete;
959
		} else if ( ! $trash) {
960
			$_where['STS_ID'] = array( '!=', EEM_Registration::status_id_incomplete );
961
		}
962
		if($reg_status){
963
			$_where['STS_ID'] = $reg_status;
964
		}
965
966
967
968
		$this_year_r = date('Y', current_time('timestamp'));
969
970
971
		$time_start = ' 00:00:00';
972
		$time_end = ' 23:59:59';
973
974
		if($today_a || $today ){
975
			$curdate = date('Y-m-d', current_time('timestamp'));
976
			$_where['REG_date']= array('BETWEEN',
977
				array(
978
					EEM_Registration::instance()->convert_datetime_for_query( 'REG_date', $curdate . $time_start, 'Y-m-d H:i:s' ),
979
					EEM_Registration::instance()->convert_datetime_for_query( 'REG_date', $curdate . $time_end, 'Y-m-d H:i:s' ),
980
			));
981
		}elseif($this_month_a || $this_month){
982
			$this_month_r = date('m', current_time('timestamp'));
983
			$days_this_month = date( 't', current_time('timestamp') );
984
			$_where['REG_date']= array('BETWEEN',
985
				array(
986
					EEM_Registration::instance()->convert_datetime_for_query( 'REG_date', $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, 'Y-m-d H:i:s' ),
987
					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' )
988
			));
989
		}elseif($month_range){
990
			$pieces = explode(' ', $this->_req_data['month_range'], 3);
991
			$month_r = !empty($pieces[0]) ? date('m', strtotime($pieces[0])) : '';
992
			$year_r = !empty($pieces[1]) ? $pieces[1] : '';
993
			$days_in_month = date('t', strtotime($year_r .  '-' . $month_r . '-' . '01') );
994
			$_where['REG_date']= array('BETWEEN',
995
				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' ) ) );
996
		}elseif($start_date && $end_date){
997
			throw new EE_Error("not yet supported");
998
		}elseif($start_date){
999
			throw new EE_Error("not yet supported");
1000
		}elseif($end_date){
1001
			throw new EE_Error("not yet supported");
1002
		}
1003
1004
		if ( ! empty( $this->_req_data['s'] ) ) {
1005
			$sstr = '%' . $this->_req_data['s'] . '%';
1006
			$_where['OR'] = array(
1007
				'Event.EVT_name' => array( 'LIKE', $sstr),
1008
				'Event.EVT_desc' => array( 'LIKE', $sstr ),
1009
				'Event.EVT_short_desc' => array( 'LIKE' , $sstr ),
1010
				'Attendee.ATT_full_name' => array( 'LIKE', $sstr ),
1011
				'Attendee.ATT_fname' => array( 'LIKE', $sstr ),
1012
				'Attendee.ATT_lname' => array( 'LIKE', $sstr ),
1013
				'Attendee.ATT_short_bio' => array( 'LIKE', $sstr ),
1014
				'Attendee.ATT_email' => array('LIKE', $sstr ),
1015
				'Attendee.ATT_address' => array( 'LIKE', $sstr ),
1016
				'Attendee.ATT_address2' => array( 'LIKE', $sstr ),
1017
				'Attendee.ATT_city' => array( 'LIKE', $sstr ),
1018
				'REG_final_price' => array( 'LIKE', $sstr ),
1019
				'REG_code' => array( 'LIKE', $sstr ),
1020
				'REG_count' => array( 'LIKE' , $sstr ),
1021
				'REG_group_size' => array( 'LIKE' , $sstr ),
1022
				'Ticket.TKT_name' => array( 'LIKE', $sstr ),
1023
				'Ticket.TKT_description' => array( 'LIKE', $sstr ),
1024
				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array( 'LIKE', $sstr )
1025
				);
1026
		}
1027
1028
		//capability checks
1029
		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'get_registrations' ) ) {
1030
			$_where['AND'] = array(
1031
				'Event.EVT_wp_user' => get_current_user_id()
1032
				);
1033
		}
1034
1035
1036
		if( $count ){
1037
			if ( $trash ) {
1038
				return EEM_Registration::instance()->count_deleted( array( $_where ));
1039
			} else if ( $incomplete ) {
1040
				return EEM_Registration::instance()->count( array( $_where ));
1041
			} else {
1042
				return EEM_Registration::instance()->count( array( $_where, 'default_where_conditions' => 'this_model_only' ));
1043
			}
1044
		} else {
1045
			//make sure we remove default where conditions cause all registrations matching query are returned
1046
			$query_params = array( $_where, 'order_by' => array( $orderby => $sort ), 'default_where_conditions' => 'this_model_only' );
1047
			if ( $per_page !== -1 ) {
1048
				$query_params['limit'] = $limit;
1049
			}
1050
			$registrations =  $trash ? EEM_Registration::instance()->get_all_deleted($query_params) : EEM_Registration::instance()->get_all($query_params);
1051
1052
1053
			if ( $EVT_ID && isset( $registrations[0] ) && $registrations[0] instanceof EE_Registration &&  $registrations[0]->event_obj()) {
1054
				$first_registration = $registrations[0];
1055
				//EEH_Debug_Tools::printr( $registrations[0], '$registrations  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
1056
				$event_name = $first_registration->event_obj()->name();
1057
				$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...
1058
				// edit event link
1059 View Code Duplication
				if ( $event_name != '' ) {
1060
					$edit_event_url = self::add_query_args_and_nonce( array( 'action'=>'edit_event', 'EVT_ID'=>$EVT_ID ), EVENTS_ADMIN_URL );
1061
					$edit_event_lnk = '<a href="'.$edit_event_url.'" title="' . esc_attr__( 'Edit ', 'event_espresso' ) . $event_name . '">' . __( 'Edit Event', 'event_espresso' ) . '</a>';
1062
					$event_name .= ' <span class="admin-page-header-edit-lnk not-bold">' . $edit_event_lnk . '</span>' ;
1063
				}
1064
1065
				$back_2_reg_url = self::add_query_args_and_nonce( array( 'action'=>'default' ), REG_ADMIN_URL );
1066
				$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>';
1067
1068
				$this->_template_args['before_admin_page_content'] = '
1069
			<div id="admin-page-header">
1070
				<h1><span class="small-text not-bold">'.__( 'Event: ', 'event_espresso' ).'</span>'. $event_name .'</h1>
1071
				<h3><span class="small-text not-bold">'.__( 'Date: ', 'event_espresso' ). '</span>'. $event_date .'</h3>
1072
				<span class="admin-page-header-go-back-lnk not-bold">' . $back_2_reg_lnk . '</span>
1073
			</div>
1074
			';
1075
1076
			}
1077
			return $registrations;
1078
		}
1079
	}
1080
1081
1082
1083
1084
1085
1086
	public function get_registration_status_array() {
1087
		return self::$_reg_status;
1088
	}
1089
1090
1091
1092
1093
	/***************************************		REGISTRATION DETAILS 		***************************************/
1094
1095
1096
1097
1098
1099
	/**
1100
	 * 		generates HTML for the View Registration Details Admin page
1101
	*		@access protected
1102
	*		@return void
1103
	*/
1104
	protected function _registration_details() {
1105
1106
		$this->_template_args = array();
1107
1108
		$this->_set_registration_object();
1109
1110
		if ( is_object( $this->_registration )) {
1111
			$transaction = $this->_registration->transaction() ? $this->_registration->transaction() : EE_Transaction::new_instance();
1112
			$this->_session = $transaction->session_data();
0 ignored issues
show
Documentation Bug introduced by
It seems like $transaction->session_data() of type array<string,null|array,...ages_visited":"array"}> or boolean is incompatible with the declared type object<EE_Session> of property $_session.

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...
1113
1114
			$event_id = $this->_registration->event_ID();
1115
1116
1117
			$this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1118
			$this->_template_args['reg_nmbr']['label'] = __( 'Registration Number', 'event_espresso' );
1119
1120
			$this->_template_args['reg_datetime']['value'] =  $this->_registration->get_i18n_datetime( 'REG_date' );
1121
			$this->_template_args['reg_datetime']['label'] = __( 'Date', 'event_espresso' );
1122
1123
			$this->_template_args['grand_total'] = $transaction->total();
1124
1125
			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1126
			// link back to overview
1127
			$this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1128
			$this->_template_args['registration'] = $this->_registration;
1129
			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'default', 'event_id' => $event_id ), REG_ADMIN_URL );
1130
			$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' ) );
1131
			$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' ) );
1132
1133
			//next and previous links
1134
			$next_reg = $this->_registration->next(null, array(), 'REG_ID' );
1135
			$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' ) : '';
1136
			$previous_reg = $this->_registration->previous( null, array(), 'REG_ID' );
1137
			$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' ) : '';
1138
1139
			// grab header
1140
			$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1141
			$this->_template_args['admin_page_header'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
1142
1143
		} else {
1144
1145
			$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...
1146
1147
		}
1148
1149
		// the details template wrapper
1150
		$this->display_admin_page_with_sidebar();
1151
1152
	}
1153
1154
1155
1156
1157
1158
1159
	protected function _registration_details_metaboxes() {
1160
		do_action( 'AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this );
1161
		$this->_set_registration_object();
1162
		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1163
		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...
1164
		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...
1165
		if ( $attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'edit-reg-questions-mbox' ) ) {
1166
			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...
1167
		}
1168
		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...
1169
		if ( $this->_registration->group_size() > 1 ) {
1170
			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...
1171
		}
1172
	}
1173
1174
1175
1176
1177
1178
1179
	/**
1180
	 * 		_set_approve_or_decline_reg_status_buttons
1181
	*		@access protected
1182
	*		@return string
1183
	*/
1184
	public function set_reg_status_buttons_metabox() {
1185
1186
		//is registration for free event OR for a completed transaction? This will determine whether the set to pending option is shown.
1187
		$is_complete = $this->_registration->transaction()->is_completed();
1188
1189
		//let's get an array of all possible buttons that we can just reference
1190
		$status_buttons = $this->_get_reg_status_buttons();
1191
		$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...
1192
		$template_args[ 'reg_status_class' ] = 'status-' . $this->_registration->status_ID();
1193
		$template_args['attendee'] = $this->_registration->attendee();
1194
		$template = REG_TEMPLATE_PATH . 'reg_status_change_buttons.template.php';
1195
		if ( $this->_set_registration_object() ) {
1196
			$current_status = $this->_registration->status_ID();
1197
			unset( $status_buttons[$current_status] );
1198
			if ( $current_status != EEM_Registration::status_id_pending_payment && $is_complete ) {
1199
				unset( $status_buttons[EEM_Registration::status_id_pending_payment] );
1200
			}
1201
			$template_args['status_buttons'] = implode( "\n", $status_buttons );
1202
		}
1203
		$template_args['form_url'] = REG_ADMIN_URL;
1204
		$template_args['REG_ID'] = $this->_registration->ID();
1205
		$template_args['nonce'] = wp_nonce_field( 'change_reg_status_nonce',  'change_reg_status_nonce', FALSE, FALSE );
1206
1207
		EEH_Template::display_template( $template, $template_args );
1208
1209
	}
1210
1211
1212
1213
1214
	/**
1215
	 * Returns an array of all the buttons for the various statuses and switch status actions
1216
	 * @return array
1217
	 */
1218
	private function _get_reg_status_buttons() {
1219
1220
		$buttons = array(
1221
			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' ) . '">',
1222
			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' ) . '">',
1223
			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' ) . '">',
1224
			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' ) . '">',
1225
			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' ) . '">',
1226
			);
1227
		return $buttons;
1228
	}
1229
1230
1231
	/**
1232
	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1233
	 *
1234
	 * @param bool $status REG status given for changing registrations to.
1235
	 * @param bool $notify Whether to send messages notifications or not.
1236
	 *
1237
	 * @return array  (array with reg_id(s) updated and whether update was successful.
1238
	 */
1239
	protected function _set_registration_status_from_request( $status = false, $notify = false ) {
1240
		$REG_ID = isset( $this->_req_data['_REG_ID'] ) ? (array) $this->_req_data['_REG_ID'] : array();
1241
1242
		$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...
1243
1244
		//notify?
1245
		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...
1246
			$this->_process_resend_registration();
1247
		}
1248
1249
		return $success;
1250
	}
1251
1252
1253
1254
	/**
1255
	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an array).
1256
	 *
1257
	 * Note, this method does NOT take care of possible notifications.  That is required by calling code.
1258
	 *
1259
	 * @param bool $REG_ID
1260
	 * @param bool $status
1261
	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as the array of updated registrations).
1262
	 */
1263
	protected function _set_registration_status( $REG_ID, $status = false ) {
1264
		$success = true;
1265
		// set default status if none is passed
1266
		$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1267
1268
		//typecast and sanitize reg_id
1269
		$reg_ids = array_filter( (array) $REG_ID, 'absint' );
1270
1271
		//loop through REG_ID's and change status
1272
		foreach ( $reg_ids as $r_id ) {
1273
			$registration = EEM_Registration::instance()->get_one_by_ID( $r_id );
1274
			if ( $registration instanceof EE_Registration ) {
1275
				$registration->set_status( $status );
1276
				$result = $registration->save();
1277
1278
				//verifying explicit fails because update *may* just return 0 for 0 rows affected
1279
				$success = $success !== false && $result !== false;
1280
			}
1281
		}
1282
1283
		//reset _req_data['_REG_ID'] for any potential future messages notifications
1284
		$this->_req_data['_REG_ID'] = $reg_ids;
1285
1286
		//return $success and processed registrations
1287
		return array( 'REG_ID' => $reg_ids, 'success' => $success );
1288
	}
1289
1290
1291
1292
1293
	/**
1294
	 * Common logic for setting up success message and redirecting to appropriate route
1295
	 * @param  string $STS_ID  status id for the registration changed to
1296
	 * @param   bool    $notify indicates whether the _set_registration_status_from_request does notifications or not.
1297
	 * @return void
1298
	 */
1299
	protected function _reg_status_change_return( $STS_ID, $notify = false ) {
1300
1301
		$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...
1302
1303
1304
		$success = isset( $result['success'] ) && $result['success'];
1305
1306
		//setup success message
1307
		if ( $success ) {
1308
			$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' ) ) ;
1309
			EE_Error::add_success( $msg );
1310
		} else {
1311
			EE_Error::add_error( __('Something went wrong, and the status was not changed', 'event_espresso' ), __FILE__, __LINE__, __FUNCTION__ );
1312
		}
1313
1314
		$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' );
1315
		//unset nonces
1316
		foreach ( $this->_req_data as $ref => $value ) {
1317
			if ( strpos( $ref, 'nonce' ) !== false ) {
1318
				unset( $this->_req_data[$ref] );
1319
				continue;
1320
			}
1321
1322
			$value = is_array( $value ) ? array_map( 'urlencode', $value ) : urlencode( $value );
1323
			$this->_req_data[$ref] = $value;
1324
		}
1325
1326
		//merge request vars so that the reloaded list table contains any existing filter query params
1327
		$route = array_merge( $this->_req_data, $route );
1328
1329
		$this->_redirect_after_action( false, '', '', $route, true );
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1330
	}
1331
1332
1333
1334
	/**
1335
	 * incoming reg status change from reg details page.
1336
	 * @return void
1337
	 */
1338
	protected function _change_reg_status() {
1339
		$this->_req_data['return'] = 'view_registration';
1340
		//set notify based on whether the send notifications toggle is set or not
1341
		$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1342
		$this->_req_data[ '_reg_status_id' ] = isset( $this->_req_data[ '_reg_status_id' ] ) ? $this->_req_data[ '_reg_status_id' ] : '';
1343
1344
		switch ( $this->_req_data['_reg_status_id'] ) {
1345
			case EEH_Template::pretty_status( EEM_Registration::status_id_approved, false, 'sentence' ) :
1346
				$this->approve_registration( $notify );
1347
				break;
1348
			case EEH_Template::pretty_status( EEM_Registration::status_id_pending_payment, false, 'sentence' ) :
1349
				$this->pending_registration( $notify );
1350
				break;
1351
			case EEH_Template::pretty_status( EEM_Registration::status_id_not_approved, false, 'sentence' ) :
1352
				$this->not_approve_registration( $notify );
1353
				break;
1354
			case EEH_Template::pretty_status( EEM_Registration::status_id_declined, false, 'sentence' ) :
1355
				$this->decline_registration( $notify );
1356
				break;
1357
			case EEH_Template::pretty_status( EEM_Registration::status_id_cancelled, false, 'sentence' ) :
1358
				$this->cancel_registration( $notify );
1359
				break;
1360
			default :
1361
				$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...
1362
				unset( $this->_req_data['return'] );
1363
				$this->_reg_status_change_return( '', false );
1364
				break;
1365
		}
1366
	}
1367
1368
1369
1370
	/**
1371
	 * 		approve_registration
1372
	*		@access protected
1373
	*		@param bool $notify whether or not to notify the registrant about their approval.
1374
	*		@return void
1375
	*/
1376
	protected function approve_registration( $notify = false ) {
1377
		$this->_reg_status_change_return( EEM_Registration::status_id_approved, $notify );
1378
	}
1379
1380
1381
1382
1383
	/**
1384
	 * 		decline_registration
1385
	*		@access protected
1386
	*		@param bool $notify whether or not to notify the registrant about their approval.
1387
	*		@return void
1388
	*/
1389
	protected function decline_registration( $notify = false ) {
1390
		$this->_reg_status_change_return( EEM_Registration::status_id_declined, $notify );
1391
	}
1392
1393
1394
1395
1396
	/**
1397
	 * 		cancel_registration
1398
	*		@access protected
1399
	*		@param bool $notify whether or not to notify the registrant about their approval.
1400
	*		@return void
1401
	*/
1402
	protected function cancel_registration( $notify = false ) {
1403
		$this->_reg_status_change_return( EEM_Registration::status_id_cancelled, $notify );
1404
	}
1405
1406
1407
1408
1409
1410
	/**
1411
	 * 		not_approve_registration
1412
	*		@access protected
1413
	*		@param bool $notify whether or not to notify the registrant about their approval.
1414
	*		@return void
1415
	*/
1416
	protected function not_approve_registration( $notify = false ) {
1417
		$this->_reg_status_change_return( EEM_Registration::status_id_not_approved, $notify );
1418
	}
1419
1420
1421
1422
	/**
1423
	 * 		decline_registration
1424
	*		@access protected
1425
	*		@param bool $notify whether or not to notify the registrant about their approval.
1426
	*		@return void
1427
	*/
1428
	protected function pending_registration( $notify = false ) {
1429
		$this->_reg_status_change_return( EEM_Registration::status_id_pending_payment, $notify );
1430
	}
1431
1432
1433
1434
1435
	/**
1436
	 * 		generates HTML for the Registration main meta box
1437
	*		@access public
1438
	*		@return void
1439
	*/
1440
	public function _reg_details_meta_box() {
1441
		EEH_Autoloader::register_line_item_display_autoloaders();
1442
		EEH_Autoloader::register_line_item_filter_autoloaders();
1443
		EE_Registry::instance()->load_Helper( 'Line_Item' );
1444
		$transaction = $this->_registration->transaction() ? $this->_registration->transaction() : EE_Transaction::new_instance();
1445
		$this->_session = $transaction->session_data();
0 ignored issues
show
Documentation Bug introduced by
It seems like $transaction->session_data() of type array<string,null|array,...ages_visited":"array"}> or boolean is incompatible with the declared type object<EE_Session> of property $_session.

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...
1446
1447
		$filters = new EE_Line_Item_Filter_Collection();
1448
		$filters->add( new EE_Single_Registration_Line_Item_Filter( $this->_registration ) );
1449
		$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1450
		$line_item_filter_processor = new EE_Line_Item_Filter_Processor( $filters, $transaction->total_line_item() );
1451
		$filtered_line_item_tree = $line_item_filter_processor->process();
1452
1453
		$this->_template_args['REG_ID'] = $this->_registration->ID();
1454
		$line_item_display = new EE_Line_Item_Display( 'reg_admin_table', 'EE_Admin_Table_Registration_Line_Item_Display_Strategy' );
1455
		$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...
1456
1457
1458
		$attendee = $this->_registration->attendee();
1459
1460
1461
		$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' ) : '';
1462
		$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' ) : '';
1463
1464
1465
		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1466
		$payment = $transaction->get_first_related( 'Payment' );
1467
		$payment = ! $payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment;
1468
		$payment_method = $payment->get_first_related( 'Payment_Method' );
1469
		$payment_method = ! $payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance() : $payment_method;
1470
		$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...
1471
		$reg_details = array(
1472
			'payment_method' => $payment_method->name(),
1473
			'response_msg' => $payment->gateway_response(),
1474
			'registration_id' => $this->_registration->get( 'REG_code' ),
1475
			'registration_session' => $this->_registration->session_ID(),
1476
			'ip_address' => isset( $this->_session['ip_address'] ) ? $this->_session['ip_address'] : '',
1477
			'user_agent' => isset( $this->_session['user_agent'] ) ? $this->_session['user_agent'] : '',
1478
			);
1479
1480
1481
		if ( isset( $reg_details['registration_id'] )) {
1482
			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1483
			$this->_template_args['reg_details']['registration_id']['label'] = __( 'Registration ID', 'event_espresso' );
1484
			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
1485
		}
1486
1487
		if ( isset( $reg_details['payment_method'] ) ) {
1488
			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
1489
			$this->_template_args['reg_details']['payment_method']['label'] = __( 'Most Recent Payment Method', 'event_espresso' );
1490
			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
1491
			$this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
1492
			$this->_template_args['reg_details']['response_msg']['label'] = __( 'Payment method response', 'event_espresso' );
1493
			$this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
1494
		}
1495
1496
		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
1497
		$this->_template_args['reg_details']['registration_session']['label'] = __( 'Registration Session', 'event_espresso' );
1498
		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
1499
1500
		$this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
1501
		$this->_template_args['reg_details']['ip_address']['label'] = __( 'Registration placed from IP', 'event_espresso' );
1502
		$this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
1503
1504
		$this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
1505
		$this->_template_args['reg_details']['user_agent']['label'] = __( 'Registrant User Agent', 'event_espresso' );
1506
		$this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
1507
1508
		$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 );
1509
1510
		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
1511
		echo EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
1512
1513
	}
1514
1515
	/**
1516
	 * generates HTML for the Registration Questions meta box.
1517
	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
1518
	 * otherwise uses new forms system
1519
	 *
1520
	 * @access public
1521
	 * @return void
1522
	*/
1523
	public function _reg_questions_meta_box() {
1524
		//allow someone to override this method entirely
1525
		if( apply_filters( 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this, $this->_registration ) ) {
1526
			$form = $this->_get_reg_custom_questions_form( $this->_registration->ID() );
1527
			$this->_template_args[ 'att_questions' ] = count( $form->subforms() ) > 0 ? $form->get_html_and_js() : '';
1528
			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
1529
			$this->_template_args['REG_ID'] = $this->_registration->ID();
1530
1531
			$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
1532
			echo EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
1533
		}
1534
	}
1535
1536
1537
1538
	/**
1539
	 * form_before_question_group
1540
	 *
1541
	 * @deprecated    as of 4.8.32.rc.000
1542
	 * @access        public
1543
	 * @param        string $output
1544
	 * @return        string
1545
	 */
1546 View Code Duplication
	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...
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...
1547
		EE_Error::doing_it_wrong(
1548
			__CLASS__ . '::' . __FUNCTION__,
1549
			__( 'This method would have been protected but was used on a filter callback'
1550
				. 'so needed to be public. Please discontinue usage as it will be removed soon.',
1551
				'event_espresso' ),
1552
			'4.8.32.rc.000'
1553
		);
1554
		return '
1555
	<table class="form-table ee-width-100">
1556
		<tbody>
1557
			';
1558
	}
1559
1560
1561
1562
	/**
1563
	 * form_after_question_group
1564
	 *
1565
	 * @deprecated    as of 4.8.32.rc.000
1566
	 * @access        public
1567
	 * @param        string $output
1568
	 * @return        string
1569
	 */
1570
	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...
1571
		EE_Error::doing_it_wrong(
1572
			__CLASS__ . '::' . __FUNCTION__,
1573
			__( 'This method would have been protected but was used on a filter callback'
1574
				. 'so needed to be public. Please discontinue usage as it will be removed soon.',
1575
				'event_espresso' ),
1576
			'4.8.32.rc.000'
1577
		);
1578
		return  '
1579
			<tr class="hide-if-no-js">
1580
				<th> </th>
1581
				<td class="reg-admin-edit-attendee-question-td">
1582
					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="' . esc_attr__( 'click to edit question', 'event_espresso' ) . '">
1583
						<span class="reg-admin-edit-question-group-spn lt-grey-txt">' . __( 'edit the above question group', 'event_espresso' ) . '</span>
1584
						<div class="dashicons dashicons-edit"></div>
1585
					</a>
1586
				</td>
1587
			</tr>
1588
		</tbody>
1589
	</table>
1590
';
1591
	}
1592
1593
1594
1595
	/**
1596
	 * form_form_field_label_wrap
1597
	 *
1598
	 * @deprecated    as of 4.8.32.rc.000
1599
	 * @access        public
1600
	 * @param        string $label
1601
	 * @return        string
1602
	 */
1603 View Code Duplication
	public function form_form_field_label_wrap( $label ) {
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...
1604
		EE_Error::doing_it_wrong(
1605
			__CLASS__ . '::' . __FUNCTION__,
1606
			__( 'This method would have been protected but was used on a filter callback'
1607
				. 'so needed to be public. Please discontinue usage as it will be removed soon.',
1608
				'event_espresso' ),
1609
			'4.8.32.rc.000'
1610
		);
1611
		return '
1612
			<tr>
1613
				<th>
1614
					' . $label  . '
1615
				</th>';
1616
	}
1617
1618
1619
1620
	/**
1621
	 * form_form_field_input__wrap
1622
	 *
1623
	 * @deprecated    as of 4.8.32.rc.000
1624
	 * @access        public
1625
	 * @param        string $input
1626
	 * @return        string
1627
	 */
1628 View Code Duplication
	public function form_form_field_input__wrap( $input ) {
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...
1629
		EE_Error::doing_it_wrong(
1630
			__CLASS__ . '::' . __FUNCTION__,
1631
			__( 'This method would have been protected but was used on a filter callback'
1632
				. 'so needed to be public. Please discontinue usage as it will be removed soon.',
1633
				'event_espresso' ),
1634
			'4.8.32.rc.000'
1635
		);
1636
		return '
1637
				<td class="reg-admin-attendee-questions-input-td disabled-input">
1638
					' . $input . '
1639
				</td>
1640
			</tr>';
1641
	}
1642
1643
	/**
1644
	 * Updates the registration's custom questions according to the form info, if the form is submitted.
1645
	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
1646
	 * to display the page
1647
	 *
1648
	 * @access protected
1649
	 * @return void
1650
	 */
1651
	protected function _update_attendee_registration_form() {
1652
		do_action( 'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this );
1653
		if( $_SERVER['REQUEST_METHOD'] == 'POST'){
1654
			$REG_ID = isset( $this->_req_data['_REG_ID'] ) ? absint( $this->_req_data['_REG_ID'] ) : FALSE;
1655
			$success = $this->_save_reg_custom_questions_form( $REG_ID );
1656
			if( $success ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $success of type integer|false is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
1657
				$what = __('Registration Form', 'event_espresso');
1658
				$route = $REG_ID ? array( 'action' => 'view_registration', '_REG_ID' => $REG_ID ) : array( 'action' => 'default' );
1659
				$this->_redirect_after_action( $success, $what, __('updated', 'event_espresso'), $route );
1660
			}
1661
		}
1662
	}
1663
1664
	/**
1665
	 * Gets the form for saving registrations custom questions (if done
1666
	 * previously retrieves the cached form object, which may have validation errors in it)
1667
	 * @param int $REG_ID
1668
	 * @return EE_Registration_Custom_Questions_Form
1669
	 */
1670
	protected function _get_reg_custom_questions_form( $REG_ID ) {
1671
		if( ! $this->_reg_custom_questions_form ) {
1672
			require_once( REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php' );
1673
			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( EEM_Registration::instance()->get_one_by_ID( $REG_ID ) );
0 ignored issues
show
Documentation introduced by
\EEM_Registration::insta...>get_one_by_ID($REG_ID) 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...
1674
			$this->_reg_custom_questions_form->_construct_finalize( null, null );
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<EE_Form_Section_Proper>.

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...
1675
		}
1676
		return $this->_reg_custom_questions_form;
1677
	}
1678
1679
1680
1681
	/**
1682
	 * Saves
1683
	 * @access private
1684
	 * @param bool $REG_ID
1685
	 * @return bool
1686
	 */
1687
	private function _save_reg_custom_questions_form( $REG_ID = FALSE ) {
1688
1689
		if ( ! $REG_ID) {
1690
			EE_Error::add_error( __('An error occurred. No registration ID was received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
1691
		}
1692
		$form = $this->_get_reg_custom_questions_form( $REG_ID );
0 ignored issues
show
Documentation introduced by
$REG_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...
1693
		$form->receive_form_submission( $this->_req_data );
1694
		$success = false;
1695
		if( $form->is_valid() ) {
1696
			foreach( $form->subforms() as $question_group_id => $question_group_form ) {
1697
				foreach( $question_group_form->inputs() as $question_id => $input ) {
1698
					$where_conditions = array(
1699
							'QST_ID' => $question_id,
1700
							'REG_ID' => $REG_ID
1701
						);
1702
					$possibly_new_values = array(
1703
							'ANS_value' => $input->normalized_value()
1704
						);
1705
					$answer = EEM_Answer::instance()->get_one( array( $where_conditions ) );
1706
					if( $answer instanceof EE_Answer ) {
1707
						$success = $answer->save( $possibly_new_values );
1708
					} else {
1709
						//insert it then
1710
						$cols_n_vals = array_merge( $where_conditions, $possibly_new_values );
1711
						$answer = EE_Answer::new_instance( $cols_n_vals );
1712
						$success = $answer->save();
1713
					}
1714
				}
1715
			}
1716
		} else {
1717
			EE_Error::add_error( $form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__ );
1718
		}
1719
		return $success;
1720
	}
1721
1722
	/**
1723
	 * 		generates HTML for the Registration main meta box
1724
	*		@access public
1725
	*		@return void
1726
	*/
1727
	public function _reg_attendees_meta_box() {
1728
1729
	    $REG = EEM_Registration::instance();
1730
		//get all other registrations on this transaction, and cache
1731
		//the attendees for them so we don't have to run another query using force_join
1732
		$registrations = $REG->get_all(array(
1733
			array(
1734
				'TXN_ID'=>$this->_registration->transaction_ID(),
1735
				'REG_ID'=>array('!=',$this->_registration->ID())
1736
			),
1737
			'force_join'=>array('Attendee')));
1738
1739
		$this->_template_args['attendees'] = array();
1740
		$this->_template_args['attendee_notice'] = '';
1741
		EE_Registry::instance()->load_helper('Array');
1742
		if ( empty( $registrations)  || ( is_array($registrations) &&  ! EEH_Array::get_one_item_from_array($registrations) ) ) {
1743
			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__ );
1744
			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
1745
		} else {
1746
1747
			$att_nmbr = 1;
1748
			foreach ( $registrations as $registration ) {
1749
				/* @var $registration EE_Registration */
1750
				$attendee = $registration->attendee() ? $registration->attendee() : EEM_Attendee::instance()->create_default_object();
1751
				$this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : '';
1752
				$this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : '';
1753
				$this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : '';
1754
				$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 : '';
1755
1756
				$this->_template_args['attendees'][ $att_nmbr ]['address'] = implode( ', ', $attendee->full_address_as_array() );
1757
1758
				$this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce( array( 'action'=>'edit_attendee', 'post'=>$attendee->ID() ), REG_ADMIN_URL );
1759
1760
				$att_nmbr++;
1761
			}
1762
1763
			//EEH_Debug_Tools::printr( $attendees, '$attendees  <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' );
1764
1765
			$this->_template_args['event_name'] = $this->_registration->event_obj()->name();
1766
			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1767
1768
	//			$this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees'  ), REG_ADMIN_URL );
1769
		}
1770
		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
1771
		echo EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
1772
1773
	}
1774
1775
1776
1777
1778
1779
1780
	/**
1781
	 * 		generates HTML for the Edit Registration side meta box
1782
	*		@access public
1783
	*		@return void
1784
	*/
1785
	public function _reg_registrant_side_meta_box() {
1786
1787
		/*@var $attendee EE_Attendee */
1788
		$att_check = $this->_registration->attendee();
1789
		$attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
1790
1791
		//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)
1792
		if ( ! $this->_registration->is_primary_registrant() ) {
1793
			$primary_registration = $this->_registration->get_primary_registration();
1794
			$primary_attendee = $primary_registration->attendee();
1795
1796
			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID() ) {
1797
				//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.
1798
				$primary_registration = NULL;
1799
			}
1800
		} else {
1801
			$primary_registration = NULL;
1802
		}
1803
1804
		$this->_template_args['ATT_ID'] = $attendee->ID();
1805
		$this->_template_args['fname'] = $attendee->fname();//$this->_registration->ATT_fname;
1806
		$this->_template_args['lname'] = $attendee->lname();//$this->_registration->ATT_lname;
1807
		$this->_template_args['email'] = $attendee->email();//$this->_registration->ATT_email;
1808
		$this->_template_args['phone'] = $attendee->phone();
1809
1810
		EE_Registry::instance()->load_helper( 'Formatter' );
1811
		$this->_template_args[ 'formatted_address' ] = EEH_Address::format( $attendee );
1812
1813
1814
		//edit link
1815
		$this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce( array( 'action'=>'edit_attendee', 'post'=>$attendee->ID() ), REG_ADMIN_URL );
1816
		$this->_template_args['att_edit_label'] = __('View/Edit Contact' );
1817
1818
		//create link
1819
		$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 ): '';
1820
		$this->_template_args['create_label'] = __('Create Contact', 'event_espresso');
1821
1822
		$this->_template_args['att_check'] = $att_check;
1823
1824
1825
		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
1826
		echo EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
1827
	}
1828
1829
1830
1831
1832
1833
	/**
1834
	 * trash or restore registrations
1835
	 * @param  boolean $trash whether to archive or restore
1836
	 * @access protected
1837
	 * @return void
1838
	 */
1839
	protected function _trash_or_restore_registrations( $trash = TRUE ) {
1840
		$REGM = EEM_Registration::instance();
1841
1842
		$success = 1;
1843
		$error = 0;
1844
1845
		$tickets = array();
1846
		$dtts = array();
1847
1848
		//if empty _REG_ID then get out because there's nothing to do
1849 View Code Duplication
		if ( empty( $this->_req_data['_REG_ID'] ) ) {
1850
			$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');
1851
			EE_Error::add_error( $msg, __FILE__, __LINE__, __FUNCTION__ );
1852
			$this->_redirect_after_action(FALSE, '', '', array(), TRUE );
0 ignored issues
show
Documentation introduced by
FALSE is of type boolean, but the function expects a integer.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1853
		}
1854
1855
		//Checkboxes
1856
		if (!empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
1857
			// if array has more than one element than success message should be plural
1858
			$success = count( $this->_req_data['_REG_ID'] ) > 1 ? 2 : 1;
1859
			// cycle thru checkboxes
1860
			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...
1861
1862
				$REG = $REGM->get_one_by_ID($REG_ID);
1863
				$payment_count = $REG->get_first_related('Transaction')->count_related('Payment');
1864
				if ( $payment_count > 0 ) {
1865
					$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...
1866
					$error = 1;
1867
					$success = 0;
1868
					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__ );
1869
					continue; //can't trash this registration because it has payments.
1870
				}
1871
				$ticket = $REG->get_first_related('Ticket');
1872
				$tickets[$ticket->ID()] = $ticket;
1873
				$dtt = $ticket->get_many_related('Datetime');
1874
				$dtts = array_merge($dtts, $dtt);
1875
1876
				$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...
1877
				if ( !$updated ) {
1878
					$success = 0;
1879
				} else {
1880
					$success = 2;
1881
				}/**/
1882
			}
1883
1884
		} else {
1885
			// grab single id and delete
1886
			$REG_ID = absint($this->_req_data['_REG_ID']);
1887
			$REG = $REGM->get_one_by_ID($REG_ID);
1888
			$ticket = $REG->get_first_related('Ticket');
1889
			$tickets[$ticket->ID()] = $ticket;
1890
			$dtts = $ticket->get_many_related('Datetime');
1891
			$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...
1892
			if ( ! $updated ) {
1893
				$success = 0;
1894
			}
1895
1896
		}
1897
1898
		//now let's update counts
1899
		EEM_Ticket::instance()->update_tickets_sold($tickets);
1900
		EEM_Datetime::instance()->update_sold($dtts);
1901
1902
		$what = $success > 1 ? __( 'Registrations', 'event_espresso' ) : __( 'Registration', 'event_espresso' );
1903
		$action_desc = $trash ? __( 'moved to the trash', 'event_espresso' ) : __( 'restored', 'event_espresso' );
1904
		$overwrite_msgs = $error ? TRUE : FALSE;
1905
		$this->_redirect_after_action( $success, $what, $action_desc, array( 'action' => 'default' ), $overwrite_msgs );
1906
	}
1907
1908
1909
1910
1911
1912
	/**
1913
	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the registration but also.
1914
	 *
1915
	 * 1. Removing relations to EE_Attendee
1916
	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are ALSO trashed.
1917
	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
1918
	 * 4. Removing relationships between all tickets and the related registrations
1919
	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
1920
	 * 6. Deleting permanently any related Checkins.
1921
	 * @return void
1922
	 */
1923
	protected function _delete_registrations() {
1924
		$REG_MDL = EEM_Registration::instance();
1925
1926
		$success = 1;
1927
1928
		//Checkboxes
1929
		if (!empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
1930
			// if array has more than one element than success message should be plural
1931
			$success = count( $this->_req_data['_REG_ID'] ) > 1 ? 2 : 1;
1932
			// cycle thru checkboxes
1933
			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...
1934
				$REG = $REG_MDL->get_one_by_ID($REG_ID);
1935
				if ( ! $REG instanceof EE_Registration )
1936
					continue;
1937
				$deleted = $this->_delete_registration($REG);
1938
				if ( !$deleted ) {
1939
					$success = 0;
1940
				}
1941
			}
1942
1943
		} else {
1944
			// grab single id and delete
1945
			$REG_ID = $this->_req_data['_REG_ID'];
1946
			$REG = $REG_MDL->get_one_by_ID($REG_ID);
1947
			$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...
1948
			if ( ! $deleted ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $deleted of type false|integer is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
1949
				$success = 0;
1950
			}
1951
1952
		}
1953
1954
		$what = $success > 1 ? __( 'Registrations', 'event_espresso' ) : __( 'Registration', 'event_espresso' );
1955
		$action_desc = __( 'permanently deleted.', 'event_espresso' );
1956
		$this->_redirect_after_action( $success, $what, $action_desc, array( 'action' => 'default' ), TRUE );
1957
	}
1958
1959
1960
1961
1962
1963
	/**
1964
	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what models get affected.
1965
	 * @param  EE_Registration $REG registration to be deleted permenantly
1966
	 * @return boolean              true = successful deletion, false = fail.
1967
	 */
1968
	protected function _delete_registration( EE_Registration $REG ) {
1969
		//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.
1970
		$TXN = $REG->get_first_related('Transaction');
1971
		$REGS = $TXN->get_many_related('Registration');
1972
1973
		$all_trashed = TRUE;
1974
		foreach ( $REGS as $registration ) {
1975
			if ( ! $registration->get('REG_deleted') )
1976
				$all_trashed = FALSE;
1977
		}
1978
1979
		if ( ! $all_trashed ) {
1980
			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__ );
1981
			return false;
1982
		}
1983
1984
		//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).
1985
		foreach ( $REGS as $registration ) {
1986
1987
			//delete related answers
1988
			$registration->delete_related_permanently('Answer');
1989
1990
			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
1991
			$attendee = $registration->get_first_related('Attendee');
1992
			if ( $attendee instanceof EE_Attendee ) {
1993
				$registration->_remove_relation_to($attendee, 'Attendee');
1994
			}
1995
1996
			//now remove relationships to tickets on this registration.
1997
			$registration->_remove_relations('Ticket');
1998
1999
			//now delete permanently the checkins related to this registration.
2000
			$registration->delete_related_permanently('Checkin');
2001
2002
			if ( $registration->ID() === $REG->ID() )
2003
				continue; //we don't want to delete permanently the existing registration just yet.
2004
2005
			//remove relation to transaction for these registrations if NOT the existing registrations
2006
			$registration->_remove_relations('Transaction');
2007
2008
			//now delete this registration permanently
2009
			$registration->delete_permanently();
2010
		}
2011
2012
		//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).
2013
		//delete the line items related to the transaction for this registration.
2014
		$TXN->delete_related_permanently('Line_Item');
2015
2016
		//we need to remove all the relationships on the transaction
2017
		$TXN->delete_related_permanently('Payment');
2018
		$TXN->delete_related_permanently('Extra_Meta');
2019
2020
		//now we can delete this REG permanently (and the transaction of course)
2021
		$REG->delete_related_permanently('Transaction');
2022
		return $REG->delete_permanently();
2023
	}
2024
2025
2026
2027
	/**
2028
	 * 	generates HTML for the Register New Attendee Admin page
2029
	 *
2030
	 * @access private
2031
	 * @throws \EE_Error
2032
	 * @return void
2033
	 */
2034
	public function new_registration() {
2035
		if ( ! $this->_set_reg_event() ) {
2036
			throw new EE_Error(__('Unable to continue with registering because there is no Event ID in the request', 'event_espresso') );
2037
		}
2038
		EE_Registry::instance()->REQ->set_espresso_page( TRUE );
2039
		// gotta start with a clean slate if we're not coming here via ajax
2040
		if (
2041
			! defined('DOING_AJAX' )
2042
			&& ( ! isset( $this->_req_data['processing_registration'] ) || isset( $this->_req_data['step_error'] ) )
2043
		) {
2044
			EE_Registry::instance()->SSN->clear_session( __CLASS__, __FUNCTION__ );
2045
		}
2046
2047
		$this->_template_args['event_name'] = '' ;
2048
		// event name
2049
		if ( $this->_reg_event ) {
2050
			$this->_template_args['event_name'] = $this->_reg_event->name();
2051
			$edit_event_url = self::add_query_args_and_nonce( array( 'action'=>'edit', 'post'=>$this->_reg_event->ID() ), EVENTS_ADMIN_URL );
2052
			$edit_event_lnk = '<a href="'.$edit_event_url.'" title="' . esc_attr__( 'Edit ', 'event_espresso' ) . $this->_reg_event->name() . '">' . __( 'Edit Event', 'event_espresso' ) . '</a>';
2053
			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' . $edit_event_lnk . '</span>' ;
2054
		}
2055
2056
		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2057
2058
		if ( defined('DOING_AJAX' ) ) {
2059
			$this->_return_json();
2060
		}
2061
		// grab header
2062
		$template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2063
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE );
2064
2065
		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2066
		// the details template wrapper
2067
		$this->display_admin_page_with_sidebar();
2068
	}
2069
2070
2071
2072
2073
	/**
2074
	 * This returns the content for a registration step
2075
	 *
2076
	 * @access protected
2077
	 * @return string html
2078
	 */
2079
	protected function _get_registration_step_content() {
2080
		if ( isset( $_COOKIE[ 'ee_registration_added' ] ) && $_COOKIE[ 'ee_registration_added' ] ) {
2081
			$warning_msg = sprintf(
2082
				__(
2083
					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2084
					'event_espresso'
2085
				),
2086
				'<br />',
2087
				'<h3 class="important-notice">',
2088
				'</h3>',
2089
				'<div class="float-right">',
2090
				'<span id="redirect_timer" class="important-notice">30</span>',
2091
				'</div>',
2092
				'<b>',
2093
				'</b>'
2094
			);
2095
			return '
2096
	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2097
	<script >
2098
		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2099
		// after just adding a new registration... we gotta try to put a stop to that !!!
2100
		var timer = 30;
2101
		setInterval( function () {
2102
			jQuery("#redirect_timer").html( parseInt( timer ) );
2103
	        if ( --timer < 0 ) {
2104
	            window.history.forward()
2105
	        }
2106
	    }, 800 );
2107
	</script >';
2108
		}
2109
		$template_args = array(
2110
			'title'                    => '',
2111
			'content'                  => '',
2112
			'step_button_text'         => '',
2113
			'show_notification_toggle' => false
2114
		);
2115
		//to indicate we're processing a new registration
2116
		$hidden_fields = array(
2117
			'processing_registration' => array(
2118
				'type' => 'hidden',
2119
				'value' => 0
2120
			),
2121
			'event_id' => array(
2122
				'type' => 'hidden',
2123
				'value' => $this->_reg_event->ID()
2124
			)
2125
		);
2126
2127
		//if the cart is empty then we know we're at step one so we'll display ticket selector
2128
		$cart = EE_Registry::instance()->SSN->cart();
2129
		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2130
2131
		switch ( $step ) {
2132
			case 'ticket' :
2133
				$hidden_fields['processing_registration']['value'] = 1;
2134
				$template_args['title'] = __('Step One: Select the Ticket for this registration', 'event_espresso');
2135
				$template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector( $this->_reg_event );
2136
				$template_args['step_button_text'] = __('Add Tickets and Continue to Registrant Details', 'event_espresso');
2137
				$template_args['show_notification_toggle'] = FALSE;
2138
				break;
2139
			case 'questions' :
2140
				$hidden_fields[ 'processing_registration' ][ 'value' ] = 2;
2141
				$template_args['title'] = __('Step Two: Add Registrant Details for this Registration', 'event_espresso');
2142
				//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.
2143
				$template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin();
2144
				$template_args['step_button_text'] = __('Save Registration and Continue to Details', 'event_espresso');
2145
				$template_args['show_notification_toggle'] = TRUE;
2146
				break;
2147
		}
2148
2149
		$this->_set_add_edit_form_tags( 'process_reg_step', $hidden_fields ); //we come back to the process_registration_step route.
2150
2151
		return EEH_Template::display_template(
2152
			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php', $template_args, TRUE
2153
		);
2154
	}
2155
2156
2157
2158
2159
2160
2161
	/**
2162
	 * 		set_reg_event
2163
	*		@access private
2164
	*		@return boolean
2165
	*/
2166
	private function _set_reg_event() {
2167
		if ( is_object( $this->_reg_event )) {
2168
			return TRUE;
2169
		}
2170
		$EVT_ID = ( ! empty( $this->_req_data['event_id'] )) ? absint( $this->_req_data['event_id'] ) : FALSE;
2171
		if ( ! $EVT_ID ) {
2172
			return FALSE;
2173
		}
2174
2175
		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
0 ignored issues
show
Documentation Bug introduced by
It seems like \EEM_Event::instance()->get_one_by_ID($EVT_ID) can also be of type object<EE_Base_Class>. However, the property $_reg_event is declared as type object<EE_Event>. 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...
2176
		return TRUE;
2177
	}
2178
2179
2180
2181
2182
2183
	/**
2184
	 * 		process_reg_step
2185
	 *
2186
	 * 		@access 		public
2187
	 * 		@return 		string
2188
	 */
2189
	public function process_reg_step() {
2190
		EE_System::do_not_cache();
2191
		$this->_set_reg_event();
2192
		EE_Registry::instance()->REQ->set_espresso_page( TRUE );
2193
2194
		//what step are we on?
2195
		$cart = EE_Registry::instance()->SSN->cart();
2196
		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2197
2198
		//if doing ajax then we need to verify the nonce
2199 View Code Duplication
		if ( defined( 'DOING_AJAX' ) ) {
2200
			$nonce = isset( $this->_req_data[$this->_req_nonce] ) ? sanitize_text_field( $this->_req_data[$this->_req_nonce] ) : '';
2201
			$this->_verify_nonce( $nonce, $this->_req_nonce );
2202
		}
2203
2204
		switch ( $step ) {
2205
2206
			case 'ticket' :
2207
				//process ticket selection
2208
				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2209
				if ( $success ) {
2210
					EE_Error::add_success( __('Tickets Selected. Now complete the registration.'), 'event_espresso');
2211
				} else {
2212
					$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...
2213
				}
2214
				if ( defined('DOING_AJAX') ) {
2215
					$this->new_registration(); //display next step
2216
				} else {
2217
					$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...
2218
					$query_args['processing_registration'] = 1;
2219
					$query_args['event_id'] = $this->_reg_event->ID();
2220
					$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
0 ignored issues
show
Documentation introduced by
FALSE is of type boolean, but the function expects a integer.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2221
				}
2222
				break;
2223
2224
			case 'questions' :
2225
				if( ! isset( $this->_req_data[ 'txn_reg_status_change' ], $this->_req_data[ 'txn_reg_status_change' ][ 'send_notifications' ] ) ) {
2226
					add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15 );
2227
				}
2228
				//process registration
2229
				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2230
				if ( $cart instanceof EE_Cart ) {
2231
					$grand_total = $cart->get_cart_grand_total();
2232
					if ( $grand_total instanceof EE_Line_Item ) {
2233
						$grand_total->save_this_and_descendants_to_txn();
2234
					}
2235
				}
2236
				if ( ! $transaction instanceof EE_Transaction ) {
2237
					$query_args = array(
2238
						'action' => 'new_registration',
2239
						'processing_registration' => 2,
2240
						'event_id' => $this->_reg_event->ID()
2241
					);
2242
2243 View Code Duplication
					if ( defined('DOING_AJAX' )) {
2244
						//display registration form again because there are errors (maybe validation?)
2245
						$this->new_registration();
2246
						return;
2247
					} else {
2248
						$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
0 ignored issues
show
Documentation introduced by
FALSE is of type boolean, but the function expects a integer.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2249
						return;
2250
					}
2251
				}
2252
				/** @type EE_Transaction_Payments $transaction_payments */
2253
				$transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' );
2254
				// maybe update status, and make sure to save transaction if not done already
2255
				if ( ! $transaction_payments->update_transaction_status_based_on_total_paid( $transaction )) {
2256
					$transaction->save();
2257
				}
2258
				EE_Registry::instance()->SSN->clear_session( __CLASS__, __FUNCTION__ );
2259
				$this->_req_data = array();
2260
				$query_args = array(
2261
					'action'        => 'redirect_to_txn',
2262
					'TXN_ID'        => $transaction->ID(),
2263
					'EVT_ID'        => $this->_reg_event->ID(),
2264
					'event_name'    => urlencode( $this->_reg_event->name() ),
2265
					'redirect_from' => 'new_registration'
2266
				);
2267
				$this->_redirect_after_action( false, '', '', $query_args, true );
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2268
				break;
2269
		}
2270
2271
		//what are you looking here for?  Should be nothing to do at this point.
2272
	}
2273
2274
2275
2276
	/**
2277
	 * redirect_to_txn
2278
	 *
2279
	 * @access public
2280
	 * @return void
2281
	 */
2282
	public function redirect_to_txn() {
2283
		EE_System::do_not_cache();
2284
		EE_Registry::instance()->SSN->clear_session( __CLASS__, __FUNCTION__ );
2285
		$query_args = array(
2286
			'action' => 'view_transaction',
2287
			'TXN_ID' => isset( $this->_req_data['TXN_ID'] ) ? absint( $this->_req_data[ 'TXN_ID' ] )  : 0,
2288
			'page'   => 'espresso_transactions'
2289
		);
2290
		if ( isset( $this->_req_data[ 'EVT_ID' ], $this->_req_data[ 'redirect_from' ] ) ) {
2291
			$query_args['EVT_ID'] = $this->_req_data[ 'EVT_ID' ];
2292
			$query_args['event_name'] = urlencode( $this->_req_data[ 'event_name' ] );
2293
			$query_args['redirect_from'] = $this->_req_data[ 'redirect_from' ];
2294
		}
2295
		EE_Error::add_success(
2296
			__( 'Registration Created.  Please review the transaction and add any payments as necessary', 'event_espresso' )
2297
		);
2298
		$this->_redirect_after_action( false, '', '', $query_args, true );
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2299
	}
2300
2301
2302
2303
	/**
2304
	 * 		generates HTML for the Attendee Contact List
2305
	*		@access protected
2306
	*		@return void
2307
	*/
2308
	protected function _attendee_contact_list_table() {
2309
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
2310
		$this->_search_btn_label = __('Contacts', 'event_espresso');
2311
		$this->display_admin_list_table_page_with_no_sidebar();
2312
	}
2313
2314
2315
2316
2317
2318
	/**
2319
	 * 		get_attendees
2320
	 * 		@param bool $count whether to return count or data.
2321
	*		@access public
2322
	*		@return array
2323
	*/
2324
	public function get_attendees( $per_page, $count = FALSE, $trash = FALSE ) {
2325
2326
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
2327
		require_once( REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php' );
2328
		$ATT_MDL = EEM_Attendee::instance();
2329
2330
		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2331
2332
		switch ($this->_req_data['orderby']) {
2333
			case 'ATT_ID':
2334
				$orderby = 'ATT_ID';
2335
				break;
2336
			case 'ATT_fname':
2337
				$orderby = 'ATT_fname';
2338
				break;
2339
			case 'ATT_email':
2340
				$orderby = 'ATT_email';
2341
				break;
2342
			case 'ATT_city':
2343
				$orderby = 'ATT_city';
2344
				break;
2345
			case 'STA_ID':
2346
				$orderby = 'STA_ID';
2347
				break;
2348
			case 'CNT_ID':
2349
				$orderby = 'CNT_ID';
2350
				break;
2351
			default:
2352
				$orderby = 'ATT_lname';
2353
		}
2354
2355
		$sort = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'ASC';
2356
2357
		$current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1;
2358
		$per_page = isset( $per_page ) && !empty( $per_page ) ? $per_page : 10;
2359
		$per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page;
2360
2361
		$_where = array();
2362
2363
		if ( isset( $this->_req_data['s'] ) ) {
2364
			$sstr = '%' . $this->_req_data['s'] . '%';
2365
			$_where['OR'] = array(
2366
				'Registration.Event.EVT_name' => array( 'LIKE', $sstr),
2367
				'Registration.Event.EVT_desc' => array( 'LIKE', $sstr ),
2368
				'Registration.Event.EVT_short_desc' => array( 'LIKE' , $sstr ),
2369
				'ATT_fname' => array( 'LIKE', $sstr ),
2370
				'ATT_lname' => array( 'LIKE', $sstr ),
2371
				'ATT_short_bio' => array( 'LIKE', $sstr ),
2372
				'ATT_email' => array('LIKE', $sstr ),
2373
				'ATT_address' => array( 'LIKE', $sstr ),
2374
				'ATT_address2' => array( 'LIKE', $sstr ),
2375
				'ATT_city' => array( 'LIKE', $sstr ),
2376
				'Country.CNT_name' => array( 'LIKE', $sstr ),
2377
				'State.STA_name' => array('LIKE', $sstr ),
2378
				'ATT_phone' => array( 'LIKE', $sstr ),
2379
				'Registration.REG_final_price' => array( 'LIKE', $sstr ),
2380
				'Registration.REG_code' => array( 'LIKE', $sstr ),
2381
				'Registration.REG_count' => array( 'LIKE' , $sstr ),
2382
				'Registration.REG_group_size' => array( 'LIKE' , $sstr )
2383
				);
2384
		}
2385
2386
2387
		$offset = ($current_page-1)*$per_page;
2388
		$limit = $count ? NULL : array( $offset, $per_page );
2389
2390
		if ( $trash ) {
2391
			$_where['status'] = array( '!=', 'publish' );
2392
			$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));
2393
		} else {
2394
			$_where['status'] = array( 'IN', array( 'publish' ) );
2395
			$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) );
2396
		}
2397
2398
		return $all_attendees;
2399
	}
2400
2401
2402
2403
2404
	/**
2405
	 * This is just taking care of resending the registration confirmation
2406
	 *
2407
	 * @access protected
2408
	 * @return void
2409
	 */
2410
	protected function _resend_registration() {
2411
		$this->_process_resend_registration();
2412
		$query_args = isset($this->_req_data['redirect_to'] ) ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'] ) : array(
2413
			'action' => 'default'
2414
		);
2415
		$this->_redirect_after_action(FALSE, '', '', $query_args, TRUE );
0 ignored issues
show
Documentation introduced by
FALSE is of type boolean, but the function expects a integer.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2416
	}
2417
2418
2419
2420
2421
2422
2423
	public function _registrations_report(){
2424
		if( ! defined( 'EE_USE_OLD_CSV_REPORT_CLASS' ) ) {
2425
			wp_redirect( EE_Admin_Page::add_query_args_and_nonce(
2426
				array(
2427
					'page' => 'espresso_batch',
2428
					'batch' => 'file',
2429
					'EVT_ID' => isset( $this->_req_data[ 'EVT_ID'] ) ? $this->_req_data[ 'EVT_ID' ] : NULL,
2430
					'job_handler' => urlencode( 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' ),
2431
					'return_url' => urlencode( $this->_req_data[ 'return_url' ] ),
2432
				)) );
2433
		} else {
2434
			EE_Registry::instance()->load_helper( 'File' );
2435
			$new_request_args = array(
2436
				'export' => 'report',
2437
				'action' => 'registrations_report_for_event',
2438
				'EVT_ID' => isset( $this->_req_data[ 'EVT_ID'] ) ? $this->_req_data[ 'EVT_ID' ] : NULL,
2439
			);
2440
			$this->_req_data = array_merge($this->_req_data, $new_request_args);
2441
2442
			if ( is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2443
				require_once(EE_CLASSES . 'EE_Export.class.php');
2444
				$EE_Export = EE_Export::instance($this->_req_data);
2445
				$EE_Export->export();
2446
			}
2447
		}
2448
	}
2449
2450
2451
2452
	public function _contact_list_export(){
2453
		EE_Registry::instance()->load_helper( 'File' );
2454
		if ( is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2455
			require_once(EE_CLASSES . 'EE_Export.class.php');
2456
			$EE_Export = EE_Export::instance($this->_req_data);
2457
			$EE_Export->export_attendees();
2458
		}
2459
	}
2460
2461
	public function _contact_list_report(){
2462
		if( ! defined( 'EE_USE_OLD_CSV_REPORT_CLASS' ) ) {
2463
			wp_redirect( EE_Admin_Page::add_query_args_and_nonce(
2464
				array(
2465
					'page' => 'espresso_batch',
2466
					'batch' => 'file',
2467
					'job_handler' => urlencode( 'EventEspressoBatchRequest\JobHandlers\AttendeesReport' ),
2468
					'return_url' => urlencode( $this->_req_data[ 'return_url' ] ),
2469
				)) );
2470
		} else {
2471
			EE_Registry::instance()->load_helper( 'File' );
2472
			if ( is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2473
				require_once(EE_CLASSES . 'EE_Export.class.php');
2474
				$EE_Export = EE_Export::instance($this->_req_data);
2475
				$EE_Export->report_attendees();
2476
			}
2477
		}
2478
	}
2479
2480
2481
2482
2483
2484
2485
	/***************************************		ATTENDEE DETAILS 		***************************************/
2486
2487
2488
	/**
2489
	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
2490
	 * @return void
2491
	 */
2492
	protected function _duplicate_attendee() {
2493
		$action = !empty( $this->_req_data['return'] ) ? $this->_req_data['return'] : 'default';
2494
		//verify we have necessary info
2495 View Code Duplication
		if ( empty($this->_req_data['_REG_ID'] )  ) {
2496
			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__ );
2497
			$query_args = array( 'action' => $action );
2498
			$this->_redirect_after_action('', '', '', $query_args, TRUE);
2499
		}
2500
2501
		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
2502
		$registration = EEM_Registration::instance()->get_one_by_ID( $this->_req_data['_REG_ID'] );
2503
		$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...
2504
2505
		//remove relation of existing attendee on registration
2506
		$registration->_remove_relation_to($attendee, 'Attendee' );
2507
		//new attendee
2508
		$new_attendee = clone $attendee;
2509
		$new_attendee->set( 'ATT_ID', 0 );
2510
		$new_attendee->save();
2511
2512
		//add new attendee to reg
2513
		$registration->_add_relation_to( $new_attendee, 'Attendee');
2514
2515
		EE_Error::add_success( __('New Contact record created.  Now make any edits you wish to make for this contact.', 'event_espresso') );
2516
2517
		//redirect to edit page for attendee
2518
		$query_args = array( 'post' => $new_attendee->ID(), 'action' => 'edit_attendee' );
2519
2520
		$this->_redirect_after_action( '', '', '', $query_args, TRUE );
2521
	}
2522
2523
2524
	//related to cpt routes
2525
	protected function _insert_update_cpt_item($post_id, $post) {
2526
		$success = true;
2527
		$attendee = EEM_Attendee::instance()->get_one_by_ID( $post_id );
2528
		//for attendee updates
2529
		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...
2530
			//note we should only be UPDATING attendees at this point.
2531
			$updated_fields = array(
2532
				'ATT_fname' => $this->_req_data['ATT_fname'],
2533
				'ATT_lname' => $this->_req_data['ATT_lname'],
2534
				'ATT_full_name'=> $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
2535
				'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
2536
				'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
2537
				'ATT_city' => isset( $this->_req_data['ATT_city'] ) ? $this->_req_data['ATT_city'] : '',
2538
				'STA_ID' => isset( $this->_req_data['STA_ID'] ) ? $this->_req_data['STA_ID'] : '',
2539
				'CNT_ISO' => isset( $this->_req_data['CNT_ISO'] ) ? $this->_req_data['CNT_ISO'] : '',
2540
				'ATT_zip' => isset( $this->_req_data['ATT_zip'] ) ? $this->_req_data['ATT_zip'] : '',
2541
				'ATT_email' => isset( $this->_req_data['ATT_email'] ) ? $this->_req_data['ATT_email'] : '',
2542
				'ATT_phone' => isset( $this->_req_data['ATT_phone'] ) ? $this->_req_data['ATT_phone'] : ''
2543
				);
2544
			foreach ( $updated_fields as $field => $value ) {
2545
				$attendee->set($field, $value);
2546
			}
2547
2548
			$success = $attendee->save();
2549
2550
			$attendee_update_callbacks = apply_filters( 'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', array() );
2551
			foreach ( $attendee_update_callbacks as $a_callback ) {
2552
				if ( FALSE === call_user_func_array( $a_callback, array($attendee, $this->_req_data ) ) ) {
2553
					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 ) );
2554
				}
2555
			}
2556
		}
2557
2558
		if ( $success === FALSE )
2559
			EE_Error::add_error(__('Something went wrong with updating the meta table data for the registration.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
2560
2561
	}
2562
2563
2564
2565
2566
	public function trash_cpt_item($post_id) {}
2567
	public function delete_cpt_item($post_id) {}
2568
	public function restore_cpt_item($post_id) {}
2569
	protected function _restore_cpt_item($post_id, $revision_id) {}
2570
2571
2572
	public function attendee_editor_metaboxes() {
2573
2574
		$this->verify_cpt_object();
2575
2576
		remove_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2577
		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2578
2579 View Code Duplication
		if ( post_type_supports( 'espresso_attendees', 'excerpt') ) {
2580
			add_meta_box('postexcerpt', __('Short Biography', 'event_espresso'), 'post_excerpt_meta_box', $this->_cpt_routes[$this->_req_action], 'normal' );
2581
		}
2582
2583 View Code Duplication
		if ( post_type_supports( 'espresso_attendees', 'comments') ) {
2584
			add_meta_box('commentsdiv', __('Notes on the Contact', 'event_espresso'), 'post_comment_meta_box', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2585
		}
2586
2587
		add_meta_box('attendee_contact_info', __('Contact Info', 'event_espresso'), array( $this, 'attendee_contact_info'), $this->_cpt_routes[$this->_req_action], 'side', 'core' );
2588
		add_meta_box('attendee_details_address', __('Address Details', 'event_espresso'), array($this, 'attendee_address_details'), $this->_cpt_routes[$this->_req_action], 'normal', 'core' );
2589
		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');
2590
	}
2591
2592
2593
	/**
2594
	 * Metabox for attendee contact info
2595
	 * @param  WP_Post $post wp post object
2596
	 * @return string        attendee contact info ( and form )
2597
	 */
2598
	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...
2599
		//get attendee object ( should already have it )
2600
		$this->_template_args['attendee'] = $this->_cpt_model_obj;
2601
		$template = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
2602
		EEH_Template::display_template($template, $this->_template_args);
2603
	}
2604
2605
2606
2607
	/**
2608
	 * Metabox for attendee details
2609
	 * @param  WP_Post $post wp post object
2610
	 * @return string        attendee address details (and form)
2611
	 */
2612
	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...
2613
		//get attendee object (should already have it)
2614
		$this->_template_args['attendee'] = $this->_cpt_model_obj;
2615
		$this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
2616
				new EE_Question_Form_Input(
2617
				EE_Question::new_instance( array(
2618
					'QST_ID' => 0,
2619
					'QST_display_text' => __('State/Province', 'event_espresso'),
2620
					'QST_system' => 'admin-state'
2621
					)),
2622
				EE_Answer::new_instance( array(
2623
					'ANS_ID' => 0,
2624
					'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...
2625
					)),
2626
				array(
2627
					'input_id' => 'STA_ID',
2628
					'input_name' => 'STA_ID',
2629
					'input_prefix' => '',
2630
					'append_qstn_id' => FALSE
2631
					)
2632
			));
2633
		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
2634
				new EE_Question_Form_Input(
2635
				EE_Question::new_instance( array(
2636
					'QST_ID' => 0,
2637
					'QST_display_text' => __('Country', 'event_espresso'),
2638
					'QST_system' => 'admin-country'
2639
					)),
2640
				EE_Answer::new_instance( array(
2641
					'ANS_ID' => 0,
2642
					'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...
2643
					)),
2644
				array(
2645
					'input_id' => 'CNT_ISO',
2646
					'input_name' => 'CNT_ISO',
2647
					'input_prefix' => '',
2648
					'append_qstn_id' => FALSE
2649
					)
2650
				));
2651
		$template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
2652
		EEH_Template::display_template($template, $this->_template_args );
2653
2654
	}
2655
2656
2657
	/**
2658
	 * 		_attendee_details
2659
	*		@access protected
2660
	*		@return void
2661
	*/
2662
	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...
2663
2664
		$this->_template_args['attendee'] = $this->_cpt_model_obj;
2665
		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
2666
		$template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
2667
		EEH_Template::display_template($template, $this->_template_args);
2668
2669
	}
2670
2671
2672
2673
2674
	/**
2675
	 * add in the form fields for the attendee edit
2676
	 * @param  WP_Post $post wp post object
2677
	 * @return string        html for new form.
2678
	 */
2679
	public function after_title_form_fields($post) {
2680
		if ( $post->post_type == 'espresso_attendees' ) {
2681
			$template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
2682
			$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...
2683
			EEH_Template::display_template($template, $template_args);
2684
		}
2685
	}
2686
2687
2688
2689
2690
2691
2692
	/**
2693
	 * 		_trash_or_restore_attendee
2694
	*		@param boolean 		$trash - whether to move item to trash (TRUE) or restore it (FALSE)
2695
	*		@access protected
2696
	*		@return void
2697
	*/
2698
	protected function _trash_or_restore_attendees( $trash = TRUE ) {
2699
2700
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
2701
2702
		$ATT_MDL = EEM_Attendee::instance();
2703
2704
		$success = 1;
2705
		//Checkboxes
2706
		if (!empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2707
			// if array has more than one element than success message should be plural
2708
			$success = count( $this->_req_data['checkbox'] ) > 1 ? 2 : 1;
2709
			// cycle thru checkboxes
2710
			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...
2711
				$updated = $trash ? $ATT_MDL->update_by_ID(array( 'status' => 'trash' ), $ATT_ID) : $ATT_MDL->update_by_ID( array('status' => 'publish' ), $ATT_ID);
2712
				if ( !$updated ) {
2713
					$success = 0;
2714
				}
2715
			}
2716
2717
		} else {
2718
			// grab single id and delete
2719
			$ATT_ID = absint($this->_req_data['ATT_ID']);
2720
			//get attendee
2721
			$att = $ATT_MDL->get_one_by_ID( $ATT_ID );
2722
			$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...
2723
			$updated = $att->save();
2724
			if ( ! $updated ) {
2725
				$success = 0;
2726
			}
2727
2728
		}
2729
2730
		$what = $success > 1 ? __( 'Contacts', 'event_espresso' ) : __( 'Contact', 'event_espresso' );
2731
		$action_desc = $trash ? __( 'moved to the trash', 'event_espresso' ) : __( 'restored', 'event_espresso' );
2732
		$this->_redirect_after_action( $success, $what, $action_desc, array( 'action' => 'contact_list' ) );
2733
2734
	}
2735
2736
}
2737
2738
2739
2740
// end of file:  includes/core/admin/transactions/Registrations_Admin_Page.core.php
2741