Completed
Branch BUG-8698-ticket-sellouts (195489)
by
unknown
87:36 queued 70:52
created
core/libraries/rest_api/controllers/model/Read.php 2 patches
Braces   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 		){
240 240
 			if( $relation instanceof \EE_Belongs_To_Relation ) {
241 241
 				$related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() );
242
-			}else{
242
+			} else{
243 243
 				$related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() );
244 244
 			}
245 245
 			return new \WP_Error(
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 		}
292 292
 		if( $relation instanceof \EE_Belongs_To_Relation ){
293 293
 			return array_shift( $nice_results );
294
-		}else{
294
+		} else{
295 295
 			return $nice_results;
296 296
 		}
297 297
 	}
@@ -405,14 +405,14 @@  discard block
 block discarded – undo
405 405
 			$field_value = $field_obj->prepare_for_set_from_db( $raw_field_value );
406 406
 			if( $this->is_subclass_of_one(  $field_obj, $this->get_model_version_info()->fields_ignored() ) ){
407 407
 				unset( $result[ $field_name ] );
408
-			}elseif(
408
+			} elseif(
409 409
 				$this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() )
410 410
 			){
411 411
 				$result[ $field_name ] = array(
412 412
 					'raw' => $field_obj->prepare_for_get( $field_value ),
413 413
 					'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value )
414 414
 				);
415
-			}elseif(
415
+			} elseif(
416 416
 				$this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() )
417 417
 			){
418 418
 				$result[ $field_name ] = array(
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
 	public static function get_related_entity_name( $relation_name, $relation_obj ){
596 596
 		if( $relation_obj instanceof \EE_Belongs_To_Relation ) {
597 597
 			return strtolower( $relation_name );
598
-		}else{
598
+		} else{
599 599
 			return \EEH_Inflector::pluralize_and_lower( $relation_name );
600 600
 		}
601 601
 	}
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
 		$valid_contexts = \EEM_Base::valid_cap_contexts();
666 666
 		if( in_array( $context, $valid_contexts )  ){
667 667
 			return $context;
668
-		}else{
668
+		} else{
669 669
 			return \EEM_Base::caps_read;
670 670
 		}
671 671
 	}
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
 			$order_by = $query_parameters[ 'order_by' ];
691 691
 		} elseif ( isset( $query_parameters[ 'orderby' ] ) ) {
692 692
 			$order_by = $query_parameters[ 'orderby' ];
693
-		}else{
693
+		} else{
694 694
 			$order_by = null;
695 695
 		}
696 696
 		if( $order_by !== null ){
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
 			$group_by = $query_parameters[ 'group_by' ];
701 701
 		} elseif ( isset( $query_parameters[ 'groupby' ] ) ) {
702 702
 			$group_by = $query_parameters[ 'groupby' ];
703
-		}else{
703
+		} else{
704 704
 			$group_by = null;
705 705
 		}
706 706
 		if( $group_by !== null ){
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
 			//limit should be either a string like '23' or '23,43', or an array with two items in it
724 724
 			if( ! is_array( $query_parameters[ 'limit' ] ) ) {
725 725
 				$limit_array = explode(',', (string)$query_parameters['limit']);
726
-			}else {
726
+			} else {
727 727
 				$limit_array = $query_parameters[ 'limit' ];
728 728
 			}
729 729
 			$sanitized_limit = array();
@@ -739,12 +739,12 @@  discard block
 block discarded – undo
739 739
 				$sanitized_limit[] = intval( $limit_part );
740 740
 			}
741 741
 			$model_query_params[ 'limit' ] = implode( ',', $sanitized_limit );
742
-		}else{
742
+		} else{
743 743
 			$model_query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit();
744 744
 		}
745 745
 		if( isset( $query_parameters[ 'caps' ] ) ) {
746 746
 			$model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] );
747
-		}else{
747
+		} else{
748 748
 			$model_query_params[ 'caps' ] = \EEM_Base::caps_read;
749 749
 		}
750 750
 		return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model );
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
 		foreach( $query_params as $key => $value ) {
765 765
 			if( is_array( $value ) ) {
766 766
 				$model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value );
767
-			}else{
767
+			} else{
768 768
 				$model_ready_query_params[ $key ] = $value;
769 769
 			}
770 770
 		}
@@ -816,11 +816,11 @@  discard block
 block discarded – undo
816 816
 					//found the model name at the exact start
817 817
 					$field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include );
818 818
 					$extracted_fields_to_include[] = $field_sans_model_name;
819
-				}elseif( $field_to_include == $model_name ){
819
+				} elseif( $field_to_include == $model_name ){
820 820
 					$extracted_fields_to_include[] = '*';
821 821
 				}
822 822
 			}
823
-		}else{
823
+		} else{
824 824
 			//look for ones with no period
825 825
 			foreach( $includes as $field_to_include ) {
826 826
 				$field_to_include = trim( $field_to_include );
Please login to merge, or discard this patch.
Spacing   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -6,8 +6,8 @@  discard block
 block discarded – undo
6 6
 use EventEspresso\core\libraries\rest_api\Rest_Exception;
7 7
 use EventEspresso\core\libraries\rest_api\Model_Data_Translator;
8 8
 
9
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
10
-	exit( 'No direct script access allowed' );
9
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
10
+	exit('No direct script access allowed');
11 11
 }
12 12
 
13 13
 /**
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
 	public function __construct() {
35 35
 		parent::__construct();
36
-		\EE_Registry::instance()->load_helper( 'Inflector' );
36
+		\EE_Registry::instance()->load_helper('Inflector');
37 37
 		$this->_fields_calculator = new Calculated_Model_Fields();
38 38
 	}
39 39
 
@@ -42,22 +42,22 @@  discard block
 block discarded – undo
42 42
 	 * @param \WP_REST_Request $request
43 43
 	 * @return \WP_REST_Response|\WP_Error
44 44
 	 */
45
-	public static function handle_request_get_all( \WP_REST_Request $request) {
45
+	public static function handle_request_get_all(\WP_REST_Request $request) {
46 46
 		$controller = new Read();
47
-		try{
47
+		try {
48 48
 			$matches = $controller->parse_route(
49 49
 				$request->get_route(),
50
-				'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~',
51
-				array( 'version', 'model' )
50
+				'~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~',
51
+				array('version', 'model')
52 52
 			);
53
-			$controller->set_requested_version( $matches[ 'version' ] );
54
-			$model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] );
55
-			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) {
53
+			$controller->set_requested_version($matches['version']);
54
+			$model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
55
+			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
56 56
 				return $controller->send_response(
57 57
 					new \WP_Error(
58 58
 						'endpoint_parsing_error',
59 59
 						sprintf(
60
-							__( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ),
60
+							__('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'),
61 61
 							$model_name_singular
62 62
 						)
63 63
 					)
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
 			}
66 66
 			return $controller->send_response(
67 67
 					$controller->get_entities_from_model(
68
-							$controller->get_model_version_info()->load_model( $model_name_singular ),
68
+							$controller->get_model_version_info()->load_model($model_name_singular),
69 69
 							$request
70 70
 					)
71 71
 			);
72
-		} catch( \Exception $e ) {
73
-			return $controller->send_response( $e );
72
+		} catch (\Exception $e) {
73
+			return $controller->send_response($e);
74 74
 		}
75 75
 	}
76 76
 
@@ -80,21 +80,21 @@  discard block
 block discarded – undo
80 80
 	 * @param \WP_Rest_Request $request
81 81
 	 * @return \WP_REST_Response|\WP_Error
82 82
 	 */
83
-	public static function handle_request_get_one( \WP_Rest_Request $request ) {
83
+	public static function handle_request_get_one(\WP_Rest_Request $request) {
84 84
 		$controller = new Read();
85
-		try{
85
+		try {
86 86
 			$matches = $controller->parse_route(
87 87
 				$request->get_route(),
88
-				'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~',
89
-				array( 'version', 'model', 'id' ) );
90
-			$controller->set_requested_version( $matches[ 'version' ] );
91
-			$model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] );
92
-			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) {
88
+				'~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~',
89
+				array('version', 'model', 'id') );
90
+			$controller->set_requested_version($matches['version']);
91
+			$model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
92
+			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
93 93
 				return $controller->send_response(
94 94
 					new \WP_Error(
95 95
 						'endpoint_parsing_error',
96 96
 						sprintf(
97
-							__( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ),
97
+							__('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'),
98 98
 							$model_name_singular
99 99
 						)
100 100
 					)
@@ -102,12 +102,12 @@  discard block
 block discarded – undo
102 102
 			}
103 103
 			return $controller->send_response(
104 104
 					$controller->get_entity_from_model(
105
-							$controller->get_model_version_info()->load_model( $model_name_singular ),
105
+							$controller->get_model_version_info()->load_model($model_name_singular),
106 106
 							$request
107 107
 						)
108 108
 				);
109
-		} catch( \Exception $e ) {
110
-			return $controller->send_response( $e );
109
+		} catch (\Exception $e) {
110
+			return $controller->send_response($e);
111 111
 		}
112 112
 	}
113 113
 
@@ -119,40 +119,40 @@  discard block
 block discarded – undo
119 119
 	 * @param \WP_REST_Request $request
120 120
 	 * @return \WP_REST_Response|\WP_Error
121 121
 	 */
122
-	public static function handle_request_get_related( \WP_REST_Request $request ) {
122
+	public static function handle_request_get_related(\WP_REST_Request $request) {
123 123
 		$controller = new Read();
124
-		try{
124
+		try {
125 125
 			$matches = $controller->parse_route(
126 126
 				$request->get_route(),
127
-				'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~',
128
-				array( 'version', 'model', 'id', 'related_model' )
127
+				'~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~',
128
+				array('version', 'model', 'id', 'related_model')
129 129
 			);
130
-			$controller->set_requested_version( $matches[ 'version' ] );
131
-			$main_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] );
132
-			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $main_model_name_singular ) ) {
130
+			$controller->set_requested_version($matches['version']);
131
+			$main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
132
+			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) {
133 133
 				return $controller->send_response(
134 134
 					new \WP_Error(
135 135
 						'endpoint_parsing_error',
136 136
 						sprintf(
137
-							__( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ),
137
+							__('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'),
138 138
 							$main_model_name_singular
139 139
 						)
140 140
 					)
141 141
 				);
142 142
 			}
143
-			$main_model = $controller->get_model_version_info()->load_model( $main_model_name_singular );
143
+			$main_model = $controller->get_model_version_info()->load_model($main_model_name_singular);
144 144
 			//assume the related model name is plural and try to find the model's name
145
-			$related_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'related_model' ] );
146
-			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) {
145
+			$related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']);
146
+			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) {
147 147
 				//so the word didn't singularize well. Maybe that's just because it's a singular word?
148
-				$related_model_name_singular = \EEH_Inflector::humanize( $matches[ 'related_model' ] );
148
+				$related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']);
149 149
 			}
150
-			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) {
150
+			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) {
151 151
 				return $controller->send_response(
152 152
 					new \WP_Error(
153 153
 						'endpoint_parsing_error',
154 154
 						sprintf(
155
-							__( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ),
155
+							__('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'),
156 156
 							$related_model_name_singular
157 157
 						)
158 158
 					)
@@ -161,13 +161,13 @@  discard block
 block discarded – undo
161 161
 
162 162
 			return $controller->send_response(
163 163
 					$controller->get_entities_from_relation(
164
-						$request->get_param( 'id' ),
165
-						$main_model->related_settings_for( $related_model_name_singular ) ,
164
+						$request->get_param('id'),
165
+						$main_model->related_settings_for($related_model_name_singular),
166 166
 						$request
167 167
 					)
168 168
 				);
169
-		} catch( \Exception $e ) {
170
-			return $controller->send_response( $e );
169
+		} catch (\Exception $e) {
170
+			return $controller->send_response($e);
171 171
 		}
172 172
 	}
173 173
 
@@ -180,27 +180,27 @@  discard block
 block discarded – undo
180 180
 	 * @param \WP_REST_Request $request
181 181
 	 * @return array
182 182
 	 */
183
-	public function get_entities_from_model( $model, $request) {
184
-		$query_params = $this->create_model_query_params( $model, $request->get_params() );
185
-		if( ! Capabilities::current_user_has_partial_access_to( $model, $query_params[ 'caps' ] ) ) {
186
-			$model_name_plural = \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() );
183
+	public function get_entities_from_model($model, $request) {
184
+		$query_params = $this->create_model_query_params($model, $request->get_params());
185
+		if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) {
186
+			$model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
187 187
 			return new \WP_Error(
188
-				sprintf( 'rest_%s_cannot_list', $model_name_plural ),
188
+				sprintf('rest_%s_cannot_list', $model_name_plural),
189 189
 				sprintf(
190
-					__( 'Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso' ),
190
+					__('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'),
191 191
 					$model_name_plural,
192
-					Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] )
192
+					Capabilities::get_missing_permissions_string($model, $query_params['caps'])
193 193
 				),
194
-				array( 'status' => 403 )
194
+				array('status' => 403)
195 195
 			);
196 196
 		}
197 197
 
198
-		$this->_set_headers_from_query_params( $model, $query_params );
198
+		$this->_set_headers_from_query_params($model, $query_params);
199 199
 		/** @type array $results */
200
-		$results = $model->get_all_wpdb_results( $query_params );
200
+		$results = $model->get_all_wpdb_results($query_params);
201 201
 		$nice_results = array( );
202
-		foreach ( $results as $result ) {
203
-			$nice_results[ ] = $this->create_entity_from_wpdb_result(
202
+		foreach ($results as $result) {
203
+			$nice_results[] = $this->create_entity_from_wpdb_result(
204 204
 					$model,
205 205
 					$result,
206 206
 					$request
@@ -221,62 +221,62 @@  discard block
 block discarded – undo
221 221
 	 * @param \WP_REST_Request $request
222 222
 	 * @return array
223 223
 	 */
224
-	public function get_entities_from_relation( $id,  $relation, $request ) {
225
-		$context = $this->validate_context( $request->get_param( 'caps' ));
224
+	public function get_entities_from_relation($id, $relation, $request) {
225
+		$context = $this->validate_context($request->get_param('caps'));
226 226
 		$model = $relation->get_this_model();
227 227
 		$related_model = $relation->get_other_model();
228 228
 		//check if they can access the 1st model object
229
-		$query_params = array( array( $model->primary_key_name() => $id ),'limit' => 1 );
230
-		if( $model instanceof \EEM_Soft_Delete_Base ){
229
+		$query_params = array(array($model->primary_key_name() => $id), 'limit' => 1);
230
+		if ($model instanceof \EEM_Soft_Delete_Base) {
231 231
 			$query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params);
232 232
 		}
233 233
 		$restricted_query_params = $query_params;
234
-		$restricted_query_params[ 'caps' ] = $context;
235
-		$this->_set_debug_info( 'main model query params', $restricted_query_params );
236
-		$this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $related_model, $context ) );
234
+		$restricted_query_params['caps'] = $context;
235
+		$this->_set_debug_info('main model query params', $restricted_query_params);
236
+		$this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context));
237 237
 
238
-		if(
238
+		if (
239 239
 			! (
240
-				Capabilities::current_user_has_partial_access_to( $related_model, $context )
241
-				&& $model->exists( $restricted_query_params )
240
+				Capabilities::current_user_has_partial_access_to($related_model, $context)
241
+				&& $model->exists($restricted_query_params)
242 242
 			)
243
-		){
244
-			if( $relation instanceof \EE_Belongs_To_Relation ) {
245
-				$related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() );
246
-			}else{
247
-				$related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() );
243
+		) {
244
+			if ($relation instanceof \EE_Belongs_To_Relation) {
245
+				$related_model_name_maybe_plural = strtolower($related_model->get_this_model_name());
246
+			} else {
247
+				$related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name());
248 248
 			}
249 249
 			return new \WP_Error(
250
-				sprintf( 'rest_%s_cannot_list', $related_model_name_maybe_plural ),
250
+				sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural),
251 251
 				sprintf(
252
-					__(	'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso' ),
252
+					__('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso'),
253 253
 					$related_model_name_maybe_plural,
254 254
 					$relation->get_this_model()->get_this_model_name(),
255 255
 					implode(
256 256
 						',',
257 257
 						array_keys(
258
-							Capabilities::get_missing_permissions( $related_model, $context )
258
+							Capabilities::get_missing_permissions($related_model, $context)
259 259
 						)
260 260
 					)
261 261
 				),
262
-				array( 'status' => 403 )
262
+				array('status' => 403)
263 263
 			);
264 264
 		}
265
-		$query_params = $this->create_model_query_params( $relation->get_other_model(), $request->get_params() );
266
-		$query_params[0][ $relation->get_this_model()->get_this_model_name() . '.' . $relation->get_this_model()->primary_key_name() ] = $id;
267
-		$query_params[ 'default_where_conditions' ] = 'none';
268
-		$query_params[ 'caps' ] = $context;
269
-		$this->_set_headers_from_query_params( $relation->get_other_model(), $query_params );
265
+		$query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params());
266
+		$query_params[0][$relation->get_this_model()->get_this_model_name().'.'.$relation->get_this_model()->primary_key_name()] = $id;
267
+		$query_params['default_where_conditions'] = 'none';
268
+		$query_params['caps'] = $context;
269
+		$this->_set_headers_from_query_params($relation->get_other_model(), $query_params);
270 270
 		/** @type array $results */
271
-		$results = $relation->get_other_model()->get_all_wpdb_results( $query_params );
271
+		$results = $relation->get_other_model()->get_all_wpdb_results($query_params);
272 272
 		$nice_results = array();
