Completed
Branch BUG-10489-non-trashed-regs-onl... (b37a8e)
by
unknown
37:13 queued 23:24
created
core/data_migration_scripts/4_6_0_stages/EE_DMS_4_6_0_gateways.dmsstage.php 2 patches
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
 	exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  * Migrates 4.1-4.5-style gateway settings (which were stores in EE_Config)
15 15
  * to 4.6-style payment methods (which have their database table)
16 16
  */
17
-class EE_DMS_4_6_0_gateways extends EE_Data_Migration_Script_Stage{
17
+class EE_DMS_4_6_0_gateways extends EE_Data_Migration_Script_Stage {
18 18
 
19 19
 	protected $_new_table_name;
20 20
 	protected $_extra_meta_table_name;
@@ -73,11 +73,11 @@  discard block
 block discarded – undo
73 73
 	 */
74 74
 	protected function _migration_step($num_items_to_migrate = 50) {
75 75
 		$items_actually_migrated = 0;
76
-		$gateways_to_deal_with = array_slice(EE_Config::instance()->gateway->payment_settings,$this->count_records_migrated(),$num_items_to_migrate);
77
-		foreach($gateways_to_deal_with as $old_gateway_slug => $old_gateway_settings){
76
+		$gateways_to_deal_with = array_slice(EE_Config::instance()->gateway->payment_settings, $this->count_records_migrated(), $num_items_to_migrate);
77
+		foreach ($gateways_to_deal_with as $old_gateway_slug => $old_gateway_settings) {
78 78
 
79
-			if( in_array( $old_gateway_slug, $this->_gateway_we_know_to_migrate ) ) {
80
-				if( ! $old_gateway_settings){
79
+			if (in_array($old_gateway_slug, $this->_gateway_we_know_to_migrate)) {
80
+				if ( ! $old_gateway_settings) {
81 81
 					//no settings existed for this gateway anyways... weird...
82 82
 					$items_actually_migrated++;
83 83
 					continue;
@@ -86,16 +86,16 @@  discard block
 block discarded – undo
86 86
 				$success = $this->_convert_gateway_settings(
87 87
 						$old_gateway_slug,
88 88
 						$old_gateway_settings,
89
-						isset( EE_Config::instance()->gateway->active_gateways[ $old_gateway_slug ] ) );
90
-				if( $success ) {
91
-					EE_Config::instance()->gateway->payment_settings[ $old_gateway_slug ] = 'Deprecated';
89
+						isset(EE_Config::instance()->gateway->active_gateways[$old_gateway_slug]) );
90
+				if ($success) {
91
+					EE_Config::instance()->gateway->payment_settings[$old_gateway_slug] = 'Deprecated';
92 92
 				}
93 93
 			}
94 94
 			$items_actually_migrated++;
95 95
 		}
96 96
 
97
-		EE_Config::instance()->update_espresso_config(false,false);
98
-		if($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()){
97
+		EE_Config::instance()->update_espresso_config(false, false);
98
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
99 99
 			$this->set_completed();
100 100
 		}
101 101
 		return $items_actually_migrated;
@@ -108,22 +108,22 @@  discard block
 block discarded – undo
108 108
 	 * @param boolean $active indicates the gateway is currently active
109 109
 	 * @return boolean success
110 110
 	 */
111
-	protected function _convert_gateway_settings($old_gateway_slug,$old_gateway_settings,$active){
112
-		switch($old_gateway_slug){
111
+	protected function _convert_gateway_settings($old_gateway_slug, $old_gateway_settings, $active) {
112
+		switch ($old_gateway_slug) {
113 113
 			case 'Aim':
114 114
 				$extra_meta_key_values = array(
115 115
 					'login_id'=>$old_gateway_settings['authnet_aim_login_id'],
116 116
 					'transaction_key'=>$old_gateway_settings['authnet_aim_transaction_key'],
117 117
 					'test_transactions'=>$old_gateway_settings['test_transactions']
118 118
 				);
119
-				$desc = __( 'Please provide the following billing information.', 'event_espresso' );
119
+				$desc = __('Please provide the following billing information.', 'event_espresso');
120 120
 				break;
121 121
 			case 'Bank':
122 122
 				$extra_meta_key_values = array(
123 123
 					'page_title'=>$old_gateway_settings['page_title'],
124 124
 					'payment_instructions'=>
125
-					sprintf( __('%1$s<br/>Name on Bank Account: %2$s<br/>Bank Account Number: %3$s<br/>Bank Name: %4$s<br/>Bank Address:%5$s', 'event_espresso'), $old_gateway_settings['bank_instructions'] , $old_gateway_settings['account_name'], $old_gateway_settings['account_number'], $old_gateway_settings['bank_name'], $old_gateway_settings['bank_address'] ) );
126
-				$desc = __( 'Make payment using an electronic funds transfer from your bank.', 'event_espresso' );
125
+					sprintf(__('%1$s<br/>Name on Bank Account: %2$s<br/>Bank Account Number: %3$s<br/>Bank Name: %4$s<br/>Bank Address:%5$s', 'event_espresso'), $old_gateway_settings['bank_instructions'], $old_gateway_settings['account_name'], $old_gateway_settings['account_number'], $old_gateway_settings['bank_name'], $old_gateway_settings['bank_address']) );
126
+				$desc = __('Make payment using an electronic funds transfer from your bank.', 'event_espresso');
127 127
 				break;
128 128
 			case 'Check':
129 129
 				$extra_meta_key_values = array(
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 					'payment_instructions'=>$old_gateway_settings['check_instructions'],
132 132
 					'address_to_send_payment'=>$old_gateway_settings['payment_address']
133 133
 				);
134
-				$desc = __( 'On the next page you will be given instructions on how to make a payment by check.', 'event_espresso' );
134
+				$desc = __('On the next page you will be given instructions on how to make a payment by check.', 'event_espresso');
135 135
 				break;
136 136
 			case 'Invoice':
137 137
 				$extra_meta_key_values = array(
@@ -139,23 +139,23 @@  discard block
 block discarded – undo
139 139
 					'pdf_payee_email' => $old_gateway_settings['template_invoice_email'],
140 140
 					'pdf_payee_tax_number' => $old_gateway_settings['template_invoice_tax_number'],
141 141
 					'pdf_payee_address' => $old_gateway_settings['template_invoice_address'],
142
-					'pdf_instructions' => $old_gateway_settings[ 'template_payment_instructions' ],
143
-					'pdf_logo_image' => $old_gateway_settings[ 'invoice_logo_url' ],
144
-					'page_confirmation_text' => isset( $old_gateway_settings[ 'page_instructions' ] ) ? $old_gateway_settings[ 'page_instructions' ] : '',
145
-					'page_extra_info' => isset( $old_gateway_settings[ 'payment_address' ] ) ? $old_gateway_settings[ 'payment_address' ] : '',
142
+					'pdf_instructions' => $old_gateway_settings['template_payment_instructions'],
143
+					'pdf_logo_image' => $old_gateway_settings['invoice_logo_url'],
144
+					'page_confirmation_text' => isset($old_gateway_settings['page_instructions']) ? $old_gateway_settings['page_instructions'] : '',
145
+					'page_extra_info' => isset($old_gateway_settings['payment_address']) ? $old_gateway_settings['payment_address'] : '',
146 146
 					'legacy_invoice_css' => $old_gateway_settings['invoice_css']
147 147
 				);
148 148
 				//if they didnt want the invoiec gateway to show, pretend it was inactive
149
-				if( ! $old_gateway_settings['show'] ){
149
+				if ( ! $old_gateway_settings['show']) {
150 150
 					$active = FALSE;
151 151
 				}
152
-				$desc = __( 'On the next page you will be able to access your invoice and instructions on how to pay it.', 'event_espresso' );
152
+				$desc = __('On the next page you will be able to access your invoice and instructions on how to pay it.', 'event_espresso');
153 153
 				break;
154 154
 			case 'Mijireh':
155 155
 				$extra_meta_key_values = array(
156
-					'access_key' => $old_gateway_settings[ 'access_key' ]
156
+					'access_key' => $old_gateway_settings['access_key']
157 157
 				);
158
-				$desc =  __( 'On the next page you will be able to enter your billing information to make the payment.', 'event_espresso' );
158
+				$desc = __('On the next page you will be able to enter your billing information to make the payment.', 'event_espresso');
159 159
 				break;
160 160
 			case 'Paypal_Pro':
161 161
 				$extra_meta_key_values = array(
@@ -164,31 +164,31 @@  discard block
 block discarded – undo
164 164
 					'signature'=>$old_gateway_settings['signature'],
165 165
 					'credit_card_types'=>$old_gateway_settings['credit_cards'],
166 166
 				);
167
-				$desc = __( 'Please provide the following billing information.', 'event_espresso' );
167
+				$desc = __('Please provide the following billing information.', 'event_espresso');
168 168
 				break;
169 169
 			case 'Paypal_Standard':
170 170
 				$extra_meta_key_values = array(
171
-					'paypal_id' => $old_gateway_settings[ 'paypal_id' ],
172
-					'image_url' => $old_gateway_settings[ 'image_url' ],
173
-					'shipping_details' => isset( $old_gateway_settings[ 'no_shipping' ] ) ? $old_gateway_settings[ 'no_shipping' ] : false,
171
+					'paypal_id' => $old_gateway_settings['paypal_id'],
172
+					'image_url' => $old_gateway_settings['image_url'],
173
+					'shipping_details' => isset($old_gateway_settings['no_shipping']) ? $old_gateway_settings['no_shipping'] : false,
174 174
 
175 175
 				);
176
-				$desc = sprintf( __( 'After clicking \'Finalize Registration\', you will be forwarded to PayPal to make your payment. Make sure you return to this site in order to properly finalize your registration.', 'event_espresso' ), '<strong>','</strong>' );
176
+				$desc = sprintf(__('After clicking \'Finalize Registration\', you will be forwarded to PayPal to make your payment. Make sure you return to this site in order to properly finalize your registration.', 'event_espresso'), '<strong>', '</strong>');
177 177
 				break;
178 178
 			default:
179 179
 				//if we don't recognize the payment method, just put everything in it into extra meta. At least this way its preserved somewhere
180 180
 				$extra_meta_key_values = $old_gateway_settings;
181 181
 				$desc = '';
182 182
 		}
183
-		$pretty_name = isset( $old_gateway_settings[ 'display_name' ] ) ? $old_gateway_settings[ 'display_name' ] : $old_gateway_slug;
184
-		$offline_gateways = array( 'Bank', 'Check', 'Invoice' );
185
-		if( $active && in_array( $old_gateway_slug, $offline_gateways ) ) {
186
-			$scope = array( 'CART', 'ADMIN');
187
-		}elseif( $active && ! in_array( $old_gateway_slug, $offline_gateways ) ) {
188
-			$scope = array( 'CART' );
189
-		}elseif( ! $active && in_array($old_gateway_slug,$offline_gateways ) ) {
190
-			$scope = array( 'ADMIN' );
191
-		}else{
183
+		$pretty_name = isset($old_gateway_settings['display_name']) ? $old_gateway_settings['display_name'] : $old_gateway_slug;
184
+		$offline_gateways = array('Bank', 'Check', 'Invoice');
185
+		if ($active && in_array($old_gateway_slug, $offline_gateways)) {
186
+			$scope = array('CART', 'ADMIN');
187
+		}elseif ($active && ! in_array($old_gateway_slug, $offline_gateways)) {
188
+			$scope = array('CART');
189
+		}elseif ( ! $active && in_array($old_gateway_slug, $offline_gateways)) {
190
+			$scope = array('ADMIN');
191
+		} else {
192 192
 			$scope = array();
193 193
 		}
194 194
 		$payment_method_col_values = array(
@@ -196,25 +196,25 @@  discard block
 block discarded – undo
196 196
 			'PMD_name' => $pretty_name,
197 197
 			'PMD_desc' => $desc,
198 198
 			'PMD_admin_name' => $pretty_name,
199
-			'PMD_slug' => sanitize_key( $old_gateway_slug ),
200
-			'PMD_debug_mode' => isset( $old_gateway_settings[ 'use_sandbox' ] ) ? $old_gateway_settings['use_sandbox'] : FALSE,
201
-			'PMD_button_url' => isset( $old_gateway_settings[ 'button_url' ] ) ? $old_gateway_settings[ 'button_url' ] : NULL,
202
-			'PMD_scope' =>  serialize( $scope )
199
+			'PMD_slug' => sanitize_key($old_gateway_slug),
200
+			'PMD_debug_mode' => isset($old_gateway_settings['use_sandbox']) ? $old_gateway_settings['use_sandbox'] : FALSE,
201
+			'PMD_button_url' => isset($old_gateway_settings['button_url']) ? $old_gateway_settings['button_url'] : NULL,
202
+			'PMD_scope' =>  serialize($scope)
203 203
 		);
204 204
 		$db_types = array(
205
-			'%s',//PMD_type
206
-			'%s',//PMD_name
207
-			'%s',//PMD_desc
208
-			'%s',//PMD_admin_name
209
-			'%s',//PMD_slug
210
-			'%d',//PMD_debug_mode
211
-			'%s',//PMD_button_url
212
-			'%s',//PMD_scope
205
+			'%s', //PMD_type
206
+			'%s', //PMD_name
207
+			'%s', //PMD_desc
208
+			'%s', //PMD_admin_name
209
+			'%s', //PMD_slug
210
+			'%d', //PMD_debug_mode
211
+			'%s', //PMD_button_url
212
+			'%s', //PMD_scope
213 213
 		);
214 214
 		global $wpdb;
215 215
 		//first: check if it already exists
216
-		$id = $wpdb->get_var( $wpdb->prepare( "SELECT PMD_ID FROM {$this->_new_table_name} WHERE PMD_slug=%s", $payment_method_col_values[ 'PMD_slug' ] ) );
217
-		if( $id ){
216
+		$id = $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM {$this->_new_table_name} WHERE PMD_slug=%s", $payment_method_col_values['PMD_slug']));
217
+		if ($id) {
218 218
 			//just update that payment method instead of creating a new one
219 219
 			$success = $wpdb->update(
220 220
 					$this->_new_table_name,
@@ -224,27 +224,27 @@  discard block
 block discarded – undo
224 224
 					),
225 225
 					$db_types,
226 226
 					array(
227
-						'%d',//PMD_ID
227
+						'%d', //PMD_ID
228 228
 					));
229
-			if( ! $success ){
230
-				$this->add_error(sprintf(__('Could not update payment method %d with properties %s because %s', "event_espresso"),$id,wp_json_encode($payment_method_col_values),$wpdb->last_error));
229
+			if ( ! $success) {
230
+				$this->add_error(sprintf(__('Could not update payment method %d with properties %s because %s', "event_espresso"), $id, wp_json_encode($payment_method_col_values), $wpdb->last_error));
231 231
 			}
232
-		}else{
232
+		} else {
233 233
 			$success = $wpdb->insert(
234 234
 					$this->_new_table_name,
235 235
 					$payment_method_col_values,
236 236
 					$db_types);
237
-			if ( ! $success ) {
237
+			if ( ! $success) {
238 238
 				$this->add_error($wpdb->last_error);
239 239
 				return false;
240
-			}else{
240
+			} else {
241 241
 				$id = $wpdb->insert_id;
242 242
 			}
243 243
 		}
244 244
 
245
-		if( $id ){
246
-			$this->_convert_extra_meta_values( $id, $extra_meta_key_values );
247
-			$this->get_migration_script()->set_mapping( 'EE_Gateway_Config', $old_gateway_slug, $this->_new_table_name, $id );
245
+		if ($id) {
246
+			$this->_convert_extra_meta_values($id, $extra_meta_key_values);
247
+			$this->get_migration_script()->set_mapping('EE_Gateway_Config', $old_gateway_slug, $this->_new_table_name, $id);
248 248
 			return true;
249 249
 		}
250 250
 		return false;
@@ -258,26 +258,26 @@  discard block
 block discarded – undo
258 258
 	 * @param int $id
259 259
 	 * @param array $extra_meta_key_values
260 260
 	 */
261
-	private function _convert_extra_meta_values($id,$extra_meta_key_values){
261
+	private function _convert_extra_meta_values($id, $extra_meta_key_values) {
262 262
 		global $wpdb;
263
-		foreach( $extra_meta_key_values as $key => $value ){
263
+		foreach ($extra_meta_key_values as $key => $value) {
264 264
 			$exm_args = array(
265 265
 				'OBJ_ID'=>$id,
266 266
 				'EXM_type'=>'Payment_Method',
267 267
 				'EXM_key'=>$key,
268
-				'EXM_value'=> maybe_serialize($value )
268
+				'EXM_value'=> maybe_serialize($value)
269 269
 			);
270 270
 			$success = $wpdb->insert(
271 271
 					$this->_extra_meta_table_name,
272 272
 					$exm_args,
273 273
 					array(
274
-						'%d',//OBJ_ID
275
-						'%s',//EXM_type
276
-						'%s',//EXM_key
277
-						'%s',//EXM_value
274
+						'%d', //OBJ_ID
275
+						'%s', //EXM_type
276
+						'%s', //EXM_key
277
+						'%s', //EXM_value
278 278
 					));
279
-			if( ! $success ){
280
-				$this->add_error(sprintf(__('Could not insert extra meta key with values %s. %s', "event_espresso"),wp_json_encode($exm_args),$wpdb->last_error));
279
+			if ( ! $success) {
280
+				$this->add_error(sprintf(__('Could not insert extra meta key with values %s. %s', "event_espresso"), wp_json_encode($exm_args), $wpdb->last_error));
281 281
 			}
282 282
 		}
283 283
 	}
Please login to merge, or discard this patch.
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -184,11 +184,11 @@  discard block
 block discarded – undo
184 184
 		$offline_gateways = array( 'Bank', 'Check', 'Invoice' );
185 185
 		if( $active && in_array( $old_gateway_slug, $offline_gateways ) ) {
186 186
 			$scope = array( 'CART', 'ADMIN');
187
-		}elseif( $active && ! in_array( $old_gateway_slug, $offline_gateways ) ) {
187
+		} elseif( $active && ! in_array( $old_gateway_slug, $offline_gateways ) ) {
188 188
 			$scope = array( 'CART' );
189
-		}elseif( ! $active && in_array($old_gateway_slug,$offline_gateways ) ) {
189
+		} elseif( ! $active && in_array($old_gateway_slug,$offline_gateways ) ) {
190 190
 			$scope = array( 'ADMIN' );
191
-		}else{
191
+		} else{
192 192
 			$scope = array();
193 193
 		}
194 194
 		$payment_method_col_values = array(
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 			if( ! $success ){
230 230
 				$this->add_error(sprintf(__('Could not update payment method %d with properties %s because %s', "event_espresso"),$id,wp_json_encode($payment_method_col_values),$wpdb->last_error));
231 231
 			}
232
-		}else{
232
+		} else{
233 233
 			$success = $wpdb->insert(
234 234
 					$this->_new_table_name,
235 235
 					$payment_method_col_values,
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 			if ( ! $success ) {
238 238
 				$this->add_error($wpdb->last_error);
239 239
 				return false;
240
-			}else{
240
+			} else{
241 241
 				$id = $wpdb->insert_id;
242 242
 			}
243 243
 		}
Please login to merge, or discard this patch.
4_9_0_stages/EE_DMS_4_9_0_Email_System_Question.dmsstage.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (!defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
 	exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * @author				Brent Christensen
14 14
  *
15 15
  */
16
-class EE_DMS_4_9_0_Email_System_Question extends EE_Data_Migration_Script_Stage_Table{
16
+class EE_DMS_4_9_0_Email_System_Question extends EE_Data_Migration_Script_Stage_Table {
17 17
 
18 18
 
19 19
 
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 */
25 25
 	public function __construct() {
26 26
 		global $wpdb;
27
-		$this->_pretty_name = __( 'Email - System Question', 'event_espresso' );
27
+		$this->_pretty_name = __('Email - System Question', 'event_espresso');
28 28
 		$this->_old_table = $wpdb->prefix.'esp_question';
29 29
 		$this->_extra_where_sql = "WHERE QST_system = 'email'";
30 30
 		parent::__construct();
@@ -37,21 +37,21 @@  discard block
 block discarded – undo
37 37
 	 * @param array $question an associative array where keys are column names and values are their values.
38 38
 	 * @return null
39 39
 	 */
40
-	protected function _migrate_old_row( $question ) {
41
-		if ( $question['QST_ID'] && $question['QST_system'] == 'email' ) {
40
+	protected function _migrate_old_row($question) {
41
+		if ($question['QST_ID'] && $question['QST_system'] == 'email') {
42 42
 			global $wpdb;
43 43
 			$success = $wpdb->update(
44 44
 				$this->_old_table,
45
-				array( 'QST_type' => 'EMAIL' ),  // data
46
-				array( 'QST_ID' => $question['QST_ID'] ),  // where
47
-				array( '%s' ),   // data format
48
-				array( '%d' )  // where format
45
+				array('QST_type' => 'EMAIL'), // data
46
+				array('QST_ID' => $question['QST_ID']), // where
47
+				array('%s'), // data format
48
+				array('%d')  // where format
49 49
 			);
50
-			if ( ! $success ) {
50
+			if ( ! $success) {
51 51
 				$this->add_error(
52 52
 					sprintf(
53
-						__( 'Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso' ),
54
-						wp_json_encode( $question['QST_system'] ),
53
+						__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'),
54
+						wp_json_encode($question['QST_system']),
55 55
 						$question['QST_ID'],
56 56
 						$wpdb->last_error
57 57
 					)
Please login to merge, or discard this patch.
admin_pages/events/templates/event_publish_box_extras.template.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  discard block
 block discarded – undo
1 1
 
2 2
 <div class="misc-pub-section">
3 3
 	<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20"></span>
4
-	<a href="<?php echo $view_approved_reg_url;?>">
5
-		<?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_approved, FALSE, 'sentence') ); ?>
4
+	<a href="<?php echo $view_approved_reg_url; ?>">
5
+		<?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_approved, FALSE, 'sentence')); ?>
6 6
 	</a>:
7 7
 	<?php echo $approved_regs; ?>
8 8
 </div>
9 9
 <div class="misc-pub-section">
10 10
 	<span class="dashicons dashicons-groups ee-icon-color-ee-blue ee-icon-size-20"></span>
11
-	<a href="<?php echo $view_pending_payment_reg_url;?>">
12
-		<?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, FALSE, 'sentence') ); ?>
11
+	<a href="<?php echo $view_pending_payment_reg_url; ?>">
12
+		<?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, FALSE, 'sentence')); ?>
13 13
 	</a>:
14 14
 	<?php echo $pending_payment_regs; ?>
15 15
 </div>
16 16
 <div class="misc-pub-section">
17 17
 	<span class="dashicons dashicons-groups ee-icon-color-ee-orange ee-icon-size-20"></span>
18
-	<a href="<?php echo $view_not_approved_reg_url;?>">
19
-		<?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, FALSE, 'sentence') ); ?>
18
+	<a href="<?php echo $view_not_approved_reg_url; ?>">
19
+		<?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, FALSE, 'sentence')); ?>
20 20
 	</a>:
21 21
 	<?php echo $not_approved_regs; ?>
22 22
 </div>
@@ -29,5 +29,5 @@  discard block
 block discarded – undo
29 29
 	</a>
30 30
 </div> /**/ ?>
31 31
 
32
-<?php echo $event_editor_overview_add;?>
32
+<?php echo $event_editor_overview_add; ?>
33 33
 <br/>
Please login to merge, or discard this patch.
templates/txn_admin_details_side_meta_box_registrant.template.php 3 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 <?php else : ?>
18 18
     <p class="clearfix">
19 19
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Name',
20
-                    'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
20
+					'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
21 21
     </p>
22 22
     <p class="clearfix">
23 23
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Email', 'event_espresso'); ?></span><a
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     </p>
26 26
     <p class="clearfix">
27 27
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Phone #',
28
-                    'event_espresso'); ?></span><?php echo $prime_reg_phone; ?>
28
+					'event_espresso'); ?></span><?php echo $prime_reg_phone; ?>
29 29
     </p>
30 30
     <p class="clearfix">
31 31
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Address', 'event_espresso'); ?></span>
@@ -36,13 +36,13 @@  discard block
 block discarded – undo
36 36
     </div> <!-- end #admin-side-mbox-primary-registrant-dv -->
37 37
 
38 38
     <?php
39
-    /** only show if logged in user has access */
40
-    if ( EE_Registry::instance()->CAP->current_user_can(
41
-            'ee_edit_contact',
42
-            'view_or_edit_contact_button',
43
-            $ATT_ID
44
-    )
45
-    ) : ?>
39
+	/** only show if logged in user has access */
40
+	if ( EE_Registry::instance()->CAP->current_user_can(
41
+			'ee_edit_contact',
42
+			'view_or_edit_contact_button',
43
+			$ATT_ID
44
+	)
45
+	) : ?>
46 46
     <p style="text-align:right;">
47 47
         <a class="button button-small" href="<?php echo $edit_attendee_url; ?>"
48 48
            title="<?php esc_attr_e('View details for this contact.', 'event_espresso'); ?>">
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 <?php else : ?>
18 18
     <p class="clearfix">
19 19
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Name',
20
-                    'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
20
+                    'event_espresso'); ?></span><?php echo $prime_reg_fname.' '.$prime_reg_lname; ?>
21 21
     </p>
22 22
     <p class="clearfix">
23 23
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Email', 'event_espresso'); ?></span><a
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
     <?php
39 39
     /** only show if logged in user has access */
40
-    if ( EE_Registry::instance()->CAP->current_user_can(
40
+    if (EE_Registry::instance()->CAP->current_user_can(
41 41
             'ee_edit_contact',
42 42
             'view_or_edit_contact_button',
43 43
             $ATT_ID
@@ -50,4 +50,4 @@  discard block
 block discarded – undo
50 50
         </a>
51 51
     </p>
52 52
     <?php endif; ?>
53
-<?php endif;  //end no attendee check?>
53
+<?php endif; //end no attendee check?>
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,10 +14,13 @@
 block discarded – undo
14 14
         <?php echo $no_attendee_message; ?>
15 15
     </p>
16 16
 </div> <!-- end #admin-side-mbox-primary-registrant-dv -->
17
-<?php else : ?>
17
+<?php else {
18
+	: ?>
18 19
     <p class="clearfix">
19 20
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Name',
20
-                    'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
21
+                    'event_espresso');
22
+}
23
+?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
21 24
     </p>
22 25
     <p class="clearfix">
23 26
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Email', 'event_espresso'); ?></span><a
Please login to merge, or discard this patch.
core/db_models/EEM_Datetime.model.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -529,7 +529,7 @@
 block discarded – undo
529 529
     /**
530 530
      * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
531 531
      *
532
-     * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
532
+     * @param  string[] $stati_to_include If included you can restrict the statuses we return counts for by including the
533 533
      *                                 stati you want counts for as values in the array.  An empty array returns counts
534 534
      *                                 for all valid stati.
535 535
      * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -482,9 +482,9 @@
 block discarded – undo
482 482
         $query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
483 483
         $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
484 484
         $columns_to_select = array(
485
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
486
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
487
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
485
+            'dtt_year'      => array('YEAR('.$query_interval.')', '%s'),
486
+            'dtt_month'     => array('MONTHNAME('.$query_interval.')', '%s'),
487
+            'dtt_month_num' => array('MONTH('.$query_interval.')', '%s'),
488 488
         );
489 489
         return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
490 490
     }
Please login to merge, or discard this patch.
Indentation   +590 added lines, -590 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
  * Class Datetime Model
@@ -11,595 +11,595 @@  discard block
 block discarded – undo
11 11
 class EEM_Datetime extends EEM_Soft_Delete_Base
12 12
 {
13 13
 
14
-    /**
15
-     * @var EEM_Datetime $_instance
16
-     */
17
-    protected static $_instance;
18
-
19
-
20
-
21
-    /**
22
-     *        private constructor to prevent direct creation
23
-     *
24
-     * @Constructor
25
-     * @access private
26
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
27
-     *                         incoming timezone data that gets saved).  Note this just sends the timezone info to the
28
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
29
-     *                         timezone in the 'timezone_string' wp option)
30
-     * @throws \EE_Error
31
-     */
32
-    protected function __construct($timezone)
33
-    {
34
-        $this->singular_item = __('Datetime', 'event_espresso');
35
-        $this->plural_item = __('Datetimes', 'event_espresso');
36
-        $this->_tables = array(
37
-            'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
38
-        );
39
-        $this->_fields = array(
40
-            'Datetime' => array(
41
-                'DTT_ID'          => new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')),
42
-                'EVT_ID'          => new EE_Foreign_Key_Int_Field(
43
-                    'EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'
44
-                ),
45
-                'DTT_name'        => new EE_Plain_Text_Field(
46
-                    'DTT_name', __('Datetime Name', 'event_espresso'), false, ''
47
-                ),
48
-                'DTT_description' => new EE_Post_Content_Field(
49
-                    'DTT_description', __('Description for Datetime', 'event_espresso'), false, ''
50
-                ),
51
-                'DTT_EVT_start'   => new EE_Datetime_Field(
52
-                    'DTT_EVT_start', __('Start time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
53
-                    $timezone
54
-                ),
55
-                'DTT_EVT_end'     => new EE_Datetime_Field(
56
-                    'DTT_EVT_end', __('End time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
57
-                    $timezone
58
-                ),
59
-                'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
60
-                    'DTT_reg_limit', __('Registration Limit for this time', 'event_espresso'), true, EE_INF),
61
-                'DTT_sold'        => new EE_Integer_Field(
62
-                    'DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0
63
-                ),
64
-                'DTT_reserved' => new EE_Integer_Field('DTT_reserved',
65
-                    __('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), false, 0
66
-                ),
67
-                'DTT_is_primary'  => new EE_Boolean_Field(
68
-                    'DTT_is_primary', __('Flag indicating datetime is primary one for event', 'event_espresso'),
69
-                    false, false
70
-                ),
71
-                'DTT_order'       => new EE_Integer_Field(
72
-                    'DTT_order', __('The order in which the Datetime is displayed', 'event_espresso'), false, 0
73
-                ),
74
-                'DTT_parent'      => new EE_Integer_Field(
75
-                    'DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0
76
-                ),
77
-                'DTT_deleted'     => new EE_Trashed_Flag_Field(
78
-                    'DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false
79
-                ),
80
-            ),
81
-        );
82
-        $this->_model_relations = array(
83
-            'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
84
-            'Event'   => new EE_Belongs_To_Relation(),
85
-            'Checkin' => new EE_Has_Many_Relation(),
86
-        );
87
-        $this->_model_chain_to_wp_user = 'Event';
88
-        //this model is generally available for reading
89
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event');
90
-        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event');
91
-        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event');
92
-        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event',
93
-            EEM_Base::caps_edit);
94
-        parent::__construct($timezone);
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * create new blank datetime
101
-     *
102
-     * @access public
103
-     * @return EE_Datetime[] array on success, FALSE on fail
104
-     * @throws \EE_Error
105
-     */
106
-    public function create_new_blank_datetime()
107
-    {
108
-        //makes sure timezone is always set.
109
-        $timezone_string = $this->get_timezone();
110
-        $blank_datetime = EE_Datetime::new_instance(
111
-            array(
112
-                'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS,
113
-                'DTT_EVT_end'   => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS,
114
-                'DTT_order'     => 1,
115
-                'DTT_reg_limit' => EE_INF,
116
-            ),
117
-            $timezone_string
118
-        );
119
-        $blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga',
120
-            $timezone_string));
121
-        $blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $timezone_string));
122
-        return array($blank_datetime);
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * get event start date from db
129
-     *
130
-     * @access public
131
-     * @param  int $EVT_ID
132
-     * @return EE_Datetime[] array on success, FALSE on fail
133
-     * @throws \EE_Error
134
-     */
135
-    public function get_all_event_dates($EVT_ID = 0)
136
-    {
137
-        if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
138
-            return $this->create_new_blank_datetime();
139
-        }
140
-        $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
141
-        if (empty($results)) {
142
-            return $this->create_new_blank_datetime();
143
-        }
144
-        return $results;
145
-    }
146
-
147
-
148
-
149
-    /**
150
-     * get all datetimes attached to an event ordered by the DTT_order field
151
-     *
152
-     * @public
153
-     * @param  int    $EVT_ID     event id
154
-     * @param boolean $include_expired
155
-     * @param boolean $include_deleted
156
-     * @param  int    $limit      If included then limit the count of results by
157
-     *                            the given number
158
-     * @return EE_Datetime[]
159
-     * @throws \EE_Error
160
-     */
161
-    public function get_datetimes_for_event_ordered_by_DTT_order(
162
-        $EVT_ID,
163
-        $include_expired = true,
164
-        $include_deleted = true,
165
-        $limit = null
166
-    ) {
167
-        //sanitize EVT_ID
168
-        $EVT_ID = absint($EVT_ID);
169
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
170
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
171
-        $where_params = array('Event.EVT_ID' => $EVT_ID);
172
-        $query_params = ! empty($limit)
173
-            ? array(
174
-                $where_params,
175
-                'limit'                    => $limit,
176
-                'order_by'                 => array('DTT_order' => 'ASC'),
177
-                'default_where_conditions' => 'none',
178
-            )
179
-            : array(
180
-                $where_params,
181
-                'order_by'                 => array('DTT_order' => 'ASC'),
182
-                'default_where_conditions' => 'none',
183
-            );
184
-        if ( ! $include_expired) {
185
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
186
-        }
187
-        if ($include_deleted) {
188
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
189
-        }
190
-        /** @var EE_Datetime[] $result */
191
-        $result = $this->get_all($query_params);
192
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
193
-        return $result;
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     * Gets the datetimes for the event (with the given limit), and orders them by "importance". By importance, we mean
200
-     * that the primary datetimes are most important (DEPRECATED FOR NOW), and then the earlier datetimes are the most
201
-     * important. Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
202
-     *
203
-     * @param int $EVT_ID
204
-     * @param int $limit
205
-     * @return EE_Datetime[]|EE_Base_Class[]
206
-     * @throws \EE_Error
207
-     */
208
-    public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
209
-    {
210
-        return $this->get_all(
211
-            array(
212
-                array('Event.EVT_ID' => $EVT_ID),
213
-                'limit'                    => $limit,
214
-                'order_by'                 => array('DTT_EVT_start' => 'ASC'),
215
-                'default_where_conditions' => 'none',
216
-            )
217
-        );
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * @param int     $EVT_ID
224
-     * @param boolean $include_expired
225
-     * @param boolean $include_deleted
226
-     * @return EE_Datetime
227
-     * @throws \EE_Error
228
-     */
229
-    public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
230
-    {
231
-        $results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
232
-        if ($results) {
233
-            return array_shift($results);
234
-        } else {
235
-            return null;
236
-        }
237
-    }
238
-
239
-
240
-
241
-    /**
242
-     * Gets the 'primary' datetime for an event.
243
-     *
244
-     * @param int  $EVT_ID
245
-     * @param bool $try_to_exclude_expired
246
-     * @param bool $try_to_exclude_deleted
247
-     * @return \EE_Datetime
248
-     * @throws \EE_Error
249
-     */
250
-    public function get_primary_datetime_for_event(
251
-        $EVT_ID,
252
-        $try_to_exclude_expired = true,
253
-        $try_to_exclude_deleted = true
254
-    ) {
255
-        if ($try_to_exclude_expired) {
256
-            $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
257
-            if ($non_expired) {
258
-                return $non_expired;
259
-            }
260
-        }
261
-        if ($try_to_exclude_deleted) {
262
-            $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
263
-            if ($expired_even) {
264
-                return $expired_even;
265
-            }
266
-        }
267
-        return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
274
-     * only by start date
275
-     *
276
-     * @param int     $EVT_ID
277
-     * @param boolean $include_expired
278
-     * @param boolean $include_deleted
279
-     * @param int     $limit
280
-     * @return EE_Datetime[]
281
-     * @throws \EE_Error
282
-     */
283
-    public function get_datetimes_for_event_ordered_by_start_time(
284
-        $EVT_ID,
285
-        $include_expired = true,
286
-        $include_deleted = true,
287
-        $limit = null
288
-    ) {
289
-        //sanitize EVT_ID
290
-        $EVT_ID = absint($EVT_ID);
291
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
292
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
293
-        $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
294
-        if ( ! $include_expired) {
295
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
296
-        }
297
-        if ($include_deleted) {
298
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
299
-        }
300
-        if ($limit) {
301
-            $query_params['limit'] = $limit;
302
-        }
303
-        /** @var EE_Datetime[] $result */
304
-        $result = $this->get_all($query_params);
305
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
306
-        return $result;
307
-    }
308
-
309
-
310
-
311
-    /**
312
-     * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
313
-     * only by start date
314
-     *
315
-     * @param int     $TKT_ID
316
-     * @param boolean $include_expired
317
-     * @param boolean $include_deleted
318
-     * @param int     $limit
319
-     * @return EE_Datetime[]
320
-     * @throws \EE_Error
321
-     */
322
-    public function get_datetimes_for_ticket_ordered_by_start_time(
323
-        $TKT_ID,
324
-        $include_expired = true,
325
-        $include_deleted = true,
326
-        $limit = null
327
-    ) {
328
-        //sanitize TKT_ID
329
-        $TKT_ID = absint($TKT_ID);
330
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
331
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
332
-        $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
333
-        if ( ! $include_expired) {
334
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
335
-        }
336
-        if ($include_deleted) {
337
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
338
-        }
339
-        if ($limit) {
340
-            $query_params['limit'] = $limit;
341
-        }
342
-        /** @var EE_Datetime[] $result */
343
-        $result = $this->get_all($query_params);
344
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
345
-        return $result;
346
-    }
347
-
348
-
349
-
350
-    /**
351
-     * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
352
-     * datetimes.
353
-     *
354
-     * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
355
-     * @param  boolean  $include_expired whether to include expired datetimes or not
356
-     * @param  boolean  $include_deleted whether to include trashed datetimes or not.
357
-     * @param  int|null $limit           if null, no limit, if int then limit results by
358
-     *                                   that number
359
-     * @return EE_Datetime[]
360
-     * @throws \EE_Error
361
-     */
362
-    public function get_datetimes_for_ticket_ordered_by_DTT_order(
363
-        $TKT_ID,
364
-        $include_expired = true,
365
-        $include_deleted = true,
366
-        $limit = null
367
-    ) {
368
-        //sanitize id.
369
-        $TKT_ID = absint($TKT_ID);
370
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
371
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
372
-        $where_params = array('Ticket.TKT_ID' => $TKT_ID);
373
-        $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
374
-        if ( ! $include_expired) {
375
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
376
-        }
377
-        if ($include_deleted) {
378
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
379
-        }
380
-        if ($limit) {
381
-            $query_params['limit'] = $limit;
382
-        }
383
-        /** @var EE_Datetime[] $result */
384
-        $result = $this->get_all($query_params);
385
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
386
-        return $result;
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
393
-     * reason it doesn't exist, we consider the earliest event the most important)
394
-     *
395
-     * @param int $EVT_ID
396
-     * @return EE_Datetime
397
-     * @throws \EE_Error
398
-     */
399
-    public function get_most_important_datetime_for_event($EVT_ID)
400
-    {
401
-        $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
402
-        if ($results) {
403
-            return array_shift($results);
404
-        } else {
405
-            return null;
406
-        }
407
-    }
408
-
409
-
410
-
411
-    /**
412
-     * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
413
-     * grouped by month and year.
414
-     *
415
-     * @param  array  $where_params      Array of query_params as described in the comments for EEM_Base::get_all()
416
-     * @param  string $evt_active_status A string representing the evt active status to filter the months by.
417
-     *                                   Can be:
418
-     *                                   - '' = no filter
419
-     *                                   - upcoming = Published events with at least one upcoming datetime.
420
-     *                                   - expired = Events with all datetimes expired.
421
-     *                                   - active = Events that are published and have at least one datetime that
422
-     *                                   starts before now and ends after now.
423
-     *                                   - inactive = Events that are either not published.
424
-     * @return EE_Base_Class[]
425
-     * @throws \EE_Error
426
-     */
427
-    public function get_dtt_months_and_years($where_params, $evt_active_status = '')
428
-    {
429
-        $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
430
-        $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end');
431
-        switch ($evt_active_status) {
432
-            case 'upcoming' :
433
-                $where_params['Event.status'] = 'publish';
434
-                //if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
435
-                if (isset($where_params['DTT_EVT_start'])) {
436
-                    $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
437
-                }
438
-                $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
439
-                break;
440
-            case 'expired' :
441
-                if (isset($where_params['Event.status'])) {
442
-                    unset($where_params['Event.status']);
443
-                }
444
-                //get events to exclude
445
-                $exclude_query[0] = array_merge($where_params,
446
-                    array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)));
447
-                //first get all events that have datetimes where its not expired.
448
-                $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID');
449
-                $event_ids = array_keys($event_ids);
450
-                if (isset($where_params['DTT_EVT_end'])) {
451
-                    $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
452
-                }
453
-                $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end);
454
-                $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
455
-                break;
456
-            case 'active' :
457
-                $where_params['Event.status'] = 'publish';
458
-                if (isset($where_params['DTT_EVT_start'])) {
459
-                    $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
460
-                }
461
-                if (isset($where_params['Datetime.DTT_EVT_end'])) {
462
-                    $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
463
-                }
464
-                $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
465
-                $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end);
466
-                break;
467
-            case 'inactive' :
468
-                if (isset($where_params['Event.status'])) {
469
-                    unset($where_params['Event.status']);
470
-                }
471
-                if (isset($where_params['OR'])) {
472
-                    $where_params['AND']['OR'] = $where_params['OR'];
473
-                }
474
-                if (isset($where_params['DTT_EVT_end'])) {
475
-                    $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
476
-                    unset($where_params['DTT_EVT_end']);
477
-                }
478
-                if (isset($where_params['DTT_EVT_start'])) {
479
-                    $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
480
-                    unset($where_params['DTT_EVT_start']);
481
-                }
482
-                $where_params['AND']['Event.status'] = array('!=', 'publish');
483
-                break;
484
-        }
485
-        $query_params[0] = $where_params;
486
-        $query_params['group_by'] = array('dtt_year', 'dtt_month');
487
-        $query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
488
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
489
-        $columns_to_select = array(
490
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
491
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
492
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
493
-        );
494
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
495
-    }
496
-
497
-
498
-
499
-    /**
500
-     * Updates the DTT_sold attribute on each datetime (based on the registrations
501
-     * for the tickets for each datetime)
502
-     *
503
-     * @param EE_Base_Class[]|EE_Datetime[] $datetimes
504
-     * @throws \EE_Error
505
-     */
506
-    public function update_sold($datetimes)
507
-    {
508
-        EE_Error::doing_it_wrong(
509
-            __FUNCTION__,
510
-            esc_html__(
511
-                'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
512
-                'event_espresso'
513
-            ),
514
-            '4.9.32.rc.005'
515
-        );
516
-        foreach ($datetimes as $datetime) {
517
-            $datetime->update_sold();
518
-        }
519
-    }
520
-
521
-
522
-
523
-    /**
524
-     *    Gets the total number of tickets available at a particular datetime
525
-     *    (does NOT take into account the datetime's spaces available)
526
-     *
527
-     * @param int   $DTT_ID
528
-     * @param array $query_params
529
-     * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
530
-     *             tickets attached to datetime then FALSE is returned.
531
-     */
532
-    public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
533
-    {
534
-        $datetime = $this->get_one_by_ID($DTT_ID);
535
-        if ($datetime instanceof EE_Datetime) {
536
-            return $datetime->tickets_remaining($query_params);
537
-        }
538
-        return 0;
539
-    }
540
-
541
-
542
-
543
-    /**
544
-     * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
545
-     *
546
-     * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
547
-     *                                 stati you want counts for as values in the array.  An empty array returns counts
548
-     *                                 for all valid stati.
549
-     * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
550
-     *                                 only for Datetimes connected to a specific event, or specific ticket.
551
-     * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
552
-     * @throws \EE_Error
553
-     *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming EE_Datetime::expired
554
-     */
555
-    public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
556
-    {
557
-        //only accept where conditions for this query.
558
-        $_where = isset($query_params[0]) ? $query_params[0] : array();
559
-        $status_query_args = array(
560
-            EE_Datetime::active   => array_merge(
561
-                $_where,
562
-                array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
563
-            ),
564
-            EE_Datetime::upcoming => array_merge(
565
-                $_where,
566
-                array('DTT_EVT_start' => array('>', time()))
567
-            ),
568
-            EE_Datetime::expired  => array_merge(
569
-                $_where,
570
-                array('DTT_EVT_end' => array('<', time()))
571
-            ),
572
-        );
573
-        if ( ! empty($stati_to_include)) {
574
-            foreach (array_keys($status_query_args) as $status) {
575
-                if ( ! in_array($status, $stati_to_include, true)) {
576
-                    unset($status_query_args[$status]);
577
-                }
578
-            }
579
-        }
580
-        //loop through and query counts for each stati.
581
-        $status_query_results = array();
582
-        foreach ($status_query_args as $status => $status_where_conditions) {
583
-            $status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true);
584
-        }
585
-        return $status_query_results;
586
-    }
587
-
588
-
589
-
590
-    /**
591
-     * Returns the specific count for a given Datetime status matching any given query_params.
592
-     *
593
-     * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
594
-     * @param array  $query_params
595
-     * @return int
596
-     * @throws \EE_Error
597
-     */
598
-    public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
599
-    {
600
-        $count = $this->get_datetime_counts_by_status(array($status), $query_params);
601
-        return ! empty($count[$status]) ? $count[$status] : 0;
602
-    }
14
+	/**
15
+	 * @var EEM_Datetime $_instance
16
+	 */
17
+	protected static $_instance;
18
+
19
+
20
+
21
+	/**
22
+	 *        private constructor to prevent direct creation
23
+	 *
24
+	 * @Constructor
25
+	 * @access private
26
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
27
+	 *                         incoming timezone data that gets saved).  Note this just sends the timezone info to the
28
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
29
+	 *                         timezone in the 'timezone_string' wp option)
30
+	 * @throws \EE_Error
31
+	 */
32
+	protected function __construct($timezone)
33
+	{
34
+		$this->singular_item = __('Datetime', 'event_espresso');
35
+		$this->plural_item = __('Datetimes', 'event_espresso');
36
+		$this->_tables = array(
37
+			'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
38
+		);
39
+		$this->_fields = array(
40
+			'Datetime' => array(
41
+				'DTT_ID'          => new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')),
42
+				'EVT_ID'          => new EE_Foreign_Key_Int_Field(
43
+					'EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'
44
+				),
45
+				'DTT_name'        => new EE_Plain_Text_Field(
46
+					'DTT_name', __('Datetime Name', 'event_espresso'), false, ''
47
+				),
48
+				'DTT_description' => new EE_Post_Content_Field(
49
+					'DTT_description', __('Description for Datetime', 'event_espresso'), false, ''
50
+				),
51
+				'DTT_EVT_start'   => new EE_Datetime_Field(
52
+					'DTT_EVT_start', __('Start time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
53
+					$timezone
54
+				),
55
+				'DTT_EVT_end'     => new EE_Datetime_Field(
56
+					'DTT_EVT_end', __('End time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
57
+					$timezone
58
+				),
59
+				'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
60
+					'DTT_reg_limit', __('Registration Limit for this time', 'event_espresso'), true, EE_INF),
61
+				'DTT_sold'        => new EE_Integer_Field(
62
+					'DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0
63
+				),
64
+				'DTT_reserved' => new EE_Integer_Field('DTT_reserved',
65
+					__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), false, 0
66
+				),
67
+				'DTT_is_primary'  => new EE_Boolean_Field(
68
+					'DTT_is_primary', __('Flag indicating datetime is primary one for event', 'event_espresso'),
69
+					false, false
70
+				),
71
+				'DTT_order'       => new EE_Integer_Field(
72
+					'DTT_order', __('The order in which the Datetime is displayed', 'event_espresso'), false, 0
73
+				),
74
+				'DTT_parent'      => new EE_Integer_Field(
75
+					'DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0
76
+				),
77
+				'DTT_deleted'     => new EE_Trashed_Flag_Field(
78
+					'DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false
79
+				),
80
+			),
81
+		);
82
+		$this->_model_relations = array(
83
+			'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
84
+			'Event'   => new EE_Belongs_To_Relation(),
85
+			'Checkin' => new EE_Has_Many_Relation(),
86
+		);
87
+		$this->_model_chain_to_wp_user = 'Event';
88
+		//this model is generally available for reading
89
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event');
90
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event');
91
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event');
92
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event',
93
+			EEM_Base::caps_edit);
94
+		parent::__construct($timezone);
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * create new blank datetime
101
+	 *
102
+	 * @access public
103
+	 * @return EE_Datetime[] array on success, FALSE on fail
104
+	 * @throws \EE_Error
105
+	 */
106
+	public function create_new_blank_datetime()
107
+	{
108
+		//makes sure timezone is always set.
109
+		$timezone_string = $this->get_timezone();
110
+		$blank_datetime = EE_Datetime::new_instance(
111
+			array(
112
+				'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS,
113
+				'DTT_EVT_end'   => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS,
114
+				'DTT_order'     => 1,
115
+				'DTT_reg_limit' => EE_INF,
116
+			),
117
+			$timezone_string
118
+		);
119
+		$blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga',
120
+			$timezone_string));
121
+		$blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $timezone_string));
122
+		return array($blank_datetime);
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * get event start date from db
129
+	 *
130
+	 * @access public
131
+	 * @param  int $EVT_ID
132
+	 * @return EE_Datetime[] array on success, FALSE on fail
133
+	 * @throws \EE_Error
134
+	 */
135
+	public function get_all_event_dates($EVT_ID = 0)
136
+	{
137
+		if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
138
+			return $this->create_new_blank_datetime();
139
+		}
140
+		$results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
141
+		if (empty($results)) {
142
+			return $this->create_new_blank_datetime();
143
+		}
144
+		return $results;
145
+	}
146
+
147
+
148
+
149
+	/**
150
+	 * get all datetimes attached to an event ordered by the DTT_order field
151
+	 *
152
+	 * @public
153
+	 * @param  int    $EVT_ID     event id
154
+	 * @param boolean $include_expired
155
+	 * @param boolean $include_deleted
156
+	 * @param  int    $limit      If included then limit the count of results by
157
+	 *                            the given number
158
+	 * @return EE_Datetime[]
159
+	 * @throws \EE_Error
160
+	 */
161
+	public function get_datetimes_for_event_ordered_by_DTT_order(
162
+		$EVT_ID,
163
+		$include_expired = true,
164
+		$include_deleted = true,
165
+		$limit = null
166
+	) {
167
+		//sanitize EVT_ID
168
+		$EVT_ID = absint($EVT_ID);
169
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
170
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
171
+		$where_params = array('Event.EVT_ID' => $EVT_ID);
172
+		$query_params = ! empty($limit)
173
+			? array(
174
+				$where_params,
175
+				'limit'                    => $limit,
176
+				'order_by'                 => array('DTT_order' => 'ASC'),
177
+				'default_where_conditions' => 'none',
178
+			)
179
+			: array(
180
+				$where_params,
181
+				'order_by'                 => array('DTT_order' => 'ASC'),
182
+				'default_where_conditions' => 'none',
183
+			);
184
+		if ( ! $include_expired) {
185
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
186
+		}
187
+		if ($include_deleted) {
188
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
189
+		}
190
+		/** @var EE_Datetime[] $result */
191
+		$result = $this->get_all($query_params);
192
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
193
+		return $result;
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * Gets the datetimes for the event (with the given limit), and orders them by "importance". By importance, we mean
200
+	 * that the primary datetimes are most important (DEPRECATED FOR NOW), and then the earlier datetimes are the most
201
+	 * important. Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
202
+	 *
203
+	 * @param int $EVT_ID
204
+	 * @param int $limit
205
+	 * @return EE_Datetime[]|EE_Base_Class[]
206
+	 * @throws \EE_Error
207
+	 */
208
+	public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
209
+	{
210
+		return $this->get_all(
211
+			array(
212
+				array('Event.EVT_ID' => $EVT_ID),
213
+				'limit'                    => $limit,
214
+				'order_by'                 => array('DTT_EVT_start' => 'ASC'),
215
+				'default_where_conditions' => 'none',
216
+			)
217
+		);
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * @param int     $EVT_ID
224
+	 * @param boolean $include_expired
225
+	 * @param boolean $include_deleted
226
+	 * @return EE_Datetime
227
+	 * @throws \EE_Error
228
+	 */
229
+	public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
230
+	{
231
+		$results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
232
+		if ($results) {
233
+			return array_shift($results);
234
+		} else {
235
+			return null;
236
+		}
237
+	}
238
+
239
+
240
+
241
+	/**
242
+	 * Gets the 'primary' datetime for an event.
243
+	 *
244
+	 * @param int  $EVT_ID
245
+	 * @param bool $try_to_exclude_expired
246
+	 * @param bool $try_to_exclude_deleted
247
+	 * @return \EE_Datetime
248
+	 * @throws \EE_Error
249
+	 */
250
+	public function get_primary_datetime_for_event(
251
+		$EVT_ID,
252
+		$try_to_exclude_expired = true,
253
+		$try_to_exclude_deleted = true
254
+	) {
255
+		if ($try_to_exclude_expired) {
256
+			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
257
+			if ($non_expired) {
258
+				return $non_expired;
259
+			}
260
+		}
261
+		if ($try_to_exclude_deleted) {
262
+			$expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
263
+			if ($expired_even) {
264
+				return $expired_even;
265
+			}
266
+		}
267
+		return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
274
+	 * only by start date
275
+	 *
276
+	 * @param int     $EVT_ID
277
+	 * @param boolean $include_expired
278
+	 * @param boolean $include_deleted
279
+	 * @param int     $limit
280
+	 * @return EE_Datetime[]
281
+	 * @throws \EE_Error
282
+	 */
283
+	public function get_datetimes_for_event_ordered_by_start_time(
284
+		$EVT_ID,
285
+		$include_expired = true,
286
+		$include_deleted = true,
287
+		$limit = null
288
+	) {
289
+		//sanitize EVT_ID
290
+		$EVT_ID = absint($EVT_ID);
291
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
292
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
293
+		$query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
294
+		if ( ! $include_expired) {
295
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
296
+		}
297
+		if ($include_deleted) {
298
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
299
+		}
300
+		if ($limit) {
301
+			$query_params['limit'] = $limit;
302
+		}
303
+		/** @var EE_Datetime[] $result */
304
+		$result = $this->get_all($query_params);
305
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
306
+		return $result;
307
+	}
308
+
309
+
310
+
311
+	/**
312
+	 * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
313
+	 * only by start date
314
+	 *
315
+	 * @param int     $TKT_ID
316
+	 * @param boolean $include_expired
317
+	 * @param boolean $include_deleted
318
+	 * @param int     $limit
319
+	 * @return EE_Datetime[]
320
+	 * @throws \EE_Error
321
+	 */
322
+	public function get_datetimes_for_ticket_ordered_by_start_time(
323
+		$TKT_ID,
324
+		$include_expired = true,
325
+		$include_deleted = true,
326
+		$limit = null
327
+	) {
328
+		//sanitize TKT_ID
329
+		$TKT_ID = absint($TKT_ID);
330
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
331
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
332
+		$query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
333
+		if ( ! $include_expired) {
334
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
335
+		}
336
+		if ($include_deleted) {
337
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
338
+		}
339
+		if ($limit) {
340
+			$query_params['limit'] = $limit;
341
+		}
342
+		/** @var EE_Datetime[] $result */
343
+		$result = $this->get_all($query_params);
344
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
345
+		return $result;
346
+	}
347
+
348
+
349
+
350
+	/**
351
+	 * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
352
+	 * datetimes.
353
+	 *
354
+	 * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
355
+	 * @param  boolean  $include_expired whether to include expired datetimes or not
356
+	 * @param  boolean  $include_deleted whether to include trashed datetimes or not.
357
+	 * @param  int|null $limit           if null, no limit, if int then limit results by
358
+	 *                                   that number
359
+	 * @return EE_Datetime[]
360
+	 * @throws \EE_Error
361
+	 */
362
+	public function get_datetimes_for_ticket_ordered_by_DTT_order(
363
+		$TKT_ID,
364
+		$include_expired = true,
365
+		$include_deleted = true,
366
+		$limit = null
367
+	) {
368
+		//sanitize id.
369
+		$TKT_ID = absint($TKT_ID);
370
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
371
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
372
+		$where_params = array('Ticket.TKT_ID' => $TKT_ID);
373
+		$query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
374
+		if ( ! $include_expired) {
375
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
376
+		}
377
+		if ($include_deleted) {
378
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
379
+		}
380
+		if ($limit) {
381
+			$query_params['limit'] = $limit;
382
+		}
383
+		/** @var EE_Datetime[] $result */
384
+		$result = $this->get_all($query_params);
385
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
386
+		return $result;
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
393
+	 * reason it doesn't exist, we consider the earliest event the most important)
394
+	 *
395
+	 * @param int $EVT_ID
396
+	 * @return EE_Datetime
397
+	 * @throws \EE_Error
398
+	 */
399
+	public function get_most_important_datetime_for_event($EVT_ID)
400
+	{
401
+		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
402
+		if ($results) {
403
+			return array_shift($results);
404
+		} else {
405
+			return null;
406
+		}
407
+	}
408
+
409
+
410
+
411
+	/**
412
+	 * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
413
+	 * grouped by month and year.
414
+	 *
415
+	 * @param  array  $where_params      Array of query_params as described in the comments for EEM_Base::get_all()
416
+	 * @param  string $evt_active_status A string representing the evt active status to filter the months by.
417
+	 *                                   Can be:
418
+	 *                                   - '' = no filter
419
+	 *                                   - upcoming = Published events with at least one upcoming datetime.
420
+	 *                                   - expired = Events with all datetimes expired.
421
+	 *                                   - active = Events that are published and have at least one datetime that
422
+	 *                                   starts before now and ends after now.
423
+	 *                                   - inactive = Events that are either not published.
424
+	 * @return EE_Base_Class[]
425
+	 * @throws \EE_Error
426
+	 */
427
+	public function get_dtt_months_and_years($where_params, $evt_active_status = '')
428
+	{
429
+		$current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
430
+		$current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end');
431
+		switch ($evt_active_status) {
432
+			case 'upcoming' :
433
+				$where_params['Event.status'] = 'publish';
434
+				//if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
435
+				if (isset($where_params['DTT_EVT_start'])) {
436
+					$where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
437
+				}
438
+				$where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
439
+				break;
440
+			case 'expired' :
441
+				if (isset($where_params['Event.status'])) {
442
+					unset($where_params['Event.status']);
443
+				}
444
+				//get events to exclude
445
+				$exclude_query[0] = array_merge($where_params,
446
+					array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)));
447
+				//first get all events that have datetimes where its not expired.
448
+				$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID');
449
+				$event_ids = array_keys($event_ids);
450
+				if (isset($where_params['DTT_EVT_end'])) {
451
+					$where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
452
+				}
453
+				$where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end);
454
+				$where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
455
+				break;
456
+			case 'active' :
457
+				$where_params['Event.status'] = 'publish';
458
+				if (isset($where_params['DTT_EVT_start'])) {
459
+					$where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
460
+				}
461
+				if (isset($where_params['Datetime.DTT_EVT_end'])) {
462
+					$where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
463
+				}
464
+				$where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
465
+				$where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end);
466
+				break;
467
+			case 'inactive' :
468
+				if (isset($where_params['Event.status'])) {
469
+					unset($where_params['Event.status']);
470
+				}
471
+				if (isset($where_params['OR'])) {
472
+					$where_params['AND']['OR'] = $where_params['OR'];
473
+				}
474
+				if (isset($where_params['DTT_EVT_end'])) {
475
+					$where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
476
+					unset($where_params['DTT_EVT_end']);
477
+				}
478
+				if (isset($where_params['DTT_EVT_start'])) {
479
+					$where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
480
+					unset($where_params['DTT_EVT_start']);
481
+				}
482
+				$where_params['AND']['Event.status'] = array('!=', 'publish');
483
+				break;
484
+		}
485
+		$query_params[0] = $where_params;
486
+		$query_params['group_by'] = array('dtt_year', 'dtt_month');
487
+		$query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
488
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
489
+		$columns_to_select = array(
490
+			'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
491
+			'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
492
+			'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
493
+		);
494
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
495
+	}
496
+
497
+
498
+
499
+	/**
500
+	 * Updates the DTT_sold attribute on each datetime (based on the registrations
501
+	 * for the tickets for each datetime)
502
+	 *
503
+	 * @param EE_Base_Class[]|EE_Datetime[] $datetimes
504
+	 * @throws \EE_Error
505
+	 */
506
+	public function update_sold($datetimes)
507
+	{
508
+		EE_Error::doing_it_wrong(
509
+			__FUNCTION__,
510
+			esc_html__(
511
+				'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
512
+				'event_espresso'
513
+			),
514
+			'4.9.32.rc.005'
515
+		);
516
+		foreach ($datetimes as $datetime) {
517
+			$datetime->update_sold();
518
+		}
519
+	}
520
+
521
+
522
+
523
+	/**
524
+	 *    Gets the total number of tickets available at a particular datetime
525
+	 *    (does NOT take into account the datetime's spaces available)
526
+	 *
527
+	 * @param int   $DTT_ID
528
+	 * @param array $query_params
529
+	 * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
530
+	 *             tickets attached to datetime then FALSE is returned.
531
+	 */
532
+	public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
533
+	{
534
+		$datetime = $this->get_one_by_ID($DTT_ID);
535
+		if ($datetime instanceof EE_Datetime) {
536
+			return $datetime->tickets_remaining($query_params);
537
+		}
538
+		return 0;
539
+	}
540
+
541
+
542
+
543
+	/**
544
+	 * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
545
+	 *
546
+	 * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
547
+	 *                                 stati you want counts for as values in the array.  An empty array returns counts
548
+	 *                                 for all valid stati.
549
+	 * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
550
+	 *                                 only for Datetimes connected to a specific event, or specific ticket.
551
+	 * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
552
+	 * @throws \EE_Error
553
+	 *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming EE_Datetime::expired
554
+	 */
555
+	public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
556
+	{
557
+		//only accept where conditions for this query.
558
+		$_where = isset($query_params[0]) ? $query_params[0] : array();
559
+		$status_query_args = array(
560
+			EE_Datetime::active   => array_merge(
561
+				$_where,
562
+				array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
563
+			),
564
+			EE_Datetime::upcoming => array_merge(
565
+				$_where,
566
+				array('DTT_EVT_start' => array('>', time()))
567
+			),
568
+			EE_Datetime::expired  => array_merge(
569
+				$_where,
570
+				array('DTT_EVT_end' => array('<', time()))
571
+			),
572
+		);
573
+		if ( ! empty($stati_to_include)) {
574
+			foreach (array_keys($status_query_args) as $status) {
575
+				if ( ! in_array($status, $stati_to_include, true)) {
576
+					unset($status_query_args[$status]);
577
+				}
578
+			}
579
+		}
580
+		//loop through and query counts for each stati.
581
+		$status_query_results = array();
582
+		foreach ($status_query_args as $status => $status_where_conditions) {
583
+			$status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true);
584
+		}
585
+		return $status_query_results;
586
+	}
587
+
588
+
589
+
590
+	/**
591
+	 * Returns the specific count for a given Datetime status matching any given query_params.
592
+	 *
593
+	 * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
594
+	 * @param array  $query_params
595
+	 * @return int
596
+	 * @throws \EE_Error
597
+	 */
598
+	public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
599
+	{
600
+		$count = $this->get_datetime_counts_by_status(array($status), $query_params);
601
+		return ! empty($count[$status]) ? $count[$status] : 0;
602
+	}
603 603
 
604 604
 
605 605
 
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/content-espresso_events-datetimes.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@
 block discarded – undo
1 1
 <?php
2 2
 //echo '<br/><h6 style="color:#2EA2CC;">'. __FILE__ . ' &nbsp; <span style="font-weight:normal;color:#E76700"> Line #: ' . __LINE__ . '</span></h6>';
3 3
 
4
-if ( is_single() || ( is_archive() && espresso_display_datetimes_in_event_list() ) ) :
4
+if (is_single() || (is_archive() && espresso_display_datetimes_in_event_list())) :
5 5
 global $post;
6
-do_action( 'AHEE_event_details_before_event_date', $post );
6
+do_action('AHEE_event_details_before_event_date', $post);
7 7
 ?>
8 8
 	<div class="event-datetimes">
9
-		<?php espresso_list_of_event_dates( $post->ID );?>
9
+		<?php espresso_list_of_event_dates($post->ID); ?>
10 10
 	</div>
11 11
 	<!-- .event-datetimes -->
12 12
 <?php
13
-do_action( 'AHEE_event_details_after_event_date', $post );
13
+do_action('AHEE_event_details_after_event_date', $post);
14 14
 endif;
15 15
 ?>
16 16
\ No newline at end of file
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Payment_List_Shortcodes.lib.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Event Espresso
7 7
  * @subpackage messages
8 8
  */
9
-if (!defined('EVENT_ESPRESSO_VERSION') )
9
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
10 10
 	exit('NO direct script access allowed');
11 11
 
12 12
 /**
@@ -32,18 +32,18 @@  discard block
 block discarded – undo
32 32
 		$this->label = __('Payment List Shortcodes', 'event_espresso');
33 33
 		$this->description = __('All shortcodes specific to payment lists', 'event_espresso');
34 34
 		$this->_shortcodes = array(
35
-			'[PAYMENT_LIST_*]' => __('Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults.  Attributes that are available are:', 'event_espresso') . '<p><ul>' .
36
-				'<li><strong>no_payments</strong>:' . sprintf( __('Indicate with this attribute what will be used if there are no payments present.  Default is: "%sNo approved payments have been received.%s"', 'event_espresso'),  htmlspecialchars('<td class="aln-cntr" colspan="6">'), htmlspecialchars('</td>') ) . '</li>' .
35
+			'[PAYMENT_LIST_*]' => __('Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults.  Attributes that are available are:', 'event_espresso').'<p><ul>'.
36
+				'<li><strong>no_payments</strong>:'.sprintf(__('Indicate with this attribute what will be used if there are no payments present.  Default is: "%sNo approved payments have been received.%s"', 'event_espresso'), htmlspecialchars('<td class="aln-cntr" colspan="6">'), htmlspecialchars('</td>')).'</li>'.
37 37
 				'</ul></p>'
38 38
 			);
39 39
 	}
40 40
 
41 41
 
42 42
 
43
-	protected function _parser( $shortcode ) {
43
+	protected function _parser($shortcode) {
44 44
 
45
-		if ( strpos( $shortcode, '[PAYMENT_LIST_*' ) !== FALSE ) {
46
-			return $this->_get_payment_list( $shortcode );
45
+		if (strpos($shortcode, '[PAYMENT_LIST_*') !== FALSE) {
46
+			return $this->_get_payment_list($shortcode);
47 47
 		}
48 48
 		return '';
49 49
 	}
@@ -60,32 +60,32 @@  discard block
 block discarded – undo
60 60
 	 *
61 61
 	 * @return string parsed ticket line item list.
62 62
 	 */
63
-	private function _get_payment_list( $shortcode ) {
63
+	private function _get_payment_list($shortcode) {
64 64
 		$this->_validate_list_requirements();
65 65
 
66 66
 
67
-		if ( ! $this->_data['data'] instanceof EE_Messages_Addressee ) {
67
+		if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) {
68 68
 			return '';
69 69
 		}
70 70
 
71
-		$valid_shortcodes = array( 'payment' );
71
+		$valid_shortcodes = array('payment');
72 72
 
73 73
 		$addressee_obj = $this->_data['data'];
74 74
 		$templates = $this->_extra_data['template'];
75
-		$payments = apply_filters( 'FHEE__Payment_List_Shortcodes___get_payments_list__payments', $addressee_obj->payments );
75
+		$payments = apply_filters('FHEE__Payment_List_Shortcodes___get_payments_list__payments', $addressee_obj->payments);
76 76
 
77 77
 		//let's get any attributes that may be present and set the defaults.
78
-		$atts = $this->_get_shortcode_attrs( $shortcode );
78
+		$atts = $this->_get_shortcode_attrs($shortcode);
79 79
 
80
-		$no_payments_msg = empty( $atts['no_payments'] ) ?  __('No approved payments have been received.','event_espresso') : $atts['no_payments'];
80
+		$no_payments_msg = empty($atts['no_payments']) ? __('No approved payments have been received.', 'event_espresso') : $atts['no_payments'];
81 81
 
82 82
 		//made it here so we have an array of paymnets, so we should have what we need.
83
-		$payment_content = empty( $payments ) ? $no_payments_msg : '';
83
+		$payment_content = empty($payments) ? $no_payments_msg : '';
84 84
 
85 85
 		$payments = (array) $payments;
86 86
 
87
-		foreach ( $payments as $payment ) {
88
-			$payment_content .= $this->_shortcode_helper->parse_payment_list_template( $templates['payment_list'], $payment, $valid_shortcodes, $this->_extra_data );
87
+		foreach ($payments as $payment) {
88
+			$payment_content .= $this->_shortcode_helper->parse_payment_list_template($templates['payment_list'], $payment, $valid_shortcodes, $this->_extra_data);
89 89
 		}
90 90
 
91 91
 		return $payment_content;
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,8 +6,9 @@
 block discarded – undo
6 6
  * @package Event Espresso
7 7
  * @subpackage messages
8 8
  */
9
-if (!defined('EVENT_ESPRESSO_VERSION') )
9
+if (!defined('EVENT_ESPRESSO_VERSION') ) {
10 10
 	exit('NO direct script access allowed');
11
+}
11 12
 
12 13
 /**
13 14
  *
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Table_Base.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -9,164 +9,164 @@
 block discarded – undo
9 9
 abstract class EE_Table_Base
10 10
 {
11 11
 
12
-    /**
13
-     * This holds the table_name without the table prefix.
14
-     *
15
-     * @var string
16
-     */
17
-    var $_table_name;
18
-
19
-
20
-    /**
21
-     * This holds what is used as the alias for the table in queries.
22
-     *
23
-     * @var string
24
-     */
25
-    var $_table_alias;
26
-
27
-
28
-    /**
29
-     * Table's private key column
30
-     *
31
-     * @var string
32
-     */
33
-    protected $_pk_column;
34
-
35
-
36
-    /**
37
-     * Whether this table is a global table (in multisite) or specific to site.
38
-     *
39
-     * @var bool
40
-     */
41
-    protected $_global;
42
-
43
-
44
-
45
-    /**
46
-     * @global wpdb   $wpdb
47
-     * @param string  $table_name with or without wpdb prefix
48
-     * @param string  $pk_column
49
-     * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
50
-     *                            install, or whether each site on a multisite install has a copy of this table
51
-     */
52
-    function __construct($table_name, $pk_column, $global = false)
53
-    {
54
-        $this->_global = $global;
55
-        $prefix = $this->get_table_prefix();
56
-        //if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
57
-        if (strpos($table_name, $prefix) === 0) {
58
-            $table_name = ltrim($table_name, $prefix);
59
-        }
60
-        $this->_table_name = $table_name;
61
-        $this->_pk_column = $pk_column;
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * This returns the table prefix for the current model state.
68
-     *
69
-     * @global wpdb $wpdb
70
-     * @return string
71
-     */
72
-    public function get_table_prefix()
73
-    {
74
-        global $wpdb;
75
-        if ($this->_global) {
76
-            $prefix = $wpdb->base_prefix;
77
-        } else {
78
-            $prefix = $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
79
-        }
80
-        return $prefix;
81
-    }
82
-
83
-
84
-
85
-    /**
86
-     * Used to set the table_alias property
87
-     *
88
-     * @param string $table_alias
89
-     */
90
-    function _construct_finalize_with_alias($table_alias)
91
-    {
92
-        $this->_table_alias = $table_alias;
93
-    }
94
-
95
-
96
-
97
-    /**
98
-     * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
99
-     *
100
-     * @return string
101
-     */
102
-    function get_table_name()
103
-    {
104
-        return $this->get_table_prefix() . $this->_table_name;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * Provides what is currently set as the alias for the table to be used in queries.
111
-     *
112
-     * @return string
113
-     * @throws EE_Error
114
-     */
115
-    function get_table_alias()
116
-    {
117
-        if ( ! $this->_table_alias) {
118
-            throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
119
-        }
120
-        return $this->_table_alias;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * @return string name of column of PK
127
-     */
128
-    function get_pk_column()
129
-    {
130
-        return $this->_pk_column;
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     * returns a string with the table alias, a period, and the private key's column.
137
-     *
138
-     * @return string
139
-     */
140
-    function get_fully_qualified_pk_column()
141
-    {
142
-        $sql = $this->get_table_alias() . "." . $this->get_pk_column();
143
-        return $sql;
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * returns the special sql for a inner select with a limit.
150
-     *
151
-     * @return string    SQL select
152
-     */
153
-    public function get_select_join_limit($limit)
154
-    {
155
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit;
156
-        $SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
157
-        return $SQL;
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * Returns whether or not htis is a global table (ie, on multisite there's
164
-     * only one of these tables, on the main blog)
165
-     *
166
-     * @return boolean
167
-     */
168
-    public function is_global()
169
-    {
170
-        return $this->_global;
171
-    }
12
+	/**
13
+	 * This holds the table_name without the table prefix.
14
+	 *
15
+	 * @var string
16
+	 */
17
+	var $_table_name;
18
+
19
+
20
+	/**
21
+	 * This holds what is used as the alias for the table in queries.
22
+	 *
23
+	 * @var string
24
+	 */
25
+	var $_table_alias;
26
+
27
+
28
+	/**
29
+	 * Table's private key column
30
+	 *
31
+	 * @var string
32
+	 */
33
+	protected $_pk_column;
34
+
35
+
36
+	/**
37
+	 * Whether this table is a global table (in multisite) or specific to site.
38
+	 *
39
+	 * @var bool
40
+	 */
41
+	protected $_global;
42
+
43
+
44
+
45
+	/**
46
+	 * @global wpdb   $wpdb
47
+	 * @param string  $table_name with or without wpdb prefix
48
+	 * @param string  $pk_column
49
+	 * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
50
+	 *                            install, or whether each site on a multisite install has a copy of this table
51
+	 */
52
+	function __construct($table_name, $pk_column, $global = false)
53
+	{
54
+		$this->_global = $global;
55
+		$prefix = $this->get_table_prefix();
56
+		//if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
57
+		if (strpos($table_name, $prefix) === 0) {
58
+			$table_name = ltrim($table_name, $prefix);
59
+		}
60
+		$this->_table_name = $table_name;
61
+		$this->_pk_column = $pk_column;
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * This returns the table prefix for the current model state.
68
+	 *
69
+	 * @global wpdb $wpdb
70
+	 * @return string
71
+	 */
72
+	public function get_table_prefix()
73
+	{
74
+		global $wpdb;
75
+		if ($this->_global) {
76
+			$prefix = $wpdb->base_prefix;
77
+		} else {
78
+			$prefix = $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
79
+		}
80
+		return $prefix;
81
+	}
82
+
83
+
84
+
85
+	/**
86
+	 * Used to set the table_alias property
87
+	 *
88
+	 * @param string $table_alias
89
+	 */
90
+	function _construct_finalize_with_alias($table_alias)
91
+	{
92
+		$this->_table_alias = $table_alias;
93
+	}
94
+
95
+
96
+
97
+	/**
98
+	 * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
99
+	 *
100
+	 * @return string
101
+	 */
102
+	function get_table_name()
103
+	{
104
+		return $this->get_table_prefix() . $this->_table_name;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * Provides what is currently set as the alias for the table to be used in queries.
111
+	 *
112
+	 * @return string
113
+	 * @throws EE_Error
114
+	 */
115
+	function get_table_alias()
116
+	{
117
+		if ( ! $this->_table_alias) {
118
+			throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
119
+		}
120
+		return $this->_table_alias;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * @return string name of column of PK
127
+	 */
128
+	function get_pk_column()
129
+	{
130
+		return $this->_pk_column;
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 * returns a string with the table alias, a period, and the private key's column.
137
+	 *
138
+	 * @return string
139
+	 */
140
+	function get_fully_qualified_pk_column()
141
+	{
142
+		$sql = $this->get_table_alias() . "." . $this->get_pk_column();
143
+		return $sql;
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * returns the special sql for a inner select with a limit.
150
+	 *
151
+	 * @return string    SQL select
152
+	 */
153
+	public function get_select_join_limit($limit)
154
+	{
155
+		$limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit;
156
+		$SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
157
+		return $SQL;
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * Returns whether or not htis is a global table (ie, on multisite there's
164
+	 * only one of these tables, on the main blog)
165
+	 *
166
+	 * @return boolean
167
+	 */
168
+	public function is_global()
169
+	{
170
+		return $this->_global;
171
+	}
172 172
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      */
102 102
     function get_table_name()
103 103
     {
104
-        return $this->get_table_prefix() . $this->_table_name;
104
+        return $this->get_table_prefix().$this->_table_name;
105 105
     }
106 106
 
107 107
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     function get_fully_qualified_pk_column()
141 141
     {
142
-        $sql = $this->get_table_alias() . "." . $this->get_pk_column();
142
+        $sql = $this->get_table_alias().".".$this->get_pk_column();
143 143
         return $sql;
144 144
     }
145 145
 
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function get_select_join_limit($limit)
154 154
     {
155
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit;
156
-        $SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
155
+        $limit = is_array($limit) ? 'LIMIT '.implode(',', array_map('intval', $limit)) : 'LIMIT '.(int) $limit;
156
+        $SQL = SP.'(SELECT * FROM '.$this->_table_name.SP.$limit.') AS '.$this->_table_alias;
157 157
         return $SQL;
158 158
     }
159 159
 
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1247,7 +1247,7 @@
 block discarded – undo
1247 1247
     /**
1248 1248
      * Sets up the limit for the registrations query.
1249 1249
      *
1250
-     * @param $per_page
1250
+     * @param integer $per_page
1251 1251
      * @return array
1252 1252
      */
1253 1253
     protected function _get_limit($per_page)
Please login to merge, or discard this patch.
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         // when adding a new registration...
70 70
         if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71 71
             EE_System::do_not_cache();
72
-            if (! isset($this->_req_data['processing_registration'])
72
+            if ( ! isset($this->_req_data['processing_registration'])
73 73
                  || absint($this->_req_data['processing_registration']) !== 1
74 74
             ) {
75 75
                 // and it's NOT the attendee information reg step
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
     public function _set_page_routes()
165 165
     {
166 166
         $this->_get_registration_status_array();
167
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
167
+        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168 168
             ? $this->_req_data['_REG_ID'] : 0;
169 169
         $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
170 170
             ? $this->_req_data['reg_status_change_form']['REG_ID']
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
         //style
647 647
         wp_register_style(
648 648
             'espresso_reg',
649
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
649
+            REG_ASSETS_URL.'espresso_registrations_admin.css',
650 650
             array('ee-admin-css'),
651 651
             EVENT_ESPRESSO_VERSION
652 652
         );
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
         //script
655 655
         wp_register_script(
656 656
             'espresso_reg',
657
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
657
+            REG_ASSETS_URL.'espresso_registrations_admin.js',
658 658
             array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
659 659
             EVENT_ESPRESSO_VERSION,
660 660
             true
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
         wp_deregister_style('espresso_reg');
693 693
         wp_register_style(
694 694
             'espresso_att',
695
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
695
+            REG_ASSETS_URL.'espresso_attendees_admin.css',
696 696
             array('ee-admin-css'),
697 697
             EVENT_ESPRESSO_VERSION
698 698
         );
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
     {
705 705
         wp_register_script(
706 706
             'ee-spco-for-admin',
707
-            REG_ASSETS_URL . 'spco_for_admin.js',
707
+            REG_ASSETS_URL.'spco_for_admin.js',
708 708
             array('underscore', 'jquery'),
709 709
             EVENT_ESPRESSO_VERSION,
710 710
             true
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
                     'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
838 838
                 ),
839 839
             );
840
-            $this->_views['trash']      = array(
840
+            $this->_views['trash'] = array(
841 841
                 'slug'        => 'trash',
842 842
                 'label'       => esc_html__('Trash', 'event_espresso'),
843 843
                 'count'       => 0,
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
         }
927 927
         $sc_items = array(
928 928
             'approved_status'   => array(
929
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
929
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
930 930
                 'desc'  => EEH_Template::pretty_status(
931 931
                     EEM_Registration::status_id_approved,
932 932
                     false,
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
                 ),
935 935
             ),
936 936
             'pending_status'    => array(
937
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
937
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
938 938
                 'desc'  => EEH_Template::pretty_status(
939 939
                     EEM_Registration::status_id_pending_payment,
940 940
                     false,
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
                 ),
943 943
             ),
944 944
             'wait_list'         => array(
945
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
945
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
946 946
                 'desc'  => EEH_Template::pretty_status(
947 947
                     EEM_Registration::status_id_wait_list,
948 948
                     false,
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
                 ),
951 951
             ),
952 952
             'incomplete_status' => array(
953
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
953
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete,
954 954
                 'desc'  => EEH_Template::pretty_status(
955 955
                     EEM_Registration::status_id_incomplete,
956 956
                     false,
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
                 ),
959 959
             ),
960 960
             'not_approved'      => array(
961
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
961
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
962 962
                 'desc'  => EEH_Template::pretty_status(
963 963
                     EEM_Registration::status_id_not_approved,
964 964
                     false,
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
                 ),
967 967
             ),
968 968
             'declined_status'   => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
969
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
970 970
                 'desc'  => EEH_Template::pretty_status(
971 971
                     EEM_Registration::status_id_declined,
972 972
                     false,
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
                 ),
975 975
             ),
976 976
             'cancelled_status'  => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
977
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
978 978
                 'desc'  => EEH_Template::pretty_status(
979 979
                     EEM_Registration::status_id_cancelled,
980 980
                     false,
@@ -1003,7 +1003,7 @@  discard block
 block discarded – undo
1003 1003
                 'espresso_registrations_new_registration',
1004 1004
                 $EVT_ID
1005 1005
             )) {
1006
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1006
+                $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1007 1007
                     'new_registration',
1008 1008
                     'add-registrant',
1009 1009
                     array('event_id' => $EVT_ID),
@@ -1043,7 +1043,7 @@  discard block
 block discarded – undo
1043 1043
                 $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1044 1044
                 $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1045 1045
                 $this->_template_args['admin_page_header'] .= $datetime->name();
1046
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1046
+                $this->_template_args['admin_page_header'] .= ' ( '.$datetime->start_date().' )';
1047 1047
                 $this->_template_args['admin_page_header'] .= '</span></h3>';
1048 1048
             }
1049 1049
         }
@@ -1143,7 +1143,7 @@  discard block
 block discarded – undo
1143 1143
             'caps'                     => EEM_Registration::caps_read_admin,
1144 1144
             'default_where_conditions' => 'this_model_only',
1145 1145
         );
1146
-        if (! $count) {
1146
+        if ( ! $count) {
1147 1147
             $query_params = array_merge(
1148 1148
                 $query_params,
1149 1149
                 $this->_get_orderby_for_registrations_query(),
@@ -1164,7 +1164,7 @@  discard block
 block discarded – undo
1164 1164
     protected function _add_event_id_to_where_conditions(array $request)
1165 1165
     {
1166 1166
         $where = array();
1167
-        if (! empty($request['event_id'])) {
1167
+        if ( ! empty($request['event_id'])) {
1168 1168
             $where['EVT_ID'] = absint($request['event_id']);
1169 1169
         }
1170 1170
         return $where;
@@ -1180,7 +1180,7 @@  discard block
 block discarded – undo
1180 1180
     protected function _add_category_id_to_where_conditions(array $request)
1181 1181
     {
1182 1182
         $where = array();
1183
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1183
+        if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1184 1184
             $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1185 1185
         }
1186 1186
         return $where;
@@ -1196,10 +1196,10 @@  discard block
 block discarded – undo
1196 1196
     protected function _add_datetime_id_to_where_conditions(array $request)
1197 1197
     {
1198 1198
         $where = array();
1199
-        if (! empty($request['datetime_id'])) {
1199
+        if ( ! empty($request['datetime_id'])) {
1200 1200
             $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1201 1201
         }
1202
-        if (! empty($request['DTT_ID'])) {
1202
+        if ( ! empty($request['DTT_ID'])) {
1203 1203
             $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1204 1204
         }
1205 1205
         return $where;
@@ -1225,7 +1225,7 @@  discard block
 block discarded – undo
1225 1225
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1226 1226
          * UNLESS viewing trashed registrations.
1227 1227
          */
1228
-        if (! empty($registration_status)) {
1228
+        if ( ! empty($registration_status)) {
1229 1229
             $where['STS_ID'] = $registration_status;
1230 1230
         } else {
1231 1231
             //make sure we exclude incomplete registrations, but only if not trashed.
@@ -1265,12 +1265,12 @@  discard block
 block discarded – undo
1265 1265
                 array(
1266 1266
                     EEM_Registration::instance()->convert_datetime_for_query(
1267 1267
                         'REG_date',
1268
-                        $now . ' 00:00:00',
1268
+                        $now.' 00:00:00',
1269 1269
                         'Y-m-d H:i:s'
1270 1270
                     ),
1271 1271
                     EEM_Registration::instance()->convert_datetime_for_query(
1272 1272
                         'REG_date',
1273
-                        $now . ' 23:59:59',
1273
+                        $now.' 23:59:59',
1274 1274
                         'Y-m-d H:i:s'
1275 1275
                     ),
1276 1276
                 ),
@@ -1283,12 +1283,12 @@  discard block
 block discarded – undo
1283 1283
                 array(
1284 1284
                     EEM_Registration::instance()->convert_datetime_for_query(
1285 1285
                         'REG_date',
1286
-                        $current_year_and_month . '-01 00:00:00',
1286
+                        $current_year_and_month.'-01 00:00:00',
1287 1287
                         'Y-m-d H:i:s'
1288 1288
                     ),
1289 1289
                     EEM_Registration::instance()->convert_datetime_for_query(
1290 1290
                         'REG_date',
1291
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1291
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
1292 1292
                         'Y-m-d H:i:s'
1293 1293
                     ),
1294 1294
                 ),
@@ -1303,18 +1303,18 @@  discard block
 block discarded – undo
1303 1303
                 : '';
1304 1304
             //if there is not a month or year then we can't go further
1305 1305
             if ($month_requested && $year_requested) {
1306
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1306
+                $days_in_month     = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
1307 1307
                 $where['REG_date'] = array(
1308 1308
                     'BETWEEN',
1309 1309
                     array(
1310 1310
                         EEM_Registration::instance()->convert_datetime_for_query(
1311 1311
                             'REG_date',
1312
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1312
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
1313 1313
                             'Y-m-d H:i:s'
1314 1314
                         ),
1315 1315
                         EEM_Registration::instance()->convert_datetime_for_query(
1316 1316
                             'REG_date',
1317
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1317
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
1318 1318
                             'Y-m-d H:i:s'
1319 1319
                         ),
1320 1320
                     ),
@@ -1334,8 +1334,8 @@  discard block
 block discarded – undo
1334 1334
     protected function _add_search_to_where_conditions(array $request)
1335 1335
     {
1336 1336
         $where = array();
1337
-        if (! empty($request['s'])) {
1338
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1337
+        if ( ! empty($request['s'])) {
1338
+            $search_string = '%'.sanitize_text_field($request['s']).'%';
1339 1339
             $where['OR*search_conditions'] = array(
1340 1340
                 'Event.EVT_name'                          => array('LIKE', $search_string),
1341 1341
                 'Event.EVT_desc'                          => array('LIKE', $search_string),
@@ -1448,7 +1448,7 @@  discard block
 block discarded – undo
1448 1448
             : $per_page;
1449 1449
 
1450 1450
         //-1 means return all results so get out if that's set.
1451
-        if ((int)$per_page === -1) {
1451
+        if ((int) $per_page === -1) {
1452 1452
             return array();
1453 1453
         }
1454 1454
         $per_page = absint($per_page);
@@ -1501,7 +1501,7 @@  discard block
 block discarded – undo
1501 1501
                 ),
1502 1502
                 REG_ADMIN_URL
1503 1503
             );
1504
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1504
+            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1505 1505
                 array(
1506 1506
                     'action' => 'default',
1507 1507
                     'EVT_ID' => $event_id,
@@ -1509,7 +1509,7 @@  discard block
 block discarded – undo
1509 1509
                 ),
1510 1510
                 admin_url('admin.php')
1511 1511
             );
1512
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1512
+            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1513 1513
                 array(
1514 1514
                     'page'   => 'espresso_events',
1515 1515
                     'action' => 'edit',
@@ -1518,12 +1518,12 @@  discard block
 block discarded – undo
1518 1518
                 admin_url('admin.php')
1519 1519
             );
1520 1520
             //next and previous links
1521
-            $next_reg                                      = $this->_registration->next(
1521
+            $next_reg = $this->_registration->next(
1522 1522
                 null,
1523 1523
                 array(),
1524 1524
                 'REG_ID'
1525 1525
             );
1526
-            $this->_template_args['next_registration']     = $next_reg
1526
+            $this->_template_args['next_registration'] = $next_reg
1527 1527
                 ? $this->_next_link(
1528 1528
                     EE_Admin_Page::add_query_args_and_nonce(
1529 1529
                         array(
@@ -1535,7 +1535,7 @@  discard block
 block discarded – undo
1535 1535
                     'dashicons dashicons-arrow-right ee-icon-size-22'
1536 1536
                 )
1537 1537
                 : '';
1538
-            $previous_reg                                  = $this->_registration->previous(
1538
+            $previous_reg = $this->_registration->previous(
1539 1539
                 null,
1540 1540
                 array(),
1541 1541
                 'REG_ID'
@@ -1553,7 +1553,7 @@  discard block
 block discarded – undo
1553 1553
                 )
1554 1554
                 : '';
1555 1555
             // grab header
1556
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1556
+            $template_path                             = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1557 1557
             $this->_template_args['REG_ID']            = $this->_registration->ID();
1558 1558
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1559 1559
                 $template_path,
@@ -1669,7 +1669,7 @@  discard block
 block discarded – undo
1669 1669
                             EEH_HTML::strong(
1670 1670
                                 $this->_registration->pretty_status(),
1671 1671
                                 '',
1672
-                                'status-' . $this->_registration->status_ID(),
1672
+                                'status-'.$this->_registration->status_ID(),
1673 1673
                                 'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1674 1674
                             )
1675 1675
                         )
@@ -1741,9 +1741,9 @@  discard block
 block discarded – undo
1741 1741
     {
1742 1742
         if (isset($this->_req_data['reg_status_change_form'])) {
1743 1743
             $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1744
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1744
+                ? (array) $this->_req_data['reg_status_change_form']['REG_ID'] : array();
1745 1745
         } else {
1746
-            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1746
+            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array) $this->_req_data['_REG_ID'] : array();
1747 1747
         }
1748 1748
         $success = $this->_set_registration_status($REG_IDs, $status);
1749 1749
         //notify?
@@ -1778,7 +1778,7 @@  discard block
 block discarded – undo
1778 1778
     {
1779 1779
         $success = false;
1780 1780
         // typecast $REG_IDs
1781
-        $REG_IDs = (array)$REG_IDs;
1781
+        $REG_IDs = (array) $REG_IDs;
1782 1782
         if ( ! empty($REG_IDs)) {
1783 1783
             $success = true;
1784 1784
             // set default status if none is passed
@@ -1917,7 +1917,7 @@  discard block
 block discarded – undo
1917 1917
             $action,
1918 1918
             $notify
1919 1919
         );
1920
-        $method = $action . '_registration';
1920
+        $method = $action.'_registration';
1921 1921
         if (method_exists($this, $method)) {
1922 1922
             $this->$method($notify);
1923 1923
         }
@@ -2031,7 +2031,7 @@  discard block
 block discarded – undo
2031 2031
             $filtered_line_item_tree,
2032 2032
             array('EE_Registration' => $this->_registration)
2033 2033
         );
2034
-        $attendee                                = $this->_registration->attendee();
2034
+        $attendee = $this->_registration->attendee();
2035 2035
         if (EE_Registry::instance()->CAP->current_user_can(
2036 2036
             'ee_read_transaction',
2037 2037
             'espresso_transactions_view_transaction'
@@ -2110,7 +2110,7 @@  discard block
 block discarded – undo
2110 2110
                 'Payment method response',
2111 2111
                 'event_espresso'
2112 2112
             );
2113
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2113
+            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2114 2114
         }
2115 2115
         $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2116 2116
         $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
@@ -2138,7 +2138,7 @@  discard block
 block discarded – undo
2138 2138
         $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2139 2139
         $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2140 2140
         $template_path                                                        =
2141
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2141
+            REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2142 2142
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2143 2143
     }
2144 2144
 
@@ -2167,7 +2167,7 @@  discard block
 block discarded – undo
2167 2167
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2168 2168
             $this->_template_args['REG_ID']                    = $this->_registration->ID();
2169 2169
             $template_path                                     =
2170
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2170
+                REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2171 2171
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
2172 2172
         }
2173 2173
     }
@@ -2184,7 +2184,7 @@  discard block
 block discarded – undo
2184 2184
     public function form_before_question_group($output)
2185 2185
     {
2186 2186
         EE_Error::doing_it_wrong(
2187
-            __CLASS__ . '::' . __FUNCTION__,
2187
+            __CLASS__.'::'.__FUNCTION__,
2188 2188
             esc_html__(
2189 2189
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2190 2190
                 'event_espresso'
@@ -2209,7 +2209,7 @@  discard block
 block discarded – undo
2209 2209
     public function form_after_question_group($output)
2210 2210
     {
2211 2211
         EE_Error::doing_it_wrong(
2212
-            __CLASS__ . '::' . __FUNCTION__,
2212
+            __CLASS__.'::'.__FUNCTION__,
2213 2213
             esc_html__(
2214 2214
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2215 2215
                 'event_espresso'
@@ -2247,7 +2247,7 @@  discard block
 block discarded – undo
2247 2247
     public function form_form_field_label_wrap($label)
2248 2248
     {
2249 2249
         EE_Error::doing_it_wrong(
2250
-            __CLASS__ . '::' . __FUNCTION__,
2250
+            __CLASS__.'::'.__FUNCTION__,
2251 2251
             esc_html__(
2252 2252
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2253 2253
                 'event_espresso'
@@ -2257,7 +2257,7 @@  discard block
 block discarded – undo
2257 2257
         return '
2258 2258
 			<tr>
2259 2259
 				<th>
2260
-					' . $label . '
2260
+					' . $label.'
2261 2261
 				</th>';
2262 2262
     }
2263 2263
 
@@ -2273,7 +2273,7 @@  discard block
 block discarded – undo
2273 2273
     public function form_form_field_input__wrap($input)
2274 2274
     {
2275 2275
         EE_Error::doing_it_wrong(
2276
-            __CLASS__ . '::' . __FUNCTION__,
2276
+            __CLASS__.'::'.__FUNCTION__,
2277 2277
             esc_html__(
2278 2278
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2279 2279
                 'event_espresso'
@@ -2282,7 +2282,7 @@  discard block
 block discarded – undo
2282 2282
         );
2283 2283
         return '
2284 2284
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2285
-					' . $input . '
2285
+					' . $input.'
2286 2286
 				</td>
2287 2287
 			</tr>';
2288 2288
     }
@@ -2324,7 +2324,7 @@  discard block
 block discarded – undo
2324 2324
     protected function _get_reg_custom_questions_form($REG_ID)
2325 2325
     {
2326 2326
         if ( ! $this->_reg_custom_questions_form) {
2327
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2327
+            require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php');
2328 2328
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2329 2329
                 EEM_Registration::instance()->get_one_by_ID($REG_ID)
2330 2330
             );
@@ -2357,7 +2357,7 @@  discard block
 block discarded – undo
2357 2357
         if ($form->is_valid()) {
2358 2358
             foreach ($form->subforms() as $question_group_id => $question_group_form) {
2359 2359
                 foreach ($question_group_form->inputs() as $question_id => $input) {
2360
-                    $where_conditions    = array(
2360
+                    $where_conditions = array(
2361 2361
                         'QST_ID' => $question_id,
2362 2362
                         'REG_ID' => $REG_ID,
2363 2363
                     );
@@ -2395,7 +2395,7 @@  discard block
 block discarded – undo
2395 2395
         $REG = EEM_Registration::instance();
2396 2396
         //get all other registrations on this transaction, and cache
2397 2397
         //the attendees for them so we don't have to run another query using force_join
2398
-        $registrations                           = $REG->get_all(array(
2398
+        $registrations = $REG->get_all(array(
2399 2399
             array(
2400 2400
                 'TXN_ID' => $this->_registration->transaction_ID(),
2401 2401
                 'REG_ID' => array('!=', $this->_registration->ID()),
@@ -2419,7 +2419,7 @@  discard block
 block discarded – undo
2419 2419
             $att_nmbr = 1;
2420 2420
             foreach ($registrations as $registration) {
2421 2421
                 /* @var $registration EE_Registration */
2422
-                $attendee                                                    = $registration->attendee()
2422
+                $attendee = $registration->attendee()
2423 2423
                     ? $registration->attendee()
2424 2424
                     : EEM_Attendee::instance()
2425 2425
                                   ->create_default_object();
@@ -2432,19 +2432,19 @@  discard block
 block discarded – undo
2432 2432
                     ', ',
2433 2433
                     $attendee->full_address_as_array()
2434 2434
                 );
2435
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2435
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2436 2436
                     array(
2437 2437
                         'action' => 'edit_attendee',
2438 2438
                         'post'   => $attendee->ID(),
2439 2439
                     ),
2440 2440
                     REG_ADMIN_URL
2441 2441
                 );
2442
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2442
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name();
2443 2443
                 $att_nmbr++;
2444 2444
             }
2445 2445
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2446 2446
         }
2447
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2447
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2448 2448
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2449 2449
     }
2450 2450
 
@@ -2484,20 +2484,20 @@  discard block
 block discarded – undo
2484 2484
         $this->_template_args['phone']             = $attendee->phone();
2485 2485
         $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2486 2486
         //edit link
2487
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2487
+        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
2488 2488
             'action' => 'edit_attendee',
2489 2489
             'post'   => $attendee->ID(),
2490 2490
         ), REG_ADMIN_URL);
2491 2491
         $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2492 2492
         //create link
2493
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2493
+        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2494 2494
             ? EE_Admin_Page::add_query_args_and_nonce(array(
2495 2495
                 'action'  => 'duplicate_attendee',
2496 2496
                 '_REG_ID' => $this->_registration->ID(),
2497 2497
             ), REG_ADMIN_URL) : '';
2498 2498
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2499 2499
         $this->_template_args['att_check']    = $att_check;
2500
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2500
+        $template_path                        = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2501 2501
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2502 2502
     }
2503 2503
 
@@ -2539,7 +2539,7 @@  discard block
 block discarded – undo
2539 2539
             /** @var EE_Registration $REG */
2540 2540
             $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2541 2541
             $payments = $REG->registration_payments();
2542
-            if (! empty($payments)) {
2542
+            if ( ! empty($payments)) {
2543 2543
                 $name = $REG->attendee() instanceof EE_Attendee
2544 2544
                     ? $REG->attendee()->full_name()
2545 2545
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2732,7 +2732,7 @@  discard block
 block discarded – undo
2732 2732
                 'action' => 'edit',
2733 2733
                 'post'   => $this->_reg_event->ID(),
2734 2734
             ), EVENTS_ADMIN_URL);
2735
-            $edit_event_lnk                     = '<a href="'
2735
+            $edit_event_lnk = '<a href="'
2736 2736
                                                   . $edit_event_url
2737 2737
                                                   . '" title="'
2738 2738
                                                   . esc_attr__('Edit ', 'event_espresso')
@@ -2750,7 +2750,7 @@  discard block
 block discarded – undo
2750 2750
         }
2751 2751
         // grab header
2752 2752
         $template_path                              =
2753
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2753
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2754 2754
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2755 2755
             $this->_template_args, true);
2756 2756
         //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
@@ -2785,7 +2785,7 @@  discard block
 block discarded – undo
2785 2785
                 '</b>'
2786 2786
             );
2787 2787
             return '
2788
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2788
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
2789 2789
 	<script >
2790 2790
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2791 2791
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -2853,7 +2853,7 @@  discard block
 block discarded – undo
2853 2853
         //we come back to the process_registration_step route.
2854 2854
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2855 2855
         return EEH_Template::display_template(
2856
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2856
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
2857 2857
             $template_args,
2858 2858
             true
2859 2859
         );
@@ -2872,7 +2872,7 @@  discard block
 block discarded – undo
2872 2872
         if (is_object($this->_reg_event)) {
2873 2873
             return true;
2874 2874
         }
2875
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2875
+        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2876 2876
         if ( ! $EVT_ID) {
2877 2877
             return false;
2878 2878
         }
@@ -2938,7 +2938,7 @@  discard block
 block discarded – undo
2938 2938
                 }
2939 2939
                 break;
2940 2940
             case 'questions' :
2941
-                if (! isset(
2941
+                if ( ! isset(
2942 2942
                     $this->_req_data['txn_reg_status_change'],
2943 2943
                     $this->_req_data['txn_reg_status_change']['send_notifications'])
2944 2944
                 ) {
@@ -3052,7 +3052,7 @@  discard block
 block discarded – undo
3052 3052
     public function get_attendees($per_page, $count = false, $trash = false)
3053 3053
     {
3054 3054
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3055
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3055
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
3056 3056
         $ATT_MDL                    = EEM_Attendee::instance();
3057 3057
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3058 3058
         switch ($this->_req_data['orderby']) {
@@ -3089,7 +3089,7 @@  discard block
 block discarded – undo
3089 3089
             : $per_page;
3090 3090
         $_where       = array();
3091 3091
         if ( ! empty($this->_req_data['s'])) {
3092
-            $sstr         = '%' . $this->_req_data['s'] . '%';
3092
+            $sstr         = '%'.$this->_req_data['s'].'%';
3093 3093
             $_where['OR'] = array(
3094 3094
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3095 3095
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -3165,9 +3165,9 @@  discard block
 block discarded – undo
3165 3165
      *                                                     the query parameters from the request
3166 3166
      * @return void ends the request with a redirect or download
3167 3167
      */
3168
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3168
+    public function _registrations_report_base($method_name_for_getting_query_params)
3169 3169
     {
3170
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3170
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3171 3171
             wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3172 3172
                 array(
3173 3173
                     'page'        => 'espresso_batch',
@@ -3176,7 +3176,7 @@  discard block
 block discarded – undo
3176 3176
                     'filters'     => urlencode(
3177 3177
                         serialize(
3178 3178
                             call_user_func(
3179
-                                array( $this, $method_name_for_getting_query_params ),
3179
+                                array($this, $method_name_for_getting_query_params),
3180 3180
                                 EEH_Array::is_set(
3181 3181
                                     $this->_req_data,
3182 3182
                                     'filters',
@@ -3196,8 +3196,8 @@  discard block
 block discarded – undo
3196 3196
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3197 3197
             );
3198 3198
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
3199
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3200
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3199
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3200
+                require_once(EE_CLASSES.'EE_Export.class.php');
3201 3201
                 $EE_Export = EE_Export::instance($this->_req_data);
3202 3202
                 $EE_Export->export();
3203 3203
             }
@@ -3218,8 +3218,8 @@  discard block
 block discarded – undo
3218 3218
 
3219 3219
     public function _contact_list_export()
3220 3220
     {
3221
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3222
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3221
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3222
+            require_once(EE_CLASSES.'EE_Export.class.php');
3223 3223
             $EE_Export = EE_Export::instance($this->_req_data);
3224 3224
             $EE_Export->export_attendees();
3225 3225
         }
@@ -3236,8 +3236,8 @@  discard block
 block discarded – undo
3236 3236
                 'return_url'  => urlencode($this->_req_data['return_url']),
3237 3237
             )));
3238 3238
         } else {
3239
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3240
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3239
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3240
+                require_once(EE_CLASSES.'EE_Export.class.php');
3241 3241
                 $EE_Export = EE_Export::instance($this->_req_data);
3242 3242
                 $EE_Export->report_attendees();
3243 3243
             }
@@ -3303,7 +3303,7 @@  discard block
 block discarded – undo
3303 3303
             $updated_fields = array(
3304 3304
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
3305 3305
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
3306
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3306
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
3307 3307
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3308 3308
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3309 3309
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -3436,7 +3436,7 @@  discard block
 block discarded – undo
3436 3436
     {
3437 3437
         //get attendee object ( should already have it )
3438 3438
         $this->_template_args['attendee'] = $this->_cpt_model_obj;
3439
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3439
+        $template                         = REG_TEMPLATE_PATH.'attendee_contact_info_metabox_content.template.php';
3440 3440
         EEH_Template::display_template($template, $this->_template_args);
3441 3441
     }
3442 3442
 
@@ -3498,8 +3498,8 @@  discard block
 block discarded – undo
3498 3498
                 )
3499 3499
             )
3500 3500
         );
3501
-        $template                             =
3502
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3501
+        $template =
3502
+            REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3503 3503
         EEH_Template::display_template($template, $this->_template_args);
3504 3504
     }
3505 3505
 
@@ -3518,7 +3518,7 @@  discard block
 block discarded – undo
3518 3518
         $this->_template_args['attendee']      = $this->_cpt_model_obj;
3519 3519
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3520 3520
         $template                              =
3521
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3521
+            REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3522 3522
         EEH_Template::display_template($template, $this->_template_args);
3523 3523
     }
3524 3524
 
@@ -3533,7 +3533,7 @@  discard block
 block discarded – undo
3533 3533
     public function after_title_form_fields($post)
3534 3534
     {
3535 3535
         if ($post->post_type == 'espresso_attendees') {
3536
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3536
+            $template                  = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3537 3537
             $template_args['attendee'] = $this->_cpt_model_obj;
3538 3538
             EEH_Template::display_template($template, $template_args);
3539 3539
         }
Please login to merge, or discard this patch.
Indentation   +3531 added lines, -3531 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
 
@@ -23,2217 +23,2217 @@  discard block
 block discarded – undo
23 23
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registration
28
-     */
29
-    private $_registration;
30
-
31
-    /**
32
-     * @var EE_Event
33
-     */
34
-    private $_reg_event;
35
-
36
-    /**
37
-     * @var EE_Session
38
-     */
39
-    private $_session;
40
-
41
-    private static $_reg_status;
42
-
43
-    /**
44
-     * Form for displaying the custom questions for this registration.
45
-     * This gets used a few times throughout the request so its best to cache it
46
-     *
47
-     * @var EE_Registration_Custom_Questions_Form
48
-     */
49
-    protected $_reg_custom_questions_form = null;
50
-
51
-
52
-    /**
53
-     *        constructor
54
-     *
55
-     * @Constructor
56
-     * @access public
57
-     * @param bool $routing
58
-     * @return Registrations_Admin_Page
59
-     */
60
-    public function __construct($routing = true)
61
-    {
62
-        parent::__construct($routing);
63
-        add_action('wp_loaded', array($this, 'wp_loaded'));
64
-    }
65
-
66
-
67
-    public function wp_loaded()
68
-    {
69
-        // when adding a new registration...
70
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
-            EE_System::do_not_cache();
72
-            if (! isset($this->_req_data['processing_registration'])
73
-                 || absint($this->_req_data['processing_registration']) !== 1
74
-            ) {
75
-                // and it's NOT the attendee information reg step
76
-                // force cookie expiration by setting time to last week
77
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
-                // and update the global
79
-                $_COOKIE['ee_registration_added'] = 0;
80
-            }
81
-        }
82
-    }
83
-
84
-
85
-    protected function _init_page_props()
86
-    {
87
-        $this->page_slug        = REG_PG_SLUG;
88
-        $this->_admin_base_url  = REG_ADMIN_URL;
89
-        $this->_admin_base_path = REG_ADMIN;
90
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
91
-        $this->_cpt_routes      = array(
92
-            'add_new_attendee' => 'espresso_attendees',
93
-            'edit_attendee'    => 'espresso_attendees',
94
-            'insert_attendee'  => 'espresso_attendees',
95
-            'update_attendee'  => 'espresso_attendees',
96
-        );
97
-        $this->_cpt_model_names = array(
98
-            'add_new_attendee' => 'EEM_Attendee',
99
-            'edit_attendee'    => 'EEM_Attendee',
100
-        );
101
-        $this->_cpt_edit_routes = array(
102
-            'espresso_attendees' => 'edit_attendee',
103
-        );
104
-        $this->_pagenow_map     = array(
105
-            'add_new_attendee' => 'post-new.php',
106
-            'edit_attendee'    => 'post.php',
107
-            'trash'            => 'post.php',
108
-        );
109
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
-        //add filters so that the comment urls don't take users to a confusing 404 page
111
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
-    }
113
-
114
-
115
-    public function clear_comment_link($link, $comment, $args)
116
-    {
117
-        //gotta make sure this only happens on this route
118
-        $post_type = get_post_type($comment->comment_post_ID);
119
-        if ($post_type === 'espresso_attendees') {
120
-            return '#commentsdiv';
121
-        }
122
-        return $link;
123
-    }
124
-
125
-
126
-    protected function _ajax_hooks()
127
-    {
128
-        //todo: all hooks for registrations ajax goes in here
129
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
-    }
131
-
132
-
133
-    protected function _define_page_props()
134
-    {
135
-        $this->_admin_page_title = $this->page_label;
136
-        $this->_labels           = array(
137
-            'buttons'                      => array(
138
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
139
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
140
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
141
-                'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
142
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
143
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
144
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
145
-                'contact_list_export' => esc_html__("Export Data", "event_espresso"),
146
-            ),
147
-            'publishbox'                   => array(
148
-                'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
149
-                'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
150
-            ),
151
-            'hide_add_button_on_cpt_route' => array(
152
-                'edit_attendee' => true,
153
-            ),
154
-        );
155
-    }
156
-
157
-
158
-    /**
159
-     *        grab url requests and route them
160
-     *
161
-     * @access private
162
-     * @return void
163
-     */
164
-    public function _set_page_routes()
165
-    {
166
-        $this->_get_registration_status_array();
167
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
-            ? $this->_req_data['_REG_ID'] : 0;
169
-        $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
170
-            ? $this->_req_data['reg_status_change_form']['REG_ID']
171
-            : $reg_id;
172
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
173
-            ? $this->_req_data['ATT_ID'] : 0;
174
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
175
-            ? $this->_req_data['post']
176
-            : $att_id;
177
-        $this->_page_routes = array(
178
-            'default'                            => array(
179
-                'func'       => '_registrations_overview_list_table',
180
-                'capability' => 'ee_read_registrations',
181
-            ),
182
-            'view_registration'                  => array(
183
-                'func'       => '_registration_details',
184
-                'capability' => 'ee_read_registration',
185
-                'obj_id'     => $reg_id,
186
-            ),
187
-            'edit_registration'                  => array(
188
-                'func'               => '_update_attendee_registration_form',
189
-                'noheader'           => true,
190
-                'headers_sent_route' => 'view_registration',
191
-                'capability'         => 'ee_edit_registration',
192
-                'obj_id'             => $reg_id,
193
-                '_REG_ID'            => $reg_id,
194
-            ),
195
-            'trash_registrations'                => array(
196
-                'func'       => '_trash_or_restore_registrations',
197
-                'args'       => array('trash' => true),
198
-                'noheader'   => true,
199
-                'capability' => 'ee_delete_registrations',
200
-            ),
201
-            'restore_registrations'              => array(
202
-                'func'       => '_trash_or_restore_registrations',
203
-                'args'       => array('trash' => false),
204
-                'noheader'   => true,
205
-                'capability' => 'ee_delete_registrations',
206
-            ),
207
-            'delete_registrations'               => array(
208
-                'func'       => '_delete_registrations',
209
-                'noheader'   => true,
210
-                'capability' => 'ee_delete_registrations',
211
-            ),
212
-            'new_registration'                   => array(
213
-                'func'       => 'new_registration',
214
-                'capability' => 'ee_edit_registrations',
215
-            ),
216
-            'process_reg_step'                   => array(
217
-                'func'       => 'process_reg_step',
218
-                'noheader'   => true,
219
-                'capability' => 'ee_edit_registrations',
220
-            ),
221
-            'redirect_to_txn'                    => array(
222
-                'func'       => 'redirect_to_txn',
223
-                'noheader'   => true,
224
-                'capability' => 'ee_edit_registrations',
225
-            ),
226
-            'change_reg_status'                  => array(
227
-                'func'       => '_change_reg_status',
228
-                'noheader'   => true,
229
-                'capability' => 'ee_edit_registration',
230
-                'obj_id'     => $reg_id,
231
-            ),
232
-            'approve_registration'               => array(
233
-                'func'       => 'approve_registration',
234
-                'noheader'   => true,
235
-                'capability' => 'ee_edit_registration',
236
-                'obj_id'     => $reg_id,
237
-            ),
238
-            'approve_and_notify_registration'    => array(
239
-                'func'       => 'approve_registration',
240
-                'noheader'   => true,
241
-                'args'       => array(true),
242
-                'capability' => 'ee_edit_registration',
243
-                'obj_id'     => $reg_id,
244
-            ),
245
-            'approve_registrations'               => array(
246
-                'func'       => 'bulk_action_on_registrations',
247
-                'noheader'   => true,
248
-                'capability' => 'ee_edit_registrations',
249
-                'args' => array('approve')
250
-            ),
251
-            'approve_and_notify_registrations'               => array(
252
-                'func'       => 'bulk_action_on_registrations',
253
-                'noheader'   => true,
254
-                'capability' => 'ee_edit_registrations',
255
-                'args' => array('approve', true)
256
-            ),
257
-            'decline_registration'               => array(
258
-                'func'       => 'decline_registration',
259
-                'noheader'   => true,
260
-                'capability' => 'ee_edit_registration',
261
-                'obj_id'     => $reg_id,
262
-            ),
263
-            'decline_and_notify_registration'    => array(
264
-                'func'       => 'decline_registration',
265
-                'noheader'   => true,
266
-                'args'       => array(true),
267
-                'capability' => 'ee_edit_registration',
268
-                'obj_id'     => $reg_id,
269
-            ),
270
-            'decline_registrations'               => array(
271
-                'func'       => 'bulk_action_on_registrations',
272
-                'noheader'   => true,
273
-                'capability' => 'ee_edit_registrations',
274
-                'args' => array('decline')
275
-            ),
276
-            'decline_and_notify_registrations'    => array(
277
-                'func'       => 'bulk_action_on_registrations',
278
-                'noheader'   => true,
279
-                'capability' => 'ee_edit_registrations',
280
-                'args' => array('decline', true)
281
-            ),
282
-            'pending_registration'               => array(
283
-                'func'       => 'pending_registration',
284
-                'noheader'   => true,
285
-                'capability' => 'ee_edit_registration',
286
-                'obj_id'     => $reg_id,
287
-            ),
288
-            'pending_and_notify_registration'    => array(
289
-                'func'       => 'pending_registration',
290
-                'noheader'   => true,
291
-                'args'       => array(true),
292
-                'capability' => 'ee_edit_registration',
293
-                'obj_id'     => $reg_id,
294
-            ),
295
-            'pending_registrations'               => array(
296
-                'func'       => 'bulk_action_on_registrations',
297
-                'noheader'   => true,
298
-                'capability' => 'ee_edit_registrations',
299
-                'args' => array('pending')
300
-            ),
301
-            'pending_and_notify_registrations'    => array(
302
-                'func'       => 'bulk_action_on_registrations',
303
-                'noheader'   => true,
304
-                'capability' => 'ee_edit_registrations',
305
-                'args' => array('pending', true)
306
-            ),
307
-            'no_approve_registration'            => array(
308
-                'func'       => 'not_approve_registration',
309
-                'noheader'   => true,
310
-                'capability' => 'ee_edit_registration',
311
-                'obj_id'     => $reg_id,
312
-            ),
313
-            'no_approve_and_notify_registration' => array(
314
-                'func'       => 'not_approve_registration',
315
-                'noheader'   => true,
316
-                'args'       => array(true),
317
-                'capability' => 'ee_edit_registration',
318
-                'obj_id'     => $reg_id,
319
-            ),
320
-            'no_approve_registrations'            => array(
321
-                'func'       => 'bulk_action_on_registrations',
322
-                'noheader'   => true,
323
-                'capability' => 'ee_edit_registrations',
324
-                'args' => array('no_approve')
325
-            ),
326
-            'no_approve_and_notify_registrations' => array(
327
-                'func'       => 'bulk_action_on_registrations',
328
-                'noheader'   => true,
329
-                'capability' => 'ee_edit_registrations',
330
-                'args' => array('no_approve', true)
331
-            ),
332
-            'cancel_registration'                => array(
333
-                'func'       => 'cancel_registration',
334
-                'noheader'   => true,
335
-                'capability' => 'ee_edit_registration',
336
-                'obj_id'     => $reg_id,
337
-            ),
338
-            'cancel_and_notify_registration'     => array(
339
-                'func'       => 'cancel_registration',
340
-                'noheader'   => true,
341
-                'args'       => array(true),
342
-                'capability' => 'ee_edit_registration',
343
-                'obj_id'     => $reg_id,
344
-            ),
345
-            'cancel_registrations'                => array(
346
-                'func'       => 'bulk_action_on_registrations',
347
-                'noheader'   => true,
348
-                'capability' => 'ee_edit_registrations',
349
-                'args' => array('cancel')
350
-            ),
351
-            'cancel_and_notify_registrations'     => array(
352
-                'func'       => 'bulk_action_on_registrations',
353
-                'noheader'   => true,
354
-                'capability' => 'ee_edit_registrations',
355
-                'args' => array('cancel', true)
356
-            ),
357
-            'wait_list_registration' => array(
358
-                'func'       => 'wait_list_registration',
359
-                'noheader'   => true,
360
-                'capability' => 'ee_edit_registration',
361
-                'obj_id'     => $reg_id,
362
-            ),
363
-            'contact_list'                       => array(
364
-                'func'       => '_attendee_contact_list_table',
365
-                'capability' => 'ee_read_contacts',
366
-            ),
367
-            'add_new_attendee'                   => array(
368
-                'func' => '_create_new_cpt_item',
369
-                'args' => array(
370
-                    'new_attendee' => true,
371
-                    'capability'   => 'ee_edit_contacts',
372
-                ),
373
-            ),
374
-            'edit_attendee'                      => array(
375
-                'func'       => '_edit_cpt_item',
376
-                'capability' => 'ee_edit_contacts',
377
-                'obj_id'     => $att_id,
378
-            ),
379
-            'duplicate_attendee'                 => array(
380
-                'func'       => '_duplicate_attendee',
381
-                'noheader'   => true,
382
-                'capability' => 'ee_edit_contacts',
383
-                'obj_id'     => $att_id,
384
-            ),
385
-            'insert_attendee'                    => array(
386
-                'func'       => '_insert_or_update_attendee',
387
-                'args'       => array(
388
-                    'new_attendee' => true,
389
-                ),
390
-                'noheader'   => true,
391
-                'capability' => 'ee_edit_contacts',
392
-            ),
393
-            'update_attendee'                    => array(
394
-                'func'       => '_insert_or_update_attendee',
395
-                'args'       => array(
396
-                    'new_attendee' => false,
397
-                ),
398
-                'noheader'   => true,
399
-                'capability' => 'ee_edit_contacts',
400
-                'obj_id'     => $att_id,
401
-            ),
402
-            'trash_attendees' => array(
403
-                'func' => '_trash_or_restore_attendees',
404
-                'args' => array(
405
-                    'trash' => 'true'
406
-                ),
407
-                'noheader' => true,
408
-                'capability' => 'ee_delete_contacts'
409
-            ),
410
-            'trash_attendee'                    => array(
411
-                'func'       => '_trash_or_restore_attendees',
412
-                'args'       => array(
413
-                    'trash' => true,
414
-                ),
415
-                'noheader'   => true,
416
-                'capability' => 'ee_delete_contacts',
417
-                'obj_id'     => $att_id,
418
-            ),
419
-            'restore_attendees'                  => array(
420
-                'func'       => '_trash_or_restore_attendees',
421
-                'args'       => array(
422
-                    'trash' => false,
423
-                ),
424
-                'noheader'   => true,
425
-                'capability' => 'ee_delete_contacts',
426
-                'obj_id'     => $att_id,
427
-            ),
428
-            'resend_registration'                => array(
429
-                'func'       => '_resend_registration',
430
-                'noheader'   => true,
431
-                'capability' => 'ee_send_message',
432
-            ),
433
-            'registrations_report'               => array(
434
-                'func'       => '_registrations_report',
435
-                'noheader'   => true,
436
-                'capability' => 'ee_read_registrations',
437
-            ),
438
-            'contact_list_export'                => array(
439
-                'func'       => '_contact_list_export',
440
-                'noheader'   => true,
441
-                'capability' => 'export',
442
-            ),
443
-            'contact_list_report'                => array(
444
-                'func'       => '_contact_list_report',
445
-                'noheader'   => true,
446
-                'capability' => 'ee_read_contacts',
447
-            ),
448
-        );
449
-    }
450
-
451
-
452
-    protected function _set_page_config()
453
-    {
454
-        $this->_page_config = array(
455
-            'default'           => array(
456
-                'nav'           => array(
457
-                    'label' => esc_html__('Overview', 'event_espresso'),
458
-                    'order' => 5,
459
-                ),
460
-                'help_tabs'     => array(
461
-                    'registrations_overview_help_tab'                       => array(
462
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
463
-                        'filename' => 'registrations_overview',
464
-                    ),
465
-                    'registrations_overview_table_column_headings_help_tab' => array(
466
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
467
-                        'filename' => 'registrations_overview_table_column_headings',
468
-                    ),
469
-                    'registrations_overview_filters_help_tab'               => array(
470
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
471
-                        'filename' => 'registrations_overview_filters',
472
-                    ),
473
-                    'registrations_overview_views_help_tab'                 => array(
474
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
475
-                        'filename' => 'registrations_overview_views',
476
-                    ),
477
-                    'registrations_regoverview_other_help_tab'              => array(
478
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
479
-                        'filename' => 'registrations_overview_other',
480
-                    ),
481
-                ),
482
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
483
-                'qtips'         => array('Registration_List_Table_Tips'),
484
-                'list_table'    => 'EE_Registrations_List_Table',
485
-                'require_nonce' => false,
486
-            ),
487
-            'view_registration' => array(
488
-                'nav'           => array(
489
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
490
-                    'order'      => 15,
491
-                    'url'        => isset($this->_req_data['_REG_ID'])
492
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
493
-                        : $this->_admin_base_url,
494
-                    'persistent' => false,
495
-                ),
496
-                'help_tabs'     => array(
497
-                    'registrations_details_help_tab'                    => array(
498
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
499
-                        'filename' => 'registrations_details',
500
-                    ),
501
-                    'registrations_details_table_help_tab'              => array(
502
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
503
-                        'filename' => 'registrations_details_table',
504
-                    ),
505
-                    'registrations_details_form_answers_help_tab'       => array(
506
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
507
-                        'filename' => 'registrations_details_form_answers',
508
-                    ),
509
-                    'registrations_details_registrant_details_help_tab' => array(
510
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
511
-                        'filename' => 'registrations_details_registrant_details',
512
-                    ),
513
-                ),
514
-                'help_tour'     => array('Registration_Details_Help_Tour'),
515
-                'metaboxes'     => array_merge(
516
-                    $this->_default_espresso_metaboxes,
517
-                    array('_registration_details_metaboxes')
518
-                ),
519
-                'require_nonce' => false,
520
-            ),
521
-            'new_registration'  => array(
522
-                'nav'           => array(
523
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
524
-                    'url'        => '#',
525
-                    'order'      => 15,
526
-                    'persistent' => false,
527
-                ),
528
-                'metaboxes'     => $this->_default_espresso_metaboxes,
529
-                'labels'        => array(
530
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
531
-                ),
532
-                'require_nonce' => false,
533
-            ),
534
-            'add_new_attendee'  => array(
535
-                'nav'           => array(
536
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
537
-                    'order'      => 15,
538
-                    'persistent' => false,
539
-                ),
540
-                'metaboxes'     => array_merge(
541
-                    $this->_default_espresso_metaboxes,
542
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
543
-                ),
544
-                'require_nonce' => false,
545
-            ),
546
-            'edit_attendee'     => array(
547
-                'nav'           => array(
548
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
549
-                    'order'      => 15,
550
-                    'persistent' => false,
551
-                    'url'        => isset($this->_req_data['ATT_ID'])
552
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
553
-                        : $this->_admin_base_url,
554
-                ),
555
-                'metaboxes'     => array('attendee_editor_metaboxes'),
556
-                'require_nonce' => false,
557
-            ),
558
-            'contact_list'      => array(
559
-                'nav'           => array(
560
-                    'label' => esc_html__('Contact List', 'event_espresso'),
561
-                    'order' => 20,
562
-                ),
563
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
564
-                'help_tabs'     => array(
565
-                    'registrations_contact_list_help_tab'                       => array(
566
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
567
-                        'filename' => 'registrations_contact_list',
568
-                    ),
569
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
570
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
571
-                        'filename' => 'registrations_contact_list_table_column_headings',
572
-                    ),
573
-                    'registrations_contact_list_views_help_tab'                 => array(
574
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
575
-                        'filename' => 'registrations_contact_list_views',
576
-                    ),
577
-                    'registrations_contact_list_other_help_tab'                 => array(
578
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
579
-                        'filename' => 'registrations_contact_list_other',
580
-                    ),
581
-                ),
582
-                'help_tour'     => array('Contact_List_Help_Tour'),
583
-                'metaboxes'     => array(),
584
-                'require_nonce' => false,
585
-            ),
586
-            //override default cpt routes
587
-            'create_new'        => '',
588
-            'edit'              => '',
589
-        );
590
-    }
591
-
592
-
593
-    /**
594
-     * The below methods aren't used by this class currently
595
-     */
596
-    protected function _add_screen_options()
597
-    {
598
-    }
599
-
600
-
601
-    protected function _add_feature_pointers()
602
-    {
603
-    }
604
-
605
-
606
-    public function admin_init()
607
-    {
608
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
609
-            'click "Update Registration Questions" to save your changes',
610
-            'event_espresso'
611
-        );
612
-    }
613
-
614
-
615
-    public function admin_notices()
616
-    {
617
-    }
618
-
619
-
620
-    public function admin_footer_scripts()
621
-    {
622
-    }
623
-
624
-
625
-    /**
626
-     *        get list of registration statuses
627
-     *
628
-     * @access private
629
-     * @return void
630
-     */
631
-    private function _get_registration_status_array()
632
-    {
633
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
634
-    }
635
-
636
-
637
-    protected function _add_screen_options_default()
638
-    {
639
-        $this->_per_page_screen_option();
640
-    }
641
-
642
-
643
-    protected function _add_screen_options_contact_list()
644
-    {
645
-        $page_title              = $this->_admin_page_title;
646
-        $this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
647
-        $this->_per_page_screen_option();
648
-        $this->_admin_page_title = $page_title;
649
-    }
650
-
651
-
652
-    public function load_scripts_styles()
653
-    {
654
-        //style
655
-        wp_register_style(
656
-            'espresso_reg',
657
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
658
-            array('ee-admin-css'),
659
-            EVENT_ESPRESSO_VERSION
660
-        );
661
-        wp_enqueue_style('espresso_reg');
662
-        //script
663
-        wp_register_script(
664
-            'espresso_reg',
665
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
666
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
667
-            EVENT_ESPRESSO_VERSION,
668
-            true
669
-        );
670
-        wp_enqueue_script('espresso_reg');
671
-    }
672
-
673
-
674
-    public function load_scripts_styles_edit_attendee()
675
-    {
676
-        //stuff to only show up on our attendee edit details page.
677
-        $attendee_details_translations = array(
678
-            'att_publish_text' => sprintf(
679
-                esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
680
-                $this->_cpt_model_obj->get_datetime('ATT_created')
681
-            ),
682
-        );
683
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
684
-        wp_enqueue_script('jquery-validate');
685
-    }
686
-
687
-
688
-    public function load_scripts_styles_view_registration()
689
-    {
690
-        //styles
691
-        wp_enqueue_style('espresso-ui-theme');
692
-        //scripts
693
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
694
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
695
-    }
696
-
697
-
698
-    public function load_scripts_styles_contact_list()
699
-    {
700
-        wp_deregister_style('espresso_reg');
701
-        wp_register_style(
702
-            'espresso_att',
703
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
704
-            array('ee-admin-css'),
705
-            EVENT_ESPRESSO_VERSION
706
-        );
707
-        wp_enqueue_style('espresso_att');
708
-    }
709
-
710
-
711
-    public function load_scripts_styles_new_registration()
712
-    {
713
-        wp_register_script(
714
-            'ee-spco-for-admin',
715
-            REG_ASSETS_URL . 'spco_for_admin.js',
716
-            array('underscore', 'jquery'),
717
-            EVENT_ESPRESSO_VERSION,
718
-            true
719
-        );
720
-        wp_enqueue_script('ee-spco-for-admin');
721
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
722
-        EE_Form_Section_Proper::wp_enqueue_scripts();
723
-        EED_Ticket_Selector::load_tckt_slctr_assets();
724
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
725
-    }
726
-
727
-
728
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
729
-    {
730
-        add_filter('FHEE_load_EE_messages', '__return_true');
731
-    }
732
-
733
-
734
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
735
-    {
736
-        add_filter('FHEE_load_EE_messages', '__return_true');
737
-    }
738
-
739
-
740
-    protected function _set_list_table_views_default()
741
-    {
742
-        //for notification related bulk actions we need to make sure only active messengers have an option.
743
-        EED_Messages::set_autoloaders();
744
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
745
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
746
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
747
-        //key= bulk_action_slug, value= message type.
748
-        $match_array = array(
749
-            'approve_registrations'    => 'registration',
750
-            'decline_registrations'    => 'declined_registration',
751
-            'pending_registrations'    => 'pending_approval',
752
-            'no_approve_registrations' => 'not_approved_registration',
753
-            'cancel_registrations'     => 'cancelled_registration',
754
-        );
755
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
756
-            'ee_send_message',
757
-            'batch_send_messages'
758
-        );
759
-        /** setup reg status bulk actions **/
760
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
761
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
762
-                $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
763
-                    'Approve and Notify Registrations',
764
-                    'event_espresso'
765
-                );
766
-        }
767
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
768
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
769
-                $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
770
-                    'Decline and Notify Registrations',
771
-                    'event_espresso'
772
-                );
773
-        }
774
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
775
-            'Set Registrations to Pending Payment',
776
-            'event_espresso'
777
-        );
778
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
779
-                $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
780
-                    'Set Registrations to Pending Payment and Notify',
781
-                    'event_espresso'
782
-                );
783
-        }
784
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
785
-            'Set Registrations to Not Approved',
786
-            'event_espresso'
787
-        );
788
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
789
-                $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
790
-                    'Set Registrations to Not Approved and Notify',
791
-                    'event_espresso'
792
-                );
793
-        }
794
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
795
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
796
-                $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
797
-                    'Cancel Registrations and Notify',
798
-                    'event_espresso'
799
-                );
800
-        }
801
-        $def_reg_status_actions = apply_filters(
802
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
803
-            $def_reg_status_actions,
804
-            $active_mts
805
-        );
806
-
807
-        $this->_views = array(
808
-            'all'   => array(
809
-                'slug'        => 'all',
810
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
811
-                'count'       => 0,
812
-                'bulk_action' => array_merge($def_reg_status_actions, array(
813
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
814
-                )),
815
-            ),
816
-            'month' => array(
817
-                'slug'        => 'month',
818
-                'label'       => esc_html__('This Month', 'event_espresso'),
819
-                'count'       => 0,
820
-                'bulk_action' => array_merge($def_reg_status_actions, array(
821
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
822
-                )),
823
-            ),
824
-            'today' => array(
825
-                'slug'        => 'today',
826
-                'label'       => sprintf(
827
-                    esc_html__('Today - %s', 'event_espresso'),
828
-                    date('M d, Y', current_time('timestamp'))
829
-                ),
830
-                'count'       => 0,
831
-                'bulk_action' => array_merge($def_reg_status_actions, array(
832
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
833
-                )),
834
-            ),
835
-        );
836
-        if (EE_Registry::instance()->CAP->current_user_can(
837
-            'ee_delete_registrations',
838
-            'espresso_registrations_delete_registration'
839
-        )) {
840
-            $this->_views['incomplete'] = array(
841
-                'slug'        => 'incomplete',
842
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
843
-                'count'       => 0,
844
-                'bulk_action' => array(
845
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
846
-                ),
847
-            );
848
-            $this->_views['trash']      = array(
849
-                'slug'        => 'trash',
850
-                'label'       => esc_html__('Trash', 'event_espresso'),
851
-                'count'       => 0,
852
-                'bulk_action' => array(
853
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
854
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
855
-                ),
856
-            );
857
-        }
858
-    }
859
-
860
-
861
-    protected function _set_list_table_views_contact_list()
862
-    {
863
-        $this->_views = array(
864
-            'in_use' => array(
865
-                'slug'        => 'in_use',
866
-                'label'       => esc_html__('In Use', 'event_espresso'),
867
-                'count'       => 0,
868
-                'bulk_action' => array(
869
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
870
-                ),
871
-            ),
872
-        );
873
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
874
-            'espresso_registrations_trash_attendees')
875
-        ) {
876
-            $this->_views['trash'] = array(
877
-                'slug'        => 'trash',
878
-                'label'       => esc_html__('Trash', 'event_espresso'),
879
-                'count'       => 0,
880
-                'bulk_action' => array(
881
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
882
-                ),
883
-            );
884
-        }
885
-    }
886
-
887
-
888
-    protected function _registration_legend_items()
889
-    {
890
-        $fc_items = array(
891
-            'star-icon'        => array(
892
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
893
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
894
-            ),
895
-            'view_details'     => array(
896
-                'class' => 'dashicons dashicons-clipboard',
897
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
898
-            ),
899
-            'edit_attendee'    => array(
900
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
901
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
902
-            ),
903
-            'view_transaction' => array(
904
-                'class' => 'dashicons dashicons-cart',
905
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
906
-            ),
907
-            'view_invoice'     => array(
908
-                'class' => 'dashicons dashicons-media-spreadsheet',
909
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
910
-            ),
911
-        );
912
-        if (EE_Registry::instance()->CAP->current_user_can(
913
-            'ee_send_message',
914
-            'espresso_registrations_resend_registration'
915
-        )) {
916
-            $fc_items['resend_registration'] = array(
917
-                'class' => 'dashicons dashicons-email-alt',
918
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
919
-            );
920
-        } else {
921
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
922
-        }
923
-        if (EE_Registry::instance()->CAP->current_user_can(
924
-            'ee_read_global_messages',
925
-            'view_filtered_messages'
926
-        )) {
927
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
928
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
929
-                $fc_items['view_related_messages'] = array(
930
-                    'class' => $related_for_icon['css_class'],
931
-                    'desc'  => $related_for_icon['label'],
932
-                );
933
-            }
934
-        }
935
-        $sc_items = array(
936
-            'approved_status'   => array(
937
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
938
-                'desc'  => EEH_Template::pretty_status(
939
-                    EEM_Registration::status_id_approved,
940
-                    false,
941
-                    'sentence'
942
-                ),
943
-            ),
944
-            'pending_status'    => array(
945
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
946
-                'desc'  => EEH_Template::pretty_status(
947
-                    EEM_Registration::status_id_pending_payment,
948
-                    false,
949
-                    'sentence'
950
-                ),
951
-            ),
952
-            'wait_list'         => array(
953
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
954
-                'desc'  => EEH_Template::pretty_status(
955
-                    EEM_Registration::status_id_wait_list,
956
-                    false,
957
-                    'sentence'
958
-                ),
959
-            ),
960
-            'incomplete_status' => array(
961
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
962
-                'desc'  => EEH_Template::pretty_status(
963
-                    EEM_Registration::status_id_incomplete,
964
-                    false,
965
-                    'sentence'
966
-                ),
967
-            ),
968
-            'not_approved'      => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
970
-                'desc'  => EEH_Template::pretty_status(
971
-                    EEM_Registration::status_id_not_approved,
972
-                    false,
973
-                    'sentence'
974
-                ),
975
-            ),
976
-            'declined_status'   => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
978
-                'desc'  => EEH_Template::pretty_status(
979
-                    EEM_Registration::status_id_declined,
980
-                    false,
981
-                    'sentence'
982
-                ),
983
-            ),
984
-            'cancelled_status'  => array(
985
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
986
-                'desc'  => EEH_Template::pretty_status(
987
-                    EEM_Registration::status_id_cancelled,
988
-                    false,
989
-                    'sentence'
990
-                ),
991
-            ),
992
-        );
993
-        return array_merge($fc_items, $sc_items);
994
-    }
995
-
996
-
997
-
998
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
999
-    /**
1000
-     * @throws \EE_Error
1001
-     */
1002
-    protected function _registrations_overview_list_table()
1003
-    {
1004
-        $this->_template_args['admin_page_header'] = '';
1005
-        $EVT_ID                                    = ! empty($this->_req_data['event_id'])
1006
-            ? absint($this->_req_data['event_id'])
1007
-            : 0;
1008
-        if ($EVT_ID) {
1009
-            if (EE_Registry::instance()->CAP->current_user_can(
1010
-                'ee_edit_registrations',
1011
-                'espresso_registrations_new_registration',
1012
-                $EVT_ID
1013
-            )) {
1014
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1015
-                    'new_registration',
1016
-                    'add-registrant',
1017
-                    array('event_id' => $EVT_ID),
1018
-                    'add-new-h2'
1019
-                );
1020
-            }
1021
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1022
-            if ($event instanceof EE_Event) {
1023
-                $this->_template_args['admin_page_header'] = sprintf(
1024
-                    esc_html__(
1025
-                        '%s Viewing registrations for the event: %s%s',
1026
-                        'event_espresso'
1027
-                    ),
1028
-                    '<h3 style="line-height:1.5em;">',
1029
-                    '<br /><a href="'
1030
-                        . EE_Admin_Page::add_query_args_and_nonce(
1031
-                            array(
1032
-                                'action' => 'edit',
1033
-                                'post'   => $event->ID(),
1034
-                            ),
1035
-                            EVENTS_ADMIN_URL
1036
-                        )
1037
-                        . '">&nbsp;'
1038
-                        . $event->get('EVT_name')
1039
-                        . '&nbsp;</a>&nbsp;',
1040
-                    '</h3>'
1041
-                );
1042
-            }
1043
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1044
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1045
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1046
-                $this->_template_args['admin_page_header'] = substr(
1047
-                    $this->_template_args['admin_page_header'],
1048
-                    0,
1049
-                    -5
1050
-                );
1051
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1052
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1053
-                $this->_template_args['admin_page_header'] .= $datetime->name();
1054
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1055
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
1056
-            }
1057
-        }
1058
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1059
-        $this->display_admin_list_table_page_with_no_sidebar();
1060
-    }
1061
-
1062
-
1063
-    /**
1064
-     * This sets the _registration property for the registration details screen
1065
-     *
1066
-     * @access private
1067
-     * @return bool
1068
-     */
1069
-    private function _set_registration_object()
1070
-    {
1071
-        //get out if we've already set the object
1072
-        if (is_object($this->_registration)) {
1073
-            return true;
1074
-        }
1075
-        $REG    = EEM_Registration::instance();
1076
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1077
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1078
-            return true;
1079
-        } else {
1080
-            $error_msg = sprintf(
1081
-                esc_html__(
1082
-                    'An error occurred and the details for Registration ID #%s could not be retrieved.',
1083
-                    'event_espresso'
1084
-                ),
1085
-                $REG_ID
1086
-            );
1087
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1088
-            $this->_registration = null;
1089
-            return false;
1090
-        }
1091
-    }
1092
-
1093
-
1094
-    /**
1095
-     * Used to retrieve registrations for the list table.
1096
-     *
1097
-     * @param int  $per_page
1098
-     * @param bool $count
1099
-     * @param bool $this_month
1100
-     * @param bool $today
1101
-     * @return EE_Registration[]|int
1102
-     * @throws EE_Error
1103
-     */
1104
-    public function get_registrations(
1105
-        $per_page = 10,
1106
-        $count = false,
1107
-        $this_month = false,
1108
-        $today = false
1109
-    ) {
1110
-        if ($this_month) {
1111
-            $this->_req_data['status'] = 'month';
1112
-        }
1113
-        if ($today) {
1114
-            $this->_req_data['status'] = 'today';
1115
-        }
1116
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1117
-        /**
1118
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1119
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1120
-         * @see EEM_Base::get_all()
1121
-         */
1122
-        $query_params['group_by'] = '';
1123
-
1124
-        return $count
1125
-            ? EEM_Registration::instance()->count($query_params)
1126
-            /** @type EE_Registration[] */
1127
-            : EEM_Registration::instance()->get_all($query_params);
1128
-    }
1129
-
1130
-
1131
-
1132
-    /**
1133
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1134
-     * Note: this listens to values on the request for some of the query parameters.
1135
-     *
1136
-     * @param array $request
1137
-     * @param int    $per_page
1138
-     * @param bool   $count
1139
-     * @return array
1140
-     */
1141
-    protected function _get_registration_query_parameters(
1142
-        $request = array(),
1143
-        $per_page = 10,
1144
-        $count = false
1145
-    ) {
1146
-
1147
-        $query_params = array(
1148
-            0                          => $this->_get_where_conditions_for_registrations_query(
1149
-                $request
1150
-            ),
1151
-            'caps'                     => EEM_Registration::caps_read_admin,
1152
-            'default_where_conditions' => 'this_model_only',
1153
-        );
1154
-        if (! $count) {
1155
-            $query_params = array_merge(
1156
-                $query_params,
1157
-                $this->_get_orderby_for_registrations_query(),
1158
-                $this->_get_limit($per_page)
1159
-            );
1160
-        }
1161
-
1162
-        return $query_params;
1163
-    }
1164
-
1165
-
1166
-    /**
1167
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1168
-     *
1169
-     * @param array $request usually the same as $this->_req_data but not necessarily
1170
-     * @return array
1171
-     */
1172
-    protected function _add_event_id_to_where_conditions(array $request)
1173
-    {
1174
-        $where = array();
1175
-        if (! empty($request['event_id'])) {
1176
-            $where['EVT_ID'] = absint($request['event_id']);
1177
-        }
1178
-        return $where;
1179
-    }
1180
-
1181
-
1182
-    /**
1183
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1184
-     *
1185
-     * @param array $request usually the same as $this->_req_data but not necessarily
1186
-     * @return array
1187
-     */
1188
-    protected function _add_category_id_to_where_conditions(array $request)
1189
-    {
1190
-        $where = array();
1191
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1192
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1193
-        }
1194
-        return $where;
1195
-    }
1196
-
1197
-
1198
-    /**
1199
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1200
-     *
1201
-     * @param array $request usually the same as $this->_req_data but not necessarily
1202
-     * @return array
1203
-     */
1204
-    protected function _add_datetime_id_to_where_conditions(array $request)
1205
-    {
1206
-        $where = array();
1207
-        if (! empty($request['datetime_id'])) {
1208
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1209
-        }
1210
-        if (! empty($request['DTT_ID'])) {
1211
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1212
-        }
1213
-        return $where;
1214
-    }
1215
-
1216
-
1217
-    /**
1218
-     * Adds the correct registration status to the where conditions for the registrations query.
1219
-     *
1220
-     * @param array $request usually the same as $this->_req_data but not necessarily
1221
-     * @return array
1222
-     */
1223
-    protected function _add_registration_status_to_where_conditions(array $request)
1224
-    {
1225
-        $where = array();
1226
-        $view = EEH_Array::is_set($request, 'status', '');
1227
-        $registration_status = ! empty($request['_reg_status'])
1228
-            ? sanitize_text_field($request['_reg_status'])
1229
-            : '';
1230
-
1231
-        /*
26
+	/**
27
+	 * @var EE_Registration
28
+	 */
29
+	private $_registration;
30
+
31
+	/**
32
+	 * @var EE_Event
33
+	 */
34
+	private $_reg_event;
35
+
36
+	/**
37
+	 * @var EE_Session
38
+	 */
39
+	private $_session;
40
+
41
+	private static $_reg_status;
42
+
43
+	/**
44
+	 * Form for displaying the custom questions for this registration.
45
+	 * This gets used a few times throughout the request so its best to cache it
46
+	 *
47
+	 * @var EE_Registration_Custom_Questions_Form
48
+	 */
49
+	protected $_reg_custom_questions_form = null;
50
+
51
+
52
+	/**
53
+	 *        constructor
54
+	 *
55
+	 * @Constructor
56
+	 * @access public
57
+	 * @param bool $routing
58
+	 * @return Registrations_Admin_Page
59
+	 */
60
+	public function __construct($routing = true)
61
+	{
62
+		parent::__construct($routing);
63
+		add_action('wp_loaded', array($this, 'wp_loaded'));
64
+	}
65
+
66
+
67
+	public function wp_loaded()
68
+	{
69
+		// when adding a new registration...
70
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
+			EE_System::do_not_cache();
72
+			if (! isset($this->_req_data['processing_registration'])
73
+				 || absint($this->_req_data['processing_registration']) !== 1
74
+			) {
75
+				// and it's NOT the attendee information reg step
76
+				// force cookie expiration by setting time to last week
77
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
+				// and update the global
79
+				$_COOKIE['ee_registration_added'] = 0;
80
+			}
81
+		}
82
+	}
83
+
84
+
85
+	protected function _init_page_props()
86
+	{
87
+		$this->page_slug        = REG_PG_SLUG;
88
+		$this->_admin_base_url  = REG_ADMIN_URL;
89
+		$this->_admin_base_path = REG_ADMIN;
90
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
91
+		$this->_cpt_routes      = array(
92
+			'add_new_attendee' => 'espresso_attendees',
93
+			'edit_attendee'    => 'espresso_attendees',
94
+			'insert_attendee'  => 'espresso_attendees',
95
+			'update_attendee'  => 'espresso_attendees',
96
+		);
97
+		$this->_cpt_model_names = array(
98
+			'add_new_attendee' => 'EEM_Attendee',
99
+			'edit_attendee'    => 'EEM_Attendee',
100
+		);
101
+		$this->_cpt_edit_routes = array(
102
+			'espresso_attendees' => 'edit_attendee',
103
+		);
104
+		$this->_pagenow_map     = array(
105
+			'add_new_attendee' => 'post-new.php',
106
+			'edit_attendee'    => 'post.php',
107
+			'trash'            => 'post.php',
108
+		);
109
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
+		//add filters so that the comment urls don't take users to a confusing 404 page
111
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
+	}
113
+
114
+
115
+	public function clear_comment_link($link, $comment, $args)
116
+	{
117
+		//gotta make sure this only happens on this route
118
+		$post_type = get_post_type($comment->comment_post_ID);
119
+		if ($post_type === 'espresso_attendees') {
120
+			return '#commentsdiv';
121
+		}
122
+		return $link;
123
+	}
124
+
125
+
126
+	protected function _ajax_hooks()
127
+	{
128
+		//todo: all hooks for registrations ajax goes in here
129
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
+	}
131
+
132
+
133
+	protected function _define_page_props()
134
+	{
135
+		$this->_admin_page_title = $this->page_label;
136
+		$this->_labels           = array(
137
+			'buttons'                      => array(
138
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
139
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
140
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
141
+				'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
142
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
143
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
144
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
145
+				'contact_list_export' => esc_html__("Export Data", "event_espresso"),
146
+			),
147
+			'publishbox'                   => array(
148
+				'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
149
+				'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
150
+			),
151
+			'hide_add_button_on_cpt_route' => array(
152
+				'edit_attendee' => true,
153
+			),
154
+		);
155
+	}
156
+
157
+
158
+	/**
159
+	 *        grab url requests and route them
160
+	 *
161
+	 * @access private
162
+	 * @return void
163
+	 */
164
+	public function _set_page_routes()
165
+	{
166
+		$this->_get_registration_status_array();
167
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
+			? $this->_req_data['_REG_ID'] : 0;
169
+		$reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
170
+			? $this->_req_data['reg_status_change_form']['REG_ID']
171
+			: $reg_id;
172
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
173
+			? $this->_req_data['ATT_ID'] : 0;
174
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
175
+			? $this->_req_data['post']
176
+			: $att_id;
177
+		$this->_page_routes = array(
178
+			'default'                            => array(
179
+				'func'       => '_registrations_overview_list_table',
180
+				'capability' => 'ee_read_registrations',
181
+			),
182
+			'view_registration'                  => array(
183
+				'func'       => '_registration_details',
184
+				'capability' => 'ee_read_registration',
185
+				'obj_id'     => $reg_id,
186
+			),
187
+			'edit_registration'                  => array(
188
+				'func'               => '_update_attendee_registration_form',
189
+				'noheader'           => true,
190
+				'headers_sent_route' => 'view_registration',
191
+				'capability'         => 'ee_edit_registration',
192
+				'obj_id'             => $reg_id,
193
+				'_REG_ID'            => $reg_id,
194
+			),
195
+			'trash_registrations'                => array(
196
+				'func'       => '_trash_or_restore_registrations',
197
+				'args'       => array('trash' => true),
198
+				'noheader'   => true,
199
+				'capability' => 'ee_delete_registrations',
200
+			),
201
+			'restore_registrations'              => array(
202
+				'func'       => '_trash_or_restore_registrations',
203
+				'args'       => array('trash' => false),
204
+				'noheader'   => true,
205
+				'capability' => 'ee_delete_registrations',
206
+			),
207
+			'delete_registrations'               => array(
208
+				'func'       => '_delete_registrations',
209
+				'noheader'   => true,
210
+				'capability' => 'ee_delete_registrations',
211
+			),
212
+			'new_registration'                   => array(
213
+				'func'       => 'new_registration',
214
+				'capability' => 'ee_edit_registrations',
215
+			),
216
+			'process_reg_step'                   => array(
217
+				'func'       => 'process_reg_step',
218
+				'noheader'   => true,
219
+				'capability' => 'ee_edit_registrations',
220
+			),
221
+			'redirect_to_txn'                    => array(
222
+				'func'       => 'redirect_to_txn',
223
+				'noheader'   => true,
224
+				'capability' => 'ee_edit_registrations',
225
+			),
226
+			'change_reg_status'                  => array(
227
+				'func'       => '_change_reg_status',
228
+				'noheader'   => true,
229
+				'capability' => 'ee_edit_registration',
230
+				'obj_id'     => $reg_id,
231
+			),
232
+			'approve_registration'               => array(
233
+				'func'       => 'approve_registration',
234
+				'noheader'   => true,
235
+				'capability' => 'ee_edit_registration',
236
+				'obj_id'     => $reg_id,
237
+			),
238
+			'approve_and_notify_registration'    => array(
239
+				'func'       => 'approve_registration',
240
+				'noheader'   => true,
241
+				'args'       => array(true),
242
+				'capability' => 'ee_edit_registration',
243
+				'obj_id'     => $reg_id,
244
+			),
245
+			'approve_registrations'               => array(
246
+				'func'       => 'bulk_action_on_registrations',
247
+				'noheader'   => true,
248
+				'capability' => 'ee_edit_registrations',
249
+				'args' => array('approve')
250
+			),
251
+			'approve_and_notify_registrations'               => array(
252
+				'func'       => 'bulk_action_on_registrations',
253
+				'noheader'   => true,
254
+				'capability' => 'ee_edit_registrations',
255
+				'args' => array('approve', true)
256
+			),
257
+			'decline_registration'               => array(
258
+				'func'       => 'decline_registration',
259
+				'noheader'   => true,
260
+				'capability' => 'ee_edit_registration',
261
+				'obj_id'     => $reg_id,
262
+			),
263
+			'decline_and_notify_registration'    => array(
264
+				'func'       => 'decline_registration',
265
+				'noheader'   => true,
266
+				'args'       => array(true),
267
+				'capability' => 'ee_edit_registration',
268
+				'obj_id'     => $reg_id,
269
+			),
270
+			'decline_registrations'               => array(
271
+				'func'       => 'bulk_action_on_registrations',
272
+				'noheader'   => true,
273
+				'capability' => 'ee_edit_registrations',
274
+				'args' => array('decline')
275
+			),
276
+			'decline_and_notify_registrations'    => array(
277
+				'func'       => 'bulk_action_on_registrations',
278
+				'noheader'   => true,
279
+				'capability' => 'ee_edit_registrations',
280
+				'args' => array('decline', true)
281
+			),
282
+			'pending_registration'               => array(
283
+				'func'       => 'pending_registration',
284
+				'noheader'   => true,
285
+				'capability' => 'ee_edit_registration',
286
+				'obj_id'     => $reg_id,
287
+			),
288
+			'pending_and_notify_registration'    => array(
289
+				'func'       => 'pending_registration',
290
+				'noheader'   => true,
291
+				'args'       => array(true),
292
+				'capability' => 'ee_edit_registration',
293
+				'obj_id'     => $reg_id,
294
+			),
295
+			'pending_registrations'               => array(
296
+				'func'       => 'bulk_action_on_registrations',
297
+				'noheader'   => true,
298
+				'capability' => 'ee_edit_registrations',
299
+				'args' => array('pending')
300
+			),
301
+			'pending_and_notify_registrations'    => array(
302
+				'func'       => 'bulk_action_on_registrations',
303
+				'noheader'   => true,
304
+				'capability' => 'ee_edit_registrations',
305
+				'args' => array('pending', true)
306
+			),
307
+			'no_approve_registration'            => array(
308
+				'func'       => 'not_approve_registration',
309
+				'noheader'   => true,
310
+				'capability' => 'ee_edit_registration',
311
+				'obj_id'     => $reg_id,
312
+			),
313
+			'no_approve_and_notify_registration' => array(
314
+				'func'       => 'not_approve_registration',
315
+				'noheader'   => true,
316
+				'args'       => array(true),
317
+				'capability' => 'ee_edit_registration',
318
+				'obj_id'     => $reg_id,
319
+			),
320
+			'no_approve_registrations'            => array(
321
+				'func'       => 'bulk_action_on_registrations',
322
+				'noheader'   => true,
323
+				'capability' => 'ee_edit_registrations',
324
+				'args' => array('no_approve')
325
+			),
326
+			'no_approve_and_notify_registrations' => array(
327
+				'func'       => 'bulk_action_on_registrations',
328
+				'noheader'   => true,
329
+				'capability' => 'ee_edit_registrations',
330
+				'args' => array('no_approve', true)
331
+			),
332
+			'cancel_registration'                => array(
333
+				'func'       => 'cancel_registration',
334
+				'noheader'   => true,
335
+				'capability' => 'ee_edit_registration',
336
+				'obj_id'     => $reg_id,
337
+			),
338
+			'cancel_and_notify_registration'     => array(
339
+				'func'       => 'cancel_registration',
340
+				'noheader'   => true,
341
+				'args'       => array(true),
342
+				'capability' => 'ee_edit_registration',
343
+				'obj_id'     => $reg_id,
344
+			),
345
+			'cancel_registrations'                => array(
346
+				'func'       => 'bulk_action_on_registrations',
347
+				'noheader'   => true,
348
+				'capability' => 'ee_edit_registrations',
349
+				'args' => array('cancel')
350
+			),
351
+			'cancel_and_notify_registrations'     => array(
352
+				'func'       => 'bulk_action_on_registrations',
353
+				'noheader'   => true,
354
+				'capability' => 'ee_edit_registrations',
355
+				'args' => array('cancel', true)
356
+			),
357
+			'wait_list_registration' => array(
358
+				'func'       => 'wait_list_registration',
359
+				'noheader'   => true,
360
+				'capability' => 'ee_edit_registration',
361
+				'obj_id'     => $reg_id,
362
+			),
363
+			'contact_list'                       => array(
364
+				'func'       => '_attendee_contact_list_table',
365
+				'capability' => 'ee_read_contacts',
366
+			),
367
+			'add_new_attendee'                   => array(
368
+				'func' => '_create_new_cpt_item',
369
+				'args' => array(
370
+					'new_attendee' => true,
371
+					'capability'   => 'ee_edit_contacts',
372
+				),
373
+			),
374
+			'edit_attendee'                      => array(
375
+				'func'       => '_edit_cpt_item',
376
+				'capability' => 'ee_edit_contacts',
377
+				'obj_id'     => $att_id,
378
+			),
379
+			'duplicate_attendee'                 => array(
380
+				'func'       => '_duplicate_attendee',
381
+				'noheader'   => true,
382
+				'capability' => 'ee_edit_contacts',
383
+				'obj_id'     => $att_id,
384
+			),
385
+			'insert_attendee'                    => array(
386
+				'func'       => '_insert_or_update_attendee',
387
+				'args'       => array(
388
+					'new_attendee' => true,
389
+				),
390
+				'noheader'   => true,
391
+				'capability' => 'ee_edit_contacts',
392
+			),
393
+			'update_attendee'                    => array(
394
+				'func'       => '_insert_or_update_attendee',
395
+				'args'       => array(
396
+					'new_attendee' => false,
397
+				),
398
+				'noheader'   => true,
399
+				'capability' => 'ee_edit_contacts',
400
+				'obj_id'     => $att_id,
401
+			),
402
+			'trash_attendees' => array(
403
+				'func' => '_trash_or_restore_attendees',
404
+				'args' => array(
405
+					'trash' => 'true'
406
+				),
407
+				'noheader' => true,
408
+				'capability' => 'ee_delete_contacts'
409
+			),
410
+			'trash_attendee'                    => array(
411
+				'func'       => '_trash_or_restore_attendees',
412
+				'args'       => array(
413
+					'trash' => true,
414
+				),
415
+				'noheader'   => true,
416
+				'capability' => 'ee_delete_contacts',
417
+				'obj_id'     => $att_id,
418
+			),
419
+			'restore_attendees'                  => array(
420
+				'func'       => '_trash_or_restore_attendees',
421
+				'args'       => array(
422
+					'trash' => false,
423
+				),
424
+				'noheader'   => true,
425
+				'capability' => 'ee_delete_contacts',
426
+				'obj_id'     => $att_id,
427
+			),
428
+			'resend_registration'                => array(
429
+				'func'       => '_resend_registration',
430
+				'noheader'   => true,
431
+				'capability' => 'ee_send_message',
432
+			),
433
+			'registrations_report'               => array(
434
+				'func'       => '_registrations_report',
435
+				'noheader'   => true,
436
+				'capability' => 'ee_read_registrations',
437
+			),
438
+			'contact_list_export'                => array(
439
+				'func'       => '_contact_list_export',
440
+				'noheader'   => true,
441
+				'capability' => 'export',
442
+			),
443
+			'contact_list_report'                => array(
444
+				'func'       => '_contact_list_report',
445
+				'noheader'   => true,
446
+				'capability' => 'ee_read_contacts',
447
+			),
448
+		);
449
+	}
450
+
451
+
452
+	protected function _set_page_config()
453
+	{
454
+		$this->_page_config = array(
455
+			'default'           => array(
456
+				'nav'           => array(
457
+					'label' => esc_html__('Overview', 'event_espresso'),
458
+					'order' => 5,
459
+				),
460
+				'help_tabs'     => array(
461
+					'registrations_overview_help_tab'                       => array(
462
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
463
+						'filename' => 'registrations_overview',
464
+					),
465
+					'registrations_overview_table_column_headings_help_tab' => array(
466
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
467
+						'filename' => 'registrations_overview_table_column_headings',
468
+					),
469
+					'registrations_overview_filters_help_tab'               => array(
470
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
471
+						'filename' => 'registrations_overview_filters',
472
+					),
473
+					'registrations_overview_views_help_tab'                 => array(
474
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
475
+						'filename' => 'registrations_overview_views',
476
+					),
477
+					'registrations_regoverview_other_help_tab'              => array(
478
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
479
+						'filename' => 'registrations_overview_other',
480
+					),
481
+				),
482
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
483
+				'qtips'         => array('Registration_List_Table_Tips'),
484
+				'list_table'    => 'EE_Registrations_List_Table',
485
+				'require_nonce' => false,
486
+			),
487
+			'view_registration' => array(
488
+				'nav'           => array(
489
+					'label'      => esc_html__('REG Details', 'event_espresso'),
490
+					'order'      => 15,
491
+					'url'        => isset($this->_req_data['_REG_ID'])
492
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
493
+						: $this->_admin_base_url,
494
+					'persistent' => false,
495
+				),
496
+				'help_tabs'     => array(
497
+					'registrations_details_help_tab'                    => array(
498
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
499
+						'filename' => 'registrations_details',
500
+					),
501
+					'registrations_details_table_help_tab'              => array(
502
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
503
+						'filename' => 'registrations_details_table',
504
+					),
505
+					'registrations_details_form_answers_help_tab'       => array(
506
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
507
+						'filename' => 'registrations_details_form_answers',
508
+					),
509
+					'registrations_details_registrant_details_help_tab' => array(
510
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
511
+						'filename' => 'registrations_details_registrant_details',
512
+					),
513
+				),
514
+				'help_tour'     => array('Registration_Details_Help_Tour'),
515
+				'metaboxes'     => array_merge(
516
+					$this->_default_espresso_metaboxes,
517
+					array('_registration_details_metaboxes')
518
+				),
519
+				'require_nonce' => false,
520
+			),
521
+			'new_registration'  => array(
522
+				'nav'           => array(
523
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
524
+					'url'        => '#',
525
+					'order'      => 15,
526
+					'persistent' => false,
527
+				),
528
+				'metaboxes'     => $this->_default_espresso_metaboxes,
529
+				'labels'        => array(
530
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
531
+				),
532
+				'require_nonce' => false,
533
+			),
534
+			'add_new_attendee'  => array(
535
+				'nav'           => array(
536
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
537
+					'order'      => 15,
538
+					'persistent' => false,
539
+				),
540
+				'metaboxes'     => array_merge(
541
+					$this->_default_espresso_metaboxes,
542
+					array('_publish_post_box', 'attendee_editor_metaboxes')
543
+				),
544
+				'require_nonce' => false,
545
+			),
546
+			'edit_attendee'     => array(
547
+				'nav'           => array(
548
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
549
+					'order'      => 15,
550
+					'persistent' => false,
551
+					'url'        => isset($this->_req_data['ATT_ID'])
552
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
553
+						: $this->_admin_base_url,
554
+				),
555
+				'metaboxes'     => array('attendee_editor_metaboxes'),
556
+				'require_nonce' => false,
557
+			),
558
+			'contact_list'      => array(
559
+				'nav'           => array(
560
+					'label' => esc_html__('Contact List', 'event_espresso'),
561
+					'order' => 20,
562
+				),
563
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
564
+				'help_tabs'     => array(
565
+					'registrations_contact_list_help_tab'                       => array(
566
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
567
+						'filename' => 'registrations_contact_list',
568
+					),
569
+					'registrations_contact-list_table_column_headings_help_tab' => array(
570
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
571
+						'filename' => 'registrations_contact_list_table_column_headings',
572
+					),
573
+					'registrations_contact_list_views_help_tab'                 => array(
574
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
575
+						'filename' => 'registrations_contact_list_views',
576
+					),
577
+					'registrations_contact_list_other_help_tab'                 => array(
578
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
579
+						'filename' => 'registrations_contact_list_other',
580
+					),
581
+				),
582
+				'help_tour'     => array('Contact_List_Help_Tour'),
583
+				'metaboxes'     => array(),
584
+				'require_nonce' => false,
585
+			),
586
+			//override default cpt routes
587
+			'create_new'        => '',
588
+			'edit'              => '',
589
+		);
590
+	}
591
+
592
+
593
+	/**
594
+	 * The below methods aren't used by this class currently
595
+	 */
596
+	protected function _add_screen_options()
597
+	{
598
+	}
599
+
600
+
601
+	protected function _add_feature_pointers()
602
+	{
603
+	}
604
+
605
+
606
+	public function admin_init()
607
+	{
608
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
609
+			'click "Update Registration Questions" to save your changes',
610
+			'event_espresso'
611
+		);
612
+	}
613
+
614
+
615
+	public function admin_notices()
616
+	{
617
+	}
618
+
619
+
620
+	public function admin_footer_scripts()
621
+	{
622
+	}
623
+
624
+
625
+	/**
626
+	 *        get list of registration statuses
627
+	 *
628
+	 * @access private
629
+	 * @return void
630
+	 */
631
+	private function _get_registration_status_array()
632
+	{
633
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
634
+	}
635
+
636
+
637
+	protected function _add_screen_options_default()
638
+	{
639
+		$this->_per_page_screen_option();
640
+	}
641
+
642
+
643
+	protected function _add_screen_options_contact_list()
644
+	{
645
+		$page_title              = $this->_admin_page_title;
646
+		$this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
647
+		$this->_per_page_screen_option();
648
+		$this->_admin_page_title = $page_title;
649
+	}
650
+
651
+
652
+	public function load_scripts_styles()
653
+	{
654
+		//style
655
+		wp_register_style(
656
+			'espresso_reg',
657
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
658
+			array('ee-admin-css'),
659
+			EVENT_ESPRESSO_VERSION
660
+		);
661
+		wp_enqueue_style('espresso_reg');
662
+		//script
663
+		wp_register_script(
664
+			'espresso_reg',
665
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
666
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
667
+			EVENT_ESPRESSO_VERSION,
668
+			true
669
+		);
670
+		wp_enqueue_script('espresso_reg');
671
+	}
672
+
673
+
674
+	public function load_scripts_styles_edit_attendee()
675
+	{
676
+		//stuff to only show up on our attendee edit details page.
677
+		$attendee_details_translations = array(
678
+			'att_publish_text' => sprintf(
679
+				esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
680
+				$this->_cpt_model_obj->get_datetime('ATT_created')
681
+			),
682
+		);
683
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
684
+		wp_enqueue_script('jquery-validate');
685
+	}
686
+
687
+
688
+	public function load_scripts_styles_view_registration()
689
+	{
690
+		//styles
691
+		wp_enqueue_style('espresso-ui-theme');
692
+		//scripts
693
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
694
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
695
+	}
696
+
697
+
698
+	public function load_scripts_styles_contact_list()
699
+	{
700
+		wp_deregister_style('espresso_reg');
701
+		wp_register_style(
702
+			'espresso_att',
703
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
704
+			array('ee-admin-css'),
705
+			EVENT_ESPRESSO_VERSION
706
+		);
707
+		wp_enqueue_style('espresso_att');
708
+	}
709
+
710
+
711
+	public function load_scripts_styles_new_registration()
712
+	{
713
+		wp_register_script(
714
+			'ee-spco-for-admin',
715
+			REG_ASSETS_URL . 'spco_for_admin.js',
716
+			array('underscore', 'jquery'),
717
+			EVENT_ESPRESSO_VERSION,
718
+			true
719
+		);
720
+		wp_enqueue_script('ee-spco-for-admin');
721
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
722
+		EE_Form_Section_Proper::wp_enqueue_scripts();
723
+		EED_Ticket_Selector::load_tckt_slctr_assets();
724
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
725
+	}
726
+
727
+
728
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
729
+	{
730
+		add_filter('FHEE_load_EE_messages', '__return_true');
731
+	}
732
+
733
+
734
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
735
+	{
736
+		add_filter('FHEE_load_EE_messages', '__return_true');
737
+	}
738
+
739
+
740
+	protected function _set_list_table_views_default()
741
+	{
742
+		//for notification related bulk actions we need to make sure only active messengers have an option.
743
+		EED_Messages::set_autoloaders();
744
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
745
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
746
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
747
+		//key= bulk_action_slug, value= message type.
748
+		$match_array = array(
749
+			'approve_registrations'    => 'registration',
750
+			'decline_registrations'    => 'declined_registration',
751
+			'pending_registrations'    => 'pending_approval',
752
+			'no_approve_registrations' => 'not_approved_registration',
753
+			'cancel_registrations'     => 'cancelled_registration',
754
+		);
755
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
756
+			'ee_send_message',
757
+			'batch_send_messages'
758
+		);
759
+		/** setup reg status bulk actions **/
760
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
761
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
762
+				$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
763
+					'Approve and Notify Registrations',
764
+					'event_espresso'
765
+				);
766
+		}
767
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
768
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
769
+				$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
770
+					'Decline and Notify Registrations',
771
+					'event_espresso'
772
+				);
773
+		}
774
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
775
+			'Set Registrations to Pending Payment',
776
+			'event_espresso'
777
+		);
778
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
779
+				$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
780
+					'Set Registrations to Pending Payment and Notify',
781
+					'event_espresso'
782
+				);
783
+		}
784
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
785
+			'Set Registrations to Not Approved',
786
+			'event_espresso'
787
+		);
788
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
789
+				$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
790
+					'Set Registrations to Not Approved and Notify',
791
+					'event_espresso'
792
+				);
793
+		}
794
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
795
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
796
+				$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
797
+					'Cancel Registrations and Notify',
798
+					'event_espresso'
799
+				);
800
+		}
801
+		$def_reg_status_actions = apply_filters(
802
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
803
+			$def_reg_status_actions,
804
+			$active_mts
805
+		);
806
+
807
+		$this->_views = array(
808
+			'all'   => array(
809
+				'slug'        => 'all',
810
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
811
+				'count'       => 0,
812
+				'bulk_action' => array_merge($def_reg_status_actions, array(
813
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
814
+				)),
815
+			),
816
+			'month' => array(
817
+				'slug'        => 'month',
818
+				'label'       => esc_html__('This Month', 'event_espresso'),
819
+				'count'       => 0,
820
+				'bulk_action' => array_merge($def_reg_status_actions, array(
821
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
822
+				)),
823
+			),
824
+			'today' => array(
825
+				'slug'        => 'today',
826
+				'label'       => sprintf(
827
+					esc_html__('Today - %s', 'event_espresso'),
828
+					date('M d, Y', current_time('timestamp'))
829
+				),
830
+				'count'       => 0,
831
+				'bulk_action' => array_merge($def_reg_status_actions, array(
832
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
833
+				)),
834
+			),
835
+		);
836
+		if (EE_Registry::instance()->CAP->current_user_can(
837
+			'ee_delete_registrations',
838
+			'espresso_registrations_delete_registration'
839
+		)) {
840
+			$this->_views['incomplete'] = array(
841
+				'slug'        => 'incomplete',
842
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
843
+				'count'       => 0,
844
+				'bulk_action' => array(
845
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
846
+				),
847
+			);
848
+			$this->_views['trash']      = array(
849
+				'slug'        => 'trash',
850
+				'label'       => esc_html__('Trash', 'event_espresso'),
851
+				'count'       => 0,
852
+				'bulk_action' => array(
853
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
854
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
855
+				),
856
+			);
857
+		}
858
+	}
859
+
860
+
861
+	protected function _set_list_table_views_contact_list()
862
+	{
863
+		$this->_views = array(
864
+			'in_use' => array(
865
+				'slug'        => 'in_use',
866
+				'label'       => esc_html__('In Use', 'event_espresso'),
867
+				'count'       => 0,
868
+				'bulk_action' => array(
869
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
870
+				),
871
+			),
872
+		);
873
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
874
+			'espresso_registrations_trash_attendees')
875
+		) {
876
+			$this->_views['trash'] = array(
877
+				'slug'        => 'trash',
878
+				'label'       => esc_html__('Trash', 'event_espresso'),
879
+				'count'       => 0,
880
+				'bulk_action' => array(
881
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
882
+				),
883
+			);
884
+		}
885
+	}
886
+
887
+
888
+	protected function _registration_legend_items()
889
+	{
890
+		$fc_items = array(
891
+			'star-icon'        => array(
892
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
893
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
894
+			),
895
+			'view_details'     => array(
896
+				'class' => 'dashicons dashicons-clipboard',
897
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
898
+			),
899
+			'edit_attendee'    => array(
900
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
901
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
902
+			),
903
+			'view_transaction' => array(
904
+				'class' => 'dashicons dashicons-cart',
905
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
906
+			),
907
+			'view_invoice'     => array(
908
+				'class' => 'dashicons dashicons-media-spreadsheet',
909
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
910
+			),
911
+		);
912
+		if (EE_Registry::instance()->CAP->current_user_can(
913
+			'ee_send_message',
914
+			'espresso_registrations_resend_registration'
915
+		)) {
916
+			$fc_items['resend_registration'] = array(
917
+				'class' => 'dashicons dashicons-email-alt',
918
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
919
+			);
920
+		} else {
921
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
922
+		}
923
+		if (EE_Registry::instance()->CAP->current_user_can(
924
+			'ee_read_global_messages',
925
+			'view_filtered_messages'
926
+		)) {
927
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
928
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
929
+				$fc_items['view_related_messages'] = array(
930
+					'class' => $related_for_icon['css_class'],
931
+					'desc'  => $related_for_icon['label'],
932
+				);
933
+			}
934
+		}
935
+		$sc_items = array(
936
+			'approved_status'   => array(
937
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
938
+				'desc'  => EEH_Template::pretty_status(
939
+					EEM_Registration::status_id_approved,
940
+					false,
941
+					'sentence'
942
+				),
943
+			),
944
+			'pending_status'    => array(
945
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
946
+				'desc'  => EEH_Template::pretty_status(
947
+					EEM_Registration::status_id_pending_payment,
948
+					false,
949
+					'sentence'
950
+				),
951
+			),
952
+			'wait_list'         => array(
953
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
954
+				'desc'  => EEH_Template::pretty_status(
955
+					EEM_Registration::status_id_wait_list,
956
+					false,
957
+					'sentence'
958
+				),
959
+			),
960
+			'incomplete_status' => array(
961
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
962
+				'desc'  => EEH_Template::pretty_status(
963
+					EEM_Registration::status_id_incomplete,
964
+					false,
965
+					'sentence'
966
+				),
967
+			),
968
+			'not_approved'      => array(
969
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
970
+				'desc'  => EEH_Template::pretty_status(
971
+					EEM_Registration::status_id_not_approved,
972
+					false,
973
+					'sentence'
974
+				),
975
+			),
976
+			'declined_status'   => array(
977
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
978
+				'desc'  => EEH_Template::pretty_status(
979
+					EEM_Registration::status_id_declined,
980
+					false,
981
+					'sentence'
982
+				),
983
+			),
984
+			'cancelled_status'  => array(
985
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
986
+				'desc'  => EEH_Template::pretty_status(
987
+					EEM_Registration::status_id_cancelled,
988
+					false,
989
+					'sentence'
990
+				),
991
+			),
992
+		);
993
+		return array_merge($fc_items, $sc_items);
994
+	}
995
+
996
+
997
+
998
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
999
+	/**
1000
+	 * @throws \EE_Error
1001
+	 */
1002
+	protected function _registrations_overview_list_table()
1003
+	{
1004
+		$this->_template_args['admin_page_header'] = '';
1005
+		$EVT_ID                                    = ! empty($this->_req_data['event_id'])
1006
+			? absint($this->_req_data['event_id'])
1007
+			: 0;
1008
+		if ($EVT_ID) {
1009
+			if (EE_Registry::instance()->CAP->current_user_can(
1010
+				'ee_edit_registrations',
1011
+				'espresso_registrations_new_registration',
1012
+				$EVT_ID
1013
+			)) {
1014
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1015
+					'new_registration',
1016
+					'add-registrant',
1017
+					array('event_id' => $EVT_ID),
1018
+					'add-new-h2'
1019
+				);
1020
+			}
1021
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1022
+			if ($event instanceof EE_Event) {
1023
+				$this->_template_args['admin_page_header'] = sprintf(
1024
+					esc_html__(
1025
+						'%s Viewing registrations for the event: %s%s',
1026
+						'event_espresso'
1027
+					),
1028
+					'<h3 style="line-height:1.5em;">',
1029
+					'<br /><a href="'
1030
+						. EE_Admin_Page::add_query_args_and_nonce(
1031
+							array(
1032
+								'action' => 'edit',
1033
+								'post'   => $event->ID(),
1034
+							),
1035
+							EVENTS_ADMIN_URL
1036
+						)
1037
+						. '">&nbsp;'
1038
+						. $event->get('EVT_name')
1039
+						. '&nbsp;</a>&nbsp;',
1040
+					'</h3>'
1041
+				);
1042
+			}
1043
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1044
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1045
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1046
+				$this->_template_args['admin_page_header'] = substr(
1047
+					$this->_template_args['admin_page_header'],
1048
+					0,
1049
+					-5
1050
+				);
1051
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1052
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1053
+				$this->_template_args['admin_page_header'] .= $datetime->name();
1054
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1055
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
1056
+			}
1057
+		}
1058
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1059
+		$this->display_admin_list_table_page_with_no_sidebar();
1060
+	}
1061
+
1062
+
1063
+	/**
1064
+	 * This sets the _registration property for the registration details screen
1065
+	 *
1066
+	 * @access private
1067
+	 * @return bool
1068
+	 */
1069
+	private function _set_registration_object()
1070
+	{
1071
+		//get out if we've already set the object
1072
+		if (is_object($this->_registration)) {
1073
+			return true;
1074
+		}
1075
+		$REG    = EEM_Registration::instance();
1076
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1077
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1078
+			return true;
1079
+		} else {
1080
+			$error_msg = sprintf(
1081
+				esc_html__(
1082
+					'An error occurred and the details for Registration ID #%s could not be retrieved.',
1083
+					'event_espresso'
1084
+				),
1085
+				$REG_ID
1086
+			);
1087
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1088
+			$this->_registration = null;
1089
+			return false;
1090
+		}
1091
+	}
1092
+
1093
+
1094
+	/**
1095
+	 * Used to retrieve registrations for the list table.
1096
+	 *
1097
+	 * @param int  $per_page
1098
+	 * @param bool $count
1099
+	 * @param bool $this_month
1100
+	 * @param bool $today
1101
+	 * @return EE_Registration[]|int
1102
+	 * @throws EE_Error
1103
+	 */
1104
+	public function get_registrations(
1105
+		$per_page = 10,
1106
+		$count = false,
1107
+		$this_month = false,
1108
+		$today = false
1109
+	) {
1110
+		if ($this_month) {
1111
+			$this->_req_data['status'] = 'month';
1112
+		}
1113
+		if ($today) {
1114
+			$this->_req_data['status'] = 'today';
1115
+		}
1116
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1117
+		/**
1118
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1119
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1120
+		 * @see EEM_Base::get_all()
1121
+		 */
1122
+		$query_params['group_by'] = '';
1123
+
1124
+		return $count
1125
+			? EEM_Registration::instance()->count($query_params)
1126
+			/** @type EE_Registration[] */
1127
+			: EEM_Registration::instance()->get_all($query_params);
1128
+	}
1129
+
1130
+
1131
+
1132
+	/**
1133
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1134
+	 * Note: this listens to values on the request for some of the query parameters.
1135
+	 *
1136
+	 * @param array $request
1137
+	 * @param int    $per_page
1138
+	 * @param bool   $count
1139
+	 * @return array
1140
+	 */
1141
+	protected function _get_registration_query_parameters(
1142
+		$request = array(),
1143
+		$per_page = 10,
1144
+		$count = false
1145
+	) {
1146
+
1147
+		$query_params = array(
1148
+			0                          => $this->_get_where_conditions_for_registrations_query(
1149
+				$request
1150
+			),
1151
+			'caps'                     => EEM_Registration::caps_read_admin,
1152
+			'default_where_conditions' => 'this_model_only',
1153
+		);
1154
+		if (! $count) {
1155
+			$query_params = array_merge(
1156
+				$query_params,
1157
+				$this->_get_orderby_for_registrations_query(),
1158
+				$this->_get_limit($per_page)
1159
+			);
1160
+		}
1161
+
1162
+		return $query_params;
1163
+	}
1164
+
1165
+
1166
+	/**
1167
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1168
+	 *
1169
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1170
+	 * @return array
1171
+	 */
1172
+	protected function _add_event_id_to_where_conditions(array $request)
1173
+	{
1174
+		$where = array();
1175
+		if (! empty($request['event_id'])) {
1176
+			$where['EVT_ID'] = absint($request['event_id']);
1177
+		}
1178
+		return $where;
1179
+	}
1180
+
1181
+
1182
+	/**
1183
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1184
+	 *
1185
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1186
+	 * @return array
1187
+	 */
1188
+	protected function _add_category_id_to_where_conditions(array $request)
1189
+	{
1190
+		$where = array();
1191
+		if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1192
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1193
+		}
1194
+		return $where;
1195
+	}
1196
+
1197
+
1198
+	/**
1199
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1200
+	 *
1201
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1202
+	 * @return array
1203
+	 */
1204
+	protected function _add_datetime_id_to_where_conditions(array $request)
1205
+	{
1206
+		$where = array();
1207
+		if (! empty($request['datetime_id'])) {
1208
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1209
+		}
1210
+		if (! empty($request['DTT_ID'])) {
1211
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1212
+		}
1213
+		return $where;
1214
+	}
1215
+
1216
+
1217
+	/**
1218
+	 * Adds the correct registration status to the where conditions for the registrations query.
1219
+	 *
1220
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1221
+	 * @return array
1222
+	 */
1223
+	protected function _add_registration_status_to_where_conditions(array $request)
1224
+	{
1225
+		$where = array();
1226
+		$view = EEH_Array::is_set($request, 'status', '');
1227
+		$registration_status = ! empty($request['_reg_status'])
1228
+			? sanitize_text_field($request['_reg_status'])
1229
+			: '';
1230
+
1231
+		/*
1232 1232
          * If filtering by registration status, then we show registrations matching that status.
1233 1233
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1234 1234
          * UNLESS viewing trashed registrations.
1235 1235
          */
1236
-        if (! empty($registration_status)) {
1237
-            $where['STS_ID'] = $registration_status;
1238
-        } else {
1239
-            //make sure we exclude incomplete registrations, but only if not trashed.
1240
-            if ($view === 'trash') {
1241
-                $where['REG_deleted'] = true;
1242
-            } elseif ($view === 'incomplete') {
1243
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1244
-            } else {
1245
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1246
-            }
1247
-        }
1248
-        return $where;
1249
-    }
1250
-
1251
-
1252
-    /**
1253
-     * Adds any provided date restraints to the where conditions for the registrations query.
1254
-     *
1255
-     * @param array $request usually the same as $this->_req_data but not necessarily
1256
-     * @return array
1257
-     * @throws EE_Error
1258
-     */
1259
-    protected function _add_date_to_where_conditions(array $request)
1260
-    {
1261
-        $where = array();
1262
-        $view = EEH_Array::is_set($request, 'status', '');
1263
-        $month_range             = ! empty($request['month_range'])
1264
-            ? sanitize_text_field($request['month_range'])
1265
-            : '';
1266
-        $retrieve_for_today      = $view === 'today';
1267
-        $retrieve_for_this_month = $view === 'month';
1268
-
1269
-        if ($retrieve_for_today) {
1270
-            $now               = date('Y-m-d', current_time('timestamp'));
1271
-            $where['REG_date'] = array(
1272
-                'BETWEEN',
1273
-                array(
1274
-                    EEM_Registration::instance()->convert_datetime_for_query(
1275
-                        'REG_date',
1276
-                        $now . ' 00:00:00',
1277
-                        'Y-m-d H:i:s'
1278
-                    ),
1279
-                    EEM_Registration::instance()->convert_datetime_for_query(
1280
-                        'REG_date',
1281
-                        $now . ' 23:59:59',
1282
-                        'Y-m-d H:i:s'
1283
-                    ),
1284
-                ),
1285
-            );
1286
-        } elseif ($retrieve_for_this_month) {
1287
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1288
-            $days_this_month        = date('t', current_time('timestamp'));
1289
-            $where['REG_date']      = array(
1290
-                'BETWEEN',
1291
-                array(
1292
-                    EEM_Registration::instance()->convert_datetime_for_query(
1293
-                        'REG_date',
1294
-                        $current_year_and_month . '-01 00:00:00',
1295
-                        'Y-m-d H:i:s'
1296
-                    ),
1297
-                    EEM_Registration::instance()->convert_datetime_for_query(
1298
-                        'REG_date',
1299
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1300
-                        'Y-m-d H:i:s'
1301
-                    ),
1302
-                ),
1303
-            );
1304
-        } elseif ($month_range) {
1305
-            $pieces          = explode(' ', $month_range, 3);
1306
-            $month_requested = ! empty($pieces[0])
1307
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1308
-                : '';
1309
-            $year_requested  = ! empty($pieces[1])
1310
-                ? $pieces[1]
1311
-                : '';
1312
-            //if there is not a month or year then we can't go further
1313
-            if ($month_requested && $year_requested) {
1314
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1315
-                $where['REG_date'] = array(
1316
-                    'BETWEEN',
1317
-                    array(
1318
-                        EEM_Registration::instance()->convert_datetime_for_query(
1319
-                            'REG_date',
1320
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1321
-                            'Y-m-d H:i:s'
1322
-                        ),
1323
-                        EEM_Registration::instance()->convert_datetime_for_query(
1324
-                            'REG_date',
1325
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1326
-                            'Y-m-d H:i:s'
1327
-                        ),
1328
-                    ),
1329
-                );
1330
-            }
1331
-        }
1332
-        return $where;
1333
-    }
1334
-
1335
-
1336
-    /**
1337
-     * Adds any provided search restraints to the where conditions for the registrations query
1338
-     *
1339
-     * @param array $request usually the same as $this->_req_data but not necessarily
1340
-     * @return array
1341
-     */
1342
-    protected function _add_search_to_where_conditions(array $request)
1343
-    {
1344
-        $where = array();
1345
-        if (! empty($request['s'])) {
1346
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1347
-            $where['OR*search_conditions'] = array(
1348
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1349
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1350
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1351
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1352
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1353
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1354
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1355
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1356
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1357
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1358
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1359
-                'REG_final_price'                         => array('LIKE', $search_string),
1360
-                'REG_code'                                => array('LIKE', $search_string),
1361
-                'REG_count'                               => array('LIKE', $search_string),
1362
-                'REG_group_size'                          => array('LIKE', $search_string),
1363
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1364
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1365
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1366
-            );
1367
-        }
1368
-        return $where;
1369
-    }
1370
-
1371
-
1372
-    /**
1373
-     * Sets up the where conditions for the registrations query.
1374
-     *
1375
-     * @param array $request
1376
-     * @return array
1377
-     * @throws EE_Error
1378
-     */
1379
-    protected function _get_where_conditions_for_registrations_query($request)
1380
-    {
1381
-        return apply_filters(
1382
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1383
-            array_merge(
1384
-                $this->_add_event_id_to_where_conditions($request),
1385
-                $this->_add_category_id_to_where_conditions($request),
1386
-                $this->_add_datetime_id_to_where_conditions($request),
1387
-                $this->_add_registration_status_to_where_conditions($request),
1388
-                $this->_add_date_to_where_conditions($request),
1389
-                $this->_add_search_to_where_conditions($request)
1390
-            ),
1391
-            $request
1392
-        );
1393
-    }
1394
-
1395
-
1396
-    /**
1397
-     * Sets up the orderby for the registrations query.
1398
-     *
1399
-     * @return array
1400
-     */
1401
-    protected function _get_orderby_for_registrations_query()
1402
-    {
1403
-        $orderby_field = ! empty($this->_req_data['orderby'])
1404
-            ? sanitize_text_field($this->_req_data['orderby'])
1405
-            : '';
1406
-        switch ($orderby_field) {
1407
-            case '_REG_ID':
1408
-                $orderby_field = 'REG_ID';
1409
-                break;
1410
-            case '_Reg_status':
1411
-                $orderby_field = 'STS_ID';
1412
-                break;
1413
-            case 'ATT_fname':
1414
-                $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1415
-                break;
1416
-            case 'ATT_lname':
1417
-                $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1418
-                break;
1419
-            case 'event_name':
1420
-                $orderby_field = 'Event.EVT_name';
1421
-                break;
1422
-            case 'DTT_EVT_start':
1423
-                $orderby_field = 'Event.Datetime.DTT_EVT_start';
1424
-                break;
1425
-            default: //'REG_date'
1426
-                $orderby_field = 'REG_date';
1427
-        }
1428
-
1429
-        //order
1430
-        $order = ! empty($this->_req_data['order'])
1431
-            ? sanitize_text_field($this->_req_data['order'])
1432
-            : 'DESC';
1433
-
1434
-        //mutate orderby_field
1435
-        $orderby_field = array_combine(
1436
-            (array) $orderby_field,
1437
-            array_fill(0, count($orderby_field), $order)
1438
-        );
1439
-        return array('order_by' => $orderby_field);
1440
-    }
1441
-
1442
-
1443
-    /**
1444
-     * Sets up the limit for the registrations query.
1445
-     *
1446
-     * @param $per_page
1447
-     * @return array
1448
-     */
1449
-    protected function _get_limit($per_page)
1450
-    {
1451
-        $current_page = ! empty($this->_req_data['paged'])
1452
-            ? absint($this->_req_data['paged'])
1453
-            : 1;
1454
-        $per_page     = ! empty($this->_req_data['perpage'])
1455
-            ? $this->_req_data['perpage']
1456
-            : $per_page;
1457
-
1458
-        //-1 means return all results so get out if that's set.
1459
-        if ((int)$per_page === -1) {
1460
-            return array();
1461
-        }
1462
-        $per_page = absint($per_page);
1463
-        $offset   = ($current_page - 1) * $per_page;
1464
-        return array('limit' => array($offset, $per_page));
1465
-    }
1466
-
1467
-
1468
-    public function get_registration_status_array()
1469
-    {
1470
-        return self::$_reg_status;
1471
-    }
1472
-
1473
-
1474
-
1475
-
1476
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1477
-    /**
1478
-     *        generates HTML for the View Registration Details Admin page
1479
-     *
1480
-     * @access protected
1481
-     * @return void
1482
-     * @throws DomainException
1483
-     * @throws EE_Error
1484
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1485
-     */
1486
-    protected function _registration_details()
1487
-    {
1488
-        $this->_template_args = array();
1489
-        $this->_set_registration_object();
1490
-        if (is_object($this->_registration)) {
1491
-            $transaction                                   = $this->_registration->transaction()
1492
-                ? $this->_registration->transaction()
1493
-                : EE_Transaction::new_instance();
1494
-            $this->_session                                = $transaction->session_data();
1495
-            $event_id                                      = $this->_registration->event_ID();
1496
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1497
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1498
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1499
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1500
-            $this->_template_args['grand_total']           = $transaction->total();
1501
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1502
-            // link back to overview
1503
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1504
-            $this->_template_args['registration']                = $this->_registration;
1505
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1506
-                array(
1507
-                    'action'   => 'default',
1508
-                    'event_id' => $event_id,
1509
-                ),
1510
-                REG_ADMIN_URL
1511
-            );
1512
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1513
-                array(
1514
-                    'action' => 'default',
1515
-                    'EVT_ID' => $event_id,
1516
-                    'page'   => 'espresso_transactions',
1517
-                ),
1518
-                admin_url('admin.php')
1519
-            );
1520
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1521
-                array(
1522
-                    'page'   => 'espresso_events',
1523
-                    'action' => 'edit',
1524
-                    'post'   => $event_id,
1525
-                ),
1526
-                admin_url('admin.php')
1527
-            );
1528
-            //next and previous links
1529
-            $next_reg                                      = $this->_registration->next(
1530
-                null,
1531
-                array(),
1532
-                'REG_ID'
1533
-            );
1534
-            $this->_template_args['next_registration']     = $next_reg
1535
-                ? $this->_next_link(
1536
-                    EE_Admin_Page::add_query_args_and_nonce(
1537
-                        array(
1538
-                            'action'  => 'view_registration',
1539
-                            '_REG_ID' => $next_reg['REG_ID'],
1540
-                        ),
1541
-                        REG_ADMIN_URL
1542
-                    ),
1543
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1544
-                )
1545
-                : '';
1546
-            $previous_reg                                  = $this->_registration->previous(
1547
-                null,
1548
-                array(),
1549
-                'REG_ID'
1550
-            );
1551
-            $this->_template_args['previous_registration'] = $previous_reg
1552
-                ? $this->_previous_link(
1553
-                    EE_Admin_Page::add_query_args_and_nonce(
1554
-                        array(
1555
-                            'action'  => 'view_registration',
1556
-                            '_REG_ID' => $previous_reg['REG_ID'],
1557
-                        ),
1558
-                        REG_ADMIN_URL
1559
-                    ),
1560
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1561
-                )
1562
-                : '';
1563
-            // grab header
1564
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1565
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1566
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1567
-                $template_path,
1568
-                $this->_template_args,
1569
-                true
1570
-            );
1571
-        } else {
1572
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1573
-        }
1574
-        // the details template wrapper
1575
-        $this->display_admin_page_with_sidebar();
1576
-    }
1577
-
1578
-
1579
-    protected function _registration_details_metaboxes()
1580
-    {
1581
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1582
-        $this->_set_registration_object();
1583
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1584
-        add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1585
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1586
-        add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1587
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1588
-        if ($attendee instanceof EE_Attendee
1589
-            && EE_Registry::instance()->CAP->current_user_can(
1590
-                'ee_edit_registration',
1591
-                'edit-reg-questions-mbox'
1592
-            )
1593
-        ) {
1594
-            add_meta_box(
1595
-                'edit-reg-questions-mbox',
1596
-                esc_html__('Registration Form Answers', 'event_espresso'),
1597
-                array($this, '_reg_questions_meta_box'),
1598
-                $this->wp_page_slug,
1599
-                'normal',
1600
-                'high'
1601
-            );
1602
-        }
1603
-        add_meta_box(
1604
-            'edit-reg-registrant-mbox',
1605
-            esc_html__('Contact Details', 'event_espresso'),
1606
-            array($this, '_reg_registrant_side_meta_box'),
1607
-            $this->wp_page_slug,
1608
-            'side',
1609
-            'high'
1610
-        );
1611
-        if ($this->_registration->group_size() > 1) {
1612
-            add_meta_box(
1613
-                'edit-reg-attendees-mbox',
1614
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1615
-                array($this, '_reg_attendees_meta_box'),
1616
-                $this->wp_page_slug,
1617
-                'normal',
1618
-                'high'
1619
-            );
1620
-        }
1621
-    }
1622
-
1623
-
1624
-    /**
1625
-     * set_reg_status_buttons_metabox
1626
-     *
1627
-     * @access protected
1628
-     * @return string
1629
-     * @throws \EE_Error
1630
-     */
1631
-    public function set_reg_status_buttons_metabox()
1632
-    {
1633
-        $this->_set_registration_object();
1634
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1635
-        echo $change_reg_status_form->form_open(
1636
-            self::add_query_args_and_nonce(
1637
-                array(
1638
-                    'action' => 'change_reg_status',
1639
-                ),
1640
-                REG_ADMIN_URL
1641
-            )
1642
-        );
1643
-        echo $change_reg_status_form->get_html();
1644
-        echo $change_reg_status_form->form_close();
1645
-    }
1646
-
1647
-
1648
-
1649
-    /**
1650
-     * @return EE_Form_Section_Proper
1651
-     * @throws EE_Error
1652
-     */
1653
-    protected function _generate_reg_status_change_form()
1654
-    {
1655
-        return new EE_Form_Section_Proper(array(
1656
-            'name'            => 'reg_status_change_form',
1657
-            'html_id'         => 'reg-status-change-form',
1658
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1659
-            'subsections'     => array(
1660
-                'return'             => new EE_Hidden_Input(array(
1661
-                    'name'    => 'return',
1662
-                    'default' => 'view_registration',
1663
-                )),
1664
-                'REG_ID'             => new EE_Hidden_Input(array(
1665
-                    'name'    => 'REG_ID',
1666
-                    'default' => $this->_registration->ID(),
1667
-                )),
1668
-                'current_status'     => new EE_Form_Section_HTML(
1669
-                    EEH_HTML::tr(
1670
-                        EEH_HTML::th(
1671
-                            EEH_HTML::label(
1672
-                                EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1673
-                                )
1674
-                            )
1675
-                        )
1676
-                        . EEH_HTML::td(
1677
-                            EEH_HTML::strong(
1678
-                                $this->_registration->pretty_status(),
1679
-                                '',
1680
-                                'status-' . $this->_registration->status_ID(),
1681
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1682
-                            )
1683
-                        )
1684
-                    )
1685
-                ),
1686
-                'reg_status'         => new EE_Select_Input(
1687
-                    $this->_get_reg_statuses(),
1688
-                    array(
1689
-                        'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1690
-                        'default'         => $this->_registration->status_ID(),
1691
-                    )
1692
-                ),
1693
-                'send_notifications' => new EE_Yes_No_Input(
1694
-                    array(
1695
-                        'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1696
-                        'default'         => false,
1697
-                        'html_help_text'  => esc_html__(
1698
-                            'If set to "Yes", then the related messages will be sent to the registrant.',
1699
-                            'event_espresso'
1700
-                        ),
1701
-                    )
1702
-                ),
1703
-                'submit'             => new EE_Submit_Input(
1704
-                    array(
1705
-                        'html_class'      => 'button-primary',
1706
-                        'html_label_text' => '&nbsp;',
1707
-                        'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1708
-                    )
1709
-                ),
1710
-            ),
1711
-        ));
1712
-    }
1713
-
1714
-
1715
-    /**
1716
-     * Returns an array of all the buttons for the various statuses and switch status actions
1717
-     *
1718
-     * @return array
1719
-     * @throws EE_Error
1720
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1721
-     */
1722
-    protected function _get_reg_statuses()
1723
-    {
1724
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1725
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1726
-        // get current reg status
1727
-        $current_status = $this->_registration->status_ID();
1728
-        // is registration for free event? This will determine whether to display the pending payment option
1729
-        if (
1730
-            $current_status !== EEM_Registration::status_id_pending_payment
1731
-            && $this->_registration->transaction()->is_free()
1732
-        ) {
1733
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1734
-        }
1735
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1736
-    }
1737
-
1738
-
1739
-
1740
-    /**
1741
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1742
-     *
1743
-     * @param bool $status REG status given for changing registrations to.
1744
-     * @param bool $notify Whether to send messages notifications or not.
1745
-     * @return array  (array with reg_id(s) updated and whether update was successful.
1746
-     * @throws \EE_Error
1747
-     */
1748
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1749
-    {
1750
-        if (isset($this->_req_data['reg_status_change_form'])) {
1751
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1752
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1753
-        } else {
1754
-            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1755
-        }
1756
-        $success = $this->_set_registration_status($REG_IDs, $status);
1757
-        //notify?
1758
-        if ($success
1759
-            && $notify
1760
-            && EE_Registry::instance()->CAP->current_user_can(
1761
-                'ee_send_message',
1762
-                'espresso_registrations_resend_registration'
1763
-            )
1764
-        ) {
1765
-            $this->_process_resend_registration();
1766
-        }
1767
-        return $success;
1768
-    }
1769
-
1770
-
1771
-
1772
-    /**
1773
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1774
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1775
-     *
1776
-     * @param array $REG_IDs
1777
-     * @param bool  $status
1778
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1779
-     * @throws \RuntimeException
1780
-     * @throws \EE_Error
1781
-     *               the array of updated registrations).
1782
-     * @throws EE_Error
1783
-     * @throws RuntimeException
1784
-     */
1785
-    protected function _set_registration_status($REG_IDs = array(), $status = false)
1786
-    {
1787
-        $success = false;
1788
-        // typecast $REG_IDs
1789
-        $REG_IDs = (array)$REG_IDs;
1790
-        if ( ! empty($REG_IDs)) {
1791
-            $success = true;
1792
-            // set default status if none is passed
1793
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1794
-            // sanitize $REG_IDs
1795
-            $REG_IDs = array_filter($REG_IDs, 'absint');
1796
-            //loop through REG_ID's and change status
1797
-            foreach ($REG_IDs as $REG_ID) {
1798
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1799
-                if ($registration instanceof EE_Registration) {
1800
-                    $registration->set_status($status);
1801
-                    $result = $registration->save();
1802
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1803
-                    $success = $result !== false ? $success : false;
1804
-                }
1805
-            }
1806
-        }
1807
-        //reset _req_data['_REG_ID'] for any potential future messages notifications
1808
-        $this->_req_data['_REG_ID'] = $REG_IDs;
1809
-        //return $success and processed registrations
1810
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1811
-    }
1812
-
1813
-
1814
-    /**
1815
-     * Common logic for setting up success message and redirecting to appropriate route
1816
-     *
1817
-     * @param  string $STS_ID status id for the registration changed to
1818
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1819
-     * @return void
1820
-     */
1821
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1822
-    {
1823
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1824
-            : array('success' => false);
1825
-        $success = isset($result['success']) && $result['success'];
1826
-        //setup success message
1827
-        if ($success) {
1828
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1829
-                $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1830
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1831
-            } else {
1832
-                $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1833
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1834
-            }
1835
-            EE_Error::add_success($msg);
1836
-        } else {
1837
-            EE_Error::add_error(
1838
-                esc_html__(
1839
-                    'Something went wrong, and the status was not changed',
1840
-                    'event_espresso'
1841
-                ), __FILE__, __LINE__, __FUNCTION__
1842
-            );
1843
-        }
1844
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1845
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1846
-        } else {
1847
-            $route = array('action' => 'default');
1848
-        }
1849
-        //unset nonces
1850
-        foreach ($this->_req_data as $ref => $value) {
1851
-            if (strpos($ref, 'nonce') !== false) {
1852
-                unset($this->_req_data[$ref]);
1853
-                continue;
1854
-            }
1855
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1856
-            $this->_req_data[$ref] = $value;
1857
-        }
1858
-        //merge request vars so that the reloaded list table contains any existing filter query params
1859
-        $route = array_merge($this->_req_data, $route);
1860
-        $this->_redirect_after_action($success, '', '', $route, true);
1861
-    }
1862
-
1863
-
1864
-    /**
1865
-     * incoming reg status change from reg details page.
1866
-     *
1867
-     * @return void
1868
-     */
1869
-    protected function _change_reg_status()
1870
-    {
1871
-        $this->_req_data['return'] = 'view_registration';
1872
-        //set notify based on whether the send notifications toggle is set or not
1873
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1874
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1875
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1876
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1877
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1878
-            case EEM_Registration::status_id_approved :
1879
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1880
-                $this->approve_registration($notify);
1881
-                break;
1882
-            case EEM_Registration::status_id_pending_payment :
1883
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1884
-                $this->pending_registration($notify);
1885
-                break;
1886
-            case EEM_Registration::status_id_not_approved :
1887
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1888
-                $this->not_approve_registration($notify);
1889
-                break;
1890
-            case EEM_Registration::status_id_declined :
1891
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1892
-                $this->decline_registration($notify);
1893
-                break;
1894
-            case EEM_Registration::status_id_cancelled :
1895
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1896
-                $this->cancel_registration($notify);
1897
-                break;
1898
-            case EEM_Registration::status_id_wait_list :
1899
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1900
-                $this->wait_list_registration($notify);
1901
-                break;
1902
-            case EEM_Registration::status_id_incomplete :
1903
-            default :
1904
-                $result['success'] = false;
1905
-                unset($this->_req_data['return']);
1906
-                $this->_reg_status_change_return('', false);
1907
-                break;
1908
-        }
1909
-    }
1910
-
1911
-
1912
-    /**
1913
-     * Callback for bulk action routes.
1914
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1915
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1916
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1917
-     * when an action is happening on just a single registration).
1918
-     * @param      $action
1919
-     * @param bool $notify
1920
-     */
1921
-    protected function bulk_action_on_registrations($action, $notify = false) {
1922
-        do_action(
1923
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1924
-            $this,
1925
-            $action,
1926
-            $notify
1927
-        );
1928
-        $method = $action . '_registration';
1929
-        if (method_exists($this, $method)) {
1930
-            $this->$method($notify);
1931
-        }
1932
-    }
1933
-
1934
-
1935
-    /**
1936
-     * approve_registration
1937
-     *
1938
-     * @access protected
1939
-     * @param bool $notify whether or not to notify the registrant about their approval.
1940
-     * @return void
1941
-     */
1942
-    protected function approve_registration($notify = false)
1943
-    {
1944
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1945
-    }
1946
-
1947
-
1948
-    /**
1949
-     *        decline_registration
1950
-     *
1951
-     * @access protected
1952
-     * @param bool $notify whether or not to notify the registrant about their status change.
1953
-     * @return void
1954
-     */
1955
-    protected function decline_registration($notify = false)
1956
-    {
1957
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1958
-    }
1959
-
1960
-
1961
-    /**
1962
-     *        cancel_registration
1963
-     *
1964
-     * @access protected
1965
-     * @param bool $notify whether or not to notify the registrant about their status change.
1966
-     * @return void
1967
-     */
1968
-    protected function cancel_registration($notify = false)
1969
-    {
1970
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1971
-    }
1972
-
1973
-
1974
-    /**
1975
-     *        not_approve_registration
1976
-     *
1977
-     * @access protected
1978
-     * @param bool $notify whether or not to notify the registrant about their status change.
1979
-     * @return void
1980
-     */
1981
-    protected function not_approve_registration($notify = false)
1982
-    {
1983
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1984
-    }
1985
-
1986
-
1987
-    /**
1988
-     *        decline_registration
1989
-     *
1990
-     * @access protected
1991
-     * @param bool $notify whether or not to notify the registrant about their status change.
1992
-     * @return void
1993
-     */
1994
-    protected function pending_registration($notify = false)
1995
-    {
1996
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1997
-    }
1998
-
1999
-
2000
-    /**
2001
-     * waitlist_registration
2002
-     *
2003
-     * @access protected
2004
-     * @param bool $notify whether or not to notify the registrant about their status change.
2005
-     * @return void
2006
-     */
2007
-    protected function wait_list_registration($notify = false)
2008
-    {
2009
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2010
-    }
2011
-
2012
-
2013
-    /**
2014
-     *        generates HTML for the Registration main meta box
2015
-     *
2016
-     * @access public
2017
-     * @return void
2018
-     * @throws DomainException
2019
-     * @throws EE_Error
2020
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
2021
-     */
2022
-    public function _reg_details_meta_box()
2023
-    {
2024
-        EEH_Autoloader::register_line_item_display_autoloaders();
2025
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2026
-        EE_Registry::instance()->load_helper('Line_Item');
2027
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2028
-            : EE_Transaction::new_instance();
2029
-        $this->_session = $transaction->session_data();
2030
-        $filters        = new EE_Line_Item_Filter_Collection();
2031
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2032
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2033
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2034
-            $transaction->total_line_item());
2035
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2036
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2037
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2038
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2039
-            $filtered_line_item_tree,
2040
-            array('EE_Registration' => $this->_registration)
2041
-        );
2042
-        $attendee                                = $this->_registration->attendee();
2043
-        if (EE_Registry::instance()->CAP->current_user_can(
2044
-            'ee_read_transaction',
2045
-            'espresso_transactions_view_transaction'
2046
-        )) {
2047
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2048
-                EE_Admin_Page::add_query_args_and_nonce(
2049
-                    array(
2050
-                        'action' => 'view_transaction',
2051
-                        'TXN_ID' => $transaction->ID(),
2052
-                    ),
2053
-                    TXN_ADMIN_URL
2054
-                ),
2055
-                esc_html__(' View Transaction', 'event_espresso'),
2056
-                'button secondary-button right',
2057
-                'dashicons dashicons-cart'
2058
-            );
2059
-        } else {
2060
-            $this->_template_args['view_transaction_button'] = '';
2061
-        }
2062
-        if ($attendee instanceof EE_Attendee
2063
-            && EE_Registry::instance()->CAP->current_user_can(
2064
-                'ee_send_message',
2065
-                'espresso_registrations_resend_registration'
2066
-            )
2067
-        ) {
2068
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2069
-                EE_Admin_Page::add_query_args_and_nonce(
2070
-                    array(
2071
-                        'action'      => 'resend_registration',
2072
-                        '_REG_ID'     => $this->_registration->ID(),
2073
-                        'redirect_to' => 'view_registration',
2074
-                    ),
2075
-                    REG_ADMIN_URL
2076
-                ),
2077
-                esc_html__(' Resend Registration', 'event_espresso'),
2078
-                'button secondary-button right',
2079
-                'dashicons dashicons-email-alt'
2080
-            );
2081
-        } else {
2082
-            $this->_template_args['resend_registration_button'] = '';
2083
-        }
2084
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2085
-        $payment                               = $transaction->get_first_related('Payment');
2086
-        $payment                               = ! $payment instanceof EE_Payment
2087
-            ? EE_Payment::new_instance()
2088
-            : $payment;
2089
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2090
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2091
-            ? EE_Payment_Method::new_instance()
2092
-            : $payment_method;
2093
-        $reg_details                           = array(
2094
-            'payment_method'       => $payment_method->name(),
2095
-            'response_msg'         => $payment->gateway_response(),
2096
-            'registration_id'      => $this->_registration->get('REG_code'),
2097
-            'registration_session' => $this->_registration->session_ID(),
2098
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2099
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2100
-        );
2101
-        if (isset($reg_details['registration_id'])) {
2102
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2103
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2104
-                'Registration ID',
2105
-                'event_espresso'
2106
-            );
2107
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2108
-        }
2109
-        if (isset($reg_details['payment_method'])) {
2110
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2111
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2112
-                'Most Recent Payment Method',
2113
-                'event_espresso'
2114
-            );
2115
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2116
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2117
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2118
-                'Payment method response',
2119
-                'event_espresso'
2120
-            );
2121
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2122
-        }
2123
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2124
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2125
-            'Registration Session',
2126
-            'event_espresso'
2127
-        );
2128
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2129
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2130
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2131
-            'Registration placed from IP',
2132
-            'event_espresso'
2133
-        );
2134
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2135
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2136
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2137
-            'event_espresso');
2138
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2139
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2140
-            array(
2141
-                'action'   => 'default',
2142
-                'event_id' => $this->_registration->event_ID(),
2143
-            ),
2144
-            REG_ADMIN_URL
2145
-        );
2146
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2147
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2148
-        $template_path                                                        =
2149
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2150
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2151
-    }
2152
-
2153
-
2154
-    /**
2155
-     * generates HTML for the Registration Questions meta box.
2156
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2157
-     * otherwise uses new forms system
2158
-     *
2159
-     * @access public
2160
-     * @return void
2161
-     * @throws DomainException
2162
-     * @throws EE_Error
2163
-     */
2164
-    public function _reg_questions_meta_box()
2165
-    {
2166
-        //allow someone to override this method entirely
2167
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2168
-            $this->_registration)) {
2169
-            $form                                              = $this->_get_reg_custom_questions_form(
2170
-                $this->_registration->ID()
2171
-            );
2172
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2173
-                ? $form->get_html_and_js()
2174
-                : '';
2175
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2176
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2177
-            $template_path                                     =
2178
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2179
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2180
-        }
2181
-    }
2182
-
2183
-
2184
-    /**
2185
-     * form_before_question_group
2186
-     *
2187
-     * @deprecated    as of 4.8.32.rc.000
2188
-     * @access        public
2189
-     * @param        string $output
2190
-     * @return        string
2191
-     */
2192
-    public function form_before_question_group($output)
2193
-    {
2194
-        EE_Error::doing_it_wrong(
2195
-            __CLASS__ . '::' . __FUNCTION__,
2196
-            esc_html__(
2197
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2198
-                'event_espresso'
2199
-            ),
2200
-            '4.8.32.rc.000'
2201
-        );
2202
-        return '
1236
+		if (! empty($registration_status)) {
1237
+			$where['STS_ID'] = $registration_status;
1238
+		} else {
1239
+			//make sure we exclude incomplete registrations, but only if not trashed.
1240
+			if ($view === 'trash') {
1241
+				$where['REG_deleted'] = true;
1242
+			} elseif ($view === 'incomplete') {
1243
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1244
+			} else {
1245
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1246
+			}
1247
+		}
1248
+		return $where;
1249
+	}
1250
+
1251
+
1252
+	/**
1253
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1254
+	 *
1255
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1256
+	 * @return array
1257
+	 * @throws EE_Error
1258
+	 */
1259
+	protected function _add_date_to_where_conditions(array $request)
1260
+	{
1261
+		$where = array();
1262
+		$view = EEH_Array::is_set($request, 'status', '');
1263
+		$month_range             = ! empty($request['month_range'])
1264
+			? sanitize_text_field($request['month_range'])
1265
+			: '';
1266
+		$retrieve_for_today      = $view === 'today';
1267
+		$retrieve_for_this_month = $view === 'month';
1268
+
1269
+		if ($retrieve_for_today) {
1270
+			$now               = date('Y-m-d', current_time('timestamp'));
1271
+			$where['REG_date'] = array(
1272
+				'BETWEEN',
1273
+				array(
1274
+					EEM_Registration::instance()->convert_datetime_for_query(
1275
+						'REG_date',
1276
+						$now . ' 00:00:00',
1277
+						'Y-m-d H:i:s'
1278
+					),
1279
+					EEM_Registration::instance()->convert_datetime_for_query(
1280
+						'REG_date',
1281
+						$now . ' 23:59:59',
1282
+						'Y-m-d H:i:s'
1283
+					),
1284
+				),
1285
+			);
1286
+		} elseif ($retrieve_for_this_month) {
1287
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1288
+			$days_this_month        = date('t', current_time('timestamp'));
1289
+			$where['REG_date']      = array(
1290
+				'BETWEEN',
1291
+				array(
1292
+					EEM_Registration::instance()->convert_datetime_for_query(
1293
+						'REG_date',
1294
+						$current_year_and_month . '-01 00:00:00',
1295
+						'Y-m-d H:i:s'
1296
+					),
1297
+					EEM_Registration::instance()->convert_datetime_for_query(
1298
+						'REG_date',
1299
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1300
+						'Y-m-d H:i:s'
1301
+					),
1302
+				),
1303
+			);
1304
+		} elseif ($month_range) {
1305
+			$pieces          = explode(' ', $month_range, 3);
1306
+			$month_requested = ! empty($pieces[0])
1307
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1308
+				: '';
1309
+			$year_requested  = ! empty($pieces[1])
1310
+				? $pieces[1]
1311
+				: '';
1312
+			//if there is not a month or year then we can't go further
1313
+			if ($month_requested && $year_requested) {
1314
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1315
+				$where['REG_date'] = array(
1316
+					'BETWEEN',
1317
+					array(
1318
+						EEM_Registration::instance()->convert_datetime_for_query(
1319
+							'REG_date',
1320
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1321
+							'Y-m-d H:i:s'
1322
+						),
1323
+						EEM_Registration::instance()->convert_datetime_for_query(
1324
+							'REG_date',
1325
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1326
+							'Y-m-d H:i:s'
1327
+						),
1328
+					),
1329
+				);
1330
+			}
1331
+		}
1332
+		return $where;
1333
+	}
1334
+
1335
+
1336
+	/**
1337
+	 * Adds any provided search restraints to the where conditions for the registrations query
1338
+	 *
1339
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1340
+	 * @return array
1341
+	 */
1342
+	protected function _add_search_to_where_conditions(array $request)
1343
+	{
1344
+		$where = array();
1345
+		if (! empty($request['s'])) {
1346
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1347
+			$where['OR*search_conditions'] = array(
1348
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1349
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1350
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1351
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1352
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1353
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1354
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1355
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1356
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1357
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1358
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1359
+				'REG_final_price'                         => array('LIKE', $search_string),
1360
+				'REG_code'                                => array('LIKE', $search_string),
1361
+				'REG_count'                               => array('LIKE', $search_string),
1362
+				'REG_group_size'                          => array('LIKE', $search_string),
1363
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1364
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1365
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1366
+			);
1367
+		}
1368
+		return $where;
1369
+	}
1370
+
1371
+
1372
+	/**
1373
+	 * Sets up the where conditions for the registrations query.
1374
+	 *
1375
+	 * @param array $request
1376
+	 * @return array
1377
+	 * @throws EE_Error
1378
+	 */
1379
+	protected function _get_where_conditions_for_registrations_query($request)
1380
+	{
1381
+		return apply_filters(
1382
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1383
+			array_merge(
1384
+				$this->_add_event_id_to_where_conditions($request),
1385
+				$this->_add_category_id_to_where_conditions($request),
1386
+				$this->_add_datetime_id_to_where_conditions($request),
1387
+				$this->_add_registration_status_to_where_conditions($request),
1388
+				$this->_add_date_to_where_conditions($request),
1389
+				$this->_add_search_to_where_conditions($request)
1390
+			),
1391
+			$request
1392
+		);
1393
+	}
1394
+
1395
+
1396
+	/**
1397
+	 * Sets up the orderby for the registrations query.
1398
+	 *
1399
+	 * @return array
1400
+	 */
1401
+	protected function _get_orderby_for_registrations_query()
1402
+	{
1403
+		$orderby_field = ! empty($this->_req_data['orderby'])
1404
+			? sanitize_text_field($this->_req_data['orderby'])
1405
+			: '';
1406
+		switch ($orderby_field) {
1407
+			case '_REG_ID':
1408
+				$orderby_field = 'REG_ID';
1409
+				break;
1410
+			case '_Reg_status':
1411
+				$orderby_field = 'STS_ID';
1412
+				break;
1413
+			case 'ATT_fname':
1414
+				$orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1415
+				break;
1416
+			case 'ATT_lname':
1417
+				$orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1418
+				break;
1419
+			case 'event_name':
1420
+				$orderby_field = 'Event.EVT_name';
1421
+				break;
1422
+			case 'DTT_EVT_start':
1423
+				$orderby_field = 'Event.Datetime.DTT_EVT_start';
1424
+				break;
1425
+			default: //'REG_date'
1426
+				$orderby_field = 'REG_date';
1427
+		}
1428
+
1429
+		//order
1430
+		$order = ! empty($this->_req_data['order'])
1431
+			? sanitize_text_field($this->_req_data['order'])
1432
+			: 'DESC';
1433
+
1434
+		//mutate orderby_field
1435
+		$orderby_field = array_combine(
1436
+			(array) $orderby_field,
1437
+			array_fill(0, count($orderby_field), $order)
1438
+		);
1439
+		return array('order_by' => $orderby_field);
1440
+	}
1441
+
1442
+
1443
+	/**
1444
+	 * Sets up the limit for the registrations query.
1445
+	 *
1446
+	 * @param $per_page
1447
+	 * @return array
1448
+	 */
1449
+	protected function _get_limit($per_page)
1450
+	{
1451
+		$current_page = ! empty($this->_req_data['paged'])
1452
+			? absint($this->_req_data['paged'])
1453
+			: 1;
1454
+		$per_page     = ! empty($this->_req_data['perpage'])
1455
+			? $this->_req_data['perpage']
1456
+			: $per_page;
1457
+
1458
+		//-1 means return all results so get out if that's set.
1459
+		if ((int)$per_page === -1) {
1460
+			return array();
1461
+		}
1462
+		$per_page = absint($per_page);
1463
+		$offset   = ($current_page - 1) * $per_page;
1464
+		return array('limit' => array($offset, $per_page));
1465
+	}
1466
+
1467
+
1468
+	public function get_registration_status_array()
1469
+	{
1470
+		return self::$_reg_status;
1471
+	}
1472
+
1473
+
1474
+
1475
+
1476
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1477
+	/**
1478
+	 *        generates HTML for the View Registration Details Admin page
1479
+	 *
1480
+	 * @access protected
1481
+	 * @return void
1482
+	 * @throws DomainException
1483
+	 * @throws EE_Error
1484
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1485
+	 */
1486
+	protected function _registration_details()
1487
+	{
1488
+		$this->_template_args = array();
1489
+		$this->_set_registration_object();
1490
+		if (is_object($this->_registration)) {
1491
+			$transaction                                   = $this->_registration->transaction()
1492
+				? $this->_registration->transaction()
1493
+				: EE_Transaction::new_instance();
1494
+			$this->_session                                = $transaction->session_data();
1495
+			$event_id                                      = $this->_registration->event_ID();
1496
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1497
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1498
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1499
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1500
+			$this->_template_args['grand_total']           = $transaction->total();
1501
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1502
+			// link back to overview
1503
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1504
+			$this->_template_args['registration']                = $this->_registration;
1505
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1506
+				array(
1507
+					'action'   => 'default',
1508
+					'event_id' => $event_id,
1509
+				),
1510
+				REG_ADMIN_URL
1511
+			);
1512
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1513
+				array(
1514
+					'action' => 'default',
1515
+					'EVT_ID' => $event_id,
1516
+					'page'   => 'espresso_transactions',
1517
+				),
1518
+				admin_url('admin.php')
1519
+			);
1520
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1521
+				array(
1522
+					'page'   => 'espresso_events',
1523
+					'action' => 'edit',
1524
+					'post'   => $event_id,
1525
+				),
1526
+				admin_url('admin.php')
1527
+			);
1528
+			//next and previous links
1529
+			$next_reg                                      = $this->_registration->next(
1530
+				null,
1531
+				array(),
1532
+				'REG_ID'
1533
+			);
1534
+			$this->_template_args['next_registration']     = $next_reg
1535
+				? $this->_next_link(
1536
+					EE_Admin_Page::add_query_args_and_nonce(
1537
+						array(
1538
+							'action'  => 'view_registration',
1539
+							'_REG_ID' => $next_reg['REG_ID'],
1540
+						),
1541
+						REG_ADMIN_URL
1542
+					),
1543
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1544
+				)
1545
+				: '';
1546
+			$previous_reg                                  = $this->_registration->previous(
1547
+				null,
1548
+				array(),
1549
+				'REG_ID'
1550
+			);
1551
+			$this->_template_args['previous_registration'] = $previous_reg
1552
+				? $this->_previous_link(
1553
+					EE_Admin_Page::add_query_args_and_nonce(
1554
+						array(
1555
+							'action'  => 'view_registration',
1556
+							'_REG_ID' => $previous_reg['REG_ID'],
1557
+						),
1558
+						REG_ADMIN_URL
1559
+					),
1560
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1561
+				)
1562
+				: '';
1563
+			// grab header
1564
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1565
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1566
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1567
+				$template_path,
1568
+				$this->_template_args,
1569
+				true
1570
+			);
1571
+		} else {
1572
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1573
+		}
1574
+		// the details template wrapper
1575
+		$this->display_admin_page_with_sidebar();
1576
+	}
1577
+
1578
+
1579
+	protected function _registration_details_metaboxes()
1580
+	{
1581
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1582
+		$this->_set_registration_object();
1583
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1584
+		add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1585
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1586
+		add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1587
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1588
+		if ($attendee instanceof EE_Attendee
1589
+			&& EE_Registry::instance()->CAP->current_user_can(
1590
+				'ee_edit_registration',
1591
+				'edit-reg-questions-mbox'
1592
+			)
1593
+		) {
1594
+			add_meta_box(
1595
+				'edit-reg-questions-mbox',
1596
+				esc_html__('Registration Form Answers', 'event_espresso'),
1597
+				array($this, '_reg_questions_meta_box'),
1598
+				$this->wp_page_slug,
1599
+				'normal',
1600
+				'high'
1601
+			);
1602
+		}
1603
+		add_meta_box(
1604
+			'edit-reg-registrant-mbox',
1605
+			esc_html__('Contact Details', 'event_espresso'),
1606
+			array($this, '_reg_registrant_side_meta_box'),
1607
+			$this->wp_page_slug,
1608
+			'side',
1609
+			'high'
1610
+		);
1611
+		if ($this->_registration->group_size() > 1) {
1612
+			add_meta_box(
1613
+				'edit-reg-attendees-mbox',
1614
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1615
+				array($this, '_reg_attendees_meta_box'),
1616
+				$this->wp_page_slug,
1617
+				'normal',
1618
+				'high'
1619
+			);
1620
+		}
1621
+	}
1622
+
1623
+
1624
+	/**
1625
+	 * set_reg_status_buttons_metabox
1626
+	 *
1627
+	 * @access protected
1628
+	 * @return string
1629
+	 * @throws \EE_Error
1630
+	 */
1631
+	public function set_reg_status_buttons_metabox()
1632
+	{
1633
+		$this->_set_registration_object();
1634
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1635
+		echo $change_reg_status_form->form_open(
1636
+			self::add_query_args_and_nonce(
1637
+				array(
1638
+					'action' => 'change_reg_status',
1639
+				),
1640
+				REG_ADMIN_URL
1641
+			)
1642
+		);
1643
+		echo $change_reg_status_form->get_html();
1644
+		echo $change_reg_status_form->form_close();
1645
+	}
1646
+
1647
+
1648
+
1649
+	/**
1650
+	 * @return EE_Form_Section_Proper
1651
+	 * @throws EE_Error
1652
+	 */
1653
+	protected function _generate_reg_status_change_form()
1654
+	{
1655
+		return new EE_Form_Section_Proper(array(
1656
+			'name'            => 'reg_status_change_form',
1657
+			'html_id'         => 'reg-status-change-form',
1658
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1659
+			'subsections'     => array(
1660
+				'return'             => new EE_Hidden_Input(array(
1661
+					'name'    => 'return',
1662
+					'default' => 'view_registration',
1663
+				)),
1664
+				'REG_ID'             => new EE_Hidden_Input(array(
1665
+					'name'    => 'REG_ID',
1666
+					'default' => $this->_registration->ID(),
1667
+				)),
1668
+				'current_status'     => new EE_Form_Section_HTML(
1669
+					EEH_HTML::tr(
1670
+						EEH_HTML::th(
1671
+							EEH_HTML::label(
1672
+								EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1673
+								)
1674
+							)
1675
+						)
1676
+						. EEH_HTML::td(
1677
+							EEH_HTML::strong(
1678
+								$this->_registration->pretty_status(),
1679
+								'',
1680
+								'status-' . $this->_registration->status_ID(),
1681
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1682
+							)
1683
+						)
1684
+					)
1685
+				),
1686
+				'reg_status'         => new EE_Select_Input(
1687
+					$this->_get_reg_statuses(),
1688
+					array(
1689
+						'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1690
+						'default'         => $this->_registration->status_ID(),
1691
+					)
1692
+				),
1693
+				'send_notifications' => new EE_Yes_No_Input(
1694
+					array(
1695
+						'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1696
+						'default'         => false,
1697
+						'html_help_text'  => esc_html__(
1698
+							'If set to "Yes", then the related messages will be sent to the registrant.',
1699
+							'event_espresso'
1700
+						),
1701
+					)
1702
+				),
1703
+				'submit'             => new EE_Submit_Input(
1704
+					array(
1705
+						'html_class'      => 'button-primary',
1706
+						'html_label_text' => '&nbsp;',
1707
+						'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1708
+					)
1709
+				),
1710
+			),
1711
+		));
1712
+	}
1713
+
1714
+
1715
+	/**
1716
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1717
+	 *
1718
+	 * @return array
1719
+	 * @throws EE_Error
1720
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1721
+	 */
1722
+	protected function _get_reg_statuses()
1723
+	{
1724
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1725
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1726
+		// get current reg status
1727
+		$current_status = $this->_registration->status_ID();
1728
+		// is registration for free event? This will determine whether to display the pending payment option
1729
+		if (
1730
+			$current_status !== EEM_Registration::status_id_pending_payment
1731
+			&& $this->_registration->transaction()->is_free()
1732
+		) {
1733
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1734
+		}
1735
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1736
+	}
1737
+
1738
+
1739
+
1740
+	/**
1741
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1742
+	 *
1743
+	 * @param bool $status REG status given for changing registrations to.
1744
+	 * @param bool $notify Whether to send messages notifications or not.
1745
+	 * @return array  (array with reg_id(s) updated and whether update was successful.
1746
+	 * @throws \EE_Error
1747
+	 */
1748
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1749
+	{
1750
+		if (isset($this->_req_data['reg_status_change_form'])) {
1751
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1752
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1753
+		} else {
1754
+			$REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1755
+		}
1756
+		$success = $this->_set_registration_status($REG_IDs, $status);
1757
+		//notify?
1758
+		if ($success
1759
+			&& $notify
1760
+			&& EE_Registry::instance()->CAP->current_user_can(
1761
+				'ee_send_message',
1762
+				'espresso_registrations_resend_registration'
1763
+			)
1764
+		) {
1765
+			$this->_process_resend_registration();
1766
+		}
1767
+		return $success;
1768
+	}
1769
+
1770
+
1771
+
1772
+	/**
1773
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1774
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1775
+	 *
1776
+	 * @param array $REG_IDs
1777
+	 * @param bool  $status
1778
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1779
+	 * @throws \RuntimeException
1780
+	 * @throws \EE_Error
1781
+	 *               the array of updated registrations).
1782
+	 * @throws EE_Error
1783
+	 * @throws RuntimeException
1784
+	 */
1785
+	protected function _set_registration_status($REG_IDs = array(), $status = false)
1786
+	{
1787
+		$success = false;
1788
+		// typecast $REG_IDs
1789
+		$REG_IDs = (array)$REG_IDs;
1790
+		if ( ! empty($REG_IDs)) {
1791
+			$success = true;
1792
+			// set default status if none is passed
1793
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1794
+			// sanitize $REG_IDs
1795
+			$REG_IDs = array_filter($REG_IDs, 'absint');
1796
+			//loop through REG_ID's and change status
1797
+			foreach ($REG_IDs as $REG_ID) {
1798
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1799
+				if ($registration instanceof EE_Registration) {
1800
+					$registration->set_status($status);
1801
+					$result = $registration->save();
1802
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1803
+					$success = $result !== false ? $success : false;
1804
+				}
1805
+			}
1806
+		}
1807
+		//reset _req_data['_REG_ID'] for any potential future messages notifications
1808
+		$this->_req_data['_REG_ID'] = $REG_IDs;
1809
+		//return $success and processed registrations
1810
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1811
+	}
1812
+
1813
+
1814
+	/**
1815
+	 * Common logic for setting up success message and redirecting to appropriate route
1816
+	 *
1817
+	 * @param  string $STS_ID status id for the registration changed to
1818
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1819
+	 * @return void
1820
+	 */
1821
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1822
+	{
1823
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1824
+			: array('success' => false);
1825
+		$success = isset($result['success']) && $result['success'];
1826
+		//setup success message
1827
+		if ($success) {
1828
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1829
+				$msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1830
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1831
+			} else {
1832
+				$msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1833
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1834
+			}
1835
+			EE_Error::add_success($msg);
1836
+		} else {
1837
+			EE_Error::add_error(
1838
+				esc_html__(
1839
+					'Something went wrong, and the status was not changed',
1840
+					'event_espresso'
1841
+				), __FILE__, __LINE__, __FUNCTION__
1842
+			);
1843
+		}
1844
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1845
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1846
+		} else {
1847
+			$route = array('action' => 'default');
1848
+		}
1849
+		//unset nonces
1850
+		foreach ($this->_req_data as $ref => $value) {
1851
+			if (strpos($ref, 'nonce') !== false) {
1852
+				unset($this->_req_data[$ref]);
1853
+				continue;
1854
+			}
1855
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1856
+			$this->_req_data[$ref] = $value;
1857
+		}
1858
+		//merge request vars so that the reloaded list table contains any existing filter query params
1859
+		$route = array_merge($this->_req_data, $route);
1860
+		$this->_redirect_after_action($success, '', '', $route, true);
1861
+	}
1862
+
1863
+
1864
+	/**
1865
+	 * incoming reg status change from reg details page.
1866
+	 *
1867
+	 * @return void
1868
+	 */
1869
+	protected function _change_reg_status()
1870
+	{
1871
+		$this->_req_data['return'] = 'view_registration';
1872
+		//set notify based on whether the send notifications toggle is set or not
1873
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1874
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1875
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1876
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1877
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1878
+			case EEM_Registration::status_id_approved :
1879
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1880
+				$this->approve_registration($notify);
1881
+				break;
1882
+			case EEM_Registration::status_id_pending_payment :
1883
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1884
+				$this->pending_registration($notify);
1885
+				break;
1886
+			case EEM_Registration::status_id_not_approved :
1887
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1888
+				$this->not_approve_registration($notify);
1889
+				break;
1890
+			case EEM_Registration::status_id_declined :
1891
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1892
+				$this->decline_registration($notify);
1893
+				break;
1894
+			case EEM_Registration::status_id_cancelled :
1895
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1896
+				$this->cancel_registration($notify);
1897
+				break;
1898
+			case EEM_Registration::status_id_wait_list :
1899
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1900
+				$this->wait_list_registration($notify);
1901
+				break;
1902
+			case EEM_Registration::status_id_incomplete :
1903
+			default :
1904
+				$result['success'] = false;
1905
+				unset($this->_req_data['return']);
1906
+				$this->_reg_status_change_return('', false);
1907
+				break;
1908
+		}
1909
+	}
1910
+
1911
+
1912
+	/**
1913
+	 * Callback for bulk action routes.
1914
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1915
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1916
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1917
+	 * when an action is happening on just a single registration).
1918
+	 * @param      $action
1919
+	 * @param bool $notify
1920
+	 */
1921
+	protected function bulk_action_on_registrations($action, $notify = false) {
1922
+		do_action(
1923
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1924
+			$this,
1925
+			$action,
1926
+			$notify
1927
+		);
1928
+		$method = $action . '_registration';
1929
+		if (method_exists($this, $method)) {
1930
+			$this->$method($notify);
1931
+		}
1932
+	}
1933
+
1934
+
1935
+	/**
1936
+	 * approve_registration
1937
+	 *
1938
+	 * @access protected
1939
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1940
+	 * @return void
1941
+	 */
1942
+	protected function approve_registration($notify = false)
1943
+	{
1944
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1945
+	}
1946
+
1947
+
1948
+	/**
1949
+	 *        decline_registration
1950
+	 *
1951
+	 * @access protected
1952
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1953
+	 * @return void
1954
+	 */
1955
+	protected function decline_registration($notify = false)
1956
+	{
1957
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1958
+	}
1959
+
1960
+
1961
+	/**
1962
+	 *        cancel_registration
1963
+	 *
1964
+	 * @access protected
1965
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1966
+	 * @return void
1967
+	 */
1968
+	protected function cancel_registration($notify = false)
1969
+	{
1970
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1971
+	}
1972
+
1973
+
1974
+	/**
1975
+	 *        not_approve_registration
1976
+	 *
1977
+	 * @access protected
1978
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1979
+	 * @return void
1980
+	 */
1981
+	protected function not_approve_registration($notify = false)
1982
+	{
1983
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1984
+	}
1985
+
1986
+
1987
+	/**
1988
+	 *        decline_registration
1989
+	 *
1990
+	 * @access protected
1991
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1992
+	 * @return void
1993
+	 */
1994
+	protected function pending_registration($notify = false)
1995
+	{
1996
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1997
+	}
1998
+
1999
+
2000
+	/**
2001
+	 * waitlist_registration
2002
+	 *
2003
+	 * @access protected
2004
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2005
+	 * @return void
2006
+	 */
2007
+	protected function wait_list_registration($notify = false)
2008
+	{
2009
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2010
+	}
2011
+
2012
+
2013
+	/**
2014
+	 *        generates HTML for the Registration main meta box
2015
+	 *
2016
+	 * @access public
2017
+	 * @return void
2018
+	 * @throws DomainException
2019
+	 * @throws EE_Error
2020
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
2021
+	 */
2022
+	public function _reg_details_meta_box()
2023
+	{
2024
+		EEH_Autoloader::register_line_item_display_autoloaders();
2025
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2026
+		EE_Registry::instance()->load_helper('Line_Item');
2027
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2028
+			: EE_Transaction::new_instance();
2029
+		$this->_session = $transaction->session_data();
2030
+		$filters        = new EE_Line_Item_Filter_Collection();
2031
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2032
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2033
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2034
+			$transaction->total_line_item());
2035
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2036
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2037
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2038
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2039
+			$filtered_line_item_tree,
2040
+			array('EE_Registration' => $this->_registration)
2041
+		);
2042
+		$attendee                                = $this->_registration->attendee();
2043
+		if (EE_Registry::instance()->CAP->current_user_can(
2044
+			'ee_read_transaction',
2045
+			'espresso_transactions_view_transaction'
2046
+		)) {
2047
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2048
+				EE_Admin_Page::add_query_args_and_nonce(
2049
+					array(
2050
+						'action' => 'view_transaction',
2051
+						'TXN_ID' => $transaction->ID(),
2052
+					),
2053
+					TXN_ADMIN_URL
2054
+				),
2055
+				esc_html__(' View Transaction', 'event_espresso'),
2056
+				'button secondary-button right',
2057
+				'dashicons dashicons-cart'
2058
+			);
2059
+		} else {
2060
+			$this->_template_args['view_transaction_button'] = '';
2061
+		}
2062
+		if ($attendee instanceof EE_Attendee
2063
+			&& EE_Registry::instance()->CAP->current_user_can(
2064
+				'ee_send_message',
2065
+				'espresso_registrations_resend_registration'
2066
+			)
2067
+		) {
2068
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2069
+				EE_Admin_Page::add_query_args_and_nonce(
2070
+					array(
2071
+						'action'      => 'resend_registration',
2072
+						'_REG_ID'     => $this->_registration->ID(),
2073
+						'redirect_to' => 'view_registration',
2074
+					),
2075
+					REG_ADMIN_URL
2076
+				),
2077
+				esc_html__(' Resend Registration', 'event_espresso'),
2078
+				'button secondary-button right',
2079
+				'dashicons dashicons-email-alt'
2080
+			);
2081
+		} else {
2082
+			$this->_template_args['resend_registration_button'] = '';
2083
+		}
2084
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2085
+		$payment                               = $transaction->get_first_related('Payment');
2086
+		$payment                               = ! $payment instanceof EE_Payment
2087
+			? EE_Payment::new_instance()
2088
+			: $payment;
2089
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2090
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2091
+			? EE_Payment_Method::new_instance()
2092
+			: $payment_method;
2093
+		$reg_details                           = array(
2094
+			'payment_method'       => $payment_method->name(),
2095
+			'response_msg'         => $payment->gateway_response(),
2096
+			'registration_id'      => $this->_registration->get('REG_code'),
2097
+			'registration_session' => $this->_registration->session_ID(),
2098
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2099
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2100
+		);
2101
+		if (isset($reg_details['registration_id'])) {
2102
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2103
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2104
+				'Registration ID',
2105
+				'event_espresso'
2106
+			);
2107
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2108
+		}
2109
+		if (isset($reg_details['payment_method'])) {
2110
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2111
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2112
+				'Most Recent Payment Method',
2113
+				'event_espresso'
2114
+			);
2115
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2116
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2117
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2118
+				'Payment method response',
2119
+				'event_espresso'
2120
+			);
2121
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2122
+		}
2123
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2124
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2125
+			'Registration Session',
2126
+			'event_espresso'
2127
+		);
2128
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2129
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2130
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2131
+			'Registration placed from IP',
2132
+			'event_espresso'
2133
+		);
2134
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2135
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2136
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2137
+			'event_espresso');
2138
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2139
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2140
+			array(
2141
+				'action'   => 'default',
2142
+				'event_id' => $this->_registration->event_ID(),
2143
+			),
2144
+			REG_ADMIN_URL
2145
+		);
2146
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2147
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2148
+		$template_path                                                        =
2149
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2150
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2151
+	}
2152
+
2153
+
2154
+	/**
2155
+	 * generates HTML for the Registration Questions meta box.
2156
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2157
+	 * otherwise uses new forms system
2158
+	 *
2159
+	 * @access public
2160
+	 * @return void
2161
+	 * @throws DomainException
2162
+	 * @throws EE_Error
2163
+	 */
2164
+	public function _reg_questions_meta_box()
2165
+	{
2166
+		//allow someone to override this method entirely
2167
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2168
+			$this->_registration)) {
2169
+			$form                                              = $this->_get_reg_custom_questions_form(
2170
+				$this->_registration->ID()
2171
+			);
2172
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2173
+				? $form->get_html_and_js()
2174
+				: '';
2175
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2176
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2177
+			$template_path                                     =
2178
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2179
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2180
+		}
2181
+	}
2182
+
2183
+
2184
+	/**
2185
+	 * form_before_question_group
2186
+	 *
2187
+	 * @deprecated    as of 4.8.32.rc.000
2188
+	 * @access        public
2189
+	 * @param        string $output
2190
+	 * @return        string
2191
+	 */
2192
+	public function form_before_question_group($output)
2193
+	{
2194
+		EE_Error::doing_it_wrong(
2195
+			__CLASS__ . '::' . __FUNCTION__,
2196
+			esc_html__(
2197
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2198
+				'event_espresso'
2199
+			),
2200
+			'4.8.32.rc.000'
2201
+		);
2202
+		return '
2203 2203
 	<table class="form-table ee-width-100">
2204 2204
 		<tbody>
2205 2205
 			';
2206
-    }
2207
-
2208
-
2209
-    /**
2210
-     * form_after_question_group
2211
-     *
2212
-     * @deprecated    as of 4.8.32.rc.000
2213
-     * @access        public
2214
-     * @param        string $output
2215
-     * @return        string
2216
-     */
2217
-    public function form_after_question_group($output)
2218
-    {
2219
-        EE_Error::doing_it_wrong(
2220
-            __CLASS__ . '::' . __FUNCTION__,
2221
-            esc_html__(
2222
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2223
-                'event_espresso'
2224
-            ),
2225
-            '4.8.32.rc.000'
2226
-        );
2227
-        return '
2206
+	}
2207
+
2208
+
2209
+	/**
2210
+	 * form_after_question_group
2211
+	 *
2212
+	 * @deprecated    as of 4.8.32.rc.000
2213
+	 * @access        public
2214
+	 * @param        string $output
2215
+	 * @return        string
2216
+	 */
2217
+	public function form_after_question_group($output)
2218
+	{
2219
+		EE_Error::doing_it_wrong(
2220
+			__CLASS__ . '::' . __FUNCTION__,
2221
+			esc_html__(
2222
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2223
+				'event_espresso'
2224
+			),
2225
+			'4.8.32.rc.000'
2226
+		);
2227
+		return '
2228 2228
 			<tr class="hide-if-no-js">
2229 2229
 				<th> </th>
2230 2230
 				<td class="reg-admin-edit-attendee-question-td">
2231 2231
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2232
-               . esc_attr__('click to edit question', 'event_espresso')
2233
-               . '">
2232
+			   . esc_attr__('click to edit question', 'event_espresso')
2233
+			   . '">
2234 2234
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2235
-               . esc_html__('edit the above question group', 'event_espresso')
2236
-               . '</span>
2235
+			   . esc_html__('edit the above question group', 'event_espresso')
2236
+			   . '</span>
2237 2237
 						<div class="dashicons dashicons-edit"></div>
2238 2238
 					</a>
2239 2239
 				</td>
@@ -2241,558 +2241,558 @@  discard block
 block discarded – undo
2241 2241
 		</tbody>
2242 2242
 	</table>
2243 2243
 ';
2244
-    }
2245
-
2246
-
2247
-    /**
2248
-     * form_form_field_label_wrap
2249
-     *
2250
-     * @deprecated    as of 4.8.32.rc.000
2251
-     * @access        public
2252
-     * @param        string $label
2253
-     * @return        string
2254
-     */
2255
-    public function form_form_field_label_wrap($label)
2256
-    {
2257
-        EE_Error::doing_it_wrong(
2258
-            __CLASS__ . '::' . __FUNCTION__,
2259
-            esc_html__(
2260
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2261
-                'event_espresso'
2262
-            ),
2263
-            '4.8.32.rc.000'
2264
-        );
2265
-        return '
2244
+	}
2245
+
2246
+
2247
+	/**
2248
+	 * form_form_field_label_wrap
2249
+	 *
2250
+	 * @deprecated    as of 4.8.32.rc.000
2251
+	 * @access        public
2252
+	 * @param        string $label
2253
+	 * @return        string
2254
+	 */
2255
+	public function form_form_field_label_wrap($label)
2256
+	{
2257
+		EE_Error::doing_it_wrong(
2258
+			__CLASS__ . '::' . __FUNCTION__,
2259
+			esc_html__(
2260
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2261
+				'event_espresso'
2262
+			),
2263
+			'4.8.32.rc.000'
2264
+		);
2265
+		return '
2266 2266
 			<tr>
2267 2267
 				<th>
2268 2268
 					' . $label . '
2269 2269
 				</th>';
2270
-    }
2271
-
2272
-
2273
-    /**
2274
-     * form_form_field_input__wrap
2275
-     *
2276
-     * @deprecated    as of 4.8.32.rc.000
2277
-     * @access        public
2278
-     * @param        string $input
2279
-     * @return        string
2280
-     */
2281
-    public function form_form_field_input__wrap($input)
2282
-    {
2283
-        EE_Error::doing_it_wrong(
2284
-            __CLASS__ . '::' . __FUNCTION__,
2285
-            esc_html__(
2286
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2287
-                'event_espresso'
2288
-            ),
2289
-            '4.8.32.rc.000'
2290
-        );
2291
-        return '
2270
+	}
2271
+
2272
+
2273
+	/**
2274
+	 * form_form_field_input__wrap
2275
+	 *
2276
+	 * @deprecated    as of 4.8.32.rc.000
2277
+	 * @access        public
2278
+	 * @param        string $input
2279
+	 * @return        string
2280
+	 */
2281
+	public function form_form_field_input__wrap($input)
2282
+	{
2283
+		EE_Error::doing_it_wrong(
2284
+			__CLASS__ . '::' . __FUNCTION__,
2285
+			esc_html__(
2286
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2287
+				'event_espresso'
2288
+			),
2289
+			'4.8.32.rc.000'
2290
+		);
2291
+		return '
2292 2292
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2293 2293
 					' . $input . '
2294 2294
 				</td>
2295 2295
 			</tr>';
2296
-    }
2297
-
2298
-
2299
-    /**
2300
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2301
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2302
-     * to display the page
2303
-     *
2304
-     * @access protected
2305
-     * @return void
2306
-     * @throws EE_Error
2307
-     */
2308
-    protected function _update_attendee_registration_form()
2309
-    {
2310
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2311
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2312
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2313
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2314
-            if ($success) {
2315
-                $what  = esc_html__('Registration Form', 'event_espresso');
2316
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2317
-                    : array('action' => 'default');
2318
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2319
-            }
2320
-        }
2321
-    }
2322
-
2323
-
2324
-    /**
2325
-     * Gets the form for saving registrations custom questions (if done
2326
-     * previously retrieves the cached form object, which may have validation errors in it)
2327
-     *
2328
-     * @param int $REG_ID
2329
-     * @return EE_Registration_Custom_Questions_Form
2330
-     * @throws EE_Error
2331
-     */
2332
-    protected function _get_reg_custom_questions_form($REG_ID)
2333
-    {
2334
-        if ( ! $this->_reg_custom_questions_form) {
2335
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2336
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2337
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2338
-            );
2339
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2340
-        }
2341
-        return $this->_reg_custom_questions_form;
2342
-    }
2343
-
2344
-
2345
-    /**
2346
-     * Saves
2347
-     *
2348
-     * @access private
2349
-     * @param bool $REG_ID
2350
-     * @return bool
2351
-     * @throws EE_Error
2352
-     */
2353
-    private function _save_reg_custom_questions_form($REG_ID = false)
2354
-    {
2355
-        if ( ! $REG_ID) {
2356
-            EE_Error::add_error(
2357
-                esc_html__(
2358
-                    'An error occurred. No registration ID was received.', 'event_espresso'),
2359
-                __FILE__, __FUNCTION__, __LINE__
2360
-            );
2361
-        }
2362
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2363
-        $form->receive_form_submission($this->_req_data);
2364
-        $success = false;
2365
-        if ($form->is_valid()) {
2366
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2367
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2368
-                    $where_conditions    = array(
2369
-                        'QST_ID' => $question_id,
2370
-                        'REG_ID' => $REG_ID,
2371
-                    );
2372
-                    $possibly_new_values = array(
2373
-                        'ANS_value' => $input->normalized_value(),
2374
-                    );
2375
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2376
-                    if ($answer instanceof EE_Answer) {
2377
-                        $success = $answer->save($possibly_new_values);
2378
-                    } else {
2379
-                        //insert it then
2380
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2381
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2382
-                        $success     = $answer->save();
2383
-                    }
2384
-                }
2385
-            }
2386
-        } else {
2387
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2388
-        }
2389
-        return $success;
2390
-    }
2391
-
2392
-
2393
-    /**
2394
-     *        generates HTML for the Registration main meta box
2395
-     *
2396
-     * @access public
2397
-     * @return void
2398
-     * @throws DomainException
2399
-     * @throws EE_Error
2400
-     */
2401
-    public function _reg_attendees_meta_box()
2402
-    {
2403
-        $REG = EEM_Registration::instance();
2404
-        //get all other registrations on this transaction, and cache
2405
-        //the attendees for them so we don't have to run another query using force_join
2406
-        $registrations                           = $REG->get_all(array(
2407
-            array(
2408
-                'TXN_ID' => $this->_registration->transaction_ID(),
2409
-                'REG_ID' => array('!=', $this->_registration->ID()),
2410
-            ),
2411
-            'force_join' => array('Attendee'),
2412
-        ));
2413
-        $this->_template_args['attendees']       = array();
2414
-        $this->_template_args['attendee_notice'] = '';
2415
-        if (empty($registrations)
2416
-            || (is_array($registrations)
2417
-                && ! EEH_Array::get_one_item_from_array($registrations))
2418
-        ) {
2419
-            EE_Error::add_error(
2420
-                esc_html__(
2421
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2422
-                    'event_espresso'
2423
-                ), __FILE__, __FUNCTION__, __LINE__
2424
-            );
2425
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2426
-        } else {
2427
-            $att_nmbr = 1;
2428
-            foreach ($registrations as $registration) {
2429
-                /* @var $registration EE_Registration */
2430
-                $attendee                                                    = $registration->attendee()
2431
-                    ? $registration->attendee()
2432
-                    : EEM_Attendee::instance()
2433
-                                  ->create_default_object();
2434
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2435
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2436
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2437
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2438
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2439
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2440
-                    ', ',
2441
-                    $attendee->full_address_as_array()
2442
-                );
2443
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2444
-                    array(
2445
-                        'action' => 'edit_attendee',
2446
-                        'post'   => $attendee->ID(),
2447
-                    ),
2448
-                    REG_ADMIN_URL
2449
-                );
2450
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2451
-                $att_nmbr++;
2452
-            }
2453
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2454
-        }
2455
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2456
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2457
-    }
2458
-
2459
-
2460
-    /**
2461
-     *        generates HTML for the Edit Registration side meta box
2462
-     *
2463
-     * @access public
2464
-     * @return void
2465
-     * @throws DomainException
2466
-     * @throws EE_Error
2467
-     */
2468
-    public function _reg_registrant_side_meta_box()
2469
-    {
2470
-        /*@var $attendee EE_Attendee */
2471
-        $att_check = $this->_registration->attendee();
2472
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2473
-        //now let's determine if this is not the primary registration.  If it isn't then we set the
2474
-        //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2475
-        //primary registration object (that way we know if we need to show create button or not)
2476
-        if ( ! $this->_registration->is_primary_registrant()) {
2477
-            $primary_registration = $this->_registration->get_primary_registration();
2478
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2479
-                : null;
2480
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2481
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2482
-                //custom attendee object so let's not worry about the primary reg.
2483
-                $primary_registration = null;
2484
-            }
2485
-        } else {
2486
-            $primary_registration = null;
2487
-        }
2488
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2489
-        $this->_template_args['fname']             = $attendee->fname();
2490
-        $this->_template_args['lname']             = $attendee->lname();
2491
-        $this->_template_args['email']             = $attendee->email();
2492
-        $this->_template_args['phone']             = $attendee->phone();
2493
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2494
-        //edit link
2495
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2496
-            'action' => 'edit_attendee',
2497
-            'post'   => $attendee->ID(),
2498
-        ), REG_ADMIN_URL);
2499
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2500
-        //create link
2501
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2502
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2503
-                'action'  => 'duplicate_attendee',
2504
-                '_REG_ID' => $this->_registration->ID(),
2505
-            ), REG_ADMIN_URL) : '';
2506
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2507
-        $this->_template_args['att_check']    = $att_check;
2508
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2509
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2510
-    }
2511
-
2512
-
2513
-    /**
2514
-     * trash or restore registrations
2515
-     *
2516
-     * @param  boolean $trash whether to archive or restore
2517
-     * @return void
2518
-     * @throws EE_Error
2519
-     * @throws RuntimeException
2520
-     * @access protected
2521
-     */
2522
-    protected function _trash_or_restore_registrations($trash = true)
2523
-    {
2524
-        //if empty _REG_ID then get out because there's nothing to do
2525
-        if (empty($this->_req_data['_REG_ID'])) {
2526
-            EE_Error::add_error(
2527
-                sprintf(
2528
-                    esc_html__(
2529
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2530
-                        'event_espresso'
2531
-                    ),
2532
-                    $trash ? 'trash' : 'restore'
2533
-                ),
2534
-                __FILE__, __LINE__, __FUNCTION__
2535
-            );
2536
-            $this->_redirect_after_action(false, '', '', array(), true);
2537
-        }
2538
-        $success = 0;
2539
-        $overwrite_msgs = false;
2540
-        //Checkboxes
2541
-        if ( ! is_array($this->_req_data['_REG_ID'])) {
2542
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2543
-        }
2544
-        $reg_count = count($this->_req_data['_REG_ID']);
2545
-        // cycle thru checkboxes
2546
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2547
-            /** @var EE_Registration $REG */
2548
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2549
-            $payments = $REG->registration_payments();
2550
-            if (! empty($payments)) {
2551
-                $name = $REG->attendee() instanceof EE_Attendee
2552
-                    ? $REG->attendee()->full_name()
2553
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2554
-                $overwrite_msgs = true;
2555
-                EE_Error::add_error(
2556
-                    sprintf(
2557
-                        esc_html__(
2558
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2559
-                            'event_espresso'
2560
-                        ),
2561
-                        $name
2562
-                    ),
2563
-                    __FILE__, __FUNCTION__, __LINE__
2564
-                );
2565
-                //can't trash this registration because it has payments.
2566
-                continue;
2567
-            }
2568
-            $updated = $trash ? $REG->delete() : $REG->restore();
2569
-            if ($updated) {
2570
-                $success++;
2571
-            }
2572
-        }
2573
-        $this->_redirect_after_action(
2574
-            $success === $reg_count, // were ALL registrations affected?
2575
-            $success > 1
2576
-                ? esc_html__('Registrations', 'event_espresso')
2577
-                : esc_html__('Registration', 'event_espresso'),
2578
-            $trash
2579
-                ? esc_html__('moved to the trash', 'event_espresso')
2580
-                : esc_html__('restored', 'event_espresso'),
2581
-            array('action' => 'default'),
2582
-            $overwrite_msgs
2583
-        );
2584
-    }
2585
-
2586
-
2587
-    /**
2588
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2589
-     * registration but also.
2590
-     * 1. Removing relations to EE_Attendee
2591
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2592
-     * ALSO trashed.
2593
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2594
-     * 4. Removing relationships between all tickets and the related registrations
2595
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2596
-     * 6. Deleting permanently any related Checkins.
2597
-     *
2598
-     * @return void
2599
-     * @throws EE_Error
2600
-     */
2601
-    protected function _delete_registrations()
2602
-    {
2603
-        $REG_MDL = EEM_Registration::instance();
2604
-        $success = 1;
2605
-        //Checkboxes
2606
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2607
-            // if array has more than one element than success message should be plural
2608
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2609
-            // cycle thru checkboxes
2610
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2611
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2612
-                if ( ! $REG instanceof EE_Registration) {
2613
-                    continue;
2614
-                }
2615
-                $deleted = $this->_delete_registration($REG);
2616
-                if ( ! $deleted) {
2617
-                    $success = 0;
2618
-                }
2619
-            }
2620
-        } else {
2621
-            // grab single id and delete
2622
-            $REG_ID  = $this->_req_data['_REG_ID'];
2623
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2624
-            $deleted = $this->_delete_registration($REG);
2625
-            if ( ! $deleted) {
2626
-                $success = 0;
2627
-            }
2628
-        }
2629
-        $what        = $success > 1
2630
-            ? esc_html__('Registrations', 'event_espresso')
2631
-            : esc_html__('Registration', 'event_espresso');
2632
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2633
-        $this->_redirect_after_action(
2634
-            $success,
2635
-            $what,
2636
-            $action_desc,
2637
-            array('action' => 'default'),
2638
-            true
2639
-        );
2640
-    }
2641
-
2642
-
2643
-    /**
2644
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2645
-     * models get affected.
2646
-     *
2647
-     * @param  EE_Registration $REG registration to be deleted permenantly
2648
-     * @return bool true = successful deletion, false = fail.
2649
-     * @throws EE_Error
2650
-     */
2651
-    protected function _delete_registration(EE_Registration $REG)
2652
-    {
2653
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2654
-        //registrations on the transaction that are NOT trashed.
2655
-        $TXN         = $REG->get_first_related('Transaction');
2656
-        $REGS        = $TXN->get_many_related('Registration');
2657
-        $all_trashed = true;
2658
-        foreach ($REGS as $registration) {
2659
-            if ( ! $registration->get('REG_deleted')) {
2660
-                $all_trashed = false;
2661
-            }
2662
-        }
2663
-        if ( ! $all_trashed) {
2664
-            EE_Error::add_error(
2665
-                esc_html__(
2666
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2667
-                    'event_espresso'
2668
-                ),
2669
-                __FILE__, __FUNCTION__, __LINE__
2670
-            );
2671
-            return false;
2672
-        }
2673
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them
2674
-        //separately from THIS one).
2675
-        foreach ($REGS as $registration) {
2676
-            //delete related answers
2677
-            $registration->delete_related_permanently('Answer');
2678
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2679
-            $attendee = $registration->get_first_related('Attendee');
2680
-            if ($attendee instanceof EE_Attendee) {
2681
-                $registration->_remove_relation_to($attendee, 'Attendee');
2682
-            }
2683
-            //now remove relationships to tickets on this registration.
2684
-            $registration->_remove_relations('Ticket');
2685
-            //now delete permanently the checkins related to this registration.
2686
-            $registration->delete_related_permanently('Checkin');
2687
-            if ($registration->ID() === $REG->ID()) {
2688
-                continue;
2689
-            } //we don't want to delete permanently the existing registration just yet.
2690
-            //remove relation to transaction for these registrations if NOT the existing registrations
2691
-            $registration->_remove_relations('Transaction');
2692
-            //delete permanently any related messages.
2693
-            $registration->delete_related_permanently('Message');
2694
-            //now delete this registration permanently
2695
-            $registration->delete_permanently();
2696
-        }
2697
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself
2698
-        // (the transaction and line items should be all that's left).
2699
-        // delete the line items related to the transaction for this registration.
2700
-        $TXN->delete_related_permanently('Line_Item');
2701
-        //we need to remove all the relationships on the transaction
2702
-        $TXN->delete_related_permanently('Payment');
2703
-        $TXN->delete_related_permanently('Extra_Meta');
2704
-        $TXN->delete_related_permanently('Message');
2705
-        //now we can delete this REG permanently (and the transaction of course)
2706
-        $REG->delete_related_permanently('Transaction');
2707
-        return $REG->delete_permanently();
2708
-    }
2709
-
2710
-
2711
-    /**
2712
-     *    generates HTML for the Register New Attendee Admin page
2713
-     *
2714
-     * @access private
2715
-     * @throws DomainException
2716
-     * @throws EE_Error
2717
-     */
2718
-    public function new_registration()
2719
-    {
2720
-        if ( ! $this->_set_reg_event()) {
2721
-            throw new EE_Error(
2722
-                esc_html__(
2723
-                    'Unable to continue with registering because there is no Event ID in the request',
2724
-                    'event_espresso'
2725
-                )
2726
-            );
2727
-        }
2728
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2729
-        // gotta start with a clean slate if we're not coming here via ajax
2730
-        if ( ! defined('DOING_AJAX')
2731
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2732
-        ) {
2733
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2734
-        }
2735
-        $this->_template_args['event_name'] = '';
2736
-        // event name
2737
-        if ($this->_reg_event) {
2738
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2739
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2740
-                'action' => 'edit',
2741
-                'post'   => $this->_reg_event->ID(),
2742
-            ), EVENTS_ADMIN_URL);
2743
-            $edit_event_lnk                     = '<a href="'
2744
-                                                  . $edit_event_url
2745
-                                                  . '" title="'
2746
-                                                  . esc_attr__('Edit ', 'event_espresso')
2747
-                                                  . $this->_reg_event->name()
2748
-                                                  . '">'
2749
-                                                  . esc_html__('Edit Event', 'event_espresso')
2750
-                                                  . '</a>';
2751
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2752
-                                                   . $edit_event_lnk
2753
-                                                   . '</span>';
2754
-        }
2755
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2756
-        if (defined('DOING_AJAX')) {
2757
-            $this->_return_json();
2758
-        }
2759
-        // grab header
2760
-        $template_path                              =
2761
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2762
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2763
-            $this->_template_args, true);
2764
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2765
-        // the details template wrapper
2766
-        $this->display_admin_page_with_sidebar();
2767
-    }
2768
-
2769
-
2770
-    /**
2771
-     * This returns the content for a registration step
2772
-     *
2773
-     * @access protected
2774
-     * @return string html
2775
-     * @throws DomainException
2776
-     * @throws EE_Error
2777
-     */
2778
-    protected function _get_registration_step_content()
2779
-    {
2780
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2781
-            $warning_msg = sprintf(
2782
-                esc_html__(
2783
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2784
-                    'event_espresso'
2785
-                ),
2786
-                '<br />',
2787
-                '<h3 class="important-notice">',
2788
-                '</h3>',
2789
-                '<div class="float-right">',
2790
-                '<span id="redirect_timer" class="important-notice">30</span>',
2791
-                '</div>',
2792
-                '<b>',
2793
-                '</b>'
2794
-            );
2795
-            return '
2296
+	}
2297
+
2298
+
2299
+	/**
2300
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2301
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2302
+	 * to display the page
2303
+	 *
2304
+	 * @access protected
2305
+	 * @return void
2306
+	 * @throws EE_Error
2307
+	 */
2308
+	protected function _update_attendee_registration_form()
2309
+	{
2310
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2311
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2312
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2313
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2314
+			if ($success) {
2315
+				$what  = esc_html__('Registration Form', 'event_espresso');
2316
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2317
+					: array('action' => 'default');
2318
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2319
+			}
2320
+		}
2321
+	}
2322
+
2323
+
2324
+	/**
2325
+	 * Gets the form for saving registrations custom questions (if done
2326
+	 * previously retrieves the cached form object, which may have validation errors in it)
2327
+	 *
2328
+	 * @param int $REG_ID
2329
+	 * @return EE_Registration_Custom_Questions_Form
2330
+	 * @throws EE_Error
2331
+	 */
2332
+	protected function _get_reg_custom_questions_form($REG_ID)
2333
+	{
2334
+		if ( ! $this->_reg_custom_questions_form) {
2335
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2336
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2337
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2338
+			);
2339
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2340
+		}
2341
+		return $this->_reg_custom_questions_form;
2342
+	}
2343
+
2344
+
2345
+	/**
2346
+	 * Saves
2347
+	 *
2348
+	 * @access private
2349
+	 * @param bool $REG_ID
2350
+	 * @return bool
2351
+	 * @throws EE_Error
2352
+	 */
2353
+	private function _save_reg_custom_questions_form($REG_ID = false)
2354
+	{
2355
+		if ( ! $REG_ID) {
2356
+			EE_Error::add_error(
2357
+				esc_html__(
2358
+					'An error occurred. No registration ID was received.', 'event_espresso'),
2359
+				__FILE__, __FUNCTION__, __LINE__
2360
+			);
2361
+		}
2362
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2363
+		$form->receive_form_submission($this->_req_data);
2364
+		$success = false;
2365
+		if ($form->is_valid()) {
2366
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2367
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2368
+					$where_conditions    = array(
2369
+						'QST_ID' => $question_id,
2370
+						'REG_ID' => $REG_ID,
2371
+					);
2372
+					$possibly_new_values = array(
2373
+						'ANS_value' => $input->normalized_value(),
2374
+					);
2375
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2376
+					if ($answer instanceof EE_Answer) {
2377
+						$success = $answer->save($possibly_new_values);
2378
+					} else {
2379
+						//insert it then
2380
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2381
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2382
+						$success     = $answer->save();
2383
+					}
2384
+				}
2385
+			}
2386
+		} else {
2387
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2388
+		}
2389
+		return $success;
2390
+	}
2391
+
2392
+
2393
+	/**
2394
+	 *        generates HTML for the Registration main meta box
2395
+	 *
2396
+	 * @access public
2397
+	 * @return void
2398
+	 * @throws DomainException
2399
+	 * @throws EE_Error
2400
+	 */
2401
+	public function _reg_attendees_meta_box()
2402
+	{
2403
+		$REG = EEM_Registration::instance();
2404
+		//get all other registrations on this transaction, and cache
2405
+		//the attendees for them so we don't have to run another query using force_join
2406
+		$registrations                           = $REG->get_all(array(
2407
+			array(
2408
+				'TXN_ID' => $this->_registration->transaction_ID(),
2409
+				'REG_ID' => array('!=', $this->_registration->ID()),
2410
+			),
2411
+			'force_join' => array('Attendee'),
2412
+		));
2413
+		$this->_template_args['attendees']       = array();
2414
+		$this->_template_args['attendee_notice'] = '';
2415
+		if (empty($registrations)
2416
+			|| (is_array($registrations)
2417
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2418
+		) {
2419
+			EE_Error::add_error(
2420
+				esc_html__(
2421
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2422
+					'event_espresso'
2423
+				), __FILE__, __FUNCTION__, __LINE__
2424
+			);
2425
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2426
+		} else {
2427
+			$att_nmbr = 1;
2428
+			foreach ($registrations as $registration) {
2429
+				/* @var $registration EE_Registration */
2430
+				$attendee                                                    = $registration->attendee()
2431
+					? $registration->attendee()
2432
+					: EEM_Attendee::instance()
2433
+								  ->create_default_object();
2434
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2435
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2436
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2437
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2438
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2439
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2440
+					', ',
2441
+					$attendee->full_address_as_array()
2442
+				);
2443
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2444
+					array(
2445
+						'action' => 'edit_attendee',
2446
+						'post'   => $attendee->ID(),
2447
+					),
2448
+					REG_ADMIN_URL
2449
+				);
2450
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2451
+				$att_nmbr++;
2452
+			}
2453
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2454
+		}
2455
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2456
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2457
+	}
2458
+
2459
+
2460
+	/**
2461
+	 *        generates HTML for the Edit Registration side meta box
2462
+	 *
2463
+	 * @access public
2464
+	 * @return void
2465
+	 * @throws DomainException
2466
+	 * @throws EE_Error
2467
+	 */
2468
+	public function _reg_registrant_side_meta_box()
2469
+	{
2470
+		/*@var $attendee EE_Attendee */
2471
+		$att_check = $this->_registration->attendee();
2472
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2473
+		//now let's determine if this is not the primary registration.  If it isn't then we set the
2474
+		//primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2475
+		//primary registration object (that way we know if we need to show create button or not)
2476
+		if ( ! $this->_registration->is_primary_registrant()) {
2477
+			$primary_registration = $this->_registration->get_primary_registration();
2478
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2479
+				: null;
2480
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2481
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2482
+				//custom attendee object so let's not worry about the primary reg.
2483
+				$primary_registration = null;
2484
+			}
2485
+		} else {
2486
+			$primary_registration = null;
2487
+		}
2488
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2489
+		$this->_template_args['fname']             = $attendee->fname();
2490
+		$this->_template_args['lname']             = $attendee->lname();
2491
+		$this->_template_args['email']             = $attendee->email();
2492
+		$this->_template_args['phone']             = $attendee->phone();
2493
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2494
+		//edit link
2495
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2496
+			'action' => 'edit_attendee',
2497
+			'post'   => $attendee->ID(),
2498
+		), REG_ADMIN_URL);
2499
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2500
+		//create link
2501
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2502
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2503
+				'action'  => 'duplicate_attendee',
2504
+				'_REG_ID' => $this->_registration->ID(),
2505
+			), REG_ADMIN_URL) : '';
2506
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2507
+		$this->_template_args['att_check']    = $att_check;
2508
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2509
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2510
+	}
2511
+
2512
+
2513
+	/**
2514
+	 * trash or restore registrations
2515
+	 *
2516
+	 * @param  boolean $trash whether to archive or restore
2517
+	 * @return void
2518
+	 * @throws EE_Error
2519
+	 * @throws RuntimeException
2520
+	 * @access protected
2521
+	 */
2522
+	protected function _trash_or_restore_registrations($trash = true)
2523
+	{
2524
+		//if empty _REG_ID then get out because there's nothing to do
2525
+		if (empty($this->_req_data['_REG_ID'])) {
2526
+			EE_Error::add_error(
2527
+				sprintf(
2528
+					esc_html__(
2529
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2530
+						'event_espresso'
2531
+					),
2532
+					$trash ? 'trash' : 'restore'
2533
+				),
2534
+				__FILE__, __LINE__, __FUNCTION__
2535
+			);
2536
+			$this->_redirect_after_action(false, '', '', array(), true);
2537
+		}
2538
+		$success = 0;
2539
+		$overwrite_msgs = false;
2540
+		//Checkboxes
2541
+		if ( ! is_array($this->_req_data['_REG_ID'])) {
2542
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2543
+		}
2544
+		$reg_count = count($this->_req_data['_REG_ID']);
2545
+		// cycle thru checkboxes
2546
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2547
+			/** @var EE_Registration $REG */
2548
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2549
+			$payments = $REG->registration_payments();
2550
+			if (! empty($payments)) {
2551
+				$name = $REG->attendee() instanceof EE_Attendee
2552
+					? $REG->attendee()->full_name()
2553
+					: esc_html__('Unknown Attendee', 'event_espresso');
2554
+				$overwrite_msgs = true;
2555
+				EE_Error::add_error(
2556
+					sprintf(
2557
+						esc_html__(
2558
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2559
+							'event_espresso'
2560
+						),
2561
+						$name
2562
+					),
2563
+					__FILE__, __FUNCTION__, __LINE__
2564
+				);
2565
+				//can't trash this registration because it has payments.
2566
+				continue;
2567
+			}
2568
+			$updated = $trash ? $REG->delete() : $REG->restore();
2569
+			if ($updated) {
2570
+				$success++;
2571
+			}
2572
+		}
2573
+		$this->_redirect_after_action(
2574
+			$success === $reg_count, // were ALL registrations affected?
2575
+			$success > 1
2576
+				? esc_html__('Registrations', 'event_espresso')
2577
+				: esc_html__('Registration', 'event_espresso'),
2578
+			$trash
2579
+				? esc_html__('moved to the trash', 'event_espresso')
2580
+				: esc_html__('restored', 'event_espresso'),
2581
+			array('action' => 'default'),
2582
+			$overwrite_msgs
2583
+		);
2584
+	}
2585
+
2586
+
2587
+	/**
2588
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2589
+	 * registration but also.
2590
+	 * 1. Removing relations to EE_Attendee
2591
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2592
+	 * ALSO trashed.
2593
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2594
+	 * 4. Removing relationships between all tickets and the related registrations
2595
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2596
+	 * 6. Deleting permanently any related Checkins.
2597
+	 *
2598
+	 * @return void
2599
+	 * @throws EE_Error
2600
+	 */
2601
+	protected function _delete_registrations()
2602
+	{
2603
+		$REG_MDL = EEM_Registration::instance();
2604
+		$success = 1;
2605
+		//Checkboxes
2606
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2607
+			// if array has more than one element than success message should be plural
2608
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2609
+			// cycle thru checkboxes
2610
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2611
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2612
+				if ( ! $REG instanceof EE_Registration) {
2613
+					continue;
2614
+				}
2615
+				$deleted = $this->_delete_registration($REG);
2616
+				if ( ! $deleted) {
2617
+					$success = 0;
2618
+				}
2619
+			}
2620
+		} else {
2621
+			// grab single id and delete
2622
+			$REG_ID  = $this->_req_data['_REG_ID'];
2623
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2624
+			$deleted = $this->_delete_registration($REG);
2625
+			if ( ! $deleted) {
2626
+				$success = 0;
2627
+			}
2628
+		}
2629
+		$what        = $success > 1
2630
+			? esc_html__('Registrations', 'event_espresso')
2631
+			: esc_html__('Registration', 'event_espresso');
2632
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2633
+		$this->_redirect_after_action(
2634
+			$success,
2635
+			$what,
2636
+			$action_desc,
2637
+			array('action' => 'default'),
2638
+			true
2639
+		);
2640
+	}
2641
+
2642
+
2643
+	/**
2644
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2645
+	 * models get affected.
2646
+	 *
2647
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2648
+	 * @return bool true = successful deletion, false = fail.
2649
+	 * @throws EE_Error
2650
+	 */
2651
+	protected function _delete_registration(EE_Registration $REG)
2652
+	{
2653
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2654
+		//registrations on the transaction that are NOT trashed.
2655
+		$TXN         = $REG->get_first_related('Transaction');
2656
+		$REGS        = $TXN->get_many_related('Registration');
2657
+		$all_trashed = true;
2658
+		foreach ($REGS as $registration) {
2659
+			if ( ! $registration->get('REG_deleted')) {
2660
+				$all_trashed = false;
2661
+			}
2662
+		}
2663
+		if ( ! $all_trashed) {
2664
+			EE_Error::add_error(
2665
+				esc_html__(
2666
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2667
+					'event_espresso'
2668
+				),
2669
+				__FILE__, __FUNCTION__, __LINE__
2670
+			);
2671
+			return false;
2672
+		}
2673
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them
2674
+		//separately from THIS one).
2675
+		foreach ($REGS as $registration) {
2676
+			//delete related answers
2677
+			$registration->delete_related_permanently('Answer');
2678
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2679
+			$attendee = $registration->get_first_related('Attendee');
2680
+			if ($attendee instanceof EE_Attendee) {
2681
+				$registration->_remove_relation_to($attendee, 'Attendee');
2682
+			}
2683
+			//now remove relationships to tickets on this registration.
2684
+			$registration->_remove_relations('Ticket');
2685
+			//now delete permanently the checkins related to this registration.
2686
+			$registration->delete_related_permanently('Checkin');
2687
+			if ($registration->ID() === $REG->ID()) {
2688
+				continue;
2689
+			} //we don't want to delete permanently the existing registration just yet.
2690
+			//remove relation to transaction for these registrations if NOT the existing registrations
2691
+			$registration->_remove_relations('Transaction');
2692
+			//delete permanently any related messages.
2693
+			$registration->delete_related_permanently('Message');
2694
+			//now delete this registration permanently
2695
+			$registration->delete_permanently();
2696
+		}
2697
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself
2698
+		// (the transaction and line items should be all that's left).
2699
+		// delete the line items related to the transaction for this registration.
2700
+		$TXN->delete_related_permanently('Line_Item');
2701
+		//we need to remove all the relationships on the transaction
2702
+		$TXN->delete_related_permanently('Payment');
2703
+		$TXN->delete_related_permanently('Extra_Meta');
2704
+		$TXN->delete_related_permanently('Message');
2705
+		//now we can delete this REG permanently (and the transaction of course)
2706
+		$REG->delete_related_permanently('Transaction');
2707
+		return $REG->delete_permanently();
2708
+	}
2709
+
2710
+
2711
+	/**
2712
+	 *    generates HTML for the Register New Attendee Admin page
2713
+	 *
2714
+	 * @access private
2715
+	 * @throws DomainException
2716
+	 * @throws EE_Error
2717
+	 */
2718
+	public function new_registration()
2719
+	{
2720
+		if ( ! $this->_set_reg_event()) {
2721
+			throw new EE_Error(
2722
+				esc_html__(
2723
+					'Unable to continue with registering because there is no Event ID in the request',
2724
+					'event_espresso'
2725
+				)
2726
+			);
2727
+		}
2728
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2729
+		// gotta start with a clean slate if we're not coming here via ajax
2730
+		if ( ! defined('DOING_AJAX')
2731
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2732
+		) {
2733
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2734
+		}
2735
+		$this->_template_args['event_name'] = '';
2736
+		// event name
2737
+		if ($this->_reg_event) {
2738
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2739
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2740
+				'action' => 'edit',
2741
+				'post'   => $this->_reg_event->ID(),
2742
+			), EVENTS_ADMIN_URL);
2743
+			$edit_event_lnk                     = '<a href="'
2744
+												  . $edit_event_url
2745
+												  . '" title="'
2746
+												  . esc_attr__('Edit ', 'event_espresso')
2747
+												  . $this->_reg_event->name()
2748
+												  . '">'
2749
+												  . esc_html__('Edit Event', 'event_espresso')
2750
+												  . '</a>';
2751
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2752
+												   . $edit_event_lnk
2753
+												   . '</span>';
2754
+		}
2755
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2756
+		if (defined('DOING_AJAX')) {
2757
+			$this->_return_json();
2758
+		}
2759
+		// grab header
2760
+		$template_path                              =
2761
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2762
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2763
+			$this->_template_args, true);
2764
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2765
+		// the details template wrapper
2766
+		$this->display_admin_page_with_sidebar();
2767
+	}
2768
+
2769
+
2770
+	/**
2771
+	 * This returns the content for a registration step
2772
+	 *
2773
+	 * @access protected
2774
+	 * @return string html
2775
+	 * @throws DomainException
2776
+	 * @throws EE_Error
2777
+	 */
2778
+	protected function _get_registration_step_content()
2779
+	{
2780
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2781
+			$warning_msg = sprintf(
2782
+				esc_html__(
2783
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2784
+					'event_espresso'
2785
+				),
2786
+				'<br />',
2787
+				'<h3 class="important-notice">',
2788
+				'</h3>',
2789
+				'<div class="float-right">',
2790
+				'<span id="redirect_timer" class="important-notice">30</span>',
2791
+				'</div>',
2792
+				'<b>',
2793
+				'</b>'
2794
+			);
2795
+			return '
2796 2796
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2797 2797
 	<script >
2798 2798
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2805,792 +2805,792 @@  discard block
 block discarded – undo
2805 2805
 	        }
2806 2806
 	    }, 800 );
2807 2807
 	</script >';
2808
-        }
2809
-        $template_args = array(
2810
-            'title'                    => '',
2811
-            'content'                  => '',
2812
-            'step_button_text'         => '',
2813
-            'show_notification_toggle' => false,
2814
-        );
2815
-        //to indicate we're processing a new registration
2816
-        $hidden_fields = array(
2817
-            'processing_registration' => array(
2818
-                'type'  => 'hidden',
2819
-                'value' => 0,
2820
-            ),
2821
-            'event_id'                => array(
2822
-                'type'  => 'hidden',
2823
-                'value' => $this->_reg_event->ID(),
2824
-            ),
2825
-        );
2826
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2827
-        $cart = EE_Registry::instance()->SSN->cart();
2828
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2829
-        switch ($step) {
2830
-            case 'ticket' :
2831
-                $hidden_fields['processing_registration']['value'] = 1;
2832
-                $template_args['title']                            = esc_html__(
2833
-                    'Step One: Select the Ticket for this registration',
2834
-                    'event_espresso'
2835
-                );
2836
-                $template_args['content']                          =
2837
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2838
-                $template_args['step_button_text']                 = esc_html__(
2839
-                    'Add Tickets and Continue to Registrant Details',
2840
-                    'event_espresso'
2841
-                );
2842
-                $template_args['show_notification_toggle']         = false;
2843
-                break;
2844
-            case 'questions' :
2845
-                $hidden_fields['processing_registration']['value'] = 2;
2846
-                $template_args['title']                            = esc_html__(
2847
-                    'Step Two: Add Registrant Details for this Registration',
2848
-                    'event_espresso'
2849
-                );
2850
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2851
-                // properly by the first process_reg_step run.
2852
-                $template_args['content']                  =
2853
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2854
-                $template_args['step_button_text']         = esc_html__(
2855
-                    'Save Registration and Continue to Details',
2856
-                    'event_espresso'
2857
-                );
2858
-                $template_args['show_notification_toggle'] = true;
2859
-                break;
2860
-        }
2861
-        //we come back to the process_registration_step route.
2862
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2863
-        return EEH_Template::display_template(
2864
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2865
-            $template_args,
2866
-            true
2867
-        );
2868
-    }
2869
-
2870
-
2871
-    /**
2872
-     *        set_reg_event
2873
-     *
2874
-     * @access private
2875
-     * @return bool
2876
-     * @throws EE_Error
2877
-     */
2878
-    private function _set_reg_event()
2879
-    {
2880
-        if (is_object($this->_reg_event)) {
2881
-            return true;
2882
-        }
2883
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2884
-        if ( ! $EVT_ID) {
2885
-            return false;
2886
-        }
2887
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2888
-        return true;
2889
-    }
2890
-
2891
-
2892
-    /**
2893
-     * process_reg_step
2894
-     *
2895
-     * @access        public
2896
-     * @return string
2897
-     * @throws DomainException
2898
-     * @throws EE_Error
2899
-     * @throws RuntimeException
2900
-     */
2901
-    public function process_reg_step()
2902
-    {
2903
-        EE_System::do_not_cache();
2904
-        $this->_set_reg_event();
2905
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2906
-        EE_Registry::instance()->REQ->set('uts', time());
2907
-        //what step are we on?
2908
-        $cart = EE_Registry::instance()->SSN->cart();
2909
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2910
-        //if doing ajax then we need to verify the nonce
2911
-        if (defined('DOING_AJAX')) {
2912
-            $nonce = isset($this->_req_data[$this->_req_nonce])
2913
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2914
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2915
-        }
2916
-        switch ($step) {
2917
-            case 'ticket' :
2918
-                //process ticket selection
2919
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2920
-                if ($success) {
2921
-                    EE_Error::add_success(
2922
-                        esc_html__(
2923
-                            'Tickets Selected. Now complete the registration.',
2924
-                            'event_espresso'
2925
-                        )
2926
-                    );
2927
-                } else {
2928
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
2929
-                }
2930
-                if (defined('DOING_AJAX')) {
2931
-                    $this->new_registration(); //display next step
2932
-                } else {
2933
-                    $query_args = array(
2934
-                        'action'                  => 'new_registration',
2935
-                        'processing_registration' => 1,
2936
-                        'event_id'                => $this->_reg_event->ID(),
2937
-                        'uts'                     => time(),
2938
-                    );
2939
-                    $this->_redirect_after_action(
2940
-                        false,
2941
-                        '',
2942
-                        '',
2943
-                        $query_args,
2944
-                        true
2945
-                    );
2946
-                }
2947
-                break;
2948
-            case 'questions' :
2949
-                if (! isset(
2950
-                    $this->_req_data['txn_reg_status_change'],
2951
-                    $this->_req_data['txn_reg_status_change']['send_notifications'])
2952
-                ) {
2953
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2954
-                }
2955
-                //process registration
2956
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2957
-                if ($cart instanceof EE_Cart) {
2958
-                    $grand_total = $cart->get_cart_grand_total();
2959
-                    if ($grand_total instanceof EE_Line_Item) {
2960
-                        $grand_total->save_this_and_descendants_to_txn();
2961
-                    }
2962
-                }
2963
-                if ( ! $transaction instanceof EE_Transaction) {
2964
-                    $query_args = array(
2965
-                        'action'                  => 'new_registration',
2966
-                        'processing_registration' => 2,
2967
-                        'event_id'                => $this->_reg_event->ID(),
2968
-                        'uts'                     => time(),
2969
-                    );
2970
-                    if (defined('DOING_AJAX')) {
2971
-                        //display registration form again because there are errors (maybe validation?)
2972
-                        $this->new_registration();
2973
-                        return;
2974
-                    } else {
2975
-                        $this->_redirect_after_action(
2976
-                            false,
2977
-                            '',
2978
-                            '',
2979
-                            $query_args,
2980
-                            true
2981
-                        );
2982
-                        return;
2983
-                    }
2984
-                }
2985
-                // maybe update status, and make sure to save transaction if not done already
2986
-                if ( ! $transaction->update_status_based_on_total_paid()) {
2987
-                    $transaction->save();
2988
-                }
2989
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2990
-                $this->_req_data = array();
2991
-                $query_args      = array(
2992
-                    'action'        => 'redirect_to_txn',
2993
-                    'TXN_ID'        => $transaction->ID(),
2994
-                    'EVT_ID'        => $this->_reg_event->ID(),
2995
-                    'event_name'    => urlencode($this->_reg_event->name()),
2996
-                    'redirect_from' => 'new_registration',
2997
-                );
2998
-                $this->_redirect_after_action(false, '', '', $query_args, true);
2999
-                break;
3000
-        }
3001
-        //what are you looking here for?  Should be nothing to do at this point.
3002
-    }
3003
-
3004
-
3005
-    /**
3006
-     * redirect_to_txn
3007
-     *
3008
-     * @access public
3009
-     * @return void
3010
-     * @throws EE_Error
3011
-     */
3012
-    public function redirect_to_txn()
3013
-    {
3014
-        EE_System::do_not_cache();
3015
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3016
-        $query_args = array(
3017
-            'action' => 'view_transaction',
3018
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3019
-            'page'   => 'espresso_transactions',
3020
-        );
3021
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3022
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3023
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
3024
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3025
-        }
3026
-        EE_Error::add_success(
3027
-            esc_html__(
3028
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3029
-                'event_espresso'
3030
-            )
3031
-        );
3032
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3033
-    }
3034
-
3035
-
3036
-    /**
3037
-     *        generates HTML for the Attendee Contact List
3038
-     *
3039
-     * @access protected
3040
-     * @return void
3041
-     */
3042
-    protected function _attendee_contact_list_table()
3043
-    {
3044
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3045
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3046
-        $this->display_admin_list_table_page_with_no_sidebar();
3047
-    }
3048
-
3049
-
3050
-    /**
3051
-     *        get_attendees
3052
-     *
3053
-     * @param      $per_page
3054
-     * @param bool $count whether to return count or data.
3055
-     * @param bool $trash
3056
-     * @return array
3057
-     * @throws EE_Error
3058
-     * @access public
3059
-     */
3060
-    public function get_attendees($per_page, $count = false, $trash = false)
3061
-    {
3062
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3063
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3064
-        $ATT_MDL                    = EEM_Attendee::instance();
3065
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3066
-        switch ($this->_req_data['orderby']) {
3067
-            case 'ATT_ID':
3068
-                $orderby = 'ATT_ID';
3069
-                break;
3070
-            case 'ATT_fname':
3071
-                $orderby = 'ATT_fname';
3072
-                break;
3073
-            case 'ATT_email':
3074
-                $orderby = 'ATT_email';
3075
-                break;
3076
-            case 'ATT_city':
3077
-                $orderby = 'ATT_city';
3078
-                break;
3079
-            case 'STA_ID':
3080
-                $orderby = 'STA_ID';
3081
-                break;
3082
-            case 'CNT_ID':
3083
-                $orderby = 'CNT_ID';
3084
-                break;
3085
-            default:
3086
-                $orderby = 'ATT_lname';
3087
-        }
3088
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3089
-            ? $this->_req_data['order']
3090
-            : 'ASC';
3091
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3092
-            ? $this->_req_data['paged']
3093
-            : 1;
3094
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3095
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3096
-            ? $this->_req_data['perpage']
3097
-            : $per_page;
3098
-        $_where       = array();
3099
-        if ( ! empty($this->_req_data['s'])) {
3100
-            $sstr         = '%' . $this->_req_data['s'] . '%';
3101
-            $_where['OR'] = array(
3102
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3103
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3104
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3105
-                'ATT_fname'                         => array('LIKE', $sstr),
3106
-                'ATT_lname'                         => array('LIKE', $sstr),
3107
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3108
-                'ATT_email'                         => array('LIKE', $sstr),
3109
-                'ATT_address'                       => array('LIKE', $sstr),
3110
-                'ATT_address2'                      => array('LIKE', $sstr),
3111
-                'ATT_city'                          => array('LIKE', $sstr),
3112
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3113
-                'State.STA_name'                    => array('LIKE', $sstr),
3114
-                'ATT_phone'                         => array('LIKE', $sstr),
3115
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3116
-                'Registration.REG_code'             => array('LIKE', $sstr),
3117
-                'Registration.REG_count'            => array('LIKE', $sstr),
3118
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3119
-            );
3120
-        }
3121
-        $offset = ($current_page - 1) * $per_page;
3122
-        $limit  = $count ? null : array($offset, $per_page);
3123
-        if ($trash) {
3124
-            $_where['status'] = array('!=', 'publish');
3125
-            $all_attendees    = $count
3126
-                ? $ATT_MDL->count(array(
3127
-                    $_where,
3128
-                    'order_by' => array($orderby => $sort),
3129
-                    'limit'    => $limit,
3130
-                ), 'ATT_ID', true)
3131
-                : $ATT_MDL->get_all(array(
3132
-                    $_where,
3133
-                    'order_by' => array($orderby => $sort),
3134
-                    'limit'    => $limit,
3135
-                ));
3136
-        } else {
3137
-            $_where['status'] = array('IN', array('publish'));
3138
-            $all_attendees    = $count
3139
-                ? $ATT_MDL->count(array(
3140
-                    $_where,
3141
-                    'order_by' => array($orderby => $sort),
3142
-                    'limit'    => $limit,
3143
-                ), 'ATT_ID', true)
3144
-                : $ATT_MDL->get_all(array(
3145
-                    $_where,
3146
-                    'order_by' => array($orderby => $sort),
3147
-                    'limit'    => $limit,
3148
-                ));
3149
-        }
3150
-        return $all_attendees;
3151
-    }
3152
-
3153
-
3154
-    /**
3155
-     * This is just taking care of resending the registration confirmation
3156
-     *
3157
-     * @access protected
3158
-     * @return void
3159
-     */
3160
-    protected function _resend_registration()
3161
-    {
3162
-        $this->_process_resend_registration();
3163
-        $query_args = isset($this->_req_data['redirect_to'])
3164
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3165
-            : array('action' => 'default');
3166
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3167
-    }
3168
-
3169
-    /**
3170
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3171
-     * to use when selecting registrations
3172
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3173
-     *                                                     the query parameters from the request
3174
-     * @return void ends the request with a redirect or download
3175
-     */
3176
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3177
-    {
3178
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3179
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3180
-                array(
3181
-                    'page'        => 'espresso_batch',
3182
-                    'batch'       => 'file',
3183
-                    'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3184
-                    'filters'     => urlencode(
3185
-                        serialize(
3186
-                            call_user_func(
3187
-                                array( $this, $method_name_for_getting_query_params ),
3188
-                                EEH_Array::is_set(
3189
-                                    $this->_req_data,
3190
-                                    'filters',
3191
-                                    array()
3192
-                                )
3193
-                            )
3194
-                        )
3195
-                ),
3196
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3197
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3198
-                'return_url'  => urlencode($this->_req_data['return_url']),
3199
-            )));
3200
-        } else {
3201
-            $new_request_args = array(
3202
-                'export' => 'report',
3203
-                'action' => 'registrations_report_for_event',
3204
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3205
-            );
3206
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3207
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3208
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3209
-                $EE_Export = EE_Export::instance($this->_req_data);
3210
-                $EE_Export->export();
3211
-            }
3212
-        }
3213
-    }
3214
-
3215
-
3216
-
3217
-    /**
3218
-     * Creates a registration report using only query parameters in the request
3219
-     * @return void
3220
-     */
3221
-    public function _registrations_report()
3222
-    {
3223
-        $this->_registrations_report_base('_get_registration_query_parameters');
3224
-    }
3225
-
3226
-
3227
-    public function _contact_list_export()
3228
-    {
3229
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3230
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3231
-            $EE_Export = EE_Export::instance($this->_req_data);
3232
-            $EE_Export->export_attendees();
3233
-        }
3234
-    }
3235
-
3236
-
3237
-    public function _contact_list_report()
3238
-    {
3239
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3240
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3241
-                'page'        => 'espresso_batch',
3242
-                'batch'       => 'file',
3243
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3244
-                'return_url'  => urlencode($this->_req_data['return_url']),
3245
-            )));
3246
-        } else {
3247
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3248
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3249
-                $EE_Export = EE_Export::instance($this->_req_data);
3250
-                $EE_Export->report_attendees();
3251
-            }
3252
-        }
3253
-    }
3254
-
3255
-
3256
-
3257
-
3258
-
3259
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3260
-    /**
3261
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3262
-     *
3263
-     * @return void
3264
-     * @throws EE_Error
3265
-     */
3266
-    protected function _duplicate_attendee()
3267
-    {
3268
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3269
-        //verify we have necessary info
3270
-        if (empty($this->_req_data['_REG_ID'])) {
3271
-            EE_Error::add_error(
3272
-                esc_html__(
3273
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3274
-                    'event_espresso'
3275
-                ), __FILE__, __LINE__, __FUNCTION__
3276
-            );
3277
-            $query_args = array('action' => $action);
3278
-            $this->_redirect_after_action('', '', '', $query_args, true);
3279
-        }
3280
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3281
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3282
-        $attendee     = $registration->attendee();
3283
-        //remove relation of existing attendee on registration
3284
-        $registration->_remove_relation_to($attendee, 'Attendee');
3285
-        //new attendee
3286
-        $new_attendee = clone $attendee;
3287
-        $new_attendee->set('ATT_ID', 0);
3288
-        $new_attendee->save();
3289
-        //add new attendee to reg
3290
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3291
-        EE_Error::add_success(
3292
-            esc_html__(
3293
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3294
-                'event_espresso'
3295
-            )
3296
-        );
3297
-        //redirect to edit page for attendee
3298
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3299
-        $this->_redirect_after_action('', '', '', $query_args, true);
3300
-    }
3301
-
3302
-
3303
-    //related to cpt routes
3304
-    protected function _insert_update_cpt_item($post_id, $post)
3305
-    {
3306
-        $success  = true;
3307
-        $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3308
-        //for attendee updates
3309
-        if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3310
-            //note we should only be UPDATING attendees at this point.
3311
-            $updated_fields = array(
3312
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3313
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3314
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3315
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3316
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3317
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3318
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3319
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3320
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3321
-                'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3322
-                'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3323
-            );
3324
-            foreach ($updated_fields as $field => $value) {
3325
-                $attendee->set($field, $value);
3326
-            }
3327
-            $success                   = $attendee->save();
3328
-            $attendee_update_callbacks = apply_filters(
3329
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3330
-                array()
3331
-            );
3332
-            foreach ($attendee_update_callbacks as $a_callback) {
3333
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3334
-                    throw new EE_Error(
3335
-                        sprintf(
3336
-                            esc_html__(
3337
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3338
-                                'event_espresso'
3339
-                            ),
3340
-                            $a_callback
3341
-                        )
3342
-                    );
3343
-                }
3344
-            }
3345
-        }
3346
-        if ($success === false) {
3347
-            EE_Error::add_error(
3348
-                esc_html__(
3349
-                    'Something went wrong with updating the meta table data for the registration.',
3350
-                    'event_espresso'
3351
-                ),
3352
-                __FILE__, __FUNCTION__, __LINE__
3353
-            );
3354
-        }
3355
-    }
3356
-
3357
-
3358
-    public function trash_cpt_item($post_id)
3359
-    {
3360
-    }
3361
-
3362
-
3363
-    public function delete_cpt_item($post_id)
3364
-    {
3365
-    }
3366
-
3367
-
3368
-    public function restore_cpt_item($post_id)
3369
-    {
3370
-    }
3371
-
3372
-
3373
-    protected function _restore_cpt_item($post_id, $revision_id)
3374
-    {
3375
-    }
3376
-
3377
-
3378
-    public function attendee_editor_metaboxes()
3379
-    {
3380
-        $this->verify_cpt_object();
3381
-        remove_meta_box(
3382
-            'postexcerpt',
3383
-            esc_html__('Excerpt', 'event_espresso'),
3384
-            'post_excerpt_meta_box',
3385
-            $this->_cpt_routes[$this->_req_action],
3386
-            'normal',
3387
-            'core'
3388
-        );
3389
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3390
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3391
-            add_meta_box(
3392
-                'postexcerpt',
3393
-                esc_html__('Short Biography', 'event_espresso'),
3394
-                'post_excerpt_meta_box',
3395
-                $this->_cpt_routes[$this->_req_action],
3396
-                'normal'
3397
-            );
3398
-        }
3399
-        if (post_type_supports('espresso_attendees', 'comments')) {
3400
-            add_meta_box(
3401
-                'commentsdiv',
3402
-                esc_html__('Notes on the Contact', 'event_espresso'),
3403
-                'post_comment_meta_box',
3404
-                $this->_cpt_routes[$this->_req_action],
3405
-                'normal',
3406
-                'core'
3407
-            );
3408
-        }
3409
-        add_meta_box(
3410
-            'attendee_contact_info',
3411
-            esc_html__('Contact Info', 'event_espresso'),
3412
-            array($this, 'attendee_contact_info'),
3413
-            $this->_cpt_routes[$this->_req_action],
3414
-            'side',
3415
-            'core'
3416
-        );
3417
-        add_meta_box(
3418
-            'attendee_details_address',
3419
-            esc_html__('Address Details', 'event_espresso'),
3420
-            array($this, 'attendee_address_details'),
3421
-            $this->_cpt_routes[$this->_req_action],
3422
-            'normal',
3423
-            'core'
3424
-        );
3425
-        add_meta_box(
3426
-            'attendee_registrations',
3427
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3428
-            array($this, 'attendee_registrations_meta_box'),
3429
-            $this->_cpt_routes[$this->_req_action],
3430
-            'normal',
3431
-            'high'
3432
-        );
3433
-    }
3434
-
3435
-
3436
-    /**
3437
-     * Metabox for attendee contact info
3438
-     *
3439
-     * @param  WP_Post $post wp post object
3440
-     * @return string attendee contact info ( and form )
3441
-     * @throws DomainException
3442
-     */
3443
-    public function attendee_contact_info($post)
3444
-    {
3445
-        //get attendee object ( should already have it )
3446
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3447
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3448
-        EEH_Template::display_template($template, $this->_template_args);
3449
-    }
3450
-
3451
-
3452
-    /**
3453
-     * Metabox for attendee details
3454
-     *
3455
-     * @param  WP_Post $post wp post object
3456
-     * @return string attendee address details (and form)
3457
-     * @throws DomainException
3458
-     */
3459
-    public function attendee_address_details($post)
3460
-    {
3461
-        //get attendee object (should already have it)
3462
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3463
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3464
-            new EE_Question_Form_Input(
3465
-                EE_Question::new_instance(
3466
-                    array(
3467
-                        'QST_ID'           => 0,
3468
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3469
-                        'QST_system'       => 'admin-state',
3470
-                    )
3471
-                ),
3472
-                EE_Answer::new_instance(
3473
-                    array(
3474
-                        'ANS_ID'    => 0,
3475
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3476
-                    )
3477
-                ),
3478
-                array(
3479
-                    'input_id'       => 'STA_ID',
3480
-                    'input_name'     => 'STA_ID',
3481
-                    'input_prefix'   => '',
3482
-                    'append_qstn_id' => false,
3483
-                )
3484
-            )
3485
-        );
3486
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3487
-            new EE_Question_Form_Input(
3488
-                EE_Question::new_instance(
3489
-                    array(
3490
-                        'QST_ID'           => 0,
3491
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3492
-                        'QST_system'       => 'admin-country',
3493
-                    )
3494
-                ),
3495
-                EE_Answer::new_instance(
3496
-                    array(
3497
-                        'ANS_ID'    => 0,
3498
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3499
-                    )
3500
-                ),
3501
-                array(
3502
-                    'input_id'       => 'CNT_ISO',
3503
-                    'input_name'     => 'CNT_ISO',
3504
-                    'input_prefix'   => '',
3505
-                    'append_qstn_id' => false,
3506
-                )
3507
-            )
3508
-        );
3509
-        $template                             =
3510
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3511
-        EEH_Template::display_template($template, $this->_template_args);
3512
-    }
3513
-
3514
-
3515
-    /**
3516
-     *        _attendee_details
3517
-     *
3518
-     * @access protected
3519
-     * @param $post
3520
-     * @return void
3521
-     * @throws DomainException
3522
-     * @throws EE_Error
3523
-     */
3524
-    public function attendee_registrations_meta_box($post)
3525
-    {
3526
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3527
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3528
-        $template                              =
3529
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3530
-        EEH_Template::display_template($template, $this->_template_args);
3531
-    }
3532
-
3533
-
3534
-    /**
3535
-     * add in the form fields for the attendee edit
3536
-     *
3537
-     * @param  WP_Post $post wp post object
3538
-     * @return string html for new form.
3539
-     * @throws DomainException
3540
-     */
3541
-    public function after_title_form_fields($post)
3542
-    {
3543
-        if ($post->post_type == 'espresso_attendees') {
3544
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3545
-            $template_args['attendee'] = $this->_cpt_model_obj;
3546
-            EEH_Template::display_template($template, $template_args);
3547
-        }
3548
-    }
3549
-
3550
-
3551
-    /**
3552
-     *        _trash_or_restore_attendee
3553
-     *
3554
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3555
-     * @return void
3556
-     * @throws EE_Error
3557
-     * @access protected
3558
-     */
3559
-    protected function _trash_or_restore_attendees($trash = true)
3560
-    {
3561
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3562
-        $ATT_MDL = EEM_Attendee::instance();
3563
-        $success = 1;
3564
-        //Checkboxes
3565
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3566
-            // if array has more than one element than success message should be plural
3567
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3568
-            // cycle thru checkboxes
3569
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3570
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3571
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3572
-                if ( ! $updated) {
3573
-                    $success = 0;
3574
-                }
3575
-            }
3576
-        } else {
3577
-            // grab single id and delete
3578
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3579
-            //get attendee
3580
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3581
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3582
-            $updated = $att->save();
3583
-            if ( ! $updated) {
3584
-                $success = 0;
3585
-            }
3586
-        }
3587
-        $what        = $success > 1
3588
-            ? esc_html__('Contacts', 'event_espresso')
3589
-            : esc_html__('Contact', 'event_espresso');
3590
-        $action_desc = $trash
3591
-            ? esc_html__('moved to the trash', 'event_espresso')
3592
-            : esc_html__('restored', 'event_espresso');
3593
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3594
-    }
2808
+		}
2809
+		$template_args = array(
2810
+			'title'                    => '',
2811
+			'content'                  => '',
2812
+			'step_button_text'         => '',
2813
+			'show_notification_toggle' => false,
2814
+		);
2815
+		//to indicate we're processing a new registration
2816
+		$hidden_fields = array(
2817
+			'processing_registration' => array(
2818
+				'type'  => 'hidden',
2819
+				'value' => 0,
2820
+			),
2821
+			'event_id'                => array(
2822
+				'type'  => 'hidden',
2823
+				'value' => $this->_reg_event->ID(),
2824
+			),
2825
+		);
2826
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2827
+		$cart = EE_Registry::instance()->SSN->cart();
2828
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2829
+		switch ($step) {
2830
+			case 'ticket' :
2831
+				$hidden_fields['processing_registration']['value'] = 1;
2832
+				$template_args['title']                            = esc_html__(
2833
+					'Step One: Select the Ticket for this registration',
2834
+					'event_espresso'
2835
+				);
2836
+				$template_args['content']                          =
2837
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2838
+				$template_args['step_button_text']                 = esc_html__(
2839
+					'Add Tickets and Continue to Registrant Details',
2840
+					'event_espresso'
2841
+				);
2842
+				$template_args['show_notification_toggle']         = false;
2843
+				break;
2844
+			case 'questions' :
2845
+				$hidden_fields['processing_registration']['value'] = 2;
2846
+				$template_args['title']                            = esc_html__(
2847
+					'Step Two: Add Registrant Details for this Registration',
2848
+					'event_espresso'
2849
+				);
2850
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2851
+				// properly by the first process_reg_step run.
2852
+				$template_args['content']                  =
2853
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2854
+				$template_args['step_button_text']         = esc_html__(
2855
+					'Save Registration and Continue to Details',
2856
+					'event_espresso'
2857
+				);
2858
+				$template_args['show_notification_toggle'] = true;
2859
+				break;
2860
+		}
2861
+		//we come back to the process_registration_step route.
2862
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2863
+		return EEH_Template::display_template(
2864
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2865
+			$template_args,
2866
+			true
2867
+		);
2868
+	}
2869
+
2870
+
2871
+	/**
2872
+	 *        set_reg_event
2873
+	 *
2874
+	 * @access private
2875
+	 * @return bool
2876
+	 * @throws EE_Error
2877
+	 */
2878
+	private function _set_reg_event()
2879
+	{
2880
+		if (is_object($this->_reg_event)) {
2881
+			return true;
2882
+		}
2883
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2884
+		if ( ! $EVT_ID) {
2885
+			return false;
2886
+		}
2887
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2888
+		return true;
2889
+	}
2890
+
2891
+
2892
+	/**
2893
+	 * process_reg_step
2894
+	 *
2895
+	 * @access        public
2896
+	 * @return string
2897
+	 * @throws DomainException
2898
+	 * @throws EE_Error
2899
+	 * @throws RuntimeException
2900
+	 */
2901
+	public function process_reg_step()
2902
+	{
2903
+		EE_System::do_not_cache();
2904
+		$this->_set_reg_event();
2905
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2906
+		EE_Registry::instance()->REQ->set('uts', time());
2907
+		//what step are we on?
2908
+		$cart = EE_Registry::instance()->SSN->cart();
2909
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2910
+		//if doing ajax then we need to verify the nonce
2911
+		if (defined('DOING_AJAX')) {
2912
+			$nonce = isset($this->_req_data[$this->_req_nonce])
2913
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2914
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2915
+		}
2916
+		switch ($step) {
2917
+			case 'ticket' :
2918
+				//process ticket selection
2919
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2920
+				if ($success) {
2921
+					EE_Error::add_success(
2922
+						esc_html__(
2923
+							'Tickets Selected. Now complete the registration.',
2924
+							'event_espresso'
2925
+						)
2926
+					);
2927
+				} else {
2928
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
2929
+				}
2930
+				if (defined('DOING_AJAX')) {
2931
+					$this->new_registration(); //display next step
2932
+				} else {
2933
+					$query_args = array(
2934
+						'action'                  => 'new_registration',
2935
+						'processing_registration' => 1,
2936
+						'event_id'                => $this->_reg_event->ID(),
2937
+						'uts'                     => time(),
2938
+					);
2939
+					$this->_redirect_after_action(
2940
+						false,
2941
+						'',
2942
+						'',
2943
+						$query_args,
2944
+						true
2945
+					);
2946
+				}
2947
+				break;
2948
+			case 'questions' :
2949
+				if (! isset(
2950
+					$this->_req_data['txn_reg_status_change'],
2951
+					$this->_req_data['txn_reg_status_change']['send_notifications'])
2952
+				) {
2953
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2954
+				}
2955
+				//process registration
2956
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2957
+				if ($cart instanceof EE_Cart) {
2958
+					$grand_total = $cart->get_cart_grand_total();
2959
+					if ($grand_total instanceof EE_Line_Item) {
2960
+						$grand_total->save_this_and_descendants_to_txn();
2961
+					}
2962
+				}
2963
+				if ( ! $transaction instanceof EE_Transaction) {
2964
+					$query_args = array(
2965
+						'action'                  => 'new_registration',
2966
+						'processing_registration' => 2,
2967
+						'event_id'                => $this->_reg_event->ID(),
2968
+						'uts'                     => time(),
2969
+					);
2970
+					if (defined('DOING_AJAX')) {
2971
+						//display registration form again because there are errors (maybe validation?)
2972
+						$this->new_registration();
2973
+						return;
2974
+					} else {
2975
+						$this->_redirect_after_action(
2976
+							false,
2977
+							'',
2978
+							'',
2979
+							$query_args,
2980
+							true
2981
+						);
2982
+						return;
2983
+					}
2984
+				}
2985
+				// maybe update status, and make sure to save transaction if not done already
2986
+				if ( ! $transaction->update_status_based_on_total_paid()) {
2987
+					$transaction->save();
2988
+				}
2989
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2990
+				$this->_req_data = array();
2991
+				$query_args      = array(
2992
+					'action'        => 'redirect_to_txn',
2993
+					'TXN_ID'        => $transaction->ID(),
2994
+					'EVT_ID'        => $this->_reg_event->ID(),
2995
+					'event_name'    => urlencode($this->_reg_event->name()),
2996
+					'redirect_from' => 'new_registration',
2997
+				);
2998
+				$this->_redirect_after_action(false, '', '', $query_args, true);
2999
+				break;
3000
+		}
3001
+		//what are you looking here for?  Should be nothing to do at this point.
3002
+	}
3003
+
3004
+
3005
+	/**
3006
+	 * redirect_to_txn
3007
+	 *
3008
+	 * @access public
3009
+	 * @return void
3010
+	 * @throws EE_Error
3011
+	 */
3012
+	public function redirect_to_txn()
3013
+	{
3014
+		EE_System::do_not_cache();
3015
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3016
+		$query_args = array(
3017
+			'action' => 'view_transaction',
3018
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3019
+			'page'   => 'espresso_transactions',
3020
+		);
3021
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3022
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3023
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
3024
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3025
+		}
3026
+		EE_Error::add_success(
3027
+			esc_html__(
3028
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3029
+				'event_espresso'
3030
+			)
3031
+		);
3032
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3033
+	}
3034
+
3035
+
3036
+	/**
3037
+	 *        generates HTML for the Attendee Contact List
3038
+	 *
3039
+	 * @access protected
3040
+	 * @return void
3041
+	 */
3042
+	protected function _attendee_contact_list_table()
3043
+	{
3044
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3045
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3046
+		$this->display_admin_list_table_page_with_no_sidebar();
3047
+	}
3048
+
3049
+
3050
+	/**
3051
+	 *        get_attendees
3052
+	 *
3053
+	 * @param      $per_page
3054
+	 * @param bool $count whether to return count or data.
3055
+	 * @param bool $trash
3056
+	 * @return array
3057
+	 * @throws EE_Error
3058
+	 * @access public
3059
+	 */
3060
+	public function get_attendees($per_page, $count = false, $trash = false)
3061
+	{
3062
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3063
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3064
+		$ATT_MDL                    = EEM_Attendee::instance();
3065
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3066
+		switch ($this->_req_data['orderby']) {
3067
+			case 'ATT_ID':
3068
+				$orderby = 'ATT_ID';
3069
+				break;
3070
+			case 'ATT_fname':
3071
+				$orderby = 'ATT_fname';
3072
+				break;
3073
+			case 'ATT_email':
3074
+				$orderby = 'ATT_email';
3075
+				break;
3076
+			case 'ATT_city':
3077
+				$orderby = 'ATT_city';
3078
+				break;
3079
+			case 'STA_ID':
3080
+				$orderby = 'STA_ID';
3081
+				break;
3082
+			case 'CNT_ID':
3083
+				$orderby = 'CNT_ID';
3084
+				break;
3085
+			default:
3086
+				$orderby = 'ATT_lname';
3087
+		}
3088
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3089
+			? $this->_req_data['order']
3090
+			: 'ASC';
3091
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3092
+			? $this->_req_data['paged']
3093
+			: 1;
3094
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3095
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3096
+			? $this->_req_data['perpage']
3097
+			: $per_page;
3098
+		$_where       = array();
3099
+		if ( ! empty($this->_req_data['s'])) {
3100
+			$sstr         = '%' . $this->_req_data['s'] . '%';
3101
+			$_where['OR'] = array(
3102
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3103
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3104
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3105
+				'ATT_fname'                         => array('LIKE', $sstr),
3106
+				'ATT_lname'                         => array('LIKE', $sstr),
3107
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3108
+				'ATT_email'                         => array('LIKE', $sstr),
3109
+				'ATT_address'                       => array('LIKE', $sstr),
3110
+				'ATT_address2'                      => array('LIKE', $sstr),
3111
+				'ATT_city'                          => array('LIKE', $sstr),
3112
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3113
+				'State.STA_name'                    => array('LIKE', $sstr),
3114
+				'ATT_phone'                         => array('LIKE', $sstr),
3115
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3116
+				'Registration.REG_code'             => array('LIKE', $sstr),
3117
+				'Registration.REG_count'            => array('LIKE', $sstr),
3118
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3119
+			);
3120
+		}
3121
+		$offset = ($current_page - 1) * $per_page;
3122
+		$limit  = $count ? null : array($offset, $per_page);
3123
+		if ($trash) {
3124
+			$_where['status'] = array('!=', 'publish');
3125
+			$all_attendees    = $count
3126
+				? $ATT_MDL->count(array(
3127
+					$_where,
3128
+					'order_by' => array($orderby => $sort),
3129
+					'limit'    => $limit,
3130
+				), 'ATT_ID', true)
3131
+				: $ATT_MDL->get_all(array(
3132
+					$_where,
3133
+					'order_by' => array($orderby => $sort),
3134
+					'limit'    => $limit,
3135
+				));
3136
+		} else {
3137
+			$_where['status'] = array('IN', array('publish'));
3138
+			$all_attendees    = $count
3139
+				? $ATT_MDL->count(array(
3140
+					$_where,
3141
+					'order_by' => array($orderby => $sort),
3142
+					'limit'    => $limit,
3143
+				), 'ATT_ID', true)
3144
+				: $ATT_MDL->get_all(array(
3145
+					$_where,
3146
+					'order_by' => array($orderby => $sort),
3147
+					'limit'    => $limit,
3148
+				));
3149
+		}
3150
+		return $all_attendees;
3151
+	}
3152
+
3153
+
3154
+	/**
3155
+	 * This is just taking care of resending the registration confirmation
3156
+	 *
3157
+	 * @access protected
3158
+	 * @return void
3159
+	 */
3160
+	protected function _resend_registration()
3161
+	{
3162
+		$this->_process_resend_registration();
3163
+		$query_args = isset($this->_req_data['redirect_to'])
3164
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3165
+			: array('action' => 'default');
3166
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3167
+	}
3168
+
3169
+	/**
3170
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3171
+	 * to use when selecting registrations
3172
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3173
+	 *                                                     the query parameters from the request
3174
+	 * @return void ends the request with a redirect or download
3175
+	 */
3176
+	public function _registrations_report_base( $method_name_for_getting_query_params )
3177
+	{
3178
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3179
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3180
+				array(
3181
+					'page'        => 'espresso_batch',
3182
+					'batch'       => 'file',
3183
+					'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3184
+					'filters'     => urlencode(
3185
+						serialize(
3186
+							call_user_func(
3187
+								array( $this, $method_name_for_getting_query_params ),
3188
+								EEH_Array::is_set(
3189
+									$this->_req_data,
3190
+									'filters',
3191
+									array()
3192
+								)
3193
+							)
3194
+						)
3195
+				),
3196
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3197
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3198
+				'return_url'  => urlencode($this->_req_data['return_url']),
3199
+			)));
3200
+		} else {
3201
+			$new_request_args = array(
3202
+				'export' => 'report',
3203
+				'action' => 'registrations_report_for_event',
3204
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3205
+			);
3206
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3207
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3208
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3209
+				$EE_Export = EE_Export::instance($this->_req_data);
3210
+				$EE_Export->export();
3211
+			}
3212
+		}
3213
+	}
3214
+
3215
+
3216
+
3217
+	/**
3218
+	 * Creates a registration report using only query parameters in the request
3219
+	 * @return void
3220
+	 */
3221
+	public function _registrations_report()
3222
+	{
3223
+		$this->_registrations_report_base('_get_registration_query_parameters');
3224
+	}
3225
+
3226
+
3227
+	public function _contact_list_export()
3228
+	{
3229
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3230
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3231
+			$EE_Export = EE_Export::instance($this->_req_data);
3232
+			$EE_Export->export_attendees();
3233
+		}
3234
+	}
3235
+
3236
+
3237
+	public function _contact_list_report()
3238
+	{
3239
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3240
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3241
+				'page'        => 'espresso_batch',
3242
+				'batch'       => 'file',
3243
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3244
+				'return_url'  => urlencode($this->_req_data['return_url']),
3245
+			)));
3246
+		} else {
3247
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3248
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3249
+				$EE_Export = EE_Export::instance($this->_req_data);
3250
+				$EE_Export->report_attendees();
3251
+			}
3252
+		}
3253
+	}
3254
+
3255
+
3256
+
3257
+
3258
+
3259
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3260
+	/**
3261
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3262
+	 *
3263
+	 * @return void
3264
+	 * @throws EE_Error
3265
+	 */
3266
+	protected function _duplicate_attendee()
3267
+	{
3268
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3269
+		//verify we have necessary info
3270
+		if (empty($this->_req_data['_REG_ID'])) {
3271
+			EE_Error::add_error(
3272
+				esc_html__(
3273
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3274
+					'event_espresso'
3275
+				), __FILE__, __LINE__, __FUNCTION__
3276
+			);
3277
+			$query_args = array('action' => $action);
3278
+			$this->_redirect_after_action('', '', '', $query_args, true);
3279
+		}
3280
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3281
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3282
+		$attendee     = $registration->attendee();
3283
+		//remove relation of existing attendee on registration
3284
+		$registration->_remove_relation_to($attendee, 'Attendee');
3285
+		//new attendee
3286
+		$new_attendee = clone $attendee;
3287
+		$new_attendee->set('ATT_ID', 0);
3288
+		$new_attendee->save();
3289
+		//add new attendee to reg
3290
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3291
+		EE_Error::add_success(
3292
+			esc_html__(
3293
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3294
+				'event_espresso'
3295
+			)
3296
+		);
3297
+		//redirect to edit page for attendee
3298
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3299
+		$this->_redirect_after_action('', '', '', $query_args, true);
3300
+	}
3301
+
3302
+
3303
+	//related to cpt routes
3304
+	protected function _insert_update_cpt_item($post_id, $post)
3305
+	{
3306
+		$success  = true;
3307
+		$attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3308
+		//for attendee updates
3309
+		if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3310
+			//note we should only be UPDATING attendees at this point.
3311
+			$updated_fields = array(
3312
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3313
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3314
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3315
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3316
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3317
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3318
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3319
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3320
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3321
+				'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3322
+				'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3323
+			);
3324
+			foreach ($updated_fields as $field => $value) {
3325
+				$attendee->set($field, $value);
3326
+			}
3327
+			$success                   = $attendee->save();
3328
+			$attendee_update_callbacks = apply_filters(
3329
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3330
+				array()
3331
+			);
3332
+			foreach ($attendee_update_callbacks as $a_callback) {
3333
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3334
+					throw new EE_Error(
3335
+						sprintf(
3336
+							esc_html__(
3337
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3338
+								'event_espresso'
3339
+							),
3340
+							$a_callback
3341
+						)
3342
+					);
3343
+				}
3344
+			}
3345
+		}
3346
+		if ($success === false) {
3347
+			EE_Error::add_error(
3348
+				esc_html__(
3349
+					'Something went wrong with updating the meta table data for the registration.',
3350
+					'event_espresso'
3351
+				),
3352
+				__FILE__, __FUNCTION__, __LINE__
3353
+			);
3354
+		}
3355
+	}
3356
+
3357
+
3358
+	public function trash_cpt_item($post_id)
3359
+	{
3360
+	}
3361
+
3362
+
3363
+	public function delete_cpt_item($post_id)
3364
+	{
3365
+	}
3366
+
3367
+
3368
+	public function restore_cpt_item($post_id)
3369
+	{
3370
+	}
3371
+
3372
+
3373
+	protected function _restore_cpt_item($post_id, $revision_id)
3374
+	{
3375
+	}
3376
+
3377
+
3378
+	public function attendee_editor_metaboxes()
3379
+	{
3380
+		$this->verify_cpt_object();
3381
+		remove_meta_box(
3382
+			'postexcerpt',
3383
+			esc_html__('Excerpt', 'event_espresso'),
3384
+			'post_excerpt_meta_box',
3385
+			$this->_cpt_routes[$this->_req_action],
3386
+			'normal',
3387
+			'core'
3388
+		);
3389
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3390
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3391
+			add_meta_box(
3392
+				'postexcerpt',
3393
+				esc_html__('Short Biography', 'event_espresso'),
3394
+				'post_excerpt_meta_box',
3395
+				$this->_cpt_routes[$this->_req_action],
3396
+				'normal'
3397
+			);
3398
+		}
3399
+		if (post_type_supports('espresso_attendees', 'comments')) {
3400
+			add_meta_box(
3401
+				'commentsdiv',
3402
+				esc_html__('Notes on the Contact', 'event_espresso'),
3403
+				'post_comment_meta_box',
3404
+				$this->_cpt_routes[$this->_req_action],
3405
+				'normal',
3406
+				'core'
3407
+			);
3408
+		}
3409
+		add_meta_box(
3410
+			'attendee_contact_info',
3411
+			esc_html__('Contact Info', 'event_espresso'),
3412
+			array($this, 'attendee_contact_info'),
3413
+			$this->_cpt_routes[$this->_req_action],
3414
+			'side',
3415
+			'core'
3416
+		);
3417
+		add_meta_box(
3418
+			'attendee_details_address',
3419
+			esc_html__('Address Details', 'event_espresso'),
3420
+			array($this, 'attendee_address_details'),
3421
+			$this->_cpt_routes[$this->_req_action],
3422
+			'normal',
3423
+			'core'
3424
+		);
3425
+		add_meta_box(
3426
+			'attendee_registrations',
3427
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3428
+			array($this, 'attendee_registrations_meta_box'),
3429
+			$this->_cpt_routes[$this->_req_action],
3430
+			'normal',
3431
+			'high'
3432
+		);
3433
+	}
3434
+
3435
+
3436
+	/**
3437
+	 * Metabox for attendee contact info
3438
+	 *
3439
+	 * @param  WP_Post $post wp post object
3440
+	 * @return string attendee contact info ( and form )
3441
+	 * @throws DomainException
3442
+	 */
3443
+	public function attendee_contact_info($post)
3444
+	{
3445
+		//get attendee object ( should already have it )
3446
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3447
+		$template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3448
+		EEH_Template::display_template($template, $this->_template_args);
3449
+	}
3450
+
3451
+
3452
+	/**
3453
+	 * Metabox for attendee details
3454
+	 *
3455
+	 * @param  WP_Post $post wp post object
3456
+	 * @return string attendee address details (and form)
3457
+	 * @throws DomainException
3458
+	 */
3459
+	public function attendee_address_details($post)
3460
+	{
3461
+		//get attendee object (should already have it)
3462
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3463
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3464
+			new EE_Question_Form_Input(
3465
+				EE_Question::new_instance(
3466
+					array(
3467
+						'QST_ID'           => 0,
3468
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3469
+						'QST_system'       => 'admin-state',
3470
+					)
3471
+				),
3472
+				EE_Answer::new_instance(
3473
+					array(
3474
+						'ANS_ID'    => 0,
3475
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3476
+					)
3477
+				),
3478
+				array(
3479
+					'input_id'       => 'STA_ID',
3480
+					'input_name'     => 'STA_ID',
3481
+					'input_prefix'   => '',
3482
+					'append_qstn_id' => false,
3483
+				)
3484
+			)
3485
+		);
3486
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3487
+			new EE_Question_Form_Input(
3488
+				EE_Question::new_instance(
3489
+					array(
3490
+						'QST_ID'           => 0,
3491
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3492
+						'QST_system'       => 'admin-country',
3493
+					)
3494
+				),
3495
+				EE_Answer::new_instance(
3496
+					array(
3497
+						'ANS_ID'    => 0,
3498
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3499
+					)
3500
+				),
3501
+				array(
3502
+					'input_id'       => 'CNT_ISO',
3503
+					'input_name'     => 'CNT_ISO',
3504
+					'input_prefix'   => '',
3505
+					'append_qstn_id' => false,
3506
+				)
3507
+			)
3508
+		);
3509
+		$template                             =
3510
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3511
+		EEH_Template::display_template($template, $this->_template_args);
3512
+	}
3513
+
3514
+
3515
+	/**
3516
+	 *        _attendee_details
3517
+	 *
3518
+	 * @access protected
3519
+	 * @param $post
3520
+	 * @return void
3521
+	 * @throws DomainException
3522
+	 * @throws EE_Error
3523
+	 */
3524
+	public function attendee_registrations_meta_box($post)
3525
+	{
3526
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3527
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3528
+		$template                              =
3529
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3530
+		EEH_Template::display_template($template, $this->_template_args);
3531
+	}
3532
+
3533
+
3534
+	/**
3535
+	 * add in the form fields for the attendee edit
3536
+	 *
3537
+	 * @param  WP_Post $post wp post object
3538
+	 * @return string html for new form.
3539
+	 * @throws DomainException
3540
+	 */
3541
+	public function after_title_form_fields($post)
3542
+	{
3543
+		if ($post->post_type == 'espresso_attendees') {
3544
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3545
+			$template_args['attendee'] = $this->_cpt_model_obj;
3546
+			EEH_Template::display_template($template, $template_args);
3547
+		}
3548
+	}
3549
+
3550
+
3551
+	/**
3552
+	 *        _trash_or_restore_attendee
3553
+	 *
3554
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3555
+	 * @return void
3556
+	 * @throws EE_Error
3557
+	 * @access protected
3558
+	 */
3559
+	protected function _trash_or_restore_attendees($trash = true)
3560
+	{
3561
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3562
+		$ATT_MDL = EEM_Attendee::instance();
3563
+		$success = 1;
3564
+		//Checkboxes
3565
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3566
+			// if array has more than one element than success message should be plural
3567
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3568
+			// cycle thru checkboxes
3569
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3570
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3571
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3572
+				if ( ! $updated) {
3573
+					$success = 0;
3574
+				}
3575
+			}
3576
+		} else {
3577
+			// grab single id and delete
3578
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3579
+			//get attendee
3580
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3581
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3582
+			$updated = $att->save();
3583
+			if ( ! $updated) {
3584
+				$success = 0;
3585
+			}
3586
+		}
3587
+		$what        = $success > 1
3588
+			? esc_html__('Contacts', 'event_espresso')
3589
+			: esc_html__('Contact', 'event_espresso');
3590
+		$action_desc = $trash
3591
+			? esc_html__('moved to the trash', 'event_espresso')
3592
+			: esc_html__('restored', 'event_espresso');
3593
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3594
+	}
3595 3595
 
3596 3596
 }
Please login to merge, or discard this patch.