@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | * date_format and the second value is the time format |
38 | 38 | * @return EE_Question |
39 | 39 | */ |
40 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
41 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
42 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
40 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
41 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
42 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | * the website will be used. |
51 | 51 | * @return EE_Question |
52 | 52 | */ |
53 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
54 | - return new self( $props_n_values, TRUE, $timezone ); |
|
53 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
54 | + return new self($props_n_values, TRUE, $timezone); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * @access public |
63 | 63 | * @param string $QST_display_text |
64 | 64 | */ |
65 | - public function set_display_text( $QST_display_text = '' ) { |
|
66 | - $this->set( 'QST_display_text', $QST_display_text ); |
|
65 | + public function set_display_text($QST_display_text = '') { |
|
66 | + $this->set('QST_display_text', $QST_display_text); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | * @access public |
75 | 75 | * @param string $QST_admin_label |
76 | 76 | */ |
77 | - public function set_admin_label( $QST_admin_label = '' ) { |
|
78 | - $this->set( 'QST_admin_label', $QST_admin_label ); |
|
77 | + public function set_admin_label($QST_admin_label = '') { |
|
78 | + $this->set('QST_admin_label', $QST_admin_label); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | * @access public |
87 | 87 | * @param mixed $QST_system |
88 | 88 | */ |
89 | - public function set_system_ID( $QST_system = '' ) { |
|
90 | - $this->set( 'QST_system', $QST_system ); |
|
89 | + public function set_system_ID($QST_system = '') { |
|
90 | + $this->set('QST_system', $QST_system); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | * @access public |
99 | 99 | * @param string $QST_type |
100 | 100 | */ |
101 | - public function set_question_type( $QST_type = '' ) { |
|
102 | - $this->set( 'QST_type', $QST_type ); |
|
101 | + public function set_question_type($QST_type = '') { |
|
102 | + $this->set('QST_type', $QST_type); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | * @access public |
111 | 111 | * @param bool $QST_required |
112 | 112 | */ |
113 | - public function set_required( $QST_required = FALSE ) { |
|
114 | - $this->set( 'QST_required', $QST_required ); |
|
113 | + public function set_required($QST_required = FALSE) { |
|
114 | + $this->set('QST_required', $QST_required); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | * @access public |
123 | 123 | * @param string $QST_required_text |
124 | 124 | */ |
125 | - public function set_required_text( $QST_required_text = '' ) { |
|
126 | - $this->set( 'QST_required_text', $QST_required_text ); |
|
125 | + public function set_required_text($QST_required_text = '') { |
|
126 | + $this->set('QST_required_text', $QST_required_text); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | * @access public |
135 | 135 | * @param int $QST_order |
136 | 136 | */ |
137 | - public function set_order( $QST_order = 0 ) { |
|
138 | - $this->set( 'QST_order', $QST_order ); |
|
137 | + public function set_order($QST_order = 0) { |
|
138 | + $this->set('QST_order', $QST_order); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * @access public |
147 | 147 | * @param bool $QST_admin_only |
148 | 148 | */ |
149 | - public function set_admin_only( $QST_admin_only = FALSE ) { |
|
150 | - $this->set( 'QST_admin_only', $QST_admin_only ); |
|
149 | + public function set_admin_only($QST_admin_only = FALSE) { |
|
150 | + $this->set('QST_admin_only', $QST_admin_only); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @access public |
159 | 159 | * @param int $QST_wp_user |
160 | 160 | */ |
161 | - public function set_wp_user( $QST_wp_user = 1 ) { |
|
162 | - $this->set( 'QST_wp_user', $QST_wp_user ); |
|
161 | + public function set_wp_user($QST_wp_user = 1) { |
|
162 | + $this->set('QST_wp_user', $QST_wp_user); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | * @access public |
176 | 176 | * @param bool $QST_deleted |
177 | 177 | */ |
178 | - public function set_deleted( $QST_deleted = FALSE ) { |
|
179 | - $this->set( 'QST_deleted', $QST_deleted ); |
|
178 | + public function set_deleted($QST_deleted = FALSE) { |
|
179 | + $this->set('QST_deleted', $QST_deleted); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @return string |
188 | 188 | */ |
189 | 189 | public function display_text() { |
190 | - return $this->get( 'QST_display_text' ); |
|
190 | + return $this->get('QST_display_text'); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @return string |
199 | 199 | */ |
200 | 200 | public function admin_label() { |
201 | - return $this->get( 'QST_admin_label' ); |
|
201 | + return $this->get('QST_admin_label'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @return string |
210 | 210 | */ |
211 | 211 | public function system_ID() { |
212 | - return $this->get( 'QST_system' ); |
|
212 | + return $this->get('QST_system'); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @return boolean |
221 | 221 | */ |
222 | 222 | public function required() { |
223 | - return $this->get( 'QST_required' ); |
|
223 | + return $this->get('QST_required'); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * @return string |
233 | 233 | */ |
234 | 234 | public function required_text() { |
235 | - return $this->get( 'QST_required_text' ); |
|
235 | + return $this->get('QST_required_text'); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @return string |
244 | 244 | */ |
245 | 245 | public function type() { |
246 | - return $this->get( 'QST_type' ); |
|
246 | + return $this->get('QST_type'); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @return int |
256 | 256 | */ |
257 | 257 | public function order() { |
258 | - return $this->get( 'QST_order' ); |
|
258 | + return $this->get('QST_order'); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @return boolean |
268 | 268 | */ |
269 | 269 | public function admin_only() { |
270 | - return $this->get( 'QST_admin_only' ); |
|
270 | + return $this->get('QST_admin_only'); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @return int |
279 | 279 | */ |
280 | 280 | public function wp_user() { |
281 | - return $this->get( 'QST_wp_user' ); |
|
281 | + return $this->get('QST_wp_user'); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * @return boolean |
290 | 290 | */ |
291 | 291 | public function deleted() { |
292 | - return $this->get( 'QST_deleted' ); |
|
292 | + return $this->get('QST_deleted'); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @return EE_Answer[] |
300 | 300 | */ |
301 | 301 | public function answers() { |
302 | - return $this->get_many_related( 'Answer' ); |
|
302 | + return $this->get_many_related('Answer'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * @return boolean true = has answers, false = no answers. |
310 | 310 | */ |
311 | 311 | public function has_answers() { |
312 | - return $this->count_related( 'Answer' ) > 0 ? TRUE : FALSE; |
|
312 | + return $this->count_related('Answer') > 0 ? TRUE : FALSE; |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @return EE_Question_Group[] |
320 | 320 | */ |
321 | 321 | public function question_groups() { |
322 | - return $this->get_many_related( 'Question_Group' ); |
|
322 | + return $this->get_many_related('Question_Group'); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | |
@@ -333,24 +333,24 @@ discard block |
||
333 | 333 | * whether it was trashed or not. |
334 | 334 | * @return EE_Question_Option[] |
335 | 335 | */ |
336 | - public function options( $notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL ) { |
|
337 | - if ( ! $this->ID() ) { |
|
336 | + public function options($notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL) { |
|
337 | + if ( ! $this->ID()) { |
|
338 | 338 | return array(); |
339 | 339 | } |
340 | 340 | $query_params = array(); |
341 | - if ( $selected_value_to_always_include ) { |
|
342 | - if ( is_array( $selected_value_to_always_include ) ) { |
|
343 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = array( 'IN', $selected_value_to_always_include ); |
|
341 | + if ($selected_value_to_always_include) { |
|
342 | + if (is_array($selected_value_to_always_include)) { |
|
343 | + $query_params[0]['OR*options-query']['QSO_value'] = array('IN', $selected_value_to_always_include); |
|
344 | 344 | } else { |
345 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = $selected_value_to_always_include; |
|
345 | + $query_params[0]['OR*options-query']['QSO_value'] = $selected_value_to_always_include; |
|
346 | 346 | } |
347 | 347 | } |
348 | - if ( $notDeletedOptionsOnly ) { |
|
349 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_deleted' ] = FALSE; |
|
348 | + if ($notDeletedOptionsOnly) { |
|
349 | + $query_params[0]['OR*options-query']['QSO_deleted'] = FALSE; |
|
350 | 350 | } |
351 | 351 | //order by QSO_order |
352 | - $query_params[ 'order_by' ] = array( 'QSO_order' => 'ASC' ); |
|
353 | - return $this->get_many_related( 'Question_Option', $query_params ); |
|
352 | + $query_params['order_by'] = array('QSO_order' => 'ASC'); |
|
353 | + return $this->get_many_related('Question_Option', $query_params); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | * @return \EE_Question_Option[] |
361 | 361 | */ |
362 | 362 | public function temp_options() { |
363 | - return $this->_model_relations[ 'Question_Option' ]; |
|
363 | + return $this->_model_relations['Question_Option']; |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | * @param EE_Question_Option $option |
372 | 372 | * @return boolean success |
373 | 373 | */ |
374 | - public function add_option( EE_Question_Option $option ) { |
|
375 | - return $this->_add_relation_to( $option, 'Question_Option' ); |
|
374 | + public function add_option(EE_Question_Option $option) { |
|
375 | + return $this->_add_relation_to($option, 'Question_Option'); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | * @param EE_Question_Option $option |
383 | 383 | * @return boolean success |
384 | 384 | */ |
385 | - public function add_temp_option( EE_Question_Option $option ) { |
|
386 | - $this->_model_relations[ 'Question_Option' ][ ] = $option; |
|
385 | + public function add_temp_option(EE_Question_Option $option) { |
|
386 | + $this->_model_relations['Question_Option'][] = $option; |
|
387 | 387 | return TRUE; |
388 | 388 | } |
389 | 389 | |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | * @param EE_Question_Option $option |
395 | 395 | * @return boolean success |
396 | 396 | */ |
397 | - public function remove_option( EE_Question_Option $option ) { |
|
398 | - return $this->_remove_relation_to( $option, 'Question_Option' ); |
|
397 | + public function remove_option(EE_Question_Option $option) { |
|
398 | + return $this->_remove_relation_to($option, 'Question_Option'); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | |
@@ -404,8 +404,8 @@ discard block |
||
404 | 404 | * @return bool |
405 | 405 | */ |
406 | 406 | public function is_system_question() { |
407 | - $system_ID = $this->get( 'QST_system' ); |
|
408 | - return ! empty( $system_ID ) ? TRUE : FALSE; |
|
407 | + $system_ID = $this->get('QST_system'); |
|
408 | + return ! empty($system_ID) ? TRUE : FALSE; |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | |
@@ -418,8 +418,8 @@ discard block |
||
418 | 418 | */ |
419 | 419 | public function set_order_to_latest() { |
420 | 420 | $latest_order = $this->get_model()->get_latest_question_order(); |
421 | - $latest_order ++; |
|
422 | - $this->set( 'QST_order', $latest_order ); |
|
421 | + $latest_order++; |
|
422 | + $this->set('QST_order', $latest_order); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | |
@@ -438,20 +438,20 @@ discard block |
||
438 | 438 | * Duplicates this question and its question options |
439 | 439 | * @return \EE_Question |
440 | 440 | */ |
441 | - public function duplicate( $options = array() ) { |
|
441 | + public function duplicate($options = array()) { |
|
442 | 442 | $new_question = clone $this; |
443 | - $new_question->set( 'QST_ID', null ); |
|
444 | - $new_question->set_display_text( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->display_text() ) ); |
|
445 | - $new_question->set_admin_label( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->admin_label() ) ); |
|
446 | - $new_question->set_system_ID( null ); |
|
447 | - $new_question->set_wp_user( get_current_user_id() ); |
|
443 | + $new_question->set('QST_ID', null); |
|
444 | + $new_question->set_display_text(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->display_text())); |
|
445 | + $new_question->set_admin_label(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->admin_label())); |
|
446 | + $new_question->set_system_ID(null); |
|
447 | + $new_question->set_wp_user(get_current_user_id()); |
|
448 | 448 | //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
449 | - $new_question->set_deleted( false ); |
|
449 | + $new_question->set_deleted(false); |
|
450 | 450 | $success = $new_question->save(); |
451 | - if( $success ) { |
|
451 | + if ($success) { |
|
452 | 452 | //we don't totally want to duplicate the question options, because we want them to be for the NEW question |
453 | - foreach( $this->options() as $question_option ) { |
|
454 | - $question_option->duplicate( array( 'QST_ID' => $new_question->ID() ) ); |
|
453 | + foreach ($this->options() as $question_option) { |
|
454 | + $question_option->duplicate(array('QST_ID' => $new_question->ID())); |
|
455 | 455 | } |
456 | 456 | return $new_question; |
457 | 457 | } else { |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | * @return int|float |
465 | 465 | */ |
466 | 466 | public function max() { |
467 | - return $this->get( 'QST_max' ); |
|
467 | + return $this->get('QST_max'); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /** |
@@ -472,8 +472,8 @@ discard block |
||
472 | 472 | * @param int|float $new_max |
473 | 473 | * @return void |
474 | 474 | */ |
475 | - public function set_max( $new_max ) { |
|
476 | - $this->set( 'QST_max', $new_max ); |
|
475 | + public function set_max($new_max) { |
|
476 | + $this->set('QST_max', $new_max); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | * @param array $input_constructor_args |
486 | 486 | * @return EE_Form_Input_Base |
487 | 487 | */ |
488 | - public function generate_form_input( $registration = null, $answer = null, $input_constructor_args = array() ) { |
|
488 | + public function generate_form_input($registration = null, $answer = null, $input_constructor_args = array()) { |
|
489 | 489 | $identifier = $this->is_system_question() ? $this->system_ID() : $this->ID(); |
490 | 490 | |
491 | 491 | $input_constructor_args = array_merge( |
@@ -496,27 +496,27 @@ discard block |
||
496 | 496 | ), |
497 | 497 | $input_constructor_args |
498 | 498 | ); |
499 | - if( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration ) { |
|
500 | - $answer = EEM_Answer::instance()->get_registration_question_answer_object( $registration, $this->ID() ); |
|
499 | + if ( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration) { |
|
500 | + $answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID()); |
|
501 | 501 | } |
502 | 502 | // has this question been answered ? |
503 | - if ( $answer instanceof EE_Answer ) { |
|
503 | + if ($answer instanceof EE_Answer) { |
|
504 | 504 | //answer gets htmlspecialchars called on it, undo that please |
505 | 505 | //beceause the form input's display strategy may call esc_attr too |
506 | 506 | //which also does html special characters |
507 | 507 | $values_with_html_special_chars = $answer->value(); |
508 | - if( is_array( $values_with_html_special_chars ) ) { |
|
509 | - $default_value = array_map( 'htmlspecialchars_decode', $values_with_html_special_chars ); |
|
508 | + if (is_array($values_with_html_special_chars)) { |
|
509 | + $default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars); |
|
510 | 510 | } else { |
511 | - $default_value = htmlspecialchars_decode( $values_with_html_special_chars ); |
|
511 | + $default_value = htmlspecialchars_decode($values_with_html_special_chars); |
|
512 | 512 | } |
513 | 513 | $input_constructor_args['default'] = $default_value; |
514 | 514 | } |
515 | - $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question( $this->system_ID() ); |
|
516 | - if( EEM_Question::instance()->question_type_is_in_category( $this->type(), 'text' ) ) { |
|
517 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Max_Length_Validation_Strategy( |
|
515 | + $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID()); |
|
516 | + if (EEM_Question::instance()->question_type_is_in_category($this->type(), 'text')) { |
|
517 | + $input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy( |
|
518 | 518 | null, |
519 | - min( $max_max_for_question, $this->max() ) |
|
519 | + min($max_max_for_question, $this->max()) |
|
520 | 520 | ); |
521 | 521 | } |
522 | 522 | $input_constructor_args = apply_filters( |
@@ -528,22 +528,22 @@ discard block |
||
528 | 528 | ); |
529 | 529 | |
530 | 530 | $result = null; |
531 | - switch ( $this->type() ) { |
|
531 | + switch ($this->type()) { |
|
532 | 532 | // Text |
533 | 533 | case EEM_Question::QST_type_text : |
534 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
534 | + $result = new EE_Text_Input($input_constructor_args); |
|
535 | 535 | break; |
536 | 536 | // Textarea |
537 | 537 | case EEM_Question::QST_type_textarea : |
538 | - $result = new EE_Text_Area_Input( $input_constructor_args ); |
|
538 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
539 | 539 | break; |
540 | 540 | // Radio Buttons |
541 | 541 | case EEM_Question::QST_type_radio : |
542 | - $result = new EE_Radio_Button_Input( $this->options(), $input_constructor_args ); |
|
542 | + $result = new EE_Radio_Button_Input($this->options(), $input_constructor_args); |
|
543 | 543 | break; |
544 | 544 | // Dropdown |
545 | 545 | case EEM_Question::QST_type_dropdown : |
546 | - $result = new EE_Select_Input( $this->options(), $input_constructor_args ); |
|
546 | + $result = new EE_Select_Input($this->options(), $input_constructor_args); |
|
547 | 547 | break; |
548 | 548 | // State Dropdown |
549 | 549 | case EEM_Question::QST_type_state : |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | $registration, |
555 | 555 | $answer |
556 | 556 | ); |
557 | - $result = new EE_State_Select_Input( $state_options, $input_constructor_args ); |
|
557 | + $result = new EE_State_Select_Input($state_options, $input_constructor_args); |
|
558 | 558 | break; |
559 | 559 | // Country Dropdown |
560 | 560 | case EEM_Question::QST_type_country : |
@@ -565,49 +565,49 @@ discard block |
||
565 | 565 | $registration, |
566 | 566 | $answer |
567 | 567 | ); |
568 | - $result = new EE_Country_Select_Input( $country_options, $input_constructor_args ); |
|
568 | + $result = new EE_Country_Select_Input($country_options, $input_constructor_args); |
|
569 | 569 | break; |
570 | 570 | // Checkboxes |
571 | 571 | case EEM_Question::QST_type_checkbox : |
572 | - $result = new EE_Checkbox_Multi_Input( $this->options(), $input_constructor_args ); |
|
572 | + $result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args); |
|
573 | 573 | break; |
574 | 574 | // Date |
575 | 575 | case EEM_Question::QST_type_date : |
576 | - $result = new EE_Datepicker_Input( $input_constructor_args ); |
|
576 | + $result = new EE_Datepicker_Input($input_constructor_args); |
|
577 | 577 | break; |
578 | 578 | case EEM_Question::QST_type_html_textarea : |
579 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Simple_HTML_Validation_Strategy(); |
|
580 | - $result = new EE_Text_Area_Input( $input_constructor_args ); |
|
581 | - $result->remove_validation_strategy( 'EE_Plaintext_Validation_Strategy' ); |
|
579 | + $input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy(); |
|
580 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
581 | + $result->remove_validation_strategy('EE_Plaintext_Validation_Strategy'); |
|
582 | 582 | break; |
583 | 583 | case EEM_Question::QST_type_email : |
584 | - $result = new EE_Email_Input( $input_constructor_args ); |
|
584 | + $result = new EE_Email_Input($input_constructor_args); |
|
585 | 585 | break; |
586 | 586 | case EEM_Question::QST_type_us_phone : |
587 | - $result = new EE_Phone_Input( $input_constructor_args ); |
|
587 | + $result = new EE_Phone_Input($input_constructor_args); |
|
588 | 588 | break; |
589 | 589 | case EEM_Question::QST_type_int : |
590 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Int_Validation_Strategy(); |
|
591 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
590 | + $input_constructor_args['validation_strategies'][] = new EE_Int_Validation_Strategy(); |
|
591 | + $result = new EE_Text_Input($input_constructor_args); |
|
592 | 592 | break; |
593 | 593 | case EEM_Question::QST_type_decimal : |
594 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Float_Validation_Strategy(); |
|
595 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
594 | + $input_constructor_args['validation_strategies'][] = new EE_Float_Validation_Strategy(); |
|
595 | + $result = new EE_Text_Input($input_constructor_args); |
|
596 | 596 | break; |
597 | 597 | case EEM_Question::QST_type_url : |
598 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_URL_Validation_Strategy(); |
|
599 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
598 | + $input_constructor_args['validation_strategies'][] = new EE_URL_Validation_Strategy(); |
|
599 | + $result = new EE_Text_Input($input_constructor_args); |
|
600 | 600 | break; |
601 | 601 | case EEM_Question::QST_type_year : |
602 | 602 | $result = new EE_Year_Input( |
603 | 603 | $input_constructor_args, |
604 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this ), |
|
605 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this ), |
|
606 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this ) |
|
604 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this), |
|
605 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this), |
|
606 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this) |
|
607 | 607 | ); |
608 | 608 | break; |
609 | 609 | case EEM_Question::QST_type_multi_select : |
610 | - $result = new EE_Select_Multiple_Input( $this->options(), $input_constructor_args ); |
|
610 | + $result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args); |
|
611 | 611 | break; |
612 | 612 | // fallback |
613 | 613 | default : |
@@ -618,12 +618,12 @@ discard block |
||
618 | 618 | $this, |
619 | 619 | $input_constructor_args |
620 | 620 | ); |
621 | - if( ! $default_input ){ |
|
622 | - $default_input = new EE_Text_Input( $input_constructor_args ); |
|
621 | + if ( ! $default_input) { |
|
622 | + $default_input = new EE_Text_Input($input_constructor_args); |
|
623 | 623 | } |
624 | 624 | $result = $default_input; |
625 | 625 | } |
626 | - return apply_filters( 'FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer ); |
|
626 | + return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * Adds an option for this question. Note: if the option were previously associated with a different |
370 | 370 | * Question, that relationship will be overwritten. |
371 | 371 | * @param EE_Question_Option $option |
372 | - * @return boolean success |
|
372 | + * @return EE_Base_Class success |
|
373 | 373 | */ |
374 | 374 | public function add_option( EE_Question_Option $option ) { |
375 | 375 | return $this->_add_relation_to( $option, 'Question_Option' ); |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | /** |
393 | 393 | * Marks the option as deleted. |
394 | 394 | * @param EE_Question_Option $option |
395 | - * @return boolean success |
|
395 | + * @return EE_Base_Class success |
|
396 | 396 | */ |
397 | 397 | public function remove_option( EE_Question_Option $option ) { |
398 | 398 | return $this->_remove_relation_to( $option, 'Question_Option' ); |
@@ -445,8 +445,8 @@ |
||
445 | 445 | $new_question->set_admin_label( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->admin_label() ) ); |
446 | 446 | $new_question->set_system_ID( null ); |
447 | 447 | $new_question->set_wp_user( get_current_user_id() ); |
448 | - //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
|
449 | - $new_question->set_deleted( false ); |
|
448 | + //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
|
449 | + $new_question->set_deleted( false ); |
|
450 | 450 | $success = $new_question->save(); |
451 | 451 | if( $success ) { |
452 | 452 | //we don't totally want to duplicate the question options, because we want them to be for the NEW question |
@@ -32,73 +32,73 @@ |
||
32 | 32 | */ |
33 | 33 | class Socket |
34 | 34 | { |
35 | - private $handle = null; |
|
35 | + private $handle = null; |
|
36 | 36 | |
37 | - /** |
|
38 | - * fsockopen |
|
39 | - * |
|
40 | - * @see http://php.net/fsockopen |
|
41 | - * @param string $hostname |
|
42 | - * @param int $port |
|
43 | - * @param int $errno |
|
44 | - * @param string $errstr |
|
45 | - * @param float $timeout |
|
46 | - * @return resource |
|
47 | - */ |
|
48 | - public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null) |
|
49 | - { |
|
50 | - $this->handle = fsockopen($hostname, $port, $errno, $errstr, (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout)); |
|
37 | + /** |
|
38 | + * fsockopen |
|
39 | + * |
|
40 | + * @see http://php.net/fsockopen |
|
41 | + * @param string $hostname |
|
42 | + * @param int $port |
|
43 | + * @param int $errno |
|
44 | + * @param string $errstr |
|
45 | + * @param float $timeout |
|
46 | + * @return resource |
|
47 | + */ |
|
48 | + public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null) |
|
49 | + { |
|
50 | + $this->handle = fsockopen($hostname, $port, $errno, $errstr, (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout)); |
|
51 | 51 | |
52 | - if ($this->handle != false && $errno === 0 && $errstr === '') { |
|
53 | - return $this->handle; |
|
54 | - } else { |
|
55 | - return false; |
|
56 | - } |
|
57 | - } |
|
52 | + if ($this->handle != false && $errno === 0 && $errstr === '') { |
|
53 | + return $this->handle; |
|
54 | + } else { |
|
55 | + return false; |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * fwrite |
|
61 | - * |
|
62 | - * @see http://php.net/fwrite |
|
63 | - * @param string $string |
|
64 | - * @param int $length |
|
65 | - * @return int | bool |
|
66 | - */ |
|
67 | - public function fwrite($string, $length = null) |
|
68 | - { |
|
69 | - return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length)); |
|
70 | - } |
|
59 | + /** |
|
60 | + * fwrite |
|
61 | + * |
|
62 | + * @see http://php.net/fwrite |
|
63 | + * @param string $string |
|
64 | + * @param int $length |
|
65 | + * @return int | bool |
|
66 | + */ |
|
67 | + public function fwrite($string, $length = null) |
|
68 | + { |
|
69 | + return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length)); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * fgets |
|
74 | - * |
|
75 | - * @see http://php.net/fgets |
|
76 | - * @param int $length |
|
77 | - */ |
|
78 | - public function fgets($length = null) |
|
79 | - { |
|
80 | - return fgets($this->handle, $length); |
|
81 | - } |
|
72 | + /** |
|
73 | + * fgets |
|
74 | + * |
|
75 | + * @see http://php.net/fgets |
|
76 | + * @param int $length |
|
77 | + */ |
|
78 | + public function fgets($length = null) |
|
79 | + { |
|
80 | + return fgets($this->handle, $length); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * feof |
|
85 | - * |
|
86 | - * @see http://php.net/feof |
|
87 | - * @return bool |
|
88 | - */ |
|
89 | - public function feof() |
|
90 | - { |
|
91 | - return feof($this->handle); |
|
92 | - } |
|
83 | + /** |
|
84 | + * feof |
|
85 | + * |
|
86 | + * @see http://php.net/feof |
|
87 | + * @return bool |
|
88 | + */ |
|
89 | + public function feof() |
|
90 | + { |
|
91 | + return feof($this->handle); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * fclose |
|
96 | - * |
|
97 | - * @see http://php.net/fclose |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - public function fclose() |
|
101 | - { |
|
102 | - return fclose($this->handle); |
|
103 | - } |
|
94 | + /** |
|
95 | + * fclose |
|
96 | + * |
|
97 | + * @see http://php.net/fclose |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + public function fclose() |
|
101 | + { |
|
102 | + return fclose($this->handle); |
|
103 | + } |
|
104 | 104 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | ){ |
240 | 240 | if( $relation instanceof \EE_Belongs_To_Relation ) { |
241 | 241 | $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
242 | - }else{ |
|
242 | + } else{ |
|
243 | 243 | $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
244 | 244 | } |
245 | 245 | return new \WP_Error( |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | } |
292 | 292 | if( $relation instanceof \EE_Belongs_To_Relation ){ |
293 | 293 | return array_shift( $nice_results ); |
294 | - }else{ |
|
294 | + } else{ |
|
295 | 295 | return $nice_results; |
296 | 296 | } |
297 | 297 | } |
@@ -405,14 +405,14 @@ discard block |
||
405 | 405 | $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
406 | 406 | if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
407 | 407 | unset( $result[ $field_name ] ); |
408 | - }elseif( |
|
408 | + } elseif( |
|
409 | 409 | $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
410 | 410 | ){ |
411 | 411 | $result[ $field_name ] = array( |
412 | 412 | 'raw' => $field_obj->prepare_for_get( $field_value ), |
413 | 413 | 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
414 | 414 | ); |
415 | - }elseif( |
|
415 | + } elseif( |
|
416 | 416 | $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
417 | 417 | ){ |
418 | 418 | $result[ $field_name ] = array( |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | public static function get_related_entity_name( $relation_name, $relation_obj ){ |
596 | 596 | if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
597 | 597 | return strtolower( $relation_name ); |
598 | - }else{ |
|
598 | + } else{ |
|
599 | 599 | return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
600 | 600 | } |
601 | 601 | } |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
666 | 666 | if( in_array( $context, $valid_contexts ) ){ |
667 | 667 | return $context; |
668 | - }else{ |
|
668 | + } else{ |
|
669 | 669 | return \EEM_Base::caps_read; |
670 | 670 | } |
671 | 671 | } |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | $order_by = $query_parameters[ 'order_by' ]; |
691 | 691 | } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
692 | 692 | $order_by = $query_parameters[ 'orderby' ]; |
693 | - }else{ |
|
693 | + } else{ |
|
694 | 694 | $order_by = null; |
695 | 695 | } |
696 | 696 | if( $order_by !== null ){ |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | $group_by = $query_parameters[ 'group_by' ]; |
701 | 701 | } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
702 | 702 | $group_by = $query_parameters[ 'groupby' ]; |
703 | - }else{ |
|
703 | + } else{ |
|
704 | 704 | $group_by = null; |
705 | 705 | } |
706 | 706 | if( $group_by !== null ){ |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
724 | 724 | if( ! is_array( $query_parameters[ 'limit' ] ) ) { |
725 | 725 | $limit_array = explode(',', (string)$query_parameters['limit']); |
726 | - }else { |
|
726 | + } else { |
|
727 | 727 | $limit_array = $query_parameters[ 'limit' ]; |
728 | 728 | } |
729 | 729 | $sanitized_limit = array(); |
@@ -739,12 +739,12 @@ discard block |
||
739 | 739 | $sanitized_limit[] = intval( $limit_part ); |
740 | 740 | } |
741 | 741 | $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
742 | - }else{ |
|
742 | + } else{ |
|
743 | 743 | $model_query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
744 | 744 | } |
745 | 745 | if( isset( $query_parameters[ 'caps' ] ) ) { |
746 | 746 | $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
747 | - }else{ |
|
747 | + } else{ |
|
748 | 748 | $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
749 | 749 | } |
750 | 750 | return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
@@ -764,7 +764,7 @@ discard block |
||
764 | 764 | foreach( $query_params as $key => $value ) { |
765 | 765 | if( is_array( $value ) ) { |
766 | 766 | $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
767 | - }else{ |
|
767 | + } else{ |
|
768 | 768 | $model_ready_query_params[ $key ] = $value; |
769 | 769 | } |
770 | 770 | } |
@@ -816,11 +816,11 @@ discard block |
||
816 | 816 | //found the model name at the exact start |
817 | 817 | $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
818 | 818 | $extracted_fields_to_include[] = $field_sans_model_name; |
819 | - }elseif( $field_to_include == $model_name ){ |
|
819 | + } elseif( $field_to_include == $model_name ){ |
|
820 | 820 | $extracted_fields_to_include[] = '*'; |
821 | 821 | } |
822 | 822 | } |
823 | - }else{ |
|
823 | + } else{ |
|
824 | 824 | //look for ones with no period |
825 | 825 | foreach( $includes as $field_to_include ) { |
826 | 826 | $field_to_include = trim( $field_to_include ); |
@@ -577,7 +577,7 @@ |
||
577 | 577 | * @param \EEM_Base $model |
578 | 578 | * @param array $wpdb_row |
579 | 579 | * @param \WP_REST_Request $rest_request |
580 | - * @return array the _calculations item in the entity |
|
580 | + * @return \stdClass the _calculations item in the entity |
|
581 | 581 | */ |
582 | 582 | protected function _get_entity_calculations( $model, $wpdb_row, $rest_request ) { |
583 | 583 | $calculated_fields = $this->explode_and_get_items_prefixed_with( |
@@ -6,8 +6,8 @@ discard block |
||
6 | 6 | use EventEspresso\core\libraries\rest_api\Rest_Exception; |
7 | 7 | use EventEspresso\core\libraries\rest_api\Model_Data_Translator; |
8 | 8 | |
9 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
10 | - exit( 'No direct script access allowed' ); |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -46,22 +46,22 @@ discard block |
||
46 | 46 | * @param \WP_REST_Request $request |
47 | 47 | * @return \WP_REST_Response|\WP_Error |
48 | 48 | */ |
49 | - public static function handle_request_get_all( \WP_REST_Request $request) { |
|
49 | + public static function handle_request_get_all(\WP_REST_Request $request) { |
|
50 | 50 | $controller = new Read(); |
51 | - try{ |
|
51 | + try { |
|
52 | 52 | $matches = $controller->parse_route( |
53 | 53 | $request->get_route(), |
54 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
55 | - array( 'version', 'model' ) |
|
54 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~', |
|
55 | + array('version', 'model') |
|
56 | 56 | ); |
57 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
58 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
59 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
57 | + $controller->set_requested_version($matches['version']); |
|
58 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
59 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
60 | 60 | return $controller->send_response( |
61 | 61 | new \WP_Error( |
62 | 62 | 'endpoint_parsing_error', |
63 | 63 | sprintf( |
64 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
64 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
65 | 65 | $model_name_singular |
66 | 66 | ) |
67 | 67 | ) |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | } |
70 | 70 | return $controller->send_response( |
71 | 71 | $controller->get_entities_from_model( |
72 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
72 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
73 | 73 | $request |
74 | 74 | ) |
75 | 75 | ); |
76 | - } catch( \Exception $e ) { |
|
77 | - return $controller->send_response( $e ); |
|
76 | + } catch (\Exception $e) { |
|
77 | + return $controller->send_response($e); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
@@ -84,21 +84,21 @@ discard block |
||
84 | 84 | * @param \WP_REST_Request $request |
85 | 85 | * @return \WP_REST_Response|\WP_Error |
86 | 86 | */ |
87 | - public static function handle_request_get_one( \WP_REST_Request $request ) { |
|
87 | + public static function handle_request_get_one(\WP_REST_Request $request) { |
|
88 | 88 | $controller = new Read(); |
89 | - try{ |
|
89 | + try { |
|
90 | 90 | $matches = $controller->parse_route( |
91 | 91 | $request->get_route(), |
92 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
93 | - array( 'version', 'model', 'id' ) ); |
|
94 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
95 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
96 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
92 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~', |
|
93 | + array('version', 'model', 'id') ); |
|
94 | + $controller->set_requested_version($matches['version']); |
|
95 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
96 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
97 | 97 | return $controller->send_response( |
98 | 98 | new \WP_Error( |
99 | 99 | 'endpoint_parsing_error', |
100 | 100 | sprintf( |
101 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
101 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
102 | 102 | $model_name_singular |
103 | 103 | ) |
104 | 104 | ) |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | } |
107 | 107 | return $controller->send_response( |
108 | 108 | $controller->get_entity_from_model( |
109 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
109 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
110 | 110 | $request |
111 | 111 | ) |
112 | 112 | ); |
113 | - } catch( \Exception $e ) { |
|
114 | - return $controller->send_response( $e ); |
|
113 | + } catch (\Exception $e) { |
|
114 | + return $controller->send_response($e); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
@@ -123,40 +123,40 @@ discard block |
||
123 | 123 | * @param \WP_REST_Request $request |
124 | 124 | * @return \WP_REST_Response|\WP_Error |
125 | 125 | */ |
126 | - public static function handle_request_get_related( \WP_REST_Request $request ) { |
|
126 | + public static function handle_request_get_related(\WP_REST_Request $request) { |
|
127 | 127 | $controller = new Read(); |
128 | - try{ |
|
128 | + try { |
|
129 | 129 | $matches = $controller->parse_route( |
130 | 130 | $request->get_route(), |
131 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
132 | - array( 'version', 'model', 'id', 'related_model' ) |
|
131 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~', |
|
132 | + array('version', 'model', 'id', 'related_model') |
|
133 | 133 | ); |
134 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
135 | - $main_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
136 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $main_model_name_singular ) ) { |
|
134 | + $controller->set_requested_version($matches['version']); |
|
135 | + $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
136 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
137 | 137 | return $controller->send_response( |
138 | 138 | new \WP_Error( |
139 | 139 | 'endpoint_parsing_error', |
140 | 140 | sprintf( |
141 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
141 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
142 | 142 | $main_model_name_singular |
143 | 143 | ) |
144 | 144 | ) |
145 | 145 | ); |
146 | 146 | } |
147 | - $main_model = $controller->get_model_version_info()->load_model( $main_model_name_singular ); |
|
147 | + $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
|
148 | 148 | //assume the related model name is plural and try to find the model's name |
149 | - $related_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'related_model' ] ); |
|
150 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
149 | + $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
|
150 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
151 | 151 | //so the word didn't singularize well. Maybe that's just because it's a singular word? |
152 | - $related_model_name_singular = \EEH_Inflector::humanize( $matches[ 'related_model' ] ); |
|
152 | + $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); |
|
153 | 153 | } |
154 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
154 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
155 | 155 | return $controller->send_response( |
156 | 156 | new \WP_Error( |
157 | 157 | 'endpoint_parsing_error', |
158 | 158 | sprintf( |
159 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
159 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
160 | 160 | $related_model_name_singular |
161 | 161 | ) |
162 | 162 | ) |
@@ -165,13 +165,13 @@ discard block |
||
165 | 165 | |
166 | 166 | return $controller->send_response( |
167 | 167 | $controller->get_entities_from_relation( |
168 | - $request->get_param( 'id' ), |
|
169 | - $main_model->related_settings_for( $related_model_name_singular ) , |
|
168 | + $request->get_param('id'), |
|
169 | + $main_model->related_settings_for($related_model_name_singular), |
|
170 | 170 | $request |
171 | 171 | ) |
172 | 172 | ); |
173 | - } catch( \Exception $e ) { |
|
174 | - return $controller->send_response( $e ); |
|
173 | + } catch (\Exception $e) { |
|
174 | + return $controller->send_response($e); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
@@ -184,28 +184,28 @@ discard block |
||
184 | 184 | * @param \WP_REST_Request $request |
185 | 185 | * @return array |
186 | 186 | */ |
187 | - public function get_entities_from_model( $model, $request) { |
|
188 | - $query_params = $this->create_model_query_params( $model, $request->get_params() ); |
|
189 | - if( ! Capabilities::current_user_has_partial_access_to( $model, $query_params[ 'caps' ] ) ) { |
|
190 | - $model_name_plural = \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ); |
|
187 | + public function get_entities_from_model($model, $request) { |
|
188 | + $query_params = $this->create_model_query_params($model, $request->get_params()); |
|
189 | + if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
190 | + $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
191 | 191 | return new \WP_Error( |
192 | - sprintf( 'rest_%s_cannot_list', $model_name_plural ), |
|
192 | + sprintf('rest_%s_cannot_list', $model_name_plural), |
|
193 | 193 | sprintf( |
194 | - __( 'Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso' ), |
|
194 | + __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'), |
|
195 | 195 | $model_name_plural, |
196 | - Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) |
|
196 | + Capabilities::get_missing_permissions_string($model, $query_params['caps']) |
|
197 | 197 | ), |
198 | - array( 'status' => 403 ) |
|
198 | + array('status' => 403) |
|
199 | 199 | ); |
200 | 200 | } |
201 | - if( ! $request->get_header( 'no_rest_headers' ) ) { |
|
202 | - $this->_set_headers_from_query_params( $model, $query_params ); |
|
201 | + if ( ! $request->get_header('no_rest_headers')) { |
|
202 | + $this->_set_headers_from_query_params($model, $query_params); |
|
203 | 203 | } |
204 | 204 | /** @type array $results */ |
205 | - $results = $model->get_all_wpdb_results( $query_params ); |
|
205 | + $results = $model->get_all_wpdb_results($query_params); |
|
206 | 206 | $nice_results = array( ); |
207 | - foreach ( $results as $result ) { |
|
208 | - $nice_results[ ] = $this->create_entity_from_wpdb_result( |
|
207 | + foreach ($results as $result) { |
|
208 | + $nice_results[] = $this->create_entity_from_wpdb_result( |
|
209 | 209 | $model, |
210 | 210 | $result, |
211 | 211 | $request |
@@ -226,64 +226,64 @@ discard block |
||
226 | 226 | * @param \WP_REST_Request $request |
227 | 227 | * @return array |
228 | 228 | */ |
229 | - public function get_entities_from_relation( $id, $relation, $request ) { |
|
230 | - $context = $this->validate_context( $request->get_param( 'caps' )); |
|
229 | + public function get_entities_from_relation($id, $relation, $request) { |
|
230 | + $context = $this->validate_context($request->get_param('caps')); |
|
231 | 231 | $model = $relation->get_this_model(); |
232 | 232 | $related_model = $relation->get_other_model(); |
233 | 233 | //check if they can access the 1st model object |
234 | - $query_params = array( array( $model->primary_key_name() => $id ),'limit' => 1 ); |
|
235 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
234 | + $query_params = array(array($model->primary_key_name() => $id), 'limit' => 1); |
|
235 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
236 | 236 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
237 | 237 | } |
238 | 238 | $restricted_query_params = $query_params; |
239 | - $restricted_query_params[ 'caps' ] = $context; |
|
240 | - $this->_set_debug_info( 'main model query params', $restricted_query_params ); |
|
241 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $related_model, $context ) ); |
|
239 | + $restricted_query_params['caps'] = $context; |
|
240 | + $this->_set_debug_info('main model query params', $restricted_query_params); |
|
241 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context)); |
|
242 | 242 | |
243 | - if( |
|
243 | + if ( |
|
244 | 244 | ! ( |
245 | - Capabilities::current_user_has_partial_access_to( $related_model, $context ) |
|
246 | - && $model->exists( $restricted_query_params ) |
|
245 | + Capabilities::current_user_has_partial_access_to($related_model, $context) |
|
246 | + && $model->exists($restricted_query_params) |
|
247 | 247 | ) |
248 | - ){ |
|
249 | - if( $relation instanceof \EE_Belongs_To_Relation ) { |
|
250 | - $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
|
251 | - }else{ |
|
252 | - $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
|
248 | + ) { |
|
249 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
250 | + $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name()); |
|
251 | + } else { |
|
252 | + $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name()); |
|
253 | 253 | } |
254 | 254 | return new \WP_Error( |
255 | - sprintf( 'rest_%s_cannot_list', $related_model_name_maybe_plural ), |
|
255 | + sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), |
|
256 | 256 | sprintf( |
257 | - __( 'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso' ), |
|
257 | + __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso'), |
|
258 | 258 | $related_model_name_maybe_plural, |
259 | 259 | $relation->get_this_model()->get_this_model_name(), |
260 | 260 | implode( |
261 | 261 | ',', |
262 | 262 | array_keys( |
263 | - Capabilities::get_missing_permissions( $related_model, $context ) |
|
263 | + Capabilities::get_missing_permissions($related_model, $context) |
|
264 | 264 | ) |
265 | 265 | ) |
266 | 266 | ), |
267 | - array( 'status' => 403 ) |
|
267 | + array('status' => 403) |
|
268 | 268 | ); |
269 | 269 | } |
270 | - $query_params = $this->create_model_query_params( $relation->get_other_model(), $request->get_params() ); |
|
271 | - $query_params[0][ $relation->get_this_model()->get_this_model_name() . '.' . $relation->get_this_model()->primary_key_name() ] = $id; |
|
272 | - $query_params[ 'default_where_conditions' ] = 'none'; |
|
273 | - $query_params[ 'caps' ] = $context; |
|
274 | - if( ! $request->get_header( 'no_rest_headers' ) ) { |
|
275 | - $this->_set_headers_from_query_params( $relation->get_other_model(), $query_params ); |
|
270 | + $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params()); |
|
271 | + $query_params[0][$relation->get_this_model()->get_this_model_name().'.'.$relation->get_this_model()->primary_key_name()] = $id; |
|
272 | + $query_params['default_where_conditions'] = 'none'; |
|
273 | + $query_params['caps'] = $context; |
|
274 | + if ( ! $request->get_header('no_rest_headers')) { |
|
275 | + $this->_set_headers_from_query_params($relation->get_other_model(), $query_params); |
|
276 | 276 | } |
277 | 277 | /** @type array $results */ |
278 | - $results = $relation->get_other_model()->get_all_wpdb_results( $query_params ); |
|
278 | + $results = $relation->get_other_model()->get_all_wpdb_results($query_params); |
|
279 | 279 | $nice_results = array(); |
280 | - foreach( $results as $result ) { |
|
280 | + foreach ($results as $result) { |
|
281 | 281 | $nice_result = $this->create_entity_from_wpdb_result( |
282 | 282 | $relation->get_other_model(), |
283 | 283 | $result, |
284 | 284 | $request |
285 | 285 | ); |
286 | - if( $relation instanceof \EE_HABTM_Relation ) { |
|
286 | + if ($relation instanceof \EE_HABTM_Relation) { |
|
287 | 287 | //put the unusual stuff (properties from the HABTM relation) first, and make sure |
288 | 288 | //if there are conflicts we prefer the properties from the main model |
289 | 289 | $join_model_result = $this->create_entity_from_wpdb_result( |
@@ -291,18 +291,18 @@ discard block |
||
291 | 291 | $result, |
292 | 292 | $request |
293 | 293 | ); |
294 | - $joined_result = array_merge( $nice_result, $join_model_result ); |
|
294 | + $joined_result = array_merge($nice_result, $join_model_result); |
|
295 | 295 | //but keep the meta stuff from the main model |
296 | - if( isset( $nice_result['meta'] ) ){ |
|
296 | + if (isset($nice_result['meta'])) { |
|
297 | 297 | $joined_result['meta'] = $nice_result['meta']; |
298 | 298 | } |
299 | 299 | $nice_result = $joined_result; |
300 | 300 | } |
301 | 301 | $nice_results[] = $nice_result; |
302 | 302 | } |
303 | - if( $relation instanceof \EE_Belongs_To_Relation ){ |
|
304 | - return array_shift( $nice_results ); |
|
305 | - }else{ |
|
303 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
304 | + return array_shift($nice_results); |
|
305 | + } else { |
|
306 | 306 | return $nice_results; |
307 | 307 | } |
308 | 308 | } |
@@ -315,30 +315,30 @@ discard block |
||
315 | 315 | * @param array $query_params |
316 | 316 | * @return void |
317 | 317 | */ |
318 | - protected function _set_headers_from_query_params( $model, $query_params ) { |
|
319 | - $this->_set_debug_info( 'model query params', $query_params ); |
|
320 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) ); |
|
318 | + protected function _set_headers_from_query_params($model, $query_params) { |
|
319 | + $this->_set_debug_info('model query params', $query_params); |
|
320 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($model, $query_params['caps'])); |
|
321 | 321 | //normally the limit to a 2-part array, where the 2nd item is the limit |
322 | - if( ! isset( $query_params[ 'limit' ] ) ) { |
|
323 | - $query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
322 | + if ( ! isset($query_params['limit'])) { |
|
323 | + $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
324 | 324 | } |
325 | - if( is_array( $query_params[ 'limit' ] ) ) { |
|
326 | - $limit_parts = $query_params[ 'limit' ]; |
|
325 | + if (is_array($query_params['limit'])) { |
|
326 | + $limit_parts = $query_params['limit']; |
|
327 | 327 | } else { |
328 | - $limit_parts = explode(',', $query_params[ 'limit' ] ); |
|
329 | - if( count( $limit_parts ) == 1 ){ |
|
330 | - $limit_parts = array(0, $limit_parts[ 0 ] ); |
|
328 | + $limit_parts = explode(',', $query_params['limit']); |
|
329 | + if (count($limit_parts) == 1) { |
|
330 | + $limit_parts = array(0, $limit_parts[0]); |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | //remove the group by and having parts of the query, as those will |
334 | 334 | //make the sql query return an array of values, instead of just a single value |
335 | - unset( $query_params[ 'group_by' ], $query_params[ 'having' ], $query_params[ 'limit' ] ); |
|
336 | - $count = $model->count( $query_params, null, true ); |
|
335 | + unset($query_params['group_by'], $query_params['having'], $query_params['limit']); |
|
336 | + $count = $model->count($query_params, null, true); |
|
337 | 337 | |
338 | - $pages = $count / $limit_parts[ 1 ]; |
|
339 | - $this->_set_response_header( 'Total', $count, false ); |
|
340 | - $this->_set_response_header( 'PageSize', $limit_parts[ 1 ], false ); |
|
341 | - $this->_set_response_header( 'TotalPages', ceil( $pages ), false ); |
|
338 | + $pages = $count / $limit_parts[1]; |
|
339 | + $this->_set_response_header('Total', $count, false); |
|
340 | + $this->_set_response_header('PageSize', $limit_parts[1], false); |
|
341 | + $this->_set_response_header('TotalPages', ceil($pages), false); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | |
@@ -351,47 +351,47 @@ discard block |
||
351 | 351 | * @param string $deprecated no longer used |
352 | 352 | * @return array ready for being converted into json for sending to client |
353 | 353 | */ |
354 | - public function create_entity_from_wpdb_result( $model, $db_row, $rest_request, $deprecated = null ) { |
|
355 | - if( ! $rest_request instanceof \WP_REST_Request ) { |
|
354 | + public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) { |
|
355 | + if ( ! $rest_request instanceof \WP_REST_Request) { |
|
356 | 356 | //ok so this was called in the old style, where the 3rd arg was |
357 | 357 | //$include, and the 4th arg was $context |
358 | 358 | //now setup the request just to avoid fatal errors, although we won't be able |
359 | 359 | //to truly make use of it because it's kinda devoid of info |
360 | 360 | $rest_request = new \WP_REST_Request(); |
361 | - $rest_request->set_param( 'include', $rest_request ); |
|
362 | - $rest_request->set_param( 'caps', $deprecated ); |
|
361 | + $rest_request->set_param('include', $rest_request); |
|
362 | + $rest_request->set_param('caps', $deprecated); |
|
363 | 363 | } |
364 | - if( $rest_request->get_param( 'caps' ) == null ) { |
|
365 | - $rest_request->set_param( 'caps', \EEM_Base::caps_read ); |
|
364 | + if ($rest_request->get_param('caps') == null) { |
|
365 | + $rest_request->set_param('caps', \EEM_Base::caps_read); |
|
366 | 366 | } |
367 | - $entity_array = $this->_create_bare_entity_from_wpdb_results( $model, $db_row ); |
|
368 | - $entity_array = $this->_add_extra_fields( $model, $db_row, $entity_array ); |
|
369 | - $entity_array[ '_links' ] = $this->_get_entity_links( $model, $db_row, $entity_array ); |
|
370 | - $entity_array[ '_calculated_fields'] = $this->_get_entity_calculations( $model, $db_row, $rest_request ); |
|
371 | - $entity_array = $this->_include_requested_models( $model, $rest_request, $entity_array ); |
|
367 | + $entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row); |
|
368 | + $entity_array = $this->_add_extra_fields($model, $db_row, $entity_array); |
|
369 | + $entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array); |
|
370 | + $entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request); |
|
371 | + $entity_array = $this->_include_requested_models($model, $rest_request, $entity_array); |
|
372 | 372 | $entity_array = apply_filters( |
373 | 373 | 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
374 | 374 | $entity_array, |
375 | 375 | $model, |
376 | - $rest_request->get_param( 'caps' ), |
|
376 | + $rest_request->get_param('caps'), |
|
377 | 377 | $rest_request, |
378 | 378 | $this |
379 | 379 | ); |
380 | 380 | $result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields( |
381 | 381 | $entity_array, |
382 | 382 | $model, |
383 | - $rest_request->get_param( 'caps' ), |
|
383 | + $rest_request->get_param('caps'), |
|
384 | 384 | $this->get_model_version_info() |
385 | 385 | ); |
386 | 386 | $this->_set_debug_info( |
387 | 387 | 'inaccessible fields', |
388 | - array_keys( array_diff_key( $entity_array, $result_without_inaccessible_fields ) ) |
|
388 | + array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields)) |
|
389 | 389 | ); |
390 | 390 | return apply_filters( |
391 | 391 | 'FHEE__Read__create_entity_from_wpdb_results__entity_return', |
392 | 392 | $result_without_inaccessible_fields, |
393 | 393 | $model, |
394 | - $rest_request->get_param( 'caps' ) |
|
394 | + $rest_request->get_param('caps') |
|
395 | 395 | ); |
396 | 396 | } |
397 | 397 | |
@@ -403,38 +403,38 @@ discard block |
||
403 | 403 | * @param array $db_row |
404 | 404 | * @return array entity mostly ready for converting to JSON and sending in the response |
405 | 405 | */ |
406 | - protected function _create_bare_entity_from_wpdb_results( \EEM_Base $model, $db_row ) { |
|
407 | - $result = $model->deduce_fields_n_values_from_cols_n_values( $db_row ); |
|
408 | - $result = array_intersect_key( $result, $this->get_model_version_info()->fields_on_model_in_this_version( $model ) ); |
|
409 | - foreach( $result as $field_name => $raw_field_value ) { |
|
406 | + protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row) { |
|
407 | + $result = $model->deduce_fields_n_values_from_cols_n_values($db_row); |
|
408 | + $result = array_intersect_key($result, $this->get_model_version_info()->fields_on_model_in_this_version($model)); |
|
409 | + foreach ($result as $field_name => $raw_field_value) { |
|
410 | 410 | $field_obj = $model->field_settings_for($field_name); |
411 | - $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
|
412 | - if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
|
413 | - unset( $result[ $field_name ] ); |
|
414 | - }elseif( |
|
415 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
|
416 | - ){ |
|
417 | - $result[ $field_name ] = array( |
|
418 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
419 | - 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
411 | + $field_value = $field_obj->prepare_for_set_from_db($raw_field_value); |
|
412 | + if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) { |
|
413 | + unset($result[$field_name]); |
|
414 | + }elseif ( |
|
415 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format()) |
|
416 | + ) { |
|
417 | + $result[$field_name] = array( |
|
418 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
419 | + 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
420 | 420 | ); |
421 | - }elseif( |
|
422 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
|
423 | - ){ |
|
424 | - $result[ $field_name ] = array( |
|
425 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
426 | - 'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
421 | + }elseif ( |
|
422 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format()) |
|
423 | + ) { |
|
424 | + $result[$field_name] = array( |
|
425 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
426 | + 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
427 | 427 | ); |
428 | - } elseif ( $field_obj instanceof \EE_Datetime_Field ) { |
|
429 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
428 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
429 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
430 | 430 | $field_obj, |
431 | 431 | $field_value, |
432 | 432 | $this->get_model_version_info()->requested_version() |
433 | 433 | ); |
434 | 434 | } else { |
435 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
435 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
436 | 436 | $field_obj, |
437 | - $field_obj->prepare_for_get( $field_value ), |
|
437 | + $field_obj->prepare_for_get($field_value), |
|
438 | 438 | $this->get_model_version_info()->requested_version() |
439 | 439 | ); |
440 | 440 | } |
@@ -449,9 +449,9 @@ discard block |
||
449 | 449 | * @param array $entity_array |
450 | 450 | * @return array modified entity |
451 | 451 | */ |
452 | - protected function _add_extra_fields( \EEM_Base $model, $db_row, $entity_array ) { |
|
453 | - if( $model instanceof \EEM_CPT_Base ) { |
|
454 | - $entity_array[ 'link' ] = get_permalink( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ); |
|
452 | + protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array) { |
|
453 | + if ($model instanceof \EEM_CPT_Base) { |
|
454 | + $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]); |
|
455 | 455 | } |
456 | 456 | return $entity_array; |
457 | 457 | } |
@@ -465,20 +465,20 @@ discard block |
||
465 | 465 | * @param array $entity_array |
466 | 466 | * @return array the _links item in the entity |
467 | 467 | */ |
468 | - protected function _get_entity_links( $model, $db_row, $entity_array ) { |
|
468 | + protected function _get_entity_links($model, $db_row, $entity_array) { |
|
469 | 469 | //add basic links |
470 | 470 | $links = array( |
471 | 471 | 'self' => array( |
472 | 472 | array( |
473 | 473 | 'href' => $this->get_versioned_link_to( |
474 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] |
|
474 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()] |
|
475 | 475 | ) |
476 | 476 | ) |
477 | 477 | ), |
478 | 478 | 'collection' => array( |
479 | 479 | array( |
480 | 480 | 'href' => $this->get_versioned_link_to( |
481 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) |
|
481 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
482 | 482 | ) |
483 | 483 | ) |
484 | 484 | ), |
@@ -486,24 +486,24 @@ discard block |
||
486 | 486 | |
487 | 487 | //add link to the wp core endpoint, if wp api is active |
488 | 488 | global $wp_rest_server; |
489 | - if( $model instanceof \EEM_CPT_Base && |
|
489 | + if ($model instanceof \EEM_CPT_Base && |
|
490 | 490 | $wp_rest_server instanceof \WP_REST_Server && |
491 | - $wp_rest_server->get_route_options( '/wp/v2/posts' ) ) { |
|
492 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . 'self_wp_post' ] = array( |
|
491 | + $wp_rest_server->get_route_options('/wp/v2/posts')) { |
|
492 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.'self_wp_post'] = array( |
|
493 | 493 | array( |
494 | - 'href' => rest_url( '/wp/v2/posts/' . $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ), |
|
494 | + 'href' => rest_url('/wp/v2/posts/'.$db_row[$model->get_primary_key_field()->get_qualified_column()]), |
|
495 | 495 | 'single' => true |
496 | 496 | ) |
497 | 497 | ); |
498 | 498 | } |
499 | 499 | |
500 | 500 | //add links to related models |
501 | - foreach( $this->get_model_version_info()->relation_settings( $model ) as $relation_name => $relation_obj ) { |
|
502 | - $related_model_part = Read::get_related_entity_name( $relation_name, $relation_obj ); |
|
503 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array( |
|
501 | + foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) { |
|
502 | + $related_model_part = Read::get_related_entity_name($relation_name, $relation_obj); |
|
503 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.$related_model_part] = array( |
|
504 | 504 | array( |
505 | 505 | 'href' => $this->get_versioned_link_to( |
506 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] . '/' . $related_model_part |
|
506 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()].'/'.$related_model_part |
|
507 | 507 | ), |
508 | 508 | 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false |
509 | 509 | ) |
@@ -519,51 +519,51 @@ discard block |
||
519 | 519 | * @param array $entity_array |
520 | 520 | * @return array the modified entity |
521 | 521 | */ |
522 | - protected function _include_requested_models( \EEM_Base $model, \WP_REST_Request $rest_request, $entity_array ) { |
|
523 | - $includes_for_this_model = $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'include' ), '' ); |
|
524 | - $includes_for_this_model = $this->_remove_model_names_from_array( $includes_for_this_model ); |
|
522 | + protected function _include_requested_models(\EEM_Base $model, \WP_REST_Request $rest_request, $entity_array) { |
|
523 | + $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), ''); |
|
524 | + $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model); |
|
525 | 525 | //if they passed in * or didn't specify any includes, return everything |
526 | - if( ! in_array( '*', $includes_for_this_model ) |
|
527 | - && ! empty( $includes_for_this_model ) ) { |
|
528 | - if( $model->has_primary_key_field() ) { |
|
526 | + if ( ! in_array('*', $includes_for_this_model) |
|
527 | + && ! empty($includes_for_this_model)) { |
|
528 | + if ($model->has_primary_key_field()) { |
|
529 | 529 | //always include the primary key. ya just gotta know that at least |
530 | 530 | $includes_for_this_model[] = $model->primary_key_name(); |
531 | 531 | } |
532 | - if( $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'calculate' ), '' ) ) { |
|
532 | + if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) { |
|
533 | 533 | $includes_for_this_model[] = '_calculated_fields'; |
534 | 534 | } |
535 | - $entity_array = array_intersect_key( $entity_array, array_flip( $includes_for_this_model ) ); |
|
535 | + $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model)); |
|
536 | 536 | } |
537 | - $relation_settings = $this->get_model_version_info()->relation_settings( $model ); |
|
538 | - foreach( $relation_settings as $relation_name => $relation_obj ) { |
|
537 | + $relation_settings = $this->get_model_version_info()->relation_settings($model); |
|
538 | + foreach ($relation_settings as $relation_name => $relation_obj) { |
|
539 | 539 | $related_fields_to_include = $this->explode_and_get_items_prefixed_with( |
540 | - $rest_request->get_param( 'include' ), |
|
540 | + $rest_request->get_param('include'), |
|
541 | 541 | $relation_name |
542 | 542 | ); |
543 | 543 | $related_fields_to_calculate = $this->explode_and_get_items_prefixed_with( |
544 | - $rest_request->get_param( 'calculate' ), |
|
544 | + $rest_request->get_param('calculate'), |
|
545 | 545 | $relation_name |
546 | 546 | ); |
547 | 547 | //did they specify they wanted to include a related model, or |
548 | 548 | //specific fields from a related model? |
549 | 549 | //or did they specify to calculate a field from a related model? |
550 | - if( $related_fields_to_include || $related_fields_to_calculate ) { |
|
550 | + if ($related_fields_to_include || $related_fields_to_calculate) { |
|
551 | 551 | //if so, we should include at least some part of the related model |
552 | 552 | $pretend_related_request = new \WP_REST_Request(); |
553 | 553 | $pretend_related_request->set_query_params( |
554 | 554 | array( |
555 | - 'caps' => $rest_request->get_param( 'caps' ), |
|
555 | + 'caps' => $rest_request->get_param('caps'), |
|
556 | 556 | 'include' => $related_fields_to_include, |
557 | 557 | 'calculate' => $related_fields_to_calculate, |
558 | 558 | ) |
559 | 559 | ); |
560 | - $pretend_related_request->add_header( 'no_rest_headers', true ); |
|
560 | + $pretend_related_request->add_header('no_rest_headers', true); |
|
561 | 561 | $related_results = $this->get_entities_from_relation( |
562 | - $entity_array[ $model->primary_key_name() ], |
|
562 | + $entity_array[$model->primary_key_name()], |
|
563 | 563 | $relation_obj, |
564 | 564 | $pretend_related_request |
565 | 565 | ); |
566 | - $entity_array[ Read::get_related_entity_name( $relation_name, $relation_obj ) ] = $related_results instanceof \WP_Error |
|
566 | + $entity_array[Read::get_related_entity_name($relation_name, $relation_obj)] = $related_results instanceof \WP_Error |
|
567 | 567 | ? null |
568 | 568 | : $related_results; |
569 | 569 | } |
@@ -577,8 +577,8 @@ discard block |
||
577 | 577 | * @param array $arr |
578 | 578 | * @return array |
579 | 579 | */ |
580 | - private function _remove_model_names_from_array( $arr ) { |
|
581 | - return array_diff( $arr, array_keys( \EE_Registry::instance()->non_abstract_db_models ) ); |
|
580 | + private function _remove_model_names_from_array($arr) { |
|
581 | + return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models)); |
|
582 | 582 | } |
583 | 583 | /** |
584 | 584 | * Gets the calculated fields for the response |
@@ -588,15 +588,15 @@ discard block |
||
588 | 588 | * @param \WP_REST_Request $rest_request |
589 | 589 | * @return array the _calculations item in the entity |
590 | 590 | */ |
591 | - protected function _get_entity_calculations( $model, $wpdb_row, $rest_request ) { |
|
591 | + protected function _get_entity_calculations($model, $wpdb_row, $rest_request) { |
|
592 | 592 | $calculated_fields = $this->explode_and_get_items_prefixed_with( |
593 | - $rest_request->get_param( 'calculate' ), |
|
593 | + $rest_request->get_param('calculate'), |
|
594 | 594 | '' |
595 | 595 | ); |
596 | 596 | //note: setting calculate=* doesn't do anything |
597 | 597 | $calculated_fields_to_return = new \stdClass(); |
598 | - foreach( $calculated_fields as $field_to_calculate ) { |
|
599 | - try{ |
|
598 | + foreach ($calculated_fields as $field_to_calculate) { |
|
599 | + try { |
|
600 | 600 | $calculated_fields_to_return->$field_to_calculate = Model_Data_Translator::prepare_field_value_for_json( |
601 | 601 | null, |
602 | 602 | $this->_fields_calculator->retrieve_calculated_field_value( |
@@ -608,10 +608,10 @@ discard block |
||
608 | 608 | ), |
609 | 609 | $this->get_model_version_info()->requested_version() |
610 | 610 | ); |
611 | - } catch( Rest_Exception $e ) { |
|
611 | + } catch (Rest_Exception $e) { |
|
612 | 612 | //if we don't have permission to read it, just leave it out. but let devs know about the problem |
613 | 613 | $this->_set_response_header( |
614 | - 'Notices-Field-Calculation-Errors[' . $e->get_string_code() . '][' . $model->get_this_model_name() . '][' . $field_to_calculate . ']', |
|
614 | + 'Notices-Field-Calculation-Errors['.$e->get_string_code().']['.$model->get_this_model_name().']['.$field_to_calculate.']', |
|
615 | 615 | $e->getMessage(), |
616 | 616 | true |
617 | 617 | ); |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | * @param string $link_part_after_version_and_slash eg "events/10/datetimes" |
626 | 626 | * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes" |
627 | 627 | */ |
628 | - public function get_versioned_link_to( $link_part_after_version_and_slash ) { |
|
628 | + public function get_versioned_link_to($link_part_after_version_and_slash) { |
|
629 | 629 | return rest_url( |
630 | 630 | \EED_Core_Rest_Api::ee_api_namespace |
631 | 631 | . $this->get_model_version_info()->requested_version() |
@@ -641,11 +641,11 @@ discard block |
||
641 | 641 | * @param \EE_Model_Relation_Base $relation_obj |
642 | 642 | * @return string |
643 | 643 | */ |
644 | - public static function get_related_entity_name( $relation_name, $relation_obj ){ |
|
645 | - if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
|
646 | - return strtolower( $relation_name ); |
|
647 | - }else{ |
|
648 | - return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
|
644 | + public static function get_related_entity_name($relation_name, $relation_obj) { |
|
645 | + if ($relation_obj instanceof \EE_Belongs_To_Relation) { |
|
646 | + return strtolower($relation_name); |
|
647 | + } else { |
|
648 | + return \EEH_Inflector::pluralize_and_lower($relation_name); |
|
649 | 649 | } |
650 | 650 | } |
651 | 651 | |
@@ -658,43 +658,43 @@ discard block |
||
658 | 658 | * @param \WP_REST_Request $request |
659 | 659 | * @return array |
660 | 660 | */ |
661 | - public function get_entity_from_model( $model, $request ) { |
|
662 | - $query_params = array( array( $model->primary_key_name() => $request->get_param( 'id' ) ),'limit' => 1); |
|
663 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
661 | + public function get_entity_from_model($model, $request) { |
|
662 | + $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1); |
|
663 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
664 | 664 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
665 | 665 | } |
666 | 666 | $restricted_query_params = $query_params; |
667 | - $restricted_query_params[ 'caps' ] = $this->validate_context( $request->get_param( 'caps' ) ); |
|
668 | - $this->_set_debug_info( 'model query params', $restricted_query_params ); |
|
669 | - $model_rows = $model->get_all_wpdb_results( $restricted_query_params ); |
|
670 | - if ( ! empty ( $model_rows ) ) { |
|
667 | + $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
|
668 | + $this->_set_debug_info('model query params', $restricted_query_params); |
|
669 | + $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
|
670 | + if ( ! empty ($model_rows)) { |
|
671 | 671 | return $this->create_entity_from_wpdb_result( |
672 | 672 | $model, |
673 | - array_shift( $model_rows ), |
|
673 | + array_shift($model_rows), |
|
674 | 674 | $request ); |
675 | 675 | } else { |
676 | 676 | //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
677 | - $lowercase_model_name = strtolower( $model->get_this_model_name() ); |
|
678 | - $model_rows_found_sans_restrictions = $model->get_all_wpdb_results( $query_params ); |
|
679 | - if( ! empty( $model_rows_found_sans_restrictions ) ) { |
|
677 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
678 | + $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
|
679 | + if ( ! empty($model_rows_found_sans_restrictions)) { |
|
680 | 680 | //you got shafted- it existed but we didn't want to tell you! |
681 | 681 | return new \WP_Error( |
682 | 682 | 'rest_user_cannot_read', |
683 | 683 | sprintf( |
684 | - __( 'Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso' ), |
|
685 | - strtolower( $model->get_this_model_name() ), |
|
684 | + __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), |
|
685 | + strtolower($model->get_this_model_name()), |
|
686 | 686 | Capabilities::get_missing_permissions_string( |
687 | 687 | $model, |
688 | - $this->validate_context( $request->get_param( 'caps' ) ) ) |
|
688 | + $this->validate_context($request->get_param('caps')) ) |
|
689 | 689 | ), |
690 | - array( 'status' => 403 ) |
|
690 | + array('status' => 403) |
|
691 | 691 | ); |
692 | 692 | } else { |
693 | 693 | //it's not you. It just doesn't exist |
694 | 694 | return new \WP_Error( |
695 | - sprintf( 'rest_%s_invalid_id', $lowercase_model_name ), |
|
696 | - sprintf( __( 'Invalid %s ID.', 'event_espresso' ), $lowercase_model_name ), |
|
697 | - array( 'status' => 404 ) |
|
695 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
696 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
697 | + array('status' => 404) |
|
698 | 698 | ); |
699 | 699 | } |
700 | 700 | } |
@@ -707,14 +707,14 @@ discard block |
||
707 | 707 | * @param string $context |
708 | 708 | * @return string array key of EEM_Base::cap_contexts_to_cap_action_map() |
709 | 709 | */ |
710 | - public function validate_context( $context ) { |
|
711 | - if( ! $context ) { |
|
710 | + public function validate_context($context) { |
|
711 | + if ( ! $context) { |
|
712 | 712 | $context = \EEM_Base::caps_read; |
713 | 713 | } |
714 | 714 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
715 | - if( in_array( $context, $valid_contexts ) ){ |
|
715 | + if (in_array($context, $valid_contexts)) { |
|
716 | 716 | return $context; |
717 | - }else{ |
|
717 | + } else { |
|
718 | 718 | return \EEM_Base::caps_read; |
719 | 719 | } |
720 | 720 | } |
@@ -733,77 +733,77 @@ discard block |
||
733 | 733 | * that absolutely no results should be returned |
734 | 734 | * @throws \EE_Error |
735 | 735 | */ |
736 | - public function create_model_query_params( $model, $query_parameters ) { |
|
736 | + public function create_model_query_params($model, $query_parameters) { |
|
737 | 737 | $model_query_params = array( ); |
738 | - if ( isset( $query_parameters[ 'where' ] ) ) { |
|
739 | - $model_query_params[ 0 ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
740 | - $query_parameters[ 'where' ], |
|
738 | + if (isset($query_parameters['where'])) { |
|
739 | + $model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
740 | + $query_parameters['where'], |
|
741 | 741 | $model, |
742 | 742 | $this->get_model_version_info()->requested_version() |
743 | 743 | ); |
744 | 744 | } |
745 | - if ( isset( $query_parameters[ 'order_by' ] ) ) { |
|
746 | - $order_by = $query_parameters[ 'order_by' ]; |
|
747 | - } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
|
748 | - $order_by = $query_parameters[ 'orderby' ]; |
|
749 | - }else{ |
|
745 | + if (isset($query_parameters['order_by'])) { |
|
746 | + $order_by = $query_parameters['order_by']; |
|
747 | + } elseif (isset($query_parameters['orderby'])) { |
|
748 | + $order_by = $query_parameters['orderby']; |
|
749 | + } else { |
|
750 | 750 | $order_by = null; |
751 | 751 | } |
752 | - if( $order_by !== null ){ |
|
753 | - $model_query_params[ 'order_by' ] = $order_by; |
|
752 | + if ($order_by !== null) { |
|
753 | + $model_query_params['order_by'] = $order_by; |
|
754 | 754 | } |
755 | - if ( isset( $query_parameters[ 'group_by' ] ) ) { |
|
756 | - $group_by = $query_parameters[ 'group_by' ]; |
|
757 | - } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
|
758 | - $group_by = $query_parameters[ 'groupby' ]; |
|
759 | - }else{ |
|
760 | - $group_by = array_keys( $model->get_combined_primary_key_fields() ); |
|
755 | + if (isset($query_parameters['group_by'])) { |
|
756 | + $group_by = $query_parameters['group_by']; |
|
757 | + } elseif (isset($query_parameters['groupby'])) { |
|
758 | + $group_by = $query_parameters['groupby']; |
|
759 | + } else { |
|
760 | + $group_by = array_keys($model->get_combined_primary_key_fields()); |
|
761 | 761 | } |
762 | - if( $group_by !== null ){ |
|
763 | - $model_query_params[ 'group_by' ] = $group_by; |
|
762 | + if ($group_by !== null) { |
|
763 | + $model_query_params['group_by'] = $group_by; |
|
764 | 764 | } |
765 | - if ( isset( $query_parameters[ 'having' ] ) ) { |
|
766 | - $model_query_params[ 'having' ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
767 | - $query_parameters[ 'having' ], |
|
765 | + if (isset($query_parameters['having'])) { |
|
766 | + $model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
767 | + $query_parameters['having'], |
|
768 | 768 | $model, |
769 | 769 | $this->get_model_version_info()->requested_version() |
770 | 770 | ); |
771 | 771 | } |
772 | - if ( isset( $query_parameters[ 'order' ] ) ) { |
|
773 | - $model_query_params[ 'order' ] = $query_parameters[ 'order' ]; |
|
772 | + if (isset($query_parameters['order'])) { |
|
773 | + $model_query_params['order'] = $query_parameters['order']; |
|
774 | 774 | } |
775 | - if ( isset( $query_parameters[ 'mine' ] ) ){ |
|
776 | - $model_query_params = $model->alter_query_params_to_only_include_mine( $model_query_params ); |
|
775 | + if (isset($query_parameters['mine'])) { |
|
776 | + $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params); |
|
777 | 777 | } |
778 | - if( isset( $query_parameters[ 'limit' ] ) ) { |
|
778 | + if (isset($query_parameters['limit'])) { |
|
779 | 779 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
780 | - if( ! is_array( $query_parameters[ 'limit' ] ) ) { |
|
781 | - $limit_array = explode(',', (string)$query_parameters['limit']); |
|
782 | - }else { |
|
783 | - $limit_array = $query_parameters[ 'limit' ]; |
|
780 | + if ( ! is_array($query_parameters['limit'])) { |
|
781 | + $limit_array = explode(',', (string) $query_parameters['limit']); |
|
782 | + } else { |
|
783 | + $limit_array = $query_parameters['limit']; |
|
784 | 784 | } |
785 | 785 | $sanitized_limit = array(); |
786 | - foreach( $limit_array as $key => $limit_part ) { |
|
787 | - if( $this->_debug_mode && ( ! is_numeric( $limit_part ) || count( $sanitized_limit ) > 2 ) ) { |
|
786 | + foreach ($limit_array as $key => $limit_part) { |
|
787 | + if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
788 | 788 | throw new \EE_Error( |
789 | 789 | sprintf( |
790 | - __( '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' ), |
|
791 | - json_encode( $query_parameters[ 'limit' ] ) |
|
790 | + __('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'), |
|
791 | + json_encode($query_parameters['limit']) |
|
792 | 792 | ) |
793 | 793 | ); |
794 | 794 | } |
795 | - $sanitized_limit[] = (int)$limit_part; |
|
795 | + $sanitized_limit[] = (int) $limit_part; |
|
796 | 796 | } |
797 | - $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
|
798 | - }else{ |
|
799 | - $model_query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
797 | + $model_query_params['limit'] = implode(',', $sanitized_limit); |
|
798 | + } else { |
|
799 | + $model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
800 | 800 | } |
801 | - if( isset( $query_parameters[ 'caps' ] ) ) { |
|
802 | - $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
|
803 | - }else{ |
|
804 | - $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
|
801 | + if (isset($query_parameters['caps'])) { |
|
802 | + $model_query_params['caps'] = $this->validate_context($query_parameters['caps']); |
|
803 | + } else { |
|
804 | + $model_query_params['caps'] = \EEM_Base::caps_read; |
|
805 | 805 | } |
806 | - return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
|
806 | + return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model); |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | |
@@ -815,13 +815,13 @@ discard block |
||
815 | 815 | * @param array $query_params sub-array from @see EEM_Base::get_all() |
816 | 816 | * @return array |
817 | 817 | */ |
818 | - public function prepare_rest_query_params_key_for_models( $model, $query_params ) { |
|
818 | + public function prepare_rest_query_params_key_for_models($model, $query_params) { |
|
819 | 819 | $model_ready_query_params = array(); |
820 | - foreach( $query_params as $key => $value ) { |
|
821 | - if( is_array( $value ) ) { |
|
822 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
|
823 | - }else{ |
|
824 | - $model_ready_query_params[ $key ] = $value; |
|
820 | + foreach ($query_params as $key => $value) { |
|
821 | + if (is_array($value)) { |
|
822 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value); |
|
823 | + } else { |
|
824 | + $model_ready_query_params[$key] = $value; |
|
825 | 825 | } |
826 | 826 | } |
827 | 827 | return $model_ready_query_params; |
@@ -835,13 +835,13 @@ discard block |
||
835 | 835 | * @param $query_params |
836 | 836 | * @return array |
837 | 837 | */ |
838 | - public function prepare_rest_query_params_values_for_models( $model, $query_params ) { |
|
838 | + public function prepare_rest_query_params_values_for_models($model, $query_params) { |
|
839 | 839 | $model_ready_query_params = array(); |
840 | - foreach( $query_params as $key => $value ) { |
|
841 | - if( is_array( $value ) ) { |
|
842 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_values_for_models( $model, $value ); |
|
840 | + foreach ($query_params as $key => $value) { |
|
841 | + if (is_array($value)) { |
|
842 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value); |
|
843 | 843 | } else { |
844 | - $model_ready_query_params[ $key ] = $value; |
|
844 | + $model_ready_query_params[$key] = $value; |
|
845 | 845 | } |
846 | 846 | } |
847 | 847 | return $model_ready_query_params; |
@@ -856,33 +856,33 @@ discard block |
||
856 | 856 | * we only return strings starting with that and a period; if no prefix was specified |
857 | 857 | * we return all items containing NO periods |
858 | 858 | */ |
859 | - public function explode_and_get_items_prefixed_with( $string_to_explode, $prefix ) { |
|
860 | - if( is_string( $string_to_explode ) ) { |
|
861 | - $exploded_contents = explode( ',', $string_to_explode ); |
|
862 | - } else if( is_array( $string_to_explode ) ) { |
|
859 | + public function explode_and_get_items_prefixed_with($string_to_explode, $prefix) { |
|
860 | + if (is_string($string_to_explode)) { |
|
861 | + $exploded_contents = explode(',', $string_to_explode); |
|
862 | + } else if (is_array($string_to_explode)) { |
|
863 | 863 | $exploded_contents = $string_to_explode; |
864 | 864 | } else { |
865 | 865 | $exploded_contents = array(); |
866 | 866 | } |
867 | 867 | //if the string was empty, we want an empty array |
868 | - $exploded_contents = array_filter( $exploded_contents ); |
|
868 | + $exploded_contents = array_filter($exploded_contents); |
|
869 | 869 | $contents_with_prefix = array(); |
870 | - foreach( $exploded_contents as $item ) { |
|
871 | - $item = trim( $item ); |
|
870 | + foreach ($exploded_contents as $item) { |
|
871 | + $item = trim($item); |
|
872 | 872 | //if no prefix was provided, so we look for items with no "." in them |
873 | - if( ! $prefix ) { |
|
873 | + if ( ! $prefix) { |
|
874 | 874 | //does this item have a period? |
875 | - if( strpos( $item, '.' ) === false ) { |
|
875 | + if (strpos($item, '.') === false) { |
|
876 | 876 | //if not, then its what we're looking for |
877 | 877 | $contents_with_prefix[] = $item; |
878 | 878 | } |
879 | - } else if( strpos( $item, $prefix . '.' ) === 0 ) { |
|
879 | + } else if (strpos($item, $prefix.'.') === 0) { |
|
880 | 880 | //this item has the prefix and a period, grab it |
881 | 881 | $contents_with_prefix[] = substr( |
882 | 882 | $item, |
883 | - strpos( $item, $prefix . '.' ) + strlen( $prefix . '.' ) |
|
883 | + strpos($item, $prefix.'.') + strlen($prefix.'.') |
|
884 | 884 | ); |
885 | - } else if( $item === $prefix ) { |
|
885 | + } else if ($item === $prefix) { |
|
886 | 886 | //this item is JUST the prefix |
887 | 887 | //so let's grab everything after, which is a blank string |
888 | 888 | $contents_with_prefix[] = ''; |
@@ -905,33 +905,33 @@ discard block |
||
905 | 905 | * the fields for that model, with the model's name removed from each. |
906 | 906 | * If $include_string was blank or '*' returns an empty array |
907 | 907 | */ |
908 | - public function extract_includes_for_this_model( $include_string, $model_name = null ) { |
|
909 | - if( is_array( $include_string ) ) { |
|
910 | - $include_string = implode( ',', $include_string ); |
|
908 | + public function extract_includes_for_this_model($include_string, $model_name = null) { |
|
909 | + if (is_array($include_string)) { |
|
910 | + $include_string = implode(',', $include_string); |
|
911 | 911 | } |
912 | - if( $include_string === '*' || $include_string === '' ) { |
|
912 | + if ($include_string === '*' || $include_string === '') { |
|
913 | 913 | return array(); |
914 | 914 | } |
915 | - $includes = explode( ',', $include_string ); |
|
915 | + $includes = explode(',', $include_string); |
|
916 | 916 | $extracted_fields_to_include = array(); |
917 | - if( $model_name ){ |
|
918 | - foreach( $includes as $field_to_include ) { |
|
919 | - $field_to_include = trim( $field_to_include ); |
|
920 | - if( strpos( $field_to_include, $model_name . '.' ) === 0 ) { |
|
917 | + if ($model_name) { |
|
918 | + foreach ($includes as $field_to_include) { |
|
919 | + $field_to_include = trim($field_to_include); |
|
920 | + if (strpos($field_to_include, $model_name.'.') === 0) { |
|
921 | 921 | //found the model name at the exact start |
922 | - $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
|
922 | + $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include); |
|
923 | 923 | $extracted_fields_to_include[] = $field_sans_model_name; |
924 | - }elseif( $field_to_include == $model_name ){ |
|
924 | + }elseif ($field_to_include == $model_name) { |
|
925 | 925 | $extracted_fields_to_include[] = '*'; |
926 | 926 | } |
927 | 927 | } |
928 | - }else{ |
|
928 | + } else { |
|
929 | 929 | //look for ones with no period |
930 | - foreach( $includes as $field_to_include ) { |
|
931 | - $field_to_include = trim( $field_to_include ); |
|
930 | + foreach ($includes as $field_to_include) { |
|
931 | + $field_to_include = trim($field_to_include); |
|
932 | 932 | if ( |
933 | - strpos( $field_to_include, '.' ) === false |
|
934 | - && ! $this->get_model_version_info()->is_model_name_in_this_version( $field_to_include ) |
|
933 | + strpos($field_to_include, '.') === false |
|
934 | + && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include) |
|
935 | 935 | ) { |
936 | 936 | $extracted_fields_to_include[] = $field_to_include; |
937 | 937 | } |
@@ -5,7 +5,9 @@ |
||
5 | 5 | * @subpackage plugin api, messages |
6 | 6 | * @since 4.5.0 |
7 | 7 | */ |
8 | -if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
8 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
9 | + exit('No direct script access allowed'); |
|
10 | +} |
|
9 | 11 | |
10 | 12 | /** |
11 | 13 | * Use this to register or deregister a new message template pack variation for the EE messages system. |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | |
23 | 23 | public function __construct() { |
24 | 24 | $this->name = 'newsletter'; |
25 | - $this->description = __( 'Newsletter message types are triggered manually by the admin for sending mass email to select groups of registrants.', 'event_espresso' ); |
|
25 | + $this->description = __('Newsletter message types are triggered manually by the admin for sending mass email to select groups of registrants.', 'event_espresso'); |
|
26 | 26 | $this->label = array( |
27 | - 'singular' => __( 'newsletter', 'event_espresso' ), |
|
28 | - 'plural' => __( 'newsletters', 'event_espresso' ) |
|
27 | + 'singular' => __('newsletter', 'event_espresso'), |
|
28 | + 'plural' => __('newsletters', 'event_espresso') |
|
29 | 29 | ); |
30 | 30 | $this->_master_templates = array( |
31 | 31 | 'email' => 'registration', |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | |
50 | 50 | |
51 | 51 | |
52 | - protected function _get_data_for_context( $context, EE_Registration $registration, $id ) { |
|
52 | + protected function _get_data_for_context($context, EE_Registration $registration, $id) { |
|
53 | 53 | //newsletter message type data handler is 'Registrations' and it expects an array of EE_Registration objects. |
54 | - return array( $registration ); |
|
54 | + return array($registration); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -64,15 +64,15 @@ discard block |
||
64 | 64 | |
65 | 65 | protected function _set_contexts() { |
66 | 66 | $this->_context_label = array( |
67 | - 'label' => __( 'recipient', 'event_espresso' ), |
|
68 | - 'plural' => __( 'recipients', 'event_espresso' ), |
|
69 | - 'description' => __( 'Recipient\'s are who will receive the message.', 'event_espresso' ) |
|
67 | + 'label' => __('recipient', 'event_espresso'), |
|
68 | + 'plural' => __('recipients', 'event_espresso'), |
|
69 | + 'description' => __('Recipient\'s are who will receive the message.', 'event_espresso') |
|
70 | 70 | ); |
71 | 71 | |
72 | 72 | $this->_contexts = array( |
73 | 73 | 'attendee' => array( |
74 | - 'label' => __( 'Registrant', 'event_espresso' ), |
|
75 | - 'description' => __( 'This template goes to selected registrants.', 'event_espresso' ) |
|
74 | + 'label' => __('Registrant', 'event_espresso'), |
|
75 | + 'description' => __('This template goes to selected registrants.', 'event_espresso') |
|
76 | 76 | ) |
77 | 77 | ); |
78 | 78 | } |
@@ -98,13 +98,13 @@ discard block |
||
98 | 98 | 'newsletter', |
99 | 99 | ); |
100 | 100 | |
101 | - foreach ( $this->_valid_shortcodes as $context => $shortcodes ) { |
|
102 | - foreach ( $shortcodes as $key => $shortcode ) { |
|
103 | - if ( ! in_array( $shortcode, $included_shortcodes ) ) { |
|
104 | - unset( $this->_valid_shortcodes[ $context ][ $key ] ); |
|
101 | + foreach ($this->_valid_shortcodes as $context => $shortcodes) { |
|
102 | + foreach ($shortcodes as $key => $shortcode) { |
|
103 | + if ( ! in_array($shortcode, $included_shortcodes)) { |
|
104 | + unset($this->_valid_shortcodes[$context][$key]); |
|
105 | 105 | } |
106 | 106 | } |
107 | - $this->_valid_shortcodes[ $context ][] = 'newsletter'; |
|
107 | + $this->_valid_shortcodes[$context][] = 'newsletter'; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | } |
@@ -118,44 +118,44 @@ discard block |
||
118 | 118 | $addressee = array(); |
119 | 119 | |
120 | 120 | //looping through registrations |
121 | - foreach ( $this->_data->registrations as $reg_id => $details ) { |
|
121 | + foreach ($this->_data->registrations as $reg_id => $details) { |
|
122 | 122 | //set $attendee array to blank on each loop |
123 | 123 | $aee = array(); |
124 | 124 | |
125 | 125 | //need to get the attendee from this registration. |
126 | - $attendee = isset( $details['att_obj'] ) && $details['att_obj'] instanceof EE_Attendee |
|
126 | + $attendee = isset($details['att_obj']) && $details['att_obj'] instanceof EE_Attendee |
|
127 | 127 | ? $details['att_obj'] |
128 | 128 | : null; |
129 | 129 | |
130 | - if ( ! $attendee instanceof EE_Attendee ) { |
|
130 | + if ( ! $attendee instanceof EE_Attendee) { |
|
131 | 131 | continue; |
132 | 132 | } |
133 | 133 | |
134 | 134 | //set $aee from attendee object |
135 | 135 | $aee['att_obj'] = $attendee; |
136 | - $aee['reg_objs'] = isset( $this->_data->attendees[ $attendee->ID() ]['reg_objs'] ) |
|
137 | - ? $this->_data->attendees[ $attendee->ID() ]['reg_objs'] |
|
136 | + $aee['reg_objs'] = isset($this->_data->attendees[$attendee->ID()]['reg_objs']) |
|
137 | + ? $this->_data->attendees[$attendee->ID()]['reg_objs'] |
|
138 | 138 | : array(); |
139 | 139 | $aee['attendee_email'] = $attendee->email(); |
140 | - $aee['tkt_objs'] = isset( $this->_data->attendees[ $attendee->ID() ]['tkt_objs'] ) |
|
141 | - ? $this->_data->attendees[ $attendee->ID() ]['tkt_objs'] |
|
140 | + $aee['tkt_objs'] = isset($this->_data->attendees[$attendee->ID()]['tkt_objs']) |
|
141 | + ? $this->_data->attendees[$attendee->ID()]['tkt_objs'] |
|
142 | 142 | : array(); |
143 | 143 | |
144 | - if ( isset( $this->_data->attendees[ $attendee->ID() ]['evt_objs'] ) ) { |
|
145 | - $aee['evt_objs'] = $this->_data->attendees[ $attendee->ID() ]['evt_objs']; |
|
146 | - $aee['events'] = $this->_data->attendees[ $attendee->ID() ]['evt_objs']; |
|
144 | + if (isset($this->_data->attendees[$attendee->ID()]['evt_objs'])) { |
|
145 | + $aee['evt_objs'] = $this->_data->attendees[$attendee->ID()]['evt_objs']; |
|
146 | + $aee['events'] = $this->_data->attendees[$attendee->ID()]['evt_objs']; |
|
147 | 147 | } else { |
148 | 148 | $aee['evt_objs'] = $aee['events'] = array(); |
149 | 149 | } |
150 | 150 | |
151 | - $aee['reg_obj'] = isset( $details['reg_obj'] ) |
|
151 | + $aee['reg_obj'] = isset($details['reg_obj']) |
|
152 | 152 | ? $details['reg_obj'] |
153 | 153 | : null; |
154 | 154 | $aee['attendees'] = $this->_data->attendees; |
155 | 155 | |
156 | 156 | //merge in the primary attendee data |
157 | - $aee = array_merge( $this->_default_addressee_data, $aee ); |
|
158 | - $addressee[] = new EE_Messages_Addressee( $aee ); |
|
157 | + $aee = array_merge($this->_default_addressee_data, $aee); |
|
158 | + $addressee[] = new EE_Messages_Addressee($aee); |
|
159 | 159 | } |
160 | 160 | return $addressee; |
161 | 161 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * This prepares data for message types that send messages for multiple registrations (that could span multiple transactions) |
@@ -20,13 +20,13 @@ discard block |
||
20 | 20 | * @throws EE_Error |
21 | 21 | * @access protected |
22 | 22 | */ |
23 | - public function __construct( $data = array() ) { |
|
23 | + public function __construct($data = array()) { |
|
24 | 24 | |
25 | 25 | //validate that the first element in the array is an EE_Registration object. |
26 | - if ( ! reset( $data ) instanceof EE_Registration ) { |
|
27 | - throw new EE_Error( __( 'The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', 'event_espresso' ) ); |
|
26 | + if ( ! reset($data) instanceof EE_Registration) { |
|
27 | + throw new EE_Error(__('The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', 'event_espresso')); |
|
28 | 28 | } |
29 | - parent::__construct( $data ); |
|
29 | + parent::__construct($data); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 |
@@ -1,5 +1,7 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | + exit( 'No direct script access allowed' ); |
|
4 | +} |
|
3 | 5 | |
4 | 6 | /** |
5 | 7 | * This prepares data for message types that send messages for multiple registrations (that could span multiple transactions) |
@@ -347,7 +347,7 @@ |
||
347 | 347 | $total_ticket_count++; |
348 | 348 | $tickets[ $ticket->ID() ]['ticket'] = $ticket; |
349 | 349 | $tickets[ $ticket->ID() ]['count'] = is_array( $tickets[ $ticket->ID() ] ) |
350 | - && isset( $tickets[ $ticket->ID() ]['count'] ) |
|
350 | + && isset( $tickets[ $ticket->ID() ]['count'] ) |
|
351 | 351 | ? $tickets[ $ticket->ID() ]['count'] + 1 |
352 | 352 | : 1; |
353 | 353 | $tickets[ $ticket->ID() ]['att_objs'][ $reg->attendee_ID() ] = $reg->attendee(); |
@@ -6,8 +6,9 @@ |
||
6 | 6 | * @package Event Espresso |
7 | 7 | * @subpackage messages |
8 | 8 | */ |
9 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
9 | +if (!defined('EVENT_ESPRESSO_VERSION') ) { |
|
10 | 10 | exit('NO direct script access allowed'); |
11 | +} |
|
11 | 12 | |
12 | 13 | /** |
13 | 14 | * |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('NO direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * @param mixed $data incoming data object|array. Suggested that child classes use type hinting for expected |
267 | 267 | * data object. But here parent will be generic because we don't know what's coming in. |
268 | 268 | */ |
269 | - public function __construct( $data ) { |
|
269 | + public function __construct($data) { |
|
270 | 270 | $this->_data = $data; |
271 | 271 | $this->_setup_data(); |
272 | 272 | } |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | * |
289 | 289 | * @return mixed The prepped data for db |
290 | 290 | */ |
291 | - static public function convert_data_for_persistent_storage( $data ) { |
|
291 | + static public function convert_data_for_persistent_storage($data) { |
|
292 | 292 | return $data; |
293 | 293 | } |
294 | 294 | |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | * |
305 | 305 | * @return mixed |
306 | 306 | */ |
307 | - static public function convert_data_from_persistent_storage( $data ) { |
|
307 | + static public function convert_data_from_persistent_storage($data) { |
|
308 | 308 | return $data; |
309 | 309 | } |
310 | 310 | |
@@ -331,8 +331,8 @@ discard block |
||
331 | 331 | protected function _assemble_data() { |
332 | 332 | //verify that reg_objs is set |
333 | 333 | if ( |
334 | - ! is_array( $this->reg_objs ) |
|
335 | - && ! reset( $this->reg_objs ) instanceof EE_Registration |
|
334 | + ! is_array($this->reg_objs) |
|
335 | + && ! reset($this->reg_objs) instanceof EE_Registration |
|
336 | 336 | ) { |
337 | 337 | throw new EE_Error( |
338 | 338 | __( |
@@ -347,82 +347,82 @@ discard block |
||
347 | 347 | $answers = $questions = $attendees = $line_items = $registrations = array(); |
348 | 348 | $total_ticket_count = 0; |
349 | 349 | |
350 | - if ( ! empty( $this->reg_objs ) ) { |
|
350 | + if ( ! empty($this->reg_objs)) { |
|
351 | 351 | $event_attendee_count = array(); |
352 | - foreach ( $this->reg_objs as $reg ) { |
|
352 | + foreach ($this->reg_objs as $reg) { |
|
353 | 353 | //account for filtered registrations by status. |
354 | - if ( ! empty( $this->filtered_reg_status ) && $this->filtered_reg_status !== $reg->status_ID() ) { |
|
354 | + if ( ! empty($this->filtered_reg_status) && $this->filtered_reg_status !== $reg->status_ID()) { |
|
355 | 355 | continue; |
356 | 356 | } |
357 | 357 | |
358 | 358 | $evt_id = $reg->event_ID(); |
359 | 359 | /** @type EE_Ticket $ticket */ |
360 | - $ticket = $reg->get_first_related( 'Ticket' ); |
|
360 | + $ticket = $reg->get_first_related('Ticket'); |
|
361 | 361 | $relateddatetime = $ticket->datetimes(); |
362 | 362 | $total_ticket_count++; |
363 | - $tickets[ $ticket->ID() ]['ticket'] = $ticket; |
|
364 | - $tickets[ $ticket->ID() ]['count'] = is_array( $tickets[ $ticket->ID() ] ) |
|
365 | - && isset( $tickets[ $ticket->ID() ]['count'] ) |
|
366 | - ? $tickets[ $ticket->ID() ]['count'] + 1 |
|
363 | + $tickets[$ticket->ID()]['ticket'] = $ticket; |
|
364 | + $tickets[$ticket->ID()]['count'] = is_array($tickets[$ticket->ID()]) |
|
365 | + && isset($tickets[$ticket->ID()]['count']) |
|
366 | + ? $tickets[$ticket->ID()]['count'] + 1 |
|
367 | 367 | : 1; |
368 | - $tickets[ $ticket->ID() ]['att_objs'][ $reg->attendee_ID() ] = $reg->attendee(); |
|
369 | - $tickets[ $ticket->ID() ]['dtt_objs'] = $relateddatetime; |
|
370 | - $tickets[ $ticket->ID() ]['reg_objs'][ $reg->ID() ] = $reg; |
|
368 | + $tickets[$ticket->ID()]['att_objs'][$reg->attendee_ID()] = $reg->attendee(); |
|
369 | + $tickets[$ticket->ID()]['dtt_objs'] = $relateddatetime; |
|
370 | + $tickets[$ticket->ID()]['reg_objs'][$reg->ID()] = $reg; |
|
371 | 371 | $event = $reg->event(); |
372 | - $tickets[ $ticket->ID() ]['EE_Event'] = $event; |
|
373 | - $evtcache[ $evt_id ] = $event; |
|
374 | - $eventsetup[ $evt_id ]['reg_objs'][ $reg->ID() ] = $reg; |
|
375 | - $eventsetup[ $evt_id ]['tkt_objs'][ $ticket->ID() ] = $ticket; |
|
376 | - $eventsetup[ $evt_id ]['att_objs'][ $reg->attendee_ID() ] = $reg->attendee(); |
|
377 | - $event_attendee_count[ $evt_id ] = isset( $event_attendee_count[ $evt_id ] ) |
|
378 | - ? $event_attendee_count[ $evt_id ] + 1 |
|
372 | + $tickets[$ticket->ID()]['EE_Event'] = $event; |
|
373 | + $evtcache[$evt_id] = $event; |
|
374 | + $eventsetup[$evt_id]['reg_objs'][$reg->ID()] = $reg; |
|
375 | + $eventsetup[$evt_id]['tkt_objs'][$ticket->ID()] = $ticket; |
|
376 | + $eventsetup[$evt_id]['att_objs'][$reg->attendee_ID()] = $reg->attendee(); |
|
377 | + $event_attendee_count[$evt_id] = isset($event_attendee_count[$evt_id]) |
|
378 | + ? $event_attendee_count[$evt_id] + 1 |
|
379 | 379 | : 0; |
380 | - $attendees[ $reg->attendee_ID() ]['line_ref'][] = $evt_id; |
|
381 | - $attendees[ $reg->attendee_ID() ]['att_obj'] = $reg->attendee(); |
|
382 | - $attendees[ $reg->attendee_ID() ]['reg_objs'][ $reg->ID() ] = $reg; |
|
380 | + $attendees[$reg->attendee_ID()]['line_ref'][] = $evt_id; |
|
381 | + $attendees[$reg->attendee_ID()]['att_obj'] = $reg->attendee(); |
|
382 | + $attendees[$reg->attendee_ID()]['reg_objs'][$reg->ID()] = $reg; |
|
383 | 383 | //$attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID(); |
384 | - $attendees[ $reg->attendee_ID() ]['attendee_email'] = $reg->attendee() instanceof EE_Attendee |
|
384 | + $attendees[$reg->attendee_ID()]['attendee_email'] = $reg->attendee() instanceof EE_Attendee |
|
385 | 385 | ? $reg->attendee()->email() |
386 | 386 | : ''; |
387 | - $attendees[ $reg->attendee_ID() ]['tkt_objs'][ $ticket->ID() ] = $ticket; |
|
388 | - $attendees[ $reg->attendee_ID() ]['evt_objs'][ $evt_id ] = $event; |
|
387 | + $attendees[$reg->attendee_ID()]['tkt_objs'][$ticket->ID()] = $ticket; |
|
388 | + $attendees[$reg->attendee_ID()]['evt_objs'][$evt_id] = $event; |
|
389 | 389 | |
390 | 390 | //registrations |
391 | - $registrations[ $reg->ID() ]['tkt_obj'] = $ticket; |
|
392 | - $registrations[ $reg->ID() ]['evt_obj'] = $event; |
|
393 | - $registrations[ $reg->ID() ]['reg_obj'] = $reg; |
|
394 | - $registrations[ $reg->ID() ]['att_obj'] = $reg->attendee(); |
|
391 | + $registrations[$reg->ID()]['tkt_obj'] = $ticket; |
|
392 | + $registrations[$reg->ID()]['evt_obj'] = $event; |
|
393 | + $registrations[$reg->ID()]['reg_obj'] = $reg; |
|
394 | + $registrations[$reg->ID()]['att_obj'] = $reg->attendee(); |
|
395 | 395 | |
396 | 396 | //set up answer objects |
397 | - $rel_ans = $reg->get_many_related( 'Answer' ); |
|
398 | - foreach ( $rel_ans as $ansid => $answer ) { |
|
399 | - if ( ! isset( $questions[ $ansid ] ) ) { |
|
400 | - $questions[ $ansid ] = $answer->get_first_related( 'Question' ); |
|
397 | + $rel_ans = $reg->get_many_related('Answer'); |
|
398 | + foreach ($rel_ans as $ansid => $answer) { |
|
399 | + if ( ! isset($questions[$ansid])) { |
|
400 | + $questions[$ansid] = $answer->get_first_related('Question'); |
|
401 | 401 | } |
402 | - $answers[ $ansid ] = $answer; |
|
403 | - $registrations[ $reg->ID() ]['ans_objs'][ $ansid ] = $answer; |
|
402 | + $answers[$ansid] = $answer; |
|
403 | + $registrations[$reg->ID()]['ans_objs'][$ansid] = $answer; |
|
404 | 404 | } |
405 | 405 | |
406 | - foreach ( $relateddatetime as $dtt_id => $datetime ) { |
|
407 | - $eventsetup[ $evt_id ]['dtt_objs'][ $dtt_id ] = $datetime; |
|
408 | - $registrations[ $reg->ID() ]['dtt_objs'][ $dtt_id ] = $datetime; |
|
406 | + foreach ($relateddatetime as $dtt_id => $datetime) { |
|
407 | + $eventsetup[$evt_id]['dtt_objs'][$dtt_id] = $datetime; |
|
408 | + $registrations[$reg->ID()]['dtt_objs'][$dtt_id] = $datetime; |
|
409 | 409 | |
410 | - if ( isset( $datetimes[ $dtt_id ] ) ) { |
|
410 | + if (isset($datetimes[$dtt_id])) { |
|
411 | 411 | continue; //already have this info in the datetimes array. |
412 | 412 | } |
413 | 413 | |
414 | - $datetimes[ $dtt_id ]['tkt_objs'][] = $ticket; |
|
415 | - $datetimes[ $dtt_id ]['datetime'] = $datetime; |
|
416 | - $datetimes[ $dtt_id ]['evt_objs'][ $evt_id ] = $event; |
|
417 | - $datetimes[ $dtt_id ]['reg_objs'][ $reg->ID() ] = $reg; |
|
414 | + $datetimes[$dtt_id]['tkt_objs'][] = $ticket; |
|
415 | + $datetimes[$dtt_id]['datetime'] = $datetime; |
|
416 | + $datetimes[$dtt_id]['evt_objs'][$evt_id] = $event; |
|
417 | + $datetimes[$dtt_id]['reg_objs'][$reg->ID()] = $reg; |
|
418 | 418 | } |
419 | 419 | } |
420 | 420 | |
421 | 421 | //let's loop through the unique event=>reg items and setup data on them |
422 | 422 | |
423 | - if ( ! empty( $eventsetup ) ) { |
|
424 | - foreach ( $eventsetup as $evt_id => $items ) { |
|
425 | - if ( $this->txn instanceof EE_Transaction ) { |
|
423 | + if ( ! empty($eventsetup)) { |
|
424 | + foreach ($eventsetup as $evt_id => $items) { |
|
425 | + if ($this->txn instanceof EE_Transaction) { |
|
426 | 426 | $ticket_line_items_for_event = EEM_Line_Item::instance()->get_all( |
427 | 427 | array( |
428 | 428 | array( |
@@ -435,25 +435,25 @@ discard block |
||
435 | 435 | } else { |
436 | 436 | $ticket_line_items_for_event = array(); |
437 | 437 | } |
438 | - $events[ $evt_id ] = array( |
|
438 | + $events[$evt_id] = array( |
|
439 | 439 | 'ID' => $evt_id, |
440 | - 'event' => $evtcache[ $evt_id ], |
|
441 | - 'name' => $evtcache[ $evt_id ] instanceof EE_Event ? $evtcache[ $evt_id ]->name() : '', |
|
442 | - 'total_attendees' => $event_attendee_count[ $evt_id ], |
|
440 | + 'event' => $evtcache[$evt_id], |
|
441 | + 'name' => $evtcache[$evt_id] instanceof EE_Event ? $evtcache[$evt_id]->name() : '', |
|
442 | + 'total_attendees' => $event_attendee_count[$evt_id], |
|
443 | 443 | 'reg_objs' => $items['reg_objs'], |
444 | 444 | 'tkt_objs' => $items['tkt_objs'], |
445 | 445 | 'att_objs' => $items['att_objs'], |
446 | - 'dtt_objs' => isset( $items['dtt_objs'] ) ? $items['dtt_objs'] : array(), |
|
446 | + 'dtt_objs' => isset($items['dtt_objs']) ? $items['dtt_objs'] : array(), |
|
447 | 447 | 'line_items' => $ticket_line_items_for_event, |
448 | 448 | ); |
449 | 449 | |
450 | 450 | //make sure the tickets have the line items setup for them. |
451 | - foreach ( $ticket_line_items_for_event as $line_id => $line_item ) { |
|
452 | - if ( $line_item instanceof EE_Line_Item ) { |
|
453 | - $tickets[ $line_item->ticket()->ID() ]['line_item'] = $line_item; |
|
454 | - $tickets[ $line_item->ticket()->ID() ]['sub_line_items'] = $line_item->children(); |
|
455 | - $line_items[ $line_item->ID() ]['children'] = $line_item->children(); |
|
456 | - $line_items[ $line_item->ID() ]['EE_Ticket'] = $line_item->ticket(); |
|
451 | + foreach ($ticket_line_items_for_event as $line_id => $line_item) { |
|
452 | + if ($line_item instanceof EE_Line_Item) { |
|
453 | + $tickets[$line_item->ticket()->ID()]['line_item'] = $line_item; |
|
454 | + $tickets[$line_item->ticket()->ID()]['sub_line_items'] = $line_item->children(); |
|
455 | + $line_items[$line_item->ID()]['children'] = $line_item->children(); |
|
456 | + $line_items[$line_item->ID()]['EE_Ticket'] = $line_item->ticket(); |
|
457 | 457 | } |
458 | 458 | } |
459 | 459 | } |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | $this->total_ticket_count = $total_ticket_count; |
476 | 476 | $this->registrations = $registrations; |
477 | 477 | |
478 | - if ( $this->txn instanceof EE_Transaction ) { |
|
478 | + if ($this->txn instanceof EE_Transaction) { |
|
479 | 479 | $this->tax_line_items = $this->txn->tax_items(); |
480 | 480 | $this->additional_line_items = $this->txn->non_ticket_line_items(); |
481 | 481 | $this->payments = $this->txn->payments(); |
@@ -485,10 +485,10 @@ discard block |
||
485 | 485 | //let's get just the primary_attendee_data! First we get the primary registration object. |
486 | 486 | $primary_reg = $this->txn->primary_registration(); |
487 | 487 | // verify |
488 | - if ( $primary_reg instanceof EE_Registration ) { |
|
488 | + if ($primary_reg instanceof EE_Registration) { |
|
489 | 489 | |
490 | 490 | // get attendee object |
491 | - if ( $primary_reg->attendee() instanceof EE_Attendee ) { |
|
491 | + if ($primary_reg->attendee() instanceof EE_Attendee) { |
|
492 | 492 | |
493 | 493 | //now we can setup the primary_attendee_data array |
494 | 494 | $this->primary_attendee_data = array( |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
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 | |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | * @return EE_Messenger_Collection |
135 | 135 | */ |
136 | 136 | protected function _initialize_collections() { |
137 | - if ( $this->_initialized ) { |
|
137 | + if ($this->_initialized) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | 140 | $this->_initialized = true; |
141 | 141 | $this->_messenger_collection_loader->load_messengers_from_folder(); |
142 | 142 | $this->_message_type_collection_loader->load_message_types_from_folder(); |
143 | 143 | $this->_set_active_messengers_and_message_types(); |
144 | - $this->get_has_activated_messengers_option( true ); |
|
144 | + $this->get_has_activated_messengers_option(true); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | * @param string $messenger_name |
171 | 171 | * @return \EE_messenger |
172 | 172 | */ |
173 | - public function get_messenger( $messenger_name ) { |
|
174 | - return $this->messenger_collection()->get_by_info( $messenger_name ); |
|
173 | + public function get_messenger($messenger_name) { |
|
174 | + return $this->messenger_collection()->get_by_info($messenger_name); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | * @param string $messenger |
183 | 183 | * @return EE_messenger | null |
184 | 184 | */ |
185 | - public function get_active_messenger( $messenger ) { |
|
185 | + public function get_active_messenger($messenger) { |
|
186 | 186 | $this->_initialize_collections(); |
187 | - return ! empty( $this->_active_messengers[ $messenger ] ) ? $this->_active_messengers[ $messenger ] : null; |
|
187 | + return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | |
@@ -193,11 +193,11 @@ discard block |
||
193 | 193 | * @return \EE_messenger[] |
194 | 194 | */ |
195 | 195 | public function installed_messengers() { |
196 | - if ( empty( $this->_installed_messengers ) ) { |
|
196 | + if (empty($this->_installed_messengers)) { |
|
197 | 197 | $this->_installed_messengers = array(); |
198 | 198 | $this->messenger_collection()->rewind(); |
199 | - while ( $this->messenger_collection()->valid() ) { |
|
200 | - $this->_installed_messengers[ $this->messenger_collection()->current()->name ] = $this->messenger_collection()->current(); |
|
199 | + while ($this->messenger_collection()->valid()) { |
|
200 | + $this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current(); |
|
201 | 201 | $this->messenger_collection()->next(); |
202 | 202 | } |
203 | 203 | } |
@@ -211,14 +211,14 @@ discard block |
||
211 | 211 | * @return \EE_messenger |
212 | 212 | * @throws \EE_Error |
213 | 213 | */ |
214 | - public function valid_messenger( $messenger_name ) { |
|
215 | - $messenger = $this->get_messenger( $messenger_name ); |
|
216 | - if ( $messenger instanceof EE_messenger ) { |
|
214 | + public function valid_messenger($messenger_name) { |
|
215 | + $messenger = $this->get_messenger($messenger_name); |
|
216 | + if ($messenger instanceof EE_messenger) { |
|
217 | 217 | return $messenger; |
218 | 218 | } |
219 | 219 | throw new EE_Error( |
220 | 220 | sprintf( |
221 | - __( 'The "%1$s" messenger is either invalid or not installed', 'event_espresso' ), |
|
221 | + __('The "%1$s" messenger is either invalid or not installed', 'event_espresso'), |
|
222 | 222 | $messenger_name |
223 | 223 | ) |
224 | 224 | ); |
@@ -250,8 +250,8 @@ discard block |
||
250 | 250 | * @param string $message_type_name |
251 | 251 | * @return \EE_message_type |
252 | 252 | */ |
253 | - public function get_message_type( $message_type_name ) { |
|
254 | - return $this->message_type_collection()->get_by_info( $message_type_name ); |
|
253 | + public function get_message_type($message_type_name) { |
|
254 | + return $this->message_type_collection()->get_by_info($message_type_name); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | |
@@ -263,9 +263,9 @@ discard block |
||
263 | 263 | * @param string $message_type_name |
264 | 264 | * @return \EE_message_type|null |
265 | 265 | */ |
266 | - public function get_active_message_type_for_messenger( $messenger_name, $message_type_name ) { |
|
267 | - return $this->is_message_type_active_for_messenger( $messenger_name, $message_type_name ) |
|
268 | - ? $this->get_message_type( $message_type_name ) |
|
266 | + public function get_active_message_type_for_messenger($messenger_name, $message_type_name) { |
|
267 | + return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name) |
|
268 | + ? $this->get_message_type($message_type_name) |
|
269 | 269 | : null; |
270 | 270 | } |
271 | 271 | |
@@ -279,9 +279,9 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @return bool |
281 | 281 | */ |
282 | - public function is_message_type_active_for_messenger( $messenger_name, $message_type_name ) { |
|
282 | + public function is_message_type_active_for_messenger($messenger_name, $message_type_name) { |
|
283 | 283 | $this->_initialize_collections(); |
284 | - return ! empty( $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ] ); |
|
284 | + return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | |
@@ -292,9 +292,9 @@ discard block |
||
292 | 292 | * @param string $messenger_name the name of the messenger to check if active. |
293 | 293 | * @return bool |
294 | 294 | */ |
295 | - public function is_messenger_active( $messenger_name ) { |
|
295 | + public function is_messenger_active($messenger_name) { |
|
296 | 296 | $this->_initialize_collections(); |
297 | - return ! empty( $this->_active_message_types[ $messenger_name ] ); |
|
297 | + return ! empty($this->_active_message_types[$messenger_name]); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | |
@@ -305,11 +305,11 @@ discard block |
||
305 | 305 | * @param string $message_type_name The slug of the message type getting the settings for. |
306 | 306 | * @return array |
307 | 307 | */ |
308 | - public function get_message_type_settings_for_messenger( $messenger_name, $message_type_name ) { |
|
308 | + public function get_message_type_settings_for_messenger($messenger_name, $message_type_name) { |
|
309 | 309 | $settings = array(); |
310 | - if ( $this->is_message_type_active_for_messenger( $messenger_name, $message_type_name ) ) { |
|
311 | - $settings = isset( $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] ) |
|
312 | - ? $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] |
|
310 | + if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
311 | + $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings']) |
|
312 | + ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'] |
|
313 | 313 | : array(); |
314 | 314 | } |
315 | 315 | return $settings; |
@@ -324,11 +324,11 @@ discard block |
||
324 | 324 | * @param string $messenger_name |
325 | 325 | * @return bool |
326 | 326 | */ |
327 | - public function messenger_has_active_message_types( $messenger_name ) { |
|
327 | + public function messenger_has_active_message_types($messenger_name) { |
|
328 | 328 | $this->_initialize_collections(); |
329 | 329 | return |
330 | - ! empty( $this->_active_message_types[ $messenger_name ] ) |
|
331 | - && ! empty( $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ] ); |
|
330 | + ! empty($this->_active_message_types[$messenger_name]) |
|
331 | + && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types']); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | |
@@ -341,15 +341,15 @@ discard block |
||
341 | 341 | * @param string $messenger_name The messenger being checked |
342 | 342 | * @return EE_message_type[] (or empty array if none present) |
343 | 343 | */ |
344 | - public function get_active_message_types_for_messenger( $messenger_name ) { |
|
344 | + public function get_active_message_types_for_messenger($messenger_name) { |
|
345 | 345 | $message_types = array(); |
346 | - if ( ! $this->messenger_has_active_message_types( $messenger_name ) ) { |
|
346 | + if ( ! $this->messenger_has_active_message_types($messenger_name)) { |
|
347 | 347 | return $message_types; |
348 | 348 | } |
349 | 349 | $installed_message_types = $this->installed_message_types(); |
350 | - foreach ( $installed_message_types as $message_type_name => $message_type ) { |
|
351 | - if ( $this->is_message_type_active_for_messenger( $messenger_name, $message_type_name ) ) { |
|
352 | - $message_types[ $message_type_name ] = $message_type; |
|
350 | + foreach ($installed_message_types as $message_type_name => $message_type) { |
|
351 | + if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
352 | + $message_types[$message_type_name] = $message_type; |
|
353 | 353 | } |
354 | 354 | } |
355 | 355 | return $message_types; |
@@ -367,12 +367,12 @@ discard block |
||
367 | 367 | public function list_of_active_message_types() { |
368 | 368 | $active_message_type_names = array(); |
369 | 369 | $this->_initialize_collections(); |
370 | - foreach ( $this->_active_message_types as $messenger => $messenger_settings ) { |
|
371 | - if ( ! isset( $messenger_settings['settings'][ $messenger . '-message_types' ] ) ) { |
|
370 | + foreach ($this->_active_message_types as $messenger => $messenger_settings) { |
|
371 | + if ( ! isset($messenger_settings['settings'][$messenger.'-message_types'])) { |
|
372 | 372 | continue; |
373 | 373 | } |
374 | - foreach ( $messenger_settings['settings'][ $messenger . '-message_types' ] as $message_type_name => $message_type_config ) { |
|
375 | - if ( ! in_array( $message_type_name, $active_message_type_names ) ) { |
|
374 | + foreach ($messenger_settings['settings'][$messenger.'-message_types'] as $message_type_name => $message_type_config) { |
|
375 | + if ( ! in_array($message_type_name, $active_message_type_names)) { |
|
376 | 376 | $active_message_type_names[] = $message_type_name; |
377 | 377 | } |
378 | 378 | } |
@@ -392,9 +392,9 @@ discard block |
||
392 | 392 | $active_message_types = array(); |
393 | 393 | $installed_message_types = $this->installed_message_types(); |
394 | 394 | $active_message_type_names = $this->list_of_active_message_types(); |
395 | - foreach ( $active_message_type_names as $active_message_type_name ) { |
|
396 | - if ( isset( $installed_message_types[ $active_message_type_name ] ) ) { |
|
397 | - $active_message_types[ $active_message_type_name ] = $installed_message_types[ $active_message_type_name ]; |
|
395 | + foreach ($active_message_type_names as $active_message_type_name) { |
|
396 | + if (isset($installed_message_types[$active_message_type_name])) { |
|
397 | + $active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name]; |
|
398 | 398 | } |
399 | 399 | } |
400 | 400 | return $active_message_types; |
@@ -406,10 +406,10 @@ discard block |
||
406 | 406 | * @return \EE_message_type[] |
407 | 407 | */ |
408 | 408 | public function installed_message_types() { |
409 | - if ( empty( $this->_installed_message_types ) ) { |
|
409 | + if (empty($this->_installed_message_types)) { |
|
410 | 410 | $this->message_type_collection()->rewind(); |
411 | - while ( $this->message_type_collection()->valid() ) { |
|
412 | - $this->_installed_message_types[ $this->message_type_collection()->current()->name ] = $this->message_type_collection()->current(); |
|
411 | + while ($this->message_type_collection()->valid()) { |
|
412 | + $this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current(); |
|
413 | 413 | $this->message_type_collection()->next(); |
414 | 414 | } |
415 | 415 | } |
@@ -422,14 +422,14 @@ discard block |
||
422 | 422 | * @return \EE_message_type |
423 | 423 | * @throws \EE_Error |
424 | 424 | */ |
425 | - public function valid_message_type( $message_type_name ) { |
|
426 | - $message_type = $this->get_message_type( $message_type_name ); |
|
427 | - if ( $message_type instanceof EE_message_type ) { |
|
425 | + public function valid_message_type($message_type_name) { |
|
426 | + $message_type = $this->get_message_type($message_type_name); |
|
427 | + if ($message_type instanceof EE_message_type) { |
|
428 | 428 | return $message_type; |
429 | 429 | } |
430 | 430 | throw new EE_Error( |
431 | 431 | sprintf( |
432 | - __( 'The "%1$s" message type is either invalid or not installed', 'event_espresso' ), |
|
432 | + __('The "%1$s" message type is either invalid or not installed', 'event_espresso'), |
|
433 | 433 | $message_type_name |
434 | 434 | ) |
435 | 435 | ); |
@@ -445,9 +445,9 @@ discard block |
||
445 | 445 | * @return boolean |
446 | 446 | * @throws \EE_Error |
447 | 447 | */ |
448 | - public function valid_message_type_for_messenger( EE_messenger $messenger, $message_type_name ) { |
|
448 | + public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name) { |
|
449 | 449 | $valid_message_types = $messenger->get_valid_message_types(); |
450 | - if ( ! in_array( $message_type_name, $valid_message_types ) ) { |
|
450 | + if ( ! in_array($message_type_name, $valid_message_types)) { |
|
451 | 451 | throw new EE_Error( |
452 | 452 | sprintf( |
453 | 453 | __( |
@@ -474,9 +474,9 @@ discard block |
||
474 | 474 | * |
475 | 475 | * @return array |
476 | 476 | */ |
477 | - public function get_active_messengers_option( $reset = false) { |
|
478 | - if ( $reset ) { |
|
479 | - $this->_active_message_types = get_option( 'ee_active_messengers', array() ); |
|
477 | + public function get_active_messengers_option($reset = false) { |
|
478 | + if ($reset) { |
|
479 | + $this->_active_message_types = get_option('ee_active_messengers', array()); |
|
480 | 480 | } |
481 | 481 | return $this->_active_message_types; |
482 | 482 | } |
@@ -490,11 +490,11 @@ discard block |
||
490 | 490 | * representing this data is used. |
491 | 491 | * @return bool FALSE if not updated, TRUE if updated. |
492 | 492 | */ |
493 | - public function update_active_messengers_option( $active_messenger_settings = array() ) { |
|
494 | - $active_messenger_settings = empty( $active_messenger_settings ) ? $this->_active_message_types : $active_messenger_settings; |
|
493 | + public function update_active_messengers_option($active_messenger_settings = array()) { |
|
494 | + $active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings; |
|
495 | 495 | //make sure _active_message_types is updated (this is the internal cache for the settings). |
496 | 496 | $this->_active_message_types = $active_messenger_settings; |
497 | - return update_option( 'ee_active_messengers', $active_messenger_settings ); |
|
497 | + return update_option('ee_active_messengers', $active_messenger_settings); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | |
@@ -509,9 +509,9 @@ discard block |
||
509 | 509 | * |
510 | 510 | * @return array |
511 | 511 | */ |
512 | - public function get_has_activated_messengers_option( $reset = false ) { |
|
513 | - if ( $reset ) { |
|
514 | - $this->_has_activated_messengers_and_message_types = get_option( 'ee_has_activated_messenger', array() ); |
|
512 | + public function get_has_activated_messengers_option($reset = false) { |
|
513 | + if ($reset) { |
|
514 | + $this->_has_activated_messengers_and_message_types = get_option('ee_has_activated_messenger', array()); |
|
515 | 515 | } |
516 | 516 | return $this->_has_activated_messengers_and_message_types; |
517 | 517 | } |
@@ -526,11 +526,11 @@ discard block |
||
526 | 526 | * |
527 | 527 | * @return bool FALSE if not updated, TRUE if updated. |
528 | 528 | */ |
529 | - public function update_has_activated_messengers_option( $has_activated_messengers = array() ) { |
|
530 | - $has_activated_messengers = empty( $has_activated_messengers ) |
|
529 | + public function update_has_activated_messengers_option($has_activated_messengers = array()) { |
|
530 | + $has_activated_messengers = empty($has_activated_messengers) |
|
531 | 531 | ? $this->_has_activated_messengers_and_message_types |
532 | 532 | : $has_activated_messengers; |
533 | - return update_option( 'ee_has_activated_messenger', $has_activated_messengers ); |
|
533 | + return update_option('ee_has_activated_messenger', $has_activated_messengers); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | |
@@ -552,8 +552,8 @@ discard block |
||
552 | 552 | //echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n"; |
553 | 553 | // list of activated messengers as set via the admin |
554 | 554 | // note calling `get_active_messengers_options` also initializes the _active_message_types property. |
555 | - $this->get_active_messengers_option( true ); |
|
556 | - $this->ensure_messengers_are_active( array(), false, true ); |
|
555 | + $this->get_active_messengers_option(true); |
|
556 | + $this->ensure_messengers_are_active(array(), false, true); |
|
557 | 557 | $this->update_active_messengers_option(); |
558 | 558 | $this->update_has_activated_messengers_option(); |
559 | 559 | } |
@@ -571,11 +571,11 @@ discard block |
||
571 | 571 | * @param bool $update_option Whether to update the option in the db or not. |
572 | 572 | * @return boolean true if either already active or successfully activated. |
573 | 573 | */ |
574 | - public function ensure_messenger_is_active( $messenger_name, $update_option = true ) { |
|
575 | - if ( ! isset( $this->_active_messengers[ $messenger_name ] ) ) { |
|
574 | + public function ensure_messenger_is_active($messenger_name, $update_option = true) { |
|
575 | + if ( ! isset($this->_active_messengers[$messenger_name])) { |
|
576 | 576 | try { |
577 | - $this->activate_messenger( $messenger_name, array(), $update_option ); |
|
578 | - } catch( EE_Error $e ) { |
|
577 | + $this->activate_messenger($messenger_name, array(), $update_option); |
|
578 | + } catch (EE_Error $e) { |
|
579 | 579 | EE_Error::add_error( |
580 | 580 | $e->getMessage(), |
581 | 581 | __FILE__, |
@@ -602,25 +602,25 @@ discard block |
||
602 | 602 | * and a messenger is indicated as active, but is NOT installed, then it will automatically be |
603 | 603 | * deactivated. |
604 | 604 | */ |
605 | - public function ensure_messengers_are_active( $messenger_names = array(), $update_option = true, $verify = false ) { |
|
606 | - $messenger_names = empty( $messenger_names ) ? array_keys( $this->_active_message_types ) : $messenger_names; |
|
605 | + public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false) { |
|
606 | + $messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names; |
|
607 | 607 | |
608 | 608 | $not_installed = array(); |
609 | - foreach( $messenger_names as $messenger_name ) { |
|
610 | - if ( $verify && ! $this->messenger_collection()->has_by_name( $messenger_name ) ) { |
|
609 | + foreach ($messenger_names as $messenger_name) { |
|
610 | + if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) { |
|
611 | 611 | $not_installed[] = $messenger_name; |
612 | - $this->deactivate_messenger( $messenger_name ); |
|
612 | + $this->deactivate_messenger($messenger_name); |
|
613 | 613 | continue; |
614 | 614 | } |
615 | - $this->ensure_messenger_is_active( $messenger_name, $update_option ); |
|
615 | + $this->ensure_messenger_is_active($messenger_name, $update_option); |
|
616 | 616 | } |
617 | 617 | |
618 | - if ( ! empty( $not_installed_messenger ) ) { |
|
618 | + if ( ! empty($not_installed_messenger)) { |
|
619 | 619 | EE_Error::add_error( |
620 | 620 | sprintf( |
621 | - __( 'The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso' ), |
|
621 | + __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'), |
|
622 | 622 | '<br />', |
623 | - implode( ', ', $not_installed_messenger ) |
|
623 | + implode(', ', $not_installed_messenger) |
|
624 | 624 | ), |
625 | 625 | __FILE__, __FUNCTION__, __LINE__ |
626 | 626 | ); |
@@ -639,18 +639,18 @@ discard block |
||
639 | 639 | * @return bool Returns true if already is active or if was activated successfully. |
640 | 640 | * @throws \EE_Error |
641 | 641 | */ |
642 | - public function ensure_message_type_is_active( $message_type_name, $messenger_name, $update_option = true ) { |
|
642 | + public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true) { |
|
643 | 643 | // grab the messenger to work with. |
644 | - $messenger = $this->valid_messenger( $messenger_name ); |
|
645 | - if ( $this->valid_message_type_for_messenger( $messenger, $message_type_name ) ) { |
|
644 | + $messenger = $this->valid_messenger($messenger_name); |
|
645 | + if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) { |
|
646 | 646 | //ensure messenger is active (that's an inherent coupling between active message types and the |
647 | 647 | //messenger they are being activated for. |
648 | 648 | try { |
649 | - if ( ! $this->is_message_type_active_for_messenger( $messenger_name, $message_type_name ) ) { |
|
649 | + if ( ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
650 | 650 | //all is good so let's just get it active |
651 | - $this->activate_messenger( $messenger_name, array( $message_type_name ), $update_option ); |
|
651 | + $this->activate_messenger($messenger_name, array($message_type_name), $update_option); |
|
652 | 652 | } |
653 | - } catch( EE_Error $e ) { |
|
653 | + } catch (EE_Error $e) { |
|
654 | 654 | EE_Error::add_error( |
655 | 655 | $e->getMessage(), |
656 | 656 | __FILE__, |
@@ -674,14 +674,14 @@ discard block |
||
674 | 674 | * @param string $messenger_name The name of the messenger that the message types are to be activated on. |
675 | 675 | * @param bool $update_option Whether to persist the activation to the database or not (default true). |
676 | 676 | */ |
677 | - public function ensure_message_types_are_active( $message_type_names, $messenger_name, $update_option = true ) { |
|
677 | + public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true) { |
|
678 | 678 | $message_type_names = (array) $message_type_names; |
679 | - foreach ( $message_type_names as $message_type_name ) { |
|
679 | + foreach ($message_type_names as $message_type_name) { |
|
680 | 680 | // note, intentionally not updating option here because we're in a loop. |
681 | 681 | // We'll follow the instructions of the incoming $update_option argument after the loop. |
682 | - $this->ensure_message_type_is_active( $message_type_name, $messenger_name, false ); |
|
682 | + $this->ensure_message_type_is_active($message_type_name, $messenger_name, false); |
|
683 | 683 | } |
684 | - if ( $update_option ) { |
|
684 | + if ($update_option) { |
|
685 | 685 | $this->update_active_messengers_option(); |
686 | 686 | $this->update_has_activated_messengers_option(); |
687 | 687 | } |
@@ -708,24 +708,24 @@ discard block |
||
708 | 708 | ) { |
709 | 709 | $templates = array(); |
710 | 710 | // grab the messenger to work with. |
711 | - $messenger = $this->messenger_collection()->get_by_info( $messenger_name ); |
|
711 | + $messenger = $this->messenger_collection()->get_by_info($messenger_name); |
|
712 | 712 | // it's inactive. Activate it. |
713 | - if ( $messenger instanceof EE_messenger ) { |
|
714 | - $this->_active_messengers[ $messenger->name ] = $messenger; |
|
713 | + if ($messenger instanceof EE_messenger) { |
|
714 | + $this->_active_messengers[$messenger->name] = $messenger; |
|
715 | 715 | //activate incoming message types set to be activated with messenger. |
716 | - $message_type_names = $this->_activate_message_types( $messenger, $message_type_names ); |
|
716 | + $message_type_names = $this->_activate_message_types($messenger, $message_type_names); |
|
717 | 717 | // setup any initial settings for the messenger if necessary. |
718 | - $this->add_settings_for_messenger( $messenger->name ); |
|
719 | - if ( $update_active_messengers_option ) { |
|
718 | + $this->add_settings_for_messenger($messenger->name); |
|
719 | + if ($update_active_messengers_option) { |
|
720 | 720 | $this->update_active_messengers_option(); |
721 | 721 | $this->update_has_activated_messengers_option(); |
722 | 722 | } |
723 | 723 | //generate new templates if necessary and ensure all related templates that are already in the database are |
724 | 724 | //marked active. Note, this will also deactivate a message type for a messenger if the template |
725 | 725 | //cannot be successfully created during its attempt (only happens for global template attempts). |
726 | - if ( ! empty( $message_type_names ) ) { |
|
727 | - $templates = EEH_MSG_Template::generate_new_templates( $messenger->name, $message_type_names, 0, true ); |
|
728 | - EEH_MSG_Template::update_to_active( array( $messenger->name ), $message_type_names ); |
|
726 | + if ( ! empty($message_type_names)) { |
|
727 | + $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true); |
|
728 | + EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names); |
|
729 | 729 | } |
730 | 730 | } |
731 | 731 | return $templates; |
@@ -744,29 +744,29 @@ discard block |
||
744 | 744 | * |
745 | 745 | * @return array |
746 | 746 | */ |
747 | - protected function _activate_message_types( EE_messenger $messenger, $message_type_names = array() ) { |
|
747 | + protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array()) { |
|
748 | 748 | //If $message_type_names is empty, AND $this->_active_message_types is empty, then that means |
749 | 749 | //things have never been initialized (which should happen on EEH_Activation::generate_message_templates). |
750 | 750 | //So ONLY then do we need to actually grab defaults and cycle through them. Otherwise we |
751 | 751 | //only override _active_message_types when an explicit array of $message_type_names has been provided. |
752 | - $message_type_names = empty( $message_type_names ) && ! isset( $this->_active_message_types[ $messenger->name ] ) |
|
752 | + $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name]) |
|
753 | 753 | ? $messenger->get_default_message_types() |
754 | 754 | : (array) $message_type_names; |
755 | 755 | |
756 | 756 | //now we ALWAYS need to make sure that the messenger is active for the message types we're activating! |
757 | - if ( ! isset( $this->_active_message_types[ $messenger->name ] ) ) { |
|
758 | - $this->_active_message_types[ $messenger->name ]['settings'] = array(); |
|
757 | + if ( ! isset($this->_active_message_types[$messenger->name])) { |
|
758 | + $this->_active_message_types[$messenger->name]['settings'] = array(); |
|
759 | 759 | } |
760 | 760 | |
761 | - if ( $message_type_names ) { |
|
761 | + if ($message_type_names) { |
|
762 | 762 | // cycle thru message types |
763 | - foreach ( $message_type_names as $message_type_name ) { |
|
763 | + foreach ($message_type_names as $message_type_name) { |
|
764 | 764 | //only register the message type as active IF it isn't already active! |
765 | 765 | //and if its actually installed. |
766 | 766 | if ( |
767 | - ! $this->is_message_type_active_for_messenger( $messenger->name, $message_type_name ) |
|
767 | + ! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name) |
|
768 | 768 | ) { |
769 | - $this->add_settings_for_message_type( $messenger->name, $message_type_name ); |
|
769 | + $this->add_settings_for_message_type($messenger->name, $message_type_name); |
|
770 | 770 | $this->_set_messenger_has_activated_message_type( |
771 | 771 | $messenger, |
772 | 772 | $message_type_name |
@@ -789,24 +789,24 @@ discard block |
||
789 | 789 | * @param string $message_type_name The name of the message type adding the settings for |
790 | 790 | * @param array $new_settings Any new settings being set for the message type and messenger |
791 | 791 | */ |
792 | - public function add_settings_for_message_type( $messenger_name, $message_type_name, $new_settings = array() ) { |
|
792 | + public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array()) { |
|
793 | 793 | // get installed message type from collection |
794 | - $message_type = $this->message_type_collection()->get_by_info( $message_type_name ); |
|
795 | - $existing_settings = $this->get_message_type_settings_for_messenger( $messenger_name, $message_type_name ); |
|
794 | + $message_type = $this->message_type_collection()->get_by_info($message_type_name); |
|
795 | + $existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name); |
|
796 | 796 | //we need to setup any initial settings for message types |
797 | - if ( $message_type instanceof EE_message_type ) { |
|
797 | + if ($message_type instanceof EE_message_type) { |
|
798 | 798 | $default_settings = $message_type->get_admin_settings_fields(); |
799 | - foreach ( $default_settings as $field => $values ) { |
|
800 | - if ( isset( $new_settings[ $field ] ) ) { |
|
801 | - $existing_settings[ $field ] = $new_settings[ $field ]; |
|
799 | + foreach ($default_settings as $field => $values) { |
|
800 | + if (isset($new_settings[$field])) { |
|
801 | + $existing_settings[$field] = $new_settings[$field]; |
|
802 | 802 | continue; |
803 | 803 | } |
804 | - if ( ! isset( $existing_settings[ $field ] ) ) { |
|
805 | - $existing_settings[ $field ] = $values['default']; |
|
804 | + if ( ! isset($existing_settings[$field])) { |
|
805 | + $existing_settings[$field] = $values['default']; |
|
806 | 806 | } |
807 | 807 | } |
808 | 808 | } |
809 | - $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] = $existing_settings; |
|
809 | + $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'] = $existing_settings; |
|
810 | 810 | } |
811 | 811 | |
812 | 812 | |
@@ -819,14 +819,14 @@ discard block |
||
819 | 819 | * @param \EE_messenger $messenger |
820 | 820 | * @param string $message_type_name |
821 | 821 | */ |
822 | - protected function _set_messenger_has_activated_message_type( EE_messenger $messenger, $message_type_name ) { |
|
822 | + protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name) { |
|
823 | 823 | // make sure this messenger has a record in the has_activated array |
824 | - if ( ! isset( $this->_has_activated_messengers_and_message_types[ $messenger->name ] ) ) { |
|
825 | - $this->_has_activated_messengers_and_message_types[ $messenger->name ] = array(); |
|
824 | + if ( ! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) { |
|
825 | + $this->_has_activated_messengers_and_message_types[$messenger->name] = array(); |
|
826 | 826 | } |
827 | 827 | // check if message type has already been added |
828 | - if ( ! in_array( $message_type_name, $this->_has_activated_messengers_and_message_types[ $messenger->name ] ) ) { |
|
829 | - $this->_has_activated_messengers_and_message_types[ $messenger->name ][] = $message_type_name; |
|
828 | + if ( ! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) { |
|
829 | + $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name; |
|
830 | 830 | } |
831 | 831 | } |
832 | 832 | |
@@ -841,20 +841,20 @@ discard block |
||
841 | 841 | * @param string $messenger_name The name of the messenger the settings is being added for. |
842 | 842 | * @param array $new_settings An array of settings to update the existing settings. |
843 | 843 | */ |
844 | - public function add_settings_for_messenger( $messenger_name, $new_settings = array() ) { |
|
845 | - $messenger = $this->get_messenger( $messenger_name ); |
|
846 | - if ( $messenger instanceof EE_messenger ) { |
|
844 | + public function add_settings_for_messenger($messenger_name, $new_settings = array()) { |
|
845 | + $messenger = $this->get_messenger($messenger_name); |
|
846 | + if ($messenger instanceof EE_messenger) { |
|
847 | 847 | $msgr_settings = $messenger->get_admin_settings_fields(); |
848 | - if ( ! empty( $msgr_settings ) ) { |
|
849 | - foreach ( $msgr_settings as $field => $value ) { |
|
848 | + if ( ! empty($msgr_settings)) { |
|
849 | + foreach ($msgr_settings as $field => $value) { |
|
850 | 850 | //is there a new setting for this? |
851 | - if ( isset( $new_settings[ $field ] ) ) { |
|
852 | - $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $new_settings[ $field ]; |
|
851 | + if (isset($new_settings[$field])) { |
|
852 | + $this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field]; |
|
853 | 853 | continue; |
854 | 854 | } |
855 | 855 | //only set the default if it isn't already set. |
856 | - if ( ! isset( $this->_active_message_types[ $messenger->name ]['settings'][ $field ] ) ) { |
|
857 | - $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $value; |
|
856 | + if ( ! isset($this->_active_message_types[$messenger->name]['settings'][$field])) { |
|
857 | + $this->_active_message_types[$messenger->name]['settings'][$field] = $value; |
|
858 | 858 | } |
859 | 859 | } |
860 | 860 | } |
@@ -869,13 +869,13 @@ discard block |
||
869 | 869 | * @param string|EE_messenger $messenger_name name of messenger |
870 | 870 | * @return void |
871 | 871 | */ |
872 | - public function deactivate_messenger( $messenger_name ) { |
|
873 | - if ( $messenger_name instanceof EE_messenger ) { |
|
872 | + public function deactivate_messenger($messenger_name) { |
|
873 | + if ($messenger_name instanceof EE_messenger) { |
|
874 | 874 | $messenger_name = $messenger_name->name; |
875 | 875 | } |
876 | - unset( $this->_active_messengers[ $messenger_name ] ); |
|
877 | - unset( $this->_active_message_types[ $messenger_name ] ); |
|
878 | - $this->_message_template_group_model->deactivate_message_template_groups_for( $messenger_name ); |
|
876 | + unset($this->_active_messengers[$messenger_name]); |
|
877 | + unset($this->_active_message_types[$messenger_name]); |
|
878 | + $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name); |
|
879 | 879 | $this->update_active_messengers_option(); |
880 | 880 | } |
881 | 881 | |
@@ -885,16 +885,16 @@ discard block |
||
885 | 885 | * |
886 | 886 | * @param string $message_type_name name of message type being deactivated |
887 | 887 | */ |
888 | - public function deactivate_message_type( $message_type_name ) { |
|
889 | - if ( $message_type_name instanceof EE_message_type ) { |
|
888 | + public function deactivate_message_type($message_type_name) { |
|
889 | + if ($message_type_name instanceof EE_message_type) { |
|
890 | 890 | $message_type_name = $message_type_name->name; |
891 | 891 | } |
892 | - foreach ( $this->_active_message_types as $messenger => $settings ) { |
|
892 | + foreach ($this->_active_message_types as $messenger => $settings) { |
|
893 | 893 | unset( |
894 | - $this->_active_message_types[ $messenger ]['settings'][ $messenger . '-message_types' ][ $message_type_name ] |
|
894 | + $this->_active_message_types[$messenger]['settings'][$messenger.'-message_types'][$message_type_name] |
|
895 | 895 | ); |
896 | 896 | } |
897 | - $this->_message_template_group_model->deactivate_message_template_groups_for( '', $message_type_name ); |
|
897 | + $this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name); |
|
898 | 898 | $this->update_active_messengers_option(); |
899 | 899 | } |
900 | 900 | |
@@ -908,11 +908,11 @@ discard block |
||
908 | 908 | * @param string $message_type_name Name of message type being deactivated. |
909 | 909 | * @param string $messenger_name Name of messenger the message type is being deactivated for. |
910 | 910 | */ |
911 | - public function deactivate_message_type_for_messenger( $message_type_name, $messenger_name ) { |
|
912 | - if ( $this->is_message_type_active_for_messenger( $messenger_name, $message_type_name ) ) { |
|
913 | - unset( $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ] ); |
|
911 | + public function deactivate_message_type_for_messenger($message_type_name, $messenger_name) { |
|
912 | + if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
913 | + unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]); |
|
914 | 914 | } |
915 | - $this->_message_template_group_model->deactivate_message_template_groups_for( array( $messenger_name ), array( $message_type_name ) ); |
|
915 | + $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name), array($message_type_name)); |
|
916 | 916 | $this->update_active_messengers_option(); |
917 | 917 | } |
918 | 918 | |
@@ -929,12 +929,12 @@ discard block |
||
929 | 929 | * |
930 | 930 | * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send. |
931 | 931 | */ |
932 | - public function is_generating_messenger_and_active( EE_messenger $messenger, EE_message_type $message_type ) { |
|
932 | + public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) { |
|
933 | 933 | //get the $messengers the message type says it can be used with. |
934 | - foreach ( $message_type->with_messengers() as $generating_messenger => $secondary_messengers ) { |
|
934 | + foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) { |
|
935 | 935 | if ( |
936 | 936 | $messenger->name === $generating_messenger |
937 | - && $this->is_message_type_active_for_messenger( $messenger->name, $message_type->name ) |
|
937 | + && $this->is_message_type_active_for_messenger($messenger->name, $message_type->name) |
|
938 | 938 | ) { |
939 | 939 | return true; |
940 | 940 | } |
@@ -971,25 +971,25 @@ discard block |
||
971 | 971 | * or all contexts indexed by message type. |
972 | 972 | * @return array |
973 | 973 | */ |
974 | - public function get_all_contexts( $slugs_only = true ) { |
|
974 | + public function get_all_contexts($slugs_only = true) { |
|
975 | 975 | $key = $slugs_only ? 'slugs' : 'all'; |
976 | 976 | // check if contexts has been setup yet. |
977 | - if ( empty( $this->_contexts[ $key ] ) ) { |
|
977 | + if (empty($this->_contexts[$key])) { |
|
978 | 978 | // So let's get all active message type objects and loop through to get all unique contexts |
979 | - foreach ( $this->get_active_message_type_objects() as $message_type ) { |
|
980 | - if ( $message_type instanceof EE_message_type ) { |
|
979 | + foreach ($this->get_active_message_type_objects() as $message_type) { |
|
980 | + if ($message_type instanceof EE_message_type) { |
|
981 | 981 | $message_type_contexts = $message_type->get_contexts(); |
982 | - if ( $slugs_only ) { |
|
983 | - foreach ( $message_type_contexts as $context => $context_details ) { |
|
984 | - $this->_contexts[ $key ][ $context ] = $context_details[ 'label' ]; |
|
982 | + if ($slugs_only) { |
|
983 | + foreach ($message_type_contexts as $context => $context_details) { |
|
984 | + $this->_contexts[$key][$context] = $context_details['label']; |
|
985 | 985 | } |
986 | 986 | } else { |
987 | - $this->_contexts[ $key ][ $message_type->name ] = $message_type_contexts; |
|
987 | + $this->_contexts[$key][$message_type->name] = $message_type_contexts; |
|
988 | 988 | } |
989 | 989 | } |
990 | 990 | } |
991 | 991 | } |
992 | - return ! empty( $this->_contexts[ $key ] ) ? $this->_contexts[ $key ] : array(); |
|
992 | + return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array(); |
|
993 | 993 | } |
994 | 994 | |
995 | 995 | |
@@ -1008,9 +1008,9 @@ discard block |
||
1008 | 1008 | $installed_message_types = $this->installed_message_types(); |
1009 | 1009 | $all_message_types_valid = true; |
1010 | 1010 | //loop through list of active message types and verify they are installed. |
1011 | - foreach( $list_of_active_message_type_names as $message_type_name ) { |
|
1012 | - if ( ! isset( $installed_message_types[$message_type_name] ) ) { |
|
1013 | - $this->deactivate_message_type( $message_type_name ); |
|
1011 | + foreach ($list_of_active_message_type_names as $message_type_name) { |
|
1012 | + if ( ! isset($installed_message_types[$message_type_name])) { |
|
1013 | + $this->deactivate_message_type($message_type_name); |
|
1014 | 1014 | $all_message_types_valid = false; |
1015 | 1015 | } |
1016 | 1016 | } |
@@ -1029,10 +1029,10 @@ discard block |
||
1029 | 1029 | * @param $messenger_name |
1030 | 1030 | * @return bool |
1031 | 1031 | */ |
1032 | - public function has_message_type_been_activated_for_messenger( $message_type_name, $messenger_name ) { |
|
1032 | + public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name) { |
|
1033 | 1033 | $has_activated = $this->get_has_activated_messengers_option(); |
1034 | - return isset( $has_activated[ $messenger_name ] ) |
|
1035 | - && in_array( $message_type_name, $has_activated[ $messenger_name ] ); |
|
1034 | + return isset($has_activated[$messenger_name]) |
|
1035 | + && in_array($message_type_name, $has_activated[$messenger_name]); |
|
1036 | 1036 | } |
1037 | 1037 | } |
1038 | 1038 | // End of file EE_Message_Resource_Manager.lib.php |
@@ -175,7 +175,7 @@ |
||
175 | 175 | * @param array $wpdb_row |
176 | 176 | * @param \WP_REST_Request $request |
177 | 177 | * @param Base $controller |
178 | - * @return int|null if permission denied |
|
178 | + * @return integer if permission denied |
|
179 | 179 | */ |
180 | 180 | public static function registrations_checked_in_count( $wpdb_row, $request, $controller ){ |
181 | 181 | if( ! is_array( $wpdb_row ) || ! isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) { |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | * @since $VID:$ |
16 | 16 | * |
17 | 17 | */ |
18 | -if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
19 | - exit( 'No direct script access allowed' ); |
|
18 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
19 | + exit('No direct script access allowed'); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | class Event extends Calculations_Base { |
@@ -32,20 +32,20 @@ discard block |
||
32 | 32 | * @return int |
33 | 33 | * @throws \EE_Error |
34 | 34 | */ |
35 | - public static function optimum_sales_at_start( $wpdb_row, $request, $controller ){ |
|
36 | - if( is_array( $wpdb_row ) && isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) { |
|
37 | - $event_obj = \EEM_Event::instance()->get_one_by_ID( $wpdb_row[ 'Event_CPT.ID' ] ); |
|
35 | + public static function optimum_sales_at_start($wpdb_row, $request, $controller) { |
|
36 | + if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID'])) { |
|
37 | + $event_obj = \EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
38 | 38 | } else { |
39 | 39 | $event_obj = null; |
40 | 40 | } |
41 | - if( $event_obj instanceof \EE_Event ) { |
|
42 | - return $event_obj->total_available_spaces( true ); |
|
41 | + if ($event_obj instanceof \EE_Event) { |
|
42 | + return $event_obj->total_available_spaces(true); |
|
43 | 43 | } else { |
44 | 44 | throw new \EE_Error( |
45 | 45 | sprintf( |
46 | - __( 'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso' ), |
|
47 | - $wpdb_row[ 'Event_CPT.ID' ], |
|
48 | - print_r( $wpdb_row, true ) |
|
46 | + __('Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso'), |
|
47 | + $wpdb_row['Event_CPT.ID'], |
|
48 | + print_r($wpdb_row, true) |
|
49 | 49 | ) |
50 | 50 | ); |
51 | 51 | } |
@@ -64,20 +64,20 @@ discard block |
||
64 | 64 | * @return int |
65 | 65 | * @throws \EE_Error |
66 | 66 | */ |
67 | - public static function optimum_sales_now( $wpdb_row, $request, $controller ){ |
|
68 | - if( is_array( $wpdb_row ) && isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) { |
|
69 | - $event_obj = \EEM_Event::instance()->get_one_by_ID( $wpdb_row[ 'Event_CPT.ID' ] ); |
|
67 | + public static function optimum_sales_now($wpdb_row, $request, $controller) { |
|
68 | + if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID'])) { |
|
69 | + $event_obj = \EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
70 | 70 | } else { |
71 | 71 | $event_obj = null; |
72 | 72 | } |
73 | - if( $event_obj instanceof \EE_Event ) { |
|
74 | - return $event_obj->total_available_spaces( false ); |
|
73 | + if ($event_obj instanceof \EE_Event) { |
|
74 | + return $event_obj->total_available_spaces(false); |
|
75 | 75 | } else { |
76 | 76 | throw new \EE_Error( |
77 | 77 | sprintf( |
78 | - __( 'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso' ), |
|
79 | - $wpdb_row[ 'Event_CPT.ID' ], |
|
80 | - print_r( $wpdb_row, true ) |
|
78 | + __('Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso'), |
|
79 | + $wpdb_row['Event_CPT.ID'], |
|
80 | + print_r($wpdb_row, true) |
|
81 | 81 | ) |
82 | 82 | ); |
83 | 83 | } |
@@ -95,20 +95,20 @@ discard block |
||
95 | 95 | * @return int |
96 | 96 | * @throws \EE_Error |
97 | 97 | */ |
98 | - public static function spaces_remaining( $wpdb_row, $request, $controller ){ |
|
99 | - if( is_array( $wpdb_row ) && isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) { |
|
100 | - $event_obj = \EEM_Event::instance()->get_one_by_ID( $wpdb_row[ 'Event_CPT.ID' ] ); |
|
98 | + public static function spaces_remaining($wpdb_row, $request, $controller) { |
|
99 | + if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID'])) { |
|
100 | + $event_obj = \EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
101 | 101 | } else { |
102 | 102 | $event_obj = null; |
103 | 103 | } |
104 | - if( $event_obj instanceof \EE_Event ) { |
|
104 | + if ($event_obj instanceof \EE_Event) { |
|
105 | 105 | return $event_obj->spaces_remaining_for_sale(); |
106 | 106 | } else { |
107 | 107 | throw new \EE_Error( |
108 | 108 | sprintf( |
109 | - __( 'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso' ), |
|
110 | - $wpdb_row[ 'Event_CPT.ID' ], |
|
111 | - print_r( $wpdb_row, true ) |
|
109 | + __('Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso'), |
|
110 | + $wpdb_row['Event_CPT.ID'], |
|
111 | + print_r($wpdb_row, true) |
|
112 | 112 | ) |
113 | 113 | ); |
114 | 114 | } |
@@ -126,19 +126,19 @@ discard block |
||
126 | 126 | * @return int |
127 | 127 | * @throws \EE_Error |
128 | 128 | */ |
129 | - public static function spots_taken( $wpdb_row, $request, $controller ){ |
|
130 | - if( ! is_array( $wpdb_row ) || ! isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) { |
|
129 | + public static function spots_taken($wpdb_row, $request, $controller) { |
|
130 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
131 | 131 | throw new \EE_Error( |
132 | 132 | sprintf( |
133 | - __( 'Cannot calculate spots_taken because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso' ), |
|
134 | - print_r( $wpdb_row, true ) |
|
133 | + __('Cannot calculate spots_taken because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso'), |
|
134 | + print_r($wpdb_row, true) |
|
135 | 135 | ) |
136 | 136 | ); |
137 | 137 | } |
138 | 138 | return \EEM_Registration::instance()->count( |
139 | 139 | array( |
140 | 140 | array( |
141 | - 'EVT_ID' => $wpdb_row[ 'Event_CPT.ID' ], |
|
141 | + 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
142 | 142 | 'STS_ID' => \EEM_Registration::status_id_approved |
143 | 143 | ) |
144 | 144 | ), |
@@ -160,20 +160,20 @@ discard block |
||
160 | 160 | * @throws \EE_Error |
161 | 161 | * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
162 | 162 | */ |
163 | - public static function spots_taken_pending_payment( $wpdb_row, $request, $controller ){ |
|
164 | - if( ! is_array( $wpdb_row ) || ! isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) { |
|
163 | + public static function spots_taken_pending_payment($wpdb_row, $request, $controller) { |
|
164 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
165 | 165 | throw new \EE_Error( |
166 | 166 | sprintf( |
167 | - __( 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso' ), |
|
168 | - print_r( $wpdb_row, true ) |
|
167 | + __('Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso'), |
|
168 | + print_r($wpdb_row, true) |
|
169 | 169 | ) |
170 | 170 | ); |
171 | 171 | } |
172 | - self::_verify_current_user_can( 'ee_read_registrations', 'spots_taken_pending_payment' ); |
|
172 | + self::_verify_current_user_can('ee_read_registrations', 'spots_taken_pending_payment'); |
|
173 | 173 | return \EEM_Registration::instance()->count( |
174 | 174 | array( |
175 | 175 | array( |
176 | - 'EVT_ID' => $wpdb_row[ 'Event_CPT.ID' ], |
|
176 | + 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
177 | 177 | 'STS_ID' => \EEM_Registration::status_id_pending_payment |
178 | 178 | ) |
179 | 179 | ), |
@@ -195,17 +195,17 @@ discard block |
||
195 | 195 | * @throws \EE_Error |
196 | 196 | * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
197 | 197 | */ |
198 | - public static function registrations_checked_in_count( $wpdb_row, $request, $controller ){ |
|
199 | - if( ! is_array( $wpdb_row ) || ! isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) { |
|
198 | + public static function registrations_checked_in_count($wpdb_row, $request, $controller) { |
|
199 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
200 | 200 | throw new \EE_Error( |
201 | 201 | sprintf( |
202 | - __( 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso' ), |
|
203 | - print_r( $wpdb_row, true ) |
|
202 | + __('Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso'), |
|
203 | + print_r($wpdb_row, true) |
|
204 | 204 | ) |
205 | 205 | ); |
206 | 206 | } |
207 | - self::_verify_current_user_can( 'ee_read_checkins', 'registrations_checked_in_count' ); |
|
208 | - return \EEM_Registration::instance()->count_registrations_checked_into_event( $wpdb_row[ 'Event_CPT.ID' ], true ); |
|
207 | + self::_verify_current_user_can('ee_read_checkins', 'registrations_checked_in_count'); |
|
208 | + return \EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -221,17 +221,17 @@ discard block |
||
221 | 221 | * @throws \EE_Error |
222 | 222 | * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
223 | 223 | */ |
224 | - public static function registrations_checked_out_count( $wpdb_row, $request, $controller ){ |
|
225 | - if( ! is_array( $wpdb_row ) || ! isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) { |
|
224 | + public static function registrations_checked_out_count($wpdb_row, $request, $controller) { |
|
225 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
226 | 226 | throw new \EE_Error( |
227 | 227 | sprintf( |
228 | - __( 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso' ), |
|
229 | - print_r( $wpdb_row, true ) |
|
228 | + __('Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', 'event_espresso'), |
|
229 | + print_r($wpdb_row, true) |
|
230 | 230 | ) |
231 | 231 | ); |
232 | 232 | } |
233 | - self::_verify_current_user_can( 'ee_read_checkins', 'registrations_checked_out_count' ); |
|
234 | - return \EEM_Registration::instance()->count_registrations_checked_into_event( $wpdb_row[ 'Event_CPT.ID' ], false ); |
|
233 | + self::_verify_current_user_can('ee_read_checkins', 'registrations_checked_out_count'); |
|
234 | + return \EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -241,8 +241,8 @@ discard block |
||
241 | 241 | * @param Base $controller |
242 | 242 | * @return array |
243 | 243 | */ |
244 | - public static function image_thumbnail( $wpdb_row, $request, $controller ) { |
|
245 | - return self::_calculate_image_data($wpdb_row[ 'Event_CPT.ID' ], 'thumbnail' ); |
|
244 | + public static function image_thumbnail($wpdb_row, $request, $controller) { |
|
245 | + return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'thumbnail'); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | * @param Base $controller |
253 | 253 | * @return array |
254 | 254 | */ |
255 | - public static function image_medium( $wpdb_row, $request, $controller ) { |
|
256 | - return self::_calculate_image_data($wpdb_row[ 'Event_CPT.ID' ], 'medium' ); |
|
255 | + public static function image_medium($wpdb_row, $request, $controller) { |
|
256 | + return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'medium'); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | * @param Base $controller |
264 | 264 | * @return array |
265 | 265 | */ |
266 | - public static function image_medium_large( $wpdb_row, $request, $controller ) { |
|
267 | - return self::_calculate_image_data($wpdb_row[ 'Event_CPT.ID' ], 'medium_large' ); |
|
266 | + public static function image_medium_large($wpdb_row, $request, $controller) { |
|
267 | + return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'medium_large'); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -274,8 +274,8 @@ discard block |
||
274 | 274 | * @param Base $controller |
275 | 275 | * @return array |
276 | 276 | */ |
277 | - public static function image_large( $wpdb_row, $request, $controller ) { |
|
278 | - return self::_calculate_image_data($wpdb_row[ 'Event_CPT.ID' ], 'large' ); |
|
277 | + public static function image_large($wpdb_row, $request, $controller) { |
|
278 | + return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'large'); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | * @param Base $controller |
286 | 286 | * @return array |
287 | 287 | */ |
288 | - public static function image_post_thumbnail( $wpdb_row, $request, $controller ) { |
|
289 | - return self::_calculate_image_data($wpdb_row[ 'Event_CPT.ID' ], 'post-thumbnail' ); |
|
288 | + public static function image_post_thumbnail($wpdb_row, $request, $controller) { |
|
289 | + return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'post-thumbnail'); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -296,8 +296,8 @@ discard block |
||
296 | 296 | * @param Base $controller |
297 | 297 | * @return array |
298 | 298 | */ |
299 | - public static function image_full( $wpdb_row, $request, $controller ) { |
|
300 | - return self::_calculate_image_data($wpdb_row[ 'Event_CPT.ID' ], 'full' ); |
|
299 | + public static function image_full($wpdb_row, $request, $controller) { |
|
300 | + return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'full'); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
@@ -307,21 +307,21 @@ discard block |
||
307 | 307 | * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full |
308 | 308 | * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original' |
309 | 309 | */ |
310 | - protected static function _calculate_image_data( $EVT_ID, $image_size ) { |
|
311 | - $attachment_id = get_post_thumbnail_id( $EVT_ID ); |
|
312 | - $data = wp_get_attachment_image_src( $attachment_id, $image_size ); |
|
313 | - if( ! $data ) { |
|
310 | + protected static function _calculate_image_data($EVT_ID, $image_size) { |
|
311 | + $attachment_id = get_post_thumbnail_id($EVT_ID); |
|
312 | + $data = wp_get_attachment_image_src($attachment_id, $image_size); |
|
313 | + if ( ! $data) { |
|
314 | 314 | return false; |
315 | 315 | } |
316 | - if( isset( $data[ 3] ) ) { |
|
317 | - $generated = $data[ 3 ]; |
|
316 | + if (isset($data[3])) { |
|
317 | + $generated = $data[3]; |
|
318 | 318 | } else { |
319 | 319 | $generated = true; |
320 | 320 | } |
321 | 321 | return array( |
322 | - 'url' => $data[ 0 ], |
|
323 | - 'width' => $data[ 1 ], |
|
324 | - 'height' => $data[ 2 ], |
|
322 | + 'url' => $data[0], |
|
323 | + 'width' => $data[1], |
|
324 | + 'height' => $data[2], |
|
325 | 325 | 'generated' => $generated |
326 | 326 | ); |
327 | 327 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | /** |
56 | 56 | * Prepares incoming data from the json or $_REQUEST parameters for the models' |
57 | 57 | * "$query_params". |
58 | - * @param EE_Model_Field_Base $field_obj |
|
58 | + * @param \EE_Model_Field_Base $field_obj |
|
59 | 59 | * @param mixed $original_value |
60 | 60 | * @param string $requested_version |
61 | 61 | * @return mixed |
@@ -77,6 +77,7 @@ discard block |
||
77 | 77 | * Prepares a field's value for display in the API |
78 | 78 | * @param \EE_Model_Field_Base $field_obj |
79 | 79 | * @param mixed $original_value |
80 | + * @param string $requested_version |
|
80 | 81 | * @return mixed |
81 | 82 | */ |
82 | 83 | public static function prepare_field_value_for_json( $field_obj, $original_value, $requested_version ) { |
@@ -131,6 +132,9 @@ discard block |
||
131 | 132 | return $query_param_for_models; |
132 | 133 | } |
133 | 134 | |
135 | + /** |
|
136 | + * @return string |
|
137 | + */ |
|
134 | 138 | public static function remove_stars_and_anything_after_from_condition_query_param_key( $condition_query_param_key ) { |
135 | 139 | $pos_of_star = strpos($condition_query_param_key, '*'); |
136 | 140 | if($pos_of_star === FALSE){ |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | - * Prepares a field's value for display in the API |
|
78 | - * @param \EE_Model_Field_Base $field_obj |
|
79 | - * @param mixed $original_value |
|
80 | - * @return mixed |
|
81 | - */ |
|
77 | + * Prepares a field's value for display in the API |
|
78 | + * @param \EE_Model_Field_Base $field_obj |
|
79 | + * @param mixed $original_value |
|
80 | + * @return mixed |
|
81 | + */ |
|
82 | 82 | public static function prepare_field_value_for_json( $field_obj, $original_value, $requested_version ) { |
83 | 83 | if( $original_value === EE_INF ) { |
84 | 84 | $new_value = self::ee_inf_in_rest; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $original_value, |
96 | 96 | $requested_version |
97 | 97 | ); |
98 | - } |
|
98 | + } |
|
99 | 99 | |
100 | 100 | /** |
101 | 101 | * Prepares condition-query-parameters (like what's in where and having) from |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $pos_of_star = strpos($condition_query_param_key, '*'); |
136 | 136 | if($pos_of_star === FALSE){ |
137 | 137 | return $condition_query_param_key; |
138 | - }else{ |
|
138 | + } else{ |
|
139 | 139 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
140 | 140 | return $condition_query_param_sans_star; |
141 | 141 | } |
@@ -159,14 +159,14 @@ discard block |
||
159 | 159 | $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
160 | 160 | if($number_of_parts == 1){ |
161 | 161 | $field_name = $last_query_param_part; |
162 | - }else{// $number_of_parts >= 2 |
|
162 | + } else{// $number_of_parts >= 2 |
|
163 | 163 | //the last part is the column name, and there are only 2parts. therefore... |
164 | 164 | $field_name = $last_query_param_part; |
165 | 165 | $model = \EE_Registry::instance()->load_model( $query_param_parts[ $number_of_parts - 2 ]); |
166 | 166 | } |
167 | 167 | try{ |
168 | 168 | return $model->field_settings_for($field_name); |
169 | - }catch(\EE_Error $e){ |
|
169 | + } catch(\EE_Error $e){ |
|
170 | 170 | return null; |
171 | 171 | } |
172 | 172 | } |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | */ |
22 | 22 | |
23 | 23 | |
24 | -if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
25 | - exit( 'No direct script access allowed' ); |
|
24 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
25 | + exit('No direct script access allowed'); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | class Model_Data_Translator { |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | * @param string $requested_version |
41 | 41 | * @return mixed |
42 | 42 | */ |
43 | - public static function prepare_field_values_from_json( $field_obj, $original_value_maybe_array, $requested_version ) { |
|
44 | - if( is_array( $original_value_maybe_array ) ) { |
|
43 | + public static function prepare_field_values_from_json($field_obj, $original_value_maybe_array, $requested_version) { |
|
44 | + if (is_array($original_value_maybe_array)) { |
|
45 | 45 | $new_value_maybe_array = array(); |
46 | - foreach( $original_value_maybe_array as $array_key => $array_item ) { |
|
47 | - $new_value_maybe_array[ $array_key ] = self::prepare_field_value_from_json( $field_obj, $array_item, $requested_version ); |
|
46 | + foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
47 | + $new_value_maybe_array[$array_key] = self::prepare_field_value_from_json($field_obj, $array_item, $requested_version); |
|
48 | 48 | } |
49 | 49 | } else { |
50 | - $new_value_maybe_array = self::prepare_field_value_from_json( $field_obj, $original_value_maybe_array, $requested_version ); |
|
50 | + $new_value_maybe_array = self::prepare_field_value_from_json($field_obj, $original_value_maybe_array, $requested_version); |
|
51 | 51 | } |
52 | 52 | return $new_value_maybe_array; |
53 | 53 | } |
@@ -60,13 +60,13 @@ discard block |
||
60 | 60 | * @param string $requested_version |
61 | 61 | * @return mixed |
62 | 62 | */ |
63 | - public static function prepare_field_value_from_json( $field_obj, $original_value, $requested_version ) { |
|
63 | + public static function prepare_field_value_from_json($field_obj, $original_value, $requested_version) { |
|
64 | 64 | $new_value = null; |
65 | - if( $field_obj instanceof \EE_Infinite_Integer_Field |
|
66 | - && in_array( $original_value, array( null, '' ), true ) ) { |
|
65 | + if ($field_obj instanceof \EE_Infinite_Integer_Field |
|
66 | + && in_array($original_value, array(null, ''), true)) { |
|
67 | 67 | $new_value = EE_INF; |
68 | - } elseif( $field_obj instanceof \EE_Datetime_Field ) { |
|
69 | - $new_value = rest_parse_date( $original_value ); |
|
68 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
69 | + $new_value = rest_parse_date($original_value); |
|
70 | 70 | } else { |
71 | 71 | $new_value = $original_value; |
72 | 72 | } |
@@ -79,17 +79,17 @@ discard block |
||
79 | 79 | * @param mixed $original_value |
80 | 80 | * @return mixed |
81 | 81 | */ |
82 | - public static function prepare_field_value_for_json( $field_obj, $original_value, $requested_version ) { |
|
83 | - if( $original_value === EE_INF ) { |
|
82 | + public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version) { |
|
83 | + if ($original_value === EE_INF) { |
|
84 | 84 | $new_value = self::ee_inf_in_rest; |
85 | - } elseif( $field_obj instanceof \EE_Datetime_Field && |
|
86 | - $original_value instanceof \DateTime ) { |
|
87 | - $new_value = $original_value->format( 'c' ); |
|
88 | - $new_value = mysql_to_rfc3339( $new_value ); |
|
85 | + } elseif ($field_obj instanceof \EE_Datetime_Field && |
|
86 | + $original_value instanceof \DateTime) { |
|
87 | + $new_value = $original_value->format('c'); |
|
88 | + $new_value = mysql_to_rfc3339($new_value); |
|
89 | 89 | } else { |
90 | 90 | $new_value = $original_value; |
91 | 91 | } |
92 | - return apply_filters( 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
92 | + return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
93 | 93 | $new_value, |
94 | 94 | $field_obj, |
95 | 95 | $original_value, |
@@ -105,39 +105,39 @@ discard block |
||
105 | 105 | * @param string $requested_version |
106 | 106 | * @return array |
107 | 107 | */ |
108 | - public static function prepare_conditions_query_params_for_models( $inputted_query_params_of_this_type, \EEM_Base $model, $requested_version ) { |
|
108 | + public static function prepare_conditions_query_params_for_models($inputted_query_params_of_this_type, \EEM_Base $model, $requested_version) { |
|
109 | 109 | $query_param_for_models = array(); |
110 | - foreach( $inputted_query_params_of_this_type as $query_param_key => $query_param_value ) { |
|
110 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
111 | 111 | $field = self::deduce_field_from_query_param( |
112 | - self::remove_stars_and_anything_after_from_condition_query_param_key( $query_param_key ), |
|
112 | + self::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key), |
|
113 | 113 | $model |
114 | 114 | ); |
115 | - if( $field instanceof \EE_Model_Field_Base ) { |
|
115 | + if ($field instanceof \EE_Model_Field_Base) { |
|
116 | 116 | //did they specify an operator? |
117 | - if( is_array( $query_param_value ) ) { |
|
118 | - $op = $query_param_value[ 0 ]; |
|
119 | - $translated_value = array( $op ); |
|
120 | - if( isset( $query_param_value[ 1 ] ) ) { |
|
121 | - $value = $query_param_value[ 1 ]; |
|
122 | - $translated_value[1] = self::prepare_field_values_from_json( $field, $value, $requested_version ); |
|
117 | + if (is_array($query_param_value)) { |
|
118 | + $op = $query_param_value[0]; |
|
119 | + $translated_value = array($op); |
|
120 | + if (isset($query_param_value[1])) { |
|
121 | + $value = $query_param_value[1]; |
|
122 | + $translated_value[1] = self::prepare_field_values_from_json($field, $value, $requested_version); |
|
123 | 123 | } |
124 | 124 | } else { |
125 | - $translated_value = self::prepare_field_value_from_json( $field, $query_param_value, $requested_version ); |
|
125 | + $translated_value = self::prepare_field_value_from_json($field, $query_param_value, $requested_version); |
|
126 | 126 | } |
127 | - $query_param_for_models[ $query_param_key ] = $translated_value; |
|
127 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
128 | 128 | } else { |
129 | 129 | //so it's not for a field, assume it's a logic query param key |
130 | - $query_param_for_models[ $query_param_key ] = self::prepare_conditions_query_params_for_models( $query_param_value, $model, $requested_version ); |
|
130 | + $query_param_for_models[$query_param_key] = self::prepare_conditions_query_params_for_models($query_param_value, $model, $requested_version); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | return $query_param_for_models; |
134 | 134 | } |
135 | 135 | |
136 | - public static function remove_stars_and_anything_after_from_condition_query_param_key( $condition_query_param_key ) { |
|
136 | + public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
137 | 137 | $pos_of_star = strpos($condition_query_param_key, '*'); |
138 | - if($pos_of_star === FALSE){ |
|
138 | + if ($pos_of_star === FALSE) { |
|
139 | 139 | return $condition_query_param_key; |
140 | - }else{ |
|
140 | + } else { |
|
141 | 141 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
142 | 142 | return $condition_query_param_sans_star; |
143 | 143 | } |
@@ -149,26 +149,26 @@ discard block |
||
149 | 149 | * @throws EE_Error |
150 | 150 | * @return EE_Model_Field_Base |
151 | 151 | */ |
152 | - public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model){ |
|
152 | + public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model) { |
|
153 | 153 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
154 | 154 | //which will help us find the database table and column |
155 | 155 | |
156 | - $query_param_parts = explode(".",$query_param_name); |
|
157 | - if(empty($query_param_parts)){ |
|
158 | - throw new \EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s",'event_espresso'),$query_param_name)); |
|
156 | + $query_param_parts = explode(".", $query_param_name); |
|
157 | + if (empty($query_param_parts)) { |
|
158 | + throw new \EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s", 'event_espresso'), $query_param_name)); |
|
159 | 159 | } |
160 | 160 | $number_of_parts = count($query_param_parts); |
161 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
162 | - if($number_of_parts == 1){ |
|
161 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
162 | + if ($number_of_parts == 1) { |
|
163 | 163 | $field_name = $last_query_param_part; |
164 | - }else{// $number_of_parts >= 2 |
|
164 | + } else {// $number_of_parts >= 2 |
|
165 | 165 | //the last part is the column name, and there are only 2parts. therefore... |
166 | 166 | $field_name = $last_query_param_part; |
167 | - $model = \EE_Registry::instance()->load_model( $query_param_parts[ $number_of_parts - 2 ]); |
|
167 | + $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]); |
|
168 | 168 | } |
169 | - try{ |
|
169 | + try { |
|
170 | 170 | return $model->field_settings_for($field_name); |
171 | - }catch(\EE_Error $e){ |
|
171 | + } catch (\EE_Error $e) { |
|
172 | 172 | return null; |
173 | 173 | } |
174 | 174 | } |