Completed
Branch FET-8284-automagic-dependency-... (a299cf)
by
unknown
1189:26 queued 1175:37
created

Extend_Registrations_Admin_Page   F

Complexity

Total Complexity 127

Size/Duplication

Total Lines 913
Duplicated Lines 15.44 %

Coupling/Cohesion

Components 1
Dependencies 19

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 141
loc 913
rs 1.263
wmc 127
lcom 1
cbo 19

25 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A load_scripts_styles_reports() 0 5 1
A _add_screen_options_event_registrations() 0 3 1
A _registration_reports_js_setup() 0 4 1
A _registration_reports() 7 7 1
B _registrations_per_day_report() 38 38 3
B _registrations_per_event_report() 38 38 3
B _extend_page_config() 0 115 6
A _ajax_hooks() 0 4 1
A load_scripts_styles() 0 13 2
A _add_screen_options_registration_checkins() 6 6 1
A _set_list_table_views_event_registrations() 13 13 2
A _set_list_table_views_registration_checkins() 10 10 1
F get_newsletter_form_content() 12 45 10
B add_newsletter_action_buttons() 0 20 8
B newsletter_send_form_skeleton() 0 37 5
C _newsletter_selected_send() 6 57 16
D _registration_checkin_list_table() 0 28 8
A toggle_checkin_status() 6 23 3
D _toggle_checkin_status() 0 32 10
A _toggle_checkin() 0 11 2
C _delete_checkin_rows() 0 26 8
B _delete_checkin_row() 0 18 5
B _event_registrations_list_table() 0 54 5
F get_event_attendees() 5 117 23

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 Extend_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 Extend_Registrations_Admin_Page, and based on these observations, apply Extract Interface, too.

1
<?php
2
if (!defined('EVENT_ESPRESSO_VERSION') )
3
	exit('NO direct script access allowed');
4
5
/**
6
 * Event Espresso
7
 *
8
 * Event Registration and Management Plugin for Wordpress
9
 *
10
 * @package		Event Espresso
11
 * @author		Seth Shoultes
12
 * @copyright	(c)2009-2012 Event Espresso All Rights Reserved.
13
 * @license		http://eventespresso.com/support/terms-conditions/  ** see Plugin Licensing **
14
 * @link		http://www.eventespresso.com
15
 * @version		4.0
16
 *
17
 * ------------------------------------------------------------------------
18
 *
19
 * Extend_Registrations_Admin_Page
20
 *
21
 * This is the Registrations Caffeinated admin page.
22
 *
23
 *
24
 * @package		Extend_Registrations_Admin_Page
25
 * @subpackage	caffeinated/admin/extend/registrations/Extend_Registrations_Admin_Page.core.php
26
 * @author		Darren Ethier
27
 *
28
 * ------------------------------------------------------------------------
29
 */
