Completed
Branch BUG-8866-category-permalink (0af2d2)
by
unknown
22:53 queued 19s
created
libraries/line_item_display/EE_SPCO_Line_Item_Display_Strategy.strategy.php 2 patches
Spacing   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -69,104 +69,104 @@  discard block
 block discarded – undo
69 69
 	 * @param array        $options
70 70
 	 * @return mixed
71 71
 	 */
72
-	public function display_line_item( EE_Line_Item $line_item, $options = array() ) {
72
+	public function display_line_item(EE_Line_Item $line_item, $options = array()) {
73 73
 
74
-		EE_Registry::instance()->load_helper( 'Template' );
75
-		EE_Registry::instance()->load_helper( 'HTML' );
74
+		EE_Registry::instance()->load_helper('Template');
75
+		EE_Registry::instance()->load_helper('HTML');
76 76
 
77 77
 		$html = '';
78 78
 		// set some default options and merge with incoming
79 79
 		$default_options = array(
80
-			'show_desc' => true,  // 	true 		false
80
+			'show_desc' => true, // 	true 		false
81 81
 			'odd' => false
82 82
 		);
83
-		$options = array_merge( $default_options, (array)$options );
83
+		$options = array_merge($default_options, (array) $options);
84 84
 
85
-		switch( $line_item->type() ) {
85
+		switch ($line_item->type()) {
86 86
 
87 87
 			case EEM_Line_Item::type_line_item:
88 88
 				$this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
89
-				if ( $line_item->OBJ_type() == 'Ticket' ) {
89
+				if ($line_item->OBJ_type() == 'Ticket') {
90 90
 					// item row
91
-					$html .= $this->_ticket_row( $line_item, $options );
91
+					$html .= $this->_ticket_row($line_item, $options);
92 92
 					// got any kids?
93
-					foreach ( $line_item->children() as $child_line_item ) {
94
-						$this->display_line_item( $child_line_item, $options );
93
+					foreach ($line_item->children() as $child_line_item) {
94
+						$this->display_line_item($child_line_item, $options);
95 95
 					}
96 96
 				} else {
97 97
 					// item row
98
-					$html .= $this->_item_row( $line_item, $options );
98
+					$html .= $this->_item_row($line_item, $options);
99 99
 					// got any kids?
100
-					foreach ( $line_item->children() as $child_line_item ) {
101
-						$this->display_line_item( $child_line_item, $options );
100
+					foreach ($line_item->children() as $child_line_item) {
101
+						$this->display_line_item($child_line_item, $options);
102 102
 					}
103 103
 				}
104 104
 				break;
105 105
 
106 106
 			case EEM_Line_Item::type_sub_line_item:
107
-				$html .= $this->_sub_item_row( $line_item, $options );
107
+				$html .= $this->_sub_item_row($line_item, $options);
108 108
 				break;
109 109
 
110 110
 			case EEM_Line_Item::type_sub_total:
111 111
 				static $sub_total = 0;
112 112
 				$event_sub_total = 0;
113
-				$text = __( 'Sub-Total', 'event_espresso' );
114
-				if ( $line_item->OBJ_type() == 'Event' ) {
115
-					$options[ 'event_id' ] = $event_id = $line_item->OBJ_ID();
116
-					if ( ! isset( $this->_events[ $options[ 'event_id' ] ] ) ) {
117
-						$event = EEM_Event::instance()->get_one_by_ID( $options[ 'event_id' ] );
118
-						if ( $event instanceof EE_Event ) {
119
-							if ( $event->default_registration_status() == EEM_Registration::status_id_not_approved ) {
113
+				$text = __('Sub-Total', 'event_espresso');
114
+				if ($line_item->OBJ_type() == 'Event') {
115
+					$options['event_id'] = $event_id = $line_item->OBJ_ID();
116
+					if ( ! isset($this->_events[$options['event_id']])) {
117
+						$event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
118
+						if ($event instanceof EE_Event) {
119
+							if ($event->default_registration_status() == EEM_Registration::status_id_not_approved) {
120 120
 								return '';
121 121
 							}
122 122
 						}
123
-						$this->_events[ $options[ 'event_id' ] ] = 0;
124
-						$html .= $this->_event_row( $line_item );
125
-						$text = __( 'Event Sub-Total', 'event_espresso' );
123
+						$this->_events[$options['event_id']] = 0;
124
+						$html .= $this->_event_row($line_item);
125
+						$text = __('Event Sub-Total', 'event_espresso');
126 126
 					}
127 127
 				}
128 128
 				$child_line_items = $line_item->children();
129 129
 				// loop thru children
130
-				foreach( $child_line_items as $child_line_item ) {
130
+				foreach ($child_line_items as $child_line_item) {
131 131
 					// recursively feed children back into this method
132
-					$html .= $this->display_line_item( $child_line_item, $options );
132
+					$html .= $this->display_line_item($child_line_item, $options);
133 133
 				}
134
-				$event_sub_total += isset( $options[ 'event_id' ] ) ? $this->_events[ $options[ 'event_id' ] ] : 0;
134
+				$event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
135 135
 				$sub_total += $event_sub_total;
136 136
 				if (
137 137
 					(
138 138
 						// event subtotals
139 139
 						$line_item->code() != 'pre-tax-subtotal' &&
140
-						count( $child_line_items ) > 1
140
+						count($child_line_items) > 1
141 141
 					)
142 142
 					||
143 143
 					(
144 144
 						// pre-tax subtotals
145 145
 						$line_item->code() == 'pre-tax-subtotal' &&
146
-						count( $this->_events ) > 1
146
+						count($this->_events) > 1
147 147
 					)
148 148
 				) {
149 149
 					$options['sub_total'] = $line_item->OBJ_type() == 'Event' ? $event_sub_total : $sub_total;
150
-					$html .= $this->_sub_total_row( $line_item, $text, $options );
150
+					$html .= $this->_sub_total_row($line_item, $text, $options);
151 151
 				}
152 152
 				break;
153 153
 
154 154
 			case EEM_Line_Item::type_tax:
155
-				if ( $this->_show_taxes ) {
156
-					$this->_taxes_html .= $this->_tax_row( $line_item, $options );
155
+				if ($this->_show_taxes) {
156
+					$this->_taxes_html .= $this->_tax_row($line_item, $options);
157 157
 				}
158 158
 				break;
159 159
 
160 160
 			case EEM_Line_Item::type_tax_sub_total:
161
-				if ( $this->_show_taxes ) {
161
+				if ($this->_show_taxes) {
162 162
 					$child_line_items = $line_item->children();
163 163
 					// loop thru children
164
-					foreach( $child_line_items as $child_line_item ) {
164
+					foreach ($child_line_items as $child_line_item) {
165 165
 						// recursively feed children back into this method
166
-						$html .= $this->display_line_item( $child_line_item, $options );
166
+						$html .= $this->display_line_item($child_line_item, $options);
167 167
 					}
168
-					if ( count( $child_line_items ) > 1 ) {
169
-						$this->_taxes_html .= $this->_total_tax_row( $line_item, __( 'Tax Total', 'event_espresso' ) );
168
+					if (count($child_line_items) > 1) {
169
+						$this->_taxes_html .= $this->_total_tax_row($line_item, __('Tax Total', 'event_espresso'));
170 170
 					}
171 171
 				}
172 172
 				break;
@@ -175,25 +175,25 @@  discard block
 block discarded – undo
175 175
 				// get all child line items
176 176
 				$children = $line_item->children();
177 177
 				// loop thru all non-tax child line items
178
-				foreach( $children as $child_line_item ) {
179
-					if ( $child_line_item->type() != EEM_Line_Item::type_tax_sub_total ) {
178
+				foreach ($children as $child_line_item) {
179
+					if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) {
180 180
 						// recursively feed children back into this method
181
-						$html .= $this->display_line_item( $child_line_item, $options );
181
+						$html .= $this->display_line_item($child_line_item, $options);
182 182
 					}
183 183
 				}
184 184
 
185 185
 				// now loop thru  tax child line items
186
-				foreach( $children as $child_line_item ) {
187
-					if ( $child_line_item->type() == EEM_Line_Item::type_tax_sub_total ) {
186
+				foreach ($children as $child_line_item) {
187
+					if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) {
188 188
 						// recursively feed children back into this method
189
-						$html .= $this->display_line_item( $child_line_item, $options );
189
+						$html .= $this->display_line_item($child_line_item, $options);
190 190
 					}
191 191
 				}
192 192
 				$html .= $this->_taxes_html;
193
-				$html .= $this->_total_row( $line_item, __('Total', 'event_espresso') );
193
+				$html .= $this->_total_row($line_item, __('Total', 'event_espresso'));
194 194
 
195 195
 
196
-				$html .= $this->_payments_and_amount_owing_rows( $line_item, $options );
196
+				$html .= $this->_payments_and_amount_owing_rows($line_item, $options);
197 197
 				break;
198 198
 
199 199
 		}
@@ -208,11 +208,11 @@  discard block
 block discarded – undo
208 208
 	 * @param EE_Line_Item $line_item
209 209
 	 * @return mixed
210 210
 	 */
211
-	private function _event_row( EE_Line_Item $line_item ) {
211
+	private function _event_row(EE_Line_Item $line_item) {
212 212
 		// start of row
213
-		$html = EEH_HTML::tr( '', 'event-cart-total-row', 'total_tr odd' );
213
+		$html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
214 214
 		// event name td
215
-		$html .= EEH_HTML::td( EEH_HTML::strong( $line_item->name() ), '', 'event-header', '', ' colspan="4"' );
215
+		$html .= EEH_HTML::td(EEH_HTML::strong($line_item->name()), '', 'event-header', '', ' colspan="4"');
216 216
 		// end of row
217 217
 		$html .= EEH_HTML::trx();
218 218
 		return $html;
@@ -227,10 +227,10 @@  discard block
 block discarded – undo
227 227
 	 * @param array        $options
228 228
 	 * @return mixed
229 229
 	 */
230
-	private function _ticket_row( EE_Line_Item $line_item, $options = array() ) {
230
+	private function _ticket_row(EE_Line_Item $line_item, $options = array()) {
231 231
 		// start of row
232 232
 		$row_class = $options['odd'] ? 'item odd' : 'item';
233
-		$html = EEH_HTML::tr( '', '', $row_class );
233
+		$html = EEH_HTML::tr('', '', $row_class);
234 234
 		// name && desc
235 235
 		$name_and_desc = apply_filters(
236 236
 			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
@@ -239,23 +239,23 @@  discard block
 block discarded – undo
239 239
 		);
240 240
 		$name_and_desc .= apply_filters(
241 241
 			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
242
-			( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ),
242
+			($options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' : ''),
243 243
 			$line_item,
244 244
 			$options
245 245
 		);
246 246
 		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
247 247
 		// name td
248
-		$html .= EEH_HTML::td( /*__FUNCTION__ .*/ $name_and_desc, '',  'item_l' );
248
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/ $name_and_desc, '', 'item_l' );
249 249
 		// price td
250
-		$html .= EEH_HTML::td( $line_item->unit_price_no_code(), '',  'item_c jst-rght' );
250
+		$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
251 251
 		// quantity td
252
-		$html .= EEH_HTML::td( $line_item->quantity(), '', 'item_l jst-rght' );
252
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
253 253
 		$this->_total_items += $line_item->quantity();
254 254
 		// determine total for line item
255 255
 		$total = $line_item->total();
256
-		$this->_events[ $options[ 'event_id' ] ] += $total;
256
+		$this->_events[$options['event_id']] += $total;
257 257
 		// total td
258
-		$html .= EEH_HTML::td( EEH_Template::format_currency( $total, false, false ), '',  'item_r jst-rght' );
258
+		$html .= EEH_HTML::td(EEH_Template::format_currency($total, false, false), '', 'item_r jst-rght');
259 259
 		// end of row
260 260
 		$html .= EEH_HTML::trx();
261 261
 		return $html;
@@ -270,41 +270,41 @@  discard block
 block discarded – undo
270 270
 	 * @param array        $options
271 271
 	 * @return mixed
272 272
 	 */
273
-	private function _item_row( EE_Line_Item $line_item, $options = array() ) {
273
+	private function _item_row(EE_Line_Item $line_item, $options = array()) {
274 274
 		// start of row
275 275
 		$row_class = $options['odd'] ? 'item odd' : 'item';
276
-		$html = EEH_HTML::tr( '', '', $row_class );
277
-		$obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type() . ': ' : '';
276
+		$html = EEH_HTML::tr('', '', $row_class);
277
+		$obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type().': ' : '';
278 278
 		// name && desc
279 279
 		$name_and_desc = apply_filters(
280 280
 			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
281
-			 $obj_name . $line_item->name(),
281
+			 $obj_name.$line_item->name(),
282 282
 			$line_item
283 283
 		);
284 284
 		$name_and_desc .= apply_filters(
285 285
 			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
286
-			( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ),
286
+			($options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' : ''),
287 287
 			$line_item,
288 288
 			$options
289 289
 		);
290 290
 		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
291 291
 		// name td
292
-		$html .= EEH_HTML::td( $name_and_desc, '',  'item_l' );
292
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l');
293 293
 		// price td
294
-		if ( $line_item->is_percent() ) {
295
-			$html .= EEH_HTML::td( $line_item->percent() . '%', '', 'item_c jst-rght' );
294
+		if ($line_item->is_percent()) {
295
+			$html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c jst-rght');
296 296
 		} else {
297
-			$html .= EEH_HTML::td( $line_item->unit_price_no_code(), '', 'item_c jst-rght' );
297
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
298 298
 		}
299 299
 		// quantity td
300
-		$html .= EEH_HTML::td( $line_item->quantity(), '', 'item_l jst-rght' );
300
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
301 301
 		//$total = $line_item->total() * $line_item->quantity();
302 302
 		$total = $line_item->total();
303
-		if( isset( $options[ 'event_id' ] ) && isset( $this->_events[ $options[ 'event_id' ] ] ) ) {
304
-			$this->_events[ $options[ 'event_id' ] ] += $total;
303
+		if (isset($options['event_id']) && isset($this->_events[$options['event_id']])) {
304
+			$this->_events[$options['event_id']] += $total;
305 305
 		}
306 306
 		// total td
307
-		$html .= EEH_HTML::td( EEH_Template::format_currency( $total, false, false ), '',  'item_r jst-rght' );
307
+		$html .= EEH_HTML::td(EEH_Template::format_currency($total, false, false), '', 'item_r jst-rght');
308 308
 		// end of row
309 309
 		$html .= EEH_HTML::trx();
310 310
 		return $html;
@@ -319,22 +319,22 @@  discard block
 block discarded – undo
319 319
 	 * @param array        $options
320 320
 	 * @return mixed
321 321
 	 */
322
-	private function _sub_item_row( EE_Line_Item $line_item, $options = array() ) {
322
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array()) {
323 323
 		// start of row
324
-		$html = EEH_HTML::tr( '', 'item sub-item-row' );
324
+		$html = EEH_HTML::tr('', 'item sub-item-row');
325 325
 		// name && desc
326 326
 		$name_and_desc = $line_item->name();
327
-		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '';
327
+		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' : '';
328 328
 		// name td
329
-		$html .= EEH_HTML::td( /*__FUNCTION__ .*/ $name_and_desc, '',  'item_l sub-item' );
329
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item' );
330 330
 		// discount/surcharge td
331
-		if ( $line_item->is_percent() ) {
332
-			$html .= EEH_HTML::td( $line_item->percent() . '%', '',  'item_c' );
331
+		if ($line_item->is_percent()) {
332
+			$html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c');
333 333
 		} else {
334
-			$html .= EEH_HTML::td( $line_item->unit_price_no_code(), '',  'item_c jst-rght' );
334
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
335 335
 		}
336 336
 		// total td
337
-		$html .= EEH_HTML::td( EEH_Template::format_currency( $line_item->total(), false, false ), '',  'item_r jst-rght' );
337
+		$html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'item_r jst-rght');
338 338
 		// end of row
339 339
 		$html .= EEH_HTML::trx();
340 340
 		return $html;
@@ -349,21 +349,21 @@  discard block
 block discarded – undo
349 349
 	 * @param array        $options
350 350
 	 * @return mixed
351 351
 	 */
352
-	private function _tax_row( EE_Line_Item $line_item, $options = array() ) {
352
+	private function _tax_row(EE_Line_Item $line_item, $options = array()) {
353 353
 		// start of row
354
-		$html = EEH_HTML::tr( '', 'item sub-item tax-total' );
354
+		$html = EEH_HTML::tr('', 'item sub-item tax-total');
355 355
 		// name && desc
356 356
 		$name_and_desc = $line_item->name();
357
-		$name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' . __( ' * taxable items', 'event_espresso' ) . '</span>';
358
-		$name_and_desc .= $options[ 'show_desc' ] ? '<br/>' . $line_item->desc() : '';
357
+		$name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'.__(' * taxable items', 'event_espresso').'</span>';
358
+		$name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : '';
359 359
 		// name td
360
-		$html .= EEH_HTML::td( /*__FUNCTION__ .*/ $name_and_desc, '',  'item_l sub-item' );
360
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item' );
361 361
 		// percent td
362
-		$html .= EEH_HTML::td( $line_item->percent() . '%', '',  ' jst-rght', '' );
362
+		$html .= EEH_HTML::td($line_item->percent().'%', '', ' jst-rght', '');
363 363
 		// empty td (price)
364
-		$html .= EEH_HTML::td( EEH_HTML::nbsp() );
364
+		$html .= EEH_HTML::td(EEH_HTML::nbsp());
365 365
 		// total td
366
-		$html .= EEH_HTML::td( EEH_Template::format_currency( $line_item->total(), false, false ), '',  'item_r jst-rght' );
366
+		$html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'item_r jst-rght');
367 367
 		// end of row
368 368
 		$html .= EEH_HTML::trx();
369 369
 		return $html;
@@ -378,17 +378,17 @@  discard block
 block discarded – undo
378 378
 	 * @param string $text
379 379
 	 * @return mixed
380 380
 	 */
381
-	private function _total_tax_row( EE_Line_Item $line_item, $text = '' ) {
381
+	private function _total_tax_row(EE_Line_Item $line_item, $text = '') {
382 382
 		$html = '';
383
-		if ( $line_item->total() ) {
383
+		if ($line_item->total()) {
384 384
 			// start of row
385
-			$html = EEH_HTML::tr( '', '', 'total_tr odd' );
385
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
386 386
 			// total td
387
-			$html .= EEH_HTML::td( $text, '', 'total_currency total jst-rght', '', ' colspan="2"' );
387
+			$html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="2"');
388 388
 			// empty td (price)
389
-			$html .= EEH_HTML::td( EEH_HTML::nbsp() );
389
+			$html .= EEH_HTML::td(EEH_HTML::nbsp());
390 390
 			// total td
391
-			$html .= EEH_HTML::td( EEH_Template::format_currency( $line_item->total(), false, false ), '', 'total jst-rght' );
391
+			$html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'total jst-rght');
392 392
 			// end of row
393 393
 			$html .= EEH_HTML::trx();
394 394
 		}
@@ -405,15 +405,15 @@  discard block
 block discarded – undo
405 405
 	 * @param array        $options
406 406
 	 * @return mixed
407 407
 	 */
408
-	private function _sub_total_row( EE_Line_Item $line_item, $text = '', $options = array() ) {
408
+	private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) {
409 409
 		$html = '';
410
-		if ( $line_item->total() ) {
410
+		if ($line_item->total()) {
411 411
 			// start of row
412
-			$html = EEH_HTML::tr( '', '', 'total_tr odd' );
412
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
413 413
 			// total td
414
-			$html .= EEH_HTML::td( $text, '', 'total_currency total jst-rght', '', ' colspan="3"' );
414
+			$html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
415 415
 			// total td
416
-			$html .= EEH_HTML::td( EEH_Template::format_currency( $options[ 'sub_total' ], false, false ), '', 'total jst-rght' );
416
+			$html .= EEH_HTML::td(EEH_Template::format_currency($options['sub_total'], false, false), '', 'total jst-rght');
417 417
 			// end of row
418 418
 			$html .= EEH_HTML::trx();
419 419
 		}
@@ -430,13 +430,13 @@  discard block
 block discarded – undo
430 430
 	 * @param string       $text
431 431
 	 * @return mixed
432 432
 	 */
433
-	private function _total_row( EE_Line_Item $line_item, $text = '' ) {
433
+	private function _total_row(EE_Line_Item $line_item, $text = '') {
434 434
 		// start of row
435
-		$html = EEH_HTML::tr( '', '', 'spco-grand-total total_tr odd' );
435
+		$html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
436 436
 		// total td
437
-		$html .= EEH_HTML::td( $text, '',  'total_currency total jst-rght',  '',  ' colspan="3"' );
437
+		$html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
438 438
 		// total td
439
-		$html .= EEH_HTML::td( EEH_Template::format_currency( $line_item->total(), false, false ), '',  'total jst-rght' );
439
+		$html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'total jst-rght');
440 440
 		// end of row
441 441
 		$html .= EEH_HTML::trx();
442 442
 		return $html;
@@ -451,30 +451,30 @@  discard block
 block discarded – undo
451 451
 	 * @param array        $options
452 452
 	 * @return mixed
453 453
 	 */
454
-	private function _payments_and_amount_owing_rows( EE_Line_Item $line_item, $options = array() ) {
454
+	private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) {
455 455
 		$html = '';
456 456
 		$owing = $line_item->total();
457
-		$transaction = EEM_Transaction::instance()->get_one_by_ID( $line_item->TXN_ID() );
458
-		if ( $transaction instanceof EE_Transaction ) {
457
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
458
+		if ($transaction instanceof EE_Transaction) {
459 459
 			$registration_payments = array();
460
-			$registrations = ! empty( $options['registrations'] )
461
-				? $options[ 'registrations' ]
460
+			$registrations = ! empty($options['registrations'])
461
+				? $options['registrations']
462 462
 				: $transaction->registrations();
463
-			foreach ( $registrations as $registration ) {
464
-				if ( $registration instanceof EE_Registration && $registration->owes_monies_and_can_pay() ) {
463
+			foreach ($registrations as $registration) {
464
+				if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
465 465
 					$registration_payments = $registration_payments + $registration->registration_payments();
466 466
 				}
467 467
 			}
468
-			if ( ! empty( $registration_payments )) {
469
-				foreach ( $registration_payments as $registration_payment ) {
470
-					if ( $registration_payment instanceof EE_Registration_Payment ) {
468
+			if ( ! empty($registration_payments)) {
469
+				foreach ($registration_payments as $registration_payment) {
470
+					if ($registration_payment instanceof EE_Registration_Payment) {
471 471
 						$owing = $owing - $registration_payment->amount();
472 472
 						$payment = $registration_payment->payment();
473
-						if ( $payment instanceof EE_Payment ) {
473
+						if ($payment instanceof EE_Payment) {
474 474
 							$payment_desc = sprintf(
475
-								__( 'Payment%1$s Received: %2$s', 'event_espresso' ),
475
+								__('Payment%1$s Received: %2$s', 'event_espresso'),
476 476
 								$payment->txn_id_chq_nmbr() != ''
477
-									? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
477
+									? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> '
478 478
 									: '',
479 479
 								$payment->timestamp()
480 480
 							);
@@ -482,12 +482,12 @@  discard block
 block discarded – undo
482 482
 							$payment_desc = '';
483 483
 						}
484 484
 						// start of row
485
-						$html .= EEH_HTML::tr( '', '', 'total_tr odd' );
485
+						$html .= EEH_HTML::tr('', '', 'total_tr odd');
486 486
 						// payment desc
487
-						$html .= EEH_HTML::td( $payment_desc, '', '', '', ' colspan="3"' );
487
+						$html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
488 488
 						// total td
489 489
 						$html .= EEH_HTML::td(
490
-							EEH_Template::format_currency( $registration_payment->amount(), false, false ),
490
+							EEH_Template::format_currency($registration_payment->amount(), false, false),
491 491
 							'',
492 492
 							'total jst-rght'
493 493
 						);
@@ -495,17 +495,17 @@  discard block
 block discarded – undo
495 495
 						$html .= EEH_HTML::trx();
496 496
 					}
497 497
 				}
498
-				if ( $line_item->total() ) {
498
+				if ($line_item->total()) {
499 499
 					// start of row
500
-					$html .= EEH_HTML::tr( '', '', 'total_tr odd' );
500
+					$html .= EEH_HTML::tr('', '', 'total_tr odd');
501 501
 					// total td
502 502
 					$html .= EEH_HTML::td(
503 503
 						__('Amount Owing', 'event_espresso'),
504
-						'',  'total_currency total jst-rght',  '',  ' colspan="3"'
504
+						'', 'total_currency total jst-rght', '', ' colspan="3"'
505 505
 					);
506 506
 					// total td
507 507
 					$html .= EEH_HTML::td(
508
-						EEH_Template::format_currency( $owing, false, false ), '',  'total jst-rght'
508
+						EEH_Template::format_currency($owing, false, false), '', 'total jst-rght'
509 509
 					);
510 510
 					// end of row
511 511
 					$html .= EEH_HTML::trx();
Please login to merge, or discard this patch.
Doc Comments   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	/**
68 68
 	 * @param EE_Line_Item $line_item
69 69
 	 * @param array        $options
70
-	 * @return mixed
70
+	 * @return string
71 71
 	 */
72 72
 	public function display_line_item( EE_Line_Item $line_item, $options = array() ) {
73 73
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	 *    _event_row - basically a Heading row displayed once above each event's ticket rows
204 204
 	 *
205 205
 	 * @param EE_Line_Item $line_item
206
-	 * @return mixed
206
+	 * @return string
207 207
 	 */
208 208
 	private function _event_row( EE_Line_Item $line_item ) {
209 209
 		// start of row
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 	 *
223 223
 	 * @param EE_Line_Item $line_item
224 224
 	 * @param array        $options
225
-	 * @return mixed
225
+	 * @return string
226 226
 	 */
227 227
 	private function _ticket_row( EE_Line_Item $line_item, $options = array() ) {
228 228
 		// start of row
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 	 *
266 266
 	 * @param EE_Line_Item $line_item
267 267
 	 * @param array        $options
268
-	 * @return mixed
268
+	 * @return string
269 269
 	 */
270 270
 	private function _item_row( EE_Line_Item $line_item, $options = array() ) {
271 271
 		// start of row
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	 *
315 315
 	 * @param EE_Line_Item $line_item
316 316
 	 * @param array        $options
317
-	 * @return mixed
317
+	 * @return string
318 318
 	 */
319 319
 	private function _sub_item_row( EE_Line_Item $line_item, $options = array() ) {
320 320
 		// start of row
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 	 *
345 345
 	 * @param EE_Line_Item $line_item
346 346
 	 * @param array        $options
347
-	 * @return mixed
347
+	 * @return string
348 348
 	 */
349 349
 	private function _tax_row( EE_Line_Item $line_item, $options = array() ) {
350 350
 		// start of row
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
 	 *
374 374
 	 * @param EE_Line_Item $line_item
375 375
 	 * @param string $text
376
-	 * @return mixed
376
+	 * @return string
377 377
 	 */
378 378
 	private function _total_tax_row( EE_Line_Item $line_item, $text = '' ) {
379 379
 		$html = '';
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	 * @param EE_Line_Item $line_item
401 401
 	 * @param string       $text
402 402
 	 * @param array        $options
403
-	 * @return mixed
403
+	 * @return string
404 404
 	 */
405 405
 	private function _sub_total_row( EE_Line_Item $line_item, $text = '', $options = array() ) {
406 406
 		$html = '';
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
 	 *
426 426
 	 * @param EE_Line_Item $line_item
427 427
 	 * @param string       $text
428
-	 * @return mixed
428
+	 * @return string
429 429
 	 */
430 430
 	private function _total_row( EE_Line_Item $line_item, $text = '' ) {
431 431
 		// start of row
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 	 *
447 447
 	 * @param EE_Line_Item $line_item
448 448
 	 * @param array        $options
449
-	 * @return mixed
449
+	 * @return string
450 450
 	 */
451 451
 	private function _payments_and_amount_owing_rows( EE_Line_Item $line_item, $options = array() ) {
452 452
 		$html = '';
Please login to merge, or discard this patch.
core/db_models/EEM_Extra_Meta.model.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -26,16 +26,16 @@  discard block
 block discarded – undo
26 26
  *
27 27
  * ------------------------------------------------------------------------
28 28
  */
29
-require_once ( EE_MODELS . 'EEM_Base.model.php' );
29
+require_once (EE_MODELS.'EEM_Base.model.php');
30 30
 
31 31
 class EEM_Extra_Meta extends EEM_Base {
32 32
 
33 33
   	// private instance of the Attendee object
34 34
 	protected static $_instance = NULL;
35 35
 
36
-	protected function __construct( $timezone = NULL ) {
37
-		$this->singular_item = __('Extra Meta','event_espresso');
38
-		$this->plural_item = __('Extra Metas','event_espresso');
36
+	protected function __construct($timezone = NULL) {
37
+		$this->singular_item = __('Extra Meta', 'event_espresso');
38
+		$this->plural_item = __('Extra Metas', 'event_espresso');
39 39
 		$this->_tables = array(
40 40
 			'Extra_Meta'=> new EE_Primary_Table('esp_extra_meta', 'EXM_ID')
41 41
 		);
@@ -50,13 +50,13 @@  discard block
 block discarded – undo
50 50
 
51 51
 			));
52 52
 		$this->_model_relations = array();
53
-		foreach($models_this_can_attach_to as $model){
53
+		foreach ($models_this_can_attach_to as $model) {
54 54
 			$this->_model_relations[$model] = new EE_Belongs_To_Any_Relation();
55 55
 		}
56
-		foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ) {
57
-			$this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta( 'EXM_key', 'EXM_value' );
56
+		foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
57
+			$this->_cap_restriction_generators[$cap_context] = new EE_Restriction_Generator_Meta('EXM_key', 'EXM_value');
58 58
 		}
59
-		parent::__construct( $timezone );
59
+		parent::__construct($timezone);
60 60
 	}
61 61
 
62 62
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3
+}
2 4
 /**
3 5
  * Event Espresso
4 6
  *
Please login to merge, or discard this patch.
core/db_models/EEM_Post_Meta.model.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -31,20 +31,20 @@  discard block
 block discarded – undo
31 31
  *
32 32
  * ------------------------------------------------------------------------
33 33
  */
34
-require_once ( EE_MODELS . 'EEM_Base.model.php' );
34
+require_once (EE_MODELS.'EEM_Base.model.php');
35 35
 
36 36
 class EEM_Post_Meta extends EEM_Base {
37 37
 
38 38
   	// private instance of the EE_Post_Meta object
39 39
 	protected static $_instance = NULL;
40 40
 
41
-	protected function __construct( $timezone = NULL ) {
42
-		$this->singular_item = __('Post Meta','event_espresso');
43
-		$this->plural_item = __('Post Metas','event_espresso');
41
+	protected function __construct($timezone = NULL) {
42
+		$this->singular_item = __('Post Meta', 'event_espresso');
43
+		$this->plural_item = __('Post Metas', 'event_espresso');
44 44
 		$this->_tables = array(
45 45
 			'Post_Meta'=> new EE_Primary_Table('postmeta', 'meta_id')
46 46
 		);
47
-		$models_this_can_attach_to = array_keys( EE_Registry::instance()->cpt_models() );
47
+		$models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
48 48
 		$this->_fields = array(
49 49
 			'Post_Meta'=>array(
50 50
 				'meta_id'=>new EE_Primary_Key_Int_Field('meta_id', __("Meta ID", "event_espresso")),
@@ -53,13 +53,13 @@  discard block
 block discarded – undo
53 53
 				'meta_value'=>new EE_Maybe_Serialized_Text_Field('meta_value', __("Meta Value", "event_espresso"), true)
54 54
 			));
55 55
 		$this->_model_relations = array();
56
-		foreach($models_this_can_attach_to as $model){
56
+		foreach ($models_this_can_attach_to as $model) {
57 57
 			$this->_model_relations[$model] = new EE_Belongs_To_Relation();
58 58
 		}
59
-		foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ) {
60
-			$this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta( 'meta_key', 'meta_value' );
59
+		foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
60
+			$this->_cap_restriction_generators[$cap_context] = new EE_Restriction_Generator_Meta('meta_key', 'meta_value');
61 61
 		}
62
-		parent::__construct( $timezone );
62
+		parent::__construct($timezone);
63 63
 	}
64 64
 
65 65
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3
+}
2 4
 /**
3 5
  * Event Espresso
4 6
  *
Please login to merge, or discard this patch.
core/db_models/strategies/EE_Restriction_Generator_Meta.strategy.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
3
-	exit( 'No direct script access allowed' );
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  * @author				Mike Nelson
15 15
  *
16 16
  */
17
-class EE_Restriction_Generator_Meta extends EE_Restriction_Generator_Base{
17
+class EE_Restriction_Generator_Meta extends EE_Restriction_Generator_Base {
18 18
 
19 19
 	/**
20 20
 	 *
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 * @param string $key_field_name
34 34
 	 * @param string $value_field_name
35 35
 	 */
36
-	public function __construct( $key_field_name, $value_field_name ) {
36
+	public function __construct($key_field_name, $value_field_name) {
37 37
 		$this->_key_field_name = $key_field_name;
38 38
 		$this->_value_field_name = $value_field_name;
39 39
 	}
@@ -45,21 +45,21 @@  discard block
 block discarded – undo
45 45
 	 * @throws EE_Error
46 46
 	 */
47 47
 	protected function _generate_restrictions() {
48
-		$whitelisted_meta_keys = apply_filters( 'FHEE__EE_Restriction_Generator_Meta___generate_restrictions__whitelisted_meta_keys', array() );
49
-		$blacklisted_meta_keys = apply_filters( 'FHEE__EE_Restriction_Generator_Meta___generate_restrictions__blacklisted_meta_keys', array() );
48
+		$whitelisted_meta_keys = apply_filters('FHEE__EE_Restriction_Generator_Meta___generate_restrictions__whitelisted_meta_keys', array());
49
+		$blacklisted_meta_keys = apply_filters('FHEE__EE_Restriction_Generator_Meta___generate_restrictions__blacklisted_meta_keys', array());
50 50
 		$conditions = array(
51
-			$this->_key_field_name => array( 'NOT_LIKE', "\\\\_%" ),//each slash is escaped because we are using double quotes, and 
51
+			$this->_key_field_name => array('NOT_LIKE', "\\\\_%"), //each slash is escaped because we are using double quotes, and 
52 52
 			//stripslashes will be called on this because the models assume this is from user input
53
-			$this->_value_field_name => array( 'NOT_REGEXP', '^[aOs]:[\d]:.*$')					
53
+			$this->_value_field_name => array('NOT_REGEXP', '^[aOs]:[\d]:.*$')					
54 54
 		);
55
-		if( ! empty( $blacklisted_meta_keys ) ) {
56
-			$conditions[ $this->_key_field_name . '*blacklisted' ] = array( 'NOT_IN', $blacklisted_meta_keys );
55
+		if ( ! empty($blacklisted_meta_keys)) {
56
+			$conditions[$this->_key_field_name.'*blacklisted'] = array('NOT_IN', $blacklisted_meta_keys);
57 57
 		}
58
-		if( ! empty( $whitelisted_meta_keys ) ) {
58
+		if ( ! empty($whitelisted_meta_keys)) {
59 59
 			$conditions = array(
60 60
 				'OR*whitelisted-or-normal' => array(
61 61
 					'AND' => $conditions,
62
-					$this->_key_field_name . '*whitelisted' => array( 'IN', $whitelisted_meta_keys ) 
62
+					$this->_key_field_name.'*whitelisted' => array('IN', $whitelisted_meta_keys) 
63 63
 				)
64 64
 			);
65 65
 		}
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 			//only allow access to non-protected metas if they're an admin
68 68
 			EE_Restriction_Generator_Base::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions(),
69 69
 			//don't allow access to protected metas to anyone. If they want that, don't apply caps to the query
70
-			'apply-to-all-queries-using-caps' => new EE_Default_Where_Conditions( $conditions ),
70
+			'apply-to-all-queries-using-caps' => new EE_Default_Where_Conditions($conditions),
71 71
 		);
72 72
 	}
73 73
 }
Please login to merge, or discard this patch.
help_tabs/payment_methods_overview_paypalstandard.help_tab.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 <?php _e('Adjust the settings for the PayPal Standard payment gateway.', 'event_espresso'); ?>
4 4
 </p>
5 5
 <p>
6
-<?php printf( __( 'See %1$shere%2$s for list of currencies supported by Paypal Standard.', 'event_espresso' ), "<a href='https://www.paypal.com/multicurrency' target='_blank'>","</a>" ); ?>
6
+<?php printf(__('See %1$shere%2$s for list of currencies supported by Paypal Standard.', 'event_espresso'), "<a href='https://www.paypal.com/multicurrency' target='_blank'>", "</a>"); ?>
7 7
 </p>
8 8
 <h3><?php _e('PayPal Standard Settings', 'event_espresso'); ?></h3>
9 9
 <ul>
@@ -21,18 +21,18 @@  discard block
 block discarded – undo
21 21
 </li>
22 22
 <li>
23 23
 <strong><?php _e('PayPal Calculates Taxes', 'event_espresso'); ?></strong><br />
24
-<?php printf( __('If set to "Yes", we will indicate to PayPal that it should calculate the taxes on the order and add it. This means PayPal\'s tax calculations will be used on the order instead of Event Espresso\'s. %1$sRead here for more information.%2$s', 'event_espresso'), "<a href='https://www.paypal.com/ca/cgi-bin/webscr?cmd=xpt/Marketing/shipping/EasyCalculateShipAndTax-outside' target='_blank'>", '</a>' ); ?><br/>
25
-<?php _e( 'Note: It may confuse users if Event Espresso initially calculates taxes on the order, and then they go to PayPal and it calculates taxes differently. So it is recommended that if PayPal is calculating taxes, that you do not set any taxes in Event Espresso.', 'event_espresso' );?>
24
+<?php printf(__('If set to "Yes", we will indicate to PayPal that it should calculate the taxes on the order and add it. This means PayPal\'s tax calculations will be used on the order instead of Event Espresso\'s. %1$sRead here for more information.%2$s', 'event_espresso'), "<a href='https://www.paypal.com/ca/cgi-bin/webscr?cmd=xpt/Marketing/shipping/EasyCalculateShipAndTax-outside' target='_blank'>", '</a>'); ?><br/>
25
+<?php _e('Note: It may confuse users if Event Espresso initially calculates taxes on the order, and then they go to PayPal and it calculates taxes differently. So it is recommended that if PayPal is calculating taxes, that you do not set any taxes in Event Espresso.', 'event_espresso'); ?>
26 26
 </li>
27 27
 <li>
28 28
 <strong><?php _e('PayPal Calculates Shipping', 'event_espresso'); ?></strong><br />
29 29
 <?php _e('Similar to the "PayPal Calculates Taxes" setting, if this is set to "Yes", we will indicate to PayPal that it should calculate the shipping on each payment (if there are multiple payments for a single transaction, PayPal is permitted to add shipping charges to each payment.)', 'event_espresso'); ?><br/>
30
-<?php _e( 'Important Note: PayPal will ONLY calculate shipping on an order if "Shipping Address Options" is set to "Prompt for an Address" (otherwise how will PayPal know how much to charge for shipping if it doesn\'t know where it\'s shipping to?)', 'event_espresso' );?>
30
+<?php _e('Important Note: PayPal will ONLY calculate shipping on an order if "Shipping Address Options" is set to "Prompt for an Address" (otherwise how will PayPal know how much to charge for shipping if it doesn\'t know where it\'s shipping to?)', 'event_espresso'); ?>
31 31
 <li>
32
-<strong><?php _e( 'Notes Regarding Paypal Taxes and Shipping', 'event_espresso' );?></strong><br/>
33
-<?php _e( 'If you want PayPal to calculate taxes and shipping on an order, those changes will NOT appear during the initial registration process until the user is redirected to PayPal for payment.', 'event_espresso' );?><br/>
34
-<?php _e( 'However, after the user has returned from PayPal, their order in Event Espresso will be updated with the new taxes and added shipping charges (e.g. it will appear on their receipt.)', 'event_espresso' );?><br/>
35
-<?php _e( 'Also Note: In order for PayPal to properly calculate taxes and shipping, they need to receive the entire order at the same time. So if a user goes to make a payment using PayPal, and their order somehow already has a payment on it, PayPal CANNOT calculate taxes or shipping on that order.', 'event_espresso' );?>
32
+<strong><?php _e('Notes Regarding Paypal Taxes and Shipping', 'event_espresso'); ?></strong><br/>
33
+<?php _e('If you want PayPal to calculate taxes and shipping on an order, those changes will NOT appear during the initial registration process until the user is redirected to PayPal for payment.', 'event_espresso'); ?><br/>
34
+<?php _e('However, after the user has returned from PayPal, their order in Event Espresso will be updated with the new taxes and added shipping charges (e.g. it will appear on their receipt.)', 'event_espresso'); ?><br/>
35
+<?php _e('Also Note: In order for PayPal to properly calculate taxes and shipping, they need to receive the entire order at the same time. So if a user goes to make a payment using PayPal, and their order somehow already has a payment on it, PayPal CANNOT calculate taxes or shipping on that order.', 'event_espresso'); ?>
36 36
 </li>
37 37
 <li>
38 38
 <strong><?php _e('Shipping Address Options', 'event_espresso'); ?></strong><br />
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/Base.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@
 block discarded – undo
129 129
 	 *
130 130
 	 * @param string $route
131 131
 	 * @param string $regex
132
-	 * @param array  $match_keys EXCLUDING matching the entire regex
132
+	 * @param string[]  $match_keys EXCLUDING matching the entire regex
133 133
 	 * @return array where  $match_keys are the keys (the first value of $match_keys
134 134
 	 * becomes the first key of the return value, etc. Eg passing in $match_keys of
135 135
 	 * array( 'model', 'id' ), will, if the regex is successful, will return
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 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
 
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
 /**
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	protected $_requested_version;
37 37
 
38 38
 	public function __construct() {
39
-		$this->_debug_mode = defined( 'EE_REST_API_DEBUG_MODE' ) ? EE_REST_API_DEBUG_MODE : false;
39
+		$this->_debug_mode = defined('EE_REST_API_DEBUG_MODE') ? EE_REST_API_DEBUG_MODE : false;
40 40
 	}
41 41
 
42 42
 
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 * Sets the version the user requested
45 45
 	 * @param string $version eg '4.8'
46 46
 	 */
47
-	public function set_requested_version( $version ) {
47
+	public function set_requested_version($version) {
48 48
 		$this->_requested_version = $version;
49 49
 	}
50 50
 
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	 * @param string $key
54 54
 	 * @param string|array $info
55 55
 	 */
56
-	protected function _set_debug_info( $key, $info ){
57
-		$this->_debug_info[ $key ] = $info;
56
+	protected function _set_debug_info($key, $info) {
57
+		$this->_debug_info[$key] = $info;
58 58
 	}
59 59
 
60 60
 
@@ -69,52 +69,52 @@  discard block
 block discarded – undo
69 69
 	 * @param array|\WP_Error|\Exception $response
70 70
 	 * @return \WP_REST_Response
71 71
 	 */
72
-	public function send_response( $response ) {
73
-		if( $response instanceof \Exception ) {
74
-			$response = new \WP_Error( $response->getCode(), $response->getMessage() );
72
+	public function send_response($response) {
73
+		if ($response instanceof \Exception) {
74
+			$response = new \WP_Error($response->getCode(), $response->getMessage());
75 75
 		}
76
-		if( $response instanceof \WP_Error ) {
76
+		if ($response instanceof \WP_Error) {
77 77
 			//we want to send a "normal"-looking WP error response, but we also
78 78
 			//want to add headers. It doesn't seem WP API 1.2 supports this.
79 79
 			//I'd like to use WP_JSON_Server::error_to_response() but its protected
80 80
 			//so here's most of it copy-and-pasted :P
81 81
 			$error_data = $response->get_error_data();
82
-			if ( is_array( $error_data ) && isset( $error_data['status'] ) ) {
82
+			if (is_array($error_data) && isset($error_data['status'])) {
83 83
 				$status = $error_data['status'];
84 84
 			} else {
85 85
 				$status = 500;
86 86
 			}
87 87
 
88 88
 			$errors = array();
89
-			foreach ( (array) $response->errors as $code => $messages ) {
90
-				foreach ( (array) $messages as $message ) {
89
+			foreach ((array) $response->errors as $code => $messages) {
90
+				foreach ((array) $messages as $message) {
91 91
 					$errors[] = array(
92 92
 						'code'    => $code,
93 93
 						'message' => $message,
94
-						'data'    => $response->get_error_data( $code )
94
+						'data'    => $response->get_error_data($code)
95 95
 					);
96 96
 				}
97 97
 			}
98
-			$data = isset( $errors[0] ) ? $errors[0] : array();
99
-			if ( count( $errors ) > 1 ) {
98
+			$data = isset($errors[0]) ? $errors[0] : array();
99
+			if (count($errors) > 1) {
100 100
 				// Remove the primary error.
101
-				array_shift( $errors );
101
+				array_shift($errors);
102 102
 				$data['additional_errors'] = $errors;
103 103
 			}
104
-			$rest_response = new \WP_REST_Response( $data, $status );
105
-		}else{
106
-			$rest_response = new \WP_REST_Response( $response, 200 );
104
+			$rest_response = new \WP_REST_Response($data, $status);
105
+		} else {
106
+			$rest_response = new \WP_REST_Response($response, 200);
107 107
 		}
108 108
 		$headers = array();
109
-		if( $this->_debug_mode && is_array( $this->_debug_info ) ) {
110
-			foreach( $this->_debug_info  as $debug_key => $debug_info ) {
111
-				if( is_array( $debug_info ) ) {
112
-					$debug_info = json_encode( $debug_info );
109
+		if ($this->_debug_mode && is_array($this->_debug_info)) {
110
+			foreach ($this->_debug_info  as $debug_key => $debug_info) {
111
+				if (is_array($debug_info)) {
112
+					$debug_info = json_encode($debug_info);
113 113
 				}
114
-				$headers[ 'X-EE4-Debug-' . ucwords( $debug_key ) ] = $debug_info;
114
+				$headers['X-EE4-Debug-'.ucwords($debug_key)] = $debug_info;
115 115
 			}
116 116
 		}
117
-		$rest_response->set_headers( $headers );
117
+		$rest_response->set_headers($headers);
118 118
 		return $rest_response;
119 119
 	}
120 120
 
@@ -136,23 +136,23 @@  discard block
 block discarded – undo
136 136
 	 * array( 'model' => 'foo', 'id' => 'bar' )
137 137
 	 * @throws \EE_Error if it couldn't be parsed
138 138
 	 */
139
-	public function parse_route( $route, $regex, $match_keys ) {
139
+	public function parse_route($route, $regex, $match_keys) {
140 140
 		$indexed_matches = array();
141
-		$success = preg_match( $regex, $route, $matches );
142
-		if(
143
-			is_array( $matches ) ) {
141
+		$success = preg_match($regex, $route, $matches);
142
+		if (
143
+			is_array($matches) ) {
144 144
 			//skip the overall regex match. Who cares
145
-			for( $i = 1; $i <= count( $match_keys ); $i++ ) {
146
-				if( ! isset( $matches[ $i ] ) ) {
145
+			for ($i = 1; $i <= count($match_keys); $i++) {
146
+				if ( ! isset($matches[$i])) {
147 147
 					$success = false;
148 148
 				} else {
149
-					$indexed_matches[ $match_keys[ $i - 1 ] ] = $matches[ $i ];
149
+					$indexed_matches[$match_keys[$i - 1]] = $matches[$i];
150 150
 				}
151 151
 			}
152 152
 		}
153
-		if( ! $success ) {
153
+		if ( ! $success) {
154 154
 			throw new \EE_Error(
155
-				__( 'We could not parse the URL. Please contact Event Espresso Support', 'event_espresso' ),
155
+				__('We could not parse the URL. Please contact Event Espresso Support', 'event_espresso'),
156 156
 				'endpoint_parsing_error'
157 157
 			);
158 158
 		}
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@
 block discarded – undo
102 102
 				$data['additional_errors'] = $errors;
103 103
 			}
104 104
 			$rest_response = new \WP_REST_Response( $data, $status );
105
-		}else{
105
+		} else{
106 106
 			$rest_response = new \WP_REST_Response( $response, 200 );
107 107
 		}
108 108
 		$headers = array();
Please login to merge, or discard this patch.
core/libraries/rest_api/Capabilities.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\libraries\rest_api;
3
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 /**
@@ -21,16 +21,16 @@  discard block
 block discarded – undo
21 21
 	 * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts()
22 22
 	 * @return boolean
23 23
 	 */
24
-	public static function current_user_has_partial_access_to( $model, $model_context = \EEM_Base::caps_read ) {
25
-		if( apply_filters( 'FHEE__Capabilities__current_user_has_partial_access_to__override_begin', false, $model, $model ) ) {
24
+	public static function current_user_has_partial_access_to($model, $model_context = \EEM_Base::caps_read) {
25
+		if (apply_filters('FHEE__Capabilities__current_user_has_partial_access_to__override_begin', false, $model, $model)) {
26 26
 			return true;
27 27
 		}
28
-		foreach( $model->caps_missing( $model_context ) as $capability_name => $restriction_obj ) {
29
-			if( $restriction_obj instanceof \EE_Return_None_Where_Conditions ){
28
+		foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) {
29
+			if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) {
30 30
 				return false;
31 31
 			}
32 32
 		}
33
-		if( apply_filters( 'FHEE__Capabilities__current_user_has_partial_access_to__override_end', false, $model, $model ) ) {
33
+		if (apply_filters('FHEE__Capabilities__current_user_has_partial_access_to__override_end', false, $model, $model)) {
34 34
 			return false;
35 35
 		}
36 36
 		return true;
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	 * @param string $request_type one of the constants on WP_JSON_Server
44 44
 	 * @return array
45 45
 	 */
46
-	public static function get_missing_permissions( $model, $request_type = \EEM_Base::caps_read ) {
47
-		return $model->caps_missing( $request_type );
46
+	public static function get_missing_permissions($model, $request_type = \EEM_Base::caps_read) {
47
+		return $model->caps_missing($request_type);
48 48
 	}
49 49
 	/**
50 50
 	 * Gets a string of all the capabilities the current user is missing that affected
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 	 * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts()
55 55
 	 * @return string
56 56
 	 */
57
-	public static function get_missing_permissions_string( $model, $model_context = \EEM_Base::caps_read ) {
58
-		return implode(',', array_keys( self::get_missing_permissions( $model, $model_context ) ) );
57
+	public static function get_missing_permissions_string($model, $model_context = \EEM_Base::caps_read) {
58
+		return implode(',', array_keys(self::get_missing_permissions($model, $model_context)));
59 59
 	}
60 60
 
61 61
 	/**
@@ -66,25 +66,25 @@  discard block
 block discarded – undo
66 66
 	 * @param Model_Version_Info $model_version_info
67 67
 	 * @return array ready for converting into json
68 68
 	 */
69
-	public static function filter_out_inaccessible_entity_fields( $entity,  $model, $request_type, $model_version_info ) {
69
+	public static function filter_out_inaccessible_entity_fields($entity, $model, $request_type, $model_version_info) {
70 70
 		//we only care to do this for frontend reads and when the user can't edit the item
71
-		if(  $request_type !== \EEM_Base::caps_read ||
72
-				$model->exists( array(
73
-					array( $model->primary_key_name() => $entity[ $model->primary_key_name() ] ),
71
+		if ($request_type !== \EEM_Base::caps_read ||
72
+				$model->exists(array(
73
+					array($model->primary_key_name() => $entity[$model->primary_key_name()]),
74 74
 					'default_where_conditions' => 'none',
75
-					'caps' => \EEM_Base::caps_edit ) ) ) {
75
+					'caps' => \EEM_Base::caps_edit ))) {
76 76
 			return $entity;
77 77
 		}
78
-		foreach( $model->field_settings() as $field_name => $field_obj ){
79
-			if( $model_version_info->field_has_rendered_format( $field_obj )
80
-				&& isset( $entity[ $field_name ][ 'raw' ] )
78
+		foreach ($model->field_settings() as $field_name => $field_obj) {
79
+			if ($model_version_info->field_has_rendered_format($field_obj)
80
+				&& isset($entity[$field_name]['raw'])
81 81
 			) {
82
-				unset( $entity[ $field_name ][ 'raw' ] );
82
+				unset($entity[$field_name]['raw']);
83 83
 			}
84 84
 		}
85 85
 		//theoretically we may want to filter out specific fields for specific models
86 86
 
87
-		return apply_filters( 'FHEE__Capabilities__filter_out_inaccessible_entity_fields', $entity, $model, $request_type );
87
+		return apply_filters('FHEE__Capabilities__filter_out_inaccessible_entity_fields', $entity, $model, $request_type);
88 88
 	}
89 89
 }
90 90
 
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/config/Read.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\libraries\rest_api\controllers\config;
3
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 /**
@@ -21,11 +21,11 @@  discard block
 block discarded – undo
21 21
 	 * @param \WP_REST_Request $request
22 22
 	 * @return \EE_Config|\WP_Error
23 23
 	 */
24
-	public static function handle_request( \WP_REST_Request $request) {
24
+	public static function handle_request(\WP_REST_Request $request) {
25 25
 		$cap = \EE_Restriction_Generator_Base::get_default_restrictions_cap();
26
-		if( \EE_Capabilities::instance()->current_user_can( $cap, 'read_over_api' ) ){
26
+		if (\EE_Capabilities::instance()->current_user_can($cap, 'read_over_api')) {
27 27
 			return \EE_Config::instance();
28
-		}else{
28
+		} else {
29 29
 			return new \WP_Error(
30 30
 				'cannot_read_config',
31 31
 				sprintf(
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 					),
36 36
 					$cap
37 37
 				),
38
-				array( 'status' => 403 )
38
+				array('status' => 403)
39 39
 			);
40 40
 		}
41 41
 	}
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 		$cap = \EE_Restriction_Generator_Base::get_default_restrictions_cap();
26 26
 		if( \EE_Capabilities::instance()->current_user_can( $cap, 'read_over_api' ) ){
27 27
 			return \EE_Config::instance();
28
-		}else{
28
+		} else{
29 29
 			return new \WP_Error(
30 30
 				'cannot_read_config',
31 31
 				sprintf(
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/model/Read.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -653,6 +653,10 @@
 block discarded – undo
653 653
 		}
654 654
 		return $model_ready_query_params;
655 655
 	}
656
+
657
+	/**
658
+	 * @param \EEM_Base $model
659
+	 */
656 660
 	public function prepare_rest_query_params_values_for_models( $model,  $query_params ) {
657 661
 		$model_ready_query_params = array();
658 662
 		foreach( $query_params as $key => $value ) {
Please login to merge, or discard this patch.
Braces   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 		){
228 228
 			if( $relation instanceof \EE_Belongs_To_Relation ) {
229 229
 				$related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() );
230
-			}else{
230
+			} else{
231 231
 				$related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() );
232 232
 			}
233 233
 			return new \WP_Error(
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 		}
281 281
 		if( $relation instanceof \EE_Belongs_To_Relation ){
282 282
 			return array_shift( $nice_results );
283
-		}else{
283
+		} else{
284 284
 			return $nice_results;
285 285
 		}
286 286
 	}
@@ -331,26 +331,26 @@  discard block
 block discarded – undo
331 331
 			$field_value = $field_obj->prepare_for_set_from_db( $raw_field_value );
332 332
 			if( $this->is_subclass_of_one(  $field_obj, $this->get_model_version_info()->fields_ignored() ) ){
333 333
 				unset( $result[ $field_name ] );
334
-			}elseif(
334
+			} elseif(
335 335
 				$this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() )
336 336
 			){
337 337
 				$result[ $field_name ] = array(
338 338
 					'raw' => $field_obj->prepare_for_get( $field_value ),
339 339
 					'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value )
340 340
 				);
341
-			}elseif(
341
+			} elseif(
342 342
 				$this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() )
343 343
 			){
344 344
 				$result[ $field_name ] = array(
345 345
 					'raw' => $field_obj->prepare_for_get( $field_value ),
346 346
 					'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value )
347 347
 				);
348
-			}elseif( $field_obj instanceof \EE_Datetime_Field ){
348
+			} elseif( $field_obj instanceof \EE_Datetime_Field ){
349 349
 				if( $raw_field_value instanceof \DateTime ) {
350 350
 					$raw_field_value = $raw_field_value->format( 'c' );
351 351
 				}
352 352
 				$result[ $field_name ] = mysql_to_rfc3339( $raw_field_value );
353
-			}else{
353
+			} else{
354 354
 				$value_prepared = $field_obj->prepare_for_get( $field_value );
355 355
 
356 356
 				$result[ $field_name ] = $value_prepared === INF ? EE_INF_IN_DB : $value_prepared;
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 	public static function get_related_entity_name( $relation_name, $relation_obj ){
480 480
 		if( $relation_obj instanceof \EE_Belongs_To_Relation ) {
481 481
 			return strtolower( $relation_name );
482
-		}else{
482
+		} else{
483 483
 			return \EEH_Inflector::pluralize_and_lower( $relation_name );
484 484
 		}
485 485
 	}
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
 		$valid_contexts = \EEM_Base::valid_cap_contexts();
549 549
 		if( in_array( $context, $valid_contexts )  ){
550 550
 			return $context;
551
-		}else{
551
+		} else{
552 552
 			return \EEM_Base::caps_read;
553 553
 		}
554 554
 	}
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
 			$order_by = $query_parameters[ 'order_by' ];
574 574
 		} elseif ( isset( $query_parameters[ 'orderby' ] ) ) {
575 575
 			$order_by = $query_parameters[ 'orderby' ];
576
-		}else{
576
+		} else{
577 577
 			$order_by = null;
578 578
 		}
579 579
 		if( $order_by !== null ){
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 			$group_by = $query_parameters[ 'group_by' ];
584 584
 		} elseif ( isset( $query_parameters[ 'groupby' ] ) ) {
585 585
 			$group_by = $query_parameters[ 'groupby' ];
586
-		}else{
586
+		} else{
587 587
 			$group_by = null;
588 588
 		}
589 589
 		if( $group_by !== null ){
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 			//limit should be either a string like '23' or '23,43', or an array with two items in it
607 607
 			if( is_string( $query_parameters[ 'limit' ] ) ) {
608 608
 				$limit_array = explode(',', $query_parameters['limit']);
609
-			}else {
609
+			} else {
610 610
 				$limit_array = $query_parameters[ 'limit' ];
611 611
 			}
612 612
 			$sanitized_limit = array();
@@ -622,12 +622,12 @@  discard block
 block discarded – undo
622 622
 				$sanitized_limit[] = intval( $limit_part );
623 623
 			}
624 624
 			$model_query_params[ 'limit' ] = implode( ',', $sanitized_limit );
625
-		}else{
625
+		} else{
626 626
 			$model_query_params[ 'limit' ] = 50;
627 627
 		}
628 628
 		if( isset( $query_parameters[ 'caps' ] ) ) {
629 629
 			$model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] );
630
-		}else{
630
+		} else{
631 631
 			$model_query_params[ 'caps' ] = \EEM_Base::caps_read;
632 632
 		}
633 633
 		return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model );
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 		foreach( $query_params as $key => $value ) {
648 648
 			if( is_array( $value ) ) {
649 649
 				$model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value );
650
-			}else{
650
+			} else{
651 651
 				$model_ready_query_params[ $key ] = $value;
652 652
 			}
653 653
 		}
@@ -689,11 +689,11 @@  discard block
 block discarded – undo
689 689
 					//found the model name at the exact start
690 690
 					$field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include );
691 691
 					$extracted_fields_to_include[] = $field_sans_model_name;
692
-				}elseif( $field_to_include == $model_name ){
692
+				} elseif( $field_to_include == $model_name ){
693 693
 					$extracted_fields_to_include[] = '*';
694 694
 				}
695 695
 			}
696
-		}else{
696
+		} else{
697 697
 			//look for ones with no period
698 698
 			foreach( $includes as $field_to_include ) {
699 699
 				$field_to_include = trim( $field_to_include );
Please login to merge, or discard this patch.
Spacing   +244 added lines, -244 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\Capabilities;
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
 /**
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 
25 25
 	public function __construct() {
26 26
 		parent::__construct();
27
-		\EE_Registry::instance()->load_helper( 'Inflector' );
27
+		\EE_Registry::instance()->load_helper('Inflector');
28 28
 	}
29 29
 
30 30
 	/**
@@ -32,22 +32,22 @@  discard block
 block discarded – undo
32 32
 	 * @param \WP_REST_Request $request
33 33
 	 * @return \WP_REST_Response|\WP_Error
34 34
 	 */
35
-	public static function handle_request_get_all( \WP_REST_Request $request) {
35
+	public static function handle_request_get_all(\WP_REST_Request $request) {
36 36
 		$controller = new Read();
37
-		try{
37
+		try {
38 38
 			$matches = $controller->parse_route(
39 39
 				$request->get_route(),
40
-				'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~',
41
-				array( 'version', 'model' )
40
+				'~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~',
41
+				array('version', 'model')
42 42
 			);
43
-			$controller->set_requested_version( $matches[ 'version' ] );
44
-			$model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] );
45
-			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) {
43
+			$controller->set_requested_version($matches['version']);
44
+			$model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
45
+			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
46 46
 				return $controller->send_response(
47 47
 					new \WP_Error(
48 48
 						'endpoint_parsing_error',
49 49
 						sprintf(
50
-							__( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ),
50
+							__('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'),
51 51
 							$model_name_singular
52 52
 						)
53 53
 					)
@@ -55,12 +55,12 @@  discard block
 block discarded – undo
55 55
 			}
56 56
 			return $controller->send_response(
57 57
 					$controller->get_entities_from_model(
58
-							$controller->get_model_version_info()->load_model( $model_name_singular ),
58
+							$controller->get_model_version_info()->load_model($model_name_singular),
59 59
 							$request
60 60
 					)
61 61
 			);
62
-		} catch( \Exception $e ) {
63
-			return $controller->send_response( $e );
62
+		} catch (\Exception $e) {
63
+			return $controller->send_response($e);
64 64
 		}
65 65
 	}
66 66
 
@@ -70,21 +70,21 @@  discard block
 block discarded – undo
70 70
 	 * @param \WP_Rest_Request $request
71 71
 	 * @return \WP_REST_Response|\WP_Error
72 72
 	 */
73
-	public static function handle_request_get_one( \WP_Rest_Request $request ) {
73
+	public static function handle_request_get_one(\WP_Rest_Request $request) {
74 74
 		$controller = new Read();
75
-		try{
75
+		try {
76 76
 			$matches = $controller->parse_route(
77 77
 				$request->get_route(),
78
-				'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~',
79
-				array( 'version', 'model', 'id' ) );
80
-			$controller->set_requested_version( $matches[ 'version' ] );
81
-			$model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] );
82
-			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) {
78
+				'~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~',
79
+				array('version', 'model', 'id') );
80
+			$controller->set_requested_version($matches['version']);
81
+			$model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
82
+			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
83 83
 				return $controller->send_response(
84 84
 					new \WP_Error(
85 85
 						'endpoint_parsing_error',
86 86
 						sprintf(
87
-							__( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ),
87
+							__('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'),
88 88
 							$model_name_singular
89 89
 						)
90 90
 					)
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
 			}
93 93
 			return $controller->send_response(
94 94
 					$controller->get_entity_from_model(
95
-							$controller->get_model_version_info()->load_model( $model_name_singular ),
95
+							$controller->get_model_version_info()->load_model($model_name_singular),
96 96
 							$request
97 97
 						)
98 98
 				);
99
-		} catch( \Exception $e ) {
100
-			return $controller->send_response( $e );
99
+		} catch (\Exception $e) {
100
+			return $controller->send_response($e);
101 101
 		}
102 102
 	}
103 103
 
@@ -109,35 +109,35 @@  discard block
 block discarded – undo
109 109
 	 * @param \WP_REST_Request $request
110 110
 	 * @return \WP_REST_Response|\WP_Error
111 111
 	 */
112
-	public static function handle_request_get_related( \WP_REST_Request $request ) {
112
+	public static function handle_request_get_related(\WP_REST_Request $request) {
113 113
 		$controller = new Read();
114
-		try{
114
+		try {
115 115
 			$matches = $controller->parse_route(
116 116
 				$request->get_route(),
117
-				'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~',
118
-				array( 'version', 'model', 'id', 'related_model' )
117
+				'~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~',
118
+				array('version', 'model', 'id', 'related_model')
119 119
 			);
120
-			$controller->set_requested_version( $matches[ 'version' ] );
121
-			$main_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] );
122
-			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $main_model_name_singular ) ) {
120
+			$controller->set_requested_version($matches['version']);
121
+			$main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
122
+			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) {
123 123
 				return $controller->send_response(
124 124
 					new \WP_Error(
125 125
 						'endpoint_parsing_error',
126 126
 						sprintf(
127
-							__( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ),
127
+							__('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'),
128 128
 							$main_model_name_singular
129 129
 						)
130 130
 					)
131 131
 				);
132 132
 			}
133
-			$main_model = $controller->get_model_version_info()->load_model( $main_model_name_singular );
134
-			$related_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'related_model' ] );
135
-			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) {
133
+			$main_model = $controller->get_model_version_info()->load_model($main_model_name_singular);
134
+			$related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']);
135
+			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) {
136 136
 				return $controller->send_response(
137 137
 					new \WP_Error(
138 138
 						'endpoint_parsing_error',
139 139
 						sprintf(
140
-							__( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ),
140
+							__('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'),
141 141
 							$related_model_name_singular
142 142
 						)
143 143
 					)
@@ -146,13 +146,13 @@  discard block
 block discarded – undo
146 146
 
147 147
 			return $controller->send_response(
148 148
 					$controller->get_entities_from_relation(
149
-						$request->get_param( 'id' ),
150
-						$main_model->related_settings_for( $related_model_name_singular ) ,
149
+						$request->get_param('id'),
150
+						$main_model->related_settings_for($related_model_name_singular),
151 151
 						$request
152 152
 					)
153 153
 				);
154
-		} catch( \Exception $e ) {
155
-			return $controller->send_response( $e );
154
+		} catch (\Exception $e) {
155
+			return $controller->send_response($e);
156 156
 		}
157 157
 	}
158 158
 
@@ -165,30 +165,30 @@  discard block
 block discarded – undo
165 165
 	 * @param \WP_REST_Request $request
166 166
 	 * @return array
167 167
 	 */
168
-	public function get_entities_from_model( $model, $request) {
169
-		$query_params = $this->create_model_query_params( $model, $request->get_params() );
170
-		if( ! Capabilities::current_user_has_partial_access_to( $model, $query_params[ 'caps' ] ) ) {
171
-			$model_name_plural = \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() );
168
+	public function get_entities_from_model($model, $request) {
169
+		$query_params = $this->create_model_query_params($model, $request->get_params());
170
+		if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) {
171
+			$model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
172 172
 			return new \WP_Error(
173
-				sprintf( 'rest_%s_cannot_list', $model_name_plural ),
173
+				sprintf('rest_%s_cannot_list', $model_name_plural),
174 174
 				sprintf(
175
-					__( 'Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso' ),
175
+					__('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'),
176 176
 					$model_name_plural,
177
-					Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] )
177
+					Capabilities::get_missing_permissions_string($model, $query_params['caps'])
178 178
 				),
179
-				array( 'status' => 403 )
179
+				array('status' => 403)
180 180
 			);
181 181
 		}
182 182
 
183
-		$this->_set_debug_info( 'model query params', $query_params );
184
-		$results = $model->get_all_wpdb_results( $query_params );
183
+		$this->_set_debug_info('model query params', $query_params);
184
+		$results = $model->get_all_wpdb_results($query_params);
185 185
 		$nice_results = array( );
186
-		foreach ( $results as $result ) {
187
-			$nice_results[ ] = $this->create_entity_from_wpdb_result(
186
+		foreach ($results as $result) {
187
+			$nice_results[] = $this->create_entity_from_wpdb_result(
188 188
 					$model,
189 189
 					$result,
190
-					$request->get_param( 'include' ),
191
-					$query_params[ 'caps' ]
190
+					$request->get_param('include'),
191
+					$query_params['caps']
192 192
 				);
193 193
 		}
194 194
 		return $nice_results;
@@ -205,82 +205,82 @@  discard block
 block discarded – undo
205 205
 	 * @param \WP_REST_Request $request
206 206
 	 * @return array
207 207
 	 */
208
-	public function get_entities_from_relation( $id,  $relation, $request ) {
209
-		$context = $this->validate_context( $request->get_param( 'caps' ));
208
+	public function get_entities_from_relation($id, $relation, $request) {
209
+		$context = $this->validate_context($request->get_param('caps'));
210 210
 		$model = $relation->get_this_model();
211 211
 		$related_model = $relation->get_other_model();
212 212
 		//check if they can access the 1st model object
213
-		$query_params = array( array( $model->primary_key_name() => $id ),'limit' => 1 );
214
-		if( $model instanceof \EEM_Soft_Delete_Base ){
213
+		$query_params = array(array($model->primary_key_name() => $id), 'limit' => 1);
214
+		if ($model instanceof \EEM_Soft_Delete_Base) {
215 215
 			$query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params);
216 216
 		}
217 217
 		$restricted_query_params = $query_params;
218
-		$restricted_query_params[ 'caps' ] = $context;
219
-		$this->_set_debug_info( 'main model query params', $restricted_query_params );
220
-		$this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $related_model, $context ) );
218
+		$restricted_query_params['caps'] = $context;
219
+		$this->_set_debug_info('main model query params', $restricted_query_params);
220
+		$this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context));
221 221
 
222
-		if(
222
+		if (
223 223
 			! (
224
-				Capabilities::current_user_has_partial_access_to( $related_model, $context )
225
-				&& $model->exists( $restricted_query_params )
224
+				Capabilities::current_user_has_partial_access_to($related_model, $context)
225
+				&& $model->exists($restricted_query_params)
226 226
 			)
227
-		){
228
-			if( $relation instanceof \EE_Belongs_To_Relation ) {
229
-				$related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() );
230
-			}else{
231
-				$related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() );
227
+		) {
228
+			if ($relation instanceof \EE_Belongs_To_Relation) {
229
+				$related_model_name_maybe_plural = strtolower($related_model->get_this_model_name());
230
+			} else {
231
+				$related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name());
232 232
 			}
233 233
 			return new \WP_Error(
234
-				sprintf( 'rest_%s_cannot_list', $related_model_name_maybe_plural ),
234
+				sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural),
235 235
 				sprintf(
236
-					__(	'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso' ),
236
+					__('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso'),
237 237
 					$related_model_name_maybe_plural,
238 238
 					$relation->get_this_model()->get_this_model_name(),
239 239
 					implode(
240 240
 						',',
241 241
 						array_keys(
242
-							Capabilities::get_missing_permissions( $related_model, $context )
242
+							Capabilities::get_missing_permissions($related_model, $context)
243 243
 						)
244 244
 					)
245 245
 				),
246
-				array( 'status' => 403 )
246
+				array('status' => 403)
247 247
 			);
248 248
 		}
249
-		$query_params = $this->create_model_query_params( $relation->get_other_model(), $request->get_params() );
250
-		$query_params[0][ $relation->get_this_model()->get_this_model_name() . '.' . $relation->get_this_model()->primary_key_name() ] = $id;
251
-		$query_params[ 'default_where_conditions' ] = 'none';
252
-		$query_params[ 'caps' ] = $context;
253
-		$this->_set_debug_info( 'model query params', $query_params );
254
-		$results = $relation->get_other_model()->get_all_wpdb_results( $query_params );
249
+		$query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params());
250
+		$query_params[0][$relation->get_this_model()->get_this_model_name().'.'.$relation->get_this_model()->primary_key_name()] = $id;
251
+		$query_params['default_where_conditions'] = 'none';
252
+		$query_params['caps'] = $context;
253
+		$this->_set_debug_info('model query params', $query_params);
254
+		$results = $relation->get_other_model()->get_all_wpdb_results($query_params);
255 255
 		$nice_results = array();
256
-		foreach( $results as $result ) {
256
+		foreach ($results as $result) {
257 257
 			$nice_result = $this->create_entity_from_wpdb_result(
258 258
 				$relation->get_other_model(),
259 259
 				$result,
260
-				$request->get_param( 'include' ),
261
-				$query_params[ 'caps' ]
260
+				$request->get_param('include'),
261
+				$query_params['caps']
262 262
 			);
263
-			if( $relation instanceof \EE_HABTM_Relation ) {
263
+			if ($relation instanceof \EE_HABTM_Relation) {
264 264
 				//put the unusual stuff (properties from the HABTM relation) first, and make sure
265 265
 				//if there are conflicts we prefer the properties from the main model
266 266
 				$join_model_result = $this->create_entity_from_wpdb_result(
267 267
 					$relation->get_join_model(),
268 268
 					$result,
269
-					$request->get_param( 'include' ),
270
-					$query_params[ 'caps' ]
269
+					$request->get_param('include'),
270
+					$query_params['caps']
271 271
 				);
272
-				$joined_result = array_merge( $nice_result, $join_model_result );
272
+				$joined_result = array_merge($nice_result, $join_model_result);
273 273
 				//but keep the meta stuff from the main model
274
-				if( isset( $nice_result['meta'] ) ){
274
+				if (isset($nice_result['meta'])) {
275 275
 					$joined_result['meta'] = $nice_result['meta'];
276 276
 				}
277 277
 				$nice_result = $joined_result;
278 278
 			}
279 279
 			$nice_results[] = $nice_result;
280 280
 		}
281
-		if( $relation instanceof \EE_Belongs_To_Relation ){
282
-			return array_shift( $nice_results );
283
-		}else{
281
+		if ($relation instanceof \EE_Belongs_To_Relation) {
282
+			return array_shift($nice_results);
283
+		} else {
284 284
 			return $nice_results;
285 285
 		}
286 286
 	}
@@ -317,110 +317,110 @@  discard block
 block discarded – undo
317 317
 	 * @param string $context one of the return values from EEM_Base::valid_cap_contexts()
318 318
 	 * @return array ready for being converted into json for sending to client
319 319
 	 */
320
-	public function create_entity_from_wpdb_result( $model, $db_row, $include, $context ) {
321
-		if( $include == null ) {
320
+	public function create_entity_from_wpdb_result($model, $db_row, $include, $context) {
321
+		if ($include == null) {
322 322
 			$include = '*';
323 323
 		}
324
-		if( $context == null ) {
324
+		if ($context == null) {
325 325
 			$context = \EEM_Base::caps_read;
326 326
 		}
327
-		$result = $model->deduce_fields_n_values_from_cols_n_values( $db_row );
328
-		$result = array_intersect_key( $result, $this->get_model_version_info()->fields_on_model_in_this_version( $model ) );
329
-		foreach( $result as $field_name => $raw_field_value ) {
327
+		$result = $model->deduce_fields_n_values_from_cols_n_values($db_row);
328
+		$result = array_intersect_key($result, $this->get_model_version_info()->fields_on_model_in_this_version($model));
329
+		foreach ($result as $field_name => $raw_field_value) {
330 330
 			$field_obj = $model->field_settings_for($field_name);
331
-			$field_value = $field_obj->prepare_for_set_from_db( $raw_field_value );
332
-			if( $this->is_subclass_of_one(  $field_obj, $this->get_model_version_info()->fields_ignored() ) ){
333
-				unset( $result[ $field_name ] );
334
-			}elseif(
335
-				$this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() )
336
-			){
337
-				$result[ $field_name ] = array(
338
-					'raw' => $field_obj->prepare_for_get( $field_value ),
339
-					'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value )
331
+			$field_value = $field_obj->prepare_for_set_from_db($raw_field_value);
332
+			if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) {
333
+				unset($result[$field_name]);
334
+			}elseif (
335
+				$this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format())
336
+			) {
337
+				$result[$field_name] = array(
338
+					'raw' => $field_obj->prepare_for_get($field_value),
339
+					'rendered' => $field_obj->prepare_for_pretty_echoing($field_value)
340 340
 				);
341
-			}elseif(
342
-				$this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() )
343
-			){
344
-				$result[ $field_name ] = array(
345
-					'raw' => $field_obj->prepare_for_get( $field_value ),
346
-					'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value )
341
+			}elseif (
342
+				$this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format())
343
+			) {
344
+				$result[$field_name] = array(
345
+					'raw' => $field_obj->prepare_for_get($field_value),
346
+					'pretty' => $field_obj->prepare_for_pretty_echoing($field_value)
347 347
 				);
348
-			}elseif( $field_obj instanceof \EE_Datetime_Field ){
349
-				if( $raw_field_value instanceof \DateTime ) {
350
-					$raw_field_value = $raw_field_value->format( 'c' );
348
+			}elseif ($field_obj instanceof \EE_Datetime_Field) {
349
+				if ($raw_field_value instanceof \DateTime) {
350
+					$raw_field_value = $raw_field_value->format('c');
351 351
 				}
352
-				$result[ $field_name ] = mysql_to_rfc3339( $raw_field_value );
353
-			}else{
354
-				$value_prepared = $field_obj->prepare_for_get( $field_value );
352
+				$result[$field_name] = mysql_to_rfc3339($raw_field_value);
353
+			} else {
354
+				$value_prepared = $field_obj->prepare_for_get($field_value);
355 355
 
356
-				$result[ $field_name ] = $value_prepared === INF ? EE_INF_IN_DB : $value_prepared;
356
+				$result[$field_name] = $value_prepared === INF ? EE_INF_IN_DB : $value_prepared;
357 357
 			}
358 358
 		}
359
-		if( $model instanceof \EEM_CPT_Base ) {
359
+		if ($model instanceof \EEM_CPT_Base) {
360 360
 			$attachment = wp_get_attachment_image_src(
361
-				get_post_thumbnail_id( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ),
361
+				get_post_thumbnail_id($db_row[$model->get_primary_key_field()->get_qualified_column()]),
362 362
 				'full'
363 363
 			);
364
-			$result[ 'featured_image_url' ] = !empty( $attachment ) ? $attachment[ 0 ] : null;
365
-			$result[ 'link' ] = get_permalink( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] );
364
+			$result['featured_image_url'] = ! empty($attachment) ? $attachment[0] : null;
365
+			$result['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]);
366 366
 		}
367 367
 		//add links to related data
368 368
 		$result['_links'] = array(
369 369
 			'self' => array(
370 370
 				array(
371 371
 					'href' => $this->get_versioned_link_to(
372
-						\EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $result[ $model->primary_key_name() ]
372
+						\EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$result[$model->primary_key_name()]
373 373
 					)
374 374
 				)
375 375
 			),
376 376
 			'collection' => array(
377 377
 				array(
378 378
 					'href' => $this->get_versioned_link_to(
379
-						\EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() )
379
+						\EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
380 380
 					)
381 381
 				)
382 382
 			),
383 383
 		);
384 384
 		global $wp_rest_server;
385
-		if( $model instanceof \EEM_CPT_Base &&
385
+		if ($model instanceof \EEM_CPT_Base &&
386 386
 			$wp_rest_server instanceof \WP_REST_Server &&
387
-			$wp_rest_server->get_route_options( '/wp/v2/posts' ) ) {
388
-			$result[ '_links' ][ 'https://api.eventespresso.com/self_wp_post' ] = array(
387
+			$wp_rest_server->get_route_options('/wp/v2/posts')) {
388
+			$result['_links']['https://api.eventespresso.com/self_wp_post'] = array(
389 389
 				array(
390
-					'href' => rest_url( '/wp/v2/posts/' . $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ),
390
+					'href' => rest_url('/wp/v2/posts/'.$db_row[$model->get_primary_key_field()->get_qualified_column()]),
391 391
 					'single' => true
392 392
 				)
393 393
 			);
394 394
 		}
395 395
 
396 396
 		//filter fields if specified
397
-		$includes_for_this_model = $this->extract_includes_for_this_model( $include );
398
-		if( ! empty( $includes_for_this_model ) ) {
399
-			if( $model->has_primary_key_field() ) {
397
+		$includes_for_this_model = $this->extract_includes_for_this_model($include);
398
+		if ( ! empty($includes_for_this_model)) {
399
+			if ($model->has_primary_key_field()) {
400 400
 				//always include the primary key
401 401
 				$includes_for_this_model[] = $model->primary_key_name();
402 402
 			}
403
-			$result = array_intersect_key( $result, array_flip( $includes_for_this_model ) );
403
+			$result = array_intersect_key($result, array_flip($includes_for_this_model));
404 404
 		}
405 405
 		//add meta links and possibly include related models
406 406
 		$relation_settings = apply_filters(
407 407
 			'FHEE__Read__create_entity_from_wpdb_result__related_models_to_include',
408 408
 			$model->relation_settings()
409 409
 		);
410
-		foreach( $relation_settings as $relation_name => $relation_obj ) {
411
-			$related_model_part = $this->get_related_entity_name( $relation_name, $relation_obj );
412
-			if( empty( $includes_for_this_model ) || isset( $includes_for_this_model['meta'] ) ) {
413
-				$result['_links']['https://api.eventespresso.com/' . $related_model_part] = array(
410
+		foreach ($relation_settings as $relation_name => $relation_obj) {
411
+			$related_model_part = $this->get_related_entity_name($relation_name, $relation_obj);
412
+			if (empty($includes_for_this_model) || isset($includes_for_this_model['meta'])) {
413
+				$result['_links']['https://api.eventespresso.com/'.$related_model_part] = array(
414 414
 					array(
415 415
 						'href' => $this->get_versioned_link_to(
416
-							\EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $result[ $model->primary_key_name() ] . '/' . $related_model_part
416
+							\EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$result[$model->primary_key_name()].'/'.$related_model_part
417 417
 						),
418 418
 						'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false
419 419
 					)
420 420
 				);
421 421
 			}
422
-			$related_fields_to_include = $this->extract_includes_for_this_model( $include, $relation_name );
423
-			if( $related_fields_to_include ) {
422
+			$related_fields_to_include = $this->extract_includes_for_this_model($include, $relation_name);
423
+			if ($related_fields_to_include) {
424 424
 				$pretend_related_request = new \WP_REST_Request();
425 425
 				$pretend_related_request->set_query_params(
426 426
 					array(
@@ -432,11 +432,11 @@  discard block
 block discarded – undo
432 432
 					)
433 433
 				);
434 434
 				$related_results = $this->get_entities_from_relation(
435
-					$result[ $model->primary_key_name() ],
435
+					$result[$model->primary_key_name()],
436 436
 					$relation_obj,
437 437
 					$pretend_related_request
438 438
 				);
439
-				$result[ $related_model_part ] = $related_results instanceof \WP_Error ? null : $related_results;
439
+				$result[$related_model_part] = $related_results instanceof \WP_Error ? null : $related_results;
440 440
 			}
441 441
 		}
442 442
 		$result = apply_filters(
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 		);
454 454
 		$this->_set_debug_info(
455 455
 			'inaccessible fields',
456
-			array_keys( array_diff_key( $result, $result_without_inaccessible_fields ) )
456
+			array_keys(array_diff_key($result, $result_without_inaccessible_fields))
457 457
 		);
458 458
 		return apply_filters(
459 459
 			'FHEE__Read__create_entity_from_wpdb_results__entity_return',
@@ -468,8 +468,8 @@  discard block
 block discarded – undo
468 468
 	 * @param string $link_part_after_version_and_slash eg "events/10/datetimes"
469 469
 	 * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes"
470 470
 	 */
471
-	public function get_versioned_link_to( $link_part_after_version_and_slash ) {
472
-		return rest_url( \EED_Core_Rest_Api::ee_api_namespace . $this->get_model_version_info()->requested_version() . '/' . $link_part_after_version_and_slash );
471
+	public function get_versioned_link_to($link_part_after_version_and_slash) {
472
+		return rest_url(\EED_Core_Rest_Api::ee_api_namespace.$this->get_model_version_info()->requested_version().'/'.$link_part_after_version_and_slash);
473 473
 	}
474 474
 
475 475
 	/**
@@ -479,11 +479,11 @@  discard block
 block discarded – undo
479 479
 	 * @param \EE_Model_Relation_Base $relation_obj
480 480
 	 * @return string
481 481
 	 */
482
-	public static function get_related_entity_name( $relation_name, $relation_obj ){
483
-		if( $relation_obj instanceof \EE_Belongs_To_Relation ) {
484
-			return strtolower( $relation_name );
485
-		}else{
486
-			return \EEH_Inflector::pluralize_and_lower( $relation_name );
482
+	public static function get_related_entity_name($relation_name, $relation_obj) {
483
+		if ($relation_obj instanceof \EE_Belongs_To_Relation) {
484
+			return strtolower($relation_name);
485
+		} else {
486
+			return \EEH_Inflector::pluralize_and_lower($relation_name);
487 487
 		}
488 488
 	}
489 489
 
@@ -496,44 +496,44 @@  discard block
 block discarded – undo
496 496
 	 * @param \WP_REST_Request $request
497 497
 	 * @return array
498 498
 	 */
499
-	public function get_entity_from_model( $model, $request ) {
500
-		$query_params = array( array( $model->primary_key_name() => $request->get_param( 'id' ) ),'limit' => 1);
501
-		if( $model instanceof \EEM_Soft_Delete_Base ){
499
+	public function get_entity_from_model($model, $request) {
500
+		$query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1);
501
+		if ($model instanceof \EEM_Soft_Delete_Base) {
502 502
 			$query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params);
503 503
 		}
504 504
 		$restricted_query_params = $query_params;
505
-		$restricted_query_params[ 'caps' ] =  $this->validate_context(  $request->get_param( 'caps' ) );
506
-		$this->_set_debug_info( 'model query params', $restricted_query_params );
507
-		$model_rows = $model->get_all_wpdb_results( $restricted_query_params );
508
-		if ( ! empty ( $model_rows ) ) {
505
+		$restricted_query_params['caps'] = $this->validate_context($request->get_param('caps'));
506
+		$this->_set_debug_info('model query params', $restricted_query_params);
507
+		$model_rows = $model->get_all_wpdb_results($restricted_query_params);
508
+		if ( ! empty ($model_rows)) {
509 509
 			return $this->create_entity_from_wpdb_result(
510 510
 				$model,
511
-				array_shift( $model_rows ),
512
-				$request->get_param( 'include' ),
513
-				$this->validate_context( $request->get_param( 'caps' ) ) );
511
+				array_shift($model_rows),
512
+				$request->get_param('include'),
513
+				$this->validate_context($request->get_param('caps')) );
514 514
 		} else {
515 515
 			//ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities
516
-			$lowercase_model_name = strtolower( $model->get_this_model_name() );
517
-			$model_rows_found_sans_restrictions = $model->get_all_wpdb_results( $query_params );
518
-			if( ! empty( $model_rows_found_sans_restrictions ) ) {
516
+			$lowercase_model_name = strtolower($model->get_this_model_name());
517
+			$model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params);
518
+			if ( ! empty($model_rows_found_sans_restrictions)) {
519 519
 				//you got shafted- it existed but we didn't want to tell you!
520 520
 				return new \WP_Error(
521 521
 					'rest_user_cannot_read',
522 522
 					sprintf(
523
-						__( 'Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso' ),
524
-						strtolower( $model->get_this_model_name() ),
523
+						__('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'),
524
+						strtolower($model->get_this_model_name()),
525 525
 						Capabilities::get_missing_permissions_string(
526 526
 							$model,
527
-							$this->validate_context( $request->get_param( 'caps' ) ) )
527
+							$this->validate_context($request->get_param('caps')) )
528 528
 					),
529
-					array( 'status' => 403 )
529
+					array('status' => 403)
530 530
 				);
531 531
 			} else {
532 532
 				//it's not you. It just doesn't exist
533 533
 				return new \WP_Error(
534
-					sprintf( 'rest_%s_invalid_id', $lowercase_model_name ),
535
-					sprintf( __( 'Invalid %s ID.', 'event_espresso' ), $lowercase_model_name ),
536
-					array( 'status' => 404 )
534
+					sprintf('rest_%s_invalid_id', $lowercase_model_name),
535
+					sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name),
536
+					array('status' => 404)
537 537
 				);
538 538
 			}
539 539
 		}
@@ -546,14 +546,14 @@  discard block
 block discarded – undo
546 546
 	 * @param string $context
547 547
 	 * @return string array key of EEM_Base::cap_contexts_to_cap_action_map()
548 548
 	 */
549
-	public function validate_context( $context ) {
550
-		if( ! $context ) {
549
+	public function validate_context($context) {
550
+		if ( ! $context) {
551 551
 			$context = \EEM_Base::caps_read;
552 552
 		}
553 553
 		$valid_contexts = \EEM_Base::valid_cap_contexts();
554
-		if( in_array( $context, $valid_contexts )  ){
554
+		if (in_array($context, $valid_contexts)) {
555 555
 			return $context;
556
-		}else{
556
+		} else {
557 557
 			return \EEM_Base::caps_read;
558 558
 		}
559 559
 	}
@@ -569,73 +569,73 @@  discard block
 block discarded – undo
569 569
 	 *                          that absolutely no results should be returned
570 570
 	 * @throws \EE_Error
571 571
 	 */
572
-	public function create_model_query_params( $model, $query_parameters ) {
572
+	public function create_model_query_params($model, $query_parameters) {
573 573
 		$model_query_params = array( );
574
-		if ( isset( $query_parameters[ 'where' ] ) ) {
575
-			$model_query_params[ 0 ] = $this->prepare_rest_query_params_key_for_models( $model, $query_parameters[ 'where' ] );
576
-		}
577
-		if ( isset( $query_parameters[ 'order_by' ] ) ) {
578
-			$order_by = $query_parameters[ 'order_by' ];
579
-		} elseif ( isset( $query_parameters[ 'orderby' ] ) ) {
580
-			$order_by = $query_parameters[ 'orderby' ];
581
-		}else{
574
+		if (isset($query_parameters['where'])) {
575
+			$model_query_params[0] = $this->prepare_rest_query_params_key_for_models($model, $query_parameters['where']);
576
+		}
577
+		if (isset($query_parameters['order_by'])) {
578
+			$order_by = $query_parameters['order_by'];
579
+		} elseif (isset($query_parameters['orderby'])) {
580
+			$order_by = $query_parameters['orderby'];
581
+		} else {
582 582
 			$order_by = null;
583 583
 		}
584
-		if( $order_by !== null ){
585
-			$model_query_params[ 'order_by' ] = $this->prepare_rest_query_params_key_for_models( $model, $order_by );
584
+		if ($order_by !== null) {
585
+			$model_query_params['order_by'] = $this->prepare_rest_query_params_key_for_models($model, $order_by);
586 586
 		}
587
-		if ( isset( $query_parameters[ 'group_by' ] ) ) {
588
-			$group_by = $query_parameters[ 'group_by' ];
589
-		} elseif ( isset( $query_parameters[ 'groupby' ] ) ) {
590
-			$group_by = $query_parameters[ 'groupby' ];
591
-		}else{
587
+		if (isset($query_parameters['group_by'])) {
588
+			$group_by = $query_parameters['group_by'];
589
+		} elseif (isset($query_parameters['groupby'])) {
590
+			$group_by = $query_parameters['groupby'];
591
+		} else {
592 592
 			$group_by = null;
593 593
 		}
594
-		if( $group_by !== null ){
595
-			if( is_array( $group_by ) ) {
596
-				$group_by = $this->prepare_rest_query_params_values_for_models( $model, $group_by );
594
+		if ($group_by !== null) {
595
+			if (is_array($group_by)) {
596
+				$group_by = $this->prepare_rest_query_params_values_for_models($model, $group_by);
597 597
 			}
598
-			$model_query_params[ 'group_by' ] = $group_by;
598
+			$model_query_params['group_by'] = $group_by;
599 599
 		}
600
-		if ( isset( $query_parameters[ 'having' ] ) ) {
600
+		if (isset($query_parameters['having'])) {
601 601
 			//@todo: no good for permissions
602
-			$model_query_params[ 'having' ] = $this->prepare_rest_query_params_key_for_models( $model, $query_parameters[ 'having' ] );
602
+			$model_query_params['having'] = $this->prepare_rest_query_params_key_for_models($model, $query_parameters['having']);
603 603
 		}
604
-		if ( isset( $query_parameters[ 'order' ] ) ) {
605
-			$model_query_params[ 'order' ] = $query_parameters[ 'order' ];
604
+		if (isset($query_parameters['order'])) {
605
+			$model_query_params['order'] = $query_parameters['order'];
606 606
 		}
607
-		if ( isset( $query_parameters[ 'mine' ] ) ){
608
-			$model_query_params = $model->alter_query_params_to_only_include_mine( $model_query_params );
607
+		if (isset($query_parameters['mine'])) {
608
+			$model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params);
609 609
 		}
610
-		if( isset( $query_parameters[ 'limit' ] ) ) {
610
+		if (isset($query_parameters['limit'])) {
611 611
 			//limit should be either a string like '23' or '23,43', or an array with two items in it
612
-			if( is_string( $query_parameters[ 'limit' ] ) ) {
612
+			if (is_string($query_parameters['limit'])) {
613 613
 				$limit_array = explode(',', $query_parameters['limit']);
614
-			}else {
615
-				$limit_array = $query_parameters[ 'limit' ];
614
+			} else {
615
+				$limit_array = $query_parameters['limit'];
616 616
 			}
617 617
 			$sanitized_limit = array();
618
-			foreach( $limit_array as $key => $limit_part ) {
619
-				if( $this->_debug_mode && ( ! is_numeric( $limit_part ) || count( $sanitized_limit ) > 2 ) ) {
618
+			foreach ($limit_array as $key => $limit_part) {
619
+				if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) {
620 620
 					throw new \EE_Error(
621 621
 						sprintf(
622
-							__( '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' ),
623
-							json_encode( $query_parameters[ 'limit' ] )
622
+							__('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'),
623
+							json_encode($query_parameters['limit'])
624 624
 						)
625 625
 					);
626 626
 				}
627
-				$sanitized_limit[] = intval( $limit_part );
627
+				$sanitized_limit[] = intval($limit_part);
628 628
 			}
629
-			$model_query_params[ 'limit' ] = implode( ',', $sanitized_limit );
630
-		}else{
631
-			$model_query_params[ 'limit' ] = 50;
629
+			$model_query_params['limit'] = implode(',', $sanitized_limit);
630
+		} else {
631
+			$model_query_params['limit'] = 50;
632 632
 		}
633
-		if( isset( $query_parameters[ 'caps' ] ) ) {
634
-			$model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] );
635
-		}else{
636
-			$model_query_params[ 'caps' ] = \EEM_Base::caps_read;
633
+		if (isset($query_parameters['caps'])) {
634
+			$model_query_params['caps'] = $this->validate_context($query_parameters['caps']);
635
+		} else {
636
+			$model_query_params['caps'] = \EEM_Base::caps_read;
637 637
 		}
638
-		return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model );
638
+		return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model);
639 639
 	}
640 640
 
641 641
 
@@ -647,24 +647,24 @@  discard block
 block discarded – undo
647 647
 	 * @param array     $query_params sub-array from @see EEM_Base::get_all()
648 648
 	 * @return array
649 649
 	 */
650
-	public function prepare_rest_query_params_key_for_models( $model,  $query_params ) {
650
+	public function prepare_rest_query_params_key_for_models($model, $query_params) {
651 651
 		$model_ready_query_params = array();
652
-		foreach( $query_params as $key => $value ) {
653
-			if( is_array( $value ) ) {
654
-				$model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value );
655
-			}else{
656
-				$model_ready_query_params[ $key ] = $value;
652
+		foreach ($query_params as $key => $value) {
653
+			if (is_array($value)) {
654
+				$model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value);
655
+			} else {
656
+				$model_ready_query_params[$key] = $value;
657 657
 			}
658 658
 		}
659 659
 		return $model_ready_query_params;
660 660
 	}
661
-	public function prepare_rest_query_params_values_for_models( $model,  $query_params ) {
661
+	public function prepare_rest_query_params_values_for_models($model, $query_params) {
662 662
 		$model_ready_query_params = array();
663
-		foreach( $query_params as $key => $value ) {
664
-			if( is_array( $value ) ) {
665
-				$model_ready_query_params[ $key ] = $this->prepare_rest_query_params_values_for_models( $model, $value );
663
+		foreach ($query_params as $key => $value) {
664
+			if (is_array($value)) {
665
+				$model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value);
666 666
 			} else {
667
-				$model_ready_query_params[ $key ] = $value;
667
+				$model_ready_query_params[$key] = $value;
668 668
 			}
669 669
 		}
670 670
 		return $model_ready_query_params;
@@ -680,33 +680,33 @@  discard block
 block discarded – undo
680 680
 	 * @return array of fields for this model. If $model_name is provided, then
681 681
 	 * the fields for that model, with the model's name removed from each.
682 682
 	 */
683
-	public function extract_includes_for_this_model( $include_string, $model_name = null ) {
684
-		if( is_array( $include_string ) ) {
685
-			$include_string = implode( ',', $include_string );
683
+	public function extract_includes_for_this_model($include_string, $model_name = null) {
684
+		if (is_array($include_string)) {
685
+			$include_string = implode(',', $include_string);
686 686
 		}
687
-		if( $include_string === '*' ) {
687
+		if ($include_string === '*') {
688 688
 			return array();
689 689
 		}
690
-		$includes = explode( ',', $include_string );
690
+		$includes = explode(',', $include_string);
691 691
 		$extracted_fields_to_include = array();
692
-		if( $model_name ){
693
-			foreach( $includes as $field_to_include ) {
694
-				$field_to_include = trim( $field_to_include );
695
-				if( strpos( $field_to_include, $model_name . '.' ) === 0 ) {
692
+		if ($model_name) {
693
+			foreach ($includes as $field_to_include) {
694
+				$field_to_include = trim($field_to_include);
695
+				if (strpos($field_to_include, $model_name.'.') === 0) {
696 696
 					//found the model name at the exact start
697
-					$field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include );
697
+					$field_sans_model_name = str_replace($model_name.'.', '', $field_to_include);
698 698
 					$extracted_fields_to_include[] = $field_sans_model_name;
699
-				}elseif( $field_to_include == $model_name ){
699
+				}elseif ($field_to_include == $model_name) {
700 700
 					$extracted_fields_to_include[] = '*';
701 701
 				}
702 702
 			}
703
-		}else{
703
+		} else {
704 704
 			//look for ones with no period
705
-			foreach( $includes as $field_to_include ) {
706
-				$field_to_include = trim( $field_to_include );
705
+			foreach ($includes as $field_to_include) {
706
+				$field_to_include = trim($field_to_include);
707 707
 				if (
708
-					strpos( $field_to_include, '.' ) === false
709
-					&& ! $this->get_model_version_info()->is_model_name_in_this_version( $field_to_include )
708
+					strpos($field_to_include, '.') === false
709
+					&& ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include)
710 710
 				) {
711 711
 					$extracted_fields_to_include[] = $field_to_include;
712 712
 				}
Please login to merge, or discard this patch.