Completed
Branch FET-10840-domain-class (74341b)
by
unknown
106:40 queued 94:08
created
attendee_information/EE_SPCO_Reg_Step_Attendee_Information.class.php 4 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -588,6 +588,7 @@  discard block
 block discarded – undo
588 588
 	 * @param EE_Registration $registration
589 589
 	 * @param EE_Question     $question
590 590
 	 * @param                 mixed EE_Answer|NULL      $answer
591
+	 * @param EE_Answer $answer
591 592
 	 * @return EE_Form_Input_Base
592 593
 	 * @throws \EE_Error
593 594
 	 */
@@ -1190,7 +1191,7 @@  discard block
 block discarded – undo
1190 1191
 	 *
1191 1192
 	 * @param EE_Registration $registration
1192 1193
 	 * @param array           $attendee_data
1193
-	 * @return boolean|EE_Attendee
1194
+	 * @return EE_Attendee
1194 1195
 	 * @throws \EE_Error
1195 1196
 	 */
1196 1197
 	private function _find_existing_attendee( EE_Registration $registration, $attendee_data = array() ) {
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1012,7 +1012,7 @@
 block discarded – undo
1012 1012
 					$this->_associate_registration_with_transaction( $registration );
1013 1013
 				} // end of if ( ! $this->checkout->revisit || $this->checkout->primary_revisit || ( $this->checkout->revisit && $this->checkout->reg_url_link == $reg_url_link )) {
1014 1014
 
1015
-			}  else {
1015
+			} else {
1016 1016
 				EE_Error::add_error( __( 'An invalid or missing line item ID was encountered while attempting to process the registration form.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
1017 1017
 				// remove malformed data
1018 1018
 				unset( $valid_data[ $reg_url_link ] );
Please login to merge, or discard this patch.
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2 2
  /**
3
- *
4
- * Class EE_SPCO_Reg_Step_Attendee_Information
5
- *
6
- * Description
7
- *
8
- * @package 			Event Espresso
9
- * @subpackage 	core
10
- * @author 				Brent Christensen
11
- * @since 				4.5.0
12
- *
13
- */
3
+  *
4
+  * Class EE_SPCO_Reg_Step_Attendee_Information
5
+  *
6
+  * Description
7
+  *
8
+  * @package 			Event Espresso
9
+  * @subpackage 	core
10
+  * @author 				Brent Christensen
11
+  * @since 				4.5.0
12
+  *
13
+  */
14 14
 class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step {
15 15
 
16 16
 	/**
@@ -135,28 +135,28 @@  discard block
 block discarded – undo
135 135
 					$registration instanceof EE_Registration
136 136
 					&& $this->checkout->visit_allows_processing_of_this_registration( $registration )
137 137
 				) {
138
-                    $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration);
139
-                    if ( ! $this->checkout->admin_request) {
140
-                        $template_args['registrations'][$registration->reg_url_link()] = $registration;
141
-                        $template_args['ticket_count'][$registration->ticket()->ID()] = isset(
142
-                            $template_args['ticket_count'][$registration->ticket()->ID()]
143
-                        )
144
-                            ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1
145
-                            : 1;
146
-                        $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
147
-                            $this->checkout->cart->get_grand_total(),
148
-                            'Ticket',
149
-                            array($registration->ticket()->ID())
150
-                        );
151
-                        $ticket_line_item = is_array($ticket_line_item)
152
-                            ? reset($ticket_line_item)
153
-                            : $ticket_line_item;
154
-                        $template_args['ticket_line_item'][$registration->ticket()->ID()] =
155
-                            $Line_Item_Display->display_line_item($ticket_line_item);
156
-                    }
157
-                    if ($registration->is_primary_registrant()) {
158
-                        $primary_registrant = $registration->reg_url_link();
159
-                    }
138
+					$subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration);
139
+					if ( ! $this->checkout->admin_request) {
140
+						$template_args['registrations'][$registration->reg_url_link()] = $registration;
141
+						$template_args['ticket_count'][$registration->ticket()->ID()] = isset(
142
+							$template_args['ticket_count'][$registration->ticket()->ID()]
143
+						)
144
+							? $template_args['ticket_count'][$registration->ticket()->ID()] + 1
145
+							: 1;
146
+						$ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
147
+							$this->checkout->cart->get_grand_total(),
148
+							'Ticket',
149
+							array($registration->ticket()->ID())
150
+						);
151
+						$ticket_line_item = is_array($ticket_line_item)
152
+							? reset($ticket_line_item)
153
+							: $ticket_line_item;
154
+						$template_args['ticket_line_item'][$registration->ticket()->ID()] =
155
+							$Line_Item_Display->display_line_item($ticket_line_item);
156
+					}
157
+					if ($registration->is_primary_registrant()) {
158
+						$primary_registrant = $registration->reg_url_link();
159
+					}
160 160
 				}
161 161
 			}
162 162
 			// print_copy_info ?
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 				// generate hidden input
169 169
 				if (
170 170
 					isset( $subsections[ $primary_registrant ] )
171
-				     && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper
171
+					 && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper
172 172
 				) {
173 173
 					$subsections[ $primary_registrant ]->add_subsections( $copy_options, 'primary_registrant', false );
174 174
 				}
@@ -196,42 +196,42 @@  discard block
 block discarded – undo
196 196
 
197 197
 
198 198
 
199
-    /**
199
+	/**
200 200
 	 * @param EE_Registration $registration
201 201
 	 * @return EE_Form_Section_Base
202 202
 	 * @throws \EE_Error
203 203
 	 */
204 204
 	private function _registrations_reg_form( EE_Registration $registration ) {
205 205
 		static $attendee_nmbr = 1;
206
-        $form_args = array();
206
+		$form_args = array();
207 207
 		// verify that registration has valid event
208 208
 		if ( $registration->event() instanceof EE_Event ) {
209 209
 			$question_groups = $registration->event()->question_groups(
210
-                array(
211
-                    array(
212
-                        'Event.EVT_ID'                     => $registration->event()->ID(),
213
-                        'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false
214
-                    ),
215
-                    'order_by' => array('QSG_order' => 'ASC')
216
-                )
217
-            );
210
+				array(
211
+					array(
212
+						'Event.EVT_ID'                     => $registration->event()->ID(),
213
+						'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false
214
+					),
215
+					'order_by' => array('QSG_order' => 'ASC')
216
+				)
217
+			);
218 218
 			if ( $question_groups ) {
219
-                // array of params to pass to parent constructor
220
-                $form_args = array(
221
-                    'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
222
-                    'html_class'      => 'ee-reg-form-attendee-dv',
223
-                    'html_style'      => $this->checkout->admin_request
224
-                        ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
225
-                        : '',
226
-                    'subsections'     => array(),
227
-                    'layout_strategy' => new EE_Fieldset_Section_Layout(
228
-                        array(
229
-                            'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text',
230
-                            'legend_text'  => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr)
231
-                        )
232
-                    )
233
-                );
234
-                foreach ( $question_groups as $question_group ) {
219
+				// array of params to pass to parent constructor
220
+				$form_args = array(
221
+					'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
222
+					'html_class'      => 'ee-reg-form-attendee-dv',
223
+					'html_style'      => $this->checkout->admin_request
224
+						? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
225
+						: '',
226
+					'subsections'     => array(),
227
+					'layout_strategy' => new EE_Fieldset_Section_Layout(
228
+						array(
229
+							'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text',
230
+							'legend_text'  => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr)
231
+						)
232
+					)
233
+				);
234
+				foreach ( $question_groups as $question_group ) {
235 235
 					if ( $question_group instanceof EE_Question_Group ) {
236 236
 						$form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form(
237 237
 							$registration,
@@ -239,19 +239,19 @@  discard block
 block discarded – undo
239 239
 						);
240 240
 					}
241 241
 				}
242
-                // add hidden input
243
-                $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input(
244
-                    $registration
245
-                );
246
-                // if we have question groups for additional attendees, then display the copy options
242
+				// add hidden input
243
+				$form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input(
244
+					$registration
245
+				);
246
+				// if we have question groups for additional attendees, then display the copy options
247 247
 				$this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info;
248
-                if ($registration->is_primary_registrant()) {
249
-                    // generate hidden input
250
-                    $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs($registration);
251
-                }
252
-            }
248
+				if ($registration->is_primary_registrant()) {
249
+					// generate hidden input
250
+					$form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs($registration);
251
+				}
252
+			}
253 253
 		}
254
-        $attendee_nmbr++;
254
+		$attendee_nmbr++;
255 255
 		return ! empty($form_args) ? new EE_Form_Section_Proper( $form_args ) : new EE_Form_Section_HTML();
256 256
 	}
257 257
 
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 					if ( isset( $valid_data[ $reg_url_link ] ) ) {
885 885
 						// do we need to copy basic info from primary attendee ?
886 886
 						$copy_primary = isset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] )
887
-						                && absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0
887
+										&& absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0
888 888
 							? true
889 889
 							: false;
890 890
 						// filter form input data for this registration
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
 		) ) {
1055 1055
 			return true;
1056 1056
 		}
1057
-        /*
1057
+		/*
1058 1058
          * $answer_cache_id is the key used to find the EE_Answer we want
1059 1059
          * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477
1060 1060
          */
@@ -1062,7 +1062,7 @@  discard block
 block discarded – undo
1062 1062
 			? $form_input . '-' . $registration->reg_url_link()
1063 1063
 			: $form_input;
1064 1064
 		$answer_is_obj = isset( $this->_registration_answers[ $answer_cache_id ] )
1065
-		                 && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer
1065
+						 && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer
1066 1066
 			? true
1067 1067
 			: false;
1068 1068
 		//rename form_inputs if they are EE_Attendee properties
@@ -1182,7 +1182,7 @@  discard block
 block discarded – undo
1182 1182
 		// then attempt to copy them from the primary attendee
1183 1183
 		if (
1184 1184
 			$this->checkout->primary_attendee_obj instanceof EE_Attendee
1185
-            && ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] )
1185
+			&& ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] )
1186 1186
 		) {
1187 1187
 			return $this->checkout->primary_attendee_obj;
1188 1188
 		}
@@ -1300,7 +1300,7 @@  discard block
 block discarded – undo
1300 1300
 		}
1301 1301
 		foreach ( $critical_attendee_details as $critical_attendee_detail ) {
1302 1302
 			if ( ! isset( $attendee_data[ $critical_attendee_detail ] )
1303
-			     || empty( $attendee_data[ $critical_attendee_detail ] )
1303
+				 || empty( $attendee_data[ $critical_attendee_detail ] )
1304 1304
 			) {
1305 1305
 				$attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get(
1306 1306
 					$critical_attendee_detail
Please login to merge, or discard this patch.
Spacing   +211 added lines, -212 removed lines patch added patch discarded remove patch
@@ -41,21 +41,21 @@  discard block
 block discarded – undo
41 41
 	 * @access    public
42 42
 	 * @param    EE_Checkout $checkout
43 43
 	 */
44
-	public function __construct( EE_Checkout $checkout ) {
44
+	public function __construct(EE_Checkout $checkout) {
45 45
 		$this->_slug = 'attendee_information';
46 46
 		$this->_name = __('Attendee Information', 'event_espresso');
47
-		$this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php';
47
+		$this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'attendee_info_main.template.php';
48 48
 		$this->checkout = $checkout;
49 49
 		$this->_reset_success_message();
50 50
 		$this->set_instructions(
51
-			__( 'Please answer the following registration questions before proceeding.', 'event_espresso' )
51
+			__('Please answer the following registration questions before proceeding.', 'event_espresso')
52 52
 		);
53 53
 	}
54 54
 
55 55
 
56 56
 
57 57
 	public function translate_js_strings() {
58
-		EE_Registry::$i18n_js_strings['required_field'] = __( ' is a required question.', 'event_espresso' );
58
+		EE_Registry::$i18n_js_strings['required_field'] = __(' is a required question.', 'event_espresso');
59 59
 		EE_Registry::$i18n_js_strings['required_multi_field'] = __(
60 60
 			' is a required question. Please enter a value for at least one of the options.',
61 61
 			'event_espresso'
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 		// calculate taxes
116 116
 		$Line_Item_Display->display_line_item(
117 117
 			$this->checkout->cart->get_grand_total(),
118
-			array( 'set_tax_rate' => true )
118
+			array('set_tax_rate' => true)
119 119
 		);
120 120
 		/** @var $subsections EE_Form_Section_Proper[] */
121 121
 		$subsections = array(
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
 			'ticket_count' 	=> array()
128 128
 		);
129 129
 		// grab the saved registrations from the transaction
130
-		$registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params );
131
-		if ( $registrations ) {
132
-			foreach ( $registrations as $registration ) {
130
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
131
+		if ($registrations) {
132
+			foreach ($registrations as $registration) {
133 133
 				// can this registration be processed during this visit ?
134 134
 				if (
135 135
 					$registration instanceof EE_Registration
136
-					&& $this->checkout->visit_allows_processing_of_this_registration( $registration )
136
+					&& $this->checkout->visit_allows_processing_of_this_registration($registration)
137 137
 				) {
138 138
                     $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration);
139 139
                     if ( ! $this->checkout->admin_request) {
@@ -160,17 +160,17 @@  discard block
 block discarded – undo
160 160
 				}
161 161
 			}
162 162
 			// print_copy_info ?
163
-			if ( $primary_registrant && ! $this->checkout->admin_request && count( $registrations ) > 1 ) {
163
+			if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) {
164 164
 				// TODO: add admin option for toggling copy attendee info, then use that value to change $this->_print_copy_info
165 165
 				$copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info
166 166
 					? $this->_copy_attendee_info_form()
167 167
 					: $this->_auto_copy_attendee_info();
168 168
 				// generate hidden input
169 169
 				if (
170
-					isset( $subsections[ $primary_registrant ] )
171
-				     && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper
170
+					isset($subsections[$primary_registrant])
171
+				     && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper
172 172
 				) {
173
-					$subsections[ $primary_registrant ]->add_subsections( $copy_options, 'primary_registrant', false );
173
+					$subsections[$primary_registrant]->add_subsections($copy_options, 'primary_registrant', false);
174 174
 				}
175 175
 			}
176 176
 
@@ -182,8 +182,7 @@  discard block
 block discarded – undo
182 182
 				'html_id' 					=> $this->reg_form_name(),
183 183
 				'subsections' 			=> $subsections,
184 184
 				'layout_strategy'		=> $this->checkout->admin_request ?
185
-					new EE_Div_Per_Section_Layout() :
186
-					new EE_Template_Layout(
185
+					new EE_Div_Per_Section_Layout() : new EE_Template_Layout(
187 186
 						array(
188 187
 							'layout_template_file' 	=> $this->_template, // layout_template
189 188
 							'template_args' 				=> $template_args
@@ -201,11 +200,11 @@  discard block
 block discarded – undo
201 200
 	 * @return EE_Form_Section_Base
202 201
 	 * @throws \EE_Error
203 202
 	 */
204
-	private function _registrations_reg_form( EE_Registration $registration ) {
203
+	private function _registrations_reg_form(EE_Registration $registration) {
205 204
 		static $attendee_nmbr = 1;
206 205
         $form_args = array();
207 206
 		// verify that registration has valid event
208
-		if ( $registration->event() instanceof EE_Event ) {
207
+		if ($registration->event() instanceof EE_Event) {
209 208
 			$question_groups = $registration->event()->question_groups(
210 209
                 array(
211 210
                     array(
@@ -215,10 +214,10 @@  discard block
 block discarded – undo
215 214
                     'order_by' => array('QSG_order' => 'ASC')
216 215
                 )
217 216
             );
218
-			if ( $question_groups ) {
217
+			if ($question_groups) {
219 218
                 // array of params to pass to parent constructor
220 219
                 $form_args = array(
221
-                    'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
220
+                    'html_id'         => 'ee-registration-'.$registration->reg_url_link(),
222 221
                     'html_class'      => 'ee-reg-form-attendee-dv',
223 222
                     'html_style'      => $this->checkout->admin_request
224 223
                         ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
@@ -231,9 +230,9 @@  discard block
 block discarded – undo
231 230
                         )
232 231
                     )
233 232
                 );
234
-                foreach ( $question_groups as $question_group ) {
235
-					if ( $question_group instanceof EE_Question_Group ) {
236
-						$form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form(
233
+                foreach ($question_groups as $question_group) {
234
+					if ($question_group instanceof EE_Question_Group) {
235
+						$form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form(
237 236
 							$registration,
238 237
 							$question_group
239 238
 						);
@@ -252,7 +251,7 @@  discard block
 block discarded – undo
252 251
             }
253 252
 		}
254 253
         $attendee_nmbr++;
255
-		return ! empty($form_args) ? new EE_Form_Section_Proper( $form_args ) : new EE_Form_Section_HTML();
254
+		return ! empty($form_args) ? new EE_Form_Section_Proper($form_args) : new EE_Form_Section_HTML();
256 255
 	}
257 256
 
258 257
 
@@ -273,7 +272,7 @@  discard block
 block discarded – undo
273 272
 		// generate hidden input
274 273
 		return new EE_Hidden_Input(
275 274
 			array(
276
-				'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
275
+				'html_id' => 'additional-attendee-reg-info-'.$registration->reg_url_link(),
277 276
 				'default' => $additional_attendee_reg_info
278 277
 			)
279 278
 		);
@@ -287,26 +286,26 @@  discard block
 block discarded – undo
287 286
 	 * @return EE_Form_Section_Proper
288 287
 	 * @throws \EE_Error
289 288
 	 */
290
-	private function _question_group_reg_form( EE_Registration $registration, EE_Question_Group $question_group ){
289
+	private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) {
291 290
 		// array of params to pass to parent constructor
292 291
 		$form_args = array(
293
-			'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier(),
292
+			'html_id'         => 'ee-reg-form-qstn-grp-'.$question_group->identifier(),
294 293
 			'html_class'      => $this->checkout->admin_request
295 294
 				? 'form-table ee-reg-form-qstn-grp-dv'
296 295
 				: 'ee-reg-form-qstn-grp-dv',
297
-			'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-lbl',
296
+			'html_label_id'   => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-lbl',
298 297
 			'subsections'     => array(
299
-				'reg_form_qstn_grp_hdr' => $this->_question_group_header( $question_group )
298
+				'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group)
300 299
 			),
301 300
 			'layout_strategy' => $this->checkout->admin_request
302 301
 				? new EE_Admin_Two_Column_Layout()
303 302
 				: new EE_Div_Per_Section_Layout()
304 303
 		);
305 304
 		// where params
306
-		$query_params = array( 'QST_deleted' => 0 );
305
+		$query_params = array('QST_deleted' => 0);
307 306
 		// don't load admin only questions on the frontend
308
-		if ( ! $this->checkout->admin_request ) {
309
-			$query_params['QST_admin_only'] = array( '!=', true );
307
+		if ( ! $this->checkout->admin_request) {
308
+			$query_params['QST_admin_only'] = array('!=', true);
310 309
 		}
311 310
 		$questions = $question_group->get_many_related(
312 311
 			'Question',
@@ -328,10 +327,10 @@  discard block
 block discarded – undo
328 327
 			)
329 328
 		);
330 329
 		// loop thru questions
331
-		foreach ( $questions as $question ) {
332
-			if( $question instanceof EE_Question ){
330
+		foreach ($questions as $question) {
331
+			if ($question instanceof EE_Question) {
333 332
 				$identifier = $question->is_system_question() ? $question->system_ID() : $question->ID();
334
-				$form_args['subsections'][ $identifier ] = $this->reg_form_question( $registration, $question );
333
+				$form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question);
335 334
 			}
336 335
 		}
337 336
 		$form_args['subsections'] = apply_filters(
@@ -352,7 +351,7 @@  discard block
 block discarded – undo
352 351
 			)
353 352
 		);
354 353
 //		d( $form_args );
355
-		$question_group_reg_form = new EE_Form_Section_Proper( $form_args );
354
+		$question_group_reg_form = new EE_Form_Section_Proper($form_args);
356 355
 		return apply_filters(
357 356
 			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
358 357
 			$question_group_reg_form,
@@ -369,11 +368,11 @@  discard block
 block discarded – undo
369 368
 	 * @param EE_Question_Group $question_group
370 369
 	 * @return 	EE_Form_Section_HTML
371 370
 	 */
372
-	private function _question_group_header( EE_Question_Group $question_group ){
371
+	private function _question_group_header(EE_Question_Group $question_group) {
373 372
 		$html = '';
374 373
 		// group_name
375
-		if ( $question_group->show_group_name() && $question_group->name() !== '' ) {
376
-			if ( $this->checkout->admin_request ) {
374
+		if ($question_group->show_group_name() && $question_group->name() !== '') {
375
+			if ($this->checkout->admin_request) {
377 376
 				$html .= EEH_HTML::br();
378 377
 				$html .= EEH_HTML::h3(
379 378
 					$question_group->name(),
@@ -387,7 +386,7 @@  discard block
 block discarded – undo
387 386
 			}
388 387
 		}
389 388
 		// group_desc
390
-		if ( $question_group->show_group_desc() && $question_group->desc() !== '' ) {
389
+		if ($question_group->show_group_desc() && $question_group->desc() !== '') {
391 390
 			$html .= EEH_HTML::p(
392 391
 				$question_group->desc(),
393 392
 				'',
@@ -397,7 +396,7 @@  discard block
 block discarded – undo
397 396
 			);
398 397
 
399 398
 		}
400
-		return new EE_Form_Section_HTML( $html );
399
+		return new EE_Form_Section_HTML($html);
401 400
 	}
402 401
 
403 402
 
@@ -407,7 +406,7 @@  discard block
 block discarded – undo
407 406
 	 * @return    EE_Form_Section_Proper
408 407
 	 * @throws \EE_Error
409 408
 	 */
410
-	private function _copy_attendee_info_form(){
409
+	private function _copy_attendee_info_form() {
411 410
 		// array of params to pass to parent constructor
412 411
 		return new EE_Form_Section_Proper(
413 412
 			array(
@@ -436,7 +435,7 @@  discard block
 block discarded – undo
436 435
 	private function _auto_copy_attendee_info() {
437 436
 		return new EE_Form_Section_HTML(
438 437
 			EEH_Template::locate_template(
439
-				SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php',
438
+				SPCO_REG_STEPS_PATH.$this->_slug.DS.'_auto_copy_attendee_info.template.php',
440 439
 				apply_filters(
441 440
 					'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
442 441
 					array()
@@ -460,32 +459,32 @@  discard block
 block discarded – undo
460 459
 		$copy_attendee_info_inputs = array();
461 460
 		$prev_ticket = NULL;
462 461
 		// grab the saved registrations from the transaction
463
-		$registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params );
464
-		foreach ( $registrations as $registration ) {
462
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
463
+		foreach ($registrations as $registration) {
465 464
 			// for all  attendees other than the primary attendee
466
-			if ( $registration instanceof EE_Registration && ! $registration->is_primary_registrant() ) {
465
+			if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) {
467 466
 				// if this is a new ticket OR if this is the very first additional attendee after the primary attendee
468
-				if ( $registration->ticket()->ID() !== $prev_ticket ) {
467
+				if ($registration->ticket()->ID() !== $prev_ticket) {
469 468
 					$item_name = $registration->ticket()->name();
470 469
 					$item_name .= $registration->ticket()->description() !== ''
471
-						? ' - ' . $registration->ticket()->description()
470
+						? ' - '.$registration->ticket()->description()
472 471
 						: '';
473
-					$copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] = new EE_Form_Section_HTML(
474
-						'<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>'
472
+					$copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID().']'] = new EE_Form_Section_HTML(
473
+						'<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>'
475 474
 					);
476 475
 					$prev_ticket = $registration->ticket()->ID();
477 476
 				}
478 477
 
479
-				$copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = new
478
+				$copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] = new
480 479
 				EE_Checkbox_Multi_Input(
481 480
 					array(
482 481
 						$registration->ID() => sprintf(
483
-							__( 'Attendee #%s', 'event_espresso' ),
482
+							__('Attendee #%s', 'event_espresso'),
484 483
 							$registration->count()
485 484
 						)
486 485
 					),
487 486
 					array(
488
-						'html_id'                 => 'spco-copy-attendee-chk-' . $registration->reg_url_link(),
487
+						'html_id'                 => 'spco-copy-attendee-chk-'.$registration->reg_url_link(),
489 488
 						'html_class'              => 'spco-copy-attendee-chk ee-do-not-validate',
490 489
 						'display_html_label_text' => false
491 490
 					)
@@ -505,7 +504,7 @@  discard block
 block discarded – undo
505 504
 	 * @return    EE_Form_Input_Base
506 505
 	 * @throws \EE_Error
507 506
 	 */
508
-	private function _additional_primary_registrant_inputs( EE_Registration $registration ){
507
+	private function _additional_primary_registrant_inputs(EE_Registration $registration) {
509 508
 		// generate hidden input
510 509
 		return new EE_Hidden_Input(
511 510
 			array(
@@ -524,7 +523,7 @@  discard block
 block discarded – undo
524 523
 	 * @return    EE_Form_Input_Base
525 524
 	 * @throws \EE_Error
526 525
 	 */
527
-	public function reg_form_question( EE_Registration $registration, EE_Question $question ){
526
+	public function reg_form_question(EE_Registration $registration, EE_Question $question) {
528 527
 
529 528
 		// if this question was for an attendee detail, then check for that answer
530 529
 		$answer_value = EEM_Answer::instance()->get_attendee_property_answer_value(
@@ -533,32 +532,32 @@  discard block
 block discarded – undo
533 532
 		);
534 533
 		$answer = $answer_value === null
535 534
 			? EEM_Answer::instance()->get_one(
536
-				array( array( 'QST_ID' => $question->ID(), 'REG_ID' => $registration->ID() ) )
535
+				array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
537 536
 			)
538 537
 			: null;
539 538
 		// if NOT returning to edit an existing registration
540 539
 		// OR if this question is for an attendee property
541 540
 		// OR we still don't have an EE_Answer object
542
-		if( $answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link() ) {
541
+		if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
543 542
 			// create an EE_Answer object for storing everything in
544
-			$answer = EE_Answer::new_instance ( array(
543
+			$answer = EE_Answer::new_instance(array(
545 544
 				'QST_ID'=> $question->ID(),
546 545
 				'REG_ID'=> $registration->ID()
547 546
 			));
548 547
 		}
549 548
 		// verify instance
550
-		if( $answer instanceof EE_Answer ){
551
-			if ( ! empty( $answer_value )) {
552
-				$answer->set( 'ANS_value', $answer_value );
549
+		if ($answer instanceof EE_Answer) {
550
+			if ( ! empty($answer_value)) {
551
+				$answer->set('ANS_value', $answer_value);
553 552
 			}
554
-			$answer->cache( 'Question', $question );
553
+			$answer->cache('Question', $question);
555 554
 			//remember system ID had a bug where sometimes it could be null
556
-			$answer_cache_id =$question->is_system_question()
557
-				? $question->system_ID() . '-' . $registration->reg_url_link()
558
-				: $question->ID() . '-' . $registration->reg_url_link();
559
-			$registration->cache( 'Answer', $answer, $answer_cache_id );
555
+			$answer_cache_id = $question->is_system_question()
556
+				? $question->system_ID().'-'.$registration->reg_url_link()
557
+				: $question->ID().'-'.$registration->reg_url_link();
558
+			$registration->cache('Answer', $answer, $answer_cache_id);
560 559
 		}
561
-		return $this->_generate_question_input( $registration, $question, $answer );
560
+		return $this->_generate_question_input($registration, $question, $answer);
562 561
 
563 562
 	}
564 563
 
@@ -571,46 +570,46 @@  discard block
 block discarded – undo
571 570
 	 * @return EE_Form_Input_Base
572 571
 	 * @throws \EE_Error
573 572
 	 */
574
-	private function _generate_question_input( EE_Registration $registration, EE_Question $question, $answer ){
573
+	private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) {
575 574
 		$identifier = $question->is_system_question() ? $question->system_ID() : $question->ID();
576
-		$this->_required_questions[ $identifier ] = $question->required() ? true : false;
575
+		$this->_required_questions[$identifier] = $question->required() ? true : false;
577 576
 		add_filter(
578 577
 			'FHEE__EE_Question__generate_form_input__country_options',
579
-			array( $this, 'use_cached_countries_for_form_input' ),
578
+			array($this, 'use_cached_countries_for_form_input'),
580 579
 			10,
581 580
 			4
582 581
 		);
583 582
 		add_filter(
584 583
 			'FHEE__EE_Question__generate_form_input__state_options',
585
-			array( $this, 'use_cached_states_for_form_input' ),
584
+			array($this, 'use_cached_states_for_form_input'),
586 585
 			10,
587 586
 			4
588 587
 		);
589 588
 		$input_constructor_args = array(
590
-			'html_name'     => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
591
-			'html_id'       => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
592
-			'html_class'    => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
593
-			'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
589
+			'html_name'     => 'ee_reg_qstn['.$registration->ID().']['.$identifier.']',
590
+			'html_id'       => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier,
591
+			'html_class'    => 'ee-reg-qstn ee-reg-qstn-'.$identifier,
592
+			'html_label_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier,
594 593
 			'html_label_class'	=> 'ee-reg-qstn',
595 594
 		);
596
-		$input_constructor_args['html_label_id'] 	.= '-lbl';
597
-		if ( $answer instanceof EE_Answer && $answer->ID() ) {
598
-			$input_constructor_args[ 'html_name' ] .= '[' . $answer->ID() . ']';
599
-			$input_constructor_args[ 'html_id' ] .= '-' . $answer->ID();
600
-			$input_constructor_args[ 'html_label_id' ] .= '-' . $answer->ID();
595
+		$input_constructor_args['html_label_id'] .= '-lbl';
596
+		if ($answer instanceof EE_Answer && $answer->ID()) {
597
+			$input_constructor_args['html_name'] .= '['.$answer->ID().']';
598
+			$input_constructor_args['html_id'] .= '-'.$answer->ID();
599
+			$input_constructor_args['html_label_id'] .= '-'.$answer->ID();
601 600
 		}
602
-		$form_input =  $question->generate_form_input(
601
+		$form_input = $question->generate_form_input(
603 602
 			$registration,
604 603
 			$answer,
605 604
 			$input_constructor_args
606 605
 		);
607 606
 		remove_filter(
608 607
 			'FHEE__EE_Question__generate_form_input__country_options',
609
-			array( $this, 'use_cached_countries_for_form_input' )
608
+			array($this, 'use_cached_countries_for_form_input')
610 609
 		);
611 610
 		remove_filter(
612 611
 			'FHEE__EE_Question__generate_form_input__state_options',
613
-			array( $this, 'use_cached_states_for_form_input' )
612
+			array($this, 'use_cached_states_for_form_input')
614 613
 		);
615 614
 		return $form_input;
616 615
 	}
@@ -632,22 +631,22 @@  discard block
 block discarded – undo
632 631
 		\EE_Registration $registration = null,
633 632
 		\EE_Answer $answer = null
634 633
 	) {
635
-		$country_options = array( '' => '' );
634
+		$country_options = array('' => '');
636 635
 		// get possibly cached list of countries
637 636
 		$countries = $this->checkout->action === 'process_reg_step'
638 637
 			? EEM_Country::instance()->get_all_countries()
639 638
 			: EEM_Country::instance()->get_all_active_countries();
640
-		if ( ! empty( $countries )) {
641
-			foreach( $countries as $country ){
642
-				if ( $country instanceof EE_Country ) {
643
-					$country_options[ $country->ID() ] = $country->name();
639
+		if ( ! empty($countries)) {
640
+			foreach ($countries as $country) {
641
+				if ($country instanceof EE_Country) {
642
+					$country_options[$country->ID()] = $country->name();
644 643
 				}
645 644
 			}
646 645
 		}
647
-		if( $question instanceof EE_Question
648
-			&& $registration instanceof EE_Registration ) {
646
+		if ($question instanceof EE_Question
647
+			&& $registration instanceof EE_Registration) {
649 648
 			$answer = EEM_Answer::instance()->get_one(
650
-				array( array( 'QST_ID' => $question->ID(), 'REG_ID' => $registration->ID() ) )
649
+				array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
651 650
 			);
652 651
 		} else {
653 652
 			$answer = EE_Answer::new_instance();
@@ -680,14 +679,14 @@  discard block
 block discarded – undo
680 679
 		\EE_Registration $registration = null,
681 680
 		\EE_Answer $answer = null
682 681
 	) {
683
-		$state_options = array( '' => array( '' => ''));
682
+		$state_options = array('' => array('' => ''));
684 683
 		$states = $this->checkout->action === 'process_reg_step'
685 684
 			? EEM_State::instance()->get_all_states()
686 685
 			: EEM_State::instance()->get_all_active_states();
687
-		if ( ! empty( $states )) {
688
-			foreach( $states as $state ){
689
-				if ( $state instanceof EE_State ) {
690
-					$state_options[ $state->country()->name() ][ $state->ID() ] = $state->name();
686
+		if ( ! empty($states)) {
687
+			foreach ($states as $state) {
688
+				if ($state instanceof EE_State) {
689
+					$state_options[$state->country()->name()][$state->ID()] = $state->name();
691 690
 				}
692 691
 			}
693 692
 		}
@@ -715,24 +714,24 @@  discard block
 block discarded – undo
715 714
 	 * @throws \EE_Error
716 715
 	 */
717 716
 	public function process_reg_step() {
718
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
717
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
719 718
 		// grab validated data from form
720 719
 		$valid_data = $this->checkout->current_step->valid_data();
721 720
 		// EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
722 721
 		// EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ );
723 722
 		// if we don't have any $valid_data then something went TERRIBLY WRONG !!!
724
-		if ( empty( $valid_data ))  {
723
+		if (empty($valid_data)) {
725 724
 			EE_Error::add_error(
726
-				__( 'No valid question responses were received.', 'event_espresso' ),
725
+				__('No valid question responses were received.', 'event_espresso'),
727 726
 				__FILE__,
728 727
 				__FUNCTION__,
729 728
 				__LINE__
730 729
 			);
731 730
 			return false;
732 731
 		}
733
-		if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg ) {
732
+		if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
734 733
 			EE_Error::add_error(
735
-				__( 'A valid transaction could not be initiated for processing your registrations.', 'event_espresso' ),
734
+				__('A valid transaction could not be initiated for processing your registrations.', 'event_espresso'),
736 735
 				__FILE__,
737 736
 				__FUNCTION__,
738 737
 				__LINE__
@@ -740,11 +739,11 @@  discard block
 block discarded – undo
740 739
 			return false;
741 740
 		}
742 741
 		// get cached registrations
743
-		$registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params );
742
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
744 743
 		// verify we got the goods
745
-		if ( empty( $registrations )) {
744
+		if (empty($registrations)) {
746 745
 			EE_Error::add_error(
747
-				__( 'Your form data could not be applied to any valid registrations.', 'event_espresso' ),
746
+				__('Your form data could not be applied to any valid registrations.', 'event_espresso'),
748 747
 				__FILE__,
749 748
 				__FUNCTION__,
750 749
 				__LINE__
@@ -752,15 +751,15 @@  discard block
 block discarded – undo
752 751
 			return false;
753 752
 		}
754 753
 		// extract attendee info from form data and save to model objects
755
-		$registrations_processed = $this->_process_registrations( $registrations, $valid_data );
754
+		$registrations_processed = $this->_process_registrations($registrations, $valid_data);
756 755
 		// if first pass thru SPCO,
757 756
 		// then let's check processed registrations against the total number of tickets in the cart
758
-		if ( $registrations_processed === false ) {
757
+		if ($registrations_processed === false) {
759 758
 			// but return immediately if the previous step exited early due to errors
760 759
 			return false;
761
-		} else if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count ) {
760
+		} else if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
762 761
 			// generate a correctly translated string for all possible singular/plural combinations
763
-			if ( $this->checkout->total_ticket_count === 1 && $registrations_processed !== 1 ) {
762
+			if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
764 763
 				$error_msg = sprintf(
765 764
 					__(
766 765
 						'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
@@ -769,7 +768,7 @@  discard block
 block discarded – undo
769 768
 					$this->checkout->total_ticket_count,
770 769
 					$registrations_processed
771 770
 				);
772
-			} else if ( $this->checkout->total_ticket_count !== 1 && $registrations_processed === 1 ) {
771
+			} else if ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
773 772
 				$error_msg = sprintf(
774 773
 					__(
775 774
 						'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
@@ -788,17 +787,17 @@  discard block
 block discarded – undo
788 787
 					$registrations_processed
789 788
 				);
790 789
 			}
791
-			EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ );
790
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
792 791
 			return false;
793 792
 		}
794 793
 		// mark this reg step as completed
795 794
 		$this->set_completed();
796 795
 		$this->_set_success_message(
797
-			__( 'The Attendee Information Step has been successfully completed.', 'event_espresso' )
796
+			__('The Attendee Information Step has been successfully completed.', 'event_espresso')
798 797
 		);
799 798
 		//do action in case a plugin wants to do something with the data submitted in step 1.
800 799
 		//passes EE_Single_Page_Checkout, and it's posted data
801
-		do_action( 'AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data );
800
+		do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
802 801
 		return true;
803 802
 	}
804 803
 
@@ -812,9 +811,9 @@  discard block
 block discarded – undo
812 811
 	 * @return boolean | int
813 812
 	 * @throws \EE_Error
814 813
 	 */
815
-	private function _process_registrations( $registrations = array(), $valid_data = array() ) {
814
+	private function _process_registrations($registrations = array(), $valid_data = array()) {
816 815
 		// load resources and set some defaults
817
-		EE_Registry::instance()->load_model( 'Attendee' );
816
+		EE_Registry::instance()->load_model('Attendee');
818 817
 		// holder for primary registrant attendee object
819 818
 		$this->checkout->primary_attendee_obj = NULL;
820 819
 		// array for tracking reg form data for the primary registrant
@@ -831,9 +830,9 @@  discard block
 block discarded – undo
831 830
 		// attendee counter
832 831
 		$att_nmbr = 0;
833 832
 		// grab the saved registrations from the transaction
834
-		foreach ( $registrations  as $registration ) {
833
+		foreach ($registrations  as $registration) {
835 834
 			// verify EE_Registration object
836
-			if ( ! $registration instanceof EE_Registration ) {
835
+			if ( ! $registration instanceof EE_Registration) {
837 836
 				EE_Error::add_error(
838 837
 					__(
839 838
 						'An invalid Registration object was discovered when attempting to process your registration information.',
@@ -848,12 +847,12 @@  discard block
 block discarded – undo
848 847
 			/** @var string $reg_url_link */
849 848
 			$reg_url_link = $registration->reg_url_link();
850 849
 			// reg_url_link exists ?
851
-			if ( ! empty( $reg_url_link ) ) {
850
+			if ( ! empty($reg_url_link)) {
852 851
 				// should this registration be processed during this visit ?
853
-				if ( $this->checkout->visit_allows_processing_of_this_registration( $registration ) ) {
852
+				if ($this->checkout->visit_allows_processing_of_this_registration($registration)) {
854 853
 					// if NOT revisiting, then let's save the registration now,
855 854
 					// so that we have a REG_ID to use when generating other objects
856
-					if ( ! $this->checkout->revisit ) {
855
+					if ( ! $this->checkout->revisit) {
857 856
 						$registration->save();
858 857
 					}
859 858
 					/**
@@ -863,7 +862,7 @@  discard block
 block discarded – undo
863 862
 					 * @var bool   if true is returned by the plugin then the
864 863
 					 *      		registration processing is halted.
865 864
 					 */
866
-					if ( apply_filters(
865
+					if (apply_filters(
867 866
 						'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
868 867
 						false,
869 868
 						$att_nmbr,
@@ -871,38 +870,38 @@  discard block
 block discarded – undo
871 870
 						$registrations,
872 871
 						$valid_data,
873 872
 						$this
874
-					) ) {
873
+					)) {
875 874
 						return false;
876 875
 					}
877 876
 
878 877
 					// Houston, we have a registration!
879 878
 					$att_nmbr++;
880
-					$this->_attendee_data[ $reg_url_link ] = array();
879
+					$this->_attendee_data[$reg_url_link] = array();
881 880
 					// grab any existing related answer objects
882 881
 					$this->_registration_answers = $registration->answers();
883 882
 					// unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] );
884
-					if ( isset( $valid_data[ $reg_url_link ] ) ) {
883
+					if (isset($valid_data[$reg_url_link])) {
885 884
 						// do we need to copy basic info from primary attendee ?
886
-						$copy_primary = isset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] )
887
-						                && absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0
885
+						$copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info'])
886
+						                && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0
888 887
 							? true
889 888
 							: false;
890 889
 						// filter form input data for this registration
891
-						$valid_data[ $reg_url_link ] = (array)apply_filters(
890
+						$valid_data[$reg_url_link] = (array) apply_filters(
892 891
 							'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
893
-							$valid_data[ $reg_url_link ]
892
+							$valid_data[$reg_url_link]
894 893
 						);
895 894
 						// EEH_Debug_Tools::printr( $valid_data[ $reg_url_link ], '$valid_data[ $reg_url_link ]', __FILE__, __LINE__ );
896
-						if ( isset( $valid_data['primary_attendee'] )) {
897
-							$primary_registrant['line_item_id'] =  ! empty( $valid_data['primary_attendee'] )
895
+						if (isset($valid_data['primary_attendee'])) {
896
+							$primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee'])
898 897
 								? $valid_data['primary_attendee']
899 898
 								: false;
900
-							unset( $valid_data['primary_attendee'] );
899
+							unset($valid_data['primary_attendee']);
901 900
 						}
902 901
 						// now loop through our array of valid post data && process attendee reg forms
903
-						foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) {
904
-							if ( ! in_array( $form_section, $non_input_form_sections )) {
905
-								foreach ( $form_inputs as $form_input => $input_value ) {
902
+						foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) {
903
+							if ( ! in_array($form_section, $non_input_form_sections)) {
904
+								foreach ($form_inputs as $form_input => $input_value) {
906 905
 									// \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ );
907 906
 									// check for critical inputs
908 907
 									if (
@@ -916,16 +915,16 @@  discard block
 block discarded – undo
916 915
 									// store a bit of data about the primary attendee
917 916
 									if (
918 917
 										$att_nmbr === 1
919
-										&& ! empty( $input_value )
918
+										&& ! empty($input_value)
920 919
 										&& $reg_url_link === $primary_registrant['line_item_id']
921 920
 									) {
922
-										$primary_registrant[ $form_input ] = $input_value;
921
+										$primary_registrant[$form_input] = $input_value;
923 922
 									} else if (
924 923
 										$copy_primary
925 924
 										&& $input_value === null
926
-										&& isset( $primary_registrant[ $form_input ] )
925
+										&& isset($primary_registrant[$form_input])
927 926
 									) {
928
-										$input_value = $primary_registrant[ $form_input ];
927
+										$input_value = $primary_registrant[$form_input];
929 928
 									}
930 929
 									// now attempt to save the input data
931 930
 									if (
@@ -967,55 +966,55 @@  discard block
 block discarded – undo
967 966
 						// have we met before?
968 967
 						$attendee = $this->_find_existing_attendee(
969 968
 							$registration,
970
-							$this->_attendee_data[ $reg_url_link ]
969
+							$this->_attendee_data[$reg_url_link]
971 970
 						);
972 971
 						// did we find an already existing record for this attendee ?
973
-						if ( $attendee instanceof EE_Attendee ) {
972
+						if ($attendee instanceof EE_Attendee) {
974 973
 							$attendee = $this->_update_existing_attendee_data(
975 974
 								$attendee,
976
-								$this->_attendee_data[ $reg_url_link ]
975
+								$this->_attendee_data[$reg_url_link]
977 976
 							);
978 977
 						} else {
979 978
 							// ensure critical details are set for additional attendees
980
-							$this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1
979
+							$this->_attendee_data[$reg_url_link] = $att_nmbr > 1
981 980
 								? $this->_copy_critical_attendee_details_from_primary_registrant(
982
-									$this->_attendee_data[ $reg_url_link ]
981
+									$this->_attendee_data[$reg_url_link]
983 982
 								)
984
-								: $this->_attendee_data[ $reg_url_link ];
983
+								: $this->_attendee_data[$reg_url_link];
985 984
 							$attendee = $this->_create_new_attendee(
986 985
 								$registration,
987
-								$this->_attendee_data[ $reg_url_link ]
986
+								$this->_attendee_data[$reg_url_link]
988 987
 							);
989 988
 						}
990 989
 						// who's #1 ?
991
-						if ( $att_nmbr === 1 ) {
990
+						if ($att_nmbr === 1) {
992 991
 							$this->checkout->primary_attendee_obj = $attendee;
993 992
 						}
994 993
 					}
995 994
 					// EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ );
996 995
 					// add relation to registration, set attendee ID, and cache attendee
997
-					$this->_associate_attendee_with_registration( $registration, $attendee );
996
+					$this->_associate_attendee_with_registration($registration, $attendee);
998 997
 					// \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ );
999
-					if ( ! $registration->attendee() instanceof EE_Attendee ) {
1000
-						EE_Error::add_error( sprintf( __( 'Registration %s has an invalid or missing Attendee object.', 'event_espresso' ), $reg_url_link ), __FILE__, __FUNCTION__, __LINE__ );
998
+					if ( ! $registration->attendee() instanceof EE_Attendee) {
999
+						EE_Error::add_error(sprintf(__('Registration %s has an invalid or missing Attendee object.', 'event_espresso'), $reg_url_link), __FILE__, __FUNCTION__, __LINE__);
1001 1000
 						return false;
1002 1001
 					}
1003 1002
 					/** @type EE_Registration_Processor $registration_processor */
1004
-					$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
1003
+					$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1005 1004
 					// at this point, we should have enough details about the registrant to consider the registration NOT incomplete
1006
-					$registration_processor->toggle_incomplete_registration_status_to_default( $registration, false );
1005
+					$registration_processor->toggle_incomplete_registration_status_to_default($registration, false);
1007 1006
 					// we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned
1008 1007
 					$this->checkout->transaction->toggle_failed_transaction_status();
1009 1008
 					// if we've gotten this far, then let's save what we have
1010 1009
 					$registration->save();
1011 1010
 					// add relation between TXN and registration
1012
-					$this->_associate_registration_with_transaction( $registration );
1011
+					$this->_associate_registration_with_transaction($registration);
1013 1012
 				} // end of if ( ! $this->checkout->revisit || $this->checkout->primary_revisit || ( $this->checkout->revisit && $this->checkout->reg_url_link == $reg_url_link )) {
1014 1013
 
1015
-			}  else {
1016
-				EE_Error::add_error( __( 'An invalid or missing line item ID was encountered while attempting to process the registration form.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
1014
+			} else {
1015
+				EE_Error::add_error(__('An invalid or missing line item ID was encountered while attempting to process the registration form.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1017 1016
 				// remove malformed data
1018
-				unset( $valid_data[ $reg_url_link ] );
1017
+				unset($valid_data[$reg_url_link]);
1019 1018
 				return false;
1020 1019
 			}
1021 1020
 
@@ -1044,14 +1043,14 @@  discard block
 block discarded – undo
1044 1043
 		// \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ );
1045 1044
 		// allow for plugins to hook in and do their own processing of the form input.
1046 1045
 		// For plugins to bypass normal processing here, they just need to return a boolean value.
1047
-		if ( apply_filters(
1046
+		if (apply_filters(
1048 1047
 			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
1049 1048
 			false,
1050 1049
 			$registration,
1051 1050
 			$form_input,
1052 1051
 			$input_value,
1053 1052
 			$this
1054
-		) ) {
1053
+		)) {
1055 1054
 			return true;
1056 1055
 		}
1057 1056
         /*
@@ -1059,14 +1058,14 @@  discard block
 block discarded – undo
1059 1058
          * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477
1060 1059
          */
1061 1060
 		$answer_cache_id = $this->checkout->reg_url_link
1062
-			? $form_input . '-' . $registration->reg_url_link()
1061
+			? $form_input.'-'.$registration->reg_url_link()
1063 1062
 			: $form_input;
1064
-		$answer_is_obj = isset( $this->_registration_answers[ $answer_cache_id ] )
1065
-		                 && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer
1063
+		$answer_is_obj = isset($this->_registration_answers[$answer_cache_id])
1064
+		                 && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer
1066 1065
 			? true
1067 1066
 			: false;
1068 1067
 		//rename form_inputs if they are EE_Attendee properties
1069
-		switch( (string)$form_input ) {
1068
+		switch ((string) $form_input) {
1070 1069
 
1071 1070
 			case 'state' :
1072 1071
 			case 'STA_ID' :
@@ -1081,32 +1080,32 @@  discard block
 block discarded – undo
1081 1080
 				break;
1082 1081
 
1083 1082
 			default :
1084
-				$ATT_input = 'ATT_' . $form_input;
1083
+				$ATT_input = 'ATT_'.$form_input;
1085 1084
 				//EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ );
1086
-				$attendee_property = EEM_Attendee::instance()->has_field( $ATT_input ) ? true : false;
1087
-				$form_input = $attendee_property ? 'ATT_' . $form_input : $form_input;
1085
+				$attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false;
1086
+				$form_input = $attendee_property ? 'ATT_'.$form_input : $form_input;
1088 1087
 		}
1089 1088
 		// EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ );
1090 1089
 		// EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ );
1091 1090
 		// EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ );
1092 1091
 		// if this form input has a corresponding attendee property
1093
-		if ( $attendee_property ) {
1094
-			$this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value;
1095
-			if ( $answer_is_obj ) {
1092
+		if ($attendee_property) {
1093
+			$this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value;
1094
+			if ($answer_is_obj) {
1096 1095
 				// and delete the corresponding answer since we won't be storing this data in that object
1097
-				$registration->_remove_relation_to( $this->_registration_answers[ $answer_cache_id ], 'Answer' );
1098
-				$this->_registration_answers[ $answer_cache_id ]->delete_permanently();
1096
+				$registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer');
1097
+				$this->_registration_answers[$answer_cache_id]->delete_permanently();
1099 1098
 			}
1100 1099
 			return true;
1101
-		} elseif ( $answer_is_obj ) {
1100
+		} elseif ($answer_is_obj) {
1102 1101
 			// save this data to the answer object
1103
-			$this->_registration_answers[ $answer_cache_id ]->set_value( $input_value );
1104
-			$result = $this->_registration_answers[ $answer_cache_id ]->save();
1102
+			$this->_registration_answers[$answer_cache_id]->set_value($input_value);
1103
+			$result = $this->_registration_answers[$answer_cache_id]->save();
1105 1104
 			return $result !== false ? true : false;
1106 1105
 		} else {
1107
-			foreach ( $this->_registration_answers as $answer ) {
1108
-				if ( $answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id ) {
1109
-					$answer->set_value( $input_value );
1106
+			foreach ($this->_registration_answers as $answer) {
1107
+				if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) {
1108
+					$answer->set_value($input_value);
1110 1109
 					$result = $answer->save();
1111 1110
 					return $result !== false ? true : false;
1112 1111
 				}
@@ -1128,15 +1127,15 @@  discard block
 block discarded – undo
1128 1127
 		$form_input = '',
1129 1128
 		$input_value = ''
1130 1129
 	) {
1131
-		if ( empty( $input_value ) ) {
1130
+		if (empty($input_value)) {
1132 1131
 			// if the form input isn't marked as being required, then just return
1133
-			if ( ! isset( $this->_required_questions[ $form_input ] ) || ! $this->_required_questions[ $form_input ] ) {
1132
+			if ( ! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) {
1134 1133
 				return true;
1135 1134
 			}
1136
-			switch ( $form_input ) {
1135
+			switch ($form_input) {
1137 1136
 				case 'fname' :
1138 1137
 					EE_Error::add_error(
1139
-						__( 'First Name is a required value.', 'event_espresso' ),
1138
+						__('First Name is a required value.', 'event_espresso'),
1140 1139
 						__FILE__,
1141 1140
 						__FUNCTION__,
1142 1141
 						__LINE__
@@ -1145,7 +1144,7 @@  discard block
 block discarded – undo
1145 1144
 					break;
1146 1145
 				case 'lname' :
1147 1146
 					EE_Error::add_error(
1148
-						__( 'Last Name is a required value.', 'event_espresso' ),
1147
+						__('Last Name is a required value.', 'event_espresso'),
1149 1148
 						__FILE__,
1150 1149
 						__FUNCTION__,
1151 1150
 						__LINE__
@@ -1154,7 +1153,7 @@  discard block
 block discarded – undo
1154 1153
 					break;
1155 1154
 				case 'email' :
1156 1155
 					EE_Error::add_error(
1157
-						__( 'Please enter a valid email address.', 'event_espresso' ),
1156
+						__('Please enter a valid email address.', 'event_espresso'),
1158 1157
 						__FILE__,
1159 1158
 						__FUNCTION__,
1160 1159
 						__LINE__
@@ -1176,30 +1175,30 @@  discard block
 block discarded – undo
1176 1175
 	 * @return boolean|EE_Attendee
1177 1176
 	 * @throws \EE_Error
1178 1177
 	 */
1179
-	private function _find_existing_attendee( EE_Registration $registration, $attendee_data = array() ) {
1178
+	private function _find_existing_attendee(EE_Registration $registration, $attendee_data = array()) {
1180 1179
 		$existing_attendee = null;
1181 1180
 		// if none of the critical properties are set in the incoming attendee data...
1182 1181
 		// then attempt to copy them from the primary attendee
1183 1182
 		if (
1184 1183
 			$this->checkout->primary_attendee_obj instanceof EE_Attendee
1185
-            && ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] )
1184
+            && ! isset($attendee_data['ATT_fname'], $attendee_data['ATT_email'])
1186 1185
 		) {
1187 1186
 			return $this->checkout->primary_attendee_obj;
1188 1187
 		}
1189 1188
 		// does this attendee already exist in the db ?
1190 1189
 		// we're searching using a combination of first name, last name, AND email address
1191
-		$ATT_fname = isset( $attendee_data['ATT_fname'] ) && ! empty( $attendee_data['ATT_fname'] )
1190
+		$ATT_fname = isset($attendee_data['ATT_fname']) && ! empty($attendee_data['ATT_fname'])
1192 1191
 			? $attendee_data['ATT_fname']
1193 1192
 			: '';
1194
-		$ATT_lname = isset( $attendee_data['ATT_lname'] ) && ! empty( $attendee_data['ATT_lname'] )
1193
+		$ATT_lname = isset($attendee_data['ATT_lname']) && ! empty($attendee_data['ATT_lname'])
1195 1194
 			? $attendee_data['ATT_lname']
1196 1195
 			: '';
1197
-		$ATT_email = isset( $attendee_data['ATT_email'] ) && ! empty( $attendee_data['ATT_email'] )
1196
+		$ATT_email = isset($attendee_data['ATT_email']) && ! empty($attendee_data['ATT_email'])
1198 1197
 			? $attendee_data['ATT_email']
1199 1198
 			: '';
1200 1199
 		// but only if those have values
1201
-		if ( $ATT_fname && $ATT_lname && $ATT_email ) {
1202
-			$existing_attendee = EEM_Attendee::instance()->find_existing_attendee( array(
1200
+		if ($ATT_fname && $ATT_lname && $ATT_email) {
1201
+			$existing_attendee = EEM_Attendee::instance()->find_existing_attendee(array(
1203 1202
 				'ATT_fname' => $ATT_fname,
1204 1203
 				'ATT_lname' => $ATT_lname,
1205 1204
 				'ATT_email' => $ATT_email
@@ -1223,13 +1222,13 @@  discard block
 block discarded – undo
1223 1222
 	 * @return \EE_Attendee
1224 1223
 	 * @throws \EE_Error
1225 1224
 	 */
1226
-	private function _update_existing_attendee_data( EE_Attendee $existing_attendee, $attendee_data = array() ) {
1225
+	private function _update_existing_attendee_data(EE_Attendee $existing_attendee, $attendee_data = array()) {
1227 1226
 		// first remove fname, lname, and email from attendee data
1228
-		$dont_set = array( 'ATT_fname', 'ATT_lname', 'ATT_email' );
1227
+		$dont_set = array('ATT_fname', 'ATT_lname', 'ATT_email');
1229 1228
 		// now loop thru what's left and add to attendee CPT
1230
-		foreach ( $attendee_data as $property_name => $property_value ) {
1231
-			if ( ! in_array( $property_name, $dont_set ) && EEM_Attendee::instance()->has_field( $property_name )) {
1232
-				$existing_attendee->set( $property_name, $property_value );
1229
+		foreach ($attendee_data as $property_name => $property_value) {
1230
+			if ( ! in_array($property_name, $dont_set) && EEM_Attendee::instance()->has_field($property_name)) {
1231
+				$existing_attendee->set($property_name, $property_value);
1233 1232
 			}
1234 1233
 		}
1235 1234
 		// better save that now
@@ -1247,11 +1246,11 @@  discard block
 block discarded – undo
1247 1246
 	 * @return void
1248 1247
 	 * @throws \EE_Error
1249 1248
 	 */
1250
-	private function _associate_attendee_with_registration( EE_Registration $registration, EE_Attendee $attendee ) {
1249
+	private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) {
1251 1250
 		// add relation to attendee
1252
-		$registration->_add_relation_to( $attendee, 'Attendee' );
1253
-		$registration->set_attendee_id( $attendee->ID() );
1254
-		$registration->update_cache_after_object_save( 'Attendee', $attendee );
1251
+		$registration->_add_relation_to($attendee, 'Attendee');
1252
+		$registration->set_attendee_id($attendee->ID());
1253
+		$registration->update_cache_after_object_save('Attendee', $attendee);
1255 1254
 	}
1256 1255
 
1257 1256
 
@@ -1263,10 +1262,10 @@  discard block
 block discarded – undo
1263 1262
 	 * @return void
1264 1263
 	 * @throws \EE_Error
1265 1264
 	 */
1266
-	private function _associate_registration_with_transaction( EE_Registration $registration ) {
1265
+	private function _associate_registration_with_transaction(EE_Registration $registration) {
1267 1266
 		// add relation to attendee
1268
-		$this->checkout->transaction->_add_relation_to( $registration, 'Registration' );
1269
-		$this->checkout->transaction->update_cache_after_object_save( 'Registration', $registration );
1267
+		$this->checkout->transaction->_add_relation_to($registration, 'Registration');
1268
+		$this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
1270 1269
 	}
1271 1270
 
1272 1271
 
@@ -1279,14 +1278,14 @@  discard block
 block discarded – undo
1279 1278
 	 * @return array
1280 1279
 	 * @throws \EE_Error
1281 1280
 	 */
1282
-	private function _copy_critical_attendee_details_from_primary_registrant( $attendee_data = array() ) {
1281
+	private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) {
1283 1282
 		// bare minimum critical details include first name, last name, email address
1284
-		$critical_attendee_details = array( 'ATT_fname', 'ATT_lname', 'ATT_email' );
1283
+		$critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email');
1285 1284
 		// add address info to critical details?
1286
-		if ( apply_filters(
1285
+		if (apply_filters(
1287 1286
 			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
1288 1287
 			false
1289
-		) ) {
1288
+		)) {
1290 1289
 			$address_details = array(
1291 1290
 				'ATT_address',
1292 1291
 				'ATT_address2',
@@ -1296,13 +1295,13 @@  discard block
 block discarded – undo
1296 1295
 				'ATT_zip',
1297 1296
 				'ATT_phone'
1298 1297
 			);
1299
-			$critical_attendee_details = array_merge( $critical_attendee_details, $address_details );
1298
+			$critical_attendee_details = array_merge($critical_attendee_details, $address_details);
1300 1299
 		}
1301
-		foreach ( $critical_attendee_details as $critical_attendee_detail ) {
1302
-			if ( ! isset( $attendee_data[ $critical_attendee_detail ] )
1303
-			     || empty( $attendee_data[ $critical_attendee_detail ] )
1300
+		foreach ($critical_attendee_details as $critical_attendee_detail) {
1301
+			if ( ! isset($attendee_data[$critical_attendee_detail])
1302
+			     || empty($attendee_data[$critical_attendee_detail])
1304 1303
 			) {
1305
-				$attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get(
1304
+				$attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get(
1306 1305
 					$critical_attendee_detail
1307 1306
 				);
1308 1307
 			}
@@ -1320,11 +1319,11 @@  discard block
 block discarded – undo
1320 1319
 	 * @return \EE_Attendee
1321 1320
 	 * @throws \EE_Error
1322 1321
 	 */
1323
-	private function _create_new_attendee( EE_Registration $registration, $attendee_data = array() ) {
1322
+	private function _create_new_attendee(EE_Registration $registration, $attendee_data = array()) {
1324 1323
 		// create new attendee object
1325
-		$new_attendee = EE_Attendee::new_instance( $attendee_data );
1324
+		$new_attendee = EE_Attendee::new_instance($attendee_data);
1326 1325
 		// set author to event creator
1327
-		$new_attendee->set( 'ATT_author', $registration->event()->wp_user() );
1326
+		$new_attendee->set('ATT_author', $registration->event()->wp_user());
1328 1327
 		$new_attendee->save();
1329 1328
 		return $new_attendee;
1330 1329
 	}
@@ -1341,7 +1340,7 @@  discard block
 block discarded – undo
1341 1340
 	 */
1342 1341
 	public function update_reg_step() {
1343 1342
 		// save everything
1344
-		if ( $this->process_reg_step() ) {
1343
+		if ($this->process_reg_step()) {
1345 1344
 			$this->checkout->redirect = true;
1346 1345
 			$this->checkout->redirect_url = add_query_arg(
1347 1346
 				array(
@@ -1350,7 +1349,7 @@  discard block
 block discarded – undo
1350 1349
 				),
1351 1350
 				$this->checkout->thank_you_page_url
1352 1351
 			);
1353
-			$this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url );
1352
+			$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1354 1353
 			return true;
1355 1354
 		}
1356 1355
 		return false;
Please login to merge, or discard this patch.
templates/reg_admin_details_main_meta_box_reg_details.template.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,36 +1,36 @@
 block discarded – undo
1 1
 <div id="admin-primary-mbox-reg-details-dv" class="admin-primary-mbox-dv">
2 2
 
3
-	<?php do_action( 'AHEE__reg_admin_details_main_meta_box_reg_details__top', $REG_ID ); ?>
3
+	<?php do_action('AHEE__reg_admin_details_main_meta_box_reg_details__top', $REG_ID); ?>
4 4
 	<?php echo $resend_registration_button; ?>
5 5
 	<?php echo $view_transaction_button; ?>
6 6
 	<br/>
7 7
 
8
-	<h3 class="admin-primary-mbox-h4 hdr-has-icon"><span class="dashicons dashicons-clipboard"></span><?php _e( 'Registration Items', 'event_espresso' );?></h3>
8
+	<h3 class="admin-primary-mbox-h4 hdr-has-icon"><span class="dashicons dashicons-clipboard"></span><?php _e('Registration Items', 'event_espresso'); ?></h3>
9 9
 
10 10
 	<?php echo $line_item_table; ?>
11 11
 
12 12
 	<a id="display-additional-registration-session-info" class="display-the-hidden smaller-text" rel="additional-registration-session-info">
13
-		<span class="dashicons dashicons-plus-alt"></span><?php _e( 'view additional registration session details', 'event_espresso' );?>
13
+		<span class="dashicons dashicons-plus-alt"></span><?php _e('view additional registration session details', 'event_espresso'); ?>
14 14
 	</a>
15 15
 
16 16
 	<div id="additional-registration-session-info-dv" class="hidden">
17 17
 
18 18
 		<a id="hide-additional-registration-session-info" class="hide-the-displayed hidden smaller-text" rel="additional-registration-session-info">
19
-			<span class="dashicons dashicons-dismiss"></span><?php _e( 'hide additional registration session details', 'event_espresso' );?>
19
+			<span class="dashicons dashicons-dismiss"></span><?php _e('hide additional registration session details', 'event_espresso'); ?>
20 20
 		</a>
21 21
 	<br class="clear"/>
22 22
 
23
-		<h3 class="admin-primary-mbox-h4"><?php _e( 'Registration Session Details', 'event_espresso' );?></h3>
23
+		<h3 class="admin-primary-mbox-h4"><?php _e('Registration Session Details', 'event_espresso'); ?></h3>
24 24
 
25 25
 		<table id="admin-primary-mbox-reg-extra-session-info-tbl" class="form-table skinny-rows">
26 26
 			<tbody>
27
-			<?php foreach ( $reg_details as $key => $reg_detail ) : ?>
27
+			<?php foreach ($reg_details as $key => $reg_detail) : ?>
28 28
 				<tr>
29 29
 					<th>
30
-						<label for="<?php echo $key;?>"><?php echo $reg_detail['label'];?></label>
30
+						<label for="<?php echo $key; ?>"><?php echo $reg_detail['label']; ?></label>
31 31
 					</th>
32 32
 					<td>
33
-						<?php echo $reg_detail['value'];?>
33
+						<?php echo $reg_detail['value']; ?>
34 34
 					</td>
35 35
 				</tr>
36 36
 			<?php endforeach; // $reg_details?>
Please login to merge, or discard this patch.
core/db_models/EEM_Line_Item.model.php 3 patches
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -105,41 +105,41 @@  discard block
 block discarded – undo
105 105
 	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
106 106
 	 * @return \EEM_Line_Item
107 107
 	 */
108
-	protected function __construct( $timezone ) {
109
-		$this->singular_item = __('Line Item','event_espresso');
110
-		$this->plural_item = __('Line Items','event_espresso');
108
+	protected function __construct($timezone) {
109
+		$this->singular_item = __('Line Item', 'event_espresso');
110
+		$this->plural_item = __('Line Items', 'event_espresso');
111 111
 
112 112
 		$this->_tables = array(
113
-			'Line_Item'=>new EE_Primary_Table('esp_line_item','LIN_ID')
113
+			'Line_Item'=>new EE_Primary_Table('esp_line_item', 'LIN_ID')
114 114
 		);
115
-		$line_items_can_be_for = apply_filters( 'FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket','Price', 'Event' ) );
115
+		$line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event'));
116 116
 		$this->_fields = array(
117 117
 			'Line_Item' => array(
118
-				'LIN_ID' 				=> new EE_Primary_Key_Int_Field( 'LIN_ID', __( "ID", "event_espresso" ) ),
119
-				'LIN_code' 			=> new EE_Slug_Field( 'LIN_code', __( "Code for index into Cart", "event_espresso" ), TRUE ),
120
-				'TXN_ID' 				=> new EE_Foreign_Key_Int_Field( 'TXN_ID', __( "Transaction ID", "event_espresso" ), TRUE, NULL, 'Transaction' ),
121
-				'LIN_name' 			=> new EE_Full_HTML_Field( 'LIN_name', __( "Line Item Name", "event_espresso" ), FALSE, '' ),
122
-				'LIN_desc' 			=> new EE_Full_HTML_Field( 'LIN_desc', __( "Line Item Description", "event_espresso" ), TRUE ),
123
-				'LIN_unit_price' 	=> new EE_Money_Field( 'LIN_unit_price', __( "Unit Price", "event_espresso" ), FALSE, 0 ),
124
-				'LIN_percent' 		=> new EE_Float_Field( 'LIN_percent', __( "Percent", "event_espresso" ), FALSE, 0 ),
125
-				'LIN_is_taxable' 	=> new EE_Boolean_Field( 'LIN_is_taxable', __( "Taxable", "event_espresso" ), FALSE, FALSE ),
126
-				'LIN_order' 			=> new EE_Integer_Field( 'LIN_order', __( "Order of Application towards total of parent", "event_espresso" ), FALSE, 1 ),
127
-				'LIN_total' 			=> new EE_Money_Field( 'LIN_total', __( "Total (unit price x quantity)", "event_espresso" ), FALSE, 0 ),
128
-				'LIN_quantity' 	=> new EE_Integer_Field( 'LIN_quantity', __( "Quantity", "event_espresso" ), TRUE, 1 ),
129
-				'LIN_parent' 		=> new EE_Integer_Field( 'LIN_parent', __( "Parent ID (this item goes towards that Line Item's total)", "event_espresso" ), TRUE, NULL ),
130
-				'LIN_type' 			=> new EE_Enum_Text_Field( 'LIN_type', __( "Type", "event_espresso" ), FALSE, 'line-item', array(
118
+				'LIN_ID' 				=> new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")),
119
+				'LIN_code' 			=> new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), TRUE),
120
+				'TXN_ID' 				=> new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), TRUE, NULL, 'Transaction'),
121
+				'LIN_name' 			=> new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), FALSE, ''),
122
+				'LIN_desc' 			=> new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), TRUE),
123
+				'LIN_unit_price' 	=> new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), FALSE, 0),
124
+				'LIN_percent' 		=> new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), FALSE, 0),
125
+				'LIN_is_taxable' 	=> new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), FALSE, FALSE),
126
+				'LIN_order' 			=> new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), FALSE, 1),
127
+				'LIN_total' 			=> new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), FALSE, 0),
128
+				'LIN_quantity' 	=> new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), TRUE, 1),
129
+				'LIN_parent' 		=> new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), TRUE, NULL),
130
+				'LIN_type' 			=> new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), FALSE, 'line-item', array(
131 131
 						self::type_line_item		=>  __("Line Item", "event_espresso"),
132 132
 						self::type_sub_line_item	=>  __("Sub-Item", "event_espresso"),
133 133
 						self::type_sub_total		=>  __("Subtotal", "event_espresso"),
134 134
 						self::type_tax_sub_total 	=> __("Tax Subtotal", "event_espresso"),
135 135
 						self::type_tax					=>  __("Tax", "event_espresso"),
136 136
 						self::type_total				=>  __("Total", "event_espresso"),
137
-						self::type_cancellation	=> __( 'Cancellation', 'event_espresso' )
137
+						self::type_cancellation	=> __('Cancellation', 'event_espresso')
138 138
 					)
139 139
 				),
140
-				'OBJ_ID' 					=> new EE_Foreign_Key_Int_Field( 'OBJ_ID', __( 'ID of Item purchased.', 'event_espresso' ), TRUE, NULL, $line_items_can_be_for ),
141
-				'OBJ_type'				=>new EE_Any_Foreign_Model_Name_Field( 'OBJ_type', __( "Model Name this Line Item is for", "event_espresso" ), TRUE, NULL, $line_items_can_be_for ),
142
-				'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created','event_espresso'), false, EE_Datetime_Field::now, $timezone ),
140
+				'OBJ_ID' 					=> new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), TRUE, NULL, $line_items_can_be_for),
141
+				'OBJ_type'				=>new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), TRUE, NULL, $line_items_can_be_for),
142
+				'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
143 143
 			)
144 144
 		);
145 145
 		$this->_model_relations = array(
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 		);
151 151
 		$this->_model_chain_to_wp_user = 'Transaction.Registration.Event';
152 152
 		$this->_caps_slug = 'transactions';
153
-		parent::__construct( $timezone );
153
+		parent::__construct($timezone);
154 154
 	}
155 155
 
156 156
 
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
 	 * @param EE_Transaction|int $transaction
162 162
 	 * @return EE_Line_Item[]
163 163
 	 */
164
-	public function get_all_of_type_for_transaction( $line_item_type, $transaction ){
165
-		$transaction = EEM_Transaction::instance()->ensure_is_ID( $transaction );
166
-		return $this->get_all( array( array(
164
+	public function get_all_of_type_for_transaction($line_item_type, $transaction) {
165
+		$transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
166
+		return $this->get_all(array(array(
167 167
 			'LIN_type' => $line_item_type,
168 168
 			'TXN_ID' => $transaction
169 169
 		)));
@@ -177,14 +177,14 @@  discard block
 block discarded – undo
177 177
 	 * @param EE_Transaction|int $transaction
178 178
 	 * @return EE_Line_Item[]
179 179
 	 */
180
-	public function get_all_non_ticket_line_items_for_transaction( $transaction ) {
181
-		$transaction = EEM_Transaction::instance()->ensure_is_ID( $transaction );
182
-		return $this->get_all( array( array(
180
+	public function get_all_non_ticket_line_items_for_transaction($transaction) {
181
+		$transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
182
+		return $this->get_all(array(array(
183 183
 			'LIN_type' => self::type_line_item,
184 184
 			'TXN_ID' => $transaction,
185 185
 			'OR' => array(
186
-				'OBJ_type*notticket' => array( '!=', 'Ticket'),
187
-				'OBJ_type*null' => array( 'IS_NULL' ))
186
+				'OBJ_type*notticket' => array('!=', 'Ticket'),
187
+				'OBJ_type*null' => array('IS_NULL'))
188 188
 		)));
189 189
 	}
190 190
 
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 	 * because if there are spam bots afoot there will be LOTS of line items
195 195
 	 * @return int count of how many deleted
196 196
 	 */
197
-	public function delete_line_items_with_no_transaction(){
197
+	public function delete_line_items_with_no_transaction() {
198 198
 		/** @type WPDB $wpdb */
199 199
 		global $wpdb;
200 200
 		$time_to_leave_alone = apply_filters(
@@ -202,13 +202,13 @@  discard block
 block discarded – undo
202 202
 		);
203 203
 		$query = $wpdb->prepare(
204 204
 				'DELETE li
205
-				FROM ' . $this->table() . ' li
206
-				LEFT JOIN ' . EEM_Transaction::instance()->table(). ' t ON li.TXN_ID = t.TXN_ID
205
+				FROM ' . $this->table().' li
206
+				LEFT JOIN ' . EEM_Transaction::instance()->table().' t ON li.TXN_ID = t.TXN_ID
207 207
 				WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s',
208 208
 				// use GMT time because that's what TXN_timestamps are in
209
-				date(  'Y-m-d H:i:s', time() - $time_to_leave_alone )
209
+				date('Y-m-d H:i:s', time() - $time_to_leave_alone)
210 210
 				);
211
-		return $wpdb->query( $query );
211
+		return $wpdb->query($query);
212 212
 	}
213 213
 
214 214
 
@@ -221,10 +221,10 @@  discard block
 block discarded – undo
221 221
 	 * @param \EE_Base_Class $object
222 222
 	 * @return EE_Line_Item[]
223 223
 	 */
224
-	public function get_line_item_for_transaction_object( $TXN_ID, EE_Base_Class $object ){
225
-		return $this->get_all( array( array(
224
+	public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) {
225
+		return $this->get_all(array(array(
226 226
 			'TXN_ID' 		=> $TXN_ID,
227
-			'OBJ_type' 	=> str_replace( 'EE_', '', get_class( $object )),
227
+			'OBJ_type' 	=> str_replace('EE_', '', get_class($object)),
228 228
 			'OBJ_ID' 		=> $object->ID()
229 229
 		)));
230 230
 	}
@@ -240,16 +240,16 @@  discard block
 block discarded – undo
240 240
 	 * @param array $OBJ_IDs
241 241
 	 * @return EE_Line_Item[]
242 242
 	 */
243
-	public function get_object_line_items_for_transaction( $TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array() ){
243
+	public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array()) {
244 244
 		$query_params = array(
245 245
 			'OBJ_type' 	=> $OBJ_type,
246 246
 			// if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query
247
-			'OBJ_ID' 		=> is_array( $OBJ_IDs ) && ! isset( $OBJ_IDs['IN'] ) ? array( 'IN', $OBJ_IDs ) : $OBJ_IDs
247
+			'OBJ_ID' 		=> is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs
248 248
 		);
249
-		if ( $TXN_ID ) {
249
+		if ($TXN_ID) {
250 250
 			$query_params['TXN_ID'] = $TXN_ID;
251 251
 		}
252
-		return $this->get_all( array( $query_params ));
252
+		return $this->get_all(array($query_params));
253 253
 	}
254 254
 
255 255
 
@@ -260,13 +260,13 @@  discard block
 block discarded – undo
260 260
 	 * @param EE_Transaction $transaction
261 261
 	 * @return EE_Line_Item[]
262 262
 	 */
263
-	public function get_all_ticket_line_items_for_transaction( EE_Transaction $transaction ) {
264
-		return $this->get_all( array(
263
+	public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) {
264
+		return $this->get_all(array(
265 265
 		   array(
266 266
 			   'TXN_ID'   => $transaction->ID(),
267 267
 			   'OBJ_type' => 'Ticket',
268 268
 		   )
269
-	   ) );
269
+	   ));
270 270
 	}
271 271
 
272 272
 
@@ -278,14 +278,14 @@  discard block
 block discarded – undo
278 278
 	 * @param int $TKT_ID
279 279
 	 * @return \EE_Line_Item
280 280
 	 */
281
-	public function get_ticket_line_item_for_transaction( $TXN_ID, $TKT_ID ) {
282
-		return $this->get_one( array(
281
+	public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) {
282
+		return $this->get_one(array(
283 283
 		   array(
284
-			   'TXN_ID'   => EEM_Transaction::instance()->ensure_is_ID( $TXN_ID ),
284
+			   'TXN_ID'   => EEM_Transaction::instance()->ensure_is_ID($TXN_ID),
285 285
 			   'OBJ_ID'   => $TKT_ID,
286 286
 			   'OBJ_type' => 'Ticket',
287 287
 		   )
288
-	   ) );
288
+	   ));
289 289
 	}
290 290
 
291 291
 
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
 	 * @param EE_Promotion $promotion
301 301
 	 * @return EE_Line_Item
302 302
 	 */
303
-	public function get_existing_promotion_line_item( EE_Line_Item $parent_line_item, EE_Promotion $promotion ) {
304
-		return $this->get_one( array(
303
+	public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) {
304
+		return $this->get_one(array(
305 305
 			array(
306 306
 				'TXN_ID' 			=> $parent_line_item->TXN_ID(),
307 307
 				'LIN_parent' 	=> $parent_line_item->ID(),
@@ -322,8 +322,8 @@  discard block
 block discarded – undo
322 322
 	 * @param EE_Line_Item $parent_line_item
323 323
 	 * @return EE_Line_Item[]
324 324
 	 */
325
-	public function get_all_promotion_line_items( EE_Line_Item $parent_line_item ) {
326
-		return $this->get_all( array(
325
+	public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) {
326
+		return $this->get_all(array(
327 327
 			array(
328 328
 				'TXN_ID' 			=> $parent_line_item->TXN_ID(),
329 329
 				'LIN_parent' 	=> $parent_line_item->ID(),
@@ -340,8 +340,8 @@  discard block
 block discarded – undo
340 340
 	 * @param EE_Registration $registration
341 341
 	 * @return EE_Line_ITem
342 342
 	 */
343
-	public function get_line_item_for_registration( EE_Registration $registration ) {
344
-		return $this->get_one( $this->line_item_for_registration_query_params( $registration ));
343
+	public function get_line_item_for_registration(EE_Registration $registration) {
344
+		return $this->get_one($this->line_item_for_registration_query_params($registration));
345 345
 	}
346 346
 
347 347
 	/**
@@ -350,14 +350,14 @@  discard block
 block discarded – undo
350 350
 	 * @param array $original_query_params any extra query params you'd like to be merged with
351 351
 	 * @return array like EEM_Base::get_all()'s $query_params
352 352
 	 */
353
-	public function line_item_for_registration_query_params( EE_Registration $registration, $original_query_params = array() ) {
354
-		return array_replace_recursive( $original_query_params, array(
353
+	public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array()) {
354
+		return array_replace_recursive($original_query_params, array(
355 355
 			array(
356 356
 				'OBJ_ID' => $registration->ticket_ID(),
357 357
 				'OBJ_type' => 'Ticket',
358 358
 				'TXN_ID' => $registration->transaction_ID()
359 359
 			)
360
-		) );
360
+		));
361 361
 	}
362 362
 
363 363
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3
+}
2 4
 /**
3 5
  * Event Espresso
4 6
  *
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -362,62 +362,62 @@
 block discarded – undo
362 362
 
363 363
 
364 364
 
365
-    /**
366
-     * @return EE_Base_Class[]|EE_Line_Item[]
367
-     * @throws \EE_Error
368
-     */
369
-    public function get_total_line_items_with_no_transaction()
370
-    {
371
-        return $this->get_total_line_items_for_carts();
372
-    }
373
-
374
-
375
-
376
-    /**
377
-     * @return EE_Base_Class[]|EE_Line_Item[]
378
-     * @throws \EE_Error
379
-     */
380
-    public function get_total_line_items_for_active_carts()
381
-    {
382
-        return $this->get_total_line_items_for_carts(false);
383
-    }
384
-
385
-
386
-
387
-    /**
388
-     * @return EE_Base_Class[]|EE_Line_Item[]
389
-     * @throws \EE_Error
390
-     */
391
-    public function get_total_line_items_for_expired_carts()
392
-    {
393
-        return $this->get_total_line_items_for_carts(true);
394
-    }
395
-
396
-
397
-
398
-    /**
399
-     * Returns an array of grand total line items where the TXN_ID is 0.
400
-     * If $expired is set to true, then only line items for expired sessions will be returned.
401
-     * If $expired is set to false, then only line items for active sessions will be returned.
402
-     *
403
-     * @param bool|null $expired
404
-     * @return EE_Base_Class[]|EE_Line_Item[]
405
-     * @throws \EE_Error
406
-     */
407
-    private function get_total_line_items_for_carts($expired = null)
408
-    {
409
-        $where_params = array(
410
-            'TXN_ID'        => 0,
411
-            'LIN_type'      => 'total',
412
-        );
413
-        if ($expired !== null) {
414
-            $where_params['LIN_timestamp'] = array(
415
-                $expired ? '<=' : '>',
416
-                time() - EE_Registry::instance()->SSN->lifespan(),
417
-            );
418
-        }
419
-        return $this->get_all(array($where_params));
420
-    }
365
+	/**
366
+	 * @return EE_Base_Class[]|EE_Line_Item[]
367
+	 * @throws \EE_Error
368
+	 */
369
+	public function get_total_line_items_with_no_transaction()
370
+	{
371
+		return $this->get_total_line_items_for_carts();
372
+	}
373
+
374
+
375
+
376
+	/**
377
+	 * @return EE_Base_Class[]|EE_Line_Item[]
378
+	 * @throws \EE_Error
379
+	 */
380
+	public function get_total_line_items_for_active_carts()
381
+	{
382
+		return $this->get_total_line_items_for_carts(false);
383
+	}
384
+
385
+
386
+
387
+	/**
388
+	 * @return EE_Base_Class[]|EE_Line_Item[]
389
+	 * @throws \EE_Error
390
+	 */
391
+	public function get_total_line_items_for_expired_carts()
392
+	{
393
+		return $this->get_total_line_items_for_carts(true);
394
+	}
395
+
396
+
397
+
398
+	/**
399
+	 * Returns an array of grand total line items where the TXN_ID is 0.
400
+	 * If $expired is set to true, then only line items for expired sessions will be returned.
401
+	 * If $expired is set to false, then only line items for active sessions will be returned.
402
+	 *
403
+	 * @param bool|null $expired
404
+	 * @return EE_Base_Class[]|EE_Line_Item[]
405
+	 * @throws \EE_Error
406
+	 */
407
+	private function get_total_line_items_for_carts($expired = null)
408
+	{
409
+		$where_params = array(
410
+			'TXN_ID'        => 0,
411
+			'LIN_type'      => 'total',
412
+		);
413
+		if ($expired !== null) {
414
+			$where_params['LIN_timestamp'] = array(
415
+				$expired ? '<=' : '>',
416
+				time() - EE_Registry::instance()->SSN->lifespan(),
417
+			);
418
+		}
419
+		return $this->get_all(array($where_params));
420
+	}
421 421
 
422 422
 
423 423
 
Please login to merge, or discard this patch.
core/db_models/EEM_Registration.model.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -373,7 +373,7 @@
 block discarded – undo
373 373
      * @param    int $ATT_ID
374 374
      * @param    int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the
375 375
      *                         attendee number is required
376
-     * @return        mixed        array on success, FALSE on fail
376
+     * @return        null|EE_Base_Class        array on success, FALSE on fail
377 377
      */
378 378
     public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0)
379 379
     {
Please login to merge, or discard this patch.
Indentation   +749 added lines, -749 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\services\database\TableAnalysis;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -17,737 +17,737 @@  discard block
 block discarded – undo
17 17
 class EEM_Registration extends EEM_Soft_Delete_Base
18 18
 {
19 19
 
20
-    // private instance of the Registration object
21
-    protected static $_instance = null;
22
-
23
-    /**
24
-     * Keys are the status IDs for registrations (eg, RAP, RCN, etc), and the values
25
-     * are status codes (eg, approved, cancelled, etc)
26
-     *
27
-     * @var array
28
-     */
29
-    private static $_reg_status;
30
-
31
-    /**
32
-     * The value of REG_count for a primary registrant
33
-     */
34
-    const PRIMARY_REGISTRANT_COUNT = 1;
35
-
36
-    /**
37
-     * Status ID (STS_ID on esp_status table) to indicate an INCOMPLETE registration.
38
-     * Initial status for registrations when they are first created
39
-     * Payments are NOT allowed.
40
-     * Automatically toggled to whatever the default Event registration status is upon completion of the attendee
41
-     * information reg step NO space reserved. Registration is NOT active
42
-     */
43
-    const status_id_incomplete = 'RIC';
44
-
45
-    /**
46
-     * Status ID (STS_ID on esp_status table) to indicate an UNAPPROVED registration.
47
-     * Payments are NOT allowed.
48
-     * Event Admin must manually toggle STS_ID for it to change
49
-     * No space reserved.
50
-     * Registration is active
51
-     */
52
-    const status_id_not_approved = 'RNA';
53
-
54
-    /**
55
-     * Status ID (STS_ID on esp_status table) to indicate registration is PENDING_PAYMENT .
56
-     * Payments are allowed.
57
-     * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
58
-     * No space reserved.
59
-     * Registration is active
60
-     */
61
-    const status_id_pending_payment = 'RPP';
62
-
63
-    /**
64
-     * Status ID (STS_ID on esp_status table) to indicate registration is on the WAIT_LIST .
65
-     * Payments are allowed.
66
-     * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
67
-     * No space reserved.
68
-     * Registration is active
69
-     */
70
-    const status_id_wait_list = 'RWL';
71
-
72
-    /**
73
-     * Status ID (STS_ID on esp_status table) to indicate an APPROVED registration.
74
-     * the TXN may or may not be completed ( paid in full )
75
-     * Payments are allowed.
76
-     * A space IS reserved.
77
-     * Registration is active
78
-     */
79
-    const status_id_approved = 'RAP';
80
-
81
-    /**
82
-     * Status ID (STS_ID on esp_status table) to indicate a registration was CANCELLED by the attendee.
83
-     * Payments are NOT allowed.
84
-     * NO space reserved.
85
-     * Registration is NOT active
86
-     */
87
-    const status_id_cancelled = 'RCN';
88
-
89
-    /**
90
-     * Status ID (STS_ID on esp_status table) to indicate a registration was DECLINED by the Event Admin
91
-     * Payments are NOT allowed.
92
-     * No space reserved.
93
-     * Registration is NOT active
94
-     */
95
-    const status_id_declined = 'RDC';
96
-
97
-    /**
98
-     * @var TableAnalysis $table_analysis
99
-     */
100
-    protected $_table_analysis;
101
-
102
-
103
-
104
-    /**
105
-     *    private constructor to prevent direct creation
106
-     *
107
-     * @Constructor
108
-     * @access protected
109
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
110
-     *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
111
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
112
-     *                         timezone in the 'timezone_string' wp option)
113
-     */
114
-    protected function __construct($timezone = null)
115
-    {
116
-        $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
117
-        $this->singular_item = __('Registration', 'event_espresso');
118
-        $this->plural_item = __('Registrations', 'event_espresso');
119
-        $this->_tables = array(
120
-            'Registration' => new EE_Primary_Table('esp_registration', 'REG_ID'),
121
-        );
122
-        $this->_fields = array(
123
-            'Registration' => array(
124
-                'REG_ID'           => new EE_Primary_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso')),
125
-                'EVT_ID'           => new EE_Foreign_Key_Int_Field(
126
-                    'EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'
127
-                ),
128
-                'ATT_ID'           => new EE_Foreign_Key_Int_Field(
129
-                    'ATT_ID', __('Attendee ID', 'event_espresso'), false, 0, 'Attendee'
130
-                ),
131
-                'TXN_ID'           => new EE_Foreign_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso'),
132
-                    false, 0, 'Transaction'
133
-                ),
134
-                'TKT_ID'           => new EE_Foreign_Key_Int_Field('TKT_ID', __('Ticket ID', 'event_espresso'), false,
135
-                    0, 'Ticket'
136
-                ),
137
-                'STS_ID'           => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'),
138
-                    false, EEM_Registration::status_id_incomplete, 'Status'
139
-                ),
140
-                'REG_date'         => new EE_Datetime_Field('REG_date',
141
-                    __('Time registration occurred', 'event_espresso'), false, EE_Datetime_Field::now, $timezone
142
-                ),
143
-                'REG_final_price'  => new EE_Money_Field('REG_final_price',
144
-                    __('Registration\'s share of the transaction total', 'event_espresso'), false, 0
145
-                ),
146
-                'REG_paid'         => new EE_Money_Field('REG_paid',
147
-                    __('Amount paid to date towards registration', 'event_espresso'), false, 0
148
-                ),
149
-                'REG_session'      => new EE_Plain_Text_Field('REG_session',
150
-                    __('Session ID of registration', 'event_espresso'), false, ''
151
-                ),
152
-                'REG_code'         => new EE_Plain_Text_Field('REG_code',
153
-                    __('Unique Code for this registration', 'event_espresso'), false, ''
154
-                ),
155
-                'REG_url_link'     => new EE_Plain_Text_Field('REG_url_link',
156
-                    __('String to be used in URL for identifying registration', 'event_espresso'), false, ''
157
-                ),
158
-                'REG_count'        => new EE_Integer_Field('REG_count',
159
-                    __('Count of this registration in the group registration ', 'event_espresso'), true, 1
160
-                ),
161
-                'REG_group_size'   => new EE_Integer_Field('REG_group_size',
162
-                    __('Number of registrations on this group', 'event_espresso'), false, 1
163
-                ),
164
-                'REG_att_is_going' => new EE_Boolean_Field('REG_att_is_going',
165
-                    __('Flag indicating the registrant plans on attending', 'event_espresso'), false, false
166
-                ),
167
-                'REG_deleted'      => new EE_Trashed_Flag_Field(
168
-                    'REG_deleted', __('Flag indicating if registration has been archived or not.', 'event_espresso'),
169
-                    false, false
170
-                ),
171
-            ),
172
-        );
173
-        $this->_model_relations = array(
174
-            'Event'                => new EE_Belongs_To_Relation(),
175
-            'Attendee'             => new EE_Belongs_To_Relation(),
176
-            'Transaction'          => new EE_Belongs_To_Relation(),
177
-            'Ticket'               => new EE_Belongs_To_Relation(),
178
-            'Status'               => new EE_Belongs_To_Relation(),
179
-            'Answer'               => new EE_Has_Many_Relation(),
180
-            'Checkin'              => new EE_Has_Many_Relation(),
181
-            'Registration_Payment' => new EE_Has_Many_Relation(),
182
-            'Payment'              => new EE_HABTM_Relation('Registration_Payment'),
183
-            'Message'              => new EE_Has_Many_Any_Relation(false)
184
-            //allow deletes even if there are messages in the queue related
185
-        );
186
-        $this->_model_chain_to_wp_user = 'Event';
187
-        parent::__construct($timezone);
188
-    }
189
-
190
-
191
-
192
-    /**
193
-     * reg_statuses_that_allow_payment
194
-     * a filterable list of registration statuses that allow a registrant to make a payment
195
-     *
196
-     * @access public
197
-     * @return array
198
-     */
199
-    public static function reg_statuses_that_allow_payment()
200
-    {
201
-        return apply_filters(
202
-            'FHEE__EEM_Registration__reg_statuses_that_allow_payment',
203
-            array(
204
-                EEM_Registration::status_id_approved,
205
-                EEM_Registration::status_id_pending_payment,
206
-                EEM_Registration::status_id_wait_list,
207
-            )
208
-        );
209
-    }
210
-
211
-
212
-
213
-    /**
214
-     * inactive_reg_statuses
215
-     * a filterable list of registration statuses that are considered active
216
-     *
217
-     * @access public
218
-     * @return array
219
-     */
220
-    public static function active_reg_statuses()
221
-    {
222
-        return apply_filters(
223
-            'FHEE__EEM_Registration__reg_statuses_that_allow_payment',
224
-            array(
225
-                EEM_Registration::status_id_approved,
226
-                EEM_Registration::status_id_pending_payment,
227
-                EEM_Registration::status_id_wait_list,
228
-                EEM_Registration::status_id_not_approved,
229
-            )
230
-        );
231
-    }
232
-
233
-
234
-
235
-    /**
236
-     * inactive_reg_statuses
237
-     * a filterable list of registration statuses that are not considered active
238
-     *
239
-     * @access public
240
-     * @return array
241
-     */
242
-    public static function inactive_reg_statuses()
243
-    {
244
-        return apply_filters(
245
-            'FHEE__EEM_Registration__reg_statuses_that_allow_payment',
246
-            array(
247
-                EEM_Registration::status_id_incomplete,
248
-                EEM_Registration::status_id_cancelled,
249
-                EEM_Registration::status_id_declined,
250
-            )
251
-        );
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     *    closed_reg_statuses
258
-     *    a filterable list of registration statuses that are considered "closed"
259
-     * meaning they should not be considered in any calculations involving monies owing
260
-     *
261
-     * @access public
262
-     * @return array
263
-     */
264
-    public static function closed_reg_statuses()
265
-    {
266
-        return apply_filters(
267
-            'FHEE__EEM_Registration__closed_reg_statuses',
268
-            array(
269
-                EEM_Registration::status_id_cancelled,
270
-                EEM_Registration::status_id_declined,
271
-            )
272
-        );
273
-    }
274
-
275
-
276
-
277
-    /**
278
-     *        get list of registration statuses
279
-     *
280
-     * @access public
281
-     * @param array $exclude    The status ids to exclude from the returned results
282
-     * @param bool  $translated If true will return the values as singular localized strings
283
-     * @return array
284
-     */
285
-    public static function reg_status_array($exclude = array(), $translated = false)
286
-    {
287
-        EEM_Registration::instance()->_get_registration_status_array($exclude);
288
-        return $translated ? EEM_Status::instance()->localized_status(self::$_reg_status, false, 'sentence')
289
-            : self::$_reg_status;
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     *    get list of registration statuses
296
-     *
297
-     * @access private
298
-     * @param array $exclude
299
-     * @return array
300
-     */
301
-    private function _get_registration_status_array($exclude = array())
302
-    {
303
-        //in the very rare circumstance that we are deleting a model's table's data
304
-        //and the table hasn't actually been created, this could have an error
305
-        /** @type WPDB $wpdb */
306
-        global $wpdb;
307
-        if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
308
-            $results = $wpdb->get_results(
309
-                "SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
310
-            );
311
-            self::$_reg_status = array();
312
-            foreach ($results as $status) {
313
-                if ( ! in_array($status->STS_ID, $exclude)) {
314
-                    self::$_reg_status[$status->STS_ID] = $status->STS_code;
315
-                }
316
-            }
317
-        }
318
-    }
319
-
320
-
321
-
322
-    /**
323
-     * Gets the injected table analyzer, or throws an exception
324
-     *
325
-     * @return TableAnalysis
326
-     * @throws \EE_Error
327
-     */
328
-    protected function _get_table_analysis()
329
-    {
330
-        if ($this->_table_analysis instanceof TableAnalysis) {
331
-            return $this->_table_analysis;
332
-        } else {
333
-            throw new \EE_Error(
334
-                sprintf(
335
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
336
-                    get_class($this)
337
-                )
338
-            );
339
-        }
340
-    }
341
-
342
-
343
-
344
-    /**
345
-     * This returns a wpdb->results array of all registration date month and years matching the incoming query params
346
-     * and grouped by month and year.
347
-     *
348
-     * @param  array $where_params Array of query_params as described in the comments for EEM_Base::get_all()
349
-     * @return array
350
-     * @throws \EE_Error
351
-     */
352
-    public function get_reg_months_and_years($where_params)
353
-    {
354
-        $query_params[0] = $where_params;
355
-        $query_params['group_by'] = array('reg_year', 'reg_month');
356
-        $query_params['order_by'] = array('REG_date' => 'DESC');
357
-        $columns_to_select = array(
358
-            'reg_year'  => array('YEAR(REG_date)', '%s'),
359
-            'reg_month' => array('MONTHNAME(REG_date)', '%s'),
360
-        );
361
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
362
-    }
363
-
364
-
365
-
366
-    /**
367
-     *        retrieve ALL registrations for a particular Attendee from db
368
-     *
369
-     * @access        public
370
-     * @param        int $ATT_ID
371
-     * @return    EE_Registration[]
372
-     */
373
-    public function get_all_registrations_for_attendee($ATT_ID = 0)
374
-    {
375
-        if ( ! $ATT_ID) {
376
-            return false;
377
-        }
378
-        return $this->get_all(array(array('ATT_ID' => $ATT_ID)));
379
-    }
380
-
381
-
382
-
383
-    /**
384
-     * Gets a registration given their REG_url_link. Yes, this should usually
385
-     * be passed via a GET parameter.
386
-     *
387
-     * @param string $REG_url_link
388
-     * @return EE_Registration
389
-     */
390
-    public function get_registration_for_reg_url_link($REG_url_link)
391
-    {
392
-        if ( ! $REG_url_link) {
393
-            return false;
394
-        }
395
-        return $this->get_one(array(array('REG_url_link' => $REG_url_link)));
396
-    }
397
-
398
-
399
-
400
-    /**
401
-     *        retrieve registration for a specific transaction attendee from db
402
-     *
403
-     * @access        public
404
-     * @param    int $TXN_ID
405
-     * @param    int $ATT_ID
406
-     * @param    int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the
407
-     *                         attendee number is required
408
-     * @return        mixed        array on success, FALSE on fail
409
-     */
410
-    public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0)
411
-    {
412
-        return $this->get_one(array(
413
-            array(
414
-                'TXN_ID' => $TXN_ID,
415
-                'ATT_ID' => $ATT_ID,
416
-            ),
417
-            'limit' => array(min(($att_nmbr - 1), 0), 1),
418
-        ));
419
-    }
420
-
421
-
422
-
423
-    /**
424
-     *        get the number of registrations per day  for the Registration Admin page Reports Tab.
425
-     *        (doesn't utilize models because it's a fairly specialized query)
426
-     *
427
-     * @access        public
428
-     * @param $period string which can be passed to php's strtotime function (eg "-1 month")
429
-     * @return stdClass[] with properties regDate and total
430
-     */
431
-    public function get_registrations_per_day_report($period = '-1 month')
432
-    {
433
-        $sql_date = $this->convert_datetime_for_query('REG_date', date("Y-m-d H:i:s", strtotime($period)),
434
-            'Y-m-d H:i:s', 'UTC');
435
-        $where = array(
436
-            'REG_date' => array('>=', $sql_date),
437
-            'STS_ID'   => array('!=', EEM_Registration::status_id_incomplete),
438
-        );
439
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
440
-            $where['Event.EVT_wp_user'] = get_current_user_id();
441
-        }
442
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
443
-        $results = $this->_get_all_wpdb_results(
444
-            array(
445
-                $where,
446
-                'group_by' => 'regDate',
447
-                'order_by' => array('REG_date' => 'ASC'),
448
-            ),
449
-            OBJECT,
450
-            array(
451
-                'regDate' => array('DATE(' . $query_interval . ')', '%s'),
452
-                'total'   => array('count(REG_ID)', '%d'),
453
-            ));
454
-        return $results;
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * Get the number of registrations per day including the count of registrations for each Registration Status.
461
-     * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
462
-     *
463
-     * @param string $period
464
-     * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID
465
-     *                    (i.e. RAP)
466
-     */
467
-    public function get_registrations_per_day_and_per_status_report($period = '-1 month')
468
-    {
469
-        global $wpdb;
470
-        $registration_table = $wpdb->prefix . 'esp_registration';
471
-        $event_table = $wpdb->posts;
472
-        $sql_date = date("Y-m-d H:i:s", strtotime($period));
473
-        //prepare the query interval for displaying offset
474
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date');
475
-        //inner date query
476
-        $inner_date_query = "SELECT DISTINCT REG_date from $registration_table ";
477
-        $inner_where = " WHERE";
478
-        //exclude events not authored by user if permissions in effect
479
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
480
-            $inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
481
-            $inner_where .= " post_author = " . get_current_user_id() . " AND";
482
-        }
483
-        $inner_where .= " REG_date >= '$sql_date'";
484
-        $inner_date_query .= $inner_where;
485
-        //start main query
486
-        $select = "SELECT DATE($query_interval) as Registration_REG_date, ";
487
-        $join = '';
488
-        $join_parts = array();
489
-        $select_parts = array();
490
-        //loop through registration stati to do parts for each status.
491
-        foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
492
-            if ($STS_ID === EEM_Registration::status_id_incomplete) {
493
-                continue;
494
-            }
495
-            $select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID";
496
-            $join_parts[] = "$registration_table AS $STS_code ON $STS_code.REG_date = dates.REG_date AND $STS_code.STS_ID = '$STS_ID'";
497
-        }
498
-        //setup the selects
499
-        $select .= implode(', ', $select_parts);
500
-        $select .= " FROM ($inner_date_query) AS dates LEFT JOIN ";
501
-        //setup the joins
502
-        $join .= implode(" LEFT JOIN ", $join_parts);
503
-        //now let's put it all together
504
-        $query = $select . $join . ' GROUP BY Registration_REG_date';
505
-        //and execute it
506
-        $results = $wpdb->get_results($query, ARRAY_A);
507
-        return $results;
508
-    }
509
-
510
-
511
-
512
-    /**
513
-     *        get the number of registrations per event  for the Registration Admin page Reports Tab
514
-     *
515
-     * @access        public
516
-     * @param $period string which can be passed to php's strtotime function (eg "-1 month")
517
-     * @return stdClass[] each with properties event_name, reg_limit, and total
518
-     */
519
-    public function get_registrations_per_event_report($period = '-1 month')
520
-    {
521
-        $date_sql = $this->convert_datetime_for_query('REG_date', date("Y-m-d H:i:s", strtotime($period)),
522
-            'Y-m-d H:i:s', 'UTC');
523
-        $where = array(
524
-            'REG_date' => array('>=', $date_sql),
525
-            'STS_ID'   => array('!=', EEM_Registration::status_id_incomplete),
526
-        );
527
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
528
-            $where['Event.EVT_wp_user'] = get_current_user_id();
529
-        }
530
-        $results = $this->_get_all_wpdb_results(array(
531
-            $where,
532
-            'group_by' => 'Event.EVT_name',
533
-            'order_by' => 'Event.EVT_name',
534
-            'limit'    => array(0, 24),
535
-        ),
536
-            OBJECT,
537
-            array(
538
-                'event_name' => array('Event_CPT.post_title', '%s'),
539
-                'total'      => array('COUNT(REG_ID)', '%s'),
540
-            )
541
-        );
542
-        return $results;
543
-    }
544
-
545
-
546
-
547
-    /**
548
-     * Get the number of registrations per event grouped by registration status.
549
-     * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
550
-     *
551
-     * @param string $period
552
-     * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID
553
-     *                    (i.e. RAP)
554
-     */
555
-    public function get_registrations_per_event_and_per_status_report($period = '-1 month')
556
-    {
557
-        global $wpdb;
558
-        $registration_table = $wpdb->prefix . 'esp_registration';
559
-        $event_table = $wpdb->posts;
560
-        $sql_date = date("Y-m-d H:i:s", strtotime($period));
561
-        //inner date query
562
-        $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
563
-        $inner_where = " WHERE";
564
-        //exclude events not authored by user if permissions in effect
565
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
566
-            $inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
567
-            $inner_where .= " post_author = " . get_current_user_id() . " AND";
568
-        }
569
-        $inner_where .= " REG_date >= '$sql_date'";
570
-        $inner_date_query .= $inner_where;
571
-        //build main query
572
-        $select = "SELECT Event.post_title as Registration_Event, ";
573
-        $join = '';
574
-        $join_parts = array();
575
-        $select_parts = array();
576
-        //loop through registration stati to do parts for each status.
577
-        foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
578
-            if ($STS_ID === EEM_Registration::status_id_incomplete) {
579
-                continue;
580
-            }
581
-            $select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID";
582
-            $join_parts[] = "$registration_table AS $STS_code ON $STS_code.EVT_ID = dates.EVT_ID AND $STS_code.STS_ID = '$STS_ID' AND $STS_code.REG_date = dates.REG_date";
583
-        }
584
-        //setup the selects
585
-        $select .= implode(', ', $select_parts);
586
-        $select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN ";
587
-        //setup remaining joins
588
-        $join .= implode(" LEFT JOIN ", $join_parts);
589
-        //now put it all together
590
-        $query = $select . $join . ' GROUP BY Registration_Event';
591
-        //and execute
592
-        $results = $wpdb->get_results($query, ARRAY_A);
593
-        return $results;
594
-    }
595
-
596
-
597
-
598
-    /**
599
-     * Returns the EE_Registration of the primary attendee on the transaction id provided
600
-     *
601
-     * @param int $TXN_ID
602
-     * @return EE_Registration
603
-     */
604
-    public function get_primary_registration_for_transaction_ID($TXN_ID = 0)
605
-    {
606
-        if ( ! $TXN_ID) {
607
-            return false;
608
-        }
609
-        return $this->get_one(array(
610
-            array(
611
-                'TXN_ID'    => $TXN_ID,
612
-                'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT,
613
-            ),
614
-        ));
615
-    }
616
-
617
-
618
-
619
-    /**
620
-     *        get_event_registration_count
621
-     *
622
-     * @access public
623
-     * @param int     $EVT_ID
624
-     * @param boolean $for_incomplete_payments
625
-     * @return int
626
-     */
627
-    public function get_event_registration_count($EVT_ID, $for_incomplete_payments = false)
628
-    {
629
-        // we only count approved registrations towards registration limits
630
-        $query_params = array(array('EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved));
631
-        if ($for_incomplete_payments) {
632
-            $query_params[0]['Transaction.STS_ID'] = array('!=', EEM_Transaction::complete_status_code);
633
-        }
634
-        return $this->count($query_params);
635
-    }
636
-
637
-
638
-
639
-    /**
640
-     * Deletes all registrations with no transactions. Note that this needs to be very efficient
641
-     * and so it uses wpdb directly
642
-     *
643
-     * @global WPDB $wpdb
644
-     * @return int number deleted
645
-     */
646
-    public function delete_registrations_with_no_transaction()
647
-    {
648
-        /** @type WPDB $wpdb */
649
-        global $wpdb;
650
-        return $wpdb->query(
651
-            'DELETE r FROM '
652
-            . $this->table()
653
-            . ' r LEFT JOIN '
654
-            . EEM_Transaction::instance()->table()
655
-            . ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL');
656
-    }
657
-
658
-
659
-
660
-    /**
661
-     *  Count registrations checked into (or out of) a datetime
662
-     *
663
-     * @param int     $DTT_ID     datetime ID
664
-     * @param boolean $checked_in whether to count registrations checked IN or OUT
665
-     * @return int
666
-     */
667
-    public function count_registrations_checked_into_datetime($DTT_ID, $checked_in = true)
668
-    {
669
-        global $wpdb;
670
-        //subquery to get latest checkin
671
-        $query = $wpdb->prepare(
672
-            'SELECT '
673
-            . 'COUNT( DISTINCT checkins.REG_ID ) '
674
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
675
-            . '( SELECT '
676
-            . 'max( CHK_timestamp ) AS latest_checkin, '
677
-            . 'REG_ID AS REG_ID '
678
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' '
679
-            . 'WHERE DTT_ID=%d '
680
-            . 'GROUP BY REG_ID'
681
-            . ') AS most_recent_checkin_per_reg '
682
-            . 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
683
-            . 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
684
-            . 'WHERE '
685
-            . 'checkins.CHK_in=%d',
686
-            $DTT_ID,
687
-            $checked_in
688
-        );
689
-        return (int)$wpdb->get_var($query);
690
-    }
691
-
692
-
693
-
694
-    /**
695
-     *  Count registrations checked into (or out of) an event.
696
-     *
697
-     * @param int     $EVT_ID     event ID
698
-     * @param boolean $checked_in whether to count registrations checked IN or OUT
699
-     * @return int
700
-     */
701
-    public function count_registrations_checked_into_event($EVT_ID, $checked_in = true)
702
-    {
703
-        global $wpdb;
704
-        //subquery to get latest checkin
705
-        $query = $wpdb->prepare(
706
-            'SELECT '
707
-            . 'COUNT( DISTINCT checkins.REG_ID ) '
708
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
709
-            . '( SELECT '
710
-            . 'max( CHK_timestamp ) AS latest_checkin, '
711
-            . 'REG_ID AS REG_ID '
712
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
713
-            . 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
714
-            . 'ON c.DTT_ID=d.DTT_ID '
715
-            . 'WHERE d.EVT_ID=%d '
716
-            . 'GROUP BY REG_ID'
717
-            . ') AS most_recent_checkin_per_reg '
718
-            . 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
719
-            . 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
720
-            . 'WHERE '
721
-            . 'checkins.CHK_in=%d',
722
-            $EVT_ID,
723
-            $checked_in
724
-        );
725
-        return (int)$wpdb->get_var($query);
726
-    }
727
-
728
-
729
-
730
-    /**
731
-     * The purpose of this method is to retrieve an array of
732
-     * EE_Registration objects that represent the latest registration
733
-     * for each ATT_ID given in the function argument.
734
-     *
735
-     * @param array $attendee_ids
736
-     * @return EE_Registration[]
737
-     */
738
-    public function get_latest_registration_for_each_of_given_contacts($attendee_ids = array())
739
-    {
740
-        //first do a native wp_query to get the latest REG_ID's matching these attendees.
741
-        global $wpdb;
742
-        $registration_table = $wpdb->prefix . 'esp_registration';
743
-        $attendee_table = $wpdb->posts;
744
-        $attendee_ids = is_array($attendee_ids)
745
-            ? array_map('absint', $attendee_ids)
746
-            : array((int)$attendee_ids);
747
-        $attendee_ids = implode(',', $attendee_ids);
748
-        //first we do a query to get the registration ids
749
-        // (because a group by before order by causes the order by to be ignored.)
750
-        $registration_id_query = "
20
+	// private instance of the Registration object
21
+	protected static $_instance = null;
22
+
23
+	/**
24
+	 * Keys are the status IDs for registrations (eg, RAP, RCN, etc), and the values
25
+	 * are status codes (eg, approved, cancelled, etc)
26
+	 *
27
+	 * @var array
28
+	 */
29
+	private static $_reg_status;
30
+
31
+	/**
32
+	 * The value of REG_count for a primary registrant
33
+	 */
34
+	const PRIMARY_REGISTRANT_COUNT = 1;
35
+
36
+	/**
37
+	 * Status ID (STS_ID on esp_status table) to indicate an INCOMPLETE registration.
38
+	 * Initial status for registrations when they are first created
39
+	 * Payments are NOT allowed.
40
+	 * Automatically toggled to whatever the default Event registration status is upon completion of the attendee
41
+	 * information reg step NO space reserved. Registration is NOT active
42
+	 */
43
+	const status_id_incomplete = 'RIC';
44
+
45
+	/**
46
+	 * Status ID (STS_ID on esp_status table) to indicate an UNAPPROVED registration.
47
+	 * Payments are NOT allowed.
48
+	 * Event Admin must manually toggle STS_ID for it to change
49
+	 * No space reserved.
50
+	 * Registration is active
51
+	 */
52
+	const status_id_not_approved = 'RNA';
53
+
54
+	/**
55
+	 * Status ID (STS_ID on esp_status table) to indicate registration is PENDING_PAYMENT .
56
+	 * Payments are allowed.
57
+	 * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
58
+	 * No space reserved.
59
+	 * Registration is active
60
+	 */
61
+	const status_id_pending_payment = 'RPP';
62
+
63
+	/**
64
+	 * Status ID (STS_ID on esp_status table) to indicate registration is on the WAIT_LIST .
65
+	 * Payments are allowed.
66
+	 * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
67
+	 * No space reserved.
68
+	 * Registration is active
69
+	 */
70
+	const status_id_wait_list = 'RWL';
71
+
72
+	/**
73
+	 * Status ID (STS_ID on esp_status table) to indicate an APPROVED registration.
74
+	 * the TXN may or may not be completed ( paid in full )
75
+	 * Payments are allowed.
76
+	 * A space IS reserved.
77
+	 * Registration is active
78
+	 */
79
+	const status_id_approved = 'RAP';
80
+
81
+	/**
82
+	 * Status ID (STS_ID on esp_status table) to indicate a registration was CANCELLED by the attendee.
83
+	 * Payments are NOT allowed.
84
+	 * NO space reserved.
85
+	 * Registration is NOT active
86
+	 */
87
+	const status_id_cancelled = 'RCN';
88
+
89
+	/**
90
+	 * Status ID (STS_ID on esp_status table) to indicate a registration was DECLINED by the Event Admin
91
+	 * Payments are NOT allowed.
92
+	 * No space reserved.
93
+	 * Registration is NOT active
94
+	 */
95
+	const status_id_declined = 'RDC';
96
+
97
+	/**
98
+	 * @var TableAnalysis $table_analysis
99
+	 */
100
+	protected $_table_analysis;
101
+
102
+
103
+
104
+	/**
105
+	 *    private constructor to prevent direct creation
106
+	 *
107
+	 * @Constructor
108
+	 * @access protected
109
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
110
+	 *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
111
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
112
+	 *                         timezone in the 'timezone_string' wp option)
113
+	 */
114
+	protected function __construct($timezone = null)
115
+	{
116
+		$this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
117
+		$this->singular_item = __('Registration', 'event_espresso');
118
+		$this->plural_item = __('Registrations', 'event_espresso');
119
+		$this->_tables = array(
120
+			'Registration' => new EE_Primary_Table('esp_registration', 'REG_ID'),
121
+		);
122
+		$this->_fields = array(
123
+			'Registration' => array(
124
+				'REG_ID'           => new EE_Primary_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso')),
125
+				'EVT_ID'           => new EE_Foreign_Key_Int_Field(
126
+					'EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'
127
+				),
128
+				'ATT_ID'           => new EE_Foreign_Key_Int_Field(
129
+					'ATT_ID', __('Attendee ID', 'event_espresso'), false, 0, 'Attendee'
130
+				),
131
+				'TXN_ID'           => new EE_Foreign_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso'),
132
+					false, 0, 'Transaction'
133
+				),
134
+				'TKT_ID'           => new EE_Foreign_Key_Int_Field('TKT_ID', __('Ticket ID', 'event_espresso'), false,
135
+					0, 'Ticket'
136
+				),
137
+				'STS_ID'           => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'),
138
+					false, EEM_Registration::status_id_incomplete, 'Status'
139
+				),
140
+				'REG_date'         => new EE_Datetime_Field('REG_date',
141
+					__('Time registration occurred', 'event_espresso'), false, EE_Datetime_Field::now, $timezone
142
+				),
143
+				'REG_final_price'  => new EE_Money_Field('REG_final_price',
144
+					__('Registration\'s share of the transaction total', 'event_espresso'), false, 0
145
+				),
146
+				'REG_paid'         => new EE_Money_Field('REG_paid',
147
+					__('Amount paid to date towards registration', 'event_espresso'), false, 0
148
+				),
149
+				'REG_session'      => new EE_Plain_Text_Field('REG_session',
150
+					__('Session ID of registration', 'event_espresso'), false, ''
151
+				),
152
+				'REG_code'         => new EE_Plain_Text_Field('REG_code',
153
+					__('Unique Code for this registration', 'event_espresso'), false, ''
154
+				),
155
+				'REG_url_link'     => new EE_Plain_Text_Field('REG_url_link',
156
+					__('String to be used in URL for identifying registration', 'event_espresso'), false, ''
157
+				),
158
+				'REG_count'        => new EE_Integer_Field('REG_count',
159
+					__('Count of this registration in the group registration ', 'event_espresso'), true, 1
160
+				),
161
+				'REG_group_size'   => new EE_Integer_Field('REG_group_size',
162
+					__('Number of registrations on this group', 'event_espresso'), false, 1
163
+				),
164
+				'REG_att_is_going' => new EE_Boolean_Field('REG_att_is_going',
165
+					__('Flag indicating the registrant plans on attending', 'event_espresso'), false, false
166
+				),
167
+				'REG_deleted'      => new EE_Trashed_Flag_Field(
168
+					'REG_deleted', __('Flag indicating if registration has been archived or not.', 'event_espresso'),
169
+					false, false
170
+				),
171
+			),
172
+		);
173
+		$this->_model_relations = array(
174
+			'Event'                => new EE_Belongs_To_Relation(),
175
+			'Attendee'             => new EE_Belongs_To_Relation(),
176
+			'Transaction'          => new EE_Belongs_To_Relation(),
177
+			'Ticket'               => new EE_Belongs_To_Relation(),
178
+			'Status'               => new EE_Belongs_To_Relation(),
179
+			'Answer'               => new EE_Has_Many_Relation(),
180
+			'Checkin'              => new EE_Has_Many_Relation(),
181
+			'Registration_Payment' => new EE_Has_Many_Relation(),
182
+			'Payment'              => new EE_HABTM_Relation('Registration_Payment'),
183
+			'Message'              => new EE_Has_Many_Any_Relation(false)
184
+			//allow deletes even if there are messages in the queue related
185
+		);
186
+		$this->_model_chain_to_wp_user = 'Event';
187
+		parent::__construct($timezone);
188
+	}
189
+
190
+
191
+
192
+	/**
193
+	 * reg_statuses_that_allow_payment
194
+	 * a filterable list of registration statuses that allow a registrant to make a payment
195
+	 *
196
+	 * @access public
197
+	 * @return array
198
+	 */
199
+	public static function reg_statuses_that_allow_payment()
200
+	{
201
+		return apply_filters(
202
+			'FHEE__EEM_Registration__reg_statuses_that_allow_payment',
203
+			array(
204
+				EEM_Registration::status_id_approved,
205
+				EEM_Registration::status_id_pending_payment,
206
+				EEM_Registration::status_id_wait_list,
207
+			)
208
+		);
209
+	}
210
+
211
+
212
+
213
+	/**
214
+	 * inactive_reg_statuses
215
+	 * a filterable list of registration statuses that are considered active
216
+	 *
217
+	 * @access public
218
+	 * @return array
219
+	 */
220
+	public static function active_reg_statuses()
221
+	{
222
+		return apply_filters(
223
+			'FHEE__EEM_Registration__reg_statuses_that_allow_payment',
224
+			array(
225
+				EEM_Registration::status_id_approved,
226
+				EEM_Registration::status_id_pending_payment,
227
+				EEM_Registration::status_id_wait_list,
228
+				EEM_Registration::status_id_not_approved,
229
+			)
230
+		);
231
+	}
232
+
233
+
234
+
235
+	/**
236
+	 * inactive_reg_statuses
237
+	 * a filterable list of registration statuses that are not considered active
238
+	 *
239
+	 * @access public
240
+	 * @return array
241
+	 */
242
+	public static function inactive_reg_statuses()
243
+	{
244
+		return apply_filters(
245
+			'FHEE__EEM_Registration__reg_statuses_that_allow_payment',
246
+			array(
247
+				EEM_Registration::status_id_incomplete,
248
+				EEM_Registration::status_id_cancelled,
249
+				EEM_Registration::status_id_declined,
250
+			)
251
+		);
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 *    closed_reg_statuses
258
+	 *    a filterable list of registration statuses that are considered "closed"
259
+	 * meaning they should not be considered in any calculations involving monies owing
260
+	 *
261
+	 * @access public
262
+	 * @return array
263
+	 */
264
+	public static function closed_reg_statuses()
265
+	{
266
+		return apply_filters(
267
+			'FHEE__EEM_Registration__closed_reg_statuses',
268
+			array(
269
+				EEM_Registration::status_id_cancelled,
270
+				EEM_Registration::status_id_declined,
271
+			)
272
+		);
273
+	}
274
+
275
+
276
+
277
+	/**
278
+	 *        get list of registration statuses
279
+	 *
280
+	 * @access public
281
+	 * @param array $exclude    The status ids to exclude from the returned results
282
+	 * @param bool  $translated If true will return the values as singular localized strings
283
+	 * @return array
284
+	 */
285
+	public static function reg_status_array($exclude = array(), $translated = false)
286
+	{
287
+		EEM_Registration::instance()->_get_registration_status_array($exclude);
288
+		return $translated ? EEM_Status::instance()->localized_status(self::$_reg_status, false, 'sentence')
289
+			: self::$_reg_status;
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 *    get list of registration statuses
296
+	 *
297
+	 * @access private
298
+	 * @param array $exclude
299
+	 * @return array
300
+	 */
301
+	private function _get_registration_status_array($exclude = array())
302
+	{
303
+		//in the very rare circumstance that we are deleting a model's table's data
304
+		//and the table hasn't actually been created, this could have an error
305
+		/** @type WPDB $wpdb */
306
+		global $wpdb;
307
+		if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
308
+			$results = $wpdb->get_results(
309
+				"SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
310
+			);
311
+			self::$_reg_status = array();
312
+			foreach ($results as $status) {
313
+				if ( ! in_array($status->STS_ID, $exclude)) {
314
+					self::$_reg_status[$status->STS_ID] = $status->STS_code;
315
+				}
316
+			}
317
+		}
318
+	}
319
+
320
+
321
+
322
+	/**
323
+	 * Gets the injected table analyzer, or throws an exception
324
+	 *
325
+	 * @return TableAnalysis
326
+	 * @throws \EE_Error
327
+	 */
328
+	protected function _get_table_analysis()
329
+	{
330
+		if ($this->_table_analysis instanceof TableAnalysis) {
331
+			return $this->_table_analysis;
332
+		} else {
333
+			throw new \EE_Error(
334
+				sprintf(
335
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
336
+					get_class($this)
337
+				)
338
+			);
339
+		}
340
+	}
341
+
342
+
343
+
344
+	/**
345
+	 * This returns a wpdb->results array of all registration date month and years matching the incoming query params
346
+	 * and grouped by month and year.
347
+	 *
348
+	 * @param  array $where_params Array of query_params as described in the comments for EEM_Base::get_all()
349
+	 * @return array
350
+	 * @throws \EE_Error
351
+	 */
352
+	public function get_reg_months_and_years($where_params)
353
+	{
354
+		$query_params[0] = $where_params;
355
+		$query_params['group_by'] = array('reg_year', 'reg_month');
356
+		$query_params['order_by'] = array('REG_date' => 'DESC');
357
+		$columns_to_select = array(
358
+			'reg_year'  => array('YEAR(REG_date)', '%s'),
359
+			'reg_month' => array('MONTHNAME(REG_date)', '%s'),
360
+		);
361
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
362
+	}
363
+
364
+
365
+
366
+	/**
367
+	 *        retrieve ALL registrations for a particular Attendee from db
368
+	 *
369
+	 * @access        public
370
+	 * @param        int $ATT_ID
371
+	 * @return    EE_Registration[]
372
+	 */
373
+	public function get_all_registrations_for_attendee($ATT_ID = 0)
374
+	{
375
+		if ( ! $ATT_ID) {
376
+			return false;
377
+		}
378
+		return $this->get_all(array(array('ATT_ID' => $ATT_ID)));
379
+	}
380
+
381
+
382
+
383
+	/**
384
+	 * Gets a registration given their REG_url_link. Yes, this should usually
385
+	 * be passed via a GET parameter.
386
+	 *
387
+	 * @param string $REG_url_link
388
+	 * @return EE_Registration
389
+	 */
390
+	public function get_registration_for_reg_url_link($REG_url_link)
391
+	{
392
+		if ( ! $REG_url_link) {
393
+			return false;
394
+		}
395
+		return $this->get_one(array(array('REG_url_link' => $REG_url_link)));
396
+	}
397
+
398
+
399
+
400
+	/**
401
+	 *        retrieve registration for a specific transaction attendee from db
402
+	 *
403
+	 * @access        public
404
+	 * @param    int $TXN_ID
405
+	 * @param    int $ATT_ID
406
+	 * @param    int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the
407
+	 *                         attendee number is required
408
+	 * @return        mixed        array on success, FALSE on fail
409
+	 */
410
+	public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0)
411
+	{
412
+		return $this->get_one(array(
413
+			array(
414
+				'TXN_ID' => $TXN_ID,
415
+				'ATT_ID' => $ATT_ID,
416
+			),
417
+			'limit' => array(min(($att_nmbr - 1), 0), 1),
418
+		));
419
+	}
420
+
421
+
422
+
423
+	/**
424
+	 *        get the number of registrations per day  for the Registration Admin page Reports Tab.
425
+	 *        (doesn't utilize models because it's a fairly specialized query)
426
+	 *
427
+	 * @access        public
428
+	 * @param $period string which can be passed to php's strtotime function (eg "-1 month")
429
+	 * @return stdClass[] with properties regDate and total
430
+	 */
431
+	public function get_registrations_per_day_report($period = '-1 month')
432
+	{
433
+		$sql_date = $this->convert_datetime_for_query('REG_date', date("Y-m-d H:i:s", strtotime($period)),
434
+			'Y-m-d H:i:s', 'UTC');
435
+		$where = array(
436
+			'REG_date' => array('>=', $sql_date),
437
+			'STS_ID'   => array('!=', EEM_Registration::status_id_incomplete),
438
+		);
439
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
440
+			$where['Event.EVT_wp_user'] = get_current_user_id();
441
+		}
442
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
443
+		$results = $this->_get_all_wpdb_results(
444
+			array(
445
+				$where,
446
+				'group_by' => 'regDate',
447
+				'order_by' => array('REG_date' => 'ASC'),
448
+			),
449
+			OBJECT,
450
+			array(
451
+				'regDate' => array('DATE(' . $query_interval . ')', '%s'),
452
+				'total'   => array('count(REG_ID)', '%d'),
453
+			));
454
+		return $results;
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * Get the number of registrations per day including the count of registrations for each Registration Status.
461
+	 * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
462
+	 *
463
+	 * @param string $period
464
+	 * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID
465
+	 *                    (i.e. RAP)
466
+	 */
467
+	public function get_registrations_per_day_and_per_status_report($period = '-1 month')
468
+	{
469
+		global $wpdb;
470
+		$registration_table = $wpdb->prefix . 'esp_registration';
471
+		$event_table = $wpdb->posts;
472
+		$sql_date = date("Y-m-d H:i:s", strtotime($period));
473
+		//prepare the query interval for displaying offset
474
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date');
475
+		//inner date query
476
+		$inner_date_query = "SELECT DISTINCT REG_date from $registration_table ";
477
+		$inner_where = " WHERE";
478
+		//exclude events not authored by user if permissions in effect
479
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
480
+			$inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
481
+			$inner_where .= " post_author = " . get_current_user_id() . " AND";
482
+		}
483
+		$inner_where .= " REG_date >= '$sql_date'";
484
+		$inner_date_query .= $inner_where;
485
+		//start main query
486
+		$select = "SELECT DATE($query_interval) as Registration_REG_date, ";
487
+		$join = '';
488
+		$join_parts = array();
489
+		$select_parts = array();
490
+		//loop through registration stati to do parts for each status.
491
+		foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
492
+			if ($STS_ID === EEM_Registration::status_id_incomplete) {
493
+				continue;
494
+			}
495
+			$select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID";
496
+			$join_parts[] = "$registration_table AS $STS_code ON $STS_code.REG_date = dates.REG_date AND $STS_code.STS_ID = '$STS_ID'";
497
+		}
498
+		//setup the selects
499
+		$select .= implode(', ', $select_parts);
500
+		$select .= " FROM ($inner_date_query) AS dates LEFT JOIN ";
501
+		//setup the joins
502
+		$join .= implode(" LEFT JOIN ", $join_parts);
503
+		//now let's put it all together
504
+		$query = $select . $join . ' GROUP BY Registration_REG_date';
505
+		//and execute it
506
+		$results = $wpdb->get_results($query, ARRAY_A);
507
+		return $results;
508
+	}
509
+
510
+
511
+
512
+	/**
513
+	 *        get the number of registrations per event  for the Registration Admin page Reports Tab
514
+	 *
515
+	 * @access        public
516
+	 * @param $period string which can be passed to php's strtotime function (eg "-1 month")
517
+	 * @return stdClass[] each with properties event_name, reg_limit, and total
518
+	 */
519
+	public function get_registrations_per_event_report($period = '-1 month')
520
+	{
521
+		$date_sql = $this->convert_datetime_for_query('REG_date', date("Y-m-d H:i:s", strtotime($period)),
522
+			'Y-m-d H:i:s', 'UTC');
523
+		$where = array(
524
+			'REG_date' => array('>=', $date_sql),
525
+			'STS_ID'   => array('!=', EEM_Registration::status_id_incomplete),
526
+		);
527
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
528
+			$where['Event.EVT_wp_user'] = get_current_user_id();
529
+		}
530
+		$results = $this->_get_all_wpdb_results(array(
531
+			$where,
532
+			'group_by' => 'Event.EVT_name',
533
+			'order_by' => 'Event.EVT_name',
534
+			'limit'    => array(0, 24),
535
+		),
536
+			OBJECT,
537
+			array(
538
+				'event_name' => array('Event_CPT.post_title', '%s'),
539
+				'total'      => array('COUNT(REG_ID)', '%s'),
540
+			)
541
+		);
542
+		return $results;
543
+	}
544
+
545
+
546
+
547
+	/**
548
+	 * Get the number of registrations per event grouped by registration status.
549
+	 * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
550
+	 *
551
+	 * @param string $period
552
+	 * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID
553
+	 *                    (i.e. RAP)
554
+	 */
555
+	public function get_registrations_per_event_and_per_status_report($period = '-1 month')
556
+	{
557
+		global $wpdb;
558
+		$registration_table = $wpdb->prefix . 'esp_registration';
559
+		$event_table = $wpdb->posts;
560
+		$sql_date = date("Y-m-d H:i:s", strtotime($period));
561
+		//inner date query
562
+		$inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
563
+		$inner_where = " WHERE";
564
+		//exclude events not authored by user if permissions in effect
565
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
566
+			$inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
567
+			$inner_where .= " post_author = " . get_current_user_id() . " AND";
568
+		}
569
+		$inner_where .= " REG_date >= '$sql_date'";
570
+		$inner_date_query .= $inner_where;
571
+		//build main query
572
+		$select = "SELECT Event.post_title as Registration_Event, ";
573
+		$join = '';
574
+		$join_parts = array();
575
+		$select_parts = array();
576
+		//loop through registration stati to do parts for each status.
577
+		foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
578
+			if ($STS_ID === EEM_Registration::status_id_incomplete) {
579
+				continue;
580
+			}
581
+			$select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID";
582
+			$join_parts[] = "$registration_table AS $STS_code ON $STS_code.EVT_ID = dates.EVT_ID AND $STS_code.STS_ID = '$STS_ID' AND $STS_code.REG_date = dates.REG_date";
583
+		}
584
+		//setup the selects
585
+		$select .= implode(', ', $select_parts);
586
+		$select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN ";
587
+		//setup remaining joins
588
+		$join .= implode(" LEFT JOIN ", $join_parts);
589
+		//now put it all together
590
+		$query = $select . $join . ' GROUP BY Registration_Event';
591
+		//and execute
592
+		$results = $wpdb->get_results($query, ARRAY_A);
593
+		return $results;
594
+	}
595
+
596
+
597
+
598
+	/**
599
+	 * Returns the EE_Registration of the primary attendee on the transaction id provided
600
+	 *
601
+	 * @param int $TXN_ID
602
+	 * @return EE_Registration
603
+	 */
604
+	public function get_primary_registration_for_transaction_ID($TXN_ID = 0)
605
+	{
606
+		if ( ! $TXN_ID) {
607
+			return false;
608
+		}
609
+		return $this->get_one(array(
610
+			array(
611
+				'TXN_ID'    => $TXN_ID,
612
+				'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT,
613
+			),
614
+		));
615
+	}
616
+
617
+
618
+
619
+	/**
620
+	 *        get_event_registration_count
621
+	 *
622
+	 * @access public
623
+	 * @param int     $EVT_ID
624
+	 * @param boolean $for_incomplete_payments
625
+	 * @return int
626
+	 */
627
+	public function get_event_registration_count($EVT_ID, $for_incomplete_payments = false)
628
+	{
629
+		// we only count approved registrations towards registration limits
630
+		$query_params = array(array('EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved));
631
+		if ($for_incomplete_payments) {
632
+			$query_params[0]['Transaction.STS_ID'] = array('!=', EEM_Transaction::complete_status_code);
633
+		}
634
+		return $this->count($query_params);
635
+	}
636
+
637
+
638
+
639
+	/**
640
+	 * Deletes all registrations with no transactions. Note that this needs to be very efficient
641
+	 * and so it uses wpdb directly
642
+	 *
643
+	 * @global WPDB $wpdb
644
+	 * @return int number deleted
645
+	 */
646
+	public function delete_registrations_with_no_transaction()
647
+	{
648
+		/** @type WPDB $wpdb */
649
+		global $wpdb;
650
+		return $wpdb->query(
651
+			'DELETE r FROM '
652
+			. $this->table()
653
+			. ' r LEFT JOIN '
654
+			. EEM_Transaction::instance()->table()
655
+			. ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL');
656
+	}
657
+
658
+
659
+
660
+	/**
661
+	 *  Count registrations checked into (or out of) a datetime
662
+	 *
663
+	 * @param int     $DTT_ID     datetime ID
664
+	 * @param boolean $checked_in whether to count registrations checked IN or OUT
665
+	 * @return int
666
+	 */
667
+	public function count_registrations_checked_into_datetime($DTT_ID, $checked_in = true)
668
+	{
669
+		global $wpdb;
670
+		//subquery to get latest checkin
671
+		$query = $wpdb->prepare(
672
+			'SELECT '
673
+			. 'COUNT( DISTINCT checkins.REG_ID ) '
674
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
675
+			. '( SELECT '
676
+			. 'max( CHK_timestamp ) AS latest_checkin, '
677
+			. 'REG_ID AS REG_ID '
678
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' '
679
+			. 'WHERE DTT_ID=%d '
680
+			. 'GROUP BY REG_ID'
681
+			. ') AS most_recent_checkin_per_reg '
682
+			. 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
683
+			. 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
684
+			. 'WHERE '
685
+			. 'checkins.CHK_in=%d',
686
+			$DTT_ID,
687
+			$checked_in
688
+		);
689
+		return (int)$wpdb->get_var($query);
690
+	}
691
+
692
+
693
+
694
+	/**
695
+	 *  Count registrations checked into (or out of) an event.
696
+	 *
697
+	 * @param int     $EVT_ID     event ID
698
+	 * @param boolean $checked_in whether to count registrations checked IN or OUT
699
+	 * @return int
700
+	 */
701
+	public function count_registrations_checked_into_event($EVT_ID, $checked_in = true)
702
+	{
703
+		global $wpdb;
704
+		//subquery to get latest checkin
705
+		$query = $wpdb->prepare(
706
+			'SELECT '
707
+			. 'COUNT( DISTINCT checkins.REG_ID ) '
708
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
709
+			. '( SELECT '
710
+			. 'max( CHK_timestamp ) AS latest_checkin, '
711
+			. 'REG_ID AS REG_ID '
712
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
713
+			. 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
714
+			. 'ON c.DTT_ID=d.DTT_ID '
715
+			. 'WHERE d.EVT_ID=%d '
716
+			. 'GROUP BY REG_ID'
717
+			. ') AS most_recent_checkin_per_reg '
718
+			. 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
719
+			. 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
720
+			. 'WHERE '
721
+			. 'checkins.CHK_in=%d',
722
+			$EVT_ID,
723
+			$checked_in
724
+		);
725
+		return (int)$wpdb->get_var($query);
726
+	}
727
+
728
+
729
+
730
+	/**
731
+	 * The purpose of this method is to retrieve an array of
732
+	 * EE_Registration objects that represent the latest registration
733
+	 * for each ATT_ID given in the function argument.
734
+	 *
735
+	 * @param array $attendee_ids
736
+	 * @return EE_Registration[]
737
+	 */
738
+	public function get_latest_registration_for_each_of_given_contacts($attendee_ids = array())
739
+	{
740
+		//first do a native wp_query to get the latest REG_ID's matching these attendees.
741
+		global $wpdb;
742
+		$registration_table = $wpdb->prefix . 'esp_registration';
743
+		$attendee_table = $wpdb->posts;
744
+		$attendee_ids = is_array($attendee_ids)
745
+			? array_map('absint', $attendee_ids)
746
+			: array((int)$attendee_ids);
747
+		$attendee_ids = implode(',', $attendee_ids);
748
+		//first we do a query to get the registration ids
749
+		// (because a group by before order by causes the order by to be ignored.)
750
+		$registration_id_query = "
751 751
 			SELECT registrations.registration_ids as registration_id
752 752
 			FROM (
753 753
 				SELECT
@@ -761,23 +761,23 @@  discard block
 block discarded – undo
761 761
 			  ) AS registrations
762 762
 			  GROUP BY registrations.attendee_ids
763 763
 		";
764
-        $registration_ids = $wpdb->get_results($registration_id_query, ARRAY_A);
765
-        if (empty($registration_ids)) {
766
-            return array();
767
-        }
768
-        $ids_for_model_query = array();
769
-        //let's flatten the ids so they can be used in the model query.
770
-        foreach ($registration_ids as $registration_id) {
771
-            if (isset($registration_id['registration_id'])) {
772
-                $ids_for_model_query[] = $registration_id['registration_id'];
773
-            }
774
-        }
775
-        //construct query
776
-        $_where = array(
777
-            'REG_ID' => array('IN', $ids_for_model_query),
778
-        );
779
-        return $this->get_all(array($_where));
780
-    }
764
+		$registration_ids = $wpdb->get_results($registration_id_query, ARRAY_A);
765
+		if (empty($registration_ids)) {
766
+			return array();
767
+		}
768
+		$ids_for_model_query = array();
769
+		//let's flatten the ids so they can be used in the model query.
770
+		foreach ($registration_ids as $registration_id) {
771
+			if (isset($registration_id['registration_id'])) {
772
+				$ids_for_model_query[] = $registration_id['registration_id'];
773
+			}
774
+		}
775
+		//construct query
776
+		$_where = array(
777
+			'REG_ID' => array('IN', $ids_for_model_query),
778
+		);
779
+		return $this->get_all(array($_where));
780
+	}
781 781
 
782 782
 
783 783
 
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
         //and the table hasn't actually been created, this could have an error
305 305
         /** @type WPDB $wpdb */
306 306
         global $wpdb;
307
-        if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
307
+        if ($this->_get_table_analysis()->tableExists($wpdb->prefix.'esp_status')) {
308 308
             $results = $wpdb->get_results(
309 309
                 "SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
310 310
             );
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
             ),
449 449
             OBJECT,
450 450
             array(
451
-                'regDate' => array('DATE(' . $query_interval . ')', '%s'),
451
+                'regDate' => array('DATE('.$query_interval.')', '%s'),
452 452
                 'total'   => array('count(REG_ID)', '%d'),
453 453
             ));
454 454
         return $results;
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
     public function get_registrations_per_day_and_per_status_report($period = '-1 month')
468 468
     {
469 469
         global $wpdb;
470
-        $registration_table = $wpdb->prefix . 'esp_registration';
470
+        $registration_table = $wpdb->prefix.'esp_registration';
471 471
         $event_table = $wpdb->posts;
472 472
         $sql_date = date("Y-m-d H:i:s", strtotime($period));
473 473
         //prepare the query interval for displaying offset
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
         //exclude events not authored by user if permissions in effect
479 479
         if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
480 480
             $inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
481
-            $inner_where .= " post_author = " . get_current_user_id() . " AND";
481
+            $inner_where .= " post_author = ".get_current_user_id()." AND";
482 482
         }
483 483
         $inner_where .= " REG_date >= '$sql_date'";
484 484
         $inner_date_query .= $inner_where;
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
         //setup the joins
502 502
         $join .= implode(" LEFT JOIN ", $join_parts);
503 503
         //now let's put it all together
504
-        $query = $select . $join . ' GROUP BY Registration_REG_date';
504
+        $query = $select.$join.' GROUP BY Registration_REG_date';
505 505
         //and execute it
506 506
         $results = $wpdb->get_results($query, ARRAY_A);
507 507
         return $results;
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
     public function get_registrations_per_event_and_per_status_report($period = '-1 month')
556 556
     {
557 557
         global $wpdb;
558
-        $registration_table = $wpdb->prefix . 'esp_registration';
558
+        $registration_table = $wpdb->prefix.'esp_registration';
559 559
         $event_table = $wpdb->posts;
560 560
         $sql_date = date("Y-m-d H:i:s", strtotime($period));
561 561
         //inner date query
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
         //exclude events not authored by user if permissions in effect
565 565
         if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
566 566
             $inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
567
-            $inner_where .= " post_author = " . get_current_user_id() . " AND";
567
+            $inner_where .= " post_author = ".get_current_user_id()." AND";
568 568
         }
569 569
         $inner_where .= " REG_date >= '$sql_date'";
570 570
         $inner_date_query .= $inner_where;
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
         //setup remaining joins
588 588
         $join .= implode(" LEFT JOIN ", $join_parts);
589 589
         //now put it all together
590
-        $query = $select . $join . ' GROUP BY Registration_Event';
590
+        $query = $select.$join.' GROUP BY Registration_Event';
591 591
         //and execute
592 592
         $results = $wpdb->get_results($query, ARRAY_A);
593 593
         return $results;
@@ -671,11 +671,11 @@  discard block
 block discarded – undo
671 671
         $query = $wpdb->prepare(
672 672
             'SELECT '
673 673
             . 'COUNT( DISTINCT checkins.REG_ID ) '
674
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
674
+            . 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN'
675 675
             . '( SELECT '
676 676
             . 'max( CHK_timestamp ) AS latest_checkin, '
677 677
             . 'REG_ID AS REG_ID '
678
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' '
678
+            . 'FROM '.EEM_Checkin::instance()->table().' '
679 679
             . 'WHERE DTT_ID=%d '
680 680
             . 'GROUP BY REG_ID'
681 681
             . ') AS most_recent_checkin_per_reg '
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
             $DTT_ID,
687 687
             $checked_in
688 688
         );
689
-        return (int)$wpdb->get_var($query);
689
+        return (int) $wpdb->get_var($query);
690 690
     }
691 691
 
692 692
 
@@ -705,12 +705,12 @@  discard block
 block discarded – undo
705 705
         $query = $wpdb->prepare(
706 706
             'SELECT '
707 707
             . 'COUNT( DISTINCT checkins.REG_ID ) '
708
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
708
+            . 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN'
709 709
             . '( SELECT '
710 710
             . 'max( CHK_timestamp ) AS latest_checkin, '
711 711
             . 'REG_ID AS REG_ID '
712
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
713
-            . 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
712
+            . 'FROM '.EEM_Checkin::instance()->table().' AS c '
713
+            . 'INNER JOIN '.EEM_Datetime::instance()->table().' AS d '
714 714
             . 'ON c.DTT_ID=d.DTT_ID '
715 715
             . 'WHERE d.EVT_ID=%d '
716 716
             . 'GROUP BY REG_ID'
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
             $EVT_ID,
723 723
             $checked_in
724 724
         );
725
-        return (int)$wpdb->get_var($query);
725
+        return (int) $wpdb->get_var($query);
726 726
     }
727 727
 
728 728
 
@@ -739,11 +739,11 @@  discard block
 block discarded – undo
739 739
     {
740 740
         //first do a native wp_query to get the latest REG_ID's matching these attendees.
741 741
         global $wpdb;
742
-        $registration_table = $wpdb->prefix . 'esp_registration';
742
+        $registration_table = $wpdb->prefix.'esp_registration';
743 743
         $attendee_table = $wpdb->posts;
744 744
         $attendee_ids = is_array($attendee_ids)
745 745
             ? array_map('absint', $attendee_ids)
746
-            : array((int)$attendee_ids);
746
+            : array((int) $attendee_ids);
747 747
         $attendee_ids = implode(',', $attendee_ids);
748 748
         //first we do a query to get the registration ids
749 749
         // (because a group by before order by causes the order by to be ignored.)
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/RegistrationsReport.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -418,7 +418,7 @@
 block discarded – undo
418 418
      * In this case, we delete the temporary file
419 419
      *
420 420
      * @param JobParameters $job_parameters
421
-     * @return boolean
421
+     * @return JobStepResponse
422 422
      */
423 423
     public function cleanup_job(JobParameters $job_parameters)
424 424
     {
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -174,7 +174,7 @@
 block discarded – undo
174 174
                 $job_parameters->extra_datum('query_params'));
175 175
             \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
176 176
             $units_processed = count($csv_data);
177
-        }else{
177
+        } else{
178 178
             $units_processed = 0;
179 179
         }
180 180
         $job_parameters->mark_processed($units_processed);
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
                 array_diff_key(
84 84
                     $query_params,
85 85
                     array_flip(
86
-                        array( 'limit' )
86
+                        array('limit')
87 87
                     )
88 88
                 )
89 89
             )
@@ -130,11 +130,11 @@  discard block
 block discarded – undo
130 130
             );
131 131
         }
132 132
         $question_query_params[0]['QST_system'] = array('NOT_IN', array_keys(\EEM_Attendee::instance()->system_question_to_attendee_field_mapping()));
133
-        if(apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) {
133
+        if (apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) {
134 134
             $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
135 135
         }
136
-        $question_query_params['group_by'] = array( 'QST_ID' );
137
-        return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) );
136
+        $question_query_params['group_by'] = array('QST_ID');
137
+        return array_unique(\EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
138 138
     }
139 139
 
140 140
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
                 $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val);
154 154
             } else {
155 155
                 //it's a normal where condition
156
-                $question_where_params['Question_Group.Event.Registration.' . $key] = $val;
156
+                $question_where_params['Question_Group.Event.Registration.'.$key] = $val;
157 157
             }
158 158
         }
159 159
         return $question_where_params;
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
      */
172 172
     public function continue_job(JobParameters $job_parameters, $batch_size = 50)
173 173
     {
174
-        if( $job_parameters->units_processed() < $job_parameters->job_size() ) {
174
+        if ($job_parameters->units_processed() < $job_parameters->job_size()) {
175 175
             $csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'),
176 176
                 $job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'),
177 177
                 $job_parameters->extra_datum('query_params'));
178 178
             \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
179 179
             $units_processed = count($csv_data);
180
-        }else{
180
+        } else {
181 181
             $units_processed = 0;
182 182
         }
183 183
         $job_parameters->mark_processed($units_processed);
Please login to merge, or discard this patch.
Indentation   +414 added lines, -415 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 use EventEspressoBatchRequest\Helpers\JobStepResponse;
18 18
 
19 19
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
20
-    exit('No direct script access allowed');
20
+	exit('No direct script access allowed');
21 21
 }
22 22
 
23 23
 
@@ -25,443 +25,442 @@  discard block
 block discarded – undo
25 25
 class RegistrationsReport extends JobHandlerFile
26 26
 {
27 27
 
28
-    /**
29
-     * Performs any necessary setup for starting the job. This is also a good
30
-     * place to setup the $job_arguments which will be used for subsequent HTTP requests
31
-     * when continue_job will be called
32
-     *
33
-     * @param JobParameters $job_parameters
34
-     * @throws BatchRequestException
35
-     * @return JobStepResponse
36
-     */
37
-    public function create_job(JobParameters $job_parameters)
38
-    {
39
-        $event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
40
-        if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
41
-            throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
42
-        }
43
-        $filepath = $this->create_file_from_job_with_name($job_parameters->job_id(),
44
-            $this->get_filename($event_id));
45
-        $job_parameters->add_extra_data('filepath', $filepath);
46
-        if ($job_parameters->request_datum('use_filters', false)) {
47
-            $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
48
-        } else {
49
-            $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
50
-                array(
51
-                    'OR'                 => array(
52
-                        //don't include registrations from failed or abandoned transactions...
53
-                        'Transaction.STS_ID' => array(
54
-                            'NOT IN',
55
-                            array(
56
-                                \EEM_Transaction::failed_status_code,
57
-                                \EEM_Transaction::abandoned_status_code,
58
-                            ),
59
-                        ),
60
-                        //unless the registration is approved, in which case include it regardless of transaction status
61
-                        'STS_ID'             => \EEM_Registration::status_id_approved,
62
-                    ),
63
-                    'Ticket.TKT_deleted' => array('IN', array(true, false)),
64
-                ),
65
-                'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
66
-                'force_join' => array('Transaction', 'Ticket', 'Attendee'),
67
-                'caps'       => \EEM_Base::caps_read_admin,
68
-            ), $event_id);
69
-            if ($event_id) {
70
-                $query_params[0]['EVT_ID'] = $event_id;
71
-            } else {
72
-                $query_params['force_join'][] = 'Event';
73
-            }
74
-        }
75
-        if ( ! isset($query_params['force_join'])) {
76
-            $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
77
-        }
78
-        $job_parameters->add_extra_data('query_params', $query_params);
79
-        $question_labels = $this->_get_question_labels($query_params);
80
-        $job_parameters->add_extra_data('question_labels', $question_labels);
81
-        $job_parameters->set_job_size(
82
-            \EEM_Registration::instance()->count(
83
-                array_diff_key(
84
-                    $query_params,
85
-                    array_flip(
86
-                        array( 'limit' )
87
-                    )
88
-                )
89
-            )
90
-        );
91
-        //we should also set the header columns
92
-        $csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $job_parameters->extra_datum('question_labels'),
93
-            $job_parameters->extra_datum('query_params'));
94
-        \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
95
-        //if we actually processed a row there, record it
96
-        if ($job_parameters->job_size()) {
97
-            $job_parameters->mark_processed(1);
98
-        }
99
-        return new JobStepResponse($job_parameters,
100
-            __('Registrations report started successfully...', 'event_espresso'));
101
-    }
28
+	/**
29
+	 * Performs any necessary setup for starting the job. This is also a good
30
+	 * place to setup the $job_arguments which will be used for subsequent HTTP requests
31
+	 * when continue_job will be called
32
+	 *
33
+	 * @param JobParameters $job_parameters
34
+	 * @throws BatchRequestException
35
+	 * @return JobStepResponse
36
+	 */
37
+	public function create_job(JobParameters $job_parameters)
38
+	{
39
+		$event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
40
+		if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
41
+			throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
42
+		}
43
+		$filepath = $this->create_file_from_job_with_name($job_parameters->job_id(),
44
+			$this->get_filename($event_id));
45
+		$job_parameters->add_extra_data('filepath', $filepath);
46
+		if ($job_parameters->request_datum('use_filters', false)) {
47
+			$query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
48
+		} else {
49
+			$query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
50
+				array(
51
+					'OR'                 => array(
52
+						//don't include registrations from failed or abandoned transactions...
53
+						'Transaction.STS_ID' => array(
54
+							'NOT IN',
55
+							array(
56
+								\EEM_Transaction::failed_status_code,
57
+								\EEM_Transaction::abandoned_status_code,
58
+							),
59
+						),
60
+						//unless the registration is approved, in which case include it regardless of transaction status
61
+						'STS_ID'             => \EEM_Registration::status_id_approved,
62
+					),
63
+					'Ticket.TKT_deleted' => array('IN', array(true, false)),
64
+				),
65
+				'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
66
+				'force_join' => array('Transaction', 'Ticket', 'Attendee'),
67
+				'caps'       => \EEM_Base::caps_read_admin,
68
+			), $event_id);
69
+			if ($event_id) {
70
+				$query_params[0]['EVT_ID'] = $event_id;
71
+			} else {
72
+				$query_params['force_join'][] = 'Event';
73
+			}
74
+		}
75
+		if ( ! isset($query_params['force_join'])) {
76
+			$query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
77
+		}
78
+		$job_parameters->add_extra_data('query_params', $query_params);
79
+		$question_labels = $this->_get_question_labels($query_params);
80
+		$job_parameters->add_extra_data('question_labels', $question_labels);
81
+		$job_parameters->set_job_size(
82
+			\EEM_Registration::instance()->count(
83
+				array_diff_key(
84
+					$query_params,
85
+					array_flip(
86
+						array( 'limit' )
87
+					)
88
+				)
89
+			)
90
+		);
91
+		//we should also set the header columns
92
+		$csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $job_parameters->extra_datum('question_labels'),
93
+			$job_parameters->extra_datum('query_params'));
94
+		\EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
95
+		//if we actually processed a row there, record it
96
+		if ($job_parameters->job_size()) {
97
+			$job_parameters->mark_processed(1);
98
+		}
99
+		return new JobStepResponse($job_parameters,
100
+			__('Registrations report started successfully...', 'event_espresso'));
101
+	}
102 102
 
103 103
 
104 104
 
105
-    /**
106
-     * Gets the filename
107
-     * @return string
108
-     */
109
-    protected function get_filename()
110
-    {
111
-        return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql')));
112
-    }
105
+	/**
106
+	 * Gets the filename
107
+	 * @return string
108
+	 */
109
+	protected function get_filename()
110
+	{
111
+		return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql')));
112
+	}
113 113
 
114 114
 
115 115
 
116
-    /**
117
-     * Gets the questions which are to be used for this report, so they
118
-     * can be remembered for later
119
-     *
120
-     * @param array $registration_query_params
121
-     * @return array question admin labels to be used for this report
122
-     */
123
-    protected function _get_question_labels($registration_query_params)
124
-    {
125
-        $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
126
-        $question_query_params = array();
127
-        if ($where !== null) {
128
-            $question_query_params = array(
129
-                $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
130
-            );
131
-        }
132
-        $question_query_params[0]['QST_system'] = array('NOT_IN', array_keys(\EEM_Attendee::instance()->system_question_to_attendee_field_mapping()));
133
-        if(apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) {
134
-            $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
135
-        }
136
-        $question_query_params['group_by'] = array( 'QST_ID' );
137
-        return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) );
138
-    }
116
+	/**
117
+	 * Gets the questions which are to be used for this report, so they
118
+	 * can be remembered for later
119
+	 *
120
+	 * @param array $registration_query_params
121
+	 * @return array question admin labels to be used for this report
122
+	 */
123
+	protected function _get_question_labels($registration_query_params)
124
+	{
125
+		$where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
126
+		$question_query_params = array();
127
+		if ($where !== null) {
128
+			$question_query_params = array(
129
+				$this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
130
+			);
131
+		}
132
+		$question_query_params[0]['QST_system'] = array('NOT_IN', array_keys(\EEM_Attendee::instance()->system_question_to_attendee_field_mapping()));
133
+		if(apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) {
134
+			$question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
135
+		}
136
+		$question_query_params['group_by'] = array( 'QST_ID' );
137
+		return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) );
138
+	}
139 139
 
140 140
 
141 141
 
142
-    /**
143
-     * Takes where params meant for registrations and changes them to work for questions
144
-     *
145
-     * @param array $reg_where_params
146
-     * @return array
147
-     */
148
-    protected function _change_registration_where_params_to_question_where_params($reg_where_params)
149
-    {
150
-        $question_where_params = array();
151
-        foreach ($reg_where_params as $key => $val) {
152
-            if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
153
-                $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val);
154
-            } else {
155
-                //it's a normal where condition
156
-                $question_where_params['Question_Group.Event.Registration.' . $key] = $val;
157
-            }
158
-        }
159
-        return $question_where_params;
160
-    }
142
+	/**
143
+	 * Takes where params meant for registrations and changes them to work for questions
144
+	 *
145
+	 * @param array $reg_where_params
146
+	 * @return array
147
+	 */
148
+	protected function _change_registration_where_params_to_question_where_params($reg_where_params)
149
+	{
150
+		$question_where_params = array();
151
+		foreach ($reg_where_params as $key => $val) {
152
+			if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
153
+				$question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val);
154
+			} else {
155
+				//it's a normal where condition
156
+				$question_where_params['Question_Group.Event.Registration.' . $key] = $val;
157
+			}
158
+		}
159
+		return $question_where_params;
160
+	}
161 161
 
162 162
 
163 163
 
164
-    /**
165
-     * Performs another step of the job
166
-     *
167
-     * @param JobParameters $job_parameters
168
-     * @param int           $batch_size
169
-     * @return JobStepResponse
170
-     * @throws \EE_Error
171
-     */
172
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
173
-    {
174
-        if( $job_parameters->units_processed() < $job_parameters->job_size() ) {
175
-            $csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'),
176
-                $job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'),
177
-                $job_parameters->extra_datum('query_params'));
178
-            \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
179
-            $units_processed = count($csv_data);
180
-        }else{
181
-            $units_processed = 0;
182
-        }
183
-        $job_parameters->mark_processed($units_processed);
184
-        $extra_response_data = array(
185
-            'file_url' => '',
186
-        );
187
-        if ($units_processed < $batch_size) {
188
-            $job_parameters->set_status(JobParameters::status_complete);
189
-            $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
190
-        }
164
+	/**
165
+	 * Performs another step of the job
166
+	 *
167
+	 * @param JobParameters $job_parameters
168
+	 * @param int           $batch_size
169
+	 * @return JobStepResponse
170
+	 * @throws \EE_Error
171
+	 */
172
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
173
+	{
174
+		if( $job_parameters->units_processed() < $job_parameters->job_size() ) {
175
+			$csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'),
176
+				$job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'),
177
+				$job_parameters->extra_datum('query_params'));
178
+			\EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
179
+			$units_processed = count($csv_data);
180
+		}else{
181
+			$units_processed = 0;
182
+		}
183
+		$job_parameters->mark_processed($units_processed);
184
+		$extra_response_data = array(
185
+			'file_url' => '',
186
+		);
187
+		if ($units_processed < $batch_size) {
188
+			$job_parameters->set_status(JobParameters::status_complete);
189
+			$extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
190
+		}
191 191
 
192
-        return new JobStepResponse($job_parameters,
193
-            sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count($csv_data)),
194
-            $extra_response_data);
195
-    }
192
+		return new JobStepResponse($job_parameters,
193
+			sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count($csv_data)),
194
+			$extra_response_data);
195
+	}
196 196
 
197 197
 
198 198
 
199
-    /**
200
-     * Gets the csv data for a batch of registrations
201
-
202
-     *
199
+	/**
200
+	 * Gets the csv data for a batch of registrations
201
+	 *
203 202
 *@param int|null    $event_id
204
-     * @param int   $offset
205
-     * @param int   $limit
206
-     * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
207
-     * @param array $query_params    for using where querying the model
208
-     * @return array top-level keys are numeric, next-level keys are column headers
209
-     */
210
-    function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
211
-    {
212
-        $reg_fields_to_include = array(
213
-            'TXN_ID',
214
-            'ATT_ID',
215
-            'REG_ID',
216
-            'REG_date',
217
-            'REG_code',
218
-            'REG_count',
219
-            'REG_final_price',
220
-        );
221
-        $att_fields_to_include = array(
222
-            'ATT_fname',
223
-            'ATT_lname',
224
-            'ATT_email',
225
-            'ATT_address',
226
-            'ATT_address2',
227
-            'ATT_city',
228
-            'STA_ID',
229
-            'CNT_ISO',
230
-            'ATT_zip',
231
-            'ATT_phone',
232
-        );
233
-        $registrations_csv_ready_array = array();
234
-        $reg_model = \EE_Registry::instance()->load_model('Registration');
235
-        $query_params['limit'] = array($offset, $limit);
236
-        $registration_rows = $reg_model->get_all_wpdb_results($query_params);
237
-        $registration_ids = array();
238
-        foreach ($registration_rows as $reg_row) {
239
-            $registration_ids[] = intval($reg_row['Registration.REG_ID']);
240
-        }
241
-        foreach ($registration_rows as $reg_row) {
242
-            if (is_array($reg_row)) {
243
-                $reg_csv_array = array();
244
-                if ( ! $event_id) {
245
-                    //get the event's name and Id
246
-                    $reg_csv_array[__('Event', 'event_espresso')] = sprintf(__('%1$s (%2$s)', 'event_espresso'),
247
-                        \EEH_Export::prepare_value_from_db_for_display(\EEM_Event::instance(), 'EVT_name',
248
-                            $reg_row['Event_CPT.post_title']), $reg_row['Event_CPT.ID']);
249
-                }
250
-                $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
251
-                /*@var $reg_row EE_Registration */
252
-                foreach ($reg_fields_to_include as $field_name) {
253
-                    $field = $reg_model->field_settings_for($field_name);
254
-                    if ($field_name == 'REG_final_price') {
255
-                        $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
256
-                            $reg_row['Registration.REG_final_price'], 'localized_float');
257
-                    } elseif ($field_name == 'REG_count') {
258
-                        $value = sprintf(__('%s of %s', 'event_espresso'),
259
-                            \EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_count',
260
-                                $reg_row['Registration.REG_count']),
261
-                            \EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_group_size',
262
-                                $reg_row['Registration.REG_group_size']));
263
-                    } elseif ($field_name == 'REG_date') {
264
-                        $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
265
-                            $reg_row['Registration.REG_date'], 'no_html');
266
-                    } else {
267
-                        $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
268
-                            $reg_row[$field->get_qualified_column()]);
269
-                    }
270
-                    $reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = $value;
271
-                    if ($field_name == 'REG_final_price') {
272
-                        //add a column named Currency after the final price
273
-                        $reg_csv_array[__("Currency", "event_espresso")] = \EE_Config::instance()->currency->code;
274
-                    }
275
-                }
276
-                //get pretty status
277
-                $stati = \EEM_Status::instance()->localized_status(array(
278
-                    $reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
279
-                    $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
280
-                ), false, 'sentence');
281
-                $reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']];
282
-                //get pretty transaction status
283
-                $reg_csv_array[__("Transaction Status",
284
-                    'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']];
285
-                $reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg
286
-                    ? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_total',
287
-                        $reg_row['TransactionTable.TXN_total'], 'localized_float') : '0.00';
288
-                $reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg
289
-                    ? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_paid',
290
-                        $reg_row['TransactionTable.TXN_paid'], 'localized_float') : '0.00';
291
-                $payment_methods = array();
292
-                $gateway_txn_ids_etc = array();
293
-                $payment_times = array();
294
-                if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
295
-                    $payments_info = \EEM_Payment::instance()->get_all_wpdb_results(array(
296
-                        array(
297
-                            'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
298
-                            'STS_ID' => \EEM_Payment::status_id_approved,
299
-                        ),
300
-                        'force_join' => array('Payment_Method'),
301
-                    ), ARRAY_A,
302
-                        'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time');
303
-                    foreach ($payments_info as $payment_method_and_gateway_txn_id) {
304
-                        $payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
305
-                            ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
306
-                        $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
307
-                            ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
308
-                        $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
309
-                            ? $payment_method_and_gateway_txn_id['payment_time'] : '';
310
-                    }
311
-                }
312
-                $reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times);
313
-                $reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods);
314
-                $reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode(',', $gateway_txn_ids_etc);
315
-                //get whether or not the user has checked in
316
-                $reg_csv_array[__("Check-Ins",
317
-                    "event_espresso")] = $reg_model->count_related($reg_row['Registration.REG_ID'], 'Checkin');
318
-                //get ticket of registration and its price
319
-                $ticket_model = \EE_Registry::instance()->load_model('Ticket');
320
-                if ($reg_row['Ticket.TKT_ID']) {
321
-                    $ticket_name = \EEH_Export::prepare_value_from_db_for_display($ticket_model, 'TKT_name',
322
-                        $reg_row['Ticket.TKT_name']);
323
-                    $datetimes_strings = array();
324
-                    foreach (
325
-                        \EEM_Datetime::instance()->get_all_wpdb_results(array(
326
-                            array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
327
-                            'order_by'                 => array('DTT_EVT_start' => 'ASC'),
328
-                            'default_where_conditions' => 'none',
329
-                        )) as $datetime
330
-                    ) {
331
-                        $datetimes_strings[] = \EEH_Export::prepare_value_from_db_for_display(\EEM_Datetime::instance(),
332
-                            'DTT_EVT_start', $datetime['Datetime.DTT_EVT_start']);
333
-                    }
334
-                } else {
335
-                    $ticket_name = __('Unknown', 'event_espresso');
336
-                    $datetimes_strings = array(__('Unknown', 'event_espresso'));
337
-                }
338
-                $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name;
339
-                $reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings);
340
-                //get datetime(s) of registration
341
-                //add attendee columns
342
-                foreach ($att_fields_to_include as $att_field_name) {
343
-                    $field_obj = \EEM_Attendee::instance()->field_settings_for($att_field_name);
344
-                    if ($reg_row['Attendee_CPT.ID']) {
345
-                        if ($att_field_name == 'STA_ID') {
346
-                            $value = \EEM_State::instance()
347
-                                               ->get_var(array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
348
-                                                   'STA_name');
349
-                        } elseif ($att_field_name == 'CNT_ISO') {
350
-                            $value = \EEM_Country::instance()
351
-                                                 ->get_var(array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
352
-                                                     'CNT_name');
353
-                        } else {
354
-                            $value = \EEH_Export::prepare_value_from_db_for_display(\EEM_Attendee::instance(),
355
-                                $att_field_name, $reg_row[$field_obj->get_qualified_column()]);
356
-                        }
357
-                    } else {
358
-                        $value = '';
359
-                    }
360
-                    $reg_csv_array[\EEH_Export::get_column_name_for_field($field_obj)] = $value;
361
-                }
362
-                //make sure each registration has the same questions in the same order
363
-                foreach ($question_labels as $question_label) {
364
-                    if ( ! isset($reg_csv_array[$question_label])) {
365
-                        $reg_csv_array[$question_label] = null;
366
-                    }
367
-                }
368
-                $answers = \EEM_Answer::instance()->get_all_wpdb_results(array(
369
-                    array('REG_ID' => $reg_row['Registration.REG_ID']),
370
-                    'force_join' => array('Question'),
371
-                ));
372
-                //now fill out the questions THEY answered
373
-                foreach ($answers as $answer_row) {
374
-                    if ($answer_row['Question.QST_ID']) {
375
-                        $question_label = \EEH_Export::prepare_value_from_db_for_display(\EEM_Question::instance(),
376
-                            'QST_admin_label', $answer_row['Question.QST_admin_label']);
377
-                    } else {
378
-                        $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
379
-                    }
380
-                    if (isset($answer_row['Question.QST_type'])
381
-                        && $answer_row['Question.QST_type'] == \EEM_Question::QST_type_state
382
-                    ) {
383
-                        $reg_csv_array[$question_label] = \EEM_State::instance()
384
-                                                                    ->get_state_name_by_ID($answer_row['Answer.ANS_value']);
385
-                    } else {
386
-                        //this isn't for html, so don't show html entities
387
-                        $reg_csv_array[$question_label] = html_entity_decode(\EEH_Export::prepare_value_from_db_for_display(\EEM_Answer::instance(),
388
-                            'ANS_value', $answer_row['Answer.ANS_value']));
389
-                    }
390
-                }
391
-                /**
392
-                 * Filter to change the contents of each row of the registrations report CSV file.
393
-                 *
394
-                 * This can be used to add or remote columns from the CSV file, or change their values.                 *
395
-                 * Note: it has this name because originally that's where this filter resided,
396
-                 * and we've left its name as-is for backward compatibility.
397
-                 * Note when using: all rows in the CSV should have the same columns.
398
-                 *
399
-                 * @param array $reg_csv_array keys are column-header names, and values are that columns' value
400
-                 *                             in this row
401
-                 * @param array $reg_row is the row from the database's wp_esp_registration table
402
-                 *
403
-                 */
404
-                $registrations_csv_ready_array[] = apply_filters(
405
-                    'FHEE__EE_Export__report_registrations__reg_csv_array',
406
-                    $reg_csv_array,
407
-                    $reg_row
408
-                );
409
-            }
410
-        }
411
-        //if we couldn't export anything, we want to at least show the column headers
412
-        if (empty($registrations_csv_ready_array)) {
413
-            $reg_csv_array = array();
414
-            $model_and_fields_to_include = array(
415
-                'Registration' => $reg_fields_to_include,
416
-                'Attendee'     => $att_fields_to_include,
417
-            );
418
-            foreach ($model_and_fields_to_include as $model_name => $field_list) {
419
-                $model = \EE_Registry::instance()->load_model($model_name);
420
-                foreach ($field_list as $field_name) {
421
-                    $field = $model->field_settings_for($field_name);
422
-                    $reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = null;
423
-                }
424
-            }
425
-            $registrations_csv_ready_array[] = $reg_csv_array;
426
-        }
427
-        return $registrations_csv_ready_array;
428
-    }
203
+	 * @param int   $offset
204
+	 * @param int   $limit
205
+	 * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
206
+	 * @param array $query_params    for using where querying the model
207
+	 * @return array top-level keys are numeric, next-level keys are column headers
208
+	 */
209
+	function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
210
+	{
211
+		$reg_fields_to_include = array(
212
+			'TXN_ID',
213
+			'ATT_ID',
214
+			'REG_ID',
215
+			'REG_date',
216
+			'REG_code',
217
+			'REG_count',
218
+			'REG_final_price',
219
+		);
220
+		$att_fields_to_include = array(
221
+			'ATT_fname',
222
+			'ATT_lname',
223
+			'ATT_email',
224
+			'ATT_address',
225
+			'ATT_address2',
226
+			'ATT_city',
227
+			'STA_ID',
228
+			'CNT_ISO',
229
+			'ATT_zip',
230
+			'ATT_phone',
231
+		);
232
+		$registrations_csv_ready_array = array();
233
+		$reg_model = \EE_Registry::instance()->load_model('Registration');
234
+		$query_params['limit'] = array($offset, $limit);
235
+		$registration_rows = $reg_model->get_all_wpdb_results($query_params);
236
+		$registration_ids = array();
237
+		foreach ($registration_rows as $reg_row) {
238
+			$registration_ids[] = intval($reg_row['Registration.REG_ID']);
239
+		}
240
+		foreach ($registration_rows as $reg_row) {
241
+			if (is_array($reg_row)) {
242
+				$reg_csv_array = array();
243
+				if ( ! $event_id) {
244
+					//get the event's name and Id
245
+					$reg_csv_array[__('Event', 'event_espresso')] = sprintf(__('%1$s (%2$s)', 'event_espresso'),
246
+						\EEH_Export::prepare_value_from_db_for_display(\EEM_Event::instance(), 'EVT_name',
247
+							$reg_row['Event_CPT.post_title']), $reg_row['Event_CPT.ID']);
248
+				}
249
+				$is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
250
+				/*@var $reg_row EE_Registration */
251
+				foreach ($reg_fields_to_include as $field_name) {
252
+					$field = $reg_model->field_settings_for($field_name);
253
+					if ($field_name == 'REG_final_price') {
254
+						$value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
255
+							$reg_row['Registration.REG_final_price'], 'localized_float');
256
+					} elseif ($field_name == 'REG_count') {
257
+						$value = sprintf(__('%s of %s', 'event_espresso'),
258
+							\EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_count',
259
+								$reg_row['Registration.REG_count']),
260
+							\EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_group_size',
261
+								$reg_row['Registration.REG_group_size']));
262
+					} elseif ($field_name == 'REG_date') {
263
+						$value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
264
+							$reg_row['Registration.REG_date'], 'no_html');
265
+					} else {
266
+						$value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
267
+							$reg_row[$field->get_qualified_column()]);
268
+					}
269
+					$reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = $value;
270
+					if ($field_name == 'REG_final_price') {
271
+						//add a column named Currency after the final price
272
+						$reg_csv_array[__("Currency", "event_espresso")] = \EE_Config::instance()->currency->code;
273
+					}
274
+				}
275
+				//get pretty status
276
+				$stati = \EEM_Status::instance()->localized_status(array(
277
+					$reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
278
+					$reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
279
+				), false, 'sentence');
280
+				$reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']];
281
+				//get pretty transaction status
282
+				$reg_csv_array[__("Transaction Status",
283
+					'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']];
284
+				$reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg
285
+					? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_total',
286
+						$reg_row['TransactionTable.TXN_total'], 'localized_float') : '0.00';
287
+				$reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg
288
+					? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_paid',
289
+						$reg_row['TransactionTable.TXN_paid'], 'localized_float') : '0.00';
290
+				$payment_methods = array();
291
+				$gateway_txn_ids_etc = array();
292
+				$payment_times = array();
293
+				if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
294
+					$payments_info = \EEM_Payment::instance()->get_all_wpdb_results(array(
295
+						array(
296
+							'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
297
+							'STS_ID' => \EEM_Payment::status_id_approved,
298
+						),
299
+						'force_join' => array('Payment_Method'),
300
+					), ARRAY_A,
301
+						'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time');
302
+					foreach ($payments_info as $payment_method_and_gateway_txn_id) {
303
+						$payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
304
+							? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
305
+						$gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
306
+							? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
307
+						$payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
308
+							? $payment_method_and_gateway_txn_id['payment_time'] : '';
309
+					}
310
+				}
311
+				$reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times);
312
+				$reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods);
313
+				$reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode(',', $gateway_txn_ids_etc);
314
+				//get whether or not the user has checked in
315
+				$reg_csv_array[__("Check-Ins",
316
+					"event_espresso")] = $reg_model->count_related($reg_row['Registration.REG_ID'], 'Checkin');
317
+				//get ticket of registration and its price
318
+				$ticket_model = \EE_Registry::instance()->load_model('Ticket');
319
+				if ($reg_row['Ticket.TKT_ID']) {
320
+					$ticket_name = \EEH_Export::prepare_value_from_db_for_display($ticket_model, 'TKT_name',
321
+						$reg_row['Ticket.TKT_name']);
322
+					$datetimes_strings = array();
323
+					foreach (
324
+						\EEM_Datetime::instance()->get_all_wpdb_results(array(
325
+							array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
326
+							'order_by'                 => array('DTT_EVT_start' => 'ASC'),
327
+							'default_where_conditions' => 'none',
328
+						)) as $datetime
329
+					) {
330
+						$datetimes_strings[] = \EEH_Export::prepare_value_from_db_for_display(\EEM_Datetime::instance(),
331
+							'DTT_EVT_start', $datetime['Datetime.DTT_EVT_start']);
332
+					}
333
+				} else {
334
+					$ticket_name = __('Unknown', 'event_espresso');
335
+					$datetimes_strings = array(__('Unknown', 'event_espresso'));
336
+				}
337
+				$reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name;
338
+				$reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings);
339
+				//get datetime(s) of registration
340
+				//add attendee columns
341
+				foreach ($att_fields_to_include as $att_field_name) {
342
+					$field_obj = \EEM_Attendee::instance()->field_settings_for($att_field_name);
343
+					if ($reg_row['Attendee_CPT.ID']) {
344
+						if ($att_field_name == 'STA_ID') {
345
+							$value = \EEM_State::instance()
346
+											   ->get_var(array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
347
+												   'STA_name');
348
+						} elseif ($att_field_name == 'CNT_ISO') {
349
+							$value = \EEM_Country::instance()
350
+												 ->get_var(array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
351
+													 'CNT_name');
352
+						} else {
353
+							$value = \EEH_Export::prepare_value_from_db_for_display(\EEM_Attendee::instance(),
354
+								$att_field_name, $reg_row[$field_obj->get_qualified_column()]);
355
+						}
356
+					} else {
357
+						$value = '';
358
+					}
359
+					$reg_csv_array[\EEH_Export::get_column_name_for_field($field_obj)] = $value;
360
+				}
361
+				//make sure each registration has the same questions in the same order
362
+				foreach ($question_labels as $question_label) {
363
+					if ( ! isset($reg_csv_array[$question_label])) {
364
+						$reg_csv_array[$question_label] = null;
365
+					}
366
+				}
367
+				$answers = \EEM_Answer::instance()->get_all_wpdb_results(array(
368
+					array('REG_ID' => $reg_row['Registration.REG_ID']),
369
+					'force_join' => array('Question'),
370
+				));
371
+				//now fill out the questions THEY answered
372
+				foreach ($answers as $answer_row) {
373
+					if ($answer_row['Question.QST_ID']) {
374
+						$question_label = \EEH_Export::prepare_value_from_db_for_display(\EEM_Question::instance(),
375
+							'QST_admin_label', $answer_row['Question.QST_admin_label']);
376
+					} else {
377
+						$question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
378
+					}
379
+					if (isset($answer_row['Question.QST_type'])
380
+						&& $answer_row['Question.QST_type'] == \EEM_Question::QST_type_state
381
+					) {
382
+						$reg_csv_array[$question_label] = \EEM_State::instance()
383
+																	->get_state_name_by_ID($answer_row['Answer.ANS_value']);
384
+					} else {
385
+						//this isn't for html, so don't show html entities
386
+						$reg_csv_array[$question_label] = html_entity_decode(\EEH_Export::prepare_value_from_db_for_display(\EEM_Answer::instance(),
387
+							'ANS_value', $answer_row['Answer.ANS_value']));
388
+					}
389
+				}
390
+				/**
391
+				 * Filter to change the contents of each row of the registrations report CSV file.
392
+				 *
393
+				 * This can be used to add or remote columns from the CSV file, or change their values.                 *
394
+				 * Note: it has this name because originally that's where this filter resided,
395
+				 * and we've left its name as-is for backward compatibility.
396
+				 * Note when using: all rows in the CSV should have the same columns.
397
+				 *
398
+				 * @param array $reg_csv_array keys are column-header names, and values are that columns' value
399
+				 *                             in this row
400
+				 * @param array $reg_row is the row from the database's wp_esp_registration table
401
+				 *
402
+				 */
403
+				$registrations_csv_ready_array[] = apply_filters(
404
+					'FHEE__EE_Export__report_registrations__reg_csv_array',
405
+					$reg_csv_array,
406
+					$reg_row
407
+				);
408
+			}
409
+		}
410
+		//if we couldn't export anything, we want to at least show the column headers
411
+		if (empty($registrations_csv_ready_array)) {
412
+			$reg_csv_array = array();
413
+			$model_and_fields_to_include = array(
414
+				'Registration' => $reg_fields_to_include,
415
+				'Attendee'     => $att_fields_to_include,
416
+			);
417
+			foreach ($model_and_fields_to_include as $model_name => $field_list) {
418
+				$model = \EE_Registry::instance()->load_model($model_name);
419
+				foreach ($field_list as $field_name) {
420
+					$field = $model->field_settings_for($field_name);
421
+					$reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = null;
422
+				}
423
+			}
424
+			$registrations_csv_ready_array[] = $reg_csv_array;
425
+		}
426
+		return $registrations_csv_ready_array;
427
+	}
429 428
 
430 429
 
431 430
 
432
-    /**
433
-     * Counts total unit to process
434
-     *
435
-     * @deprecated since 4.9.19
436
-     * @param int|array $event_id
437
-     * @return int
438
-     */
439
-    public function count_units_to_process($event_id)
440
-    {
441
-        //use the legacy filter
442
-        if ($event_id) {
443
-            $query_params[0]['EVT_ID'] = $event_id;
444
-        } else {
445
-            $query_params['force_join'][] = 'Event';
446
-        }
447
-        return \EEM_Registration::instance()->count($query_params);
448
-    }
431
+	/**
432
+	 * Counts total unit to process
433
+	 *
434
+	 * @deprecated since 4.9.19
435
+	 * @param int|array $event_id
436
+	 * @return int
437
+	 */
438
+	public function count_units_to_process($event_id)
439
+	{
440
+		//use the legacy filter
441
+		if ($event_id) {
442
+			$query_params[0]['EVT_ID'] = $event_id;
443
+		} else {
444
+			$query_params['force_join'][] = 'Event';
445
+		}
446
+		return \EEM_Registration::instance()->count($query_params);
447
+	}
449 448
 
450 449
 
451 450
 
452
-    /**
453
-     * Performs any clean-up logic when we know the job is completed.
454
-     * In this case, we delete the temporary file
455
-     *
456
-     * @param JobParameters $job_parameters
457
-     * @return boolean
458
-     */
459
-    public function cleanup_job(JobParameters $job_parameters)
460
-    {
461
-        $this->_file_helper->delete(\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
462
-            true, 'd');
463
-        return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
464
-    }
451
+	/**
452
+	 * Performs any clean-up logic when we know the job is completed.
453
+	 * In this case, we delete the temporary file
454
+	 *
455
+	 * @param JobParameters $job_parameters
456
+	 * @return boolean
457
+	 */
458
+	public function cleanup_job(JobParameters $job_parameters)
459
+	{
460
+		$this->_file_helper->delete(\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
461
+			true, 'd');
462
+		return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
463
+	}
465 464
 }
466 465
 
467 466
 
Please login to merge, or discard this patch.
admin_pages/registrations/EE_Registrations_List_Table.class.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -227,7 +227,7 @@
 block discarded – undo
227 227
      *    _get_table_filters
228 228
      *
229 229
      * @access protected
230
-     * @return array
230
+     * @return string[]
231 231
      */
232 232
     protected function _get_table_filters()
233 233
     {
Please login to merge, or discard this patch.
Indentation   +840 added lines, -840 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -26,869 +26,869 @@  discard block
 block discarded – undo
26 26
 
27 27
 
28 28
 
29
-    private $_status;
30
-
31
-
32
-
33
-    /**
34
-     * An array of transaction details for the related transaction to the registration being processed.
35
-     * This is set via the _set_related_details method.
36
-     *
37
-     * @var array
38
-     */
39
-    protected $_transaction_details = array();
40
-
41
-
42
-
43
-    /**
44
-     * An array of event details for the related event to the registration being processed.
45
-     * This is set via the _set_related_details method.
46
-     *
47
-     * @var array
48
-     */
49
-    protected $_event_details = array();
50
-
51
-
52
-
53
-    /**
54
-     * @param \Registrations_Admin_Page $admin_page
55
-     */
56
-    public function __construct(Registrations_Admin_Page $admin_page)
57
-    {
58
-        if ( ! empty($_GET['event_id'])) {
59
-            $extra_query_args = array();
60
-            foreach ($admin_page->get_views() as $key => $view_details) {
61
-                $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']);
62
-            }
63
-            $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
64
-        }
65
-        parent::__construct($admin_page);
66
-        $this->_status = $this->_admin_page->get_registration_status_array();
67
-    }
68
-
69
-
70
-
71
-    /**
72
-     *    _setup_data
73
-     *
74
-     * @access protected
75
-     * @return void
76
-     */
77
-    protected function _setup_data()
78
-    {
79
-        $this->_data = $this->_admin_page->get_registrations($this->_per_page);
80
-        $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false);
81
-    }
82
-
83
-
84
-
85
-    /**
86
-     *    _set_properties
87
-     *
88
-     * @access protected
89
-     * @return void
90
-     */
91
-    protected function _set_properties()
92
-    {
93
-        $this->_wp_list_args = array(
94
-            'singular' => __('registration', 'event_espresso'),
95
-            'plural'   => __('registrations', 'event_espresso'),
96
-            'ajax'     => true,
97
-            'screen'   => $this->_admin_page->get_current_screen()->id,
98
-        );
99
-        $ID_column_name = __('ID', 'event_espresso');
100
-        $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
101
-        $ID_column_name .= __('Registrant Name', 'event_espresso');
102
-        $ID_column_name .= '</span> ';
103
-        if (isset($_GET['event_id'])) {
104
-            $this->_columns = array(
105
-                'cb'               => '<input type="checkbox" />', //Render a checkbox instead of text
106
-                '_REG_ID'          => $ID_column_name,
107
-                'ATT_fname'        => __('Name', 'event_espresso'),
108
-                'ATT_email'        => __('Email', 'event_espresso'),
109
-                '_REG_date'        => __('Reg Date', 'event_espresso'),
110
-                'PRC_amount'       => __('TKT Price', 'event_espresso'),
111
-                '_REG_final_price' => __('Final Price', 'event_espresso'),
112
-                'TXN_total'        => __('Total Txn', 'event_espresso'),
113
-                'TXN_paid'         => __('Paid', 'event_espresso'),
114
-                'actions'          => __('Actions', 'event_espresso'),
115
-            );
116
-            $this->_bottom_buttons = array(
117
-                'report' => array(
118
-                    'route'         => 'registrations_report',
119
-                    'extra_request' => array(
120
-                        'EVT_ID'     => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
121
-                        'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
122
-                    ),
123
-                ),
124
-            );
125
-        } else {
126
-            $this->_columns = array(
127
-                'cb'               => '<input type="checkbox" />', //Render a checkbox instead of text
128
-                '_REG_ID'          => $ID_column_name,
129
-                'ATT_fname'        => __('Name', 'event_espresso'),
130
-                '_REG_date'        => __('TXN Date', 'event_espresso'),
131
-                'event_name'       => __('Event', 'event_espresso'),
132
-                'DTT_EVT_start'    => __('Event Date', 'event_espresso'),
133
-                '_REG_final_price' => __('Price', 'event_espresso'),
134
-                '_REG_paid'        => __('Paid', 'event_espresso'),
135
-                'actions'          => __('Actions', 'event_espresso'),
136
-            );
137
-            $this->_bottom_buttons = array(
138
-                'report_all' => array(
139
-                    'route'         => 'registrations_report',
140
-                    'extra_request' => array(
141
-                        'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
142
-                    ),
143
-                ),
144
-            );
145
-        }
146
-        $this->_bottom_buttons['report_filtered'] = array(
147
-            'route'         => 'registrations_report',
148
-            'extra_request' => array(
149
-                'use_filters' => true,
150
-                'filters'     => array_diff_key($this->_req_data, array_flip(array(
151
-                            'page',
152
-                            'action',
153
-                            'default_nonce',
154
-                        ))),
155
-                'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
156
-            ),
157
-        );
158
-        $this->_primary_column = '_REG_ID';
159
-        $this->_sortable_columns = array(
160
-            '_REG_date'     => array('_REG_date' => true),   //true means its already sorted
161
-            /**
162
-             * Allows users to change the default sort if they wish.
163
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
164
-             */
165
-            'ATT_fname'     => array(
166
-                    'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
167
-                    true,
168
-                    $this
169
-                )
170
-                ? array('ATT_lname' => false)
171
-                : array('ATT_fname' => false),
172
-            'event_name'    => array('event_name' => false),
173
-            'DTT_EVT_start' => array('DTT_EVT_start' => false),
174
-            '_REG_ID'       => array('_REG_ID' => false),
175
-        );
176
-        $this->_hidden_columns = array();
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * This simply sets up the row class for the table rows.
183
-     * Allows for easier overriding of child methods for setting up sorting.
184
-     *
185
-     * @param  EE_Registration $item the current item
186
-     * @return string
187
-     */
188
-    protected function _get_row_class($item)
189
-    {
190
-        $class = parent::_get_row_class($item);
191
-        //add status class
192
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
193
-        if ($this->_has_checkbox_column) {
194
-            $class .= ' has-checkbox-column';
195
-        }
196
-        return $class;
197
-    }
198
-
199
-
200
-
201
-    /**
202
-     * Set the $_transaction_details property if not set yet.
203
-     *
204
-     * @param EE_Registration $registration
205
-     * @throws \EE_Error
206
-     */
207
-    protected function _set_related_details(EE_Registration $registration)
208
-    {
209
-        $transaction = $registration->get_first_related('Transaction');
210
-        $status = $transaction instanceof EE_Transaction ? $transaction->status_ID()
211
-            : EEM_Transaction::failed_status_code;
212
-        $this->_transaction_details = array(
213
-            'transaction' => $transaction,
214
-            'status'      => $status,
215
-            'id'          => $transaction instanceof EE_Transaction ? $transaction->ID() : 0,
216
-            'title_attr'  => sprintf(__('View Transaction Details (%s)', 'event_espresso'),
217
-                EEH_Template::pretty_status($status, false, 'sentence')),
218
-        );
219
-        try {
220
-            $event = $registration->event();
221
-        } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) {
222
-            $event = null;
223
-        }
224
-        $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive;
225
-        $this->_event_details = array(
226
-            'event'      => $event,
227
-            'status'     => $status,
228
-            'id'         => $event instanceof EE_Event ? $event->ID() : 0,
229
-            'title_attr' => sprintf(__('Edit Event (%s)', 'event_espresso'),
230
-                EEH_Template::pretty_status($status, false, 'sentence')),
231
-        );
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     *    _get_table_filters
238
-     *
239
-     * @access protected
240
-     * @return array
241
-     */
242
-    protected function _get_table_filters()
243
-    {
244
-        $filters = array();
245
-        //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as methods.
246
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
247
-        $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
248
-        $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : '';
249
-        $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
250
-        $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
251
-        $status = array();
252
-        $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso'));
253
-        foreach ($this->_status as $key => $value) {
254
-            $status[] = array('id' => $key, 'text' => $value);
255
-        }
256
-        if ($this->_view !== 'incomplete') {
257
-            $filters[] = EEH_Form_Fields::select_input('_reg_status', $status,
258
-                isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
259
-                    : '');
260
-        }
261
-        if (isset($this->_req_data['event_id'])) {
262
-            $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
263
-        }
264
-        return $filters;
265
-    }
266
-
267
-
268
-
269
-    /**
270
-     *    _add_view_counts
271
-     *
272
-     * @access protected
273
-     * @return void
274
-     * @throws \EE_Error
275
-     */
276
-    protected function _add_view_counts()
277
-    {
278
-        $this->_views['all']['count'] = $this->_total_registrations();
279
-        $this->_views['month']['count'] = $this->_total_registrations_this_month();
280
-        $this->_views['today']['count'] = $this->_total_registrations_today();
281
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations',
282
-            'espresso_registrations_trash_registrations')
283
-        ) {
284
-            $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
285
-            $this->_views['trash']['count'] = $this->_total_registrations('trash');
286
-        }
287
-    }
288
-
289
-
290
-
291
-    /**
292
-     * _total_registrations
293
-     *
294
-     * @access protected
295
-     * @param string $view
296
-     * @return int
297
-     * @throws \EE_Error
298
-     */
299
-    protected function _total_registrations($view = '')
300
-    {
301
-        $_where = array();
302
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
303
-        if ($EVT_ID) {
304
-            $_where['EVT_ID'] = $EVT_ID;
305
-        }
306
-        switch ($view) {
307
-            case 'trash' :
308
-                return EEM_Registration::instance()->count_deleted(array($_where));
309
-                break;
310
-            case 'incomplete' :
311
-                $_where['STS_ID'] = EEM_Registration::status_id_incomplete;
312
-                break;
313
-            default :
314
-                $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
315
-        }
316
-        return EEM_Registration::instance()->count(array($_where));
317
-    }
318
-
319
-
320
-
321
-    /**
322
-     * _total_registrations_this_month
323
-     *
324
-     * @access protected
325
-     * @return int
326
-     * @throws \EE_Error
327
-     */
328
-    protected function _total_registrations_this_month()
329
-    {
330
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
331
-        $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
332
-        $this_year_r = date('Y', current_time('timestamp'));
333
-        $time_start = ' 00:00:00';
334
-        $time_end = ' 23:59:59';
335
-        $this_month_r = date('m', current_time('timestamp'));
336
-        $days_this_month = date('t', current_time('timestamp'));
337
-        //setup date query.
338
-        $beginning_string = EEM_Registration::instance()
339
-                                            ->convert_datetime_for_query('REG_date',
340
-                                                $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
341
-                                                'Y-m-d H:i:s');
342
-        $end_string = EEM_Registration::instance()
343
-                                      ->convert_datetime_for_query('REG_date',
344
-                                          $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
345
-                                          'Y-m-d H:i:s');
346
-        $_where['REG_date'] = array(
347
-            'BETWEEN',
348
-            array(
349
-                $beginning_string,
350
-                $end_string,
351
-            ),
352
-        );
353
-        $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
354
-        return EEM_Registration::instance()->count(array($_where));
355
-    }
356
-
357
-
358
-
359
-    /**
360
-     * _total_registrations_today
361
-     *
362
-     * @access protected
363
-     * @return int
364
-     * @throws \EE_Error
365
-     */
366
-    protected function _total_registrations_today()
367
-    {
368
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
369
-        $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
370
-        $current_date = date('Y-m-d', current_time('timestamp'));
371
-        $time_start = ' 00:00:00';
372
-        $time_end = ' 23:59:59';
373
-        $_where['REG_date'] = array(
374
-            'BETWEEN',
375
-            array(
376
-                EEM_Registration::instance()
377
-                                ->convert_datetime_for_query('REG_date', $current_date . $time_start, 'Y-m-d H:i:s'),
378
-                EEM_Registration::instance()
379
-                                ->convert_datetime_for_query('REG_date', $current_date . $time_end, 'Y-m-d H:i:s'),
380
-            ),
381
-        );
382
-        $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
383
-        return EEM_Registration::instance()->count(array($_where));
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     * column_cb
390
-     *
391
-     * @access public
392
-     * @param \EE_Registration $item
393
-     * @return string
394
-     * @throws \EE_Error
395
-     */
396
-    public function column_cb($item)
397
-    {
398
-        /** checkbox/lock **/
399
-        $transaction = $item->get_first_related('Transaction');
400
-        $payment_count = $transaction instanceof EE_Transaction ? $transaction->count_related('Payment') : 0;
401
-        return $payment_count > 0 ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$s" />', $item->ID())
402
-                                    . '<span class="ee-lock-icon"></span>'
403
-            : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$s" />', $item->ID());
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * column__REG_ID
410
-     *
411
-     * @access public
412
-     * @param \EE_Registration $item
413
-     * @return string
414
-     * @throws \EE_Error
415
-     */
416
-    public function column__REG_ID(EE_Registration $item)
417
-    {
418
-        $attendee = $item->attendee();
419
-        $content = $item->ID();
420
-        $content .= '<div class="show-on-mobile-view-only">';
421
-        $content .= '<br>';
422
-        $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
423
-        $content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
424
-        $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
425
-        $content .= '</div>';
426
-        return $content;
427
-    }
428
-
429
-
430
-
431
-    /**
432
-     * column__REG_date
433
-     *
434
-     * @access public
435
-     * @param \EE_Registration $item
436
-     * @return string
437
-     * @throws \EE_Error
438
-     */
439
-    public function column__REG_date(EE_Registration $item)
440
-    {
441
-        $this->_set_related_details($item);
442
-        //Build row actions
443
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
444
-            'action' => 'view_transaction',
445
-            'TXN_ID' => $this->_transaction_details['id'],
446
-        ), TXN_ADMIN_URL);
447
-        $view_link = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction',
448
-            'espresso_transactions_view_transaction') ? '<a class="ee-status-color-'
449
-                                                        . $this->_transaction_details['status']
450
-                                                        . '" href="'
451
-                                                        . $view_lnk_url
452
-                                                        . '" title="'
453
-                                                        . esc_attr($this->_transaction_details['title_attr'])
454
-                                                        . '">'
455
-                                                        . $item->get_i18n_datetime('REG_date')
456
-                                                        . '</a>' : $item->get_i18n_datetime('REG_date');
457
-        $view_link .= '<br><span class="ee-status-text-small">'
458
-                      . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
459
-                      . '</span>';
460
-        return $view_link;
461
-    }
462
-
463
-
464
-
465
-    /**
466
-     * column_event_name
467
-     *
468
-     * @access public
469
-     * @param \EE_Registration $item
470
-     * @return string
471
-     * @throws \EE_Error
472
-     */
473
-    public function column_event_name(EE_Registration $item)
474
-    {
475
-        $this->_set_related_details($item);
476
-        // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
477
-        $EVT_ID = $item->event_ID();
478
-        $event_name = $item->event_name();
479
-        $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso');
480
-        $event_name = wp_trim_words($event_name, 30, '...');
481
-        if ($EVT_ID) {
482
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $EVT_ID),
483
-                EVENTS_ADMIN_URL);
484
-            $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
485
-                ? '<a class="ee-status-color-'
486
-                  . $this->_event_details['status']
487
-                  . '" href="'
488
-                  . $edit_event_url
489
-                  . '" title="'
490
-                  . esc_attr($this->_event_details['title_attr'])
491
-                  . '">'
492
-                  . $event_name
493
-                  . '</a>' : $event_name;
494
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
495
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
496
-            $actions['event_filter'] .= sprintf(esc_attr__('Filter this list to only show registrations for %s',
497
-                'event_espresso'), $event_name);
498
-            $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
499
-        } else {
500
-            $edit_event = $event_name;
501
-            $actions['event_filter'] = '';
502
-        }
503
-        return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
504
-    }
505
-
506
-
507
-
508
-    /**
509
-     * column_DTT_EVT_start
510
-     *
511
-     * @access public
512
-     * @param \EE_Registration $item
513
-     * @return string
514
-     * @throws \EE_Error
515
-     */
516
-    public function column_DTT_EVT_start(EE_Registration $item)
517
-    {
518
-        $datetime_strings = array();
519
-        $ticket = $item->ticket(true);
520
-        if ($ticket instanceof EE_Ticket) {
521
-            $remove_defaults = array('default_where_conditions' => 'none');
522
-            $datetimes = $ticket->datetimes($remove_defaults);
523
-            foreach ($datetimes as $datetime) {
524
-                $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
525
-            }
526
-            return implode("<br />", $datetime_strings);
527
-        } else {
528
-            return __('There is no ticket on this registration', 'event_espresso');
529
-        }
530
-    }
531
-
532
-
533
-
534
-    /**
535
-     * column_ATT_fname
536
-     *
537
-     * @access public
538
-     * @param \EE_Registration $item
539
-     * @return string
540
-     * @throws \EE_Error
541
-     */
542
-    public function column_ATT_fname(EE_Registration $item)
543
-    {
544
-        $attendee = $item->attendee();
545
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
546
-            'action'  => 'view_registration',
547
-            '_REG_ID' => $item->ID(),
548
-        ), REG_ADMIN_URL);
549
-        $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
550
-        $link = EE_Registry::instance()->CAP->current_user_can('ee_read_registration',
551
-            'espresso_registrations_view_registration', $item->ID()) ? '<a href="'
552
-                                                                       . $edit_lnk_url
553
-                                                                       . '" title="'
554
-                                                                       . esc_attr__('View Registration Details',
555
-                'event_espresso')
556
-                                                                       . '">'
557
-                                                                       . $attendee_name
558
-                                                                       . '</a>' : $attendee_name;
559
-        $link .= $item->count() === 1
560
-            ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : '';
561
-        $t = $item->get_first_related('Transaction');
562
-        $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
563
-        //append group count to name
564
-        $link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
565
-        //append reg_code
566
-        $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
567
-        //reg status text for accessibility
568
-        $link .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->status_ID(), false,
569
-                'sentence') . '</span>';
570
-        //trash/restore/delete actions
571
-        $actions = array();
572
-        if ($this->_view !== 'trash'
573
-            && $payment_count === 0
574
-            && EE_Registry::instance()->CAP->current_user_can('ee_delete_registration',
575
-                'espresso_registrations_trash_registrations', $item->ID())
576
-        ) {
577
-            $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
578
-                'action'  => 'trash_registrations',
579
-                '_REG_ID' => $item->ID(),
580
-            ), REG_ADMIN_URL);
581
-            $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' . esc_attr__('Trash Registration',
582
-                    'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>';
583
-        } elseif ($this->_view === 'trash') {
584
-            // restore registration link
585
-            if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration',
586
-                'espresso_registrations_restore_registrations', $item->ID())
587
-            ) {
588
-                $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
589
-                    'action'  => 'restore_registrations',
590
-                    '_REG_ID' => $item->ID(),
591
-                ), REG_ADMIN_URL);
592
-                $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' . esc_attr__('Restore Registration',
593
-                        'event_espresso') . '">' . __('Restore', 'event_espresso') . '</a>';
594
-            }
595
-            if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration',
596
-                'espresso_registrations_ee_delete_registrations', $item->ID())
597
-            ) {
598
-                $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
599
-                    'action'  => 'delete_registrations',
600
-                    '_REG_ID' => $item->ID(),
601
-                ), REG_ADMIN_URL);
602
-                $actions['delete'] = '<a href="'
603
-                                     . $delete_lnk_url
604
-                                     . '" title="'
605
-                                     . esc_attr__('Delete Registration Permanently', 'event_espresso')
606
-                                     . '">'
607
-                                     . __('Delete', 'event_espresso')
608
-                                     . '</a>';
609
-            }
610
-        }
611
-        return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
612
-    }
613
-
614
-
615
-
616
-    /**
617
-     * column_ATT_email
618
-     *
619
-     * @access public
620
-     * @param \EE_Registration $item
621
-     * @return string
622
-     * @throws \EE_Error
623
-     */
624
-    public function column_ATT_email(EE_Registration $item)
625
-    {
626
-        $attendee = $item->get_first_related('Attendee');
627
-        return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso')
628
-            : $attendee->email();
629
-    }
630
-
631
-
632
-
633
-    /**
634
-     * column__REG_count
635
-     *
636
-     * @access public
637
-     * @param \EE_Registration $item
638
-     * @return string
639
-     */
640
-    public function column__REG_count(EE_Registration $item)
641
-    {
642
-        return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
643
-    }
644
-
645
-
646
-
647
-    /**
648
-     * column_PRC_amount
649
-     *
650
-     * @access public
651
-     * @param \EE_Registration $item
652
-     * @return string
653
-     */
654
-    public function column_PRC_amount(EE_Registration $item)
655
-    {
656
-        $ticket = $item->ticket();
657
-        $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">'
658
-                                                                              . $ticket->name()
659
-                                                                              . '</span><br />' : '';
660
-        if ($item->final_price() > 0) {
661
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
662
-        } else {
663
-            // free event
664
-            $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
665
-                        . __('free', 'event_espresso')
666
-                        . '</span>';
667
-        }
668
-        return $content;
669
-    }
670
-
671
-
672
-
673
-    /**
674
-     * column__REG_final_price
675
-     *
676
-     * @access public
677
-     * @param \EE_Registration $item
678
-     * @return string
679
-     */
680
-    public function column__REG_final_price(EE_Registration $item)
681
-    {
682
-        $ticket = $item->ticket();
683
-        $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket
684
-            ? ''
685
-            : '<span class="TKT_name">'
686
-              . $ticket->name()
687
-              . '</span><br />';
688
-        $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
689
-        return $content;
690
-    }
691
-
692
-
693
-
694
-    /**
695
-     * column__REG_paid
696
-     *
697
-     * @access public
698
-     * @param \EE_Registration $item
699
-     * @return string
700
-     */
701
-    public function column__REG_paid(EE_Registration $item)
702
-    {
703
-        $payment_method = $item->payment_method();
704
-        $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
705
-            : __('Unknown', 'event_espresso');
706
-        $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
707
-        if ($item->paid() > 0) {
708
-            $content .= '<br><span class="ee-status-text-small">' . sprintf(__('...via %s', 'event_espresso'),
709
-                    $payment_method_name) . '</span>';
710
-        }
711
-        return $content;
712
-    }
713
-
714
-
715
-
716
-    /**
717
-     * column_TXN_total
718
-     *
719
-     * @access public
720
-     * @param \EE_Registration $item
721
-     * @return string
722
-     * @throws \EE_Error
723
-     */
724
-    public function column_TXN_total(EE_Registration $item)
725
-    {
726
-        if ($item->transaction()) {
727
-            $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
728
-                'action' => 'view_transaction',
729
-                'TXN_ID' => $item->transaction_ID(),
730
-            ), TXN_ADMIN_URL);
731
-            return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction',
732
-                'espresso_transactions_view_transaction', $item->transaction_ID())
733
-                ? '<span class="reg-pad-rght"><a class="status-'
734
-                  . $item->transaction()->status_ID()
735
-                  . '" href="'
736
-                  . $view_txn_lnk_url
737
-                  . '"  title="'
738
-                  . esc_attr__('View Transaction', 'event_espresso')
739
-                  . '">'
740
-                  . $item->transaction()->pretty_total()
741
-                  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
742
-        } else {
743
-            return __("None", "event_espresso");
744
-        }
745
-    }
746
-
747
-
748
-
749
-    /**
750
-     * column_TXN_paid
751
-     *
752
-     * @access public
753
-     * @param \EE_Registration $item
754
-     * @return string
755
-     * @throws \EE_Error
756
-     */
757
-    public function column_TXN_paid(EE_Registration $item)
758
-    {
759
-        if ($item->count() === 1) {
760
-            $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance();
761
-            if ($transaction->paid() >= $transaction->total()) {
762
-                return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
763
-            } else {
764
-                $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
765
-                    'action' => 'view_transaction',
766
-                    'TXN_ID' => $item->transaction_ID(),
767
-                ), TXN_ADMIN_URL);
768
-                return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction',
769
-                    'espresso_transactions_view_transaction', $item->transaction_ID())
770
-                    ? '<span class="reg-pad-rght"><a class="status-'
771
-                      . $transaction->status_ID()
772
-                      . '" href="'
773
-                      . $view_txn_lnk_url
774
-                      . '"  title="'
775
-                      . esc_attr__('View Transaction', 'event_espresso')
776
-                      . '">'
777
-                      . $item->transaction()->pretty_paid()
778
-                      . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
779
-            }
780
-        }
781
-        return '&nbsp;';
782
-    }
783
-
784
-
785
-
786
-    /**
787
-     * column_actions
788
-     *
789
-     * @access public
790
-     * @param \EE_Registration $item
791
-     * @return string
792
-     * @throws \EE_Error
793
-     */
794
-    public function column_actions(EE_Registration $item)
795
-    {
796
-        $actions = array();
797
-        $attendee = $item->attendee();
798
-        $this->_set_related_details($item);
799
-        //Build row actions
800
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
801
-            'action'  => 'view_registration',
802
-            '_REG_ID' => $item->ID(),
803
-        ), REG_ADMIN_URL);
804
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
805
-            'action' => 'edit_attendee',
806
-            'post'   => $item->attendee_ID(),
807
-        ), REG_ADMIN_URL);
808
-        // page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
809
-        //$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
810
-        $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
811
-            'action'  => 'resend_registration',
812
-            '_REG_ID' => $item->ID(),
813
-        ), REG_ADMIN_URL, true);
814
-        //Build row actions
815
-        $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_registration',
816
-            'espresso_registrations_view_registration', $item->ID()) ? '
29
+	private $_status;
30
+
31
+
32
+
33
+	/**
34
+	 * An array of transaction details for the related transaction to the registration being processed.
35
+	 * This is set via the _set_related_details method.
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected $_transaction_details = array();
40
+
41
+
42
+
43
+	/**
44
+	 * An array of event details for the related event to the registration being processed.
45
+	 * This is set via the _set_related_details method.
46
+	 *
47
+	 * @var array
48
+	 */
49
+	protected $_event_details = array();
50
+
51
+
52
+
53
+	/**
54
+	 * @param \Registrations_Admin_Page $admin_page
55
+	 */
56
+	public function __construct(Registrations_Admin_Page $admin_page)
57
+	{
58
+		if ( ! empty($_GET['event_id'])) {
59
+			$extra_query_args = array();
60
+			foreach ($admin_page->get_views() as $key => $view_details) {
61
+				$extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']);
62
+			}
63
+			$this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
64
+		}
65
+		parent::__construct($admin_page);
66
+		$this->_status = $this->_admin_page->get_registration_status_array();
67
+	}
68
+
69
+
70
+
71
+	/**
72
+	 *    _setup_data
73
+	 *
74
+	 * @access protected
75
+	 * @return void
76
+	 */
77
+	protected function _setup_data()
78
+	{
79
+		$this->_data = $this->_admin_page->get_registrations($this->_per_page);
80
+		$this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false);
81
+	}
82
+
83
+
84
+
85
+	/**
86
+	 *    _set_properties
87
+	 *
88
+	 * @access protected
89
+	 * @return void
90
+	 */
91
+	protected function _set_properties()
92
+	{
93
+		$this->_wp_list_args = array(
94
+			'singular' => __('registration', 'event_espresso'),
95
+			'plural'   => __('registrations', 'event_espresso'),
96
+			'ajax'     => true,
97
+			'screen'   => $this->_admin_page->get_current_screen()->id,
98
+		);
99
+		$ID_column_name = __('ID', 'event_espresso');
100
+		$ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
101
+		$ID_column_name .= __('Registrant Name', 'event_espresso');
102
+		$ID_column_name .= '</span> ';
103
+		if (isset($_GET['event_id'])) {
104
+			$this->_columns = array(
105
+				'cb'               => '<input type="checkbox" />', //Render a checkbox instead of text
106
+				'_REG_ID'          => $ID_column_name,
107
+				'ATT_fname'        => __('Name', 'event_espresso'),
108
+				'ATT_email'        => __('Email', 'event_espresso'),
109
+				'_REG_date'        => __('Reg Date', 'event_espresso'),
110
+				'PRC_amount'       => __('TKT Price', 'event_espresso'),
111
+				'_REG_final_price' => __('Final Price', 'event_espresso'),
112
+				'TXN_total'        => __('Total Txn', 'event_espresso'),
113
+				'TXN_paid'         => __('Paid', 'event_espresso'),
114
+				'actions'          => __('Actions', 'event_espresso'),
115
+			);
116
+			$this->_bottom_buttons = array(
117
+				'report' => array(
118
+					'route'         => 'registrations_report',
119
+					'extra_request' => array(
120
+						'EVT_ID'     => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
121
+						'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
122
+					),
123
+				),
124
+			);
125
+		} else {
126
+			$this->_columns = array(
127
+				'cb'               => '<input type="checkbox" />', //Render a checkbox instead of text
128
+				'_REG_ID'          => $ID_column_name,
129
+				'ATT_fname'        => __('Name', 'event_espresso'),
130
+				'_REG_date'        => __('TXN Date', 'event_espresso'),
131
+				'event_name'       => __('Event', 'event_espresso'),
132
+				'DTT_EVT_start'    => __('Event Date', 'event_espresso'),
133
+				'_REG_final_price' => __('Price', 'event_espresso'),
134
+				'_REG_paid'        => __('Paid', 'event_espresso'),
135
+				'actions'          => __('Actions', 'event_espresso'),
136
+			);
137
+			$this->_bottom_buttons = array(
138
+				'report_all' => array(
139
+					'route'         => 'registrations_report',
140
+					'extra_request' => array(
141
+						'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
142
+					),
143
+				),
144
+			);
145
+		}
146
+		$this->_bottom_buttons['report_filtered'] = array(
147
+			'route'         => 'registrations_report',
148
+			'extra_request' => array(
149
+				'use_filters' => true,
150
+				'filters'     => array_diff_key($this->_req_data, array_flip(array(
151
+							'page',
152
+							'action',
153
+							'default_nonce',
154
+						))),
155
+				'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
156
+			),
157
+		);
158
+		$this->_primary_column = '_REG_ID';
159
+		$this->_sortable_columns = array(
160
+			'_REG_date'     => array('_REG_date' => true),   //true means its already sorted
161
+			/**
162
+			 * Allows users to change the default sort if they wish.
163
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
164
+			 */
165
+			'ATT_fname'     => array(
166
+					'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
167
+					true,
168
+					$this
169
+				)
170
+				? array('ATT_lname' => false)
171
+				: array('ATT_fname' => false),
172
+			'event_name'    => array('event_name' => false),
173
+			'DTT_EVT_start' => array('DTT_EVT_start' => false),
174
+			'_REG_ID'       => array('_REG_ID' => false),
175
+		);
176
+		$this->_hidden_columns = array();
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * This simply sets up the row class for the table rows.
183
+	 * Allows for easier overriding of child methods for setting up sorting.
184
+	 *
185
+	 * @param  EE_Registration $item the current item
186
+	 * @return string
187
+	 */
188
+	protected function _get_row_class($item)
189
+	{
190
+		$class = parent::_get_row_class($item);
191
+		//add status class
192
+		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
193
+		if ($this->_has_checkbox_column) {
194
+			$class .= ' has-checkbox-column';
195
+		}
196
+		return $class;
197
+	}
198
+
199
+
200
+
201
+	/**
202
+	 * Set the $_transaction_details property if not set yet.
203
+	 *
204
+	 * @param EE_Registration $registration
205
+	 * @throws \EE_Error
206
+	 */
207
+	protected function _set_related_details(EE_Registration $registration)
208
+	{
209
+		$transaction = $registration->get_first_related('Transaction');
210
+		$status = $transaction instanceof EE_Transaction ? $transaction->status_ID()
211
+			: EEM_Transaction::failed_status_code;
212
+		$this->_transaction_details = array(
213
+			'transaction' => $transaction,
214
+			'status'      => $status,
215
+			'id'          => $transaction instanceof EE_Transaction ? $transaction->ID() : 0,
216
+			'title_attr'  => sprintf(__('View Transaction Details (%s)', 'event_espresso'),
217
+				EEH_Template::pretty_status($status, false, 'sentence')),
218
+		);
219
+		try {
220
+			$event = $registration->event();
221
+		} catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) {
222
+			$event = null;
223
+		}
224
+		$status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive;
225
+		$this->_event_details = array(
226
+			'event'      => $event,
227
+			'status'     => $status,
228
+			'id'         => $event instanceof EE_Event ? $event->ID() : 0,
229
+			'title_attr' => sprintf(__('Edit Event (%s)', 'event_espresso'),
230
+				EEH_Template::pretty_status($status, false, 'sentence')),
231
+		);
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 *    _get_table_filters
238
+	 *
239
+	 * @access protected
240
+	 * @return array
241
+	 */
242
+	protected function _get_table_filters()
243
+	{
244
+		$filters = array();
245
+		//todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as methods.
246
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
247
+		$cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
248
+		$reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : '';
249
+		$filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
250
+		$filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
251
+		$status = array();
252
+		$status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso'));
253
+		foreach ($this->_status as $key => $value) {
254
+			$status[] = array('id' => $key, 'text' => $value);
255
+		}
256
+		if ($this->_view !== 'incomplete') {
257
+			$filters[] = EEH_Form_Fields::select_input('_reg_status', $status,
258
+				isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
259
+					: '');
260
+		}
261
+		if (isset($this->_req_data['event_id'])) {
262
+			$filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
263
+		}
264
+		return $filters;
265
+	}
266
+
267
+
268
+
269
+	/**
270
+	 *    _add_view_counts
271
+	 *
272
+	 * @access protected
273
+	 * @return void
274
+	 * @throws \EE_Error
275
+	 */
276
+	protected function _add_view_counts()
277
+	{
278
+		$this->_views['all']['count'] = $this->_total_registrations();
279
+		$this->_views['month']['count'] = $this->_total_registrations_this_month();
280
+		$this->_views['today']['count'] = $this->_total_registrations_today();
281
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations',
282
+			'espresso_registrations_trash_registrations')
283
+		) {
284
+			$this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
285
+			$this->_views['trash']['count'] = $this->_total_registrations('trash');
286
+		}
287
+	}
288
+
289
+
290
+
291
+	/**
292
+	 * _total_registrations
293
+	 *
294
+	 * @access protected
295
+	 * @param string $view
296
+	 * @return int
297
+	 * @throws \EE_Error
298
+	 */
299
+	protected function _total_registrations($view = '')
300
+	{
301
+		$_where = array();
302
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
303
+		if ($EVT_ID) {
304
+			$_where['EVT_ID'] = $EVT_ID;
305
+		}
306
+		switch ($view) {
307
+			case 'trash' :
308
+				return EEM_Registration::instance()->count_deleted(array($_where));
309
+				break;
310
+			case 'incomplete' :
311
+				$_where['STS_ID'] = EEM_Registration::status_id_incomplete;
312
+				break;
313
+			default :
314
+				$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
315
+		}
316
+		return EEM_Registration::instance()->count(array($_where));
317
+	}
318
+
319
+
320
+
321
+	/**
322
+	 * _total_registrations_this_month
323
+	 *
324
+	 * @access protected
325
+	 * @return int
326
+	 * @throws \EE_Error
327
+	 */
328
+	protected function _total_registrations_this_month()
329
+	{
330
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
331
+		$_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
332
+		$this_year_r = date('Y', current_time('timestamp'));
333
+		$time_start = ' 00:00:00';
334
+		$time_end = ' 23:59:59';
335
+		$this_month_r = date('m', current_time('timestamp'));
336
+		$days_this_month = date('t', current_time('timestamp'));
337
+		//setup date query.
338
+		$beginning_string = EEM_Registration::instance()
339
+											->convert_datetime_for_query('REG_date',
340
+												$this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
341
+												'Y-m-d H:i:s');
342
+		$end_string = EEM_Registration::instance()
343
+									  ->convert_datetime_for_query('REG_date',
344
+										  $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
345
+										  'Y-m-d H:i:s');
346
+		$_where['REG_date'] = array(
347
+			'BETWEEN',
348
+			array(
349
+				$beginning_string,
350
+				$end_string,
351
+			),
352
+		);
353
+		$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
354
+		return EEM_Registration::instance()->count(array($_where));
355
+	}
356
+
357
+
358
+
359
+	/**
360
+	 * _total_registrations_today
361
+	 *
362
+	 * @access protected
363
+	 * @return int
364
+	 * @throws \EE_Error
365
+	 */
366
+	protected function _total_registrations_today()
367
+	{
368
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
369
+		$_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
370
+		$current_date = date('Y-m-d', current_time('timestamp'));
371
+		$time_start = ' 00:00:00';
372
+		$time_end = ' 23:59:59';
373
+		$_where['REG_date'] = array(
374
+			'BETWEEN',
375
+			array(
376
+				EEM_Registration::instance()
377
+								->convert_datetime_for_query('REG_date', $current_date . $time_start, 'Y-m-d H:i:s'),
378
+				EEM_Registration::instance()
379
+								->convert_datetime_for_query('REG_date', $current_date . $time_end, 'Y-m-d H:i:s'),
380
+			),
381
+		);
382
+		$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
383
+		return EEM_Registration::instance()->count(array($_where));
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 * column_cb
390
+	 *
391
+	 * @access public
392
+	 * @param \EE_Registration $item
393
+	 * @return string
394
+	 * @throws \EE_Error
395
+	 */
396
+	public function column_cb($item)
397
+	{
398
+		/** checkbox/lock **/
399
+		$transaction = $item->get_first_related('Transaction');
400
+		$payment_count = $transaction instanceof EE_Transaction ? $transaction->count_related('Payment') : 0;
401
+		return $payment_count > 0 ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$s" />', $item->ID())
402
+									. '<span class="ee-lock-icon"></span>'
403
+			: sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$s" />', $item->ID());
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * column__REG_ID
410
+	 *
411
+	 * @access public
412
+	 * @param \EE_Registration $item
413
+	 * @return string
414
+	 * @throws \EE_Error
415
+	 */
416
+	public function column__REG_ID(EE_Registration $item)
417
+	{
418
+		$attendee = $item->attendee();
419
+		$content = $item->ID();
420
+		$content .= '<div class="show-on-mobile-view-only">';
421
+		$content .= '<br>';
422
+		$content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
423
+		$content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
424
+		$content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
425
+		$content .= '</div>';
426
+		return $content;
427
+	}
428
+
429
+
430
+
431
+	/**
432
+	 * column__REG_date
433
+	 *
434
+	 * @access public
435
+	 * @param \EE_Registration $item
436
+	 * @return string
437
+	 * @throws \EE_Error
438
+	 */
439
+	public function column__REG_date(EE_Registration $item)
440
+	{
441
+		$this->_set_related_details($item);
442
+		//Build row actions
443
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
444
+			'action' => 'view_transaction',
445
+			'TXN_ID' => $this->_transaction_details['id'],
446
+		), TXN_ADMIN_URL);
447
+		$view_link = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction',
448
+			'espresso_transactions_view_transaction') ? '<a class="ee-status-color-'
449
+														. $this->_transaction_details['status']
450
+														. '" href="'
451
+														. $view_lnk_url
452
+														. '" title="'
453
+														. esc_attr($this->_transaction_details['title_attr'])
454
+														. '">'
455
+														. $item->get_i18n_datetime('REG_date')
456
+														. '</a>' : $item->get_i18n_datetime('REG_date');
457
+		$view_link .= '<br><span class="ee-status-text-small">'
458
+					  . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
459
+					  . '</span>';
460
+		return $view_link;
461
+	}
462
+
463
+
464
+
465
+	/**
466
+	 * column_event_name
467
+	 *
468
+	 * @access public
469
+	 * @param \EE_Registration $item
470
+	 * @return string
471
+	 * @throws \EE_Error
472
+	 */
473
+	public function column_event_name(EE_Registration $item)
474
+	{
475
+		$this->_set_related_details($item);
476
+		// page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
477
+		$EVT_ID = $item->event_ID();
478
+		$event_name = $item->event_name();
479
+		$event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso');
480
+		$event_name = wp_trim_words($event_name, 30, '...');
481
+		if ($EVT_ID) {
482
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $EVT_ID),
483
+				EVENTS_ADMIN_URL);
484
+			$edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
485
+				? '<a class="ee-status-color-'
486
+				  . $this->_event_details['status']
487
+				  . '" href="'
488
+				  . $edit_event_url
489
+				  . '" title="'
490
+				  . esc_attr($this->_event_details['title_attr'])
491
+				  . '">'
492
+				  . $event_name
493
+				  . '</a>' : $event_name;
494
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
495
+			$actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
496
+			$actions['event_filter'] .= sprintf(esc_attr__('Filter this list to only show registrations for %s',
497
+				'event_espresso'), $event_name);
498
+			$actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
499
+		} else {
500
+			$edit_event = $event_name;
501
+			$actions['event_filter'] = '';
502
+		}
503
+		return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
504
+	}
505
+
506
+
507
+
508
+	/**
509
+	 * column_DTT_EVT_start
510
+	 *
511
+	 * @access public
512
+	 * @param \EE_Registration $item
513
+	 * @return string
514
+	 * @throws \EE_Error
515
+	 */
516
+	public function column_DTT_EVT_start(EE_Registration $item)
517
+	{
518
+		$datetime_strings = array();
519
+		$ticket = $item->ticket(true);
520
+		if ($ticket instanceof EE_Ticket) {
521
+			$remove_defaults = array('default_where_conditions' => 'none');
522
+			$datetimes = $ticket->datetimes($remove_defaults);
523
+			foreach ($datetimes as $datetime) {
524
+				$datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
525
+			}
526
+			return implode("<br />", $datetime_strings);
527
+		} else {
528
+			return __('There is no ticket on this registration', 'event_espresso');
529
+		}
530
+	}
531
+
532
+
533
+
534
+	/**
535
+	 * column_ATT_fname
536
+	 *
537
+	 * @access public
538
+	 * @param \EE_Registration $item
539
+	 * @return string
540
+	 * @throws \EE_Error
541
+	 */
542
+	public function column_ATT_fname(EE_Registration $item)
543
+	{
544
+		$attendee = $item->attendee();
545
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
546
+			'action'  => 'view_registration',
547
+			'_REG_ID' => $item->ID(),
548
+		), REG_ADMIN_URL);
549
+		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
550
+		$link = EE_Registry::instance()->CAP->current_user_can('ee_read_registration',
551
+			'espresso_registrations_view_registration', $item->ID()) ? '<a href="'
552
+																	   . $edit_lnk_url
553
+																	   . '" title="'
554
+																	   . esc_attr__('View Registration Details',
555
+				'event_espresso')
556
+																	   . '">'
557
+																	   . $attendee_name
558
+																	   . '</a>' : $attendee_name;
559
+		$link .= $item->count() === 1
560
+			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : '';
561
+		$t = $item->get_first_related('Transaction');
562
+		$payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
563
+		//append group count to name
564
+		$link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
565
+		//append reg_code
566
+		$link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
567
+		//reg status text for accessibility
568
+		$link .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->status_ID(), false,
569
+				'sentence') . '</span>';
570
+		//trash/restore/delete actions
571
+		$actions = array();
572
+		if ($this->_view !== 'trash'
573
+			&& $payment_count === 0
574
+			&& EE_Registry::instance()->CAP->current_user_can('ee_delete_registration',
575
+				'espresso_registrations_trash_registrations', $item->ID())
576
+		) {
577
+			$trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
578
+				'action'  => 'trash_registrations',
579
+				'_REG_ID' => $item->ID(),
580
+			), REG_ADMIN_URL);
581
+			$actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' . esc_attr__('Trash Registration',
582
+					'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>';
583
+		} elseif ($this->_view === 'trash') {
584
+			// restore registration link
585
+			if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration',
586
+				'espresso_registrations_restore_registrations', $item->ID())
587
+			) {
588
+				$restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
589
+					'action'  => 'restore_registrations',
590
+					'_REG_ID' => $item->ID(),
591
+				), REG_ADMIN_URL);
592
+				$actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' . esc_attr__('Restore Registration',
593
+						'event_espresso') . '">' . __('Restore', 'event_espresso') . '</a>';
594
+			}
595
+			if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration',
596
+				'espresso_registrations_ee_delete_registrations', $item->ID())
597
+			) {
598
+				$delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
599
+					'action'  => 'delete_registrations',
600
+					'_REG_ID' => $item->ID(),
601
+				), REG_ADMIN_URL);
602
+				$actions['delete'] = '<a href="'
603
+									 . $delete_lnk_url
604
+									 . '" title="'
605
+									 . esc_attr__('Delete Registration Permanently', 'event_espresso')
606
+									 . '">'
607
+									 . __('Delete', 'event_espresso')
608
+									 . '</a>';
609
+			}
610
+		}
611
+		return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
612
+	}
613
+
614
+
615
+
616
+	/**
617
+	 * column_ATT_email
618
+	 *
619
+	 * @access public
620
+	 * @param \EE_Registration $item
621
+	 * @return string
622
+	 * @throws \EE_Error
623
+	 */
624
+	public function column_ATT_email(EE_Registration $item)
625
+	{
626
+		$attendee = $item->get_first_related('Attendee');
627
+		return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso')
628
+			: $attendee->email();
629
+	}
630
+
631
+
632
+
633
+	/**
634
+	 * column__REG_count
635
+	 *
636
+	 * @access public
637
+	 * @param \EE_Registration $item
638
+	 * @return string
639
+	 */
640
+	public function column__REG_count(EE_Registration $item)
641
+	{
642
+		return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
643
+	}
644
+
645
+
646
+
647
+	/**
648
+	 * column_PRC_amount
649
+	 *
650
+	 * @access public
651
+	 * @param \EE_Registration $item
652
+	 * @return string
653
+	 */
654
+	public function column_PRC_amount(EE_Registration $item)
655
+	{
656
+		$ticket = $item->ticket();
657
+		$content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">'
658
+																			  . $ticket->name()
659
+																			  . '</span><br />' : '';
660
+		if ($item->final_price() > 0) {
661
+			$content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
662
+		} else {
663
+			// free event
664
+			$content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
665
+						. __('free', 'event_espresso')
666
+						. '</span>';
667
+		}
668
+		return $content;
669
+	}
670
+
671
+
672
+
673
+	/**
674
+	 * column__REG_final_price
675
+	 *
676
+	 * @access public
677
+	 * @param \EE_Registration $item
678
+	 * @return string
679
+	 */
680
+	public function column__REG_final_price(EE_Registration $item)
681
+	{
682
+		$ticket = $item->ticket();
683
+		$content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket
684
+			? ''
685
+			: '<span class="TKT_name">'
686
+			  . $ticket->name()
687
+			  . '</span><br />';
688
+		$content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
689
+		return $content;
690
+	}
691
+
692
+
693
+
694
+	/**
695
+	 * column__REG_paid
696
+	 *
697
+	 * @access public
698
+	 * @param \EE_Registration $item
699
+	 * @return string
700
+	 */
701
+	public function column__REG_paid(EE_Registration $item)
702
+	{
703
+		$payment_method = $item->payment_method();
704
+		$payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
705
+			: __('Unknown', 'event_espresso');
706
+		$content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
707
+		if ($item->paid() > 0) {
708
+			$content .= '<br><span class="ee-status-text-small">' . sprintf(__('...via %s', 'event_espresso'),
709
+					$payment_method_name) . '</span>';
710
+		}
711
+		return $content;
712
+	}
713
+
714
+
715
+
716
+	/**
717
+	 * column_TXN_total
718
+	 *
719
+	 * @access public
720
+	 * @param \EE_Registration $item
721
+	 * @return string
722
+	 * @throws \EE_Error
723
+	 */
724
+	public function column_TXN_total(EE_Registration $item)
725
+	{
726
+		if ($item->transaction()) {
727
+			$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
728
+				'action' => 'view_transaction',
729
+				'TXN_ID' => $item->transaction_ID(),
730
+			), TXN_ADMIN_URL);
731
+			return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction',
732
+				'espresso_transactions_view_transaction', $item->transaction_ID())
733
+				? '<span class="reg-pad-rght"><a class="status-'
734
+				  . $item->transaction()->status_ID()
735
+				  . '" href="'
736
+				  . $view_txn_lnk_url
737
+				  . '"  title="'
738
+				  . esc_attr__('View Transaction', 'event_espresso')
739
+				  . '">'
740
+				  . $item->transaction()->pretty_total()
741
+				  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
742
+		} else {
743
+			return __("None", "event_espresso");
744
+		}
745
+	}
746
+
747
+
748
+
749
+	/**
750
+	 * column_TXN_paid
751
+	 *
752
+	 * @access public
753
+	 * @param \EE_Registration $item
754
+	 * @return string
755
+	 * @throws \EE_Error
756
+	 */
757
+	public function column_TXN_paid(EE_Registration $item)
758
+	{
759
+		if ($item->count() === 1) {
760
+			$transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance();
761
+			if ($transaction->paid() >= $transaction->total()) {
762
+				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
763
+			} else {
764
+				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
765
+					'action' => 'view_transaction',
766
+					'TXN_ID' => $item->transaction_ID(),
767
+				), TXN_ADMIN_URL);
768
+				return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction',
769
+					'espresso_transactions_view_transaction', $item->transaction_ID())
770
+					? '<span class="reg-pad-rght"><a class="status-'
771
+					  . $transaction->status_ID()
772
+					  . '" href="'
773
+					  . $view_txn_lnk_url
774
+					  . '"  title="'
775
+					  . esc_attr__('View Transaction', 'event_espresso')
776
+					  . '">'
777
+					  . $item->transaction()->pretty_paid()
778
+					  . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
779
+			}
780
+		}
781
+		return '&nbsp;';
782
+	}
783
+
784
+
785
+
786
+	/**
787
+	 * column_actions
788
+	 *
789
+	 * @access public
790
+	 * @param \EE_Registration $item
791
+	 * @return string
792
+	 * @throws \EE_Error
793
+	 */
794
+	public function column_actions(EE_Registration $item)
795
+	{
796
+		$actions = array();
797
+		$attendee = $item->attendee();
798
+		$this->_set_related_details($item);
799
+		//Build row actions
800
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
801
+			'action'  => 'view_registration',
802
+			'_REG_ID' => $item->ID(),
803
+		), REG_ADMIN_URL);
804
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
805
+			'action' => 'edit_attendee',
806
+			'post'   => $item->attendee_ID(),
807
+		), REG_ADMIN_URL);
808
+		// page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
809
+		//$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
810
+		$resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
811
+			'action'  => 'resend_registration',
812
+			'_REG_ID' => $item->ID(),
813
+		), REG_ADMIN_URL, true);
814
+		//Build row actions
815
+		$actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_registration',
816
+			'espresso_registrations_view_registration', $item->ID()) ? '
817 817
 			<li>
818 818
 			<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
819 819
 				<div class="dashicons dashicons-clipboard"></div>
820 820
 			</a>
821 821
 			</li>' : '';
822
-        $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_contacts',
823
-            'espresso_registrations_edit_attendee')
824
-                               && $attendee instanceof EE_Attendee ? '
822
+		$actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_contacts',
823
+			'espresso_registrations_edit_attendee')
824
+							   && $attendee instanceof EE_Attendee ? '
825 825
 			<li>
826 826
 			<a href="' . $edit_lnk_url . '" title="' . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
827 827
 				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
828 828
 			</a>
829 829
 			</li>' : '';
830
-        $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee
831
-                                     && EE_Registry::instance()->CAP->current_user_can('ee_send_message',
832
-            'espresso_registrations_resend_registration', $item->ID()) ? '
830
+		$actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee
831
+									 && EE_Registry::instance()->CAP->current_user_can('ee_send_message',
832
+			'espresso_registrations_resend_registration', $item->ID()) ? '
833 833
 			<li>
834 834
 			<a href="'
835
-                                                                         . $resend_reg_lnk_url
836
-                                                                         . '" title="'
837
-                                                                         . esc_attr__('Resend Registration Details',
838
-                'event_espresso')
839
-                                                                         . '" class="tiny-text">
835
+																		 . $resend_reg_lnk_url
836
+																		 . '" title="'
837
+																		 . esc_attr__('Resend Registration Details',
838
+				'event_espresso')
839
+																		 . '" class="tiny-text">
840 840
 				<div class="dashicons dashicons-email-alt"></div>
841 841
 			</a>
842 842
 			</li>' : '';
843
-        // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
844
-        $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
845
-            'action' => 'view_transaction',
846
-            'TXN_ID' => $this->_transaction_details['id'],
847
-        ), TXN_ADMIN_URL);
848
-        $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction',
849
-            'espresso_transactions_view_transaction', $this->_transaction_details['id']) ? '
843
+		// page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
844
+		$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
845
+			'action' => 'view_transaction',
846
+			'TXN_ID' => $this->_transaction_details['id'],
847
+		), TXN_ADMIN_URL);
848
+		$actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction',
849
+			'espresso_transactions_view_transaction', $this->_transaction_details['id']) ? '
850 850
 			<li>
851 851
 			<a class="ee-status-color-'
852
-                                                                                           . $this->_transaction_details['status']
853
-                                                                                           . ' tiny-text" href="'
854
-                                                                                           . $view_txn_lnk_url
855
-                                                                                           . '"  title="'
856
-                                                                                           . $this->_transaction_details['title_attr']
857
-                                                                                           . '">
852
+																						   . $this->_transaction_details['status']
853
+																						   . ' tiny-text" href="'
854
+																						   . $view_txn_lnk_url
855
+																						   . '"  title="'
856
+																						   . $this->_transaction_details['title_attr']
857
+																						   . '">
858 858
 				<div class="dashicons dashicons-cart"></div>
859 859
 			</a>
860 860
 			</li>' : '';
861
-        //invoice link
862
-        $actions['dl_invoice_lnk'] = '';
863
-        $dl_invoice_lnk_url = $item->invoice_url();
864
-        //only show invoice link if message type is active.
865
-        if ($attendee instanceof EE_Attendee
866
-            && $item->is_primary_registrant()
867
-            && EEH_MSG_Template::is_mt_active('invoice')
868
-        ) {
869
-            $actions['dl_invoice_lnk'] = '
861
+		//invoice link
862
+		$actions['dl_invoice_lnk'] = '';
863
+		$dl_invoice_lnk_url = $item->invoice_url();
864
+		//only show invoice link if message type is active.
865
+		if ($attendee instanceof EE_Attendee
866
+			&& $item->is_primary_registrant()
867
+			&& EEH_MSG_Template::is_mt_active('invoice')
868
+		) {
869
+			$actions['dl_invoice_lnk'] = '
870 870
 		<li>
871 871
 			<a title="'
872
-                                         . esc_attr__('View Transaction Invoice', 'event_espresso')
873
-                                         . '" target="_blank" href="'
874
-                                         . $dl_invoice_lnk_url
875
-                                         . '" class="tiny-text">
872
+										 . esc_attr__('View Transaction Invoice', 'event_espresso')
873
+										 . '" target="_blank" href="'
874
+										 . $dl_invoice_lnk_url
875
+										 . '" class="tiny-text">
876 876
 				<span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
877 877
 			</a>
878 878
 		</li>';
879
-        }
880
-        $actions['filtered_messages_link'] = '';
881
-        //message list table link (filtered by REG_ID
882
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
883
-            $actions['filtered_messages_link'] = '<li>'
884
-                                                 . EEH_MSG_Template::get_message_action_link('see_notifications_for',
885
-                    null, array(
886
-                        '_REG_ID' => $item->ID(),
887
-                    ))
888
-                                                 . '</li>';
889
-        }
890
-        $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
891
-        return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
892
-    }
879
+		}
880
+		$actions['filtered_messages_link'] = '';
881
+		//message list table link (filtered by REG_ID
882
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
883
+			$actions['filtered_messages_link'] = '<li>'
884
+												 . EEH_MSG_Template::get_message_action_link('see_notifications_for',
885
+					null, array(
886
+						'_REG_ID' => $item->ID(),
887
+					))
888
+												 . '</li>';
889
+		}
890
+		$actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
891
+		return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
892
+	}
893 893
 
894 894
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
         );
158 158
         $this->_primary_column = '_REG_ID';
159 159
         $this->_sortable_columns = array(
160
-            '_REG_date'     => array('_REG_date' => true),   //true means its already sorted
160
+            '_REG_date'     => array('_REG_date' => true), //true means its already sorted
161 161
             /**
162 162
              * Allows users to change the default sort if they wish.
163 163
              * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
     {
190 190
         $class = parent::_get_row_class($item);
191 191
         //add status class
192
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
192
+        $class .= ' ee-status-strip reg-status-'.$item->status_ID();
193 193
         if ($this->_has_checkbox_column) {
194 194
             $class .= ' has-checkbox-column';
195 195
         }
@@ -337,11 +337,11 @@  discard block
 block discarded – undo
337 337
         //setup date query.
338 338
         $beginning_string = EEM_Registration::instance()
339 339
                                             ->convert_datetime_for_query('REG_date',
340
-                                                $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
340
+                                                $this_year_r.'-'.$this_month_r.'-01'.' '.$time_start,
341 341
                                                 'Y-m-d H:i:s');
342 342
         $end_string = EEM_Registration::instance()
343 343
                                       ->convert_datetime_for_query('REG_date',
344
-                                          $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
344
+                                          $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' '.$time_end,
345 345
                                           'Y-m-d H:i:s');
346 346
         $_where['REG_date'] = array(
347 347
             'BETWEEN',
@@ -374,9 +374,9 @@  discard block
 block discarded – undo
374 374
             'BETWEEN',
375 375
             array(
376 376
                 EEM_Registration::instance()
377
-                                ->convert_datetime_for_query('REG_date', $current_date . $time_start, 'Y-m-d H:i:s'),
377
+                                ->convert_datetime_for_query('REG_date', $current_date.$time_start, 'Y-m-d H:i:s'),
378 378
                 EEM_Registration::instance()
379
-                                ->convert_datetime_for_query('REG_date', $current_date . $time_end, 'Y-m-d H:i:s'),
379
+                                ->convert_datetime_for_query('REG_date', $current_date.$time_end, 'Y-m-d H:i:s'),
380 380
             ),
381 381
         );
382 382
         $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
         $content .= '<div class="show-on-mobile-view-only">';
421 421
         $content .= '<br>';
422 422
         $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
423
-        $content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
424
-        $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
423
+        $content .= '&nbsp;'.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
424
+        $content .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
425 425
         $content .= '</div>';
426 426
         return $content;
427 427
     }
@@ -492,10 +492,10 @@  discard block
 block discarded – undo
492 492
                   . $event_name
493 493
                   . '</a>' : $event_name;
494 494
             $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
495
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
495
+            $actions['event_filter'] = '<a href="'.$edit_event_url.'" title="';
496 496
             $actions['event_filter'] .= sprintf(esc_attr__('Filter this list to only show registrations for %s',
497 497
                 'event_espresso'), $event_name);
498
-            $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
498
+            $actions['event_filter'] .= '">'.__('View Registrations', 'event_espresso').'</a>';
499 499
         } else {
500 500
             $edit_event = $event_name;
501 501
             $actions['event_filter'] = '';
@@ -561,12 +561,12 @@  discard block
 block discarded – undo
561 561
         $t = $item->get_first_related('Transaction');
562 562
         $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
563 563
         //append group count to name
564
-        $link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
564
+        $link .= '&nbsp;'.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
565 565
         //append reg_code
566
-        $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
566
+        $link .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
567 567
         //reg status text for accessibility
568
-        $link .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->status_ID(), false,
569
-                'sentence') . '</span>';
568
+        $link .= '<br><span class="ee-status-text-small">'.EEH_Template::pretty_status($item->status_ID(), false,
569
+                'sentence').'</span>';
570 570
         //trash/restore/delete actions
571 571
         $actions = array();
572 572
         if ($this->_view !== 'trash'
@@ -578,8 +578,8 @@  discard block
 block discarded – undo
578 578
                 'action'  => 'trash_registrations',
579 579
                 '_REG_ID' => $item->ID(),
580 580
             ), REG_ADMIN_URL);
581
-            $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' . esc_attr__('Trash Registration',
582
-                    'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>';
581
+            $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="'.esc_attr__('Trash Registration',
582
+                    'event_espresso').'">'.__('Trash', 'event_espresso').'</a>';
583 583
         } elseif ($this->_view === 'trash') {
584 584
             // restore registration link
585 585
             if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration',
@@ -589,8 +589,8 @@  discard block
 block discarded – undo
589 589
                     'action'  => 'restore_registrations',
590 590
                     '_REG_ID' => $item->ID(),
591 591
                 ), REG_ADMIN_URL);
592
-                $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' . esc_attr__('Restore Registration',
593
-                        'event_espresso') . '">' . __('Restore', 'event_espresso') . '</a>';
592
+                $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="'.esc_attr__('Restore Registration',
593
+                        'event_espresso').'">'.__('Restore', 'event_espresso').'</a>';
594 594
             }
595 595
             if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration',
596 596
                 'espresso_registrations_ee_delete_registrations', $item->ID())
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
                                                                               . $ticket->name()
659 659
                                                                               . '</span><br />' : '';
660 660
         if ($item->final_price() > 0) {
661
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
661
+            $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>';
662 662
         } else {
663 663
             // free event
664 664
             $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
             : '<span class="TKT_name">'
686 686
               . $ticket->name()
687 687
               . '</span><br />';
688
-        $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
688
+        $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>';
689 689
         return $content;
690 690
     }
691 691
 
@@ -703,10 +703,10 @@  discard block
 block discarded – undo
703 703
         $payment_method = $item->payment_method();
704 704
         $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
705 705
             : __('Unknown', 'event_espresso');
706
-        $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
706
+        $content = '<span class="reg-pad-rght">'.$item->pretty_paid().'</span>';
707 707
         if ($item->paid() > 0) {
708
-            $content .= '<br><span class="ee-status-text-small">' . sprintf(__('...via %s', 'event_espresso'),
709
-                    $payment_method_name) . '</span>';
708
+            $content .= '<br><span class="ee-status-text-small">'.sprintf(__('...via %s', 'event_espresso'),
709
+                    $payment_method_name).'</span>';
710 710
         }
711 711
         return $content;
712 712
     }
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
                   . esc_attr__('View Transaction', 'event_espresso')
739 739
                   . '">'
740 740
                   . $item->transaction()->pretty_total()
741
-                  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
741
+                  . '</a></span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_total().'</span>';
742 742
         } else {
743 743
             return __("None", "event_espresso");
744 744
         }
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
                       . esc_attr__('View Transaction', 'event_espresso')
776 776
                       . '">'
777 777
                       . $item->transaction()->pretty_paid()
778
-                      . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
778
+                      . '</a><span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>';
779 779
             }
780 780
         }
781 781
         return '&nbsp;';
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
         $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_registration',
816 816
             'espresso_registrations_view_registration', $item->ID()) ? '
817 817
 			<li>
818
-			<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
818
+			<a href="' . $view_lnk_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'" class="tiny-text">
819 819
 				<div class="dashicons dashicons-clipboard"></div>
820 820
 			</a>
821 821
 			</li>' : '';
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
             'espresso_registrations_edit_attendee')
824 824
                                && $attendee instanceof EE_Attendee ? '
825 825
 			<li>
826
-			<a href="' . $edit_lnk_url . '" title="' . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
826
+			<a href="' . $edit_lnk_url.'" title="'.esc_attr__('Edit Contact Details', 'event_espresso').'" class="tiny-text">
827 827
 				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
828 828
 			</a>
829 829
 			</li>' : '';
Please login to merge, or discard this patch.
admin_pages/maintenance/Maintenance_Admin_Page_Init.core.php 2 patches
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -29,91 +29,91 @@  discard block
 block discarded – undo
29 29
 {
30 30
 
31 31
 
32
-    public function __construct()
33
-    {
34
-        //define some page related constants
35
-        define('EE_MAINTENANCE_LABEL', __('Maintenance', 'event_espresso'));
36
-        define('EE_MAINTENANCE_PG_SLUG', 'espresso_maintenance_settings');
37
-        define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page=' . EE_MAINTENANCE_PG_SLUG));
38
-        define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES . 'maintenance' . DS);
39
-        define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN . 'templates' . DS);
40
-        define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL . 'maintenance/assets/');
41
-        //check that if we're in maintenance mode that we tell the admin that
42
-        add_action('admin_notices', array($this, 'check_maintenance_mode'));
43
-        parent::__construct();
44
-    }
45
-
46
-
47
-
48
-    protected function _set_init_properties()
49
-    {
50
-        $this->label = EE_MAINTENANCE_LABEL;
51
-    }
52
-
53
-
54
-
55
-    protected function _set_menu_map()
56
-    {
57
-        $menu_map = $this->_menu_map();
58
-        $this->_menu_map = EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
59
-            ? new EE_Admin_Page_Main_Menu($menu_map) : new EE_Admin_Page_Sub_Menu($menu_map);
60
-    }
61
-
62
-
63
-
64
-    protected function _menu_map()
65
-    {
66
-        $map = array(
67
-            'menu_group'              => 'extras',
68
-            'menu_order'              => 30,
69
-            'show_on_menu'            => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
70
-            'parent_slug'             => 'espresso_events',
71
-            'menu_slug'               => EE_MAINTENANCE_PG_SLUG,
72
-            'menu_label'              => EE_MAINTENANCE_LABEL,
73
-            'capability'              => 'manage_options',
74
-            'maintenance_mode_parent' => EE_MAINTENANCE_PG_SLUG,
75
-            'admin_init_page'         => $this,
76
-        );
77
-        if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance) {
78
-            $map['menu_group'] = 'main';
79
-            $map['subtitle'] = EE_MAINTENANCE_LABEL;
80
-            $map['menu_label'] = __('Event Espresso', 'event_espresso');
81
-        }
82
-        return $map;
83
-    }
84
-
85
-
86
-
87
-    /**
88
-     * Checks if we're in maintenance mode, and if so we notify the admin adn tell them how to take the site OUT of
89
-     * maintenance mode
90
-     */
91
-    public function check_maintenance_mode()
92
-    {
93
-        $notice = '';
94
-        $maintenance_page_url = '';
95
-        if (EE_Maintenance_Mode::instance()->level()) {
96
-            $maintenance_page_url = EE_Admin_Page::add_query_args_and_nonce(array(), EE_MAINTENANCE_ADMIN_URL);
97
-            switch (EE_Maintenance_Mode::instance()->level()) {
98
-                case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
99
-                    $notice = '<div class="update-nag">
32
+	public function __construct()
33
+	{
34
+		//define some page related constants
35
+		define('EE_MAINTENANCE_LABEL', __('Maintenance', 'event_espresso'));
36
+		define('EE_MAINTENANCE_PG_SLUG', 'espresso_maintenance_settings');
37
+		define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page=' . EE_MAINTENANCE_PG_SLUG));
38
+		define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES . 'maintenance' . DS);
39
+		define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN . 'templates' . DS);
40
+		define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL . 'maintenance/assets/');
41
+		//check that if we're in maintenance mode that we tell the admin that
42
+		add_action('admin_notices', array($this, 'check_maintenance_mode'));
43
+		parent::__construct();
44
+	}
45
+
46
+
47
+
48
+	protected function _set_init_properties()
49
+	{
50
+		$this->label = EE_MAINTENANCE_LABEL;
51
+	}
52
+
53
+
54
+
55
+	protected function _set_menu_map()
56
+	{
57
+		$menu_map = $this->_menu_map();
58
+		$this->_menu_map = EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
59
+			? new EE_Admin_Page_Main_Menu($menu_map) : new EE_Admin_Page_Sub_Menu($menu_map);
60
+	}
61
+
62
+
63
+
64
+	protected function _menu_map()
65
+	{
66
+		$map = array(
67
+			'menu_group'              => 'extras',
68
+			'menu_order'              => 30,
69
+			'show_on_menu'            => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
70
+			'parent_slug'             => 'espresso_events',
71
+			'menu_slug'               => EE_MAINTENANCE_PG_SLUG,
72
+			'menu_label'              => EE_MAINTENANCE_LABEL,
73
+			'capability'              => 'manage_options',
74
+			'maintenance_mode_parent' => EE_MAINTENANCE_PG_SLUG,
75
+			'admin_init_page'         => $this,
76
+		);
77
+		if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance) {
78
+			$map['menu_group'] = 'main';
79
+			$map['subtitle'] = EE_MAINTENANCE_LABEL;
80
+			$map['menu_label'] = __('Event Espresso', 'event_espresso');
81
+		}
82
+		return $map;
83
+	}
84
+
85
+
86
+
87
+	/**
88
+	 * Checks if we're in maintenance mode, and if so we notify the admin adn tell them how to take the site OUT of
89
+	 * maintenance mode
90
+	 */
91
+	public function check_maintenance_mode()
92
+	{
93
+		$notice = '';
94
+		$maintenance_page_url = '';
95
+		if (EE_Maintenance_Mode::instance()->level()) {
96
+			$maintenance_page_url = EE_Admin_Page::add_query_args_and_nonce(array(), EE_MAINTENANCE_ADMIN_URL);
97
+			switch (EE_Maintenance_Mode::instance()->level()) {
98
+				case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
99
+					$notice = '<div class="update-nag">
100 100
 						'
101
-                              . sprintf(__("Event Espresso is in Frontend-Only MAINTENANCE MODE. This means the front-end (ie, non-wp-admin pages) is disabled for ALL users except site admins. Visit the %s Maintenance Page %s to disable maintenance mode.",
102
-                            "event_espresso"), "<a href='$maintenance_page_url'>", "</a>")
103
-                              .
104
-                              '</div>';
105
-                    break;
106
-                case EE_Maintenance_Mode::level_2_complete_maintenance:
107
-                    $notice = '<div class="error">
101
+							  . sprintf(__("Event Espresso is in Frontend-Only MAINTENANCE MODE. This means the front-end (ie, non-wp-admin pages) is disabled for ALL users except site admins. Visit the %s Maintenance Page %s to disable maintenance mode.",
102
+							"event_espresso"), "<a href='$maintenance_page_url'>", "</a>")
103
+							  .
104
+							  '</div>';
105
+					break;
106
+				case EE_Maintenance_Mode::level_2_complete_maintenance:
107
+					$notice = '<div class="error">
108 108
 						<p>' . sprintf(__("As part of the process for updating Event Espresso, your database also
109 109
 needs to be updated. Event Espresso is in COMPLETE MAINTENANCE MODE (both WordPress admin pages and front-end event registration pages are disabled) until you run the database update script. %s Visit the Maintenance Page to get started,%s it only takes a moment.",
110
-                            "event_espresso"), "<a href='$maintenance_page_url'>", "</a>") .
111
-                              '</div>';
112
-                    break;
113
-            }
114
-        }
115
-        echo apply_filters('FHEE__Maintenance_Admin_Page_Init__check_maintenance_mode__notice', $notice,
116
-            $maintenance_page_url);
117
-    }
110
+							"event_espresso"), "<a href='$maintenance_page_url'>", "</a>") .
111
+							  '</div>';
112
+					break;
113
+			}
114
+		}
115
+		echo apply_filters('FHEE__Maintenance_Admin_Page_Init__check_maintenance_mode__notice', $notice,
116
+			$maintenance_page_url);
117
+	}
118 118
 
119 119
 } //end class Payments_Admin_Page_Init
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -34,10 +34,10 @@  discard block
 block discarded – undo
34 34
         //define some page related constants
35 35
         define('EE_MAINTENANCE_LABEL', __('Maintenance', 'event_espresso'));
36 36
         define('EE_MAINTENANCE_PG_SLUG', 'espresso_maintenance_settings');
37
-        define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page=' . EE_MAINTENANCE_PG_SLUG));
38
-        define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES . 'maintenance' . DS);
39
-        define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN . 'templates' . DS);
40
-        define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL . 'maintenance/assets/');
37
+        define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page='.EE_MAINTENANCE_PG_SLUG));
38
+        define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES.'maintenance'.DS);
39
+        define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN.'templates'.DS);
40
+        define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL.'maintenance/assets/');
41 41
         //check that if we're in maintenance mode that we tell the admin that
42 42
         add_action('admin_notices', array($this, 'check_maintenance_mode'));
43 43
         parent::__construct();
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
                     $notice = '<div class="error">
108 108
 						<p>' . sprintf(__("As part of the process for updating Event Espresso, your database also
109 109
 needs to be updated. Event Espresso is in COMPLETE MAINTENANCE MODE (both WordPress admin pages and front-end event registration pages are disabled) until you run the database update script. %s Visit the Maintenance Page to get started,%s it only takes a moment.",
110
-                            "event_espresso"), "<a href='$maintenance_page_url'>", "</a>") .
110
+                            "event_espresso"), "<a href='$maintenance_page_url'>", "</a>").
111 111
                               '</div>';
112 112
                     break;
113 113
             }
Please login to merge, or discard this patch.
modules/invalid_checkout_access/InvalidCheckoutAccess.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
 		if (
40 40
 			! ( $checkout->uts || $checkout->reg_url_link )
41 41
 			&& ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )
42
-            && \EE_Config::instance()->registration->track_invalid_checkout_access()
43
-        ) {
42
+			&& \EE_Config::instance()->registration->track_invalid_checkout_access()
43
+		) {
44 44
 			/** @var \EE_Request $request */
45 45
 			$request = \EE_Registry::instance()->load_core( 'EE_Request' );
46 46
 			$ip_address = $request->ip_address();
@@ -60,14 +60,14 @@  discard block
 block discarded – undo
60 60
 			}
61 61
 			$ee_bot_checkout[ $ip_address ][ $http_referer ]++;
62 62
 			update_option( InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout );
63
-            if (WP_DEBUG) {
64
-                \EE_Error::add_error(
65
-                    esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'),
66
-                    __FILE__,
67
-                    __FUNCTION__,
68
-                    __LINE__
69
-                );
70
-            }
63
+			if (WP_DEBUG) {
64
+				\EE_Error::add_error(
65
+					esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'),
66
+					__FILE__,
67
+					__FUNCTION__,
68
+					__LINE__
69
+				);
70
+			}
71 71
 			return true;
72 72
 		}
73 73
 		return false;
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\modules\invalid_checkout_access;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -35,31 +35,31 @@  discard block
 block discarded – undo
35 35
 	 * @param \EE_Checkout $checkout
36 36
 	 * @return bool true if access to registration checkout appears to be invalid
37 37
 	 */
38
-	public function checkoutAccessIsInvalid( \EE_Checkout $checkout ) {
38
+	public function checkoutAccessIsInvalid(\EE_Checkout $checkout) {
39 39
 		if (
40
-			! ( $checkout->uts || $checkout->reg_url_link )
41
-			&& ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )
40
+			! ($checkout->uts || $checkout->reg_url_link)
41
+			&& ! (defined('DOING_AJAX') && DOING_AJAX)
42 42
             && \EE_Config::instance()->registration->track_invalid_checkout_access()
43 43
         ) {
44 44
 			/** @var \EE_Request $request */
45
-			$request = \EE_Registry::instance()->load_core( 'EE_Request' );
45
+			$request = \EE_Registry::instance()->load_core('EE_Request');
46 46
 			$ip_address = $request->ip_address();
47
-			$ee_bot_checkout = get_option( InvalidCheckoutAccess::OPTION_KEY );
48
-			if ( $ee_bot_checkout === false ) {
47
+			$ee_bot_checkout = get_option(InvalidCheckoutAccess::OPTION_KEY);
48
+			if ($ee_bot_checkout === false) {
49 49
 				$ee_bot_checkout = array();
50
-				add_option( InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout, '', false );
50
+				add_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout, '', false);
51 51
 			}
52
-			if ( ! isset( $ee_bot_checkout[ $ip_address ] ) ) {
53
-				$ee_bot_checkout[ $ip_address ] = array();
52
+			if ( ! isset($ee_bot_checkout[$ip_address])) {
53
+				$ee_bot_checkout[$ip_address] = array();
54 54
 			}
55
-			$http_referer = isset( $_SERVER['HTTP_REFERER'] )
56
-				? esc_attr( $_SERVER['HTTP_REFERER'] )
55
+			$http_referer = isset($_SERVER['HTTP_REFERER'])
56
+				? esc_attr($_SERVER['HTTP_REFERER'])
57 57
 				: 0;
58
-			if ( ! isset( $ee_bot_checkout[ $ip_address ][ $http_referer ] ) ) {
59
-				$ee_bot_checkout[ $ip_address ][ $http_referer ] = 0;
58
+			if ( ! isset($ee_bot_checkout[$ip_address][$http_referer])) {
59
+				$ee_bot_checkout[$ip_address][$http_referer] = 0;
60 60
 			}
61
-			$ee_bot_checkout[ $ip_address ][ $http_referer ]++;
62
-			update_option( InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout );
61
+			$ee_bot_checkout[$ip_address][$http_referer]++;
62
+			update_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout);
63 63
             if (WP_DEBUG) {
64 64
                 \EE_Error::add_error(
65 65
                     esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'),
@@ -88,13 +88,13 @@  discard block
 block discarded – undo
88 88
 				'layout_strategy' => new \EE_Admin_Two_Column_Layout(),
89 89
 				'subsections'     => array(
90 90
 					'invalid_checkout_access_hdr'   => new \EE_Form_Section_HTML(
91
-						\EEH_HTML::h2( esc_html__( 'Invalid Checkout Access', 'event_espresso' ) )
91
+						\EEH_HTML::h2(esc_html__('Invalid Checkout Access', 'event_espresso'))
92 92
 					),
93 93
 					'ee_bot_checkout_data'          => new \EE_Text_Area_Input(
94 94
 						array(
95
-							'html_label_text' => esc_html__( 'Invalid Checkout Data', 'event_espresso' ),
95
+							'html_label_text' => esc_html__('Invalid Checkout Data', 'event_espresso'),
96 96
 							'default'         => var_export(
97
-								get_option( InvalidCheckoutAccess::OPTION_KEY, array() ),
97
+								get_option(InvalidCheckoutAccess::OPTION_KEY, array()),
98 98
 								true
99 99
 							),
100 100
 							'required'        => false,
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 					),
107 107
 					'track_invalid_checkout_access' => new \EE_Yes_No_Input(
108 108
 						array(
109
-							'html_label_text'         => __( 'Track Invalid Checkout Access?', 'event_espresso' ),
109
+							'html_label_text'         => __('Track Invalid Checkout Access?', 'event_espresso'),
110 110
 							'html_help_text'          => esc_html__(
111 111
 								'Controls whether or not invalid attempts to directly access the registration checkout page should be tracked. Setting this to "No" means that the above data will no longer be collected.',
112 112
 								'event_espresso'
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 					),
120 120
 					'delete_invalid_checkout_data'  => new \EE_Yes_No_Input(
121 121
 						array(
122
-							'html_label_text'         => __( 'Reset Invalid Checkout Data', 'event_espresso' ),
122
+							'html_label_text'         => __('Reset Invalid Checkout Data', 'event_espresso'),
123 123
 							'html_help_text'          => esc_html__(
124 124
 								'Setting this to "Yes" will delete all existing invalid checkout access data.',
125 125
 								'event_espresso'
@@ -141,15 +141,15 @@  discard block
 block discarded – undo
141 141
 	 * @param \EE_Registration_Config $EE_Registration_Config
142 142
 	 * @return \EE_Registration_Config
143 143
 	 */
144
-	public function processForm( \EE_Registration_Config $EE_Registration_Config ) {
144
+	public function processForm(\EE_Registration_Config $EE_Registration_Config) {
145 145
 		try {
146 146
 			$invalid_checkout_access_form = $this->getForm();
147 147
 			// if not displaying a form, then check for form submission
148
-			if ( $invalid_checkout_access_form->was_submitted() ) {
148
+			if ($invalid_checkout_access_form->was_submitted()) {
149 149
 				// capture form data
150 150
 				$invalid_checkout_access_form->receive_form_submission();
151 151
 				// validate form data
152
-				if ( $invalid_checkout_access_form->is_valid() ) {
152
+				if ($invalid_checkout_access_form->is_valid()) {
153 153
 					// grab validated data from form
154 154
 					$valid_data = $invalid_checkout_access_form->valid_data();
155 155
 					// ensure form inputs we want are set
@@ -163,8 +163,8 @@  discard block
 block discarded – undo
163 163
 							$valid_data['track_invalid_checkout_access']
164 164
 						);
165 165
 						// if deleting, then update option with empty array
166
-						if ( filter_var( $valid_data['delete_invalid_checkout_data'], FILTER_VALIDATE_BOOLEAN ) ) {
167
-							update_option( InvalidCheckoutAccess::OPTION_KEY, array() );
166
+						if (filter_var($valid_data['delete_invalid_checkout_data'], FILTER_VALIDATE_BOOLEAN)) {
167
+							update_option(InvalidCheckoutAccess::OPTION_KEY, array());
168 168
 						}
169 169
 					} else {
170 170
 						\EE_Error::add_error(
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 						);
179 179
 					}
180 180
 				} else {
181
-					if ( $invalid_checkout_access_form->submission_error_message() !== '' ) {
181
+					if ($invalid_checkout_access_form->submission_error_message() !== '') {
182 182
 						\EE_Error::add_error(
183 183
 							$invalid_checkout_access_form->submission_error_message(),
184 184
 							__FILE__,
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 					}
189 189
 				}
190 190
 			}
191
-		} catch ( \EE_Error $e ) {
191
+		} catch (\EE_Error $e) {
192 192
 			$e->get_error();
193 193
 		}
194 194
 		return $EE_Registration_Config;
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Proper.form.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -370,7 +370,7 @@
 block discarded – undo
370 370
      *                                                      with construction finalize being called later
371 371
      *                                                      (realizing that the subsections' html names
372 372
      *                                                      might not be set yet, etc.)
373
-     * @return EE_Form_Section_Base
373
+     * @return EE_Form_Section_Validatable|null
374 374
      * @throws \EE_Error
375 375
      */
376 376
     public function get_subsection($name, $require_construction_to_be_finalized = true)
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public function __construct($options_array = array())
86 86
     {
87
-        $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
87
+        $options_array = (array) apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
88 88
             $this);
89 89
         //call parent first, as it may be setting the name
90 90
         parent::__construct($options_array);
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
         if (isset($options_array['layout_strategy'])) {
108 108
             $this->_layout_strategy = $options_array['layout_strategy'];
109 109
         }
110
-        if (! $this->_layout_strategy) {
110
+        if ( ! $this->_layout_strategy) {
111 111
             $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
112 112
         }
113 113
         $this->_layout_strategy->_construct_finalize($this);
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
         if ($validate) {
259 259
             $this->_validate();
260 260
             //if it's invalid, we're going to want to re-display so remember what they submitted
261
-            if (! $this->is_valid()) {
261
+            if ( ! $this->is_valid()) {
262 262
                 $this->store_submitted_form_data_in_session();
263 263
             }
264 264
         }
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
     public function get_input($name, $require_construction_to_be_finalized = true)
439 439
     {
440 440
         $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
441
-        if (! $subsection instanceof EE_Form_Input_Base) {
441
+        if ( ! $subsection instanceof EE_Form_Input_Base) {
442 442
             throw new EE_Error(
443 443
                 sprintf(
444 444
                     __(
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
     public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
474 474
     {
475 475
         $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
476
-        if (! $subsection instanceof EE_Form_Section_Proper) {
476
+        if ( ! $subsection instanceof EE_Form_Section_Proper) {
477 477
             throw new EE_Error(
478 478
                 sprintf(
479 479
                     __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
      */
512 512
     public function is_valid()
513 513
     {
514
-        if (! $this->has_received_submission()) {
514
+        if ( ! $this->has_received_submission()) {
515 515
             throw new EE_Error(
516 516
                 sprintf(
517 517
                     __(
@@ -521,14 +521,14 @@  discard block
 block discarded – undo
521 521
                 )
522 522
             );
523 523
         }
524
-        if (! parent::is_valid()) {
524
+        if ( ! parent::is_valid()) {
525 525
             return false;
526 526
         }
527 527
         // ok so no general errors to this entire form section.
528 528
         // so let's check the subsections, but only set errors if that hasn't been done yet
529 529
         $set_submission_errors = $this->submission_error_message() === '' ? true : false;
530 530
         foreach ($this->get_validatable_subsections() as $subsection) {
531
-            if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
531
+            if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
532 532
                 if ($set_submission_errors) {
533 533
                     $this->set_submission_error_message($subsection->get_validation_error_string());
534 534
                 }
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
      */
548 548
     protected function _set_default_name_if_empty()
549 549
     {
550
-        if (! $this->_name) {
550
+        if ( ! $this->_name) {
551 551
             $classname = get_class($this);
552 552
             $default_name = str_replace("EE_", "", $classname);
553 553
             $this->_name = $default_name;
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
     {
633 633
         wp_register_script(
634 634
             'ee_form_section_validation',
635
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
635
+            EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js',
636 636
             array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
637 637
             EVENT_ESPRESSO_VERSION,
638 638
             true
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
      */
779 779
     public function ensure_scripts_localized()
780 780
     {
781
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
781
+        if ( ! EE_Form_Section_Proper::$_scripts_localized) {
782 782
             $this->_enqueue_and_localize_form_js();
783 783
         }
784 784
     }
@@ -874,8 +874,8 @@  discard block
 block discarded – undo
874 874
     protected function _validate()
875 875
     {
876 876
         foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
877
-            if (method_exists($this, '_validate_' . $subsection_name)) {
878
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
877
+            if (method_exists($this, '_validate_'.$subsection_name)) {
878
+                call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection));
879 879
             }
880 880
             $subsection->_validate();
881 881
         }
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
     public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1152 1152
     {
1153 1153
         foreach ($new_subsections as $subsection_name => $subsection) {
1154
-            if (! $subsection instanceof EE_Form_Section_Base) {
1154
+            if ( ! $subsection instanceof EE_Form_Section_Base) {
1155 1155
                 EE_Error::add_error(
1156 1156
                     sprintf(
1157 1157
                         __(
@@ -1249,7 +1249,7 @@  discard block
 block discarded – undo
1249 1249
     public function html_name_prefix()
1250 1250
     {
1251 1251
         if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1252
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1252
+            return $this->parent_section()->html_name_prefix().'['.$this->name().']';
1253 1253
         } else {
1254 1254
             return $this->name();
1255 1255
         }
@@ -1293,7 +1293,7 @@  discard block
 block discarded – undo
1293 1293
      */
1294 1294
     public function ensure_construct_finalized_called()
1295 1295
     {
1296
-        if (! $this->_construction_finalized) {
1296
+        if ( ! $this->_construction_finalized) {
1297 1297
             $this->_construct_finalize($this->_parent_section, $this->_name);
1298 1298
         }
1299 1299
     }
Please login to merge, or discard this patch.
Indentation   +1379 added lines, -1379 removed lines patch added patch discarded remove patch
@@ -11,1385 +11,1385 @@
 block discarded – undo
11 11
 class EE_Form_Section_Proper extends EE_Form_Section_Validatable
12 12
 {
13 13
 
14
-    const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
15
-
16
-    /**
17
-     * Subsections
18
-     *
19
-     * @var EE_Form_Section_Validatable[]
20
-     */
21
-    protected $_subsections = array();
22
-
23
-    /**
24
-     * Strategy for laying out the form
25
-     *
26
-     * @var EE_Form_Section_Layout_Base
27
-     */
28
-    protected $_layout_strategy;
29
-
30
-    /**
31
-     * Whether or not this form has received and validated a form submission yet
32
-     *
33
-     * @var boolean
34
-     */
35
-    protected $_received_submission = false;
36
-
37
-    /**
38
-     * message displayed to users upon successful form submission
39
-     *
40
-     * @var string
41
-     */
42
-    protected $_form_submission_success_message = '';
43
-
44
-    /**
45
-     * message displayed to users upon unsuccessful form submission
46
-     *
47
-     * @var string
48
-     */
49
-    protected $_form_submission_error_message = '';
50
-
51
-    /**
52
-     * Stores all the data that will localized for form validation
53
-     *
54
-     * @var array
55
-     */
56
-    static protected $_js_localization = array();
57
-
58
-    /**
59
-     * whether or not the form's localized validation JS vars have been set
60
-     *
61
-     * @type boolean
62
-     */
63
-    static protected $_scripts_localized = false;
64
-
65
-
66
-
67
-    /**
68
-     * when constructing a proper form section, calls _construct_finalize on children
69
-     * so that they know who their parent is, and what name they've been given.
70
-     *
71
-     * @param array $options_array   {
72
-     * @type        $subsections     EE_Form_Section_Validatable[] where keys are the section's name
73
-     * @type        $include         string[] numerically-indexed where values are section names to be included,
74
-     *                               and in that order. This is handy if you want
75
-     *                               the subsections to be ordered differently than the default, and if you override
76
-     *                               which fields are shown
77
-     * @type        $exclude         string[] values are subsections to be excluded. This is handy if you want
78
-     *                               to remove certain default subsections (note: if you specify BOTH 'include' AND
79
-     *                               'exclude', the inclusions will be applied first, and the exclusions will exclude
80
-     *                               items from that list of inclusions)
81
-     * @type        $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
82
-     *                               } @see EE_Form_Section_Validatable::__construct()
83
-     * @throws \EE_Error
84
-     */
85
-    public function __construct($options_array = array())
86
-    {
87
-        $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
88
-            $this);
89
-        //call parent first, as it may be setting the name
90
-        parent::__construct($options_array);
91
-        //if they've included subsections in the constructor, add them now
92
-        if (isset($options_array['include'])) {
93
-            //we are going to make sure we ONLY have those subsections to include
94
-            //AND we are going to make sure they're in that specified order
95
-            $reordered_subsections = array();
96
-            foreach ($options_array['include'] as $input_name) {
97
-                if (isset($this->_subsections[$input_name])) {
98
-                    $reordered_subsections[$input_name] = $this->_subsections[$input_name];
99
-                }
100
-            }
101
-            $this->_subsections = $reordered_subsections;
102
-        }
103
-        if (isset($options_array['exclude'])) {
104
-            $exclude = $options_array['exclude'];
105
-            $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
106
-        }
107
-        if (isset($options_array['layout_strategy'])) {
108
-            $this->_layout_strategy = $options_array['layout_strategy'];
109
-        }
110
-        if (! $this->_layout_strategy) {
111
-            $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
112
-        }
113
-        $this->_layout_strategy->_construct_finalize($this);
114
-        //ok so we are definitely going to want the forms JS,
115
-        //so enqueue it or remember to enqueue it during wp_enqueue_scripts
116
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
117
-            //ok so they've constructed this object after when they should have.
118
-            //just enqueue the generic form scripts and initialize the form immediately in the JS
119
-            \EE_Form_Section_Proper::wp_enqueue_scripts(true);
120
-        } else {
121
-            add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
122
-            add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
123
-        }
124
-        add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
125
-
126
-        /**
127
-         * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't
128
-         * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to
129
-         * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
130
-         * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
131
-         * @since 4.9.32
132
-         * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling
133
-         *                                      _construct_finalize has been done
134
-         * @param array $options_array options passed into the constructor
135
-         */
136
-        do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array);
137
-
138
-        if (isset($options_array['name'])) {
139
-            $this->_construct_finalize(null, $options_array['name']);
140
-        }
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * Finishes construction given the parent form section and this form section's name
147
-     *
148
-     * @param EE_Form_Section_Proper $parent_form_section
149
-     * @param string                 $name
150
-     * @throws \EE_Error
151
-     */
152
-    public function _construct_finalize($parent_form_section, $name)
153
-    {
154
-        parent::_construct_finalize($parent_form_section, $name);
155
-        $this->_set_default_name_if_empty();
156
-        $this->_set_default_html_id_if_empty();
157
-        foreach ($this->_subsections as $subsection_name => $subsection) {
158
-            if ($subsection instanceof EE_Form_Section_Base) {
159
-                $subsection->_construct_finalize($this, $subsection_name);
160
-            } else {
161
-                throw new EE_Error(
162
-                    sprintf(
163
-                        __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
164
-                            'event_espresso'),
165
-                        $subsection_name,
166
-                        get_class($this),
167
-                        $subsection ? get_class($subsection) : __('NULL', 'event_espresso')
168
-                    )
169
-                );
170
-            }
171
-        }
172
-        /**
173
-         * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
174
-         * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived
175
-         * from the name like the HTML label id, etc), this is where it should be done.
176
-         * This might only happen just before displaying the form, or just before it receives form submission data.
177
-         * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
178
-         * ensured it has a name, HTML IDs, etc
179
-         * @param EE_Form_Section_Proper $this
180
-         * @param EE_Form_Section_Proper|null $parent_form_section
181
-         * @param string $name
182
-         */
183
-        do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name);
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * Gets the layout strategy for this form section
190
-     *
191
-     * @return EE_Form_Section_Layout_Base
192
-     */
193
-    public function get_layout_strategy()
194
-    {
195
-        return $this->_layout_strategy;
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * Gets the HTML for a single input for this form section according
202
-     * to the layout strategy
203
-     *
204
-     * @param EE_Form_Input_Base $input
205
-     * @return string
206
-     */
207
-    public function get_html_for_input($input)
208
-    {
209
-        return $this->_layout_strategy->layout_input($input);
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * was_submitted - checks if form inputs are present in request data
216
-     * Basically an alias for form_data_present_in() (which is used by both
217
-     * proper form sections and form inputs)
218
-     *
219
-     * @param null $form_data
220
-     * @return boolean
221
-     */
222
-    public function was_submitted($form_data = null)
223
-    {
224
-        return $this->form_data_present_in($form_data);
225
-    }
226
-
227
-
228
-
229
-    /**
230
-     * After the form section is initially created, call this to sanitize the data in the submission
231
-     * which relates to this form section, validate it, and set it as properties on the form.
232
-     *
233
-     * @param array|null $req_data should usually be $_POST (the default).
234
-     *                             However, you CAN supply a different array.
235
-     *                             Consider using set_defaults() instead however.
236
-     *                             (If you rendered the form in the page using echo $form_x->get_html()
237
-     *                             the inputs will have the correct name in the request data for this function
238
-     *                             to find them and populate the form with them.
239
-     *                             If you have a flat form (with only input subsections),
240
-     *                             you can supply a flat array where keys
241
-     *                             are the form input names and values are their values)
242
-     * @param boolean    $validate whether or not to perform validation on this data. Default is,
243
-     *                             of course, to validate that data, and set errors on the invalid values.
244
-     *                             But if the data has already been validated
245
-     *                             (eg you validated the data then stored it in the DB)
246
-     *                             you may want to skip this step.
247
-     */
248
-    public function receive_form_submission($req_data = null, $validate = true)
249
-    {
250
-        $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this,
251
-            $validate);
252
-        if ($req_data === null) {
253
-            $req_data = array_merge($_GET, $_POST);
254
-        }
255
-        $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data,
256
-            $this);
257
-        $this->_normalize($req_data);
258
-        if ($validate) {
259
-            $this->_validate();
260
-            //if it's invalid, we're going to want to re-display so remember what they submitted
261
-            if (! $this->is_valid()) {
262
-                $this->store_submitted_form_data_in_session();
263
-            }
264
-        }
265
-        do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate);
266
-    }
267
-
268
-
269
-
270
-    /**
271
-     * caches the originally submitted input values in the session
272
-     * so that they can be used to repopulate the form if it failed validation
273
-     *
274
-     * @return boolean whether or not the data was successfully stored in the session
275
-     */
276
-    protected function store_submitted_form_data_in_session()
277
-    {
278
-        return EE_Registry::instance()->SSN->set_session_data(
279
-            array(
280
-                \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
281
-            )
282
-        );
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * retrieves the originally submitted input values in the session
289
-     * so that they can be used to repopulate the form if it failed validation
290
-     *
291
-     * @return array
292
-     */
293
-    protected function get_submitted_form_data_from_session()
294
-    {
295
-        $session = EE_Registry::instance()->SSN;
296
-        if ($session instanceof EE_Session) {
297
-            return $session->get_session_data(
298
-                \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
299
-            );
300
-        } else {
301
-            return array();
302
-        }
303
-    }
304
-
305
-
306
-
307
-    /**
308
-     * flushed the originally submitted input values from the session
309
-     *
310
-     * @return boolean whether or not the data was successfully removed from the session
311
-     */
312
-    protected function flush_submitted_form_data_from_session()
313
-    {
314
-        return EE_Registry::instance()->SSN->reset_data(
315
-            array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
316
-        );
317
-    }
318
-
319
-
320
-
321
-    /**
322
-     * Populates this form and its subsections with data from the session.
323
-     * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
324
-     * validation errors when displaying too)
325
-     * Returns true if the form was populated from the session, false otherwise
326
-     *
327
-     * @return boolean
328
-     */
329
-    public function populate_from_session()
330
-    {
331
-        $form_data_in_session = $this->get_submitted_form_data_from_session();
332
-        if (empty($form_data_in_session)) {
333
-            return false;
334
-        }
335
-        $this->receive_form_submission($form_data_in_session);
336
-        $this->flush_submitted_form_data_from_session();
337
-        if ($this->form_data_present_in($form_data_in_session)) {
338
-            return true;
339
-        } else {
340
-            return false;
341
-        }
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * Populates the default data for the form, given an array where keys are
348
-     * the input names, and values are their values (preferably normalized to be their
349
-     * proper PHP types, not all strings... although that should be ok too).
350
-     * Proper subsections are sub-arrays, the key being the subsection's name, and
351
-     * the value being an array formatted in teh same way
352
-     *
353
-     * @param array $default_data
354
-     */
355
-    public function populate_defaults($default_data)
356
-    {
357
-        foreach ($this->subsections(false) as $subsection_name => $subsection) {
358
-            if (isset($default_data[$subsection_name])) {
359
-                if ($subsection instanceof EE_Form_Input_Base) {
360
-                    $subsection->set_default($default_data[$subsection_name]);
361
-                } elseif ($subsection instanceof EE_Form_Section_Proper) {
362
-                    $subsection->populate_defaults($default_data[$subsection_name]);
363
-                }
364
-            }
365
-        }
366
-    }
367
-
368
-
369
-
370
-    /**
371
-     * returns true if subsection exists
372
-     *
373
-     * @param string $name
374
-     * @return boolean
375
-     */
376
-    public function subsection_exists($name)
377
-    {
378
-        return isset($this->_subsections[$name]) ? true : false;
379
-    }
380
-
381
-
382
-
383
-    /**
384
-     * Gets the subsection specified by its name
385
-     *
386
-     * @param string  $name
387
-     * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
388
-     *                                                      so that the inputs will be properly configured.
389
-     *                                                      However, some client code may be ok
390
-     *                                                      with construction finalize being called later
391
-     *                                                      (realizing that the subsections' html names
392
-     *                                                      might not be set yet, etc.)
393
-     * @return EE_Form_Section_Base
394
-     * @throws \EE_Error
395
-     */
396
-    public function get_subsection($name, $require_construction_to_be_finalized = true)
397
-    {
398
-        if ($require_construction_to_be_finalized) {
399
-            $this->ensure_construct_finalized_called();
400
-        }
401
-        return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     * Gets all the validatable subsections of this form section
408
-     *
409
-     * @return EE_Form_Section_Validatable[]
410
-     */
411
-    public function get_validatable_subsections()
412
-    {
413
-        $validatable_subsections = array();
414
-        foreach ($this->subsections() as $name => $obj) {
415
-            if ($obj instanceof EE_Form_Section_Validatable) {
416
-                $validatable_subsections[$name] = $obj;
417
-            }
418
-        }
419
-        return $validatable_subsections;
420
-    }
421
-
422
-
423
-
424
-    /**
425
-     * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
426
-     * throw an EE_Error.
427
-     *
428
-     * @param string  $name
429
-     * @param boolean $require_construction_to_be_finalized most client code should
430
-     *                                                      leave this as TRUE so that the inputs will be properly
431
-     *                                                      configured. However, some client code may be ok with
432
-     *                                                      construction finalize being called later
433
-     *                                                      (realizing that the subsections' html names might not be
434
-     *                                                      set yet, etc.)
435
-     * @return EE_Form_Input_Base
436
-     * @throws EE_Error
437
-     */
438
-    public function get_input($name, $require_construction_to_be_finalized = true)
439
-    {
440
-        $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
441
-        if (! $subsection instanceof EE_Form_Input_Base) {
442
-            throw new EE_Error(
443
-                sprintf(
444
-                    __(
445
-                        "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
446
-                        'event_espresso'
447
-                    ),
448
-                    $name,
449
-                    get_class($this),
450
-                    $subsection ? get_class($subsection) : __("NULL", 'event_espresso')
451
-                )
452
-            );
453
-        }
454
-        return $subsection;
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * Like get_input(), gets the proper subsection of the form given the name,
461
-     * otherwise throws an EE_Error
462
-     *
463
-     * @param string  $name
464
-     * @param boolean $require_construction_to_be_finalized most client code should
465
-     *                                                      leave this as TRUE so that the inputs will be properly
466
-     *                                                      configured. However, some client code may be ok with
467
-     *                                                      construction finalize being called later
468
-     *                                                      (realizing that the subsections' html names might not be
469
-     *                                                      set yet, etc.)
470
-     * @return EE_Form_Section_Proper
471
-     * @throws EE_Error
472
-     */
473
-    public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
474
-    {
475
-        $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
476
-        if (! $subsection instanceof EE_Form_Section_Proper) {
477
-            throw new EE_Error(
478
-                sprintf(
479
-                    __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
480
-                    $name,
481
-                    get_class($this)
482
-                )
483
-            );
484
-        }
485
-        return $subsection;
486
-    }
487
-
488
-
489
-
490
-    /**
491
-     * Gets the value of the specified input. Should be called after receive_form_submission()
492
-     * or populate_defaults() on the form, where the normalized value on the input is set.
493
-     *
494
-     * @param string $name
495
-     * @return mixed depending on the input's type and its normalization strategy
496
-     * @throws \EE_Error
497
-     */
498
-    public function get_input_value($name)
499
-    {
500
-        $input = $this->get_input($name);
501
-        return $input->normalized_value();
502
-    }
503
-
504
-
505
-
506
-    /**
507
-     * Checks if this form section itself is valid, and then checks its subsections
508
-     *
509
-     * @throws EE_Error
510
-     * @return boolean
511
-     */
512
-    public function is_valid()
513
-    {
514
-        if (! $this->has_received_submission()) {
515
-            throw new EE_Error(
516
-                sprintf(
517
-                    __(
518
-                        "You cannot check if a form is valid before receiving the form submission using receive_form_submission",
519
-                        "event_espresso"
520
-                    )
521
-                )
522
-            );
523
-        }
524
-        if (! parent::is_valid()) {
525
-            return false;
526
-        }
527
-        // ok so no general errors to this entire form section.
528
-        // so let's check the subsections, but only set errors if that hasn't been done yet
529
-        $set_submission_errors = $this->submission_error_message() === '' ? true : false;
530
-        foreach ($this->get_validatable_subsections() as $subsection) {
531
-            if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
532
-                if ($set_submission_errors) {
533
-                    $this->set_submission_error_message($subsection->get_validation_error_string());
534
-                }
535
-                return false;
536
-            }
537
-        }
538
-        return true;
539
-    }
540
-
541
-
542
-
543
-    /**
544
-     * gets teh default name of this form section if none is specified
545
-     *
546
-     * @return string
547
-     */
548
-    protected function _set_default_name_if_empty()
549
-    {
550
-        if (! $this->_name) {
551
-            $classname = get_class($this);
552
-            $default_name = str_replace("EE_", "", $classname);
553
-            $this->_name = $default_name;
554
-        }
555
-    }
556
-
557
-
558
-
559
-    /**
560
-     * Returns the HTML for the form, except for the form opening and closing tags
561
-     * (as the form section doesn't know where you necessarily want to send the information to),
562
-     * and except for a submit button. Enqueus JS and CSS; if called early enough we will
563
-     * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
564
-     * Not doing_it_wrong because theoretically this CAN be used properly,
565
-     * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
566
-     * any CSS.
567
-     *
568
-     * @throws \EE_Error
569
-     */
570
-    public function get_html_and_js()
571
-    {
572
-        $this->enqueue_js();
573
-        return $this->get_html();
574
-    }
575
-
576
-
577
-
578
-    /**
579
-     * returns HTML for displaying this form section. recursively calls display_section() on all subsections
580
-     *
581
-     * @param bool $display_previously_submitted_data
582
-     * @return string
583
-     */
584
-    public function get_html($display_previously_submitted_data = true)
585
-    {
586
-        $this->ensure_construct_finalized_called();
587
-        if ($display_previously_submitted_data) {
588
-            $this->populate_from_session();
589
-        }
590
-        return $this->_form_html_filter
591
-            ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
592
-            : $this->_layout_strategy->layout_form();
593
-    }
594
-
595
-
596
-
597
-    /**
598
-     * enqueues JS and CSS for the form.
599
-     * It is preferred to call this before wp_enqueue_scripts so the
600
-     * scripts and styles can be put in the header, but if called later
601
-     * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
602
-     * only be in the header; but in HTML5 its ok in the body.
603
-     * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
604
-     * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
605
-     *
606
-     * @return string
607
-     * @throws \EE_Error
608
-     */
609
-    public function enqueue_js()
610
-    {
611
-        $this->_enqueue_and_localize_form_js();
612
-        foreach ($this->subsections() as $subsection) {
613
-            $subsection->enqueue_js();
614
-        }
615
-    }
616
-
617
-
618
-
619
-    /**
620
-     * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
621
-     * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
622
-     * the wp_enqueue_scripts hook.
623
-     * However, registering the form js and localizing it can happen when we
624
-     * actually output the form (which is preferred, seeing how teh form's fields
625
-     * could change until it's actually outputted)
626
-     *
627
-     * @param boolean $init_form_validation_automatically whether or not we want the form validation
628
-     *                                                    to be triggered automatically or not
629
-     * @return void
630
-     */
631
-    public static function wp_enqueue_scripts($init_form_validation_automatically = true)
632
-    {
633
-        wp_register_script(
634
-            'ee_form_section_validation',
635
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
636
-            array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
637
-            EVENT_ESPRESSO_VERSION,
638
-            true
639
-        );
640
-        wp_localize_script(
641
-            'ee_form_section_validation',
642
-            'ee_form_section_validation_init',
643
-            array('init' => $init_form_validation_automatically ? '1' : '0')
644
-        );
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     * gets the variables used by form_section_validation.js.
651
-     * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
652
-     * but before the wordpress hook wp_loaded
653
-     *
654
-     * @throws \EE_Error
655
-     */
656
-    public function _enqueue_and_localize_form_js()
657
-    {
658
-        $this->ensure_construct_finalized_called();
659
-        //actually, we don't want to localize just yet. There may be other forms on the page.
660
-        //so we need to add our form section data to a static variable accessible by all form sections
661
-        //and localize it just before the footer
662
-        $this->localize_validation_rules();
663
-        add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
664
-        add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
665
-    }
666
-
667
-
668
-
669
-    /**
670
-     * add our form section data to a static variable accessible by all form sections
671
-     *
672
-     * @param bool $return_for_subsection
673
-     * @return void
674
-     * @throws \EE_Error
675
-     */
676
-    public function localize_validation_rules($return_for_subsection = false)
677
-    {
678
-        // we only want to localize vars ONCE for the entire form,
679
-        // so if the form section doesn't have a parent, then it must be the top dog
680
-        if ($return_for_subsection || ! $this->parent_section()) {
681
-            EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
682
-                'form_section_id'  => $this->html_id(true),
683
-                'validation_rules' => $this->get_jquery_validation_rules(),
684
-                'other_data'       => $this->get_other_js_data(),
685
-                'errors'           => $this->subsection_validation_errors_by_html_name(),
686
-            );
687
-            EE_Form_Section_Proper::$_scripts_localized = true;
688
-        }
689
-    }
690
-
691
-
692
-
693
-    /**
694
-     * Gets an array of extra data that will be useful for client-side javascript.
695
-     * This is primarily data added by inputs and forms in addition to any
696
-     * scripts they might enqueue
697
-     *
698
-     * @param array $form_other_js_data
699
-     * @return array
700
-     */
701
-    public function get_other_js_data($form_other_js_data = array())
702
-    {
703
-        foreach ($this->subsections() as $subsection) {
704
-            $form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
705
-        }
706
-        return $form_other_js_data;
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * Gets a flat array of inputs for this form section and its subsections.
713
-     * Keys are their form names, and values are the inputs themselves
714
-     *
715
-     * @return EE_Form_Input_Base
716
-     */
717
-    public function inputs_in_subsections()
718
-    {
719
-        $inputs = array();
720
-        foreach ($this->subsections() as $subsection) {
721
-            if ($subsection instanceof EE_Form_Input_Base) {
722
-                $inputs[$subsection->html_name()] = $subsection;
723
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
724
-                $inputs += $subsection->inputs_in_subsections();
725
-            }
726
-        }
727
-        return $inputs;
728
-    }
729
-
730
-
731
-
732
-    /**
733
-     * Gets a flat array of all the validation errors.
734
-     * Keys are html names (because those should be unique)
735
-     * and values are a string of all their validation errors
736
-     *
737
-     * @return string[]
738
-     */
739
-    public function subsection_validation_errors_by_html_name()
740
-    {
741
-        $inputs = $this->inputs();
742
-        $errors = array();
743
-        foreach ($inputs as $form_input) {
744
-            if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
745
-                $errors[$form_input->html_name()] = $form_input->get_validation_error_string();
746
-            }
747
-        }
748
-        return $errors;
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
755
-     * Should be setup by each form during the _enqueues_and_localize_form_js
756
-     */
757
-    public static function localize_script_for_all_forms()
758
-    {
759
-        //allow inputs and stuff to hook in their JS and stuff here
760
-        do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
761
-        EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
762
-        $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
763
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
764
-            : 'wp_default';
765
-        EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
766
-        wp_enqueue_script('ee_form_section_validation');
767
-        wp_localize_script(
768
-            'ee_form_section_validation',
769
-            'ee_form_section_vars',
770
-            EE_Form_Section_Proper::$_js_localization
771
-        );
772
-    }
773
-
774
-
775
-
776
-    /**
777
-     * ensure_scripts_localized
778
-     */
779
-    public function ensure_scripts_localized()
780
-    {
781
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
782
-            $this->_enqueue_and_localize_form_js();
783
-        }
784
-    }
785
-
786
-
787
-
788
-    /**
789
-     * Gets the hard-coded validation error messages to be used in the JS. The convention
790
-     * is that the key here should be the same as the custom validation rule put in the JS file
791
-     *
792
-     * @return array keys are custom validation rules, and values are internationalized strings
793
-     */
794
-    private static function _get_localized_error_messages()
795
-    {
796
-        return array(
797
-            'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"),
798
-            'regex'    => __('Please check your input', 'event_espresso'),
799
-        );
800
-    }
801
-
802
-
803
-
804
-    /**
805
-     * @return array
806
-     */
807
-    public static function js_localization()
808
-    {
809
-        return self::$_js_localization;
810
-    }
811
-
812
-
813
-
814
-    /**
815
-     * @return array
816
-     */
817
-    public static function reset_js_localization()
818
-    {
819
-        self::$_js_localization = array();
820
-    }
821
-
822
-
823
-
824
-    /**
825
-     * Gets the JS to put inside the jquery validation rules for subsection of this form section.
826
-     * See parent function for more...
827
-     *
828
-     * @return array
829
-     */
830
-    public function get_jquery_validation_rules()
831
-    {
832
-        $jquery_validation_rules = array();
833
-        foreach ($this->get_validatable_subsections() as $subsection) {
834
-            $jquery_validation_rules = array_merge(
835
-                $jquery_validation_rules,
836
-                $subsection->get_jquery_validation_rules()
837
-            );
838
-        }
839
-        return $jquery_validation_rules;
840
-    }
841
-
842
-
843
-
844
-    /**
845
-     * Sanitizes all the data and sets the sanitized value of each field
846
-     *
847
-     * @param array $req_data like $_POST
848
-     * @return void
849
-     */
850
-    protected function _normalize($req_data)
851
-    {
852
-        $this->_received_submission = true;
853
-        $this->_validation_errors = array();
854
-        foreach ($this->get_validatable_subsections() as $subsection) {
855
-            try {
856
-                $subsection->_normalize($req_data);
857
-            } catch (EE_Validation_Error $e) {
858
-                $subsection->add_validation_error($e);
859
-            }
860
-        }
861
-    }
862
-
863
-
864
-
865
-    /**
866
-     * Performs validation on this form section and its subsections.
867
-     * For each subsection,
868
-     * calls _validate_{subsection_name} on THIS form (if the function exists)
869
-     * and passes it the subsection, then calls _validate on that subsection.
870
-     * If you need to perform validation on the form as a whole (considering multiple)
871
-     * you would be best to override this _validate method,
872
-     * calling parent::_validate() first.
873
-     */
874
-    protected function _validate()
875
-    {
876
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
877
-            if (method_exists($this, '_validate_' . $subsection_name)) {
878
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
879
-            }
880
-            $subsection->_validate();
881
-        }
882
-    }
883
-
884
-
885
-
886
-    /**
887
-     * Gets all the validated inputs for the form section
888
-     *
889
-     * @return array
890
-     */
891
-    public function valid_data()
892
-    {
893
-        $inputs = array();
894
-        foreach ($this->subsections() as $subsection_name => $subsection) {
895
-            if ($subsection instanceof EE_Form_Section_Proper) {
896
-                $inputs[$subsection_name] = $subsection->valid_data();
897
-            } else if ($subsection instanceof EE_Form_Input_Base) {
898
-                $inputs[$subsection_name] = $subsection->normalized_value();
899
-            }
900
-        }
901
-        return $inputs;
902
-    }
903
-
904
-
905
-
906
-    /**
907
-     * Gets all the inputs on this form section
908
-     *
909
-     * @return EE_Form_Input_Base[]
910
-     */
911
-    public function inputs()
912
-    {
913
-        $inputs = array();
914
-        foreach ($this->subsections() as $subsection_name => $subsection) {
915
-            if ($subsection instanceof EE_Form_Input_Base) {
916
-                $inputs[$subsection_name] = $subsection;
917
-            }
918
-        }
919
-        return $inputs;
920
-    }
921
-
922
-
923
-
924
-    /**
925
-     * Gets all the subsections which are a proper form
926
-     *
927
-     * @return EE_Form_Section_Proper[]
928
-     */
929
-    public function subforms()
930
-    {
931
-        $form_sections = array();
932
-        foreach ($this->subsections() as $name => $obj) {
933
-            if ($obj instanceof EE_Form_Section_Proper) {
934
-                $form_sections[$name] = $obj;
935
-            }
936
-        }
937
-        return $form_sections;
938
-    }
939
-
940
-
941
-
942
-    /**
943
-     * Gets all the subsections (inputs, proper subsections, or html-only sections).
944
-     * Consider using inputs() or subforms()
945
-     * if you only want form inputs or proper form sections.
946
-     *
947
-     * @param boolean $require_construction_to_be_finalized most client code should
948
-     *                                                      leave this as TRUE so that the inputs will be properly
949
-     *                                                      configured. However, some client code may be ok with
950
-     *                                                      construction finalize being called later
951
-     *                                                      (realizing that the subsections' html names might not be
952
-     *                                                      set yet, etc.)
953
-     * @return EE_Form_Section_Proper[]
954
-     */
955
-    public function subsections($require_construction_to_be_finalized = true)
956
-    {
957
-        if ($require_construction_to_be_finalized) {
958
-            $this->ensure_construct_finalized_called();
959
-        }
960
-        return $this->_subsections;
961
-    }
962
-
963
-
964
-
965
-    /**
966
-     * Returns a simple array where keys are input names, and values are their normalized
967
-     * values. (Similar to calling get_input_value on inputs)
968
-     *
969
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
970
-     *                                        or just this forms' direct children inputs
971
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
972
-     *                                        or allow multidimensional array
973
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
974
-     *                                        with array keys being input names
975
-     *                                        (regardless of whether they are from a subsection or not),
976
-     *                                        and if $flatten is FALSE it can be a multidimensional array
977
-     *                                        where keys are always subsection names and values are either
978
-     *                                        the input's normalized value, or an array like the top-level array
979
-     */
980
-    public function input_values($include_subform_inputs = false, $flatten = false)
981
-    {
982
-        return $this->_input_values(false, $include_subform_inputs, $flatten);
983
-    }
984
-
985
-
986
-
987
-    /**
988
-     * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
989
-     * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
990
-     * is not necessarily the value we want to display to users. This creates an array
991
-     * where keys are the input names, and values are their display values
992
-     *
993
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
994
-     *                                        or just this forms' direct children inputs
995
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
996
-     *                                        or allow multidimensional array
997
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
998
-     *                                        with array keys being input names
999
-     *                                        (regardless of whether they are from a subsection or not),
1000
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1001
-     *                                        where keys are always subsection names and values are either
1002
-     *                                        the input's normalized value, or an array like the top-level array
1003
-     */
1004
-    public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1005
-    {
1006
-        return $this->_input_values(true, $include_subform_inputs, $flatten);
1007
-    }
1008
-
1009
-
1010
-
1011
-    /**
1012
-     * Gets the input values from the form
1013
-     *
1014
-     * @param boolean $pretty                 Whether to retrieve the pretty value,
1015
-     *                                        or just the normalized value
1016
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1017
-     *                                        or just this forms' direct children inputs
1018
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1019
-     *                                        or allow multidimensional array
1020
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1021
-     *                                        input names (regardless of whether they are from a subsection or not),
1022
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1023
-     *                                        where keys are always subsection names and values are either
1024
-     *                                        the input's normalized value, or an array like the top-level array
1025
-     */
1026
-    public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1027
-    {
1028
-        $input_values = array();
1029
-        foreach ($this->subsections() as $subsection_name => $subsection) {
1030
-            if ($subsection instanceof EE_Form_Input_Base) {
1031
-                $input_values[$subsection_name] = $pretty
1032
-                    ? $subsection->pretty_value()
1033
-                    : $subsection->normalized_value();
1034
-            } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1035
-                $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten);
1036
-                if ($flatten) {
1037
-                    $input_values = array_merge($input_values, $subform_input_values);
1038
-                } else {
1039
-                    $input_values[$subsection_name] = $subform_input_values;
1040
-                }
1041
-            }
1042
-        }
1043
-        return $input_values;
1044
-    }
1045
-
1046
-
1047
-
1048
-    /**
1049
-     * Gets the originally submitted input values from the form
1050
-     *
1051
-     * @param boolean $include_subforms  Whether to include inputs from subforms,
1052
-     *                                   or just this forms' direct children inputs
1053
-     * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1054
-     *                                   with array keys being input names
1055
-     *                                   (regardless of whether they are from a subsection or not),
1056
-     *                                   and if $flatten is FALSE it can be a multidimensional array
1057
-     *                                   where keys are always subsection names and values are either
1058
-     *                                   the input's normalized value, or an array like the top-level array
1059
-     */
1060
-    public function submitted_values($include_subforms = false)
1061
-    {
1062
-        $submitted_values = array();
1063
-        foreach ($this->subsections() as $subsection) {
1064
-            if ($subsection instanceof EE_Form_Input_Base) {
1065
-                // is this input part of an array of inputs?
1066
-                if (strpos($subsection->html_name(), '[') !== false) {
1067
-                    $full_input_name = \EEH_Array::convert_array_values_to_keys(
1068
-                        explode('[', str_replace(']', '', $subsection->html_name())),
1069
-                        $subsection->raw_value()
1070
-                    );
1071
-                    $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1072
-                } else {
1073
-                    $submitted_values[$subsection->html_name()] = $subsection->raw_value();
1074
-                }
1075
-            } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1076
-                $subform_input_values = $subsection->submitted_values($include_subforms);
1077
-                $submitted_values = array_replace_recursive($submitted_values, $subform_input_values);
1078
-            }
1079
-        }
1080
-        return $submitted_values;
1081
-    }
1082
-
1083
-
1084
-
1085
-    /**
1086
-     * Indicates whether or not this form has received a submission yet
1087
-     * (ie, had receive_form_submission called on it yet)
1088
-     *
1089
-     * @return boolean
1090
-     * @throws \EE_Error
1091
-     */
1092
-    public function has_received_submission()
1093
-    {
1094
-        $this->ensure_construct_finalized_called();
1095
-        return $this->_received_submission;
1096
-    }
1097
-
1098
-
1099
-
1100
-    /**
1101
-     * Equivalent to passing 'exclude' in the constructor's options array.
1102
-     * Removes the listed inputs from the form
1103
-     *
1104
-     * @param array $inputs_to_exclude values are the input names
1105
-     * @return void
1106
-     */
1107
-    public function exclude(array $inputs_to_exclude = array())
1108
-    {
1109
-        foreach ($inputs_to_exclude as $input_to_exclude_name) {
1110
-            unset($this->_subsections[$input_to_exclude_name]);
1111
-        }
1112
-    }
1113
-
1114
-
1115
-
1116
-    /**
1117
-     * @param array $inputs_to_hide
1118
-     * @throws \EE_Error
1119
-     */
1120
-    public function hide(array $inputs_to_hide = array())
1121
-    {
1122
-        foreach ($inputs_to_hide as $input_to_hide) {
1123
-            $input = $this->get_input($input_to_hide);
1124
-            $input->set_display_strategy(new EE_Hidden_Display_Strategy());
1125
-        }
1126
-    }
1127
-
1128
-
1129
-
1130
-    /**
1131
-     * add_subsections
1132
-     * Adds the listed subsections to the form section.
1133
-     * If $subsection_name_to_target is provided,
1134
-     * then new subsections are added before or after that subsection,
1135
-     * otherwise to the start or end of the entire subsections array.
1136
-     *
1137
-     * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1138
-     *                                                          where keys are their names
1139
-     * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1140
-     *                                                          should be added before or after
1141
-     *                                                          IF $subsection_name_to_target is null,
1142
-     *                                                          then $new_subsections will be added to
1143
-     *                                                          the beginning or end of the entire subsections array
1144
-     * @param boolean                $add_before                whether to add $new_subsections, before or after
1145
-     *                                                          $subsection_name_to_target,
1146
-     *                                                          or if $subsection_name_to_target is null,
1147
-     *                                                          before or after entire subsections array
1148
-     * @return void
1149
-     * @throws \EE_Error
1150
-     */
1151
-    public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1152
-    {
1153
-        foreach ($new_subsections as $subsection_name => $subsection) {
1154
-            if (! $subsection instanceof EE_Form_Section_Base) {
1155
-                EE_Error::add_error(
1156
-                    sprintf(
1157
-                        __(
1158
-                            "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1159
-                            "event_espresso"
1160
-                        ),
1161
-                        get_class($subsection),
1162
-                        $subsection_name,
1163
-                        $this->name()
1164
-                    )
1165
-                );
1166
-                unset($new_subsections[$subsection_name]);
1167
-            }
1168
-        }
1169
-        $this->_subsections = EEH_Array::insert_into_array(
1170
-            $this->_subsections,
1171
-            $new_subsections,
1172
-            $subsection_name_to_target,
1173
-            $add_before
1174
-        );
1175
-        if ($this->_construction_finalized) {
1176
-            foreach ($this->_subsections as $name => $subsection) {
1177
-                $subsection->_construct_finalize($this, $name);
1178
-            }
1179
-        }
1180
-    }
1181
-
1182
-
1183
-
1184
-    /**
1185
-     * Just gets all validatable subsections to clean their sensitive data
1186
-     */
1187
-    public function clean_sensitive_data()
1188
-    {
1189
-        foreach ($this->get_validatable_subsections() as $subsection) {
1190
-            $subsection->clean_sensitive_data();
1191
-        }
1192
-    }
1193
-
1194
-
1195
-
1196
-    /**
1197
-     * @param string $form_submission_error_message
1198
-     */
1199
-    public function set_submission_error_message($form_submission_error_message = '')
1200
-    {
1201
-        $this->_form_submission_error_message .= ! empty($form_submission_error_message)
1202
-            ? $form_submission_error_message
1203
-            : __('Form submission failed due to errors', 'event_espresso');
1204
-    }
1205
-
1206
-
1207
-
1208
-    /**
1209
-     * @return string
1210
-     */
1211
-    public function submission_error_message()
1212
-    {
1213
-        return $this->_form_submission_error_message;
1214
-    }
1215
-
1216
-
1217
-
1218
-    /**
1219
-     * @param string $form_submission_success_message
1220
-     */
1221
-    public function set_submission_success_message($form_submission_success_message)
1222
-    {
1223
-        $this->_form_submission_success_message .= ! empty($form_submission_success_message)
1224
-            ? $form_submission_success_message
1225
-            : __('Form submitted successfully', 'event_espresso');
1226
-    }
1227
-
1228
-
1229
-
1230
-    /**
1231
-     * @return string
1232
-     */
1233
-    public function submission_success_message()
1234
-    {
1235
-        return $this->_form_submission_success_message;
1236
-    }
1237
-
1238
-
1239
-
1240
-    /**
1241
-     * Returns the prefix that should be used on child of this form section for
1242
-     * their html names. If this form section itself has a parent, prepends ITS
1243
-     * prefix onto this form section's prefix. Used primarily by
1244
-     * EE_Form_Input_Base::_set_default_html_name_if_empty
1245
-     *
1246
-     * @return string
1247
-     * @throws \EE_Error
1248
-     */
1249
-    public function html_name_prefix()
1250
-    {
1251
-        if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1252
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1253
-        } else {
1254
-            return $this->name();
1255
-        }
1256
-    }
1257
-
1258
-
1259
-
1260
-    /**
1261
-     * Gets the name, but first checks _construct_finalize has been called. If not,
1262
-     * calls it (assumes there is no parent and that we want the name to be whatever
1263
-     * was set, which is probably nothing, or the classname)
1264
-     *
1265
-     * @return string
1266
-     * @throws \EE_Error
1267
-     */
1268
-    public function name()
1269
-    {
1270
-        $this->ensure_construct_finalized_called();
1271
-        return parent::name();
1272
-    }
1273
-
1274
-
1275
-
1276
-    /**
1277
-     * @return EE_Form_Section_Proper
1278
-     * @throws \EE_Error
1279
-     */
1280
-    public function parent_section()
1281
-    {
1282
-        $this->ensure_construct_finalized_called();
1283
-        return parent::parent_section();
1284
-    }
1285
-
1286
-
1287
-
1288
-    /**
1289
-     * make sure construction finalized was called, otherwise children might not be ready
1290
-     *
1291
-     * @return void
1292
-     * @throws \EE_Error
1293
-     */
1294
-    public function ensure_construct_finalized_called()
1295
-    {
1296
-        if (! $this->_construction_finalized) {
1297
-            $this->_construct_finalize($this->_parent_section, $this->_name);
1298
-        }
1299
-    }
1300
-
1301
-
1302
-
1303
-    /**
1304
-     * Checks if any of this form section's inputs, or any of its children's inputs,
1305
-     * are in teh form data. If any are found, returns true. Else false
1306
-     *
1307
-     * @param array $req_data
1308
-     * @return boolean
1309
-     */
1310
-    public function form_data_present_in($req_data = null)
1311
-    {
1312
-        if ($req_data === null) {
1313
-            $req_data = $_POST;
1314
-        }
1315
-        foreach ($this->subsections() as $subsection) {
1316
-            if ($subsection instanceof EE_Form_Input_Base) {
1317
-                if ($subsection->form_data_present_in($req_data)) {
1318
-                    return true;
1319
-                }
1320
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
1321
-                if ($subsection->form_data_present_in($req_data)) {
1322
-                    return true;
1323
-                }
1324
-            }
1325
-        }
1326
-        return false;
1327
-    }
1328
-
1329
-
1330
-
1331
-    /**
1332
-     * Gets validation errors for this form section and subsections
1333
-     * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1334
-     * gets the validation errors for ALL subsection
1335
-     *
1336
-     * @return EE_Validation_Error[]
1337
-     */
1338
-    public function get_validation_errors_accumulated()
1339
-    {
1340
-        $validation_errors = $this->get_validation_errors();
1341
-        foreach ($this->get_validatable_subsections() as $subsection) {
1342
-            if ($subsection instanceof EE_Form_Section_Proper) {
1343
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1344
-            } else {
1345
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors();
1346
-            }
1347
-            if ($validation_errors_on_this_subsection) {
1348
-                $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1349
-            }
1350
-        }
1351
-        return $validation_errors;
1352
-    }
1353
-
1354
-
1355
-
1356
-    /**
1357
-     * This isn't just the name of an input, it's a path pointing to an input. The
1358
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
1359
-     * dot-dot-slash (../) means to ascend into the parent section.
1360
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1361
-     * which will be returned.
1362
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1363
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1364
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1365
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1366
-     * Etc
1367
-     *
1368
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1369
-     * @return EE_Form_Section_Base
1370
-     */
1371
-    public function find_section_from_path($form_section_path)
1372
-    {
1373
-        //check if we can find the input from purely going straight up the tree
1374
-        $input = parent::find_section_from_path($form_section_path);
1375
-        if ($input instanceof EE_Form_Section_Base) {
1376
-            return $input;
1377
-        }
1378
-        $next_slash_pos = strpos($form_section_path, '/');
1379
-        if ($next_slash_pos !== false) {
1380
-            $child_section_name = substr($form_section_path, 0, $next_slash_pos);
1381
-            $subpath = substr($form_section_path, $next_slash_pos + 1);
1382
-        } else {
1383
-            $child_section_name = $form_section_path;
1384
-            $subpath = '';
1385
-        }
1386
-        $child_section = $this->get_subsection($child_section_name);
1387
-        if ($child_section instanceof EE_Form_Section_Base) {
1388
-            return $child_section->find_section_from_path($subpath);
1389
-        } else {
1390
-            return null;
1391
-        }
1392
-    }
14
+	const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
15
+
16
+	/**
17
+	 * Subsections
18
+	 *
19
+	 * @var EE_Form_Section_Validatable[]
20
+	 */
21
+	protected $_subsections = array();
22
+
23
+	/**
24
+	 * Strategy for laying out the form
25
+	 *
26
+	 * @var EE_Form_Section_Layout_Base
27
+	 */
28
+	protected $_layout_strategy;
29
+
30
+	/**
31
+	 * Whether or not this form has received and validated a form submission yet
32
+	 *
33
+	 * @var boolean
34
+	 */
35
+	protected $_received_submission = false;
36
+
37
+	/**
38
+	 * message displayed to users upon successful form submission
39
+	 *
40
+	 * @var string
41
+	 */
42
+	protected $_form_submission_success_message = '';
43
+
44
+	/**
45
+	 * message displayed to users upon unsuccessful form submission
46
+	 *
47
+	 * @var string
48
+	 */
49
+	protected $_form_submission_error_message = '';
50
+
51
+	/**
52
+	 * Stores all the data that will localized for form validation
53
+	 *
54
+	 * @var array
55
+	 */
56
+	static protected $_js_localization = array();
57
+
58
+	/**
59
+	 * whether or not the form's localized validation JS vars have been set
60
+	 *
61
+	 * @type boolean
62
+	 */
63
+	static protected $_scripts_localized = false;
64
+
65
+
66
+
67
+	/**
68
+	 * when constructing a proper form section, calls _construct_finalize on children
69
+	 * so that they know who their parent is, and what name they've been given.
70
+	 *
71
+	 * @param array $options_array   {
72
+	 * @type        $subsections     EE_Form_Section_Validatable[] where keys are the section's name
73
+	 * @type        $include         string[] numerically-indexed where values are section names to be included,
74
+	 *                               and in that order. This is handy if you want
75
+	 *                               the subsections to be ordered differently than the default, and if you override
76
+	 *                               which fields are shown
77
+	 * @type        $exclude         string[] values are subsections to be excluded. This is handy if you want
78
+	 *                               to remove certain default subsections (note: if you specify BOTH 'include' AND
79
+	 *                               'exclude', the inclusions will be applied first, and the exclusions will exclude
80
+	 *                               items from that list of inclusions)
81
+	 * @type        $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
82
+	 *                               } @see EE_Form_Section_Validatable::__construct()
83
+	 * @throws \EE_Error
84
+	 */
85
+	public function __construct($options_array = array())
86
+	{
87
+		$options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
88
+			$this);
89
+		//call parent first, as it may be setting the name
90
+		parent::__construct($options_array);
91
+		//if they've included subsections in the constructor, add them now
92
+		if (isset($options_array['include'])) {
93
+			//we are going to make sure we ONLY have those subsections to include
94
+			//AND we are going to make sure they're in that specified order
95
+			$reordered_subsections = array();
96
+			foreach ($options_array['include'] as $input_name) {
97
+				if (isset($this->_subsections[$input_name])) {
98
+					$reordered_subsections[$input_name] = $this->_subsections[$input_name];
99
+				}
100
+			}
101
+			$this->_subsections = $reordered_subsections;
102
+		}
103
+		if (isset($options_array['exclude'])) {
104
+			$exclude = $options_array['exclude'];
105
+			$this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
106
+		}
107
+		if (isset($options_array['layout_strategy'])) {
108
+			$this->_layout_strategy = $options_array['layout_strategy'];
109
+		}
110
+		if (! $this->_layout_strategy) {
111
+			$this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
112
+		}
113
+		$this->_layout_strategy->_construct_finalize($this);
114
+		//ok so we are definitely going to want the forms JS,
115
+		//so enqueue it or remember to enqueue it during wp_enqueue_scripts
116
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
117
+			//ok so they've constructed this object after when they should have.
118
+			//just enqueue the generic form scripts and initialize the form immediately in the JS
119
+			\EE_Form_Section_Proper::wp_enqueue_scripts(true);
120
+		} else {
121
+			add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
122
+			add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
123
+		}
124
+		add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
125
+
126
+		/**
127
+		 * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't
128
+		 * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to
129
+		 * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
130
+		 * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
131
+		 * @since 4.9.32
132
+		 * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling
133
+		 *                                      _construct_finalize has been done
134
+		 * @param array $options_array options passed into the constructor
135
+		 */
136
+		do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array);
137
+
138
+		if (isset($options_array['name'])) {
139
+			$this->_construct_finalize(null, $options_array['name']);
140
+		}
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * Finishes construction given the parent form section and this form section's name
147
+	 *
148
+	 * @param EE_Form_Section_Proper $parent_form_section
149
+	 * @param string                 $name
150
+	 * @throws \EE_Error
151
+	 */
152
+	public function _construct_finalize($parent_form_section, $name)
153
+	{
154
+		parent::_construct_finalize($parent_form_section, $name);
155
+		$this->_set_default_name_if_empty();
156
+		$this->_set_default_html_id_if_empty();
157
+		foreach ($this->_subsections as $subsection_name => $subsection) {
158
+			if ($subsection instanceof EE_Form_Section_Base) {
159
+				$subsection->_construct_finalize($this, $subsection_name);
160
+			} else {
161
+				throw new EE_Error(
162
+					sprintf(
163
+						__('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
164
+							'event_espresso'),
165
+						$subsection_name,
166
+						get_class($this),
167
+						$subsection ? get_class($subsection) : __('NULL', 'event_espresso')
168
+					)
169
+				);
170
+			}
171
+		}
172
+		/**
173
+		 * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
174
+		 * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived
175
+		 * from the name like the HTML label id, etc), this is where it should be done.
176
+		 * This might only happen just before displaying the form, or just before it receives form submission data.
177
+		 * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
178
+		 * ensured it has a name, HTML IDs, etc
179
+		 * @param EE_Form_Section_Proper $this
180
+		 * @param EE_Form_Section_Proper|null $parent_form_section
181
+		 * @param string $name
182
+		 */
183
+		do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * Gets the layout strategy for this form section
190
+	 *
191
+	 * @return EE_Form_Section_Layout_Base
192
+	 */
193
+	public function get_layout_strategy()
194
+	{
195
+		return $this->_layout_strategy;
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * Gets the HTML for a single input for this form section according
202
+	 * to the layout strategy
203
+	 *
204
+	 * @param EE_Form_Input_Base $input
205
+	 * @return string
206
+	 */
207
+	public function get_html_for_input($input)
208
+	{
209
+		return $this->_layout_strategy->layout_input($input);
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * was_submitted - checks if form inputs are present in request data
216
+	 * Basically an alias for form_data_present_in() (which is used by both
217
+	 * proper form sections and form inputs)
218
+	 *
219
+	 * @param null $form_data
220
+	 * @return boolean
221
+	 */
222
+	public function was_submitted($form_data = null)
223
+	{
224
+		return $this->form_data_present_in($form_data);
225
+	}
226
+
227
+
228
+
229
+	/**
230
+	 * After the form section is initially created, call this to sanitize the data in the submission
231
+	 * which relates to this form section, validate it, and set it as properties on the form.
232
+	 *
233
+	 * @param array|null $req_data should usually be $_POST (the default).
234
+	 *                             However, you CAN supply a different array.
235
+	 *                             Consider using set_defaults() instead however.
236
+	 *                             (If you rendered the form in the page using echo $form_x->get_html()
237
+	 *                             the inputs will have the correct name in the request data for this function
238
+	 *                             to find them and populate the form with them.
239
+	 *                             If you have a flat form (with only input subsections),
240
+	 *                             you can supply a flat array where keys
241
+	 *                             are the form input names and values are their values)
242
+	 * @param boolean    $validate whether or not to perform validation on this data. Default is,
243
+	 *                             of course, to validate that data, and set errors on the invalid values.
244
+	 *                             But if the data has already been validated
245
+	 *                             (eg you validated the data then stored it in the DB)
246
+	 *                             you may want to skip this step.
247
+	 */
248
+	public function receive_form_submission($req_data = null, $validate = true)
249
+	{
250
+		$req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this,
251
+			$validate);
252
+		if ($req_data === null) {
253
+			$req_data = array_merge($_GET, $_POST);
254
+		}
255
+		$req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data,
256
+			$this);
257
+		$this->_normalize($req_data);
258
+		if ($validate) {
259
+			$this->_validate();
260
+			//if it's invalid, we're going to want to re-display so remember what they submitted
261
+			if (! $this->is_valid()) {
262
+				$this->store_submitted_form_data_in_session();
263
+			}
264
+		}
265
+		do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate);
266
+	}
267
+
268
+
269
+
270
+	/**
271
+	 * caches the originally submitted input values in the session
272
+	 * so that they can be used to repopulate the form if it failed validation
273
+	 *
274
+	 * @return boolean whether or not the data was successfully stored in the session
275
+	 */
276
+	protected function store_submitted_form_data_in_session()
277
+	{
278
+		return EE_Registry::instance()->SSN->set_session_data(
279
+			array(
280
+				\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
281
+			)
282
+		);
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * retrieves the originally submitted input values in the session
289
+	 * so that they can be used to repopulate the form if it failed validation
290
+	 *
291
+	 * @return array
292
+	 */
293
+	protected function get_submitted_form_data_from_session()
294
+	{
295
+		$session = EE_Registry::instance()->SSN;
296
+		if ($session instanceof EE_Session) {
297
+			return $session->get_session_data(
298
+				\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
299
+			);
300
+		} else {
301
+			return array();
302
+		}
303
+	}
304
+
305
+
306
+
307
+	/**
308
+	 * flushed the originally submitted input values from the session
309
+	 *
310
+	 * @return boolean whether or not the data was successfully removed from the session
311
+	 */
312
+	protected function flush_submitted_form_data_from_session()
313
+	{
314
+		return EE_Registry::instance()->SSN->reset_data(
315
+			array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
316
+		);
317
+	}
318
+
319
+
320
+
321
+	/**
322
+	 * Populates this form and its subsections with data from the session.
323
+	 * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
324
+	 * validation errors when displaying too)
325
+	 * Returns true if the form was populated from the session, false otherwise
326
+	 *
327
+	 * @return boolean
328
+	 */
329
+	public function populate_from_session()
330
+	{
331
+		$form_data_in_session = $this->get_submitted_form_data_from_session();
332
+		if (empty($form_data_in_session)) {
333
+			return false;
334
+		}
335
+		$this->receive_form_submission($form_data_in_session);
336
+		$this->flush_submitted_form_data_from_session();
337
+		if ($this->form_data_present_in($form_data_in_session)) {
338
+			return true;
339
+		} else {
340
+			return false;
341
+		}
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * Populates the default data for the form, given an array where keys are
348
+	 * the input names, and values are their values (preferably normalized to be their
349
+	 * proper PHP types, not all strings... although that should be ok too).
350
+	 * Proper subsections are sub-arrays, the key being the subsection's name, and
351
+	 * the value being an array formatted in teh same way
352
+	 *
353
+	 * @param array $default_data
354
+	 */
355
+	public function populate_defaults($default_data)
356
+	{
357
+		foreach ($this->subsections(false) as $subsection_name => $subsection) {
358
+			if (isset($default_data[$subsection_name])) {
359
+				if ($subsection instanceof EE_Form_Input_Base) {
360
+					$subsection->set_default($default_data[$subsection_name]);
361
+				} elseif ($subsection instanceof EE_Form_Section_Proper) {
362
+					$subsection->populate_defaults($default_data[$subsection_name]);
363
+				}
364
+			}
365
+		}
366
+	}
367
+
368
+
369
+
370
+	/**
371
+	 * returns true if subsection exists
372
+	 *
373
+	 * @param string $name
374
+	 * @return boolean
375
+	 */
376
+	public function subsection_exists($name)
377
+	{
378
+		return isset($this->_subsections[$name]) ? true : false;
379
+	}
380
+
381
+
382
+
383
+	/**
384
+	 * Gets the subsection specified by its name
385
+	 *
386
+	 * @param string  $name
387
+	 * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
388
+	 *                                                      so that the inputs will be properly configured.
389
+	 *                                                      However, some client code may be ok
390
+	 *                                                      with construction finalize being called later
391
+	 *                                                      (realizing that the subsections' html names
392
+	 *                                                      might not be set yet, etc.)
393
+	 * @return EE_Form_Section_Base
394
+	 * @throws \EE_Error
395
+	 */
396
+	public function get_subsection($name, $require_construction_to_be_finalized = true)
397
+	{
398
+		if ($require_construction_to_be_finalized) {
399
+			$this->ensure_construct_finalized_called();
400
+		}
401
+		return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 * Gets all the validatable subsections of this form section
408
+	 *
409
+	 * @return EE_Form_Section_Validatable[]
410
+	 */
411
+	public function get_validatable_subsections()
412
+	{
413
+		$validatable_subsections = array();
414
+		foreach ($this->subsections() as $name => $obj) {
415
+			if ($obj instanceof EE_Form_Section_Validatable) {
416
+				$validatable_subsections[$name] = $obj;
417
+			}
418
+		}
419
+		return $validatable_subsections;
420
+	}
421
+
422
+
423
+
424
+	/**
425
+	 * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
426
+	 * throw an EE_Error.
427
+	 *
428
+	 * @param string  $name
429
+	 * @param boolean $require_construction_to_be_finalized most client code should
430
+	 *                                                      leave this as TRUE so that the inputs will be properly
431
+	 *                                                      configured. However, some client code may be ok with
432
+	 *                                                      construction finalize being called later
433
+	 *                                                      (realizing that the subsections' html names might not be
434
+	 *                                                      set yet, etc.)
435
+	 * @return EE_Form_Input_Base
436
+	 * @throws EE_Error
437
+	 */
438
+	public function get_input($name, $require_construction_to_be_finalized = true)
439
+	{
440
+		$subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
441
+		if (! $subsection instanceof EE_Form_Input_Base) {
442
+			throw new EE_Error(
443
+				sprintf(
444
+					__(
445
+						"Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
446
+						'event_espresso'
447
+					),
448
+					$name,
449
+					get_class($this),
450
+					$subsection ? get_class($subsection) : __("NULL", 'event_espresso')
451
+				)
452
+			);
453
+		}
454
+		return $subsection;
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * Like get_input(), gets the proper subsection of the form given the name,
461
+	 * otherwise throws an EE_Error
462
+	 *
463
+	 * @param string  $name
464
+	 * @param boolean $require_construction_to_be_finalized most client code should
465
+	 *                                                      leave this as TRUE so that the inputs will be properly
466
+	 *                                                      configured. However, some client code may be ok with
467
+	 *                                                      construction finalize being called later
468
+	 *                                                      (realizing that the subsections' html names might not be
469
+	 *                                                      set yet, etc.)
470
+	 * @return EE_Form_Section_Proper
471
+	 * @throws EE_Error
472
+	 */
473
+	public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
474
+	{
475
+		$subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
476
+		if (! $subsection instanceof EE_Form_Section_Proper) {
477
+			throw new EE_Error(
478
+				sprintf(
479
+					__("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
480
+					$name,
481
+					get_class($this)
482
+				)
483
+			);
484
+		}
485
+		return $subsection;
486
+	}
487
+
488
+
489
+
490
+	/**
491
+	 * Gets the value of the specified input. Should be called after receive_form_submission()
492
+	 * or populate_defaults() on the form, where the normalized value on the input is set.
493
+	 *
494
+	 * @param string $name
495
+	 * @return mixed depending on the input's type and its normalization strategy
496
+	 * @throws \EE_Error
497
+	 */
498
+	public function get_input_value($name)
499
+	{
500
+		$input = $this->get_input($name);
501
+		return $input->normalized_value();
502
+	}
503
+
504
+
505
+
506
+	/**
507
+	 * Checks if this form section itself is valid, and then checks its subsections
508
+	 *
509
+	 * @throws EE_Error
510
+	 * @return boolean
511
+	 */
512
+	public function is_valid()
513
+	{
514
+		if (! $this->has_received_submission()) {
515
+			throw new EE_Error(
516
+				sprintf(
517
+					__(
518
+						"You cannot check if a form is valid before receiving the form submission using receive_form_submission",
519
+						"event_espresso"
520
+					)
521
+				)
522
+			);
523
+		}
524
+		if (! parent::is_valid()) {
525
+			return false;
526
+		}
527
+		// ok so no general errors to this entire form section.
528
+		// so let's check the subsections, but only set errors if that hasn't been done yet
529
+		$set_submission_errors = $this->submission_error_message() === '' ? true : false;
530
+		foreach ($this->get_validatable_subsections() as $subsection) {
531
+			if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
532
+				if ($set_submission_errors) {
533
+					$this->set_submission_error_message($subsection->get_validation_error_string());
534
+				}
535
+				return false;
536
+			}
537
+		}
538
+		return true;
539
+	}
540
+
541
+
542
+
543
+	/**
544
+	 * gets teh default name of this form section if none is specified
545
+	 *
546
+	 * @return string
547
+	 */
548
+	protected function _set_default_name_if_empty()
549
+	{
550
+		if (! $this->_name) {
551
+			$classname = get_class($this);
552
+			$default_name = str_replace("EE_", "", $classname);
553
+			$this->_name = $default_name;
554
+		}
555
+	}
556
+
557
+
558
+
559
+	/**
560
+	 * Returns the HTML for the form, except for the form opening and closing tags
561
+	 * (as the form section doesn't know where you necessarily want to send the information to),
562
+	 * and except for a submit button. Enqueus JS and CSS; if called early enough we will
563
+	 * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
564
+	 * Not doing_it_wrong because theoretically this CAN be used properly,
565
+	 * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
566
+	 * any CSS.
567
+	 *
568
+	 * @throws \EE_Error
569
+	 */
570
+	public function get_html_and_js()
571
+	{
572
+		$this->enqueue_js();
573
+		return $this->get_html();
574
+	}
575
+
576
+
577
+
578
+	/**
579
+	 * returns HTML for displaying this form section. recursively calls display_section() on all subsections
580
+	 *
581
+	 * @param bool $display_previously_submitted_data
582
+	 * @return string
583
+	 */
584
+	public function get_html($display_previously_submitted_data = true)
585
+	{
586
+		$this->ensure_construct_finalized_called();
587
+		if ($display_previously_submitted_data) {
588
+			$this->populate_from_session();
589
+		}
590
+		return $this->_form_html_filter
591
+			? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
592
+			: $this->_layout_strategy->layout_form();
593
+	}
594
+
595
+
596
+
597
+	/**
598
+	 * enqueues JS and CSS for the form.
599
+	 * It is preferred to call this before wp_enqueue_scripts so the
600
+	 * scripts and styles can be put in the header, but if called later
601
+	 * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
602
+	 * only be in the header; but in HTML5 its ok in the body.
603
+	 * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
604
+	 * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
605
+	 *
606
+	 * @return string
607
+	 * @throws \EE_Error
608
+	 */
609
+	public function enqueue_js()
610
+	{
611
+		$this->_enqueue_and_localize_form_js();
612
+		foreach ($this->subsections() as $subsection) {
613
+			$subsection->enqueue_js();
614
+		}
615
+	}
616
+
617
+
618
+
619
+	/**
620
+	 * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
621
+	 * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
622
+	 * the wp_enqueue_scripts hook.
623
+	 * However, registering the form js and localizing it can happen when we
624
+	 * actually output the form (which is preferred, seeing how teh form's fields
625
+	 * could change until it's actually outputted)
626
+	 *
627
+	 * @param boolean $init_form_validation_automatically whether or not we want the form validation
628
+	 *                                                    to be triggered automatically or not
629
+	 * @return void
630
+	 */
631
+	public static function wp_enqueue_scripts($init_form_validation_automatically = true)
632
+	{
633
+		wp_register_script(
634
+			'ee_form_section_validation',
635
+			EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
636
+			array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
637
+			EVENT_ESPRESSO_VERSION,
638
+			true
639
+		);
640
+		wp_localize_script(
641
+			'ee_form_section_validation',
642
+			'ee_form_section_validation_init',
643
+			array('init' => $init_form_validation_automatically ? '1' : '0')
644
+		);
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 * gets the variables used by form_section_validation.js.
651
+	 * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
652
+	 * but before the wordpress hook wp_loaded
653
+	 *
654
+	 * @throws \EE_Error
655
+	 */
656
+	public function _enqueue_and_localize_form_js()
657
+	{
658
+		$this->ensure_construct_finalized_called();
659
+		//actually, we don't want to localize just yet. There may be other forms on the page.
660
+		//so we need to add our form section data to a static variable accessible by all form sections
661
+		//and localize it just before the footer
662
+		$this->localize_validation_rules();
663
+		add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
664
+		add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
665
+	}
666
+
667
+
668
+
669
+	/**
670
+	 * add our form section data to a static variable accessible by all form sections
671
+	 *
672
+	 * @param bool $return_for_subsection
673
+	 * @return void
674
+	 * @throws \EE_Error
675
+	 */
676
+	public function localize_validation_rules($return_for_subsection = false)
677
+	{
678
+		// we only want to localize vars ONCE for the entire form,
679
+		// so if the form section doesn't have a parent, then it must be the top dog
680
+		if ($return_for_subsection || ! $this->parent_section()) {
681
+			EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
682
+				'form_section_id'  => $this->html_id(true),
683
+				'validation_rules' => $this->get_jquery_validation_rules(),
684
+				'other_data'       => $this->get_other_js_data(),
685
+				'errors'           => $this->subsection_validation_errors_by_html_name(),
686
+			);
687
+			EE_Form_Section_Proper::$_scripts_localized = true;
688
+		}
689
+	}
690
+
691
+
692
+
693
+	/**
694
+	 * Gets an array of extra data that will be useful for client-side javascript.
695
+	 * This is primarily data added by inputs and forms in addition to any
696
+	 * scripts they might enqueue
697
+	 *
698
+	 * @param array $form_other_js_data
699
+	 * @return array
700
+	 */
701
+	public function get_other_js_data($form_other_js_data = array())
702
+	{
703
+		foreach ($this->subsections() as $subsection) {
704
+			$form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
705
+		}
706
+		return $form_other_js_data;
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * Gets a flat array of inputs for this form section and its subsections.
713
+	 * Keys are their form names, and values are the inputs themselves
714
+	 *
715
+	 * @return EE_Form_Input_Base
716
+	 */
717
+	public function inputs_in_subsections()
718
+	{
719
+		$inputs = array();
720
+		foreach ($this->subsections() as $subsection) {
721
+			if ($subsection instanceof EE_Form_Input_Base) {
722
+				$inputs[$subsection->html_name()] = $subsection;
723
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
724
+				$inputs += $subsection->inputs_in_subsections();
725
+			}
726
+		}
727
+		return $inputs;
728
+	}
729
+
730
+
731
+
732
+	/**
733
+	 * Gets a flat array of all the validation errors.
734
+	 * Keys are html names (because those should be unique)
735
+	 * and values are a string of all their validation errors
736
+	 *
737
+	 * @return string[]
738
+	 */
739
+	public function subsection_validation_errors_by_html_name()
740
+	{
741
+		$inputs = $this->inputs();
742
+		$errors = array();
743
+		foreach ($inputs as $form_input) {
744
+			if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
745
+				$errors[$form_input->html_name()] = $form_input->get_validation_error_string();
746
+			}
747
+		}
748
+		return $errors;
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
755
+	 * Should be setup by each form during the _enqueues_and_localize_form_js
756
+	 */
757
+	public static function localize_script_for_all_forms()
758
+	{
759
+		//allow inputs and stuff to hook in their JS and stuff here
760
+		do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
761
+		EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
762
+		$email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
763
+			? EE_Registry::instance()->CFG->registration->email_validation_level
764
+			: 'wp_default';
765
+		EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
766
+		wp_enqueue_script('ee_form_section_validation');
767
+		wp_localize_script(
768
+			'ee_form_section_validation',
769
+			'ee_form_section_vars',
770
+			EE_Form_Section_Proper::$_js_localization
771
+		);
772
+	}
773
+
774
+
775
+
776
+	/**
777
+	 * ensure_scripts_localized
778
+	 */
779
+	public function ensure_scripts_localized()
780
+	{
781
+		if (! EE_Form_Section_Proper::$_scripts_localized) {
782
+			$this->_enqueue_and_localize_form_js();
783
+		}
784
+	}
785
+
786
+
787
+
788
+	/**
789
+	 * Gets the hard-coded validation error messages to be used in the JS. The convention
790
+	 * is that the key here should be the same as the custom validation rule put in the JS file
791
+	 *
792
+	 * @return array keys are custom validation rules, and values are internationalized strings
793
+	 */
794
+	private static function _get_localized_error_messages()
795
+	{
796
+		return array(
797
+			'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"),
798
+			'regex'    => __('Please check your input', 'event_espresso'),
799
+		);
800
+	}
801
+
802
+
803
+
804
+	/**
805
+	 * @return array
806
+	 */
807
+	public static function js_localization()
808
+	{
809
+		return self::$_js_localization;
810
+	}
811
+
812
+
813
+
814
+	/**
815
+	 * @return array
816
+	 */
817
+	public static function reset_js_localization()
818
+	{
819
+		self::$_js_localization = array();
820
+	}
821
+
822
+
823
+
824
+	/**
825
+	 * Gets the JS to put inside the jquery validation rules for subsection of this form section.
826
+	 * See parent function for more...
827
+	 *
828
+	 * @return array
829
+	 */
830
+	public function get_jquery_validation_rules()
831
+	{
832
+		$jquery_validation_rules = array();
833
+		foreach ($this->get_validatable_subsections() as $subsection) {
834
+			$jquery_validation_rules = array_merge(
835
+				$jquery_validation_rules,
836
+				$subsection->get_jquery_validation_rules()
837
+			);
838
+		}
839
+		return $jquery_validation_rules;
840
+	}
841
+
842
+
843
+
844
+	/**
845
+	 * Sanitizes all the data and sets the sanitized value of each field
846
+	 *
847
+	 * @param array $req_data like $_POST
848
+	 * @return void
849
+	 */
850
+	protected function _normalize($req_data)
851
+	{
852
+		$this->_received_submission = true;
853
+		$this->_validation_errors = array();
854
+		foreach ($this->get_validatable_subsections() as $subsection) {
855
+			try {
856
+				$subsection->_normalize($req_data);
857
+			} catch (EE_Validation_Error $e) {
858
+				$subsection->add_validation_error($e);
859
+			}
860
+		}
861
+	}
862
+
863
+
864
+
865
+	/**
866
+	 * Performs validation on this form section and its subsections.
867
+	 * For each subsection,
868
+	 * calls _validate_{subsection_name} on THIS form (if the function exists)
869
+	 * and passes it the subsection, then calls _validate on that subsection.
870
+	 * If you need to perform validation on the form as a whole (considering multiple)
871
+	 * you would be best to override this _validate method,
872
+	 * calling parent::_validate() first.
873
+	 */
874
+	protected function _validate()
875
+	{
876
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
877
+			if (method_exists($this, '_validate_' . $subsection_name)) {
878
+				call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
879
+			}
880
+			$subsection->_validate();
881
+		}
882
+	}
883
+
884
+
885
+
886
+	/**
887
+	 * Gets all the validated inputs for the form section
888
+	 *
889
+	 * @return array
890
+	 */
891
+	public function valid_data()
892
+	{
893
+		$inputs = array();
894
+		foreach ($this->subsections() as $subsection_name => $subsection) {
895
+			if ($subsection instanceof EE_Form_Section_Proper) {
896
+				$inputs[$subsection_name] = $subsection->valid_data();
897
+			} else if ($subsection instanceof EE_Form_Input_Base) {
898
+				$inputs[$subsection_name] = $subsection->normalized_value();
899
+			}
900
+		}
901
+		return $inputs;
902
+	}
903
+
904
+
905
+
906
+	/**
907
+	 * Gets all the inputs on this form section
908
+	 *
909
+	 * @return EE_Form_Input_Base[]
910
+	 */
911
+	public function inputs()
912
+	{
913
+		$inputs = array();
914
+		foreach ($this->subsections() as $subsection_name => $subsection) {
915
+			if ($subsection instanceof EE_Form_Input_Base) {
916
+				$inputs[$subsection_name] = $subsection;
917
+			}
918
+		}
919
+		return $inputs;
920
+	}
921
+
922
+
923
+
924
+	/**
925
+	 * Gets all the subsections which are a proper form
926
+	 *
927
+	 * @return EE_Form_Section_Proper[]
928
+	 */
929
+	public function subforms()
930
+	{
931
+		$form_sections = array();
932
+		foreach ($this->subsections() as $name => $obj) {
933
+			if ($obj instanceof EE_Form_Section_Proper) {
934
+				$form_sections[$name] = $obj;
935
+			}
936
+		}
937
+		return $form_sections;
938
+	}
939
+
940
+
941
+
942
+	/**
943
+	 * Gets all the subsections (inputs, proper subsections, or html-only sections).
944
+	 * Consider using inputs() or subforms()
945
+	 * if you only want form inputs or proper form sections.
946
+	 *
947
+	 * @param boolean $require_construction_to_be_finalized most client code should
948
+	 *                                                      leave this as TRUE so that the inputs will be properly
949
+	 *                                                      configured. However, some client code may be ok with
950
+	 *                                                      construction finalize being called later
951
+	 *                                                      (realizing that the subsections' html names might not be
952
+	 *                                                      set yet, etc.)
953
+	 * @return EE_Form_Section_Proper[]
954
+	 */
955
+	public function subsections($require_construction_to_be_finalized = true)
956
+	{
957
+		if ($require_construction_to_be_finalized) {
958
+			$this->ensure_construct_finalized_called();
959
+		}
960
+		return $this->_subsections;
961
+	}
962
+
963
+
964
+
965
+	/**
966
+	 * Returns a simple array where keys are input names, and values are their normalized
967
+	 * values. (Similar to calling get_input_value on inputs)
968
+	 *
969
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
970
+	 *                                        or just this forms' direct children inputs
971
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
972
+	 *                                        or allow multidimensional array
973
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
974
+	 *                                        with array keys being input names
975
+	 *                                        (regardless of whether they are from a subsection or not),
976
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
977
+	 *                                        where keys are always subsection names and values are either
978
+	 *                                        the input's normalized value, or an array like the top-level array
979
+	 */
980
+	public function input_values($include_subform_inputs = false, $flatten = false)
981
+	{
982
+		return $this->_input_values(false, $include_subform_inputs, $flatten);
983
+	}
984
+
985
+
986
+
987
+	/**
988
+	 * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
989
+	 * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
990
+	 * is not necessarily the value we want to display to users. This creates an array
991
+	 * where keys are the input names, and values are their display values
992
+	 *
993
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
994
+	 *                                        or just this forms' direct children inputs
995
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
996
+	 *                                        or allow multidimensional array
997
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
998
+	 *                                        with array keys being input names
999
+	 *                                        (regardless of whether they are from a subsection or not),
1000
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1001
+	 *                                        where keys are always subsection names and values are either
1002
+	 *                                        the input's normalized value, or an array like the top-level array
1003
+	 */
1004
+	public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1005
+	{
1006
+		return $this->_input_values(true, $include_subform_inputs, $flatten);
1007
+	}
1008
+
1009
+
1010
+
1011
+	/**
1012
+	 * Gets the input values from the form
1013
+	 *
1014
+	 * @param boolean $pretty                 Whether to retrieve the pretty value,
1015
+	 *                                        or just the normalized value
1016
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1017
+	 *                                        or just this forms' direct children inputs
1018
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1019
+	 *                                        or allow multidimensional array
1020
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1021
+	 *                                        input names (regardless of whether they are from a subsection or not),
1022
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1023
+	 *                                        where keys are always subsection names and values are either
1024
+	 *                                        the input's normalized value, or an array like the top-level array
1025
+	 */
1026
+	public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1027
+	{
1028
+		$input_values = array();
1029
+		foreach ($this->subsections() as $subsection_name => $subsection) {
1030
+			if ($subsection instanceof EE_Form_Input_Base) {
1031
+				$input_values[$subsection_name] = $pretty
1032
+					? $subsection->pretty_value()
1033
+					: $subsection->normalized_value();
1034
+			} else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1035
+				$subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten);
1036
+				if ($flatten) {
1037
+					$input_values = array_merge($input_values, $subform_input_values);
1038
+				} else {
1039
+					$input_values[$subsection_name] = $subform_input_values;
1040
+				}
1041
+			}
1042
+		}
1043
+		return $input_values;
1044
+	}
1045
+
1046
+
1047
+
1048
+	/**
1049
+	 * Gets the originally submitted input values from the form
1050
+	 *
1051
+	 * @param boolean $include_subforms  Whether to include inputs from subforms,
1052
+	 *                                   or just this forms' direct children inputs
1053
+	 * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1054
+	 *                                   with array keys being input names
1055
+	 *                                   (regardless of whether they are from a subsection or not),
1056
+	 *                                   and if $flatten is FALSE it can be a multidimensional array
1057
+	 *                                   where keys are always subsection names and values are either
1058
+	 *                                   the input's normalized value, or an array like the top-level array
1059
+	 */
1060
+	public function submitted_values($include_subforms = false)
1061
+	{
1062
+		$submitted_values = array();
1063
+		foreach ($this->subsections() as $subsection) {
1064
+			if ($subsection instanceof EE_Form_Input_Base) {
1065
+				// is this input part of an array of inputs?
1066
+				if (strpos($subsection->html_name(), '[') !== false) {
1067
+					$full_input_name = \EEH_Array::convert_array_values_to_keys(
1068
+						explode('[', str_replace(']', '', $subsection->html_name())),
1069
+						$subsection->raw_value()
1070
+					);
1071
+					$submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1072
+				} else {
1073
+					$submitted_values[$subsection->html_name()] = $subsection->raw_value();
1074
+				}
1075
+			} else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1076
+				$subform_input_values = $subsection->submitted_values($include_subforms);
1077
+				$submitted_values = array_replace_recursive($submitted_values, $subform_input_values);
1078
+			}
1079
+		}
1080
+		return $submitted_values;
1081
+	}
1082
+
1083
+
1084
+
1085
+	/**
1086
+	 * Indicates whether or not this form has received a submission yet
1087
+	 * (ie, had receive_form_submission called on it yet)
1088
+	 *
1089
+	 * @return boolean
1090
+	 * @throws \EE_Error
1091
+	 */
1092
+	public function has_received_submission()
1093
+	{
1094
+		$this->ensure_construct_finalized_called();
1095
+		return $this->_received_submission;
1096
+	}
1097
+
1098
+
1099
+
1100
+	/**
1101
+	 * Equivalent to passing 'exclude' in the constructor's options array.
1102
+	 * Removes the listed inputs from the form
1103
+	 *
1104
+	 * @param array $inputs_to_exclude values are the input names
1105
+	 * @return void
1106
+	 */
1107
+	public function exclude(array $inputs_to_exclude = array())
1108
+	{
1109
+		foreach ($inputs_to_exclude as $input_to_exclude_name) {
1110
+			unset($this->_subsections[$input_to_exclude_name]);
1111
+		}
1112
+	}
1113
+
1114
+
1115
+
1116
+	/**
1117
+	 * @param array $inputs_to_hide
1118
+	 * @throws \EE_Error
1119
+	 */
1120
+	public function hide(array $inputs_to_hide = array())
1121
+	{
1122
+		foreach ($inputs_to_hide as $input_to_hide) {
1123
+			$input = $this->get_input($input_to_hide);
1124
+			$input->set_display_strategy(new EE_Hidden_Display_Strategy());
1125
+		}
1126
+	}
1127
+
1128
+
1129
+
1130
+	/**
1131
+	 * add_subsections
1132
+	 * Adds the listed subsections to the form section.
1133
+	 * If $subsection_name_to_target is provided,
1134
+	 * then new subsections are added before or after that subsection,
1135
+	 * otherwise to the start or end of the entire subsections array.
1136
+	 *
1137
+	 * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1138
+	 *                                                          where keys are their names
1139
+	 * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1140
+	 *                                                          should be added before or after
1141
+	 *                                                          IF $subsection_name_to_target is null,
1142
+	 *                                                          then $new_subsections will be added to
1143
+	 *                                                          the beginning or end of the entire subsections array
1144
+	 * @param boolean                $add_before                whether to add $new_subsections, before or after
1145
+	 *                                                          $subsection_name_to_target,
1146
+	 *                                                          or if $subsection_name_to_target is null,
1147
+	 *                                                          before or after entire subsections array
1148
+	 * @return void
1149
+	 * @throws \EE_Error
1150
+	 */
1151
+	public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1152
+	{
1153
+		foreach ($new_subsections as $subsection_name => $subsection) {
1154
+			if (! $subsection instanceof EE_Form_Section_Base) {
1155
+				EE_Error::add_error(
1156
+					sprintf(
1157
+						__(
1158
+							"Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1159
+							"event_espresso"
1160
+						),
1161
+						get_class($subsection),
1162
+						$subsection_name,
1163
+						$this->name()
1164
+					)
1165
+				);
1166
+				unset($new_subsections[$subsection_name]);
1167
+			}
1168
+		}
1169
+		$this->_subsections = EEH_Array::insert_into_array(
1170
+			$this->_subsections,
1171
+			$new_subsections,
1172
+			$subsection_name_to_target,
1173
+			$add_before
1174
+		);
1175
+		if ($this->_construction_finalized) {
1176
+			foreach ($this->_subsections as $name => $subsection) {
1177
+				$subsection->_construct_finalize($this, $name);
1178
+			}
1179
+		}
1180
+	}
1181
+
1182
+
1183
+
1184
+	/**
1185
+	 * Just gets all validatable subsections to clean their sensitive data
1186
+	 */
1187
+	public function clean_sensitive_data()
1188
+	{
1189
+		foreach ($this->get_validatable_subsections() as $subsection) {
1190
+			$subsection->clean_sensitive_data();
1191
+		}
1192
+	}
1193
+
1194
+
1195
+
1196
+	/**
1197
+	 * @param string $form_submission_error_message
1198
+	 */
1199
+	public function set_submission_error_message($form_submission_error_message = '')
1200
+	{
1201
+		$this->_form_submission_error_message .= ! empty($form_submission_error_message)
1202
+			? $form_submission_error_message
1203
+			: __('Form submission failed due to errors', 'event_espresso');
1204
+	}
1205
+
1206
+
1207
+
1208
+	/**
1209
+	 * @return string
1210
+	 */
1211
+	public function submission_error_message()
1212
+	{
1213
+		return $this->_form_submission_error_message;
1214
+	}
1215
+
1216
+
1217
+
1218
+	/**
1219
+	 * @param string $form_submission_success_message
1220
+	 */
1221
+	public function set_submission_success_message($form_submission_success_message)
1222
+	{
1223
+		$this->_form_submission_success_message .= ! empty($form_submission_success_message)
1224
+			? $form_submission_success_message
1225
+			: __('Form submitted successfully', 'event_espresso');
1226
+	}
1227
+
1228
+
1229
+
1230
+	/**
1231
+	 * @return string
1232
+	 */
1233
+	public function submission_success_message()
1234
+	{
1235
+		return $this->_form_submission_success_message;
1236
+	}
1237
+
1238
+
1239
+
1240
+	/**
1241
+	 * Returns the prefix that should be used on child of this form section for
1242
+	 * their html names. If this form section itself has a parent, prepends ITS
1243
+	 * prefix onto this form section's prefix. Used primarily by
1244
+	 * EE_Form_Input_Base::_set_default_html_name_if_empty
1245
+	 *
1246
+	 * @return string
1247
+	 * @throws \EE_Error
1248
+	 */
1249
+	public function html_name_prefix()
1250
+	{
1251
+		if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1252
+			return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1253
+		} else {
1254
+			return $this->name();
1255
+		}
1256
+	}
1257
+
1258
+
1259
+
1260
+	/**
1261
+	 * Gets the name, but first checks _construct_finalize has been called. If not,
1262
+	 * calls it (assumes there is no parent and that we want the name to be whatever
1263
+	 * was set, which is probably nothing, or the classname)
1264
+	 *
1265
+	 * @return string
1266
+	 * @throws \EE_Error
1267
+	 */
1268
+	public function name()
1269
+	{
1270
+		$this->ensure_construct_finalized_called();
1271
+		return parent::name();
1272
+	}
1273
+
1274
+
1275
+
1276
+	/**
1277
+	 * @return EE_Form_Section_Proper
1278
+	 * @throws \EE_Error
1279
+	 */
1280
+	public function parent_section()
1281
+	{
1282
+		$this->ensure_construct_finalized_called();
1283
+		return parent::parent_section();
1284
+	}
1285
+
1286
+
1287
+
1288
+	/**
1289
+	 * make sure construction finalized was called, otherwise children might not be ready
1290
+	 *
1291
+	 * @return void
1292
+	 * @throws \EE_Error
1293
+	 */
1294
+	public function ensure_construct_finalized_called()
1295
+	{
1296
+		if (! $this->_construction_finalized) {
1297
+			$this->_construct_finalize($this->_parent_section, $this->_name);
1298
+		}
1299
+	}
1300
+
1301
+
1302
+
1303
+	/**
1304
+	 * Checks if any of this form section's inputs, or any of its children's inputs,
1305
+	 * are in teh form data. If any are found, returns true. Else false
1306
+	 *
1307
+	 * @param array $req_data
1308
+	 * @return boolean
1309
+	 */
1310
+	public function form_data_present_in($req_data = null)
1311
+	{
1312
+		if ($req_data === null) {
1313
+			$req_data = $_POST;
1314
+		}
1315
+		foreach ($this->subsections() as $subsection) {
1316
+			if ($subsection instanceof EE_Form_Input_Base) {
1317
+				if ($subsection->form_data_present_in($req_data)) {
1318
+					return true;
1319
+				}
1320
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
1321
+				if ($subsection->form_data_present_in($req_data)) {
1322
+					return true;
1323
+				}
1324
+			}
1325
+		}
1326
+		return false;
1327
+	}
1328
+
1329
+
1330
+
1331
+	/**
1332
+	 * Gets validation errors for this form section and subsections
1333
+	 * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1334
+	 * gets the validation errors for ALL subsection
1335
+	 *
1336
+	 * @return EE_Validation_Error[]
1337
+	 */
1338
+	public function get_validation_errors_accumulated()
1339
+	{
1340
+		$validation_errors = $this->get_validation_errors();
1341
+		foreach ($this->get_validatable_subsections() as $subsection) {
1342
+			if ($subsection instanceof EE_Form_Section_Proper) {
1343
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1344
+			} else {
1345
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors();
1346
+			}
1347
+			if ($validation_errors_on_this_subsection) {
1348
+				$validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1349
+			}
1350
+		}
1351
+		return $validation_errors;
1352
+	}
1353
+
1354
+
1355
+
1356
+	/**
1357
+	 * This isn't just the name of an input, it's a path pointing to an input. The
1358
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
1359
+	 * dot-dot-slash (../) means to ascend into the parent section.
1360
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1361
+	 * which will be returned.
1362
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1363
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1364
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1365
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1366
+	 * Etc
1367
+	 *
1368
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1369
+	 * @return EE_Form_Section_Base
1370
+	 */
1371
+	public function find_section_from_path($form_section_path)
1372
+	{
1373
+		//check if we can find the input from purely going straight up the tree
1374
+		$input = parent::find_section_from_path($form_section_path);
1375
+		if ($input instanceof EE_Form_Section_Base) {
1376
+			return $input;
1377
+		}
1378
+		$next_slash_pos = strpos($form_section_path, '/');
1379
+		if ($next_slash_pos !== false) {
1380
+			$child_section_name = substr($form_section_path, 0, $next_slash_pos);
1381
+			$subpath = substr($form_section_path, $next_slash_pos + 1);
1382
+		} else {
1383
+			$child_section_name = $form_section_path;
1384
+			$subpath = '';
1385
+		}
1386
+		$child_section = $this->get_subsection($child_section_name);
1387
+		if ($child_section instanceof EE_Form_Section_Base) {
1388
+			return $child_section->find_section_from_path($subpath);
1389
+		} else {
1390
+			return null;
1391
+		}
1392
+	}
1393 1393
 
1394 1394
 }
1395 1395
 
Please login to merge, or discard this patch.