30
class Extend_Registrations_Admin_Page extends Registrations_Admin_Page {
31
32
33
	/**
34
	 * This is used to hold the reports template data which is setup early in the request.
35
	 * @type array
36
	 */
37
	protected $_reports_template_data = array();
38
39
40
	public function __construct( $routing = TRUE ) {
41
		parent::__construct( $routing );
42
		define( 'REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
43
		define( 'REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
44
		define( 'REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
45
	}
46
47
48
	protected function _extend_page_config() {
49
		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
50
51
		$reg_id = ! empty( $this->_req_data['_REG_ID'] ) && ! is_array( $this->_req_data['_REG_ID'] ) ? $this->_req_data['_REG_ID'] : 0;
52
		$att_id = ! empty( $this->_req_data[ 'ATT_ID' ] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0;
53
		$att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] ) ? $this->_req_data['post'] : $att_id;
0 ignored issues
show
Unused Code introduced by
$att_id 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...
54
55
		$new_page_routes = array(
56
			'reports' => array(
57
				'func' => '_registration_reports',
58
				'capability' => 'ee_read_registrations'
59
				),
60
			'registration_checkins' => array(
61
				'func' => '_registration_checkin_list_table',
62
				'capability' => 'ee_read_checkins'
63
				),
64
			'newsletter_selected_send' => array(
65
				'func' => '_newsletter_selected_send',
66
				'noheader' => TRUE,
67
				'capability' => 'ee_send_message'
68
				),
69
			'delete_checkin_rows' => array(
70
					'func' => '_delete_checkin_rows',
71
					'noheader' => TRUE,
72
					'capability' => 'ee_delete_checkins'
73
				),
74
			'delete_checkin_row' => array(
75
					'func' => '_delete_checkin_row',
76
					'noheader' => TRUE,
77
					'capability' => 'ee_delete_checkin',
78
					'obj_id' => $reg_id
79
				),
80
			'toggle_checkin_status'	=> array(
81
					'func' => '_toggle_checkin_status',
82
					'noheader' => TRUE,
83
					'capability' => 'ee_edit_checkin',
84
					'obj_id' => $reg_id
85
				),
86
			'event_registrations'=> array(
87
				'func' => '_event_registrations_list_table',
88
				'capability' => 'ee_read_checkins',
89
				)
90
			);
91
92
		$this->_page_routes = array_merge( $this->_page_routes, $new_page_routes );
93
94
		$new_page_config = array(
95
			'reports' => array(
96
				'nav' => array(
97
					'label' => __('Reports', 'event_espresso'),
98
					'order' => 30
99
					),
100
				 'help_tabs' => array(
101
					'registrations_reports_help_tab' => array(
102
						'title' => __('Registration Reports', 'event_espresso'),
103
						'filename' => 'registrations_reports'
104
						)
105
					),
106
				'help_tour' => array( 'Registration_Reports_Help_Tour' ),
107
				'require_nonce' => FALSE
108
				),
109
			'event_registrations' => array(
110
				'nav' => array(
111
					'label' => __('Event Check-In', 'event_espresso'),
112
					'order' => 10,
113
					'persistent' => true
114
					),
115
					'help_tabs' => array(
116
					'registrations_event_checkin_help_tab' => array(
117
						'title' => __('Registrations Event Check-In', 'event_espresso'),
118
						'filename' => 'registrations_event_checkin'
119
					),
120
					'registrations_event_checkin_table_column_headings_help_tab' => array(
121
						'title' => __('Event Check-In Table Column Headings', 'event_espresso'),
122
						'filename' => 'registrations_event_checkin_table_column_headings'
123
					),
124
					'registrations_event_checkin_filters_help_tab' => array(
125
						'title' => __('Event Check-In Filters', 'event_espresso'),
126
						'filename' => 'registrations_event_checkin_filters'
127
					),
128
					'registrations_event_checkin_views_help_tab' => array(
129
						'title' => __('Event Check-In Views', 'event_espresso'),
130
						'filename' => 'registrations_event_checkin_views'
131
					),
132
					'registrations_event_checkin_other_help_tab' => array(
133
						'title' => __('Event Check-In Other', 'event_espresso'),
134
						'filename' => 'registrations_event_checkin_other'
135
					)
136
				),
137
				'help_tour' => array( 'Event_Checkin_Help_Tour' ),
138
				'qtips' => array('Registration_List_Table_Tips' ),
139
				'list_table' => 'EE_Event_Registrations_List_Table',
140
				'metaboxes' => array(),
141
				'require_nonce' => FALSE
142
				),
143
			'registration_checkins' => array(
144
				'nav' => array(
145
					'label' => __('Check-In Records', 'event_espresso'),
146
					'order' => 15,
147
					'persistent' => FALSE
148
					),
149
				'list_table' => 'EE_Registration_CheckIn_List_Table',
150
				//'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
151
				'metaboxes' => array(),
152
				'require_nonce' => FALSE
153
				),
154
			);
155
156
		// var_dump($this->_req_data);
157
		// exit();
158
159
		$this->_page_config = array_merge( $this->_page_config, $new_page_config );
160
		$this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
161
		$this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
162
	}
163
164
165
166
	protected function _ajax_hooks() {
167
		parent::_ajax_hooks();
168
		add_action('wp_ajax_get_newsletter_form_content', array( $this, 'get_newsletter_form_content') );
169
	}
170
171
172
173
	public function load_scripts_styles() {
174
		parent::load_scripts_styles();
175
176
		//if newsletter message type is active then let's add filter and load js for it.
177
		EE_Registry::instance()->load_helper('MSG_Template');
178
		if ( EEH_MSG_Template::is_mt_active('newsletter') ) {
179
			//enqueue newsletter js
180
			wp_enqueue_script( 'ee-newsletter-trigger', REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', array( 'ee-dialog'), EVENT_ESPRESSO_VERSION, TRUE );
181
			wp_enqueue_style( 'ee-newsletter-trigger-css', REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', array(), EVENT_ESPRESSO_VERSION );
182
			//hook in buttons for newsletter message type trigger.
183
			add_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', array( $this, 'add_newsletter_action_buttons'), 10 );
184
		}
185
	}
186
187
188
189
	public function load_scripts_styles_reports() {
190
		wp_register_script( 'ee-reg-reports-js', REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', array( 'google-charts' ), EVENT_ESPRESSO_VERSION, true );
191
		wp_enqueue_script( 'ee-reg-reports-js' );
192
		$this->_registration_reports_js_setup();
193
	}
194
195
196
197
198
	protected function _add_screen_options_event_registrations() {
199
		$this->_per_page_screen_option();
200
	}
201
202
203
204
205
206 View Code Duplication
	protected function _add_screen_options_registration_checkins() {
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...
207
		$page_title = $this->_admin_page_title;
208
		$this->_admin_page_title = __('Check-In Records', 'event_espresso');
209
		$this->_per_page_screen_option();
210
		$this->_admin_page_title = $page_title;
211
	}
212
213
214
215
216
217 View Code Duplication
	protected function _set_list_table_views_event_registrations() {
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...
218
		$this->_views = array(
219
			'all' => array(
220
				'slug' => 'all',
221
				'label' => __('All', 'event_espresso'),
222
				'count' => 0,
223
				'bulk_action' => !isset( $this->_req_data['event_id'] ) ? array() : array(
224
					'toggle_checkin_status' => __('Toggle Check-In', 'event_espresso'),
225
					//'trash_registrations' => __('Trash Registrations', 'event_espresso')
226
					)
227
				),
228
			);
229
	}
230
231
232
233
234
235 View Code Duplication
	protected function _set_list_table_views_registration_checkins() {
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...
236
		$this->_views = array(
237
			'all' => array(
238
				'slug' => 'all',
239
				'label' => __('All', 'event_espresso'),
240
				'count' => 0,
241
				'bulk_action' => array( 'delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso') )
242
				),
243
			);
244
	}
245
246
247
248
	/**
249
	 * callback for ajax action.
250
	 *
251
	 * @since 4.3.0
252
	 *
253
	 * @return json
254
	 */
255
	public function get_newsletter_form_content() {
256
		//do a nonce check cause we're not coming in from an normal route here.
257
		$nonce = isset( $this->_req_data['get_newsletter_form_content_nonce'] ) ? sanitize_text_field( $this->_req_data['get_newsletter_form_content_nonce'] ) : '';
258
		$nonce_ref = 'get_newsletter_form_content_nonce';
259
260
		$this->_verify_nonce( $nonce, $nonce_ref );
261
		//let's get the mtp for the incoming MTP_ ID
262 View Code Duplication
		if ( !isset( $this->_req_data['GRP_ID'] ) ) {
263
			EE_Error::add_error( __('There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
264
			$this->_template_args['success'] = FALSE;
265
			$this->_template_args['error'] = TRUE;
266
			$this->_return_json();
267
		}
268
		$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $this->_req_data['GRP_ID'] );
269 View Code Duplication
		if ( ! $MTPG instanceof EE_Message_Template_Group ) {
270
			EE_Error::add_error( sprintf( __('The GRP_ID given (%d) does not appear to have a corresponding row in the database.', 'event_espresso'), $this->_req_data['GRP_ID'] ), __FILE__, __FUNCTION__, __LINE__  );
271
			$this->_template_args['success'] = FALSE;
272
			$this->_template_args['error'] = TRUE;
273
			$this->_return_json();
274
		}
275
276
		$MTPs = $MTPG->context_templates();
0 ignored issues
show
Documentation Bug introduced by
The method context_templates 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...
277
		$MTPs = $MTPs['attendee'];
278
		$template_fields = array();
279
		foreach ( $MTPs as $MTP ) {
280
			$field = $MTP->get('MTP_template_field');
281
			if ( $field == 'content'  ) {
282
				$content = $MTP->get('MTP_content');
283
				if ( !empty( $content['newsletter_content'] ) ) {
284
					$template_fields['newsletter_content'] = $content['newsletter_content'];
285
					}
286
				continue;
287
			}
288
			$template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
289
		}
290
291
		$this->_template_args['success'] = TRUE;
292
		$this->_template_args['error'] = FALSE;
293
		$this->_template_args['data'] = array(
294
			'batch_message_from' => isset($template_fields['from']) ? $template_fields['from'] : '',
295
			'batch_message_subject' => isset($template_fields['subject']) ? $template_fields['subject'] : '',
296
			'batch_message_content' => isset( $template_fields['newsletter_content'] ) ? $template_fields['newsletter_content'] : ''
297
			);
298
		$this->_return_json();
299
	}
300
301
302
303
304
	/**
305
	 * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
306
	 *
307
	 * @since 4.3.0
308
	 *
309
	 * @param EE_Admin_List_Table $list_table
310
	 * @return string html string for extra buttons
311
	 */
312
	public function add_newsletter_action_buttons( EE_Admin_List_Table $list_table ) {
0 ignored issues
show
Unused Code introduced by
The parameter $list_table 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...
313
		if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'espresso_registrations_newsletter_selected_send' ) ) {
314
			return '';
315
		}
316
317
		$routes_to_add_to = array(
318
			'contact_list',
319
			'event_registrations',
320
			'default'
321
			);
322
		if ( $this->_current_page == 'espresso_registrations' && in_array( $this->_req_action, $routes_to_add_to )  ) {
323
			if ( ( $this->_req_action == 'event_registrations' && empty( $this->_req_data['event_id'] ) ) || ( isset( $this->_req_data['status'] ) && $this->_req_data['status'] == 'trash' ) ) {
324
				echo '';
325
			} else {
326
				$button_text = sprintf( __('Send Batch Message (%s selected)', 'event_espresso'), '<span class="send-selected-newsletter-count">0</span>' );
327
				echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>' . $button_text . '</button>';
328
				add_action('admin_footer', array( $this, 'newsletter_send_form_skeleton') );
329
			}
330
		}
331
	}
332
333
334
335
336
	public function newsletter_send_form_skeleton() {
337
		$list_table = $this->_list_table_object;
338
		$codes = array();
339
		//need to templates for the newsletter message type for the template selector.
340
		$values[] = array( 'text' => __('Select Template to Use', 'event_espresso'), 'id' => 0 );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$values was never initialized. Although not strictly required by PHP, it is generally a good practice to add $values = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
341
		$mtps = EEM_Message_Template_Group::instance()->get_all( array( array( 'MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email' ) ) );
342
		foreach ( $mtps as $mtp ) {
343
			$name = $mtp->name();
344
			$values[] = array(
345
				'text' => empty( $name ) ? __('Global', 'event_espresso') : $name,
346
				'id' => $mtp->ID()
347
				);
348
		}
349
350
		//need to get a list of shortcodes that are available for the newsletter message type.
351
		EE_Registry::instance()->load_helper('MSG_Template');
352
		$shortcodes = EEH_MSG_Template::get_shortcodes( 'newsletter', 'email', array(), 'attendee', FALSE );
353
		foreach ( $shortcodes as $field => $shortcode_array ) {
354
			$codes[$field] = implode(', ', array_keys($shortcode_array ) );
355
		}
356
357
		$shortcodes = $codes;
358
359
		$form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
360
		$form_template_args = array(
361
			'form_action' => admin_url('admin.php?page=espresso_registrations'),
362
			'form_route' => 'newsletter_selected_send',
363
			'form_nonce_name' => 'newsletter_selected_send_nonce',
364
			'form_nonce' => wp_create_nonce( 'newsletter_selected_send_nonce' ),
365
			'redirect_back_to' => $this->_req_action,
366
			'ajax_nonce' => wp_create_nonce( 'get_newsletter_form_content_nonce'),
367
			'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values ),
368
			'shortcodes' => $shortcodes,
369
			'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration'
370
			);
371
		EEH_Template::display_template( $form_template, $form_template_args );
372
	}
373
374
375
376
	/**
377
	 * Handles sending selected registrations/contacts a newsletter.
378
	 *
379
	 * @since  4.3.0
380
	 *
381
	 * @return void
382
	 */
383
	protected function _newsletter_selected_send() {
384
		$success = TRUE;
385
		//first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
386
		if ( empty( $this->_req_data['newsletter_mtp_selected'] ) ) {
387
			EE_Error::add_error( __('In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
388
			$success = FALSE;
389
		}
390
391
		if ( $success ) {
392
			//update Message template in case there are any changes
393
			$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $this->_req_data['newsletter_mtp_selected'] );
394
			$MTPs = $MTPG instanceof EE_Message_Template_Group ? $MTPG->context_templates() : array();
395
			if ( empty( $MTPs ) ) {
396
				EE_Error::add_error( __('Unable to retrieve message template fields from the db. Messages not sent.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
397
				$success = FALSE;
0 ignored issues
show
Unused Code introduced by
$success 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...
398
			}
399
400
			//let's just update the specific fields
401
			foreach ( $MTPs['attendee'] as $MTP ) {
402
				$field = $MTP->get('MTP_template_field');
403
				$content = $MTP->get('MTP_content');
404
				$new_content = $content;
405
				switch( $field ) {
406 View Code Duplication
					case 'from' :
407
						$new_content = !empty( $this->_req_data['batch_message']['from'] ) ? $this->_req_data['batch_message']['from'] : $content;
408
						break;
409 View Code Duplication
					case 'subject' :
410
						$new_content = !empty( $this->_req_data['batch_message']['subject'] ) ? $this->_req_data['batch_message']['subject'] : $content;
411
						break;
412
					case 'content' :
413
						$new_content = $content;
414
						$new_content['newsletter_content'] = !empty( $this->_req_data['batch_message']['content'] ) ? $this->_req_data['batch_message']['content'] : $content['newsletter_content'];
415
						break;
416
					default :
417
						continue;
418
						break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
419
				}
420
				$MTP->set('MTP_content', $new_content);
421
				$MTP->save();
422
			}
423
424
			//great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
425
			$id_type = !empty( $this->_req_data['batch_message']['id_type'] ) ? $this->_req_data['batch_message']['id_type'] : 'registration';
426
427
			//id_type will affect how we assemble the ids.
428
			$ids = !empty( $this->_req_data['batch_message']['ids'] ) ? json_decode( stripslashes($this->_req_data['batch_message']['ids']) ) : array();
429
430
			$contacts = $id_type == 'registration' ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids( $ids ) : EEM_Attendee::instance()->get_all( array( array( 'ATT_ID' => array('in', $ids ) ) ) );
431
432
			//we do _action because ALL triggers are handled in EED_Messages.
433
			do_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', $contacts, $MTPG->ID() );
434
		}
435
		$query_args = array(
436
			'action' => !empty( $this->_req_data['redirect_back_to'] ) ? $this->_req_data['redirect_back_to'] : 'default'
437
			);
438
		$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
439
	}
440
441
442
	/**
443
	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
444
	 * Also $this->$_reports_template_data property is set for later usage by the _registration_reports method.
445
	 */
446
	protected function _registration_reports_js_setup() {
447
		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
448
		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
449
	}
450
451
452
453
454
	/**
455
	 * 		generates Business Reports regarding Registrations
456
	*		@access protected
457
	*		@return void
458
	*/
459 View Code Duplication
	protected function _registration_reports() {
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...
460
		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
461
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( $template_path, $this->_reports_template_data, true );
462
		// the final template wrapper
463
		$this->display_admin_page_with_no_sidebar();
464
465
	}
466
467
468
	/**
469
	 * Generates Business Report showing total registrations per day.
470
	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
471
	 *
472
	 * @return string
473
	 */
474 View Code Duplication
	private function _registrations_per_day_report( $period = '-1 month' ) {
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...
475
		$report_ID = 'reg-admin-registrations-per-day-report-dv';
476
477
		$REG = EEM_Registration::instance();
478
479
		$results = $REG->get_registrations_per_day_report( $period );
480
481
		$results = (array) $results;
482
		$regs = array();
483
		$subtitle = '';
484
485
		if( $results ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $results of type array 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...
486
			$regs[] = array( __( 'Date (only days with registrations are shown)', 'event_espresso' ), __('Total Registrations', 'event_espresso' ) );
487
			foreach ( $results as $result ) {
488
				$regs[] = array( $result->regDate, (int) $result->total );
489
			}
490
491
			//setup the date range.
492
			EE_Registry::instance()->load_helper( 'DTT_Helper' );
493
			$beginning_date = new DateTime( "now " . $period, new DateTimeZone( EEH_DTT_Helper::get_timezone() ) );
494
			$ending_date = new DateTime( "now", new DateTimeZone( EEH_DTT_Helper::get_timezone() ) );
495
			$subtitle = sprintf( _x( 'For the period: %s to %s', 'Used to give date range', 'event_espresso' ), $beginning_date->format( 'Y-m-d' ), $ending_date->format( 'Y-m-d' ) );
496
		}
497
498
		$report_title = __( 'Total Registrations per Day', 'event_espresso' );
499
500
		$report_params = array(
501
			'title' 	=> $report_title,
502
			'subtitle' => $subtitle,
503
			'id' 		=> $report_ID,
504
			'regs' 	=> $regs,
505
			'noResults' => empty( $regs ),
506
			'noRegsMsg' => sprintf( __('%sThere are currently no registration records in the last month for this report.%s', 'event_espresso'), '<h2>' . $report_title . '</h2><p>', '</p>' ),
507
		);
508
		wp_localize_script( 'ee-reg-reports-js', 'regPerDay', $report_params );
509
510
		return $report_ID;
511
	}
512
513
514
	/**
515
	 * Generates Business Report showing total registrations per event.
516
	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
517
	 *
518
	 * @return string
519
	 */
520 View Code Duplication
	private function _registrations_per_event_report( $period = '-1 month' ) {
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...
521
522
		$report_ID = 'reg-admin-registrations-per-event-report-dv';
523
524
		$REG = EEM_Registration::instance();
525
526
		$results = $REG->get_registrations_per_event_report( $period );
527
		$results = (array) $results;
528
		$regs = array();
529
		$subtitle = '';
530
531
		if ( $results ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $results of type array 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...
532
			$regs[] = array( __( 'Event', 'event_espresso' ), __('Total Registrations', 'event_espresso' ) );
533
			foreach ( $results as $result ) {
534
				$regs[] = array( wp_trim_words( $result->event_name, 4, '...' ), (int) $result->total );
535
			}
536
537
			//setup the date range.
538
			EE_Registry::instance()->load_helper( 'DTT_Helper' );
539
			$beginning_date = new DateTime( "now " . $period, new DateTimeZone( EEH_DTT_Helper::get_timezone() ) );
540
			$ending_date = new DateTime( "now", new DateTimeZone( EEH_DTT_Helper::get_timezone() ) );
541
			$subtitle = sprintf( _x( 'For the period: %s to %s', 'Used to give date range', 'event_espresso' ), $beginning_date->format( 'Y-m-d' ), $ending_date->format( 'Y-m-d' ) );
542
		}
543
544
		$report_title = __( 'Total Registrations per Event', 'event_espresso' );
545
546
		$report_params = array(
547
			'title' 	=> $report_title,
548
			'subtitle' => $subtitle,
549
			'id' 		=> $report_ID,
550
			'regs' 	=> $regs,
551
			'noResults' => empty( $regs ),
552
			'noRegsMsg' => sprintf( __('%sThere are currently no registration records in the last month for this report.%s', 'event_espresso'), '<h2>' . $report_title . '</h2><p>', '</p>' ),
553
		);
554
		wp_localize_script( 'ee-reg-reports-js', 'regPerEvent', $report_params );
555
556
		return $report_ID;
557
	}
558
559
560
561
562
	/**
563
	 * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
564
	 * @access protected
565
	 * @return void
566
	 */
567
	protected function _registration_checkin_list_table() {
568
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
569
		$reg_id = isset( $this->_req_data['_REGID'] ) ? $this->_req_data['_REGID'] : null;
570
		$reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
571
		$this->_admin_page_title .= $this->get_action_link_or_button('new_registration', 'add-registrant', array('event_id' => $reg->event_ID()), 'add-new-h2');
0 ignored issues
show
Documentation Bug introduced by
The method event_ID 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...
572
573
		$legend_items = array(
574
			'checkin' => array(
575
				'class' => 'ee-icon ee-icon-check-in',
576
				'desc' => __('This indicates the attendee has been checked in', 'event_espresso')
577
				),
578
			'checkout' => array(
579
				'class' => 'ee-icon ee-icon-check-out',
580
				'desc' => __('This indicates the attendee has been checked out', 'event_espresso')
581
				)
582
			);
583
		$this->_template_args['after_list_table'] = $this->_display_legend( $legend_items );
584
585
586
		$dtt_id = isset(  $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : NULL;
587
		$go_back_url = !empty( $reg_id )  ? EE_Admin_Page::add_query_args_and_nonce(array('action' => 'event_registrations', 'event_id' => EEM_Registration::instance()->get_one_by_ID($reg_id)->get_first_related('Event')->ID(), 'DTT_ID' => $dtt_id ), $this->_admin_base_url ) : '';
588
589
		$this->_template_args['before_list_table'] = !empty( $reg_id ) && !empty( $dtt_id ) ? '<h2>' . sprintf(__("%s's check in records for %s at the event, %s", 'event_espresso'), '<span id="checkin-attendee-name">' . EEM_Registration::instance()->get_one_by_ID($reg_id)->get_first_related('Attendee')->full_name() . '</span>', '<span id="checkin-dtt"><a href="' . $go_back_url . '">' . EEM_Datetime::instance()->get_one_by_ID($dtt_id)->start_date_and_time() . ' - ' . EEM_Datetime::instance()->get_one_by_ID($dtt_id)->end_date_and_time() . '</a></span>', '<span id="checkin-event-name">' . EEM_Datetime::instance()->get_one_by_ID($dtt_id)->get_first_related('Event')->get('EVT_name') . '</span>' ) . '</h2>' : '';
0 ignored issues
show
Documentation Bug introduced by
The method start_date_and_time 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...
Documentation Bug introduced by
The method end_date_and_time 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...
590
		$this->_template_args['list_table_hidden_fields'] = !empty( $reg_id ) ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
591
		$this->_template_args['list_table_hidden_fields'] .= !empty( $dtt_id ) ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
592
593
		$this->display_admin_list_table_page_with_no_sidebar();
594
	}
595
596
597
598
	/**
599
	 * toggle the Check-in status for the given registration (coming from ajax)
600
	 * @return json
601
	 */
602
	public function toggle_checkin_status() {
603
		//first make sure we have the necessary data
604 View Code Duplication
		if ( !isset( $this->_req_data['_regid'] ) ) {
605
			EE_Error::add_error( __('There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
606
			$this->_template_args['success'] = FALSE;
607
			$this->_template_args['error'] = TRUE;
608
			$this->_return_json();
609
		};
610
611
		//do a nonce check cause we're not coming in from an normal route here.
612
		$nonce = isset( $this->_req_data['checkinnonce'] ) ? sanitize_text_field( $this->_req_data['checkinnonce'] ) : '';
613
		$nonce_ref = 'checkin_nonce';
614
615
		$this->_verify_nonce( $nonce, $nonce_ref );
616
617
		//beautiful! Made it this far so let's get the status.
618
		$new_status = $this->_toggle_checkin_status();
619
620
		//setup new class to return via ajax
621
		$this->_template_args['admin_page_content'] = 'clickable trigger-checkin checkin-icons checkedin-status-' . $new_status;
622
		$this->_template_args['success'] = TRUE;
623
		$this->_return_json();
624
	}
625
626
627
628
629
630
631
	/**
632
	 * 		handles toggleing the checkin status for the registration,
633
	*		@access protected
634
	*		@param boolean 	$check_in
0 ignored issues
show
Bug introduced by
There is no parameter named $check_in. Was it maybe removed?

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

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

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

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

Loading history...
635
	*		@return void
636
	*/
637
	protected function _toggle_checkin_status() {
638
		//first let's get the query args out of the way for the redirect
639
		$query_args = array(
640
			'action' => 'event_registrations',
641
			'event_id' => isset( $this->_req_data['event_id'] ) ? $this->_req_data['event_id'] : NULL,
642
			'DTT_ID' => isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : NULL
643
			);
644
		$new_status = FALSE;
645
646
		// bulk action check in toggle
647
		if ( ! empty( $this->_req_data['checkbox'] ) && is_array( $this->_req_data['checkbox'] )) {
648
			// cycle thru checkboxes
649
			while ( list( $REG_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...
650
				$DTT_ID = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : NULL;
651
				$new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
652
			}
653
654
		} elseif ( isset( $this->_req_data['_regid'] ) ) {
655
			//coming from ajax request
656
			$DTT_ID = isset( $this->_req_data['dttid'] ) ? $this->_req_data['dttid'] : NULL;
657
			$query_args['DTT_ID'] = $DTT_ID;
658
			$new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
659
		} else {
660
			EE_Error::add_error(__('Missing some required data to toggle the Check-in', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__  );
661
		}
662
663
		if ( defined('DOING_AJAX' ) )
664
			return $new_status;
665
666
		$this->_redirect_after_action( FALSE,'', '', $query_args, TRUE );
667
668
	}
669
670
671
672
673
674
	/**
675
	 * This is toggles a single Check-in for the given registration and datetime.
676
	 * @param  int    $REG_ID The registration we're toggling
677
	 * @param  int    $DTT_ID The datetime we're toggling
678
	 * @return int            The new status toggled to.
679
	 */
680
	private function _toggle_checkin($REG_ID, $DTT_ID) {
681
		$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
682
		$new_status = $REG->toggle_checkin_status( $DTT_ID );
0 ignored issues
show
Documentation Bug introduced by
The method toggle_checkin_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...
683
		if ( $new_status !== FALSE ) {
684
			EE_Error::add_success($REG->get_checkin_msg($DTT_ID) );
0 ignored issues
show
Documentation Bug introduced by
The method get_checkin_msg 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...
685
		} else {
686
			EE_Error::add_error($REG->get_checkin_msg($DTT_ID, TRUE), __FILE__, __FUNCTION__, __LINE__ );
0 ignored issues
show
Documentation Bug introduced by
The method get_checkin_msg 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...
687
			$new_status = FALSE;
688
		}
689
		return $new_status;
690
	}
691
692
693
	/**
694
	 * Takes care of deleting multiple EE_Checkin table rows
695
	 *
696
	 * @access protected
697
	 * @return void
698
	 */
699
	protected function _delete_checkin_rows() {
700
		$query_args = array(
701
			'action' => 'registration_checkins',
702
			'DTT_ID' => isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : 0,
703
			'_REGID' => isset( $this->_req_data['_REGID'] ) ? $this->_req_data['_REGID'] : 0
704
			);
705
		if ( !empty( $this->_req_data['checkbox'] ) && is_array( $this->_req_data['checkbox'] ) ) {
706
			while ( list( $CHK_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...
707
				$errors = 0;
708
				if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID ) ) {
709
					$errors++;
710
				}
711
			}
712
		} else {
713
			EE_Error::add_error(__('So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
714
			$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
715
		}
716
717
		if ( $errors > 0 ) {
718
			EE_Error::add_error( sprintf( __('There were %d records that did not delete successfully', 'event_espresso'), $errors ), __FILE__, __FUNCTION__, __LINE__ );
0 ignored issues
show
Bug introduced by
The variable $errors 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...
719
		} else {
720
			EE_Error::add_success( __('Records were successfully deleted', 'event_espresso') );
721
		}
722
723
		$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
724
	}
725
726
727
728
	/**
729
	 * Deletes a single EE_Checkin row
730
	 * @return void
731
	 */
732
	protected function _delete_checkin_row() {
733
		$query_args = array(
734
			'action' => 'registration_checkins',
735
			'DTT_ID' => isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : 0,
736
			'_REGID' => isset( $this->_req_data['_REGID'] ) ? $this->_req_data['_REGID'] : 0
737
			);
738
739
		if ( !empty( $this->_req_data['CHK_ID'] ) ) {
740
			if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'] ) ) {
741
				EE_Error::add_error(__('Something went wrong and this check-in record was not deleted', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
742
			} else {
743
				EE_Error::add_success( __('Check-In record successfully deleted', 'event_espresso') );
744
			}
745
		} else {
746
			EE_Error::add_error(__('In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
747
		}
748
		$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
749
	}
750
751
752
753
754
755
	/**
756
	 * 		generates HTML for the Event Registrations List Table
757
	*		@access protected
758
	*		@return void
759
	*/
760
	protected function _event_registrations_list_table() {
761
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
762
		$this->_admin_page_title .= isset( $this->_req_data['event_id'] ) ? $this->get_action_link_or_button('new_registration', 'add-registrant', array('event_id' => $this->_req_data['event_id']), 'add-new-h2') : '';
763
764
		$legend_items = array(
765
			'star-icon' => array(
766
				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
767
				'desc' => __('This Registrant is the Primary Registrant', 'event_espresso')
768
				),
769
			'checkin' => array(
770
				'class' => 'ee-icon ee-icon-check-in',
771
				'desc' => __('This Registrant has been Checked In', 'event_espresso')
772
				),
773
			'checkout' => array(
774
				'class' => 'ee-icon ee-icon-check-out',
775
				'desc' => __('This Registrant has been Checked Out', 'event_espresso')
776
				),
777
			'nocheckinrecord' => array(
778
				'class' => 'dashicons dashicons-no',
779
				'desc' => __('No Check-in Record has been Created for this Registrant', 'event_espresso')
780
				),
781
			'view_details' => array(
782
				'class' => 'dashicons dashicons-search',
783
				'desc' => __('View All Check-in Records for this Registrant', 'event_espresso')
784
				),
785
			'approved_status' => array(
786
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
787
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_approved, FALSE, 'sentence' )
788
				),
789
            'cancelled_status' => array(
790
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
791
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_cancelled, FALSE, 'sentence' )
792
				),
793
            'declined_status' => array(
794
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
795
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_declined, FALSE, 'sentence' )
796
				),
797
			'not_approved' => array(
798
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
799
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_not_approved, FALSE, 'sentence' )
800
				),
801
			'pending_status' => array(
802
				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
803
				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_pending_payment, FALSE, 'sentence' )
804
				)/**/
805
			);
806
		$this->_template_args['after_list_table'] = $this->_display_legend( $legend_items );
807
808
		$event_id = isset( $this->_req_data['event_id'] ) ? $this->_req_data['event_id'] : null;
809
		$this->_template_args['before_list_table'] = !empty( $event_id ) ? '<h2>' . sprintf(__('Viewing Registrations for Event: %s', 'event_espresso'), EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') ) . '</h2>' : '';
810
		$this->_template_args['list_table_hidden_fields'] = !empty( $event_id ) ? '<input type="hidden" name="event_id" value="' . $event_id . '">' : '';
811
812
		$this->display_admin_list_table_page_with_no_sidebar();
813
	}
814
815
816
817
818
	/**
819
	 * 		get_attendees
820
	 * 		@param bool $count whether to return count or data.
821
	*		@access public
822
	*		@return array
823
	*/
824
	public function get_event_attendees( $per_page = 10, $count = FALSE, $trash = FALSE, $orderby = '' ) {
825
826
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
827
		require_once(EE_MODELS . 'EEM_Attendee.model.php');
828
		//$ATT_MDL = EEM_Attendee::instance();
829
830
		$EVT_ID = isset($this->_req_data['event_id']) ? absint( $this->_req_data['event_id'] ) : FALSE;
831
		$CAT_ID = isset($this->_req_data['category_id']) ? absint( $this->_req_data['category_id'] ) : FALSE;
832
		$DTT_ID = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : NULL;
833
834
		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
835
836
		switch ($this->_req_data['orderby']) {
837
			case '_REG_date':
838
				$orderby = 'REG_date';
839
				break;
840
			default :
841
				$orderby = 'Attendee.ATT_lname';
842
//				$orderby = 'reg.REG_final_price';
843
		}
844
845
		$sort = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'ASC';
846
847
		$current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1;
848
		$per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page;
849
850
851
		$offset = ($current_page-1)*$per_page;
852
		$limit = $count ? NULL : array( $offset, $per_page );
853
		$query_params = array(array('Event.status'=>array('IN',  array_keys(EEM_Event::instance()->get_status_array()))));
854
		if ($EVT_ID){
855
			$query_params[0]['EVT_ID']=$EVT_ID;
856
		}
857
		if($CAT_ID){
858
			throw new EE_Error("You specified a Category Id for this query. Thats odd because we are now using terms and taxonomies. So did you mean the term taxonomy id o rthe term id?");
859
		}
860
861
		//if DTT is included we do multiple datetimes.
862
		if ( $DTT_ID ) {
863
			$query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID;
864
		}
865
866
		//make sure we only have default where on the current regs
867
		$query_params['default_where_conditions'] = 'this_model_only';
868
869
		$status_ids_array = apply_filters( 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', array( EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved ) );
870
871
		$query_params[0]['STS_ID']= array('IN', $status_ids_array );
872
873
		if($trash){
874
			$query_params[0]['Attendee.status']=  EEM_CPT_Base::post_status_trashed;
875
		}
876
877
		if ( isset( $this->_req_data['s'] ) ) {
878
			$sstr = '%' . $this->_req_data['s'] . '%';
879
			$query_params[0]['OR'] = array(
880
				'Event.EVT_name' => array( 'LIKE', $sstr),
881
				'Event.EVT_desc' => array( 'LIKE', $sstr ),
882
				'Event.EVT_short_desc' => array( 'LIKE' , $sstr ),
883
				'Attendee.ATT_fname' => array( 'LIKE', $sstr ),
884
				'Attendee.ATT_lname' => array( 'LIKE', $sstr ),
885
				'Attendee.ATT_short_bio' => array( 'LIKE', $sstr ),
886
				'Attendee.ATT_email' => array('LIKE', $sstr ),
887
				'Attendee.ATT_address' => array( 'LIKE', $sstr ),
888
				'Attendee.ATT_address2' => array( 'LIKE', $sstr ),
889
				'Attendee.ATT_city' => array( 'LIKE', $sstr ),
890
				'REG_final_price' => array( 'LIKE', $sstr ),
891
				'REG_code' => array( 'LIKE', $sstr ),
892
				'REG_count' => array( 'LIKE' , $sstr ),
893
				'REG_group_size' => array( 'LIKE' , $sstr ),
894
				'Ticket.TKT_name' => array( 'LIKE', $sstr ),
895
				'Ticket.TKT_description' => array( 'LIKE', $sstr )
896
				);
897
		}
898
899
		$query_params['order_by'][$orderby] = $sort;
900
		$query_params['limit'] = $limit;
901
		$query_params['force_join'] = array('Attendee');//force join to attendee model so that it gets cached, because we're going to need the attendee for each registration
902
		if($count){
903
			$registrations = EEM_Registration::instance()->count(array($query_params[0], 'default_where_conditions' => 'this_model_only' ));
904
		}else{
905
			$registrations = EEM_Registration::instance()->get_all($query_params);
906
907
908
	//		$registrations = EEM_Registration::instance();
909
	//		$all_attendees = EEM_Attendee::instance()->get_event_attendees( $EVT_ID, $CAT_ID, $reg_status, $trash, $orderby, $sort, $limit, $output );
910
			if ( isset( $registrations[0] ) && $registrations[0] instanceof EE_Registration ) {
911
				//EEH_Debug_Tools::printr( $all_attendees[0], '$all_attendees[0]  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
912
				// name
913
				$first_registration = $registrations[0];
914
				$event_obj = $first_registration->event_obj();
915
				if($event_obj){
916
					$event_name = $first_registration->event_obj()->name();
917
					$event_date = 'TODO: we need to get date from earliest price date or should this be the actual event date?';//$first_registration->date_obj()->reg_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 ) : '';
918
					// edit event link
919 View Code Duplication
					if ( $event_name != '' ) {
920
						$edit_event_url = self::add_query_args_and_nonce( array( 'action'=>'edit_event', 'EVT_ID'=>$EVT_ID ), EVENTS_ADMIN_URL );
921
						$edit_event_lnk = '<a href="'.$edit_event_url.'" title="' . esc_attr__( 'Edit ', 'event_espresso' ) . $event_name . '">' . __( 'Edit Event', 'event_espresso' ) . '</a>';
922
						$event_name .= ' <span class="admin-page-header-edit-lnk not-bold">' . $edit_event_lnk . '</span>' ;
923
					}
924
925
					$back_2_reg_url = self::add_query_args_and_nonce( array( 'action'=>'default' ), REG_ADMIN_URL );
926
					$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>';
927
928
					$this->_template_args['before_admin_page_content'] = '
929
				<div id="admin-page-header">
930
					<h1><span class="small-text not-bold">'.__( 'Event: ', 'event_espresso' ).'</span>'. $event_name .'</h1>
931
					<h3><span class="small-text not-bold">'.__( 'Date: ', 'event_espresso' ). '</span>'. $event_date .'</h3>
932
					<span class="admin-page-header-go-back-lnk not-bold">' . $back_2_reg_lnk . '</span>
933
				</div>
934
				';
935
				}
936
			}
937
		}
938
939
		return $registrations;
940
	}
941
942
} //end class Registrations Admin Page
943