273
-		foreach( $results as $result ) {
273
+		foreach ($results as $result) {
274 274
 			$nice_result = $this->create_entity_from_wpdb_result(
275 275
 				$relation->get_other_model(),
276 276
 				$result,
277 277
 				$request
278 278
 			);
279
-			if( $relation instanceof \EE_HABTM_Relation ) {
279
+			if ($relation instanceof \EE_HABTM_Relation) {
280 280
 				//put the unusual stuff (properties from the HABTM relation) first, and make sure
281 281
 				//if there are conflicts we prefer the properties from the main model
282 282
 				$join_model_result = $this->create_entity_from_wpdb_result(
@@ -284,18 +284,18 @@  discard block
 block discarded – undo
284 284
 					$result,
285 285
 					$request
286 286
 				);
287
-				$joined_result = array_merge( $nice_result, $join_model_result );
287
+				$joined_result = array_merge($nice_result, $join_model_result);
288 288
 				//but keep the meta stuff from the main model
289
-				if( isset( $nice_result['meta'] ) ){
289
+				if (isset($nice_result['meta'])) {
290 290
 					$joined_result['meta'] = $nice_result['meta'];
291 291
 				}
292 292
 				$nice_result = $joined_result;
293 293
 			}
294 294
 			$nice_results[] = $nice_result;
295 295
 		}
296
-		if( $relation instanceof \EE_Belongs_To_Relation ){
297
-			return array_shift( $nice_results );
298
-		}else{
296
+		if ($relation instanceof \EE_Belongs_To_Relation) {
297
+			return array_shift($nice_results);
298
+		} else {
299 299
 			return $nice_results;
300 300
 		}
301 301
 	}
@@ -307,32 +307,32 @@  discard block
 block discarded – undo
307 307
 	 * @param array $query_params
308 308
 	 * @return void
309 309
 	 */
310
-	protected function _set_headers_from_query_params( $model, $query_params ) {
311
-		$this->_set_debug_info( 'model query params', $query_params );
312
-		$this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) );
310
+	protected function _set_headers_from_query_params($model, $query_params) {
311
+		$this->_set_debug_info('model query params', $query_params);
312
+		$this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($model, $query_params['caps']));
313 313
 		//normally the limit to a 2-part array, where the 2nd item is the limit
314
-		if( ! isset( $query_params[ 'limit' ] ) ) {
315
-			$query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit();
314
+		if ( ! isset($query_params['limit'])) {
315
+			$query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit();
316 316
 		}
317
-		if( is_array( $query_params[ 'limit' ] )  ) {
318
-			$limit_parts = $query_params[ 'limit' ];
317
+		if (is_array($query_params['limit'])) {
318
+			$limit_parts = $query_params['limit'];
319 319
 		} else {
320
-			$limit_parts = explode(',', $query_params[ 'limit' ] );
321
-			if( count( $limit_parts ) == 1 ){
322
-				$limit_parts = array(0, $limit_parts[ 0 ] );
320
+			$limit_parts = explode(',', $query_params['limit']);
321
+			if (count($limit_parts) == 1) {
322
+				$limit_parts = array(0, $limit_parts[0]);
323 323
 			}
324 324
 		}
325 325
 		//remove the group by and having parts of the query, as those will
326 326
 		//make the sql query return an array of values, instead of just a single value
327
-		unset( $query_params[ 'group_by' ] );
328
-		unset( $query_params[ 'having' ] );
329
-		unset( $query_params[ 'limit' ] );
330
-		$count = $model->count( $query_params, null, true );
331
-
332
-		$pages = $count / $limit_parts[ 1 ];
333
-		$this->_set_response_header( 'Total', $count, false );
334
-		$this->_set_response_header( 'PageSize', $limit_parts[ 1 ], false );
335
-		$this->_set_response_header( 'TotalPages', ceil( $pages ), false );
327
+		unset($query_params['group_by']);
328
+		unset($query_params['having']);
329
+		unset($query_params['limit']);
330
+		$count = $model->count($query_params, null, true);
331
+
332
+		$pages = $count / $limit_parts[1];
333
+		$this->_set_response_header('Total', $count, false);
334
+		$this->_set_response_header('PageSize', $limit_parts[1], false);
335
+		$this->_set_response_header('TotalPages', ceil($pages), false);
336 336
 	}
337 337
 
338 338
 
@@ -345,47 +345,47 @@  discard block
 block discarded – undo
345 345
 	 * @param string $deprecated no longer used
346 346
 	 * @return array ready for being converted into json for sending to client
347 347
 	 */
348
-	public function create_entity_from_wpdb_result( $model, $db_row, $rest_request, $deprecated = null ) {
349
-		if( ! $rest_request instanceof \WP_REST_Request ) {
348
+	public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) {
349
+		if ( ! $rest_request instanceof \WP_REST_Request) {
350 350
 			//ok so this was called in the old style, where the 3rd arg was
351 351
 			//$include, and the 4th arg was $context
352 352
 			//now setup the request just to avoid fatal errors, although we won't be able
353 353
 			//to truly make use of it because it's kinda devoid of info
354 354
 			$rest_request = new \WP_REST_Request();
355
-			$rest_request->set_param( 'include', $rest_request );
356
-			$rest_request->set_param( 'caps', $deprecated );
355
+			$rest_request->set_param('include', $rest_request);
356
+			$rest_request->set_param('caps', $deprecated);
357 357
 		}
358
-		if( $rest_request->get_param( 'caps' ) == null ) {
359
-			$rest_request->set_param( 'caps', \EEM_Base::caps_read );
358
+		if ($rest_request->get_param('caps') == null) {
359
+			$rest_request->set_param('caps', \EEM_Base::caps_read);
360 360
 		}
361
-		$entity_array = $this->_create_bare_entity_from_wpdb_results( $model, $db_row );
362
-		$entity_array = $this->_add_extra_fields( $model, $db_row, $entity_array );
363
-		$entity_array[ '_links' ] = $this->_get_entity_links( $model, $db_row, $entity_array );
364
-		$entity_array[ '_calculated_fields'] = $this->_get_entity_calculations( $model, $db_row, $rest_request );
365
-		$entity_array = $this->_include_requested_models( $model, $rest_request, $entity_array );
361
+		$entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row);
362
+		$entity_array = $this->_add_extra_fields($model, $db_row, $entity_array);
363
+		$entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array);
364
+		$entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request);
365
+		$entity_array = $this->_include_requested_models($model, $rest_request, $entity_array);
366 366
 		$entity_array = apply_filters(
367 367
 			'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal',
368 368
 			$entity_array,
369 369
 			$model,
370
-			$rest_request->get_param( 'caps' ),
370
+			$rest_request->get_param('caps'),
371 371
 			$rest_request,
372 372
 			$this
373 373
 		);
374 374
 		$result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields(
375 375
 			$entity_array,
376 376
 			$model,
377
-			$rest_request->get_param( 'caps' ),
377
+			$rest_request->get_param('caps'),
378 378
 			$this->get_model_version_info()
379 379
 		);
380 380
 		$this->_set_debug_info(
381 381
 			'inaccessible fields',
382
-			array_keys( array_diff_key( $entity_array, $result_without_inaccessible_fields ) )
382
+			array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields))
383 383
 		);
384 384
 		return apply_filters(
385 385
 			'FHEE__Read__create_entity_from_wpdb_results__entity_return',
386 386
 			$result_without_inaccessible_fields,
387 387
 			$model,
388
-			$rest_request->get_param( 'caps' )
388
+			$rest_request->get_param('caps')
389 389
 		);
390 390
 	}
391 391
 
@@ -397,38 +397,38 @@  discard block
 block discarded – undo
397 397
 	 * @param array $db_row
398 398
 	 * @return array entity mostly ready for converting to JSON and sending in the response
399 399
 	 */
400
-	protected function _create_bare_entity_from_wpdb_results( \EEM_Base $model, $db_row ) {
401
-		$result = $model->deduce_fields_n_values_from_cols_n_values( $db_row );
402
-		$result = array_intersect_key( $result, $this->get_model_version_info()->fields_on_model_in_this_version( $model ) );
403
-		foreach( $result as $field_name => $raw_field_value ) {
400
+	protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row) {
401
+		$result = $model->deduce_fields_n_values_from_cols_n_values($db_row);
402
+		$result = array_intersect_key($result, $this->get_model_version_info()->fields_on_model_in_this_version($model));
403
+		foreach ($result as $field_name => $raw_field_value) {
404 404
 			$field_obj = $model->field_settings_for($field_name);
405
-			$field_value = $field_obj->prepare_for_set_from_db( $raw_field_value );
406
-			if( $this->is_subclass_of_one(  $field_obj, $this->get_model_version_info()->fields_ignored() ) ){
407
-				unset( $result[ $field_name ] );
408
-			}elseif(
409
-				$this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() )
410
-			){
411
-				$result[ $field_name ] = array(
412
-					'raw' => $field_obj->prepare_for_get( $field_value ),
413
-					'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value )
405
+			$field_value = $field_obj->prepare_for_set_from_db($raw_field_value);
406
+			if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) {
407
+				unset($result[$field_name]);
408
+			}elseif (
409
+				$this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format())
410
+			) {
411
+				$result[$field_name] = array(
412
+					'raw' => $field_obj->prepare_for_get($field_value),
413
+					'rendered' => $field_obj->prepare_for_pretty_echoing($field_value)
414 414
 				);
415
-			}elseif(
416
-				$this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() )
417
-			){
418
-				$result[ $field_name ] = array(
419
-					'raw' => $field_obj->prepare_for_get( $field_value ),
420
-					'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value )
415
+			}elseif (
416
+				$this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format())
417
+			) {
418
+				$result[$field_name] = array(
419
+					'raw' => $field_obj->prepare_for_get($field_value),
420
+					'pretty' => $field_obj->prepare_for_pretty_echoing($field_value)
421 421
 				);
422
-			} elseif ( $field_obj instanceof \EE_Datetime_Field ) {
423
-				$result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json(
422
+			} elseif ($field_obj instanceof \EE_Datetime_Field) {
423
+				$result[$field_name] = Model_Data_Translator::prepare_field_value_for_json(
424 424
 					$field_obj,
425 425
 					$field_value,
426 426
 					$this->get_model_version_info()->requested_version()
427 427
 				);
428 428
 			} else {
429
-				$result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json(
429
+				$result[$field_name] = Model_Data_Translator::prepare_field_value_for_json(
430 430
 					$field_obj,
431
-					$field_obj->prepare_for_get( $field_value ),
431
+					$field_obj->prepare_for_get($field_value),
432 432
 					$this->get_model_version_info()->requested_version()
433 433
 				);
434 434
 			}
@@ -443,9 +443,9 @@  discard block
 block discarded – undo
443 443
 	 * @param array $entity_array
444 444
 	 * @return array modified entity
445 445
 	 */
446
-	protected function _add_extra_fields( \EEM_Base $model, $db_row, $entity_array ) {
447
-		if( $model instanceof \EEM_CPT_Base ) {
448
-			$entity_array[ 'link' ] = get_permalink( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] );
446
+	protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array) {
447
+		if ($model instanceof \EEM_CPT_Base) {
448
+			$entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]);
449 449
 		}
450 450
 		return $entity_array;
451 451
 	}
@@ -459,20 +459,20 @@  discard block
 block discarded – undo
459 459
 	 * @param array $entity_array
460 460
 	 * @return array the _links item in the entity
461 461
 	 */
462
-	protected function _get_entity_links( $model, $db_row, $entity_array ) {
462
+	protected function _get_entity_links($model, $db_row, $entity_array) {
463 463
 		//add basic links
464 464
 		$links = array(
465 465
 			'self' => array(
466 466
 				array(
467 467
 					'href' => $this->get_versioned_link_to(
468
-						\EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ]
468
+						\EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()]
469 469
 					)
470 470
 				)
471 471
 			),
472 472
 			'collection' => array(
473 473
 				array(
474 474
 					'href' => $this->get_versioned_link_to(
475
-						\EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() )
475
+						\EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
476 476
 					)
477 477
 				)
478 478
 			),
@@ -480,24 +480,24 @@  discard block
 block discarded – undo
480 480
 
481 481
 		//add link to the wp core endpoint, if wp api is active
482 482
 		global $wp_rest_server;
483
-		if( $model instanceof \EEM_CPT_Base &&
483
+		if ($model instanceof \EEM_CPT_Base &&
484 484
 			$wp_rest_server instanceof \WP_REST_Server &&
485
-			$wp_rest_server->get_route_options( '/wp/v2/posts' ) ) {
486
-			$links[ \EED_Core_Rest_Api::ee_api_link_namespace . 'self_wp_post' ] = array(
485
+			$wp_rest_server->get_route_options('/wp/v2/posts')) {
486
+			$links[\EED_Core_Rest_Api::ee_api_link_namespace.'self_wp_post'] = array(
487 487
 				array(
488
-					'href' => rest_url( '/wp/v2/posts/' . $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ),
488
+					'href' => rest_url('/wp/v2/posts/'.$db_row[$model->get_primary_key_field()->get_qualified_column()]),
489 489
 					'single' => true
490 490
 				)
491 491
 			);
492 492
 		}
493 493
 
494 494
 		//add links to related models
495
-		foreach( $this->get_model_version_info()->relation_settings( $model ) as $relation_name => $relation_obj ) {
496
-			$related_model_part = $this->get_related_entity_name( $relation_name, $relation_obj );
497
-			$links[ \EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array(
495
+		foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) {
496
+			$related_model_part = $this->get_related_entity_name($relation_name, $relation_obj);
497
+			$links[\EED_Core_Rest_Api::ee_api_link_namespace.$related_model_part] = array(
498 498
 				array(
499 499
 					'href' => $this->get_versioned_link_to(
500
-						\EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] . '/' . $related_model_part
500
+						\EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()].'/'.$related_model_part
501 501
 					),
502 502
 					'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false
503 503
 				)
@@ -513,50 +513,50 @@  discard block
 block discarded – undo
513 513
 	 * @param array $entity_array
514 514
 	 * @return array the modified entity
515 515
 	 */
516
-	protected function _include_requested_models( \EEM_Base $model, \WP_REST_Request $rest_request, $entity_array ) {
517
-		$includes_for_this_model = $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'include' ), '' );
518
-		$includes_for_this_model = $this->_remove_model_names_from_array( $includes_for_this_model );
516
+	protected function _include_requested_models(\EEM_Base $model, \WP_REST_Request $rest_request, $entity_array) {
517
+		$includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), '');
518
+		$includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model);
519 519
 		//if they passed in * or didn't specify any includes, return everything
520
-		if( ! in_array( '*', $includes_for_this_model )
521
-			&& ! empty( $includes_for_this_model ) ) {
522
-			if( $model->has_primary_key_field() ) {
520
+		if ( ! in_array('*', $includes_for_this_model)
521
+			&& ! empty($includes_for_this_model)) {
522
+			if ($model->has_primary_key_field()) {
523 523
 				//always include the primary key. ya just gotta know that at least
524 524
 				$includes_for_this_model[] = $model->primary_key_name();
525 525
 			}
526
-			if( $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'calculate' ), '' ) ) {
526
+			if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) {
527 527
 				$includes_for_this_model[] = '_calculated_fields';
528 528
 			}
529
-			$entity_array = array_intersect_key( $entity_array, array_flip( $includes_for_this_model ) );
529
+			$entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model));
530 530
 		}
531
-		$relation_settings = $this->get_model_version_info()->relation_settings( $model );
532
-		foreach( $relation_settings as $relation_name => $relation_obj ) {
531
+		$relation_settings = $this->get_model_version_info()->relation_settings($model);
532
+		foreach ($relation_settings as $relation_name => $relation_obj) {
533 533
 			$related_fields_to_include = $this->explode_and_get_items_prefixed_with(
534
-				$rest_request->get_param( 'include' ),
534
+				$rest_request->get_param('include'),
535 535
 				$relation_name
536 536
 			);
537 537
 			$related_fields_to_calculate = $this->explode_and_get_items_prefixed_with(
538
-				$rest_request->get_param( 'calculate' ),
538
+				$rest_request->get_param('calculate'),
539 539
 				$relation_name
540 540
 			);
541 541
 			//did they specify they wanted to include a related model, or
542 542
 			//specific fields from a related model?
543 543
 			//or did they specify to calculate a field from a related model?
544
-			if( $related_fields_to_include || $related_fields_to_calculate ) {
544
+			if ($related_fields_to_include || $related_fields_to_calculate) {
545 545
 				//if so, we should include at least some part of the related model
546 546
 				$pretend_related_request = new \WP_REST_Request();
547 547
 				$pretend_related_request->set_query_params(
548 548
 					array(
549
-						'caps' => $rest_request->get_param( 'caps' ),
549
+						'caps' => $rest_request->get_param('caps'),
550 550
 						'include' => $related_fields_to_include,
551 551
 						'calculate' => $related_fields_to_calculate,
552 552
 					)
553 553
 				);
554 554
 				$related_results = $this->get_entities_from_relation(
555
-					$entity_array[ $model->primary_key_name() ],
555
+					$entity_array[$model->primary_key_name()],
556 556
 					$relation_obj,
557 557
 					$pretend_related_request
558 558
 				);
559
-				$entity_array[ $this->get_related_entity_name( $relation_name, $relation_obj ) ] = $related_results instanceof \WP_Error ? null : $related_results;
559
+				$entity_array[$this->get_related_entity_name($relation_name, $relation_obj)] = $related_results instanceof \WP_Error ? null : $related_results;
560 560
 			}
561 561
 		}
562 562
 		return $entity_array;
@@ -568,8 +568,8 @@  discard block
 block discarded – undo
568 568
 	 * @param array $arr
569 569
 	 * @return array
570 570
 	 */
571
-	private function _remove_model_names_from_array( $arr ) {
572
-		return array_diff( $arr, array_keys( \EE_Registry::instance()->non_abstract_db_models ) );
571
+	private function _remove_model_names_from_array($arr) {
572
+		return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models));
573 573
 	}
574 574
 	/**
575 575
 	 * Gets the calculated fields for the response
@@ -579,16 +579,16 @@  discard block
 block discarded – undo
579 579
 	 * @param \WP_REST_Request $rest_request
580 580
 	 * @return array the _calculations item in the entity
581 581
 	 */
582
-	protected function _get_entity_calculations( $model, $wpdb_row, $rest_request ) {
582
+	protected function _get_entity_calculations($model, $wpdb_row, $rest_request) {
583 583
 		$calculated_fields = $this->explode_and_get_items_prefixed_with(
584
-			$rest_request->get_param( 'calculate' ),
584
+			$rest_request->get_param('calculate'),
585 585
 			''
586 586
 		);
587 587
 		//note: setting calculate=* doesn't do anything
588 588
 		$calculated_fields_to_return = array();
589
-		foreach( $calculated_fields as $field_to_calculate ) {
590
-			try{
591
-				$calculated_fields_to_return[ $field_to_calculate ] = Model_Data_Translator::prepare_field_value_for_json(
589
+		foreach ($calculated_fields as $field_to_calculate) {
590
+			try {
591
+				$calculated_fields_to_return[$field_to_calculate] = Model_Data_Translator::prepare_field_value_for_json(
592 592
 					null,
593 593
 					$this->_fields_calculator->retrieve_calculated_field_value(
594 594
 						$model,
@@ -599,10 +599,10 @@  discard block
 block discarded – undo
599 599
 					),
600 600
 					$this->get_model_version_info()->requested_version()
601 601
 				);
602
-			} catch( Rest_Exception $e ) {
602
+			} catch (Rest_Exception $e) {
603 603
 				//if we don't have permission to read it, just leave it out. but let devs know about the problem
604 604
 				$this->_set_response_header(
605
-					'Notices-Field-Calculation-Errors[' . $e->get_string_code() . '][' . $model->get_this_model_name() . '][' . $field_to_calculate . ']',
605
+					'Notices-Field-Calculation-Errors['.$e->get_string_code().']['.$model->get_this_model_name().']['.$field_to_calculate.']',
606 606
 					$e->getMessage(),
607 607
 					true
608 608
 				);
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
 	 * @param string $link_part_after_version_and_slash eg "events/10/datetimes"
617 617
 	 * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes"
618 618
 	 */
619
-	public function get_versioned_link_to( $link_part_after_version_and_slash ) {
619
+	public function get_versioned_link_to($link_part_after_version_and_slash) {
620 620
 		return rest_url(
621 621
 			\EED_Core_Rest_Api::ee_api_namespace
622 622
 			. $this->get_model_version_info()->requested_version()
@@ -632,11 +632,11 @@  discard block
 block discarded – undo
632 632
 	 * @param \EE_Model_Relation_Base $relation_obj
633 633
 	 * @return string
634 634
 	 */
635
-	public static function get_related_entity_name( $relation_name, $relation_obj ){
636
-		if( $relation_obj instanceof \EE_Belongs_To_Relation ) {
637
-			return strtolower( $relation_name );
638
-		}else{
639
-			return \EEH_Inflector::pluralize_and_lower( $relation_name );
635
+	public static function get_related_entity_name($relation_name, $relation_obj) {
636
+		if ($relation_obj instanceof \EE_Belongs_To_Relation) {
637
+			return strtolower($relation_name);
638
+		} else {
639
+			return \EEH_Inflector::pluralize_and_lower($relation_name);
640 640
 		}
641 641
 	}
642 642
 
@@ -649,43 +649,43 @@  discard block
 block discarded – undo
649 649
 	 * @param \WP_REST_Request $request
650 650
 	 * @return array
651 651
 	 */
652
-	public function get_entity_from_model( $model, $request ) {
653
-		$query_params = array( array( $model->primary_key_name() => $request->get_param( 'id' ) ),'limit' => 1);
654
-		if( $model instanceof \EEM_Soft_Delete_Base ){
652
+	public function get_entity_from_model($model, $request) {
653
+		$query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1);
654
+		if ($model instanceof \EEM_Soft_Delete_Base) {
655 655
 			$query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params);
656 656
 		}
657 657
 		$restricted_query_params = $query_params;
658
-		$restricted_query_params[ 'caps' ] =  $this->validate_context(  $request->get_param( 'caps' ) );
659
-		$this->_set_debug_info( 'model query params', $restricted_query_params );
660
-		$model_rows = $model->get_all_wpdb_results( $restricted_query_params );
661
-		if ( ! empty ( $model_rows ) ) {
658
+		$restricted_query_params['caps'] = $this->validate_context($request->get_param('caps'));
659
+		$this->_set_debug_info('model query params', $restricted_query_params);
660
+		$model_rows = $model->get_all_wpdb_results($restricted_query_params);
661
+		if ( ! empty ($model_rows)) {
662 662
 			return $this->create_entity_from_wpdb_result(
663 663
 				$model,
664
-				array_shift( $model_rows ),
664
+				array_shift($model_rows),
665 665
 				$request );
666 666
 		} else {
667 667
 			//ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities
668
-			$lowercase_model_name = strtolower( $model->get_this_model_name() );
669
-			$model_rows_found_sans_restrictions = $model->get_all_wpdb_results( $query_params );
670
-			if( ! empty( $model_rows_found_sans_restrictions ) ) {
668
+			$lowercase_model_name = strtolower($model->get_this_model_name());
669
+			$model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params);
670
+			if ( ! empty($model_rows_found_sans_restrictions)) {
671 671
 				//you got shafted- it existed but we didn't want to tell you!
672 672
 				return new \WP_Error(
673 673
 					'rest_user_cannot_read',
674 674
 					sprintf(
675
-						__( 'Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso' ),
676
-						strtolower( $model->get_this_model_name() ),
675
+						__('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'),
676
+						strtolower($model->get_this_model_name()),
677 677
 						Capabilities::get_missing_permissions_string(
678 678
 							$model,
679
-							$this->validate_context( $request->get_param( 'caps' ) ) )
679
+							$this->validate_context($request->get_param('caps')) )
680 680
 					),
681
-					array( 'status' => 403 )
681
+					array('status' => 403)
682 682
 				);
683 683
 			} else {
684 684
 				//it's not you. It just doesn't exist
685 685
 				return new \WP_Error(
686
-					sprintf( 'rest_%s_invalid_id', $lowercase_model_name ),
687
-					sprintf( __( 'Invalid %s ID.', 'event_espresso' ), $lowercase_model_name ),
688
-					array( 'status' => 404 )
686
+					sprintf('rest_%s_invalid_id', $lowercase_model_name),
687
+					sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name),
688
+					array('status' => 404)
689 689
 				);
690 690
 			}
691 691
 		}
@@ -698,14 +698,14 @@  discard block
 block discarded – undo
698 698
 	 * @param string $context
699 699
 	 * @return string array key of EEM_Base::cap_contexts_to_cap_action_map()
700 700
 	 */
701
-	public function validate_context( $context ) {
702
-		if( ! $context ) {
701
+	public function validate_context($context) {
702
+		if ( ! $context) {
703 703
 			$context = \EEM_Base::caps_read;
704 704
 		}
705 705
 		$valid_contexts = \EEM_Base::valid_cap_contexts();
706
-		if( in_array( $context, $valid_contexts )  ){
706
+		if (in_array($context, $valid_contexts)) {
707 707
 			return $context;
708
-		}else{
708
+		} else {
709 709
 			return \EEM_Base::caps_read;
710 710
 		}
711 711
 	}
@@ -724,77 +724,77 @@  discard block
 block discarded – undo
724 724
 	 *                          that absolutely no results should be returned
725 725
 	 * @throws \EE_Error
726 726
 	 */
727
-	public function create_model_query_params( $model, $query_parameters ) {
727
+	public function create_model_query_params($model, $query_parameters) {
728 728
 		$model_query_params = array( );
729
-		if ( isset( $query_parameters[ 'where' ] ) ) {
730
-			$model_query_params[ 0 ] = Model_Data_Translator::prepare_conditions_query_params_for_models(
731
-				$query_parameters[ 'where' ],
729
+		if (isset($query_parameters['where'])) {
730
+			$model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models(
731
+				$query_parameters['where'],
732 732
 				$model,
733 733
 				$this->get_model_version_info()->requested_version()
734 734
 			);
735 735
 		}
736
-		if ( isset( $query_parameters[ 'order_by' ] ) ) {
737
-			$order_by = $query_parameters[ 'order_by' ];
738
-		} elseif ( isset( $query_parameters[ 'orderby' ] ) ) {
739
-			$order_by = $query_parameters[ 'orderby' ];
740
-		}else{
736
+		if (isset($query_parameters['order_by'])) {
737
+			$order_by = $query_parameters['order_by'];
738
+		} elseif (isset($query_parameters['orderby'])) {
739
+			$order_by = $query_parameters['orderby'];
740
+		} else {
741 741
 			$order_by = null;
742 742
 		}
743
-		if( $order_by !== null ){
744
-			$model_query_params[ 'order_by' ] =  $order_by;
743
+		if ($order_by !== null) {
744
+			$model_query_params['order_by'] = $order_by;
745 745
 		}
746
-		if ( isset( $query_parameters[ 'group_by' ] ) ) {
747
-			$group_by = $query_parameters[ 'group_by' ];
748
-		} elseif ( isset( $query_parameters[ 'groupby' ] ) ) {
749
-			$group_by = $query_parameters[ 'groupby' ];
750
-		}else{
746
+		if (isset($query_parameters['group_by'])) {
747
+			$group_by = $query_parameters['group_by'];
748
+		} elseif (isset($query_parameters['groupby'])) {
749
+			$group_by = $query_parameters['groupby'];
750
+		} else {
751 751
 			$group_by = null;
752 752
 		}
753
-		if( $group_by !== null ){
754
-			$model_query_params[ 'group_by' ] = $group_by;
753
+		if ($group_by !== null) {
754
+			$model_query_params['group_by'] = $group_by;
755 755
 		}
756
-		if ( isset( $query_parameters[ 'having' ] ) ) {
757
-			$model_query_params[ 'having' ] = Model_Data_Translator::prepare_conditions_query_params_for_models(
758
-				$query_parameters[ 'having' ],
756
+		if (isset($query_parameters['having'])) {
757
+			$model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models(
758
+				$query_parameters['having'],
759 759
 				$model,
760 760
 				$this->get_model_version_info()->requested_version()
761 761
 			);
762 762
 		}
763
-		if ( isset( $query_parameters[ 'order' ] ) ) {
764
-			$model_query_params[ 'order' ] = $query_parameters[ 'order' ];
763
+		if (isset($query_parameters['order'])) {
764
+			$model_query_params['order'] = $query_parameters['order'];
765 765
 		}
766
-		if ( isset( $query_parameters[ 'mine' ] ) ){
767
-			$model_query_params = $model->alter_query_params_to_only_include_mine( $model_query_params );
766
+		if (isset($query_parameters['mine'])) {
767
+			$model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params);
768 768
 		}
769
-		if( isset( $query_parameters[ 'limit' ] ) ) {
769
+		if (isset($query_parameters['limit'])) {
770 770
 			//limit should be either a string like '23' or '23,43', or an array with two items in it
771
-			if( ! is_array( $query_parameters[ 'limit' ] ) ) {
772
-				$limit_array = explode(',', (string)$query_parameters['limit']);
773
-			}else {
774
-				$limit_array = $query_parameters[ 'limit' ];
771
+			if ( ! is_array($query_parameters['limit'])) {
772
+				$limit_array = explode(',', (string) $query_parameters['limit']);
773
+			} else {
774
+				$limit_array = $query_parameters['limit'];
775 775
 			}
776 776
 			$sanitized_limit = array();
777
-			foreach( $limit_array as $key => $limit_part ) {
778
-				if( $this->_debug_mode && ( ! is_numeric( $limit_part ) || count( $sanitized_limit ) > 2 ) ) {
777
+			foreach ($limit_array as $key => $limit_part) {
778
+				if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) {
779 779
 					throw new \EE_Error(
780 780
 						sprintf(
781
-							__( 'An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso' ),
782
-							json_encode( $query_parameters[ 'limit' ] )
781
+							__('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso'),
782
+							json_encode($query_parameters['limit'])
783 783
 						)
784 784
 					);
785 785
 				}
786
-				$sanitized_limit[] = intval( $limit_part );
786
+				$sanitized_limit[] = intval($limit_part);
787 787
 			}
788
-			$model_query_params[ 'limit' ] = implode( ',', $sanitized_limit );
789
-		}else{
790
-			$model_query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit();
788
+			$model_query_params['limit'] = implode(',', $sanitized_limit);
789
+		} else {
790
+			$model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit();
791 791
 		}
792
-		if( isset( $query_parameters[ 'caps' ] ) ) {
793
-			$model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] );
794
-		}else{
795
-			$model_query_params[ 'caps' ] = \EEM_Base::caps_read;
792
+		if (isset($query_parameters['caps'])) {
793
+			$model_query_params['caps'] = $this->validate_context($query_parameters['caps']);
794
+		} else {
795
+			$model_query_params['caps'] = \EEM_Base::caps_read;
796 796
 		}
797
-		return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model );
797
+		return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model);
798 798
 	}
799 799
 
800 800
 
@@ -806,13 +806,13 @@  discard block
 block discarded – undo
806 806
 	 * @param array     $query_params sub-array from @see EEM_Base::get_all()
807 807
 	 * @return array
808 808
 	 */
809
-	public function prepare_rest_query_params_key_for_models( $model,  $query_params ) {
809
+	public function prepare_rest_query_params_key_for_models($model, $query_params) {
810 810
 		$model_ready_query_params = array();
811
-		foreach( $query_params as $key => $value ) {
812
-			if( is_array( $value ) ) {
813
-				$model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value );
814
-			}else{
815
-				$model_ready_query_params[ $key ] = $value;
811
+		foreach ($query_params as $key => $value) {
812
+			if (is_array($value)) {
813
+				$model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value);
814
+			} else {
815
+				$model_ready_query_params[$key] = $value;
816 816
 			}
817 817
 		}
818 818
 		return $model_ready_query_params;
@@ -826,13 +826,13 @@  discard block
 block discarded – undo
826 826
 	 * @param $query_params
827 827
 	 * @return array
828 828
 	 */
829
-	public function prepare_rest_query_params_values_for_models( $model, $query_params ) {
829
+	public function prepare_rest_query_params_values_for_models($model, $query_params) {
830 830
 		$model_ready_query_params = array();
831
-		foreach( $query_params as $key => $value ) {
832
-			if( is_array( $value ) ) {
833
-				$model_ready_query_params[ $key ] = $this->prepare_rest_query_params_values_for_models( $model, $value );
831
+		foreach ($query_params as $key => $value) {
832
+			if (is_array($value)) {
833
+				$model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value);
834 834
 			} else {
835
-				$model_ready_query_params[ $key ] = $value;
835
+				$model_ready_query_params[$key] = $value;
836 836
 			}
837 837
 		}
838 838
 		return $model_ready_query_params;
@@ -847,33 +847,33 @@  discard block
 block discarded – undo
847 847
 	 * we only return strings starting with that and a period; if no prefix was specified
848 848
 	 * we return all items containing NO periods
849 849
 	 */
850
-	public function explode_and_get_items_prefixed_with( $string_to_explode, $prefix ) {
851
-		if( is_string( $string_to_explode ) ) {
852
-			$exploded_contents = explode( ',', $string_to_explode );
853
-		} else if( is_array( $string_to_explode ) ) {
850
+	public function explode_and_get_items_prefixed_with($string_to_explode, $prefix) {
851
+		if (is_string($string_to_explode)) {
852
+			$exploded_contents = explode(',', $string_to_explode);
853
+		} else if (is_array($string_to_explode)) {
854 854
 			$exploded_contents = $string_to_explode;
855 855
 		} else {
856 856
 			$exploded_contents = array();
857 857
 		}
858 858
 		//if the string was empty, we want an empty array
859
-		$exploded_contents = array_filter( $exploded_contents );
859
+		$exploded_contents = array_filter($exploded_contents);
860 860
 		$contents_with_prefix = array();
861
-		foreach( $exploded_contents as $item ) {
862
-			$item = trim( $item );
861
+		foreach ($exploded_contents as $item) {
862
+			$item = trim($item);
863 863
 			//if no prefix was provided, so we look for items with no "." in them
864
-			if( ! $prefix ) {
864
+			if ( ! $prefix) {
865 865
 				//does this item have a period?
866
-				if( strpos( $item, '.' ) === false ) {
866
+				if (strpos($item, '.') === false) {
867 867
 					//if not, then its what we're looking for
868 868
 					$contents_with_prefix[] = $item;
869 869
 				}
870
-			} else if( strpos( $item, $prefix . '.' ) === 0 ) {
870
+			} else if (strpos($item, $prefix.'.') === 0) {
871 871
 				//this item has the prefix and a period, grab it
872 872
 				$contents_with_prefix[] = substr(
873 873
 					$item,
874
-					strpos( $item, $prefix . '.' ) + strlen( $prefix . '.' )
874
+					strpos($item, $prefix.'.') + strlen($prefix.'.')
875 875
 					);
876
-			} else if( $item === $prefix ) {
876
+			} else if ($item === $prefix) {
877 877
 				//this item is JUST the prefix
878 878
 				//so let's grab everything after, which is a blank string
879 879
 				$contents_with_prefix[] = '';
@@ -896,33 +896,33 @@  discard block
 block discarded – undo
896 896
 	 * the fields for that model, with the model's name removed from each.
897 897
 	 * If $include_string was blank or '*' returns an empty array
898 898
 	 */
899
-	public function extract_includes_for_this_model( $include_string, $model_name = null ) {
900
-		if( is_array( $include_string ) ) {
901
-			$include_string = implode( ',', $include_string );
899
+	public function extract_includes_for_this_model($include_string, $model_name = null) {
900
+		if (is_array($include_string)) {
901
+			$include_string = implode(',', $include_string);
902 902
 		}
903
-		if( $include_string === '*' || $include_string === '' ) {
903
+		if ($include_string === '*' || $include_string === '') {
904 904
 			return array();
905 905
 		}
906
-		$includes = explode( ',', $include_string );
906
+		$includes = explode(',', $include_string);
907 907
 		$extracted_fields_to_include = array();
908
-		if( $model_name ){
909
-			foreach( $includes as $field_to_include ) {
910
-				$field_to_include = trim( $field_to_include );
911
-				if( strpos( $field_to_include, $model_name . '.' ) === 0 ) {
908
+		if ($model_name) {
909
+			foreach ($includes as $field_to_include) {
910
+				$field_to_include = trim($field_to_include);
911
+				if (strpos($field_to_include, $model_name.'.') === 0) {
912 912
 					//found the model name at the exact start
913
-					$field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include );
913
+					$field_sans_model_name = str_replace($model_name.'.', '', $field_to_include);
914 914
 					$extracted_fields_to_include[] = $field_sans_model_name;
915
-				}elseif( $field_to_include == $model_name ){
915
+				}elseif ($field_to_include == $model_name) {
916 916
 					$extracted_fields_to_include[] = '*';
917 917
 				}
918 918
 			}
919
-		}else{
919
+		} else {
920 920
 			//look for ones with no period
921
-			foreach( $includes as $field_to_include ) {
922
-				$field_to_include = trim( $field_to_include );
921
+			foreach ($includes as $field_to_include) {
922
+				$field_to_include = trim($field_to_include);
923 923
 				if (
924
-					strpos( $field_to_include, '.' ) === false
925
-					&& ! $this->get_model_version_info()->is_model_name_in_this_version( $field_to_include )
924
+					strpos($field_to_include, '.') === false
925
+					&& ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include)
926 926
 				) {
927 927
 					$extracted_fields_to_include[] = $field_to_include;
928 928
 				}
Please login to merge, or discard this patch.
core/libraries/rest_api/Model_Version_Info.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\libraries\rest_api;
3 3
 
4
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 /**
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	protected $_cached_fields_on_models = array();
89 89
 
90 90
 
91
-	public function __construct( $requested_version ) {
91
+	public function __construct($requested_version) {
92 92
 		$this->_requested_version = $requested_version;
93 93
 		$this->_model_changes = array(
94 94
 			'4.8.29' => array(
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 			'table_column' => 'N/A',
111 111
 			'always_available' => true,
112 112
 		);
113
-		foreach( $this->_resource_changes as $version => $model_classnames ) {
114
-			foreach( $model_classnames as $model_classname => $extra_fields ) {
115
-				foreach( $extra_fields as $fieldname => $field_data ) {
116
-					$this->_resource_changes[ $model_classname ][ $fieldname ][ 'name' ] = $fieldname;
117
-					foreach( $defaults as $attribute => $default_value ) {
118
-						if( ! isset( $this->_resource_changes[ $model_classname ][ $fieldname ][ $attribute ] ) ) {
119
-							$this->_resource_changes[ $model_classname ][ $fieldname ][ $attribute ] = $default_value;
113
+		foreach ($this->_resource_changes as $version => $model_classnames) {
114
+			foreach ($model_classnames as $model_classname => $extra_fields) {
115
+				foreach ($extra_fields as $fieldname => $field_data) {
116
+					$this->_resource_changes[$model_classname][$fieldname]['name'] = $fieldname;
117
+					foreach ($defaults as $attribute => $default_value) {
118
+						if ( ! isset($this->_resource_changes[$model_classname][$fieldname][$attribute])) {
119
+							$this->_resource_changes[$model_classname][$fieldname][$attribute] = $default_value;
120 120
 						}
121 121
 					}
122 122
 				}
@@ -132,11 +132,11 @@  discard block
 block discarded – undo
132 132
 	 * @return array
133 133
 	 */
134 134
 	public function model_changes_between_requested_version_and_current() {
135
-		if( $this->_cached_model_changes_between_requested_version_and_current === null ) {
135
+		if ($this->_cached_model_changes_between_requested_version_and_current === null) {
136 136
 			$model_changes = array();
137
-			foreach( $this->model_changes() as $version => $models_changed_in_version ) {
138
-				if( $version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version() ) {
139
-					$model_changes[ $version ] = $models_changed_in_version;
137
+			foreach ($this->model_changes() as $version => $models_changed_in_version) {
138
+				if ($version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version()) {
139
+					$model_changes[$version] = $models_changed_in_version;
140 140
 				}
141 141
 			}
142 142
 			$this->_cached_model_changes_between_requested_version_and_current = $model_changes;
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 	 * @return array
153 153
 	 */
154 154
 	public function resource_changes_between_requested_version_and_current() {
155
-		if( $this->_cached_resource_changes_between_requested_version_and_current === null ) {
155
+		if ($this->_cached_resource_changes_between_requested_version_and_current === null) {
156 156
 			$resource_changes = array();
157
-			foreach( $this->resource_changes() as $version => $model_classnames ) {
158
-				if( $version <= \EED_Core_Rest_Api::core_version()  && $version > $this->requested_version()  ) {
159
-					$resource_changes[ $version ] = $model_classnames;
157
+			foreach ($this->resource_changes() as $version => $model_classnames) {
158
+				if ($version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version()) {
159
+					$resource_changes[$version] = $model_classnames;
160 160
 				}
161 161
 			}
162 162
 			$this->_cached_resource_changes_between_requested_version_and_current = $resource_changes;
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 * If a request was sent to 'wp-json/ee/v4.7/events' this would be '4.7'
169 169
 	 * @return string like '4.6'
170 170
 	 */
171
-	public function requested_version(){
171
+	public function requested_version() {
172 172
 		return $this->_requested_version;
173 173
 	}
174 174
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 * If a version is missing then we don't know anything about what changes it introduced from the previous version
183 183
 	 * @return array
184 184
 	 */
185
-	public function model_changes(){
185
+	public function model_changes() {
186 186
 		return $this->_model_changes;
187 187
 	}
188 188
 
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
 	 * @return array keys are model names, values are their classname
194 194
 	 */
195 195
 	public function models_for_requested_version() {
196
-		if( $this->_cached_models_for_requested_version === null ) {
196
+		if ($this->_cached_models_for_requested_version === null) {
197 197
 			$all_models_in_current_version = \EE_Registry::instance()->non_abstract_db_models;
198
-			foreach( $this->model_changes_between_requested_version_and_current() as $version => $models_changed ) {
199
-				foreach( $models_changed as $model_name => $new_indicator_or_fields_added ) {
200
-					if( $new_indicator_or_fields_added === Model_Version_Info::model_added ) {
201
-						unset( $all_models_in_current_version[ $model_name ] );
198
+			foreach ($this->model_changes_between_requested_version_and_current() as $version => $models_changed) {
199
+				foreach ($models_changed as $model_name => $new_indicator_or_fields_added) {
200
+					if ($new_indicator_or_fields_added === Model_Version_Info::model_added) {
201
+						unset($all_models_in_current_version[$model_name]);
202 202
 					}
203 203
 				}
204 204
 			}
@@ -217,11 +217,11 @@  discard block
 block discarded – undo
217 217
 	 * @param string $model_name eg 'Event'
218 218
 	 * @return boolean
219 219
 	 */
220
-	public function is_model_name_in_this_version( $model_name ) {
220
+	public function is_model_name_in_this_version($model_name) {
221 221
 		$model_names = $this->models_for_requested_version();
222
-		if( isset( $model_names[ $model_name ] ) ) {
222
+		if (isset($model_names[$model_name])) {
223 223
 			return true;
224
-		}else{
224
+		} else {
225 225
 			return false;
226 226
 		}
227 227
 	}
@@ -236,10 +236,10 @@  discard block
 block discarded – undo
236 236
 	 * @return \EEM_Base
237 237
 	 * @throws \EE_Error
238 238
 	 */
239
-	public function load_model( $model_name ) {
240
-		if( $this->is_model_name_in_this_version( $model_name ) ) {
241
-			return \EE_Registry::instance()->load_model( $model_name );
242
-		}else{
239
+	public function load_model($model_name) {
240
+		if ($this->is_model_name_in_this_version($model_name)) {
241
+			return \EE_Registry::instance()->load_model($model_name);
242
+		} else {
243 243
 			throw new \EE_Error(
244 244
 				sprintf(
245 245
 					__(
@@ -261,21 +261,21 @@  discard block
 block discarded – undo
261 261
 	 * @param \EEM_Base $model
262 262
 	 * @return array|\EE_Model_Field_Base[]
263 263
 	 */
264
-	public function fields_on_model_in_this_version( $model ) {
265
-		if( ! isset( $this->_cached_fields_on_models[ $model->get_this_model_name() ] ) ) {
264
+	public function fields_on_model_in_this_version($model) {
265
+		if ( ! isset($this->_cached_fields_on_models[$model->get_this_model_name()])) {
266 266
 			//get all model changes between the requested version and current core version
267 267
 			$changes = $this->model_changes_between_requested_version_and_current();
268 268
 			//fetch all fields currently on this model
269 269
 			$current_fields = $model->field_settings();
270 270
 			//remove all fields that have been added since
271
-			foreach( $changes as $version => $changes_in_version ) {
272
-				if(
273
-					isset( $changes_in_version[ $model->get_this_model_name() ] )
274
-					&& $changes_in_version[ $model->get_this_model_name() ] !== Model_Version_Info::model_added
271
+			foreach ($changes as $version => $changes_in_version) {
272
+				if (
273
+					isset($changes_in_version[$model->get_this_model_name()])
274
+					&& $changes_in_version[$model->get_this_model_name()] !== Model_Version_Info::model_added
275 275
 				) {
276 276
 					$current_fields = array_diff_key(
277 277
 						$current_fields,
278
-						array_flip( $changes_in_version[ $model->get_this_model_name() ] )
278
+						array_flip($changes_in_version[$model->get_this_model_name()])
279 279
 					);
280 280
 				}
281 281
 			}
@@ -293,9 +293,9 @@  discard block
 block discarded – undo
293 293
 	 * @param array $classnames
294 294
 	 * @return boolean
295 295
 	 */
296
-	public function is_subclass_of_one( $object, $classnames ) {
297
-		foreach( $classnames as $classname ) {
298
-			if( is_a( $object, $classname ) ) {
296
+	public function is_subclass_of_one($object, $classnames) {
297
+		foreach ($classnames as $classname) {
298
+			if (is_a($object, $classname)) {
299 299
 				return true;
300 300
 			}
301 301
 		}
@@ -306,10 +306,10 @@  discard block
 block discarded – undo
306 306
 	 * Returns the list of model field classes that that the API basically ignores
307 307
 	 * @return array
308 308
 	 */
309
-	public function fields_ignored(){
309
+	public function fields_ignored() {
310 310
 		return apply_filters(
311 311
 			'FHEE__Controller_Model_Read_fields_ignored',
312
-			array( 'EE_Foreign_Key_Field_Base', 'EE_Any_Foreign_Model_Name_Field' )
312
+			array('EE_Foreign_Key_Field_Base', 'EE_Any_Foreign_Model_Name_Field')
313 313
 		);
314 314
 	}
315 315
 
@@ -318,8 +318,8 @@  discard block
 block discarded – undo
318 318
 	 * @param EE_Model_Field_Base
319 319
 	 * @return boolean
320 320
 	 */
321
-	public function field_is_ignored( $field_obj ){
322
-		 return $this->is_subclass_of_one( $field_obj, $this->fields_ignored() );
321
+	public function field_is_ignored($field_obj) {
322
+		 return $this->is_subclass_of_one($field_obj, $this->fields_ignored());
323 323
 	}
324 324
 
325 325
 	/**
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 	public function fields_that_have_rendered_format() {
331 331
 		return apply_filters(
332 332
 			'FHEE__Controller_Model_Read__fields_raw',
333
-			array( 'EE_Post_Content_Field', 'EE_Full_HTML_Field' )
333
+			array('EE_Post_Content_Field', 'EE_Full_HTML_Field')
334 334
 		);
335 335
 	}
336 336
 
@@ -339,8 +339,8 @@  discard block
 block discarded – undo
339 339
 	 * @param EE_Model_Field_Base
340 340
 	 * @return boolean
341 341
 	 */
342
-	public function field_has_rendered_format( $field_obj ){
343
-		 return $this->is_subclass_of_one( $field_obj, $this->fields_that_have_rendered_format() );
342
+	public function field_has_rendered_format($field_obj) {
343
+		 return $this->is_subclass_of_one($field_obj, $this->fields_that_have_rendered_format());
344 344
 	}
345 345
 
346 346
 	/**
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
 	public function fields_that_have_pretty_format() {
353 353
 		return apply_filters(
354 354
 			'FHEE__Controller_Model_Read__fields_pretty',
355
-			array( 'EE_Enum_Integer_Field', 'EE_Enum_Text_Field', 'EE_Money_Field' )
355
+			array('EE_Enum_Integer_Field', 'EE_Enum_Text_Field', 'EE_Money_Field')
356 356
 		);
357 357
 	}
358 358
 
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
 	 * @param EE_Model_Field_Base
362 362
 	 * @return boolean
363 363
 	 */
364
-	public function field_has_pretty_format( $field_obj ){
365
-		 return $this->is_subclass_of_one( $field_obj, $this->fields_that_have_pretty_format() );
364
+	public function field_has_pretty_format($field_obj) {
365
+		 return $this->is_subclass_of_one($field_obj, $this->fields_that_have_pretty_format());
366 366
 	}
367 367
 
368 368
 	/**
@@ -379,12 +379,12 @@  discard block
 block discarded – undo
379 379
 	 * @param \EEM_Base $model
380 380
 	 * @return array
381 381
 	 */
382
-	public function extra_resource_properties_for_model( $model ) {
382
+	public function extra_resource_properties_for_model($model) {
383 383
 		$extra_properties = array();
384
-		foreach( $this->resource_changes_between_requested_version_and_current() as $version => $model_classnames ) {
385
-			foreach( $model_classnames as $model_classname => $properties_added_in_this_version ) {
386
-				if( is_subclass_of( $model, $model_classname ) ) {
387
-					$extra_properties = array_merge( $extra_properties, $properties_added_in_this_version );
384
+		foreach ($this->resource_changes_between_requested_version_and_current() as $version => $model_classnames) {
385
+			foreach ($model_classnames as $model_classname => $properties_added_in_this_version) {
386
+				if (is_subclass_of($model, $model_classname)) {
387
+					$extra_properties = array_merge($extra_properties, $properties_added_in_this_version);
388 388
 				}
389 389
 			}
390 390
 		}
@@ -397,11 +397,11 @@  discard block
 block discarded – undo
397 397
 	 * @param \EEM_Base $model
398 398
 	 * @return \EE_Model_Relation_Base[]
399 399
 	 */
400
-	public function relation_settings( \EEM_Base $model ) {
400
+	public function relation_settings(\EEM_Base $model) {
401 401
 		$relations = array();
402
-		foreach( $model->relation_settings() as $relation_name => $relation_obj ) {
403
-			if( $this->is_model_name_in_this_version(  $relation_name ) ) {
404
-				$relations[ $relation_name ] = $relation_obj;
402
+		foreach ($model->relation_settings() as $relation_name => $relation_obj) {
403
+			if ($this->is_model_name_in_this_version($relation_name)) {
404
+				$relations[$relation_name] = $relation_obj;
405 405
 			}
406 406
 		}
407 407
 		//filter the results, but use the old filter name
Please login to merge, or discard this patch.
admin/extend/registrations/Extend_Registrations_Admin_Page.core.php 1 patch
Spacing   +233 added lines, -233 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
 /**
@@ -37,20 +37,20 @@  discard block
 block discarded – undo
37 37
 	protected $_reports_template_data = array();
38 38
 
39 39
 
40
-	public function __construct( $routing = TRUE ) {
41
-		parent::__construct( $routing );
42
-		define( 'REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
43
-		define( 'REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
44
-		define( 'REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
40
+	public function __construct($routing = TRUE) {
41
+		parent::__construct($routing);
42
+		define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/');
43
+		define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/');
44
+		define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/');
45 45
 	}
46 46
 
47 47
 
48 48
 	protected function _extend_page_config() {
49
-		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations';
50 50
 
51
-		$reg_id = ! empty( $this->_req_data['_REG_ID'] ) && ! is_array( $this->_req_data['_REG_ID'] ) ? $this->_req_data['_REG_ID'] : 0;
52
-		$att_id = ! empty( $this->_req_data[ 'ATT_ID' ] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0;
53
-		$att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] ) ? $this->_req_data['post'] : $att_id;
51
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0;
52
+		$att_id = ! empty($this->_req_data['ATT_ID']) ? ! is_array($this->_req_data['ATT_ID']) : 0;
53
+		$att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) ? $this->_req_data['post'] : $att_id;
54 54
 
55 55
 		$new_page_routes = array(
56 56
 			'reports' => array(
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 				)
90 90
 			);
91 91
 
92
-		$this->_page_routes = array_merge( $this->_page_routes, $new_page_routes );
92
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
93 93
 
94 94
 		$new_page_config = array(
95 95
 			'reports' => array(
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
 						'filename' => 'registrations_event_checkin_other'
135 135
 					)
136 136
 				),
137
-				'help_tour' => array( 'Event_Checkin_Help_Tour' ),
138
-				'qtips' => array('Registration_List_Table_Tips' ),
137
+				'help_tour' => array('Event_Checkin_Help_Tour'),
138
+				'qtips' => array('Registration_List_Table_Tips'),
139 139
 				'list_table' => 'EE_Event_Registrations_List_Table',
140 140
 				'metaboxes' => array(),
141 141
 				'require_nonce' => FALSE
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		// var_dump($this->_req_data);
157 157
 		// exit();
158 158
 
159
-		$this->_page_config = array_merge( $this->_page_config, $new_page_config );
159
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
160 160
 		$this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
161 161
 		$this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
162 162
 	}
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 
166 166
 	protected function _ajax_hooks() {
167 167
 		parent::_ajax_hooks();
168
-		add_action('wp_ajax_get_newsletter_form_content', array( $this, 'get_newsletter_form_content') );
168
+		add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
169 169
 	}
170 170
 
171 171
 
@@ -175,20 +175,20 @@  discard block
 block discarded – undo
175 175
 
176 176
 		//if newsletter message type is active then let's add filter and load js for it.
177 177
 		EE_Registry::instance()->load_helper('MSG_Template');
178
-		if ( EEH_MSG_Template::is_mt_active('newsletter') ) {
178
+		if (EEH_MSG_Template::is_mt_active('newsletter')) {
179 179
 			//enqueue newsletter js
180
-			wp_enqueue_script( 'ee-newsletter-trigger', REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', array( 'ee-dialog'), EVENT_ESPRESSO_VERSION, TRUE );
181
-			wp_enqueue_style( 'ee-newsletter-trigger-css', REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', array(), EVENT_ESPRESSO_VERSION );
180
+			wp_enqueue_script('ee-newsletter-trigger', REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js', array('ee-dialog'), EVENT_ESPRESSO_VERSION, TRUE);
181
+			wp_enqueue_style('ee-newsletter-trigger-css', REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css', array(), EVENT_ESPRESSO_VERSION);
182 182
 			//hook in buttons for newsletter message type trigger.
183
-			add_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', array( $this, 'add_newsletter_action_buttons'), 10 );
183
+			add_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', array($this, 'add_newsletter_action_buttons'), 10);
184 184
 		}
185 185
 	}
186 186
 
187 187
 
188 188
 
189 189
 	public function load_scripts_styles_reports() {
190
-		wp_register_script( 'ee-reg-reports-js', REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', array( 'google-charts' ), EVENT_ESPRESSO_VERSION, true );
191
-		wp_enqueue_script( 'ee-reg-reports-js' );
190
+		wp_register_script('ee-reg-reports-js', REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js', array('google-charts'), EVENT_ESPRESSO_VERSION, true);
191
+		wp_enqueue_script('ee-reg-reports-js');
192 192
 		$this->_registration_reports_js_setup();
193 193
 	}
194 194
 
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 				'slug' => 'all',
221 221
 				'label' => __('All', 'event_espresso'),
222 222
 				'count' => 0,
223
-				'bulk_action' => !isset( $this->_req_data['event_id'] ) ? array() : array(
223
+				'bulk_action' => ! isset($this->_req_data['event_id']) ? array() : array(
224 224
 					'toggle_checkin_status' => __('Toggle Check-In', 'event_espresso'),
225 225
 					//'trash_registrations' => __('Trash Registrations', 'event_espresso')
226 226
 					)
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 				'slug' => 'all',
239 239
 				'label' => __('All', 'event_espresso'),
240 240
 				'count' => 0,
241
-				'bulk_action' => array( 'delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso') )
241
+				'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso'))
242 242
 				),
243 243
 			);
244 244
 	}
@@ -254,20 +254,20 @@  discard block
 block discarded – undo
254 254
 	 */
255 255
 	public function get_newsletter_form_content() {
256 256
 		//do a nonce check cause we're not coming in from an normal route here.
257
-		$nonce = isset( $this->_req_data['get_newsletter_form_content_nonce'] ) ? sanitize_text_field( $this->_req_data['get_newsletter_form_content_nonce'] ) : '';
257
+		$nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field($this->_req_data['get_newsletter_form_content_nonce']) : '';
258 258
 		$nonce_ref = 'get_newsletter_form_content_nonce';
259 259
 
260
-		$this->_verify_nonce( $nonce, $nonce_ref );
260
+		$this->_verify_nonce($nonce, $nonce_ref);
261 261
 		//let's get the mtp for the incoming MTP_ ID
262
-		if ( !isset( $this->_req_data['GRP_ID'] ) ) {
263
-			EE_Error::add_error( __('There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
262
+		if ( ! isset($this->_req_data['GRP_ID'])) {
263
+			EE_Error::add_error(__('There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
264 264
 			$this->_template_args['success'] = FALSE;
265 265
 			$this->_template_args['error'] = TRUE;
266 266
 			$this->_return_json();
267 267
 		}
268
-		$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $this->_req_data['GRP_ID'] );
269
-		if ( ! $MTPG instanceof EE_Message_Template_Group ) {
270
-			EE_Error::add_error( sprintf( __('The GRP_ID given (%d) does not appear to have a corresponding row in the database.', 'event_espresso'), $this->_req_data['GRP_ID'] ), __FILE__, __FUNCTION__, __LINE__  );
268
+		$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
269
+		if ( ! $MTPG instanceof EE_Message_Template_Group) {
270
+			EE_Error::add_error(sprintf(__('The GRP_ID given (%d) does not appear to have a corresponding row in the database.', 'event_espresso'), $this->_req_data['GRP_ID']), __FILE__, __FUNCTION__, __LINE__);
271 271
 			$this->_template_args['success'] = FALSE;
272 272
 			$this->_template_args['error'] = TRUE;
273 273
 			$this->_return_json();
@@ -276,11 +276,11 @@  discard block
 block discarded – undo
276 276
 		$MTPs = $MTPG->context_templates();
277 277
 		$MTPs = $MTPs['attendee'];
278 278
 		$template_fields = array();
279
-		foreach ( $MTPs as $MTP ) {
279
+		foreach ($MTPs as $MTP) {
280 280
 			$field = $MTP->get('MTP_template_field');
281
-			if ( $field == 'content'  ) {
281
+			if ($field == 'content') {
282 282
 				$content = $MTP->get('MTP_content');
283
-				if ( !empty( $content['newsletter_content'] ) ) {
283
+				if ( ! empty($content['newsletter_content'])) {
284 284
 					$template_fields['newsletter_content'] = $content['newsletter_content'];
285 285
 					}
286 286
 				continue;
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 		$this->_template_args['data'] = array(
294 294
 			'batch_message_from' => isset($template_fields['from']) ? $template_fields['from'] : '',
295 295
 			'batch_message_subject' => isset($template_fields['subject']) ? $template_fields['subject'] : '',
296
-			'batch_message_content' => isset( $template_fields['newsletter_content'] ) ? $template_fields['newsletter_content'] : ''
296
+			'batch_message_content' => isset($template_fields['newsletter_content']) ? $template_fields['newsletter_content'] : ''
297 297
 			);
298 298
 		$this->_return_json();
299 299
 	}
@@ -309,8 +309,8 @@  discard block
 block discarded – undo
309 309
 	 * @param EE_Admin_List_Table $list_table
310 310
 	 * @return string html string for extra buttons
311 311
 	 */
312
-	public function add_newsletter_action_buttons( EE_Admin_List_Table $list_table ) {
313
-		if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'espresso_registrations_newsletter_selected_send' ) ) {
312
+	public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) {
313
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_registrations_newsletter_selected_send')) {
314 314
 			return '';
315 315
 		}
316 316
 
@@ -319,13 +319,13 @@  discard block
 block discarded – undo
319 319
 			'event_registrations',
320 320
 			'default'
321 321
 			);
322
-		if ( $this->_current_page == 'espresso_registrations' && in_array( $this->_req_action, $routes_to_add_to )  ) {
323
-			if ( ( $this->_req_action == 'event_registrations' && empty( $this->_req_data['event_id'] ) ) || ( isset( $this->_req_data['status'] ) && $this->_req_data['status'] == 'trash' ) ) {
322
+		if ($this->_current_page == 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
323
+			if (($this->_req_action == 'event_registrations' && empty($this->_req_data['event_id'])) || (isset($this->_req_data['status']) && $this->_req_data['status'] == 'trash')) {
324 324
 				echo '';
325 325
 			} else {
326
-				$button_text = sprintf( __('Send Batch Message (%s selected)', 'event_espresso'), '<span class="send-selected-newsletter-count">0</span>' );
327
-				echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>' . $button_text . '</button>';
328
-				add_action('admin_footer', array( $this, 'newsletter_send_form_skeleton') );
326
+				$button_text = sprintf(__('Send Batch Message (%s selected)', 'event_espresso'), '<span class="send-selected-newsletter-count">0</span>');
327
+				echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>'.$button_text.'</button>';
328
+				add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
329 329
 			}
330 330
 		}
331 331
 	}
@@ -337,38 +337,38 @@  discard block
 block discarded – undo
337 337
 		$list_table = $this->_list_table_object;
338 338
 		$codes = array();
339 339
 		//need to templates for the newsletter message type for the template selector.
340
-		$values[] = array( 'text' => __('Select Template to Use', 'event_espresso'), 'id' => 0 );
341
-		$mtps = EEM_Message_Template_Group::instance()->get_all( array( array( 'MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email' ) ) );
342
-		foreach ( $mtps as $mtp ) {
340
+		$values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0);
341
+		$mtps = EEM_Message_Template_Group::instance()->get_all(array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')));
342
+		foreach ($mtps as $mtp) {
343 343
 			$name = $mtp->name();
344 344
 			$values[] = array(
345
-				'text' => empty( $name ) ? __('Global', 'event_espresso') : $name,
345
+				'text' => empty($name) ? __('Global', 'event_espresso') : $name,
346 346
 				'id' => $mtp->ID()
347 347
 				);
348 348
 		}
349 349
 
350 350
 		//need to get a list of shortcodes that are available for the newsletter message type.
351 351
 		EE_Registry::instance()->load_helper('MSG_Template');
352
-		$shortcodes = EEH_MSG_Template::get_shortcodes( 'newsletter', 'email', array(), 'attendee', FALSE );
353
-		foreach ( $shortcodes as $field => $shortcode_array ) {
354
-			$codes[$field] = implode(', ', array_keys($shortcode_array ) );
352
+		$shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', FALSE);
353
+		foreach ($shortcodes as $field => $shortcode_array) {
354
+			$codes[$field] = implode(', ', array_keys($shortcode_array));
355 355
 		}
356 356
 
357 357
 		$shortcodes = $codes;
358 358
 
359
-		$form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
359
+		$form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php';
360 360
 		$form_template_args = array(
361 361
 			'form_action' => admin_url('admin.php?page=espresso_registrations'),
362 362
 			'form_route' => 'newsletter_selected_send',
363 363
 			'form_nonce_name' => 'newsletter_selected_send_nonce',
364
-			'form_nonce' => wp_create_nonce( 'newsletter_selected_send_nonce' ),
364
+			'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'),
365 365
 			'redirect_back_to' => $this->_req_action,
366
-			'ajax_nonce' => wp_create_nonce( 'get_newsletter_form_content_nonce'),
367
-			'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values ),
366
+			'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'),
367
+			'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
368 368
 			'shortcodes' => $shortcodes,
369 369
 			'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration'
370 370
 			);
371
-		EEH_Template::display_template( $form_template, $form_template_args );
371
+		EEH_Template::display_template($form_template, $form_template_args);
372 372
 	}
373 373
 
374 374
 
@@ -383,35 +383,35 @@  discard block
 block discarded – undo
383 383
 	protected function _newsletter_selected_send() {
384 384
 		$success = TRUE;
385 385
 		//first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
386
-		if ( empty( $this->_req_data['newsletter_mtp_selected'] ) ) {
387
-			EE_Error::add_error( __('In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
386
+		if (empty($this->_req_data['newsletter_mtp_selected'])) {
387
+			EE_Error::add_error(__('In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
388 388
 			$success = FALSE;
389 389
 		}
390 390
 
391
-		if ( $success ) {
391
+		if ($success) {
392 392
 			//update Message template in case there are any changes
393
-			$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $this->_req_data['newsletter_mtp_selected'] );
393
+			$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['newsletter_mtp_selected']);
394 394
 			$MTPs = $MTPG instanceof EE_Message_Template_Group ? $MTPG->context_templates() : array();
395
-			if ( empty( $MTPs ) ) {
396
-				EE_Error::add_error( __('Unable to retrieve message template fields from the db. Messages not sent.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
395
+			if (empty($MTPs)) {
396
+				EE_Error::add_error(__('Unable to retrieve message template fields from the db. Messages not sent.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
397 397
 				$success = FALSE;
398 398
 			}
399 399
 
400 400
 			//let's just update the specific fields
401
-			foreach ( $MTPs['attendee'] as $MTP ) {
401
+			foreach ($MTPs['attendee'] as $MTP) {
402 402
 				$field = $MTP->get('MTP_template_field');
403 403
 				$content = $MTP->get('MTP_content');
404 404
 				$new_content = $content;
405
-				switch( $field ) {
405
+				switch ($field) {
406 406
 					case 'from' :
407
-						$new_content = !empty( $this->_req_data['batch_message']['from'] ) ? $this->_req_data['batch_message']['from'] : $content;
407
+						$new_content = ! empty($this->_req_data['batch_message']['from']) ? $this->_req_data['batch_message']['from'] : $content;
408 408
 						break;
409 409
 					case 'subject' :
410
-						$new_content = !empty( $this->_req_data['batch_message']['subject'] ) ? $this->_req_data['batch_message']['subject'] : $content;
410
+						$new_content = ! empty($this->_req_data['batch_message']['subject']) ? $this->_req_data['batch_message']['subject'] : $content;
411 411
 						break;
412 412
 					case 'content' :
413 413
 						$new_content = $content;
414
-						$new_content['newsletter_content'] = !empty( $this->_req_data['batch_message']['content'] ) ? $this->_req_data['batch_message']['content'] : $content['newsletter_content'];
414
+						$new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) ? $this->_req_data['batch_message']['content'] : $content['newsletter_content'];
415 415
 						break;
416 416
 					default :
417 417
 						continue;
@@ -422,20 +422,20 @@  discard block
 block discarded – undo
422 422
 			}
423 423
 
424 424
 			//great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
425
-			$id_type = !empty( $this->_req_data['batch_message']['id_type'] ) ? $this->_req_data['batch_message']['id_type'] : 'registration';
425
+			$id_type = ! empty($this->_req_data['batch_message']['id_type']) ? $this->_req_data['batch_message']['id_type'] : 'registration';
426 426
 
427 427
 			//id_type will affect how we assemble the ids.
428
-			$ids = !empty( $this->_req_data['batch_message']['ids'] ) ? json_decode( stripslashes($this->_req_data['batch_message']['ids']) ) : array();
428
+			$ids = ! empty($this->_req_data['batch_message']['ids']) ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) : array();
429 429
 
430
-			$contacts = $id_type == 'registration' ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids( $ids ) : EEM_Attendee::instance()->get_all( array( array( 'ATT_ID' => array('in', $ids ) ) ) );
430
+			$contacts = $id_type == 'registration' ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
431 431
 
432 432
 			//we do _action because ALL triggers are handled in EED_Messages.
433
-			do_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', $contacts, $MTPG->ID() );
433
+			do_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', $contacts, $MTPG->ID());
434 434
 		}
435 435
 		$query_args = array(
436
-			'action' => !empty( $this->_req_data['redirect_back_to'] ) ? $this->_req_data['redirect_back_to'] : 'default'
436
+			'action' => ! empty($this->_req_data['redirect_back_to']) ? $this->_req_data['redirect_back_to'] : 'default'
437 437
 			);
438
-		$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
438
+		$this->_redirect_after_action(FALSE, '', '', $query_args, TRUE);
439 439
 	}
440 440
 
441 441
 
@@ -457,8 +457,8 @@  discard block
 block discarded – undo
457 457
 	*		@return void
458 458
 	*/
459 459
 	protected function _registration_reports() {
460
-		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
461
-		$this->_template_args['admin_page_content'] = EEH_Template::display_template( $template_path, $this->_reports_template_data, true );
460
+		$template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
461
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_reports_template_data, true);
462 462
 		// the final template wrapper
463 463
 		$this->display_admin_page_with_no_sidebar();
464 464
 
@@ -471,29 +471,29 @@  discard block
 block discarded – undo
471 471
 	 *
472 472
 	 * @return string
473 473
 	 */
474
-	private function _registrations_per_day_report( $period = '-1 month' ) {
474
+	private function _registrations_per_day_report($period = '-1 month') {
475 475
 		$report_ID = 'reg-admin-registrations-per-day-report-dv';
476 476
 
477
-		$results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report( $period );
478
-		EE_Registry::instance()->load_helper( 'Template' );
477
+		$results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
478
+		EE_Registry::instance()->load_helper('Template');
479 479
 
480 480
 		$results = (array) $results;
481 481
 		$regs = array();
482 482
 		$subtitle = '';
483 483
 
484
-		if( $results ) {
484
+		if ($results) {
485 485
 			$column_titles = array();
486 486
 			$tracker = 0;
487
-			foreach ( $results as $result ) {
487
+			foreach ($results as $result) {
488 488
 				$report_column_values = array();
489
-				foreach( $result as $property_name => $property_value ) {
489
+				foreach ($result as $property_name => $property_value) {
490 490
 					$property_value = $property_name == 'Registration_REG_date' ? $property_value : (int) $property_value;
491 491
 					$report_column_values[] = $property_value;
492
-					if ( $tracker === 0 ) {
493
-						if ( $property_name == 'Registration_REG_date' ) {
494
-							$column_titles[] = __( 'Date (only days with registrations are shown)', 'event_espresso' );
492
+					if ($tracker === 0) {
493
+						if ($property_name == 'Registration_REG_date') {
494
+							$column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso');
495 495
 						} else {
496
-							$column_titles[] = EEH_Template::pretty_status( $property_name, false, 'sentence' );
496
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
497 497
 						}
498 498
 					}
499 499
 				}
@@ -502,37 +502,37 @@  discard block
 block discarded – undo
502 502
 			}
503 503
 
504 504
 			//make sure the column_titles is pushed to the beginning of the array
505
-			array_unshift( $regs, $column_titles );
505
+			array_unshift($regs, $column_titles);
506 506
 			//setup the date range.
507
-			EE_Registry::instance()->load_helper( 'DTT_Helper' );
508
-			$DateTimeZone = new DateTimeZone( EEH_DTT_Helper::get_timezone() );
509
-			$beginning_date = new DateTime( "now " . $period, $DateTimeZone );
510
-			$ending_date = new DateTime( "now", $DateTimeZone );
507
+			EE_Registry::instance()->load_helper('DTT_Helper');
508
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
509
+			$beginning_date = new DateTime("now ".$period, $DateTimeZone);
510
+			$ending_date = new DateTime("now", $DateTimeZone);
511 511
 			$subtitle = sprintf(
512
-				_x( 'For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso' ),
513
-				$beginning_date->format( 'Y-m-d' ),
514
-				$ending_date->format( 'Y-m-d' )
512
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
513
+				$beginning_date->format('Y-m-d'),
514
+				$ending_date->format('Y-m-d')
515 515
 			);
516 516
 		}
517 517
 
518
-		$report_title = __( 'Total Registrations per Day', 'event_espresso' );
518
+		$report_title = __('Total Registrations per Day', 'event_espresso');
519 519
 
520 520
 		$report_params = array(
521 521
 			'title' 	=> $report_title,
522 522
 			'subtitle' => $subtitle,
523 523
 			'id' 		=> $report_ID,
524 524
 			'regs' 	=> $regs,
525
-			'noResults' => empty( $regs ),
525
+			'noResults' => empty($regs),
526 526
 			'noRegsMsg' => sprintf(
527 527
 				__(
528 528
 					'%sThere are currently no registration records in the last month for this report.%s',
529 529
 					'event_espresso'
530 530
 				),
531
-				'<h2>' . $report_title . '</h2><p>',
531
+				'<h2>'.$report_title.'</h2><p>',
532 532
 				'</p>'
533 533
 			),
534 534
 		);
535
-		wp_localize_script( 'ee-reg-reports-js', 'regPerDay', $report_params );
535
+		wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
536 536
 
537 537
 		return $report_ID;
538 538
 	}
@@ -544,30 +544,30 @@  discard block
 block discarded – undo
544 544
 	 *
545 545
 	 * @return string
546 546
 	 */
547
-	private function _registrations_per_event_report( $period = '-1 month' ) {
547
+	private function _registrations_per_event_report($period = '-1 month') {
548 548
 
549 549
 		$report_ID = 'reg-admin-registrations-per-event-report-dv';
550 550
 
551
-		$results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report( $period );
552
-		EE_Registry::instance()->load_helper( 'Template' );
551
+		$results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
552
+		EE_Registry::instance()->load_helper('Template');
553 553
 
554 554
 		$results = (array) $results;
555 555
 		$regs = array();
556 556
 		$subtitle = '';
557 557
 
558
-		if ( $results ) {
558
+		if ($results) {
559 559
 			$column_titles = array();
560 560
 			$tracker = 0;
561
-			foreach ( $results as $result ) {
561
+			foreach ($results as $result) {
562 562
 				$report_column_values = array();
563
-				foreach( $result as $property_name => $property_value ) {
564
-					$property_value = $property_name == 'Registration_Event' ? wp_trim_words( $property_value, 4, '...' ) : (int) $property_value;
563
+				foreach ($result as $property_name => $property_value) {
564
+					$property_value = $property_name == 'Registration_Event' ? wp_trim_words($property_value, 4, '...') : (int) $property_value;
565 565
 					$report_column_values[] = $property_value;
566
-					if ( $tracker === 0 ) {
567
-						if ( $property_name == 'Registration_Event' ) {
568
-							$column_titles[] = __( 'Event', 'event_espresso' );
566
+					if ($tracker === 0) {
567
+						if ($property_name == 'Registration_Event') {
568
+							$column_titles[] = __('Event', 'event_espresso');
569 569
 						} else {
570
-							$column_titles[] = EEH_Template::pretty_status( $property_name, false, 'sentence' );
570
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
571 571
 						}
572 572
 					}
573 573
 				}
@@ -576,38 +576,38 @@  discard block
 block discarded – undo
576 576
 			}
577 577
 
578 578
 			//make sure the column_titles is pushed to the beginning of the array
579
-			array_unshift( $regs, $column_titles );
579
+			array_unshift($regs, $column_titles);
580 580
 
581 581
 			//setup the date range.
582
-			EE_Registry::instance()->load_helper( 'DTT_Helper' );
583
-			$DateTimeZone = new DateTimeZone( EEH_DTT_Helper::get_timezone() );
584
-			$beginning_date = new DateTime( "now " . $period, $DateTimeZone );
585
-			$ending_date = new DateTime( "now", $DateTimeZone );
582
+			EE_Registry::instance()->load_helper('DTT_Helper');
583
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
584
+			$beginning_date = new DateTime("now ".$period, $DateTimeZone);
585
+			$ending_date = new DateTime("now", $DateTimeZone);
586 586
 			$subtitle = sprintf(
587
-				_x( 'For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso' ),
588
-				$beginning_date->format( 'Y-m-d' ),
589
-				$ending_date->format( 'Y-m-d' )
587
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
588
+				$beginning_date->format('Y-m-d'),
589
+				$ending_date->format('Y-m-d')
590 590
 			);
591 591
 		}
592 592
 
593
-		$report_title = __( 'Total Registrations per Event', 'event_espresso' );
593
+		$report_title = __('Total Registrations per Event', 'event_espresso');
594 594
 
595 595
 		$report_params = array(
596 596
 			'title' 	=> $report_title,
597 597
 			'subtitle' => $subtitle,
598 598
 			'id' 		=> $report_ID,
599 599
 			'regs' 	=> $regs,
600
-			'noResults' => empty( $regs ),
600
+			'noResults' => empty($regs),
601 601
 			'noRegsMsg' => sprintf(
602 602
 				__(
603 603
 					'%sThere are currently no registration records in the last month for this report.%s',
604 604
 					'event_espresso'
605 605
 				),
606
-				'<h2>' . $report_title . '</h2><p>',
606
+				'<h2>'.$report_title.'</h2><p>',
607 607
 				'</p>'
608 608
 			),
609 609
 		);
610
-		wp_localize_script( 'ee-reg-reports-js', 'regPerEvent', $report_params );
610
+		wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
611 611
 
612 612
 		return $report_ID;
613 613
 	}
@@ -621,8 +621,8 @@  discard block
 block discarded – undo
621 621
 	 * @return void
622 622
 	 */
623 623
 	protected function _registration_checkin_list_table() {
624
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
625
-		$reg_id = isset( $this->_req_data['_REGID'] ) ? $this->_req_data['_REGID'] : null;
624
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
625
+		$reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null;
626 626
 		$reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
627 627
 		$this->_admin_page_title .= $this->get_action_link_or_button('new_registration', 'add-registrant', array('event_id' => $reg->event_ID()), 'add-new-h2');
628 628
 
@@ -636,15 +636,15 @@  discard block
 block discarded – undo
636 636
 				'desc' => __('This indicates the attendee has been checked out', 'event_espresso')
637 637
 				)
638 638
 			);
639
-		$this->_template_args['after_list_table'] = $this->_display_legend( $legend_items );
639
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
640 640
 
641 641
 
642
-		$dtt_id = isset(  $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : NULL;
643
-		$go_back_url = !empty( $reg_id )  ? EE_Admin_Page::add_query_args_and_nonce(array('action' => 'event_registrations', 'event_id' => EEM_Registration::instance()->get_one_by_ID($reg_id)->get_first_related('Event')->ID(), 'DTT_ID' => $dtt_id ), $this->_admin_base_url ) : '';
642
+		$dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : NULL;
643
+		$go_back_url = ! empty($reg_id) ? EE_Admin_Page::add_query_args_and_nonce(array('action' => 'event_registrations', 'event_id' => EEM_Registration::instance()->get_one_by_ID($reg_id)->get_first_related('Event')->ID(), 'DTT_ID' => $dtt_id), $this->_admin_base_url) : '';
644 644
 
645
-		$this->_template_args['before_list_table'] = !empty( $reg_id ) && !empty( $dtt_id ) ? '<h2>' . sprintf(__("%s's check in records for %s at the event, %s", 'event_espresso'), '<span id="checkin-attendee-name">' . EEM_Registration::instance()->get_one_by_ID($reg_id)->get_first_related('Attendee')->full_name() . '</span>', '<span id="checkin-dtt"><a href="' . $go_back_url . '">' . EEM_Datetime::instance()->get_one_by_ID($dtt_id)->start_date_and_time() . ' - ' . EEM_Datetime::instance()->get_one_by_ID($dtt_id)->end_date_and_time() . '</a></span>', '<span id="checkin-event-name">' . EEM_Datetime::instance()->get_one_by_ID($dtt_id)->get_first_related('Event')->get('EVT_name') . '</span>' ) . '</h2>' : '';
646
-		$this->_template_args['list_table_hidden_fields'] = !empty( $reg_id ) ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
647
-		$this->_template_args['list_table_hidden_fields'] .= !empty( $dtt_id ) ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
645
+		$this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) ? '<h2>'.sprintf(__("%s's check in records for %s at the event, %s", 'event_espresso'), '<span id="checkin-attendee-name">'.EEM_Registration::instance()->get_one_by_ID($reg_id)->get_first_related('Attendee')->full_name().'</span>', '<span id="checkin-dtt"><a href="'.$go_back_url.'">'.EEM_Datetime::instance()->get_one_by_ID($dtt_id)->start_date_and_time().' - '.EEM_Datetime::instance()->get_one_by_ID($dtt_id)->end_date_and_time().'</a></span>', '<span id="checkin-event-name">'.EEM_Datetime::instance()->get_one_by_ID($dtt_id)->get_first_related('Event')->get('EVT_name').'</span>').'</h2>' : '';
646
+		$this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) ? '<input type="hidden" name="_REGID" value="'.$reg_id.'">' : '';
647
+		$this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : '';
648 648
 
649 649
 		$this->display_admin_list_table_page_with_no_sidebar();
650 650
 	}
@@ -657,24 +657,24 @@  discard block
 block discarded – undo
657 657
 	 */
658 658
 	public function toggle_checkin_status() {
659 659
 		//first make sure we have the necessary data
660
-		if ( !isset( $this->_req_data['_regid'] ) ) {
661
-			EE_Error::add_error( __('There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
660
+		if ( ! isset($this->_req_data['_regid'])) {
661
+			EE_Error::add_error(__('There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
662 662
 			$this->_template_args['success'] = FALSE;
663 663
 			$this->_template_args['error'] = TRUE;
664 664
 			$this->_return_json();
665 665
 		};
666 666
 
667 667
 		//do a nonce check cause we're not coming in from an normal route here.
668
-		$nonce = isset( $this->_req_data['checkinnonce'] ) ? sanitize_text_field( $this->_req_data['checkinnonce'] ) : '';
668
+		$nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) : '';
669 669
 		$nonce_ref = 'checkin_nonce';
670 670
 
671
-		$this->_verify_nonce( $nonce, $nonce_ref );
671
+		$this->_verify_nonce($nonce, $nonce_ref);
672 672
 
673 673
 		//beautiful! Made it this far so let's get the status.
674 674
 		$new_status = $this->_toggle_checkin_status();
675 675
 
676 676
 		//setup new class to return via ajax
677
-		$this->_template_args['admin_page_content'] = 'clickable trigger-checkin checkin-icons checkedin-status-' . $new_status;
677
+		$this->_template_args['admin_page_content'] = 'clickable trigger-checkin checkin-icons checkedin-status-'.$new_status;
678 678
 		$this->_template_args['success'] = TRUE;
679 679
 		$this->_return_json();
680 680
 	}
@@ -694,32 +694,32 @@  discard block
 block discarded – undo
694 694
 		//first let's get the query args out of the way for the redirect
695 695
 		$query_args = array(
696 696
 			'action' => 'event_registrations',
697
-			'event_id' => isset( $this->_req_data['event_id'] ) ? $this->_req_data['event_id'] : NULL,
698
-			'DTT_ID' => isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : NULL
697
+			'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : NULL,
698
+			'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : NULL
699 699
 			);
700 700
 		$new_status = FALSE;
701 701
 
702 702
 		// bulk action check in toggle
703
-		if ( ! empty( $this->_req_data['checkbox'] ) && is_array( $this->_req_data['checkbox'] )) {
703
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
704 704
 			// cycle thru checkboxes
705
-			while ( list( $REG_ID, $value ) = each($this->_req_data['checkbox'])) {
706
-				$DTT_ID = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : NULL;
705
+			while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
706
+				$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : NULL;
707 707
 				$new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
708 708
 			}
709 709
 
710
-		} elseif ( isset( $this->_req_data['_regid'] ) ) {
710
+		} elseif (isset($this->_req_data['_regid'])) {
711 711
 			//coming from ajax request
712
-			$DTT_ID = isset( $this->_req_data['dttid'] ) ? $this->_req_data['dttid'] : NULL;
712
+			$DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : NULL;
713 713
 			$query_args['DTT_ID'] = $DTT_ID;
714 714
 			$new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
715 715
 		} else {
716
-			EE_Error::add_error(__('Missing some required data to toggle the Check-in', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__  );
716
+			EE_Error::add_error(__('Missing some required data to toggle the Check-in', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
717 717
 		}
718 718
 
719
-		if ( defined('DOING_AJAX' ) )
719
+		if (defined('DOING_AJAX'))
720 720
 			return $new_status;
721 721
 
722
-		$this->_redirect_after_action( FALSE,'', '', $query_args, TRUE );
722
+		$this->_redirect_after_action(FALSE, '', '', $query_args, TRUE);
723 723
 
724 724
 	}
725 725
 
@@ -735,11 +735,11 @@  discard block
 block discarded – undo
735 735
 	 */
736 736
 	private function _toggle_checkin($REG_ID, $DTT_ID) {
737 737
 		$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
738
-		$new_status = $REG->toggle_checkin_status( $DTT_ID );
739
-		if ( $new_status !== FALSE ) {
740
-			EE_Error::add_success($REG->get_checkin_msg($DTT_ID) );
738
+		$new_status = $REG->toggle_checkin_status($DTT_ID);
739
+		if ($new_status !== FALSE) {
740
+			EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
741 741
 		} else {
742
-			EE_Error::add_error($REG->get_checkin_msg($DTT_ID, TRUE), __FILE__, __FUNCTION__, __LINE__ );
742
+			EE_Error::add_error($REG->get_checkin_msg($DTT_ID, TRUE), __FILE__, __FUNCTION__, __LINE__);
743 743
 			$new_status = FALSE;
744 744
 		}
745 745
 		return $new_status;
@@ -755,28 +755,28 @@  discard block
 block discarded – undo
755 755
 	protected function _delete_checkin_rows() {
756 756
 		$query_args = array(
757 757
 			'action' => 'registration_checkins',
758
-			'DTT_ID' => isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : 0,
759
-			'_REGID' => isset( $this->_req_data['_REGID'] ) ? $this->_req_data['_REGID'] : 0
758
+			'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
759
+			'_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0
760 760
 			);
761
-		if ( !empty( $this->_req_data['checkbox'] ) && is_array( $this->_req_data['checkbox'] ) ) {
762
-			while ( list( $CHK_ID, $value ) = each( $this->_req_data['checkbox'] ) ) {
761
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
762
+			while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
763 763
 				$errors = 0;
764
-				if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID ) ) {
764
+				if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
765 765
 					$errors++;
766 766
 				}
767 767
 			}
768 768
 		} else {
769
-			EE_Error::add_error(__('So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
770
-			$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
769
+			EE_Error::add_error(__('So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
770
+			$this->_redirect_after_action(FALSE, '', '', $query_args, TRUE);
771 771
 		}
772 772
 
773
-		if ( $errors > 0 ) {
774
-			EE_Error::add_error( sprintf( __('There were %d records that did not delete successfully', 'event_espresso'), $errors ), __FILE__, __FUNCTION__, __LINE__ );
773
+		if ($errors > 0) {
774
+			EE_Error::add_error(sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), __FILE__, __FUNCTION__, __LINE__);
775 775
 		} else {
776
-			EE_Error::add_success( __('Records were successfully deleted', 'event_espresso') );
776
+			EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
777 777
 		}
778 778
 
779
-		$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
779
+		$this->_redirect_after_action(FALSE, '', '', $query_args, TRUE);
780 780
 	}
781 781
 
782 782
 
@@ -788,20 +788,20 @@  discard block
 block discarded – undo
788 788
 	protected function _delete_checkin_row() {
789 789
 		$query_args = array(
790 790
 			'action' => 'registration_checkins',
791
-			'DTT_ID' => isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : 0,
792
-			'_REGID' => isset( $this->_req_data['_REGID'] ) ? $this->_req_data['_REGID'] : 0
791
+			'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
792
+			'_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0
793 793
 			);
794 794
 
795
-		if ( !empty( $this->_req_data['CHK_ID'] ) ) {
796
-			if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'] ) ) {
797
-				EE_Error::add_error(__('Something went wrong and this check-in record was not deleted', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
795
+		if ( ! empty($this->_req_data['CHK_ID'])) {
796
+			if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
797
+				EE_Error::add_error(__('Something went wrong and this check-in record was not deleted', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
798 798
 			} else {
799
-				EE_Error::add_success( __('Check-In record successfully deleted', 'event_espresso') );
799
+				EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
800 800
 			}
801 801
 		} else {
802
-			EE_Error::add_error(__('In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
802
+			EE_Error::add_error(__('In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
803 803
 		}
804
-		$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
804
+		$this->_redirect_after_action(FALSE, '', '', $query_args, TRUE);
805 805
 	}
806 806
 
807 807
 
@@ -814,8 +814,8 @@  discard block
 block discarded – undo
814 814
 	*		@return void
815 815
 	*/
816 816
 	protected function _event_registrations_list_table() {
817
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
818
-		$this->_admin_page_title .= isset( $this->_req_data['event_id'] ) ? $this->get_action_link_or_button('new_registration', 'add-registrant', array('event_id' => $this->_req_data['event_id']), 'add-new-h2') : '';
817
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
818
+		$this->_admin_page_title .= isset($this->_req_data['event_id']) ? $this->get_action_link_or_button('new_registration', 'add-registrant', array('event_id' => $this->_req_data['event_id']), 'add-new-h2') : '';
819 819
 
820 820
 		$legend_items = array(
821 821
 			'star-icon' => array(
@@ -839,31 +839,31 @@  discard block
 block discarded – undo
839 839
 				'desc' => __('View All Check-in Records for this Registrant', 'event_espresso')
840 840
 				),
841 841
 			'approved_status' => array(
842
-				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
843
-				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_approved, FALSE, 'sentence' )
842
+				'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
843
+				'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, FALSE, 'sentence')
844 844
 				),
845 845
             'cancelled_status' => array(
846
-				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
847
-				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_cancelled, FALSE, 'sentence' )
846
+				'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
847
+				'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, FALSE, 'sentence')
848 848
 				),
849 849
             'declined_status' => array(
850
-				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
851
-				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_declined, FALSE, 'sentence' )
850
+				'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
851
+				'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, FALSE, 'sentence')
852 852
 				),
853 853
 			'not_approved' => array(
854
-				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
855
-				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_not_approved, FALSE, 'sentence' )
854
+				'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
855
+				'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, FALSE, 'sentence')
856 856
 				),
857 857
 			'pending_status' => array(
858
-				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
859
-				'desc' => EEH_Template::pretty_status( EEM_Registration::status_id_pending_payment, FALSE, 'sentence' )
858
+				'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
859
+				'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, FALSE, 'sentence')
860 860
 				)/**/
861 861
 			);
862
-		$this->_template_args['after_list_table'] = $this->_display_legend( $legend_items );
862
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
863 863
 
864
-		$event_id = isset( $this->_req_data['event_id'] ) ? $this->_req_data['event_id'] : null;
865
-		$this->_template_args['before_list_table'] = !empty( $event_id ) ? '<h2>' . sprintf(__('Viewing Registrations for Event: %s', 'event_espresso'), EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') ) . '</h2>' : '';
866
-		$this->_template_args['list_table_hidden_fields'] = !empty( $event_id ) ? '<input type="hidden" name="event_id" value="' . $event_id . '">' : '';
864
+		$event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
865
+		$this->_template_args['before_list_table'] = ! empty($event_id) ? '<h2>'.sprintf(__('Viewing Registrations for Event: %s', 'event_espresso'), EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')).'</h2>' : '';
866
+		$this->_template_args['list_table_hidden_fields'] = ! empty($event_id) ? '<input type="hidden" name="event_id" value="'.$event_id.'">' : '';
867 867
 
868 868
 		$this->display_admin_list_table_page_with_no_sidebar();
869 869
 	}
@@ -877,15 +877,15 @@  discard block
 block discarded – undo
877 877
 	*		@access public
878 878
 	*		@return array
879 879
 	*/
880
-	public function get_event_attendees( $per_page = 10, $count = FALSE, $trash = FALSE, $orderby = '' ) {
880
+	public function get_event_attendees($per_page = 10, $count = FALSE, $trash = FALSE, $orderby = '') {
881 881
 
882
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
883
-		require_once(EE_MODELS . 'EEM_Attendee.model.php');
882
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
883
+		require_once(EE_MODELS.'EEM_Attendee.model.php');
884 884
 		//$ATT_MDL = EEM_Attendee::instance();
885 885
 
886
-		$EVT_ID = isset($this->_req_data['event_id']) ? absint( $this->_req_data['event_id'] ) : FALSE;
887
-		$CAT_ID = isset($this->_req_data['category_id']) ? absint( $this->_req_data['category_id'] ) : FALSE;
888
-		$DTT_ID = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : NULL;
886
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : FALSE;
887
+		$CAT_ID = isset($this->_req_data['category_id']) ? absint($this->_req_data['category_id']) : FALSE;
888
+		$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : NULL;
889 889
 
890 890
 		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
891 891
 
@@ -898,94 +898,94 @@  discard block
 block discarded – undo
898 898
 //				$orderby = 'reg.REG_final_price';
899 899
 		}
900 900
 
901
-		$sort = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'ASC';
901
+		$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
902 902
 
903
-		$current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1;
904
-		$per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page;
903
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
904
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
905 905
 
906 906
 
907
-		$offset = ($current_page-1)*$per_page;
908
-		$limit = $count ? NULL : array( $offset, $per_page );
909
-		$query_params = array(array('Event.status'=>array('IN',  array_keys(EEM_Event::instance()->get_status_array()))));
910
-		if ($EVT_ID){
911
-			$query_params[0]['EVT_ID']=$EVT_ID;
907
+		$offset = ($current_page - 1) * $per_page;
908
+		$limit = $count ? NULL : array($offset, $per_page);
909
+		$query_params = array(array('Event.status'=>array('IN', array_keys(EEM_Event::instance()->get_status_array()))));
910
+		if ($EVT_ID) {
911
+			$query_params[0]['EVT_ID'] = $EVT_ID;
912 912
 		}
913
-		if($CAT_ID){
913
+		if ($CAT_ID) {
914 914
 			throw new EE_Error("You specified a Category Id for this query. Thats odd because we are now using terms and taxonomies. So did you mean the term taxonomy id o rthe term id?");
915 915
 		}
916 916
 
917 917
 		//if DTT is included we do multiple datetimes.
918
-		if ( $DTT_ID ) {
918
+		if ($DTT_ID) {
919 919
 			$query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID;
920 920
 		}
921 921
 
922 922
 		//make sure we only have default where on the current regs
923 923
 		$query_params['default_where_conditions'] = 'this_model_only';
924 924
 
925
-		$status_ids_array = apply_filters( 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', array( EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved ) );
925
+		$status_ids_array = apply_filters('FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved));
926 926
 
927
-		$query_params[0]['STS_ID']= array('IN', $status_ids_array );
927
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
928 928
 
929
-		if($trash){
930
-			$query_params[0]['Attendee.status']=  EEM_CPT_Base::post_status_trashed;
929
+		if ($trash) {
930
+			$query_params[0]['Attendee.status'] = EEM_CPT_Base::post_status_trashed;
931 931
 		}
932 932
 
933
-		if ( isset( $this->_req_data['s'] ) ) {
934
-			$sstr = '%' . $this->_req_data['s'] . '%';
933
+		if (isset($this->_req_data['s'])) {
934
+			$sstr = '%'.$this->_req_data['s'].'%';
935 935
 			$query_params[0]['OR'] = array(
936
-				'Event.EVT_name' => array( 'LIKE', $sstr),
937
-				'Event.EVT_desc' => array( 'LIKE', $sstr ),
938
-				'Event.EVT_short_desc' => array( 'LIKE' , $sstr ),
939
-				'Attendee.ATT_fname' => array( 'LIKE', $sstr ),
940
-				'Attendee.ATT_lname' => array( 'LIKE', $sstr ),
941
-				'Attendee.ATT_short_bio' => array( 'LIKE', $sstr ),
942
-				'Attendee.ATT_email' => array('LIKE', $sstr ),
943
-				'Attendee.ATT_address' => array( 'LIKE', $sstr ),
944
-				'Attendee.ATT_address2' => array( 'LIKE', $sstr ),
945
-				'Attendee.ATT_city' => array( 'LIKE', $sstr ),
946
-				'REG_final_price' => array( 'LIKE', $sstr ),
947
-				'REG_code' => array( 'LIKE', $sstr ),
948
-				'REG_count' => array( 'LIKE' , $sstr ),
949
-				'REG_group_size' => array( 'LIKE' , $sstr ),
950
-				'Ticket.TKT_name' => array( 'LIKE', $sstr ),
951
-				'Ticket.TKT_description' => array( 'LIKE', $sstr )
936
+				'Event.EVT_name' => array('LIKE', $sstr),
937
+				'Event.EVT_desc' => array('LIKE', $sstr),
938
+				'Event.EVT_short_desc' => array('LIKE', $sstr),
939
+				'Attendee.ATT_fname' => array('LIKE', $sstr),
940
+				'Attendee.ATT_lname' => array('LIKE', $sstr),
941
+				'Attendee.ATT_short_bio' => array('LIKE', $sstr),
942
+				'Attendee.ATT_email' => array('LIKE', $sstr),
943
+				'Attendee.ATT_address' => array('LIKE', $sstr),
944
+				'Attendee.ATT_address2' => array('LIKE', $sstr),
945
+				'Attendee.ATT_city' => array('LIKE', $sstr),
946
+				'REG_final_price' => array('LIKE', $sstr),
947
+				'REG_code' => array('LIKE', $sstr),
948
+				'REG_count' => array('LIKE', $sstr),
949
+				'REG_group_size' => array('LIKE', $sstr),
950
+				'Ticket.TKT_name' => array('LIKE', $sstr),
951
+				'Ticket.TKT_description' => array('LIKE', $sstr)
952 952
 				);
953 953
 		}
954 954
 
955 955
 		$query_params['order_by'][$orderby] = $sort;
956 956
 		$query_params['limit'] = $limit;
957
-		$query_params['force_join'] = array('Attendee');//force join to attendee model so that it gets cached, because we're going to need the attendee for each registration
958
-		if($count){
959
-			$registrations = EEM_Registration::instance()->count(array($query_params[0], 'default_where_conditions' => 'this_model_only' ));
960
-		}else{
957
+		$query_params['force_join'] = array('Attendee'); //force join to attendee model so that it gets cached, because we're going to need the attendee for each registration
958
+		if ($count) {
959
+			$registrations = EEM_Registration::instance()->count(array($query_params[0], 'default_where_conditions' => 'this_model_only'));
960
+		} else {
961 961
 			$registrations = EEM_Registration::instance()->get_all($query_params);
962 962
 
963 963
 
964 964
 	//		$registrations = EEM_Registration::instance();
965 965
 	//		$all_attendees = EEM_Attendee::instance()->get_event_attendees( $EVT_ID, $CAT_ID, $reg_status, $trash, $orderby, $sort, $limit, $output );
966
-			if ( isset( $registrations[0] ) && $registrations[0] instanceof EE_Registration ) {
966
+			if (isset($registrations[0]) && $registrations[0] instanceof EE_Registration) {
967 967
 				//EEH_Debug_Tools::printr( $all_attendees[0], '$all_attendees[0]  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
968 968
 				// name
969 969
 				$first_registration = $registrations[0];
970 970
 				$event_obj = $first_registration->event_obj();
971
-				if($event_obj){
971
+				if ($event_obj) {
972 972
 					$event_name = $first_registration->event_obj()->name();
973
-					$event_date = 'TODO: we need to get date from earliest price date or should this be the actual event date?';//$first_registration->date_obj()->reg_start_date_and_time('l F j, Y,', ' g:i:s a');// isset( $registrations[0]->DTT_EVT_start ) ? date( 'l F j, Y,    g:i:s a', $registrations[0]->DTT_EVT_start ) : '';
973
+					$event_date = 'TODO: we need to get date from earliest price date or should this be the actual event date?'; //$first_registration->date_obj()->reg_start_date_and_time('l F j, Y,', ' g:i:s a');// isset( $registrations[0]->DTT_EVT_start ) ? date( 'l F j, Y,    g:i:s a', $registrations[0]->DTT_EVT_start ) : '';
974 974
 					// edit event link
975
-					if ( $event_name != '' ) {
976
-						$edit_event_url = self::add_query_args_and_nonce( array( 'action'=>'edit_event', 'EVT_ID'=>$EVT_ID ), EVENTS_ADMIN_URL );
977
-						$edit_event_lnk = '<a href="'.$edit_event_url.'" title="' . esc_attr__( 'Edit ', 'event_espresso' ) . $event_name . '">' . __( 'Edit Event', 'event_espresso' ) . '</a>';
978
-						$event_name .= ' <span class="admin-page-header-edit-lnk not-bold">' . $edit_event_lnk . '</span>' ;
975
+					if ($event_name != '') {
976
+						$edit_event_url = self::add_query_args_and_nonce(array('action'=>'edit_event', 'EVT_ID'=>$EVT_ID), EVENTS_ADMIN_URL);
977
+						$edit_event_lnk = '<a href="'.$edit_event_url.'" title="'.esc_attr__('Edit ', 'event_espresso').$event_name.'">'.__('Edit Event', 'event_espresso').'</a>';
978
+						$event_name .= ' <span class="admin-page-header-edit-lnk not-bold">'.$edit_event_lnk.'</span>';
979 979
 					}
980 980
 
981
-					$back_2_reg_url = self::add_query_args_and_nonce( array( 'action'=>'default' ), REG_ADMIN_URL );
982
-					$back_2_reg_lnk = '<a href="'.$back_2_reg_url.'" title="' . esc_attr__( 'click to return to viewing all registrations ', 'event_espresso' ) . '">&laquo; ' . __( 'Back to All Registrations', 'event_espresso' ) . '</a>';
981
+					$back_2_reg_url = self::add_query_args_and_nonce(array('action'=>'default'), REG_ADMIN_URL);
982
+					$back_2_reg_lnk = '<a href="'.$back_2_reg_url.'" title="'.esc_attr__('click to return to viewing all registrations ', 'event_espresso').'">&laquo; '.__('Back to All Registrations', 'event_espresso').'</a>';
983 983
 
984 984
 					$this->_template_args['before_admin_page_content'] = '
985 985
 				<div id="admin-page-header">
986
-					<h1><span class="small-text not-bold">'.__( 'Event: ', 'event_espresso' ).'</span>'. $event_name .'</h1>
987
-					<h3><span class="small-text not-bold">'.__( 'Date: ', 'event_espresso' ). '</span>'. $event_date .'</h3>
988
-					<span class="admin-page-header-go-back-lnk not-bold">' . $back_2_reg_lnk . '</span>
986
+					<h1><span class="small-text not-bold">'.__('Event: ', 'event_espresso').'</span>'.$event_name.'</h1>
987
+					<h3><span class="small-text not-bold">'.__('Date: ', 'event_espresso').'</span>'.$event_date.'</h3>
988
+					<span class="admin-page-header-go-back-lnk not-bold">' . $back_2_reg_lnk.'</span>
989 989
 				</div>
990 990
 				';
991 991
 				}
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Event.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -175,7 +175,7 @@
 block discarded – undo
175 175
 	 * @param array $wpdb_row
176 176
 	 * @param \WP_REST_Request $request
177 177
 	 * @param Base $controller
178
-	 * @return int|null if permission denied
178
+	 * @return integer if permission denied
179 179
 	 */
180 180
 	public static function registrations_checked_in_count( $wpdb_row, $request, $controller ){
181 181
 		if( ! is_array( $wpdb_row ) || ! isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) {
Please login to merge, or discard this patch.
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
  * @since		 	   $VID:$
16 16
  *
17 17
  */
18
-if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
19
-	exit( 'No direct script access allowed' );
18
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
19
+	exit('No direct script access allowed');
20 20
 }
21 21
 
22 22
 class Event extends Calculations_Base {
@@ -32,20 +32,20 @@  discard block
 block discarded – undo
32 32
 	 * @return int
33 33
 	 * @throws \EE_Error
34 34
 	 */
35
-	public static function optimum_sales_at_start( $wpdb_row, $request, $controller ){
36
-		if( is_array( $wpdb_row ) && isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) {
37
-			$event_obj = \EEM_Event::instance()->get_one_by_ID( $wpdb_row[ 'Event_CPT.ID' ] );
35
+	public static function optimum_sales_at_start($wpdb_row, $request, $controller) {
36
+		if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID'])) {
37
+			$event_obj = \EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
38 38
 		} else {
39 39
 			$event_obj = null;
40 40
 		}
41
-		if( $event_obj instanceof \EE_Event ) {
42
-			return $event_obj->total_available_spaces( true );
41
+		if ($event_obj instanceof \EE_Event) {
42
+			return $event_obj->total_available_spaces(true);
43 43
 		} else {
44 44
 			throw new \EE_Error(
45 45
 				sprintf(
46
-					__( 'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso' ),
47
-					$wpdb_row[ 'Event_CPT.ID' ],
48
-					print_r( $wpdb_row, true )
46
+					__('Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso'),
47
+					$wpdb_row['Event_CPT.ID'],
48
+					print_r($wpdb_row, true)
49 49
 				)
50 50
 			);
51 51
 		}
@@ -64,20 +64,20 @@  discard block
 block discarded – undo
64 64
 	 * @return int
65 65
 	 * @throws \EE_Error
66 66
 	 */
67
-	public static function optimum_sales_now( $wpdb_row, $request, $controller ){
68
-		if( is_array( $wpdb_row ) && isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) {
69
-			$event_obj = \EEM_Event::instance()->get_one_by_ID( $wpdb_row[ 'Event_CPT.ID' ] );
67
+	public static function optimum_sales_now($wpdb_row, $request, $controller) {
68
+		if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID'])) {
69
+			$event_obj = \EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
70 70
 		} else {
71 71
 			$event_obj = null;
72 72
 		}
73
-		if( $event_obj instanceof \EE_Event ) {
74
-			return $event_obj->total_available_spaces( false );
73
+		if ($event_obj instanceof \EE_Event) {
74
+			return $event_obj->total_available_spaces(false);
75 75
 		} else {
76 76
 			throw new \EE_Error(
77 77
 				sprintf(
78
-					__( 'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso' ),
79
-					$wpdb_row[ 'Event_CPT.ID' ],
80
-					print_r( $wpdb_row, true )
78
+					__('Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso'),
79
+					$wpdb_row['Event_CPT.ID'],
80
+					print_r($wpdb_row, true)
81 81
 				)
82 82
 			);
83 83
 		}
@@ -95,20 +95,20 @@  discard block
 block discarded – undo
95 95
 	 * @return int
96 96
 	 * @throws \EE_Error
97 97
 	 */
98
-	public static function spaces_remaining( $wpdb_row, $request, $controller ){
99
-		if( is_array( $wpdb_row ) && isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) {
100
-			$event_obj = \EEM_Event::instance()->get_one_by_ID( $wpdb_row[ 'Event_CPT.ID' ] );
98
+	public static function spaces_remaining($wpdb_row, $request, $controller) {
99
+		if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID'])) {
100
+			$event_obj = \EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
101 101
 		} else {
102 102
 			$event_obj = null;
103 103
 		}
104
-		if( $event_obj instanceof \EE_Event ) {
104
+		if ($event_obj instanceof \EE_Event) {
105 105
 			return $event_obj->spaces_remaining_for_sale();
106 106
 		} else {
107 107
 			throw new \EE_Error(
108 108
 				sprintf(
109
-					__( 'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso' ),
110
-					$wpdb_row[ 'Event_CPT.ID' ],
111
-					print_r( $wpdb_row, true )
109
+					__('Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso'),
110
+					$wpdb_row['Event_CPT.ID'],
111
+					print_r($wpdb_row, true)
112 112
 				)
113 113
 			);
114 114
 		}
@@ -126,19 +126,19 @@  discard block
 block discarded – undo
126 126
 	 * @return int
127 127
 	 * @throws \EE_Error
128 128
 	 */
129
-	public static function spots_taken( $wpdb_row, $request, $controller ){
130
-		if( ! is_array( $wpdb_row ) || ! isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) {
129
+	public static function spots_taken($wpdb_row, $request, $controller) {
130
+		if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) {
131 131
 			throw new \EE_Error(
132 132
 				sprintf(
133
-					__( 'Cannot calculate spots_taken because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso' ),
134
-					print_r( $wpdb_row, true )
133
+					__('Cannot calculate spots_taken because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso'),
134
+					print_r($wpdb_row, true)
135 135
 				)
136 136
 			);
137 137
 		}
138 138
 		return \EEM_Registration::instance()->count(
139 139
 			array(
140 140
 				array(
141
-					'EVT_ID' => $wpdb_row[ 'Event_CPT.ID' ],
141
+					'EVT_ID' => $wpdb_row['Event_CPT.ID'],
142 142
 					'STS_ID' => \EEM_Registration::status_id_approved
143 143
 				)
144 144
 			),
@@ -160,20 +160,20 @@  discard block
 block discarded – undo
160 160
 	 * @throws \EE_Error
161 161
 	 * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception
162 162
 	 */
163
-	public static function spots_taken_pending_payment( $wpdb_row, $request, $controller ){
164
-		if( ! is_array( $wpdb_row ) || ! isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) {
163
+	public static function spots_taken_pending_payment($wpdb_row, $request, $controller) {
164
+		if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) {
165 165
 			throw new \EE_Error(
166 166
 				sprintf(
167
-					__( 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso' ),
168
-					print_r( $wpdb_row, true )
167
+					__('Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso'),
168
+					print_r($wpdb_row, true)
169 169
 				)
170 170
 			);
171 171
 		}
172
-		self::_verify_current_user_can( 'ee_read_registrations', 'spots_taken_pending_payment' );
172
+		self::_verify_current_user_can('ee_read_registrations', 'spots_taken_pending_payment');
173 173
 		return \EEM_Registration::instance()->count(
174 174
 			array(
175 175
 				array(
176
-					'EVT_ID' => $wpdb_row[ 'Event_CPT.ID' ],
176
+					'EVT_ID' => $wpdb_row['Event_CPT.ID'],
177 177
 					'STS_ID' => \EEM_Registration::status_id_pending_payment
178 178
 				)
179 179
 			),
@@ -195,17 +195,17 @@  discard block
 block discarded – undo
195 195
 	 * @throws \EE_Error
196 196
 	 * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception
197 197
 	 */
198
-	public static function registrations_checked_in_count( $wpdb_row, $request, $controller ){
199
-		if( ! is_array( $wpdb_row ) || ! isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) {
198
+	public static function registrations_checked_in_count($wpdb_row, $request, $controller) {
199
+		if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) {
200 200
 			throw new \EE_Error(
201 201
 				sprintf(
202
-					__( 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso' ),
203
-					print_r( $wpdb_row, true )
202
+					__('Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso'),
203
+					print_r($wpdb_row, true)
204 204
 				)
205 205
 			);
206 206
 		}
207
-		self::_verify_current_user_can( 'ee_read_checkins', 'registrations_checked_in_count' );
208
-		return \EEM_Registration::instance()->count_registrations_checked_into_event( $wpdb_row[ 'Event_CPT.ID' ], true );
207
+		self::_verify_current_user_can('ee_read_checkins', 'registrations_checked_in_count');
208
+		return \EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true);
209 209
 	}
210 210
 
211 211
 
@@ -221,17 +221,17 @@  discard block
 block discarded – undo
221 221
 	 * @throws \EE_Error
222 222
 	 * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception
223 223
 	 */
224
-	public static function registrations_checked_out_count( $wpdb_row, $request, $controller ){
225
-		if( ! is_array( $wpdb_row ) || ! isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) {
224
+	public static function registrations_checked_out_count($wpdb_row, $request, $controller) {
225
+		if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) {
226 226
 			throw new \EE_Error(
227 227
 				sprintf(
228
-					__( 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso' ),
229
-					print_r( $wpdb_row, true )
228
+					__('Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso'),
229
+					print_r($wpdb_row, true)
230 230
 				)
231 231
 			);
232 232
 		}
233
-		self::_verify_current_user_can( 'ee_read_checkins', 'registrations_checked_out_count' );
234
-		return \EEM_Registration::instance()->count_registrations_checked_into_event( $wpdb_row[ 'Event_CPT.ID' ], false );
233
+		self::_verify_current_user_can('ee_read_checkins', 'registrations_checked_out_count');
234
+		return \EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false);
235 235
 	}
236 236
 
237 237
 	/**
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
 	 * @param Base $controller
242 242
 	 * @return array
243 243
 	 */
244
-	public static function image_thumbnail( $wpdb_row, $request, $controller ) {
245
-		return self::_calculate_image_data($wpdb_row[ 'Event_CPT.ID' ], 'thumbnail' );
244
+	public static function image_thumbnail($wpdb_row, $request, $controller) {
245
+		return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'thumbnail');
246 246
 	}
247 247
 
248 248
 	/**
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 	 * @param Base $controller
253 253
 	 * @return array
254 254
 	 */
255
-	public static function image_medium( $wpdb_row, $request, $controller ) {
256
-		return self::_calculate_image_data($wpdb_row[ 'Event_CPT.ID' ], 'medium' );
255
+	public static function image_medium($wpdb_row, $request, $controller) {
256
+		return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'medium');
257 257
 	}
258 258
 
259 259
 	/**
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 	 * @param Base $controller
264 264
 	 * @return array
265 265
 	 */
266
-	public static function image_medium_large( $wpdb_row, $request, $controller ) {
267
-		return self::_calculate_image_data($wpdb_row[ 'Event_CPT.ID' ], 'medium_large' );
266
+	public static function image_medium_large($wpdb_row, $request, $controller) {
267
+		return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'medium_large');
268 268
 	}
269 269
 
270 270
 	/**
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
 	 * @param Base $controller
275 275
 	 * @return array
276 276
 	 */
277
-	public static function image_large( $wpdb_row, $request, $controller ) {
278
-		return self::_calculate_image_data($wpdb_row[ 'Event_CPT.ID' ], 'large' );
277
+	public static function image_large($wpdb_row, $request, $controller) {
278
+		return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'large');
279 279
 	}
280 280
 
281 281
 	/**
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
 	 * @param Base $controller
286 286
 	 * @return array
287 287
 	 */
288
-	public static function image_post_thumbnail( $wpdb_row, $request, $controller ) {
289
-		return self::_calculate_image_data($wpdb_row[ 'Event_CPT.ID' ], 'post-thumbnail' );
288
+	public static function image_post_thumbnail($wpdb_row, $request, $controller) {
289
+		return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'post-thumbnail');
290 290
 	}
291 291
 
292 292
 	/**
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
 	 * @param Base $controller
297 297
 	 * @return array
298 298
 	 */
299
-	public static function image_full( $wpdb_row, $request, $controller ) {
300
-		return self::_calculate_image_data($wpdb_row[ 'Event_CPT.ID' ], 'full' );
299
+	public static function image_full($wpdb_row, $request, $controller) {
300
+		return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'full');
301 301
 	}
302 302
 
303 303
 	/**
@@ -307,21 +307,21 @@  discard block
 block discarded – undo
307 307
 	 * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full
308 308
 	 * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original'
309 309
 	 */
310
-	protected static function _calculate_image_data( $EVT_ID, $image_size ) {
311
-		$attachment_id = get_post_thumbnail_id( $EVT_ID );
312
-		$data = wp_get_attachment_image_src( $attachment_id, $image_size );
313
-		if( ! $data ) {
310
+	protected static function _calculate_image_data($EVT_ID, $image_size) {
311
+		$attachment_id = get_post_thumbnail_id($EVT_ID);
312
+		$data = wp_get_attachment_image_src($attachment_id, $image_size);
313
+		if ( ! $data) {
314 314
 			return false;
315 315
 		}
316
-		if( isset( $data[ 3] ) ) {
317
-			$generated = $data[ 3 ];
316
+		if (isset($data[3])) {
317
+			$generated = $data[3];
318 318
 		} else {
319 319
 			$generated = true;
320 320
 		}
321 321
 		return array(
322
-			'url' => $data[ 0 ],
323
-			'width' => $data[ 1 ],
324
-			'height' => $data[ 2 ],
322
+			'url' => $data[0],
323
+			'width' => $data[1],
324
+			'height' => $data[2],
325 325
 			'generated' => $generated
326 326
 		);
327 327
 	}
Please login to merge, or discard this patch.
core/libraries/rest_api/Model_Data_Translator.php 4 patches
Doc Comments   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	/**
56 56
 	 * Prepares incoming data from the json or $_REQUEST parameters for the models'
57 57
 	 * "$query_params". 
58
-	 * @param EE_Model_Field_Base $field_obj
58
+	 * @param \EE_Model_Field_Base $field_obj
59 59
 	 * @param mixed $original_value
60 60
 	 * @param string $requested_version
61 61
 	 * @return mixed
@@ -77,6 +77,7 @@  discard block
 block discarded – undo
77 77
 	* Prepares a field's value for display in the API
78 78
 	* @param \EE_Model_Field_Base $field_obj
79 79
 	* @param mixed $original_value
80
+	* @param string $requested_version
80 81
 	* @return mixed
81 82
 	*/
82 83
    public static function prepare_field_value_for_json( $field_obj, $original_value, $requested_version ) {
@@ -131,6 +132,9 @@  discard block
 block discarded – undo
131 132
 		return $query_param_for_models;
132 133
 	}
133 134
 	
135
+	/**
136
+	 * @return string
137
+	 */
134 138
 	public static function remove_stars_and_anything_after_from_condition_query_param_key( $condition_query_param_key ) {
135 139
 		$pos_of_star = strpos($condition_query_param_key, '*');
136 140
 		if($pos_of_star === FALSE){
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
  */
22 22
 	
23 23
 	
24
-if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
25
-	exit( 'No direct script access allowed' );
24
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
25
+	exit('No direct script access allowed');
26 26
 }
27 27
 
28 28
 class Model_Data_Translator {
@@ -40,14 +40,14 @@  discard block
 block discarded – undo
40 40
 	 * @param string  $requested_version
41 41
 	 * @return mixed
42 42
 	 */
43
-	public static function prepare_field_values_from_json( $field_obj, $original_value_maybe_array, $requested_version ) {
44
-		if( is_array( $original_value_maybe_array ) ) {
43
+	public static function prepare_field_values_from_json($field_obj, $original_value_maybe_array, $requested_version) {
44
+		if (is_array($original_value_maybe_array)) {
45 45
 			$new_value_maybe_array = array();
46
-			foreach( $original_value_maybe_array as $array_key => $array_item ) {
47
-				$new_value_maybe_array[ $array_key ] = self::prepare_field_value_from_json( $field_obj, $array_item, $requested_version );
46
+			foreach ($original_value_maybe_array as $array_key => $array_item) {
47
+				$new_value_maybe_array[$array_key] = self::prepare_field_value_from_json($field_obj, $array_item, $requested_version);
48 48
 			}
49 49
 		} else {
50
-			$new_value_maybe_array = self::prepare_field_value_from_json( $field_obj, $original_value_maybe_array, $requested_version );
50
+			$new_value_maybe_array = self::prepare_field_value_from_json($field_obj, $original_value_maybe_array, $requested_version);
51 51
 		}
52 52
 		return $new_value_maybe_array;
53 53
 	}
@@ -60,13 +60,13 @@  discard block
 block discarded – undo
60 60
 	 * @param string $requested_version
61 61
 	 * @return mixed
62 62
 	 */
63
-	public static function prepare_field_value_from_json( $field_obj, $original_value, $requested_version ) {
63
+	public static function prepare_field_value_from_json($field_obj, $original_value, $requested_version) {
64 64
 		$new_value = null;
65
-		if( $field_obj instanceof \EE_Infinite_Integer_Field 
66
-			&& in_array( $original_value, array( null, '' ), true ) ) {
65
+		if ($field_obj instanceof \EE_Infinite_Integer_Field 
66
+			&& in_array($original_value, array(null, ''), true)) {
67 67
 			$new_value = EE_INF;
68
-		} elseif( $field_obj instanceof \EE_Datetime_Field ) {
69
-			$new_value = rest_parse_date( $original_value );
68
+		} elseif ($field_obj instanceof \EE_Datetime_Field) {
69
+			$new_value = rest_parse_date($original_value);
70 70
 		} else {
71 71
 			$new_value = $original_value;
72 72
 		}
@@ -79,17 +79,17 @@  discard block
 block discarded – undo
79 79
 	* @param mixed $original_value
80 80
 	* @return mixed
81 81
 	*/
82
-   public static function prepare_field_value_for_json( $field_obj, $original_value, $requested_version ) {
83
-		if( $original_value === EE_INF ) {
82
+   public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version) {
83
+		if ($original_value === EE_INF) {
84 84
 			$new_value = self::ee_inf_in_rest;
85
-		} elseif( $field_obj instanceof \EE_Datetime_Field &&
86
-			$original_value instanceof \DateTime ) {
87
-			$new_value = $original_value->format( 'c' );
88
-			$new_value = mysql_to_rfc3339( $new_value );
85
+		} elseif ($field_obj instanceof \EE_Datetime_Field &&
86
+			$original_value instanceof \DateTime) {
87
+			$new_value = $original_value->format('c');
88
+			$new_value = mysql_to_rfc3339($new_value);
89 89
 		} else {
90 90
 			$new_value = $original_value;
91 91
 		}
92
-		return apply_filters( 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', 
92
+		return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', 
93 93
 			$new_value,
94 94
 			$field_obj,
95 95
 			$original_value,
@@ -105,37 +105,37 @@  discard block
 block discarded – undo
105 105
 	 * @param string $requested_version
106 106
 	 * @return array
107 107
 	 */
108
-	public static function prepare_conditions_query_params_for_models( $inputted_query_params_of_this_type, \EEM_Base $model, $requested_version ) {
108
+	public static function prepare_conditions_query_params_for_models($inputted_query_params_of_this_type, \EEM_Base $model, $requested_version) {
109 109
 		$query_param_for_models = array();
110
-		foreach( $inputted_query_params_of_this_type as $query_param_key => $query_param_value ) {
110
+		foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
111 111
 			$field = self::deduce_field_from_query_param( 
112
-				self::remove_stars_and_anything_after_from_condition_query_param_key( $query_param_key ), 
112
+				self::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key), 
113 113
 				$model
114 114
 			);
115
-			if( $field instanceof \EE_Model_Field_Base ) {
115
+			if ($field instanceof \EE_Model_Field_Base) {
116 116
 				//did they specify an operator?
117
-				if( is_array( $query_param_value ) ) {
118
-					$op = $query_param_value[ 0 ];
119
-					$value = $query_param_value[ 1 ];
120
-					$new_value = self::prepare_field_values_from_json( $field, $value, $requested_version );
121
-					$translated_value = array( $op, $new_value );
117
+				if (is_array($query_param_value)) {
118
+					$op = $query_param_value[0];
119
+					$value = $query_param_value[1];
120
+					$new_value = self::prepare_field_values_from_json($field, $value, $requested_version);
121
+					$translated_value = array($op, $new_value);
122 122
 				} else {
123
-					$translated_value  = self::prepare_field_value_from_json( $field, $query_param_value, $requested_version );
123
+					$translated_value = self::prepare_field_value_from_json($field, $query_param_value, $requested_version);
124 124
 				}
125
-				$query_param_for_models[ $query_param_key ] = $translated_value;
125
+				$query_param_for_models[$query_param_key] = $translated_value;
126 126
 			} else {
127 127
 				//so it's not for a field, assume it's a logic query param key
128
-				$query_param_for_models[ $query_param_key ] = self::prepare_conditions_query_params_for_models( $query_param_value, $model, $requested_version );
128
+				$query_param_for_models[$query_param_key] = self::prepare_conditions_query_params_for_models($query_param_value, $model, $requested_version);
129 129
 			}
130 130
 		}
131 131
 		return $query_param_for_models;
132 132
 	}
133 133
 	
134
-	public static function remove_stars_and_anything_after_from_condition_query_param_key( $condition_query_param_key ) {
134
+	public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) {
135 135
 		$pos_of_star = strpos($condition_query_param_key, '*');
136
-		if($pos_of_star === FALSE){
136
+		if ($pos_of_star === FALSE) {
137 137
 			return $condition_query_param_key;
138
-		}else{
138
+		} else {
139 139
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
140 140
 			return $condition_query_param_sans_star;
141 141
 		}
@@ -147,26 +147,26 @@  discard block
 block discarded – undo
147 147
 	 * @throws EE_Error
148 148
 	 * @return EE_Model_Field_Base
149 149
 	 */
150
-	public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model){
150
+	public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model) {
151 151
 		//ok, now proceed with deducing which part is the model's name, and which is the field's name
152 152
 		//which will help us find the database table and column
153 153
 
154
-		$query_param_parts = explode(".",$query_param_name);
155
-		if(empty($query_param_parts)){
156
-			throw new \EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s",'event_espresso'),$query_param_name));
154
+		$query_param_parts = explode(".", $query_param_name);
155
+		if (empty($query_param_parts)) {
156
+			throw new \EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s", 'event_espresso'), $query_param_name));
157 157
 		}
158 158
 		$number_of_parts = count($query_param_parts);
159
-		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
160
-		if($number_of_parts == 1){
159
+		$last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
160
+		if ($number_of_parts == 1) {
161 161
 			$field_name = $last_query_param_part;
162
-		}else{// $number_of_parts >= 2
162
+		} else {// $number_of_parts >= 2
163 163
 			//the last part is the column name, and there are only 2parts. therefore...
164 164
 			$field_name = $last_query_param_part;
165
-			$model = \EE_Registry::instance()->load_model( $query_param_parts[ $number_of_parts - 2 ]);
165
+			$model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]);
166 166
 		}
167
-		try{
167
+		try {
168 168
 			return $model->field_settings_for($field_name);
169
-		}catch(\EE_Error $e){
169
+		} catch (\EE_Error $e) {
170 170
 			return null;
171 171
 		}
172 172
 	}
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 		$pos_of_star = strpos($condition_query_param_key, '*');
136 136
 		if($pos_of_star === FALSE){
137 137
 			return $condition_query_param_key;
138
-		}else{
138
+		} else{
139 139
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
140 140
 			return $condition_query_param_sans_star;
141 141
 		}
@@ -159,14 +159,14 @@  discard block
 block discarded – undo
159 159
 		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
160 160
 		if($number_of_parts == 1){
161 161
 			$field_name = $last_query_param_part;
162
-		}else{// $number_of_parts >= 2
162
+		} else{// $number_of_parts >= 2
163 163
 			//the last part is the column name, and there are only 2parts. therefore...
164 164
 			$field_name = $last_query_param_part;
165 165
 			$model = \EE_Registry::instance()->load_model( $query_param_parts[ $number_of_parts - 2 ]);
166 166
 		}
167 167
 		try{
168 168
 			return $model->field_settings_for($field_name);
169
-		}catch(\EE_Error $e){
169
+		} catch(\EE_Error $e){
170 170
 			return null;
171 171
 		}
172 172
 	}
Please login to merge, or discard this patch.
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -1,24 +1,24 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\libraries\rest_api;
3 3
 /**
4
- *
5
- * Class Model_Data_Translator
6
- *
7
- * Class for translating data between the EE4 models and JSON.
8
- * Some of this class needs to interpret an incoming array of query params from 
9
- * the REST API and prepare it for use by the models. Some of this code seems duplicated
10
- * fromt he models but it's anticipated to diverge (because providing parameters
11
- * in the REST API is sometimes more difficult than in PHP directly. Eg, providing an array like
12
- * array( 'where' => array( 'EVT_ID' => array( '<', 100 ) ) ) in PHP is easy, but in a querystring it needs to look like
13
- * "where[EVT_ID][]=<&where[EVT_ID][]=100" is less intuitive, so we may want
14
- * to allow REST API query parameters to diverge from the format accepted by models)
15
- *
16
- * @package         Event Espresso
17
- * @subpackage    
18
- * @author				Mike Nelson
19
- * @since		 	   4.8.36
20
- *
21
- */
4
+	 *
5
+	 * Class Model_Data_Translator
6
+	 *
7
+	 * Class for translating data between the EE4 models and JSON.
8
+	 * Some of this class needs to interpret an incoming array of query params from 
9
+	 * the REST API and prepare it for use by the models. Some of this code seems duplicated
10
+	 * fromt he models but it's anticipated to diverge (because providing parameters
11
+	 * in the REST API is sometimes more difficult than in PHP directly. Eg, providing an array like
12
+	 * array( 'where' => array( 'EVT_ID' => array( '<', 100 ) ) ) in PHP is easy, but in a querystring it needs to look like
13
+	 * "where[EVT_ID][]=<&where[EVT_ID][]=100" is less intuitive, so we may want
14
+	 * to allow REST API query parameters to diverge from the format accepted by models)
15
+	 *
16
+	 * @package         Event Espresso
17
+	 * @subpackage    
18
+	 * @author				Mike Nelson
19
+	 * @since		 	   4.8.36
20
+	 *
21
+	 */
22 22
 	
23 23
 	
24 24
 if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
@@ -74,11 +74,11 @@  discard block
 block discarded – undo
74 74
 	}
75 75
 	
76 76
 	/**
77
-	* Prepares a field's value for display in the API
78
-	* @param \EE_Model_Field_Base $field_obj
79
-	* @param mixed $original_value
80
-	* @return mixed
81
-	*/
77
+	 * Prepares a field's value for display in the API
78
+	 * @param \EE_Model_Field_Base $field_obj
79
+	 * @param mixed $original_value
80
+	 * @return mixed
81
+	 */
82 82
    public static function prepare_field_value_for_json( $field_obj, $original_value, $requested_version ) {
83 83
 		if( $original_value === EE_INF ) {
84 84
 			$new_value = self::ee_inf_in_rest;
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 			$original_value,
96 96
 			$requested_version
97 97
 		);
98
-    }
98
+	}
99 99
 	
100 100
 	/**
101 101
 	 * Prepares condition-query-parameters (like what's in where and having) from
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/model/Meta.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\libraries\rest_api\controllers\model;
3 3
 use EventEspresso\core\libraries\rest_api\Model_Data_Translator;
4
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 /**
@@ -23,20 +23,20 @@  discard block
 block discarded – undo
23 23
 	 * @param \WP_REST_Request $request
24 24
 	 * @return array|\WP_REST_Response
25 25
 	 */
26
-	public static function handle_request_models_meta( \WP_REST_Request $request ) {
26
+	public static function handle_request_models_meta(\WP_REST_Request $request) {
27 27
 		$controller = new Meta();
28
-		try{
28
+		try {
29 29
 			$matches = $controller->parse_route(
30 30
 				$request->get_route(),
31
-				'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . 'resources~',
32
-				array( 'version' ) );
33
-			if( $matches instanceof \WP_REST_Response ) {
31
+				'~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'resources~',
32
+				array('version') );
33
+			if ($matches instanceof \WP_REST_Response) {
34 34
 				return $matches;
35 35
 			}
36
-			$controller->set_requested_version( $matches[ 'version' ] );
37
-			return $controller->send_response( $controller->_get_models_metadata_entity() );
38
-		} catch( \Exception $e ) {
39
-			return $controller->send_response( $e );
36
+			$controller->set_requested_version($matches['version']);
37
+			return $controller->send_response($controller->_get_models_metadata_entity());
38
+		} catch (\Exception $e) {
39
+			return $controller->send_response($e);
40 40
 		}
41 41
 	}
42 42
 
@@ -44,22 +44,22 @@  discard block
 block discarded – undo
44 44
 	 * Gets the model metadata resource entity
45 45
 	 * @return array for JSON response, describing all the models available in teh requested version
46 46
 	 */
47
-	protected function _get_models_metadata_entity(){
47
+	protected function _get_models_metadata_entity() {
48 48
 		$response = array();
49
-		foreach( $this->get_model_version_info()->models_for_requested_version() as $model_name => $model_classname ){
50
-			$model = $this->get_model_version_info()->load_model( $model_name );
49
+		foreach ($this->get_model_version_info()->models_for_requested_version() as $model_name => $model_classname) {
50
+			$model = $this->get_model_version_info()->load_model($model_name);
51 51
 			$fields_json = array();
52
-			foreach( $this->get_model_version_info()->fields_on_model_in_this_version( $model ) as $field_name => $field_obj ) {
53
-				if( $this->get_model_version_info()->field_is_ignored( $field_obj ) ) {
52
+			foreach ($this->get_model_version_info()->fields_on_model_in_this_version($model) as $field_name => $field_obj) {
53
+				if ($this->get_model_version_info()->field_is_ignored($field_obj)) {
54 54
 					continue;
55 55
 				}
56
-				if( $field_obj instanceof \EE_Boolean_Field ) {
56
+				if ($field_obj instanceof \EE_Boolean_Field) {
57 57
 					$datatype = 'Boolean';
58
-				}elseif( $field_obj->get_wpdb_data_type() == '%d' ) {
58
+				}elseif ($field_obj->get_wpdb_data_type() == '%d') {
59 59
 					$datatype = 'Number';
60
-				}elseif( $field_name instanceof \EE_Serialized_Text_Field ) {
60
+				}elseif ($field_name instanceof \EE_Serialized_Text_Field) {
61 61
 					$datatype = 'Object';
62
-				}else{
62
+				} else {
63 63
 					$datatype = 'String';
64 64
 				}
65 65
 				$default_value = Model_Data_Translator::prepare_field_value_for_json(
@@ -70,30 +70,30 @@  discard block
 block discarded – undo
70 70
 				$field_json = array(
71 71
 					'name' => $field_name,
72 72
 					'nicename' => $field_obj->get_nicename(),
73
-					'has_rendered_format' => $this->get_model_version_info()->field_has_rendered_format( $field_obj ),
74
-					'has_pretty_format' => $this->get_model_version_info()->field_has_pretty_format( $field_obj ),
75
-					'type' => str_replace('EE_', '', get_class( $field_obj ) ),
73
+					'has_rendered_format' => $this->get_model_version_info()->field_has_rendered_format($field_obj),
74
+					'has_pretty_format' => $this->get_model_version_info()->field_has_pretty_format($field_obj),
75
+					'type' => str_replace('EE_', '', get_class($field_obj)),
76 76
 					'datatype' => $datatype,
77 77
 					'nullable' => $field_obj->is_nullable(),
78 78
 					'default' => $default_value,
79 79
 					'table_alias' => $field_obj->get_table_alias(),
80 80
 					'table_column' => $field_obj->get_table_column(),
81 81
 				);
82
-				$fields_json[ $field_json[ 'name' ] ] = $field_json;
82
+				$fields_json[$field_json['name']] = $field_json;
83 83
 
84 84
 			}
85
-			$fields_json = array_merge( $fields_json, $this->get_model_version_info()->extra_resource_properties_for_model( $model ) );
86
-			$response[ $model_name ]['fields'] = apply_filters( 'FHEE__Meta__handle_request_models_meta__fields', $fields_json, $model );
85
+			$fields_json = array_merge($fields_json, $this->get_model_version_info()->extra_resource_properties_for_model($model));
86
+			$response[$model_name]['fields'] = apply_filters('FHEE__Meta__handle_request_models_meta__fields', $fields_json, $model);
87 87
 			$relations_json = array();
88
-			foreach( $model->relation_settings()  as $relation_name => $relation_obj ) {
88
+			foreach ($model->relation_settings()  as $relation_name => $relation_obj) {
89 89
 				$relation_json = array(
90 90
 					'name' => $relation_name,
91
-					'type' => str_replace( 'EE_', '', get_class( $relation_obj ) ),
91
+					'type' => str_replace('EE_', '', get_class($relation_obj)),
92 92
 					'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false,
93 93
 				);
94
-				$relations_json[ $relation_name ] = $relation_json;
94
+				$relations_json[$relation_name] = $relation_json;
95 95
 			}
96
-			$response[ $model_name ][ 'relations' ] = apply_filters( 'FHEE__Meta__handle_request_models_meta__relations', $relations_json, $model );
96
+			$response[$model_name]['relations'] = apply_filters('FHEE__Meta__handle_request_models_meta__relations', $relations_json, $model);
97 97
 		}
98 98
 		return $response;
99 99
 	}
@@ -103,23 +103,23 @@  discard block
 block discarded – undo
103 103
 	 * @param \WP_REST_Response $rest_response_obj
104 104
 	 * @return \WP_REST_Response
105 105
 	 */
106
-	public static function filter_ee_metadata_into_index( \WP_REST_Response $rest_response_obj ) {
106
+	public static function filter_ee_metadata_into_index(\WP_REST_Response $rest_response_obj) {
107 107
 		$response_data = $rest_response_obj->get_data();
108 108
 		$addons = array();
109
-		foreach( \EE_Registry::instance()->addons as $addon){
109
+		foreach (\EE_Registry::instance()->addons as $addon) {
110 110
 			$addon_json = array(
111 111
 				'name' => $addon->name(),
112 112
 				'version' => $addon->version()
113 113
 			);
114
-			$addons[ $addon_json[ 'name' ] ] = $addon_json;
114
+			$addons[$addon_json['name']] = $addon_json;
115 115
 		}
116
-		$response_data[ 'ee' ] = array(
116
+		$response_data['ee'] = array(
117 117
 			'version' => \EEM_System_Status::instance()->get_ee_version(),
118 118
 			'addons' => $addons,
119 119
 			'maintenance_mode' => \EE_Maintenance_Mode::instance()->real_level(),
120
-			'served_core_versions' => array_keys( \EED_Core_Rest_Api::versions_served() )
120
+			'served_core_versions' => array_keys(\EED_Core_Rest_Api::versions_served())
121 121
 		);
122
-		$rest_response_obj->set_data( $response_data );
122
+		$rest_response_obj->set_data($response_data);
123 123
 		return $rest_response_obj;
124 124
 	}
125 125
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/Base.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\libraries\rest_api\controllers;
3 3
 use EventEspresso\core\libraries\rest_api\Rest_Exception;
4
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 /**
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 
50 50
 
51 51
 	public function __construct() {
52
-		$this->_debug_mode = defined( 'EE_REST_API_DEBUG_MODE' ) ? EE_REST_API_DEBUG_MODE : false;
52
+		$this->_debug_mode = defined('EE_REST_API_DEBUG_MODE') ? EE_REST_API_DEBUG_MODE : false;
53 53
 	}
54 54
 
55 55
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 * Sets the version the user requested
58 58
 	 * @param string $version eg '4.8'
59 59
 	 */
60
-	public function set_requested_version( $version ) {
60
+	public function set_requested_version($version) {
61 61
 		$this->_requested_version = $version;
62 62
 	}
63 63
 
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 	 * @param string $key
67 67
 	 * @param string|array $info
68 68
 	 */
69
-	protected function _set_debug_info( $key, $info ){
70
-		$this->_debug_info[ $key ] = $info;
69
+	protected function _set_debug_info($key, $info) {
70
+		$this->_debug_info[$key] = $info;
71 71
 	}
72 72
 
73 73
 	/**
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
 	 * @param boolean      $use_ee_prefix whether to use the EE prefix on the header, or fallback to
80 80
 	 *                                    the standard WP one
81 81
 	 */
82
-	protected function _set_response_header( $header_key, $value, $use_ee_prefix = true ) {
83
-		if( is_array( $value ) ) {
84
-			foreach( $value as $value_key => $value_value ) {
85
-				$this->_set_response_header(  $header_key . '[' . $value_key . ']', $value_value );
82
+	protected function _set_response_header($header_key, $value, $use_ee_prefix = true) {
83
+		if (is_array($value)) {
84
+			foreach ($value as $value_key => $value_value) {
85
+				$this->_set_response_header($header_key.'['.$value_key.']', $value_value);
86 86
 			}
87 87
 		} else {
88 88
 			$prefix = $use_ee_prefix ? Base::header_prefix_for_ee : Base::header_prefix_for_wp;
89
-			$this->_response_headers[ $prefix . $header_key  ] = $value;
89
+			$this->_response_headers[$prefix.$header_key] = $value;
90 90
 		}
91 91
 	}
92 92
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 * @return array
96 96
 	 */
97 97
 	protected function _get_response_headers() {
98
-		return apply_filters( 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
98
+		return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
99 99
 			$this->_response_headers,
100 100
 			$this,
101 101
 			$this->_requested_version
@@ -107,13 +107,13 @@  discard block
 block discarded – undo
107 107
 	 * @param \WP_Error $wp_error_response
108 108
 	 * @return \WP_Error
109 109
 	 */
110
-	protected function _add_ee_errors_to_response( \WP_Error $wp_error_response ) {
110
+	protected function _add_ee_errors_to_response(\WP_Error $wp_error_response) {
111 111
 		$notices_during_checkin = \EE_Error::get_raw_notices();
112
-		if( ! empty( $notices_during_checkin[ 'errors' ] ) ) {
113
-			foreach( $notices_during_checkin[ 'errors' ] as $error_code => $error_message ) {
112
+		if ( ! empty($notices_during_checkin['errors'])) {
113
+			foreach ($notices_during_checkin['errors'] as $error_code => $error_message) {
114 114
 				$wp_error_response->add(
115
-					sanitize_key( $error_code ),
116
-					strip_tags( $error_message ) );
115
+					sanitize_key($error_code),
116
+					strip_tags($error_message) );
117 117
 			}
118 118
 		}
119 119
 		return $wp_error_response;
@@ -131,27 +131,27 @@  discard block
 block discarded – undo
131 131
 	 * @param array|\WP_Error|\Exception $response
132 132
 	 * @return \WP_REST_Response
133 133
 	 */
134
-	public function send_response( $response ) {
135
-		if( $response instanceof Rest_Exception ) {
136
-			$response = new \WP_Error( $response->get_string_code(), $response->getMessage(), $response->get_data() );
134
+	public function send_response($response) {
135
+		if ($response instanceof Rest_Exception) {
136
+			$response = new \WP_Error($response->get_string_code(), $response->getMessage(), $response->get_data());
137 137
 		}
138
-		if( $response instanceof \Exception ) {
138
+		if ($response instanceof \Exception) {
139 139
 			$code = $response->getCode() ? $response->getCode() : 'error_occurred';
140
-			$response = new \WP_Error( $code, $response->getMessage() );
140
+			$response = new \WP_Error($code, $response->getMessage());
141 141
 		}
142
-		if( $response instanceof \WP_Error ) {
143
-			$response = $this->_add_ee_errors_to_response( $response );
144
-			$rest_response = $this->_create_rest_response_from_wp_error( $response );
145
-		}else{
146
-			$rest_response = new \WP_REST_Response( $response, 200 );
142
+		if ($response instanceof \WP_Error) {
143
+			$response = $this->_add_ee_errors_to_response($response);
144
+			$rest_response = $this->_create_rest_response_from_wp_error($response);
145
+		} else {
146
+			$rest_response = new \WP_REST_Response($response, 200);
147 147
 		}
148 148
 		$headers = array();
149
-		if( $this->_debug_mode && is_array( $this->_debug_info ) ) {
150
-			foreach( $this->_debug_info  as $debug_key => $debug_info ) {
151
-				if( is_array( $debug_info ) ) {
152
-					$debug_info = json_encode( $debug_info );
149
+		if ($this->_debug_mode && is_array($this->_debug_info)) {
150
+			foreach ($this->_debug_info  as $debug_key => $debug_info) {
151
+				if (is_array($debug_info)) {
152
+					$debug_info = json_encode($debug_info);
153 153
 				}
154
-				$headers[ 'X-EE4-Debug-' . ucwords( $debug_key ) ] = $debug_info;
154
+				$headers['X-EE4-Debug-'.ucwords($debug_key)] = $debug_info;
155 155
 			}
156 156
 		}
157 157
 		$headers = array_merge(
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 			$this->_get_headers_from_ee_notices()
161 161
 		);
162 162
 
163
-		$rest_response->set_headers( $headers );
163
+		$rest_response->set_headers($headers);
164 164
 		return $rest_response;
165 165
 	}
166 166
 
@@ -171,31 +171,31 @@  discard block
 block discarded – undo
171 171
 	 * @param \WP_Error $wp_error
172 172
 	 * @return \WP_REST_Response
173 173
 	 */
174
-	protected function _create_rest_response_from_wp_error( \WP_Error $wp_error ) {
174
+	protected function _create_rest_response_from_wp_error(\WP_Error $wp_error) {
175 175
 		$error_data = $wp_error->get_error_data();
176
-		if ( is_array( $error_data ) && isset( $error_data['status'] ) ) {
176
+		if (is_array($error_data) && isset($error_data['status'])) {
177 177
 			$status = $error_data['status'];
178 178
 		} else {
179 179
 			$status = 500;
180 180
 		}
181 181
 
182 182
 		$errors = array();
183
-		foreach ( (array) $wp_error->errors as $code => $messages ) {
184
-			foreach ( (array) $messages as $message ) {
183
+		foreach ((array) $wp_error->errors as $code => $messages) {
184
+			foreach ((array) $messages as $message) {
185 185
 				$errors[] = array(
186 186
 					'code'    => $code,
187 187
 					'message' => $message,
188
-					'data'    => $wp_error->get_error_data( $code )
188
+					'data'    => $wp_error->get_error_data($code)
189 189
 				);
190 190
 			}
191 191
 		}
192
-		$data = isset( $errors[0] ) ? $errors[0] : array();
193
-		if ( count( $errors ) > 1 ) {
192
+		$data = isset($errors[0]) ? $errors[0] : array();
193
+		if (count($errors) > 1) {
194 194
 			// Remove the primary error.
195
-			array_shift( $errors );
195
+			array_shift($errors);
196 196
 			$data['additional_errors'] = $errors;
197 197
 		}
198
-		return new \WP_REST_Response( $data, $status );
198
+		return new \WP_REST_Response($data, $status);
199 199
 	}
200 200
 
201 201
 	/**
@@ -205,12 +205,12 @@  discard block
 block discarded – undo
205 205
 	protected function _get_headers_from_ee_notices() {
206 206
 		$headers = array();
207 207
 		$notices = \EE_Error::get_raw_notices();
208
-		foreach( $notices as $notice_type => $sub_notices ) {
209
-			if( ! is_array( $sub_notices ) ) {
208
+		foreach ($notices as $notice_type => $sub_notices) {
209
+			if ( ! is_array($sub_notices)) {
210 210
 				continue;
211 211
 			}
212
-			foreach( $sub_notices as $notice_code => $sub_notice ) {
213
-				$headers[ 'X-EE4-Notices-' . \EEH_Inflector::humanize( $notice_type ) . '[' . $notice_code . ']' ] = strip_tags( $sub_notice );
212
+			foreach ($sub_notices as $notice_code => $sub_notice) {
213
+				$headers['X-EE4-Notices-'.\EEH_Inflector::humanize($notice_type).'['.$notice_code.']'] = strip_tags($sub_notice);
214 214
 			}
215 215
 		}
216 216
 		return apply_filters(
@@ -228,14 +228,14 @@  discard block
 block discarded – undo
228 228
 	 * @param string $route
229 229
 	 * @return string
230 230
 	 */
231
-	public function get_requested_version( $route = null ) {
231
+	public function get_requested_version($route = null) {
232 232
 		$matches = $this->parse_route(
233 233
 			$route,
234
-			'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '~',
235
-			array( 'version' )
234
+			'~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'~',
235
+			array('version')
236 236
 			);
237
-		if( isset( $matches[ 'version' ] ) ) {
238
-			return $matches[ 'version' ];
237
+		if (isset($matches['version'])) {
238
+			return $matches['version'];
239 239
 		} else {
240 240
 			return \EED_Core_Rest_Api::latest_rest_api_version();
241 241
 		}
@@ -260,23 +260,23 @@  discard block
 block discarded – undo
260 260
 	 * array( 'model' => 'foo', 'id' => 'bar' )
261 261
 	 * @throws \EE_Error if it couldn't be parsed
262 262
 	 */
263
-	public function parse_route( $route, $regex, $match_keys ) {
263
+	public function parse_route($route, $regex, $match_keys) {
264 264
 		$indexed_matches = array();
265
-		$success = preg_match( $regex, $route, $matches );
266
-		if(
267
-			is_array( $matches ) ) {
265
+		$success = preg_match($regex, $route, $matches);
266
+		if (
267
+			is_array($matches) ) {
268 268
 			//skip the overall regex match. Who cares
269
-			for( $i = 1; $i <= count( $match_keys ); $i++ ) {
270
-				if( ! isset( $matches[ $i ] ) ) {
269
+			for ($i = 1; $i <= count($match_keys); $i++) {
270
+				if ( ! isset($matches[$i])) {
271 271
 					$success = false;
272 272
 				} else {
273
-					$indexed_matches[ $match_keys[ $i - 1 ] ] = $matches[ $i ];
273
+					$indexed_matches[$match_keys[$i - 1]] = $matches[$i];
274 274
 				}
275 275
 			}
276 276
 		}
277
-		if( ! $success ) {
277
+		if ( ! $success) {
278 278
 			throw new \EE_Error(
279
-				__( 'We could not parse the URL. Please contact Event Espresso Support', 'event_espresso' ),
279
+				__('We could not parse the URL. Please contact Event Espresso Support', 'event_espresso'),
280 280
 				'endpoint_parsing_error'
281 281
 			);
282 282
 		}
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Base.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -13,19 +13,19 @@  discard block
 block discarded – undo
13 13
  * @since		 	   $VID:$
14 14
  *
15 15
  */
16
-if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
17
-	exit( 'No direct script access allowed' );
16
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
17
+	exit('No direct script access allowed');
18 18
 }
19 19
 
20 20
 class Base {
21
-	protected static function _verify_current_user_can( $required_permission, $attempted_calculation ) {
22
-		if( ! current_user_can( $required_permission ) ) {
21
+	protected static function _verify_current_user_can($required_permission, $attempted_calculation) {
22
+		if ( ! current_user_can($required_permission)) {
23 23
 			throw new Rest_Exception(
24 24
 				'permission_denied',
25 25
 				sprintf( 
26
-					__( 'Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"', 'event_espresso' ),
26
+					__('Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"', 'event_espresso'),
27 27
 					$attempted_calculation,
28
-					\EEH_Inflector::pluralize_and_lower( self::get_resource_name() ),
28
+					\EEH_Inflector::pluralize_and_lower(self::get_resource_name()),
29 29
 					$required_permission
30 30
 				)
31 31
 			);
@@ -38,6 +38,6 @@  discard block
 block discarded – undo
38 38
 	 */
39 39
 	public static function get_resource_name() {
40 40
 		$classname = get_called_class();
41
-		return substr( $classname, strrpos( $classname, '\\' ) + 1 );
41
+		return substr($classname, strrpos($classname, '\\') + 1);
42 42
 	}
43 43
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/Calculated_Model_Fields.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
  * @since		 	   4.8.35.rc.001
16 16
  *
17 17
  */
18
-if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
19
-	exit( 'No direct script access allowed' );
18
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
19
+	exit('No direct script access allowed');
20 20
 }
21 21
 
22 22
 class Calculated_Model_Fields {
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
 	 * the WP_Request object,
39 39
 	 * the controller object
40 40
 	 */
41
-	public function mapping( $refresh = false ) {
42
-		if( ! $this->_mapping || $refresh ) {
41
+	public function mapping($refresh = false) {
42
+		if ( ! $this->_mapping || $refresh) {
43 43
 			$this->_mapping = $this->_generate_new_mapping();
44 44
 		}
45 45
 		return $this->_mapping;
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 	 */
53 53
 	protected function _generate_new_mapping() {
54 54
 		$rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\';
55
-		$event_calculations_class = $rest_api_calculations_namespace . 'Event';
56
-		$datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime';
55
+		$event_calculations_class = $rest_api_calculations_namespace.'Event';
56
+		$datetime_calculations_class = $rest_api_calculations_namespace.'Datetime';
57 57
 		return apply_filters(
58 58
 			'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping',
59 59
 			array(
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
 	 * @param \EEM_Base $model
82 82
 	 * @return array allowable values for this field
83 83
 	 */
84
-	public function retrieve_calculated_fields_for_model( \EEM_Base $model ) {
84
+	public function retrieve_calculated_fields_for_model(\EEM_Base $model) {
85 85
 		$mapping = $this->mapping();
86
-		if( isset( $mapping[ $model->get_this_model_name() ] ) ) {
87
-			return array_keys( $mapping[ $model->get_this_model_name() ] );
86
+		if (isset($mapping[$model->get_this_model_name()])) {
87
+			return array_keys($mapping[$model->get_this_model_name()]);
88 88
 		} else {
89 89
 			return array();
90 90
 		}
@@ -103,17 +103,17 @@  discard block
 block discarded – undo
103 103
 	 * @return mixed|null
104 104
 	 * @throws \EE_Error
105 105
 	 */
106
-	public function retrieve_calculated_field_value( \EEM_Base $model, $field_name, $wpdb_row, $rest_request, Base $controller ) {
106
+	public function retrieve_calculated_field_value(\EEM_Base $model, $field_name, $wpdb_row, $rest_request, Base $controller) {
107 107
 		$mapping = $this->mapping();
108
-		if( isset( $mapping[ $model->get_this_model_name() ] )
109
-			&& isset( $mapping[ $model->get_this_model_name() ][ $field_name ] ) ) {
110
-			$classname = $mapping[ $model->get_this_model_name() ][ $field_name ];
111
-			return call_user_func( array( $classname, $field_name ), $wpdb_row, $rest_request, $controller );
108
+		if (isset($mapping[$model->get_this_model_name()])
109
+			&& isset($mapping[$model->get_this_model_name()][$field_name])) {
110
+			$classname = $mapping[$model->get_this_model_name()][$field_name];
111
+			return call_user_func(array($classname, $field_name), $wpdb_row, $rest_request, $controller);
112 112
 		}
113 113
 		throw new Rest_Exception( 
114 114
 			'calculated_field_does_not_exist',
115 115
 			sprintf( 
116
-				__( 'There is no calculated field %1$s on resource %2$s', 'event_espresso' ), 
116
+				__('There is no calculated field %1$s on resource %2$s', 'event_espresso'), 
117 117
 				$field_name, 
118 118
 				$model->get_this_model_name() 
119 119
 			) 
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -3,18 +3,18 @@
 block discarded – undo
3 3
 use EventEspresso\core\libraries\rest_api\controllers\Base;
4 4
 use EventEspresso\core\libraries\rest_api\Rest_Exception;
5 5
 /**
6
- *
7
- * Class Calculationshelpers
8
- *
9
- * Class for defining which model fields can be calculated, and performing those calculations
10
- * as requested
11
- *
12
- * @package         Event Espresso
13
- * @subpackage
14
- * @author				Mike Nelson
15
- * @since		 	   4.8.35.rc.001
16
- *
17
- */
6
+  *
7
+  * Class Calculationshelpers
8
+  *
9
+  * Class for defining which model fields can be calculated, and performing those calculations
10
+  * as requested
11
+  *
12
+  * @package         Event Espresso
13
+  * @subpackage
14
+  * @author				Mike Nelson
15
+  * @since		 	   4.8.35.rc.001
16
+  *
17
+  */
18 18
 if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
19 19
 	exit( 'No direct script access allowed' );
20 20
 }
Please login to merge, or discard this patch.