@@ -22,35 +22,35 @@ discard block |
||
22 | 22 | * @param EE_Response $response |
23 | 23 | * @return EE_Response |
24 | 24 | */ |
25 | - public function handle_request( EE_Request $request, EE_Response $response ) { |
|
25 | + public function handle_request(EE_Request $request, EE_Response $response) { |
|
26 | 26 | $this->_request = $request; |
27 | 27 | $this->_response = $response; |
28 | 28 | //$this->_response->add_output( "\n\t IN >> " . __CLASS__ ); |
29 | 29 | //$this->_response->set_notice( 1, 'hey look at this' ); |
30 | 30 | // check required WP version |
31 | - if ( ! $this->_minimum_wp_version_required() ) { |
|
32 | - $this->_request->un_set( 'activate', true ); |
|
33 | - add_action( 'admin_notices', array( $this, 'minimum_wp_version_error' ), 1 ); |
|
31 | + if ( ! $this->_minimum_wp_version_required()) { |
|
32 | + $this->_request->un_set('activate', true); |
|
33 | + add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
34 | 34 | //$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' ); |
35 | 35 | $this->_response->terminate_request(); |
36 | 36 | } |
37 | 37 | // check required PHP version |
38 | - if ( ! $this->_minimum_php_version_required() ) { |
|
39 | - $this->_request->un_set( 'activate', true ); |
|
40 | - add_action( 'admin_notices', array( $this, 'minimum_php_version_error' ), 1 ); |
|
38 | + if ( ! $this->_minimum_php_version_required()) { |
|
39 | + $this->_request->un_set('activate', true); |
|
40 | + add_action('admin_notices', array($this, 'minimum_php_version_error'), 1); |
|
41 | 41 | //$this->_response->add_output( "\n<br />" . 'minimum_php_version_error' ); |
42 | 42 | $this->_response->terminate_request(); |
43 | 43 | } |
44 | 44 | // check recommended WP version |
45 | - if ( ! $this->_minimum_wp_version_recommended() ) { |
|
45 | + if ( ! $this->_minimum_wp_version_recommended()) { |
|
46 | 46 | $this->_display_minimum_recommended_wp_version_notice(); |
47 | 47 | } |
48 | 48 | // check recommended PHP version |
49 | - if ( ! $this->_minimum_php_version_recommended() ) { |
|
49 | + if ( ! $this->_minimum_php_version_recommended()) { |
|
50 | 50 | $this->_display_minimum_recommended_php_version_notice(); |
51 | 51 | } |
52 | 52 | $this->_test_for_php_version_7(); |
53 | - $this->_response = $this->process_request_stack( $this->_request, $this->_response ); |
|
53 | + $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
54 | 54 | //$this->_response->add_output( "\n\t OUT << " . __CLASS__ ); |
55 | 55 | return $this->_response; |
56 | 56 | } |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | * @param string $min_version |
65 | 65 | * @return boolean |
66 | 66 | */ |
67 | - private function _check_wp_version( $min_version = EE_MIN_WP_VER_REQUIRED ) { |
|
67 | + private function _check_wp_version($min_version = EE_MIN_WP_VER_REQUIRED) { |
|
68 | 68 | global $wp_version; |
69 | - return version_compare( $wp_version, $min_version, '>=' ) ? true : false; |
|
69 | + return version_compare($wp_version, $min_version, '>=') ? true : false; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @return boolean |
79 | 79 | */ |
80 | 80 | private function _minimum_wp_version_required() { |
81 | - return $this->_check_wp_version( EE_MIN_WP_VER_REQUIRED ); |
|
81 | + return $this->_check_wp_version(EE_MIN_WP_VER_REQUIRED); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @return boolean |
91 | 91 | */ |
92 | 92 | private function _minimum_wp_version_recommended() { |
93 | - return $this->_check_wp_version( EE_MIN_WP_VER_RECOMMENDED ); |
|
93 | + return $this->_check_wp_version(EE_MIN_WP_VER_RECOMMENDED); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | * @param string $min_version |
103 | 103 | * @return boolean |
104 | 104 | */ |
105 | - private function _check_php_version( $min_version = EE_MIN_PHP_VER_RECOMMENDED ) { |
|
106 | - return version_compare( PHP_VERSION, $min_version, '>=' ) ? true : false; |
|
105 | + private function _check_php_version($min_version = EE_MIN_PHP_VER_RECOMMENDED) { |
|
106 | + return version_compare(PHP_VERSION, $min_version, '>=') ? true : false; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @return boolean |
116 | 116 | */ |
117 | 117 | private function _minimum_php_version_required() { |
118 | - return $this->_check_php_version( EE_MIN_PHP_VER_REQUIRED ); |
|
118 | + return $this->_check_php_version(EE_MIN_PHP_VER_REQUIRED); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @return boolean |
128 | 128 | */ |
129 | 129 | private function _minimum_php_version_recommended() { |
130 | - return $this->_check_php_version( EE_MIN_PHP_VER_RECOMMENDED ); |
|
130 | + return $this->_check_php_version(EE_MIN_PHP_VER_RECOMMENDED); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | <p> |
145 | 145 | <?php |
146 | 146 | printf( |
147 | - __( 'We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', 'event_espresso' ), |
|
147 | + __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', 'event_espresso'), |
|
148 | 148 | EE_MIN_WP_VER_REQUIRED, |
149 | 149 | $wp_version, |
150 | 150 | '<br/>', |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | <p> |
170 | 170 | <?php |
171 | 171 | printf( |
172 | - __( 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', 'event_espresso' ), |
|
172 | + __('We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', 'event_espresso'), |
|
173 | 173 | EE_MIN_PHP_VER_REQUIRED, |
174 | 174 | PHP_VERSION, |
175 | 175 | '<br/>', |
@@ -192,9 +192,9 @@ discard block |
||
192 | 192 | private function _display_minimum_recommended_wp_version_notice() { |
193 | 193 | global $wp_version; |
194 | 194 | EE_Error::add_persistent_admin_notice( |
195 | - 'wp_version_' . str_replace( '.', '-', EE_MIN_WP_VER_RECOMMENDED ) . '_recommended', |
|
195 | + 'wp_version_'.str_replace('.', '-', EE_MIN_WP_VER_RECOMMENDED).'_recommended', |
|
196 | 196 | sprintf( |
197 | - __( 'Event Espresso recommends WordPress version %1$s or greater in order for everything to operate properly. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', 'event_espresso' ), |
|
197 | + __('Event Espresso recommends WordPress version %1$s or greater in order for everything to operate properly. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', 'event_espresso'), |
|
198 | 198 | EE_MIN_WP_VER_RECOMMENDED, |
199 | 199 | $wp_version, |
200 | 200 | '<br/>', |
@@ -213,9 +213,9 @@ discard block |
||
213 | 213 | */ |
214 | 214 | private function _display_minimum_recommended_php_version_notice() { |
215 | 215 | EE_Error::add_persistent_admin_notice( |
216 | - 'php_version_' . str_replace( '.', '-', EE_MIN_PHP_VER_RECOMMENDED ) . '_recommended', |
|
216 | + 'php_version_'.str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED).'_recommended', |
|
217 | 217 | sprintf( |
218 | - __( 'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', 'event_espresso' ), |
|
218 | + __('Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', 'event_espresso'), |
|
219 | 219 | EE_MIN_PHP_VER_RECOMMENDED, |
220 | 220 | PHP_VERSION, |
221 | 221 | '<br/>', |
@@ -232,10 +232,10 @@ discard block |
||
232 | 232 | * @access private |
233 | 233 | */ |
234 | 234 | private function _test_for_php_version_7() { |
235 | - if ( $this->_check_php_version( '7' ) ) { |
|
236 | - define( 'EE_PHP_7', true ); |
|
235 | + if ($this->_check_php_version('7')) { |
|
236 | + define('EE_PHP_7', true); |
|
237 | 237 | } else { |
238 | - define( 'EE_PHP_7', false ); |
|
238 | + define('EE_PHP_7', false); |
|
239 | 239 | } |
240 | 240 | } |
241 | 241 |
@@ -22,7 +22,6 @@ |
||
22 | 22 | /** |
23 | 23 | * Removes the checkin and checkout endpoints from the index for requests |
24 | 24 | * to api versions lowers than 4.8.33 |
25 | - * @param array $routes_on_this_version |
|
26 | 25 | * @param EventEspresso\core\libraries\rest_api\controllers\Base $controller |
27 | 26 | * @return array like $routes_on_this_version |
28 | 27 | */ |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | //is for lower than 4.8.33 |
14 | 14 | add_filter( |
15 | 15 | 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
16 | - array( $this, 'remove_response_headers' ), |
|
16 | + array($this, 'remove_response_headers'), |
|
17 | 17 | 10, |
18 | 18 | 3 |
19 | 19 | ); |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | * @param EventEspresso\core\libraries\rest_api\controllers\Base $controller |
27 | 27 | * @return array like $routes_on_this_version |
28 | 28 | */ |
29 | - public function remove_response_headers( $response_headers, $controller, $requested_version ) { |
|
30 | - if( $controller instanceof Base |
|
31 | - && $this->applies_to_version( $requested_version ) ) { |
|
29 | + public function remove_response_headers($response_headers, $controller, $requested_version) { |
|
30 | + if ($controller instanceof Base |
|
31 | + && $this->applies_to_version($requested_version)) { |
|
32 | 32 | return array(); |
33 | 33 | } |
34 | 34 | return $response_headers; |
@@ -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 ); |
@@ -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 | /** |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | public function __construct() { |
35 | 35 | parent::__construct(); |
36 | - \EE_Registry::instance()->load_helper( 'Inflector' ); |
|
36 | + \EE_Registry::instance()->load_helper('Inflector'); |
|
37 | 37 | $this->_fields_calculator = new Calculated_Model_Fields(); |
38 | 38 | } |
39 | 39 | |
@@ -42,22 +42,22 @@ discard block |
||
42 | 42 | * @param \WP_REST_Request $request |
43 | 43 | * @return \WP_REST_Response|\WP_Error |
44 | 44 | */ |
45 | - public static function handle_request_get_all( \WP_REST_Request $request) { |
|
45 | + public static function handle_request_get_all(\WP_REST_Request $request) { |
|
46 | 46 | $controller = new Read(); |
47 | - try{ |
|
47 | + try { |
|
48 | 48 | $matches = $controller->parse_route( |
49 | 49 | $request->get_route(), |
50 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
51 | - array( 'version', 'model' ) |
|
50 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~', |
|
51 | + array('version', 'model') |
|
52 | 52 | ); |
53 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
54 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
55 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
53 | + $controller->set_requested_version($matches['version']); |
|
54 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
55 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
56 | 56 | return $controller->send_response( |
57 | 57 | new \WP_Error( |
58 | 58 | 'endpoint_parsing_error', |
59 | 59 | sprintf( |
60 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
60 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
61 | 61 | $model_name_singular |
62 | 62 | ) |
63 | 63 | ) |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | } |
66 | 66 | return $controller->send_response( |
67 | 67 | $controller->get_entities_from_model( |
68 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
68 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
69 | 69 | $request |
70 | 70 | ) |
71 | 71 | ); |
72 | - } catch( \Exception $e ) { |
|
73 | - return $controller->send_response( $e ); |
|
72 | + } catch (\Exception $e) { |
|
73 | + return $controller->send_response($e); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
@@ -80,21 +80,21 @@ discard block |
||
80 | 80 | * @param \WP_Rest_Request $request |
81 | 81 | * @return \WP_REST_Response|\WP_Error |
82 | 82 | */ |
83 | - public static function handle_request_get_one( \WP_Rest_Request $request ) { |
|
83 | + public static function handle_request_get_one(\WP_Rest_Request $request) { |
|
84 | 84 | $controller = new Read(); |
85 | - try{ |
|
85 | + try { |
|
86 | 86 | $matches = $controller->parse_route( |
87 | 87 | $request->get_route(), |
88 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
89 | - array( 'version', 'model', 'id' ) ); |
|
90 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
91 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
92 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
88 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~', |
|
89 | + array('version', 'model', 'id') ); |
|
90 | + $controller->set_requested_version($matches['version']); |
|
91 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
92 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
93 | 93 | return $controller->send_response( |
94 | 94 | new \WP_Error( |
95 | 95 | 'endpoint_parsing_error', |
96 | 96 | sprintf( |
97 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
97 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
98 | 98 | $model_name_singular |
99 | 99 | ) |
100 | 100 | ) |
@@ -102,12 +102,12 @@ discard block |
||
102 | 102 | } |
103 | 103 | return $controller->send_response( |
104 | 104 | $controller->get_entity_from_model( |
105 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
105 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
106 | 106 | $request |
107 | 107 | ) |
108 | 108 | ); |
109 | - } catch( \Exception $e ) { |
|
110 | - return $controller->send_response( $e ); |
|
109 | + } catch (\Exception $e) { |
|
110 | + return $controller->send_response($e); |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
@@ -119,40 +119,40 @@ discard block |
||
119 | 119 | * @param \WP_REST_Request $request |
120 | 120 | * @return \WP_REST_Response|\WP_Error |
121 | 121 | */ |
122 | - public static function handle_request_get_related( \WP_REST_Request $request ) { |
|
122 | + public static function handle_request_get_related(\WP_REST_Request $request) { |
|
123 | 123 | $controller = new Read(); |
124 | - try{ |
|
124 | + try { |
|
125 | 125 | $matches = $controller->parse_route( |
126 | 126 | $request->get_route(), |
127 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
128 | - array( 'version', 'model', 'id', 'related_model' ) |
|
127 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~', |
|
128 | + array('version', 'model', 'id', 'related_model') |
|
129 | 129 | ); |
130 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
131 | - $main_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
132 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $main_model_name_singular ) ) { |
|
130 | + $controller->set_requested_version($matches['version']); |
|
131 | + $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
132 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
133 | 133 | return $controller->send_response( |
134 | 134 | new \WP_Error( |
135 | 135 | 'endpoint_parsing_error', |
136 | 136 | sprintf( |
137 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
137 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
138 | 138 | $main_model_name_singular |
139 | 139 | ) |
140 | 140 | ) |
141 | 141 | ); |
142 | 142 | } |
143 | - $main_model = $controller->get_model_version_info()->load_model( $main_model_name_singular ); |
|
143 | + $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
|
144 | 144 | //assume the related model name is plural and try to find the model's name |
145 | - $related_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'related_model' ] ); |
|
146 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
145 | + $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
|
146 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
147 | 147 | //so the word didn't singularize well. Maybe that's just because it's a singular word? |
148 | - $related_model_name_singular = \EEH_Inflector::humanize( $matches[ 'related_model' ] ); |
|
148 | + $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); |
|
149 | 149 | } |
150 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
150 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
151 | 151 | return $controller->send_response( |
152 | 152 | new \WP_Error( |
153 | 153 | 'endpoint_parsing_error', |
154 | 154 | sprintf( |
155 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
155 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
156 | 156 | $related_model_name_singular |
157 | 157 | ) |
158 | 158 | ) |
@@ -161,13 +161,13 @@ discard block |
||
161 | 161 | |
162 | 162 | return $controller->send_response( |
163 | 163 | $controller->get_entities_from_relation( |
164 | - $request->get_param( 'id' ), |
|
165 | - $main_model->related_settings_for( $related_model_name_singular ) , |
|
164 | + $request->get_param('id'), |
|
165 | + $main_model->related_settings_for($related_model_name_singular), |
|
166 | 166 | $request |
167 | 167 | ) |
168 | 168 | ); |
169 | - } catch( \Exception $e ) { |
|
170 | - return $controller->send_response( $e ); |
|
169 | + } catch (\Exception $e) { |
|
170 | + return $controller->send_response($e); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
@@ -180,27 +180,27 @@ discard block |
||
180 | 180 | * @param \WP_REST_Request $request |
181 | 181 | * @return array |
182 | 182 | */ |
183 | - public function get_entities_from_model( $model, $request) { |
|
184 | - $query_params = $this->create_model_query_params( $model, $request->get_params() ); |
|
185 | - if( ! Capabilities::current_user_has_partial_access_to( $model, $query_params[ 'caps' ] ) ) { |
|
186 | - $model_name_plural = \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ); |
|
183 | + public function get_entities_from_model($model, $request) { |
|
184 | + $query_params = $this->create_model_query_params($model, $request->get_params()); |
|
185 | + if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
186 | + $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
187 | 187 | return new \WP_Error( |
188 | - sprintf( 'rest_%s_cannot_list', $model_name_plural ), |
|
188 | + sprintf('rest_%s_cannot_list', $model_name_plural), |
|
189 | 189 | sprintf( |
190 | - __( 'Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso' ), |
|
190 | + __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'), |
|
191 | 191 | $model_name_plural, |
192 | - Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) |
|
192 | + Capabilities::get_missing_permissions_string($model, $query_params['caps']) |
|
193 | 193 | ), |
194 | - array( 'status' => 403 ) |
|
194 | + array('status' => 403) |
|
195 | 195 | ); |
196 | 196 | } |
197 | 197 | |
198 | - $this->_set_headers_from_query_params( $model, $query_params ); |
|
198 | + $this->_set_headers_from_query_params($model, $query_params); |
|
199 | 199 | /** @type array $results */ |
200 | - $results = $model->get_all_wpdb_results( $query_params ); |
|
200 | + $results = $model->get_all_wpdb_results($query_params); |
|
201 | 201 | $nice_results = array( ); |
202 | - foreach ( $results as $result ) { |
|
203 | - $nice_results[ ] = $this->create_entity_from_wpdb_result( |
|
202 | + foreach ($results as $result) { |
|
203 | + $nice_results[] = $this->create_entity_from_wpdb_result( |
|
204 | 204 | $model, |
205 | 205 | $result, |
206 | 206 | $request |
@@ -221,62 +221,62 @@ discard block |
||
221 | 221 | * @param \WP_REST_Request $request |
222 | 222 | * @return array |
223 | 223 | */ |
224 | - public function get_entities_from_relation( $id, $relation, $request ) { |
|
225 | - $context = $this->validate_context( $request->get_param( 'caps' )); |
|
224 | + public function get_entities_from_relation($id, $relation, $request) { |
|
225 | + $context = $this->validate_context($request->get_param('caps')); |
|
226 | 226 | $model = $relation->get_this_model(); |
227 | 227 | $related_model = $relation->get_other_model(); |
228 | 228 | //check if they can access the 1st model object |
229 | - $query_params = array( array( $model->primary_key_name() => $id ),'limit' => 1 ); |
|
230 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
229 | + $query_params = array(array($model->primary_key_name() => $id), 'limit' => 1); |
|
230 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
231 | 231 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
232 | 232 | } |
233 | 233 | $restricted_query_params = $query_params; |
234 | - $restricted_query_params[ 'caps' ] = $context; |
|
235 | - $this->_set_debug_info( 'main model query params', $restricted_query_params ); |
|
236 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $related_model, $context ) ); |
|
234 | + $restricted_query_params['caps'] = $context; |
|
235 | + $this->_set_debug_info('main model query params', $restricted_query_params); |
|
236 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context)); |
|
237 | 237 | |
238 | - if( |
|
238 | + if ( |
|
239 | 239 | ! ( |
240 | - Capabilities::current_user_has_partial_access_to( $related_model, $context ) |
|
241 | - && $model->exists( $restricted_query_params ) |
|
240 | + Capabilities::current_user_has_partial_access_to($related_model, $context) |
|
241 | + && $model->exists($restricted_query_params) |
|
242 | 242 | ) |
243 | - ){ |
|
244 | - if( $relation instanceof \EE_Belongs_To_Relation ) { |
|
245 | - $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
|
246 | - }else{ |
|
247 | - $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
|
243 | + ) { |
|
244 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
245 | + $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name()); |
|
246 | + } else { |
|
247 | + $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name()); |
|
248 | 248 | } |
249 | 249 | return new \WP_Error( |
250 | - sprintf( 'rest_%s_cannot_list', $related_model_name_maybe_plural ), |
|
250 | + sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), |
|
251 | 251 | sprintf( |
252 | - __( 'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso' ), |
|
252 | + __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso'), |
|
253 | 253 | $related_model_name_maybe_plural, |
254 | 254 | $relation->get_this_model()->get_this_model_name(), |
255 | 255 | implode( |
256 | 256 | ',', |
257 | 257 | array_keys( |
258 | - Capabilities::get_missing_permissions( $related_model, $context ) |
|
258 | + Capabilities::get_missing_permissions($related_model, $context) |
|
259 | 259 | ) |
260 | 260 | ) |
261 | 261 | ), |
262 | - array( 'status' => 403 ) |
|
262 | + array('status' => 403) |
|
263 | 263 | ); |
264 | 264 | } |
265 | - $query_params = $this->create_model_query_params( $relation->get_other_model(), $request->get_params() ); |
|
266 | - $query_params[0][ $relation->get_this_model()->get_this_model_name() . '.' . $relation->get_this_model()->primary_key_name() ] = $id; |
|
267 | - $query_params[ 'default_where_conditions' ] = 'none'; |
|
268 | - $query_params[ 'caps' ] = $context; |
|
269 | - $this->_set_headers_from_query_params( $relation->get_other_model(), $query_params ); |
|
265 | + $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params()); |
|
266 | + $query_params[0][$relation->get_this_model()->get_this_model_name().'.'.$relation->get_this_model()->primary_key_name()] = $id; |
|
267 | + $query_params['default_where_conditions'] = 'none'; |
|
268 | + $query_params['caps'] = $context; |
|
269 | + $this->_set_headers_from_query_params($relation->get_other_model(), $query_params); |
|
270 | 270 | /** @type array $results */ |
271 | - $results = $relation->get_other_model()->get_all_wpdb_results( $query_params ); |
|
271 | + $results = $relation->get_other_model()->get_all_wpdb_results($query_params); |
|
272 | 272 | $nice_results = array(); |
273 | - foreach( $results as $result ) { |
|
273 | + foreach ($results as $result) { |
|
274 | 274 | $nice_result = $this->create_entity_from_wpdb_result( |
275 | 275 | $relation->get_other_model(), |
276 | 276 | $result, |
277 | 277 | $request |
278 | 278 | ); |
279 | - if( $relation instanceof \EE_HABTM_Relation ) { |
|
279 | + if ($relation instanceof \EE_HABTM_Relation) { |
|
280 | 280 | //put the unusual stuff (properties from the HABTM relation) first, and make sure |
281 | 281 | //if there are conflicts we prefer the properties from the main model |
282 | 282 | $join_model_result = $this->create_entity_from_wpdb_result( |
@@ -284,18 +284,18 @@ discard block |
||
284 | 284 | $result, |
285 | 285 | $request |
286 | 286 | ); |
287 | - $joined_result = array_merge( $nice_result, $join_model_result ); |
|
287 | + $joined_result = array_merge($nice_result, $join_model_result); |
|
288 | 288 | //but keep the meta stuff from the main model |
289 | - if( isset( $nice_result['meta'] ) ){ |
|
289 | + if (isset($nice_result['meta'])) { |
|
290 | 290 | $joined_result['meta'] = $nice_result['meta']; |
291 | 291 | } |
292 | 292 | $nice_result = $joined_result; |
293 | 293 | } |
294 | 294 | $nice_results[] = $nice_result; |
295 | 295 | } |
296 | - if( $relation instanceof \EE_Belongs_To_Relation ){ |
|
297 | - return array_shift( $nice_results ); |
|
298 | - }else{ |
|
296 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
297 | + return array_shift($nice_results); |
|
298 | + } else { |
|
299 | 299 | return $nice_results; |
300 | 300 | } |
301 | 301 | } |
@@ -307,32 +307,32 @@ discard block |
||
307 | 307 | * @param array $query_params |
308 | 308 | * @return void |
309 | 309 | */ |
310 | - protected function _set_headers_from_query_params( $model, $query_params ) { |
|
311 | - $this->_set_debug_info( 'model query params', $query_params ); |
|
312 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) ); |
|
310 | + protected function _set_headers_from_query_params($model, $query_params) { |
|
311 | + $this->_set_debug_info('model query params', $query_params); |
|
312 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($model, $query_params['caps'])); |
|
313 | 313 | //normally the limit to a 2-part array, where the 2nd item is the limit |
314 | - if( ! isset( $query_params[ 'limit' ] ) ) { |
|
315 | - $query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
314 | + if ( ! isset($query_params['limit'])) { |
|
315 | + $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
316 | 316 | } |
317 | - if( is_array( $query_params[ 'limit' ] ) ) { |
|
318 | - $limit_parts = $query_params[ 'limit' ]; |
|
317 | + if (is_array($query_params['limit'])) { |
|
318 | + $limit_parts = $query_params['limit']; |
|
319 | 319 | } else { |
320 | - $limit_parts = explode(',', $query_params[ 'limit' ] ); |
|
321 | - if( count( $limit_parts ) == 1 ){ |
|
322 | - $limit_parts = array(0, $limit_parts[ 0 ] ); |
|
320 | + $limit_parts = explode(',', $query_params['limit']); |
|
321 | + if (count($limit_parts) == 1) { |
|
322 | + $limit_parts = array(0, $limit_parts[0]); |
|
323 | 323 | } |
324 | 324 | } |
325 | 325 | //remove the group by and having parts of the query, as those will |
326 | 326 | //make the sql query return an array of values, instead of just a single value |
327 | - unset( $query_params[ 'group_by' ] ); |
|
328 | - unset( $query_params[ 'having' ] ); |
|
329 | - unset( $query_params[ 'limit' ] ); |
|
330 | - $count = $model->count( $query_params, null, true ); |
|
331 | - |
|
332 | - $pages = $count / $limit_parts[ 1 ]; |
|
333 | - $this->_set_response_header( 'Total', $count, false ); |
|
334 | - $this->_set_response_header( 'PageSize', $limit_parts[ 1 ], false ); |
|
335 | - $this->_set_response_header( 'TotalPages', ceil( $pages ), false ); |
|
327 | + unset($query_params['group_by']); |
|
328 | + unset($query_params['having']); |
|
329 | + unset($query_params['limit']); |
|
330 | + $count = $model->count($query_params, null, true); |
|
331 | + |
|
332 | + $pages = $count / $limit_parts[1]; |
|
333 | + $this->_set_response_header('Total', $count, false); |
|
334 | + $this->_set_response_header('PageSize', $limit_parts[1], false); |
|
335 | + $this->_set_response_header('TotalPages', ceil($pages), false); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | |
@@ -345,47 +345,47 @@ discard block |
||
345 | 345 | * @param string $deprecated no longer used |
346 | 346 | * @return array ready for being converted into json for sending to client |
347 | 347 | */ |
348 | - public function create_entity_from_wpdb_result( $model, $db_row, $rest_request, $deprecated = null ) { |
|
349 | - if( ! $rest_request instanceof \WP_REST_Request ) { |
|
348 | + public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) { |
|
349 | + if ( ! $rest_request instanceof \WP_REST_Request) { |
|
350 | 350 | //ok so this was called in the old style, where the 3rd arg was |
351 | 351 | //$include, and the 4th arg was $context |
352 | 352 | //now setup the request just to avoid fatal errors, although we won't be able |
353 | 353 | //to truly make use of it because it's kinda devoid of info |
354 | 354 | $rest_request = new \WP_REST_Request(); |
355 | - $rest_request->set_param( 'include', $rest_request ); |
|
356 | - $rest_request->set_param( 'caps', $deprecated ); |
|
355 | + $rest_request->set_param('include', $rest_request); |
|
356 | + $rest_request->set_param('caps', $deprecated); |
|
357 | 357 | } |
358 | - if( $rest_request->get_param( 'caps' ) == null ) { |
|
359 | - $rest_request->set_param( 'caps', \EEM_Base::caps_read ); |
|
358 | + if ($rest_request->get_param('caps') == null) { |
|
359 | + $rest_request->set_param('caps', \EEM_Base::caps_read); |
|
360 | 360 | } |
361 | - $entity_array = $this->_create_bare_entity_from_wpdb_results( $model, $db_row ); |
|
362 | - $entity_array = $this->_add_extra_fields( $model, $db_row, $entity_array ); |
|
363 | - $entity_array[ '_links' ] = $this->_get_entity_links( $model, $db_row, $entity_array ); |
|
364 | - $entity_array[ '_calculated_fields'] = $this->_get_entity_calculations( $model, $db_row, $rest_request ); |
|
365 | - $entity_array = $this->_include_requested_models( $model, $rest_request, $entity_array ); |
|
361 | + $entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row); |
|
362 | + $entity_array = $this->_add_extra_fields($model, $db_row, $entity_array); |
|
363 | + $entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array); |
|
364 | + $entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request); |
|
365 | + $entity_array = $this->_include_requested_models($model, $rest_request, $entity_array); |
|
366 | 366 | $entity_array = apply_filters( |
367 | 367 | 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
368 | 368 | $entity_array, |
369 | 369 | $model, |
370 | - $rest_request->get_param( 'caps' ), |
|
370 | + $rest_request->get_param('caps'), |
|
371 | 371 | $rest_request, |
372 | 372 | $this |
373 | 373 | ); |
374 | 374 | $result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields( |
375 | 375 | $entity_array, |
376 | 376 | $model, |
377 | - $rest_request->get_param( 'caps' ), |
|
377 | + $rest_request->get_param('caps'), |
|
378 | 378 | $this->get_model_version_info() |
379 | 379 | ); |
380 | 380 | $this->_set_debug_info( |
381 | 381 | 'inaccessible fields', |
382 | - array_keys( array_diff_key( $entity_array, $result_without_inaccessible_fields ) ) |
|
382 | + array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields)) |
|
383 | 383 | ); |
384 | 384 | return apply_filters( |
385 | 385 | 'FHEE__Read__create_entity_from_wpdb_results__entity_return', |
386 | 386 | $result_without_inaccessible_fields, |
387 | 387 | $model, |
388 | - $rest_request->get_param( 'caps' ) |
|
388 | + $rest_request->get_param('caps') |
|
389 | 389 | ); |
390 | 390 | } |
391 | 391 | |
@@ -397,38 +397,38 @@ discard block |
||
397 | 397 | * @param array $db_row |
398 | 398 | * @return array entity mostly ready for converting to JSON and sending in the response |
399 | 399 | */ |
400 | - protected function _create_bare_entity_from_wpdb_results( \EEM_Base $model, $db_row ) { |
|
401 | - $result = $model->deduce_fields_n_values_from_cols_n_values( $db_row ); |
|
402 | - $result = array_intersect_key( $result, $this->get_model_version_info()->fields_on_model_in_this_version( $model ) ); |
|
403 | - foreach( $result as $field_name => $raw_field_value ) { |
|
400 | + protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row) { |
|
401 | + $result = $model->deduce_fields_n_values_from_cols_n_values($db_row); |
|
402 | + $result = array_intersect_key($result, $this->get_model_version_info()->fields_on_model_in_this_version($model)); |
|
403 | + foreach ($result as $field_name => $raw_field_value) { |
|
404 | 404 | $field_obj = $model->field_settings_for($field_name); |
405 | - $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
|
406 | - if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
|
407 | - unset( $result[ $field_name ] ); |
|
408 | - }elseif( |
|
409 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
|
410 | - ){ |
|
411 | - $result[ $field_name ] = array( |
|
412 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
413 | - 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
405 | + $field_value = $field_obj->prepare_for_set_from_db($raw_field_value); |
|
406 | + if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) { |
|
407 | + unset($result[$field_name]); |
|
408 | + }elseif ( |
|
409 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format()) |
|
410 | + ) { |
|
411 | + $result[$field_name] = array( |
|
412 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
413 | + 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
414 | 414 | ); |
415 | - }elseif( |
|
416 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
|
417 | - ){ |
|
418 | - $result[ $field_name ] = array( |
|
419 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
420 | - 'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
415 | + }elseif ( |
|
416 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format()) |
|
417 | + ) { |
|
418 | + $result[$field_name] = array( |
|
419 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
420 | + 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
421 | 421 | ); |
422 | - } elseif ( $field_obj instanceof \EE_Datetime_Field ) { |
|
423 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
422 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
423 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
424 | 424 | $field_obj, |
425 | 425 | $field_value, |
426 | 426 | $this->get_model_version_info()->requested_version() |
427 | 427 | ); |
428 | 428 | } else { |
429 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
429 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
430 | 430 | $field_obj, |
431 | - $field_obj->prepare_for_get( $field_value ), |
|
431 | + $field_obj->prepare_for_get($field_value), |
|
432 | 432 | $this->get_model_version_info()->requested_version() |
433 | 433 | ); |
434 | 434 | } |
@@ -443,9 +443,9 @@ discard block |
||
443 | 443 | * @param array $entity_array |
444 | 444 | * @return array modified entity |
445 | 445 | */ |
446 | - protected function _add_extra_fields( \EEM_Base $model, $db_row, $entity_array ) { |
|
447 | - if( $model instanceof \EEM_CPT_Base ) { |
|
448 | - $entity_array[ 'link' ] = get_permalink( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ); |
|
446 | + protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array) { |
|
447 | + if ($model instanceof \EEM_CPT_Base) { |
|
448 | + $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]); |
|
449 | 449 | } |
450 | 450 | return $entity_array; |
451 | 451 | } |
@@ -459,20 +459,20 @@ discard block |
||
459 | 459 | * @param array $entity_array |
460 | 460 | * @return array the _links item in the entity |
461 | 461 | */ |
462 | - protected function _get_entity_links( $model, $db_row, $entity_array ) { |
|
462 | + protected function _get_entity_links($model, $db_row, $entity_array) { |
|
463 | 463 | //add basic links |
464 | 464 | $links = array( |
465 | 465 | 'self' => array( |
466 | 466 | array( |
467 | 467 | 'href' => $this->get_versioned_link_to( |
468 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] |
|
468 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()] |
|
469 | 469 | ) |
470 | 470 | ) |
471 | 471 | ), |
472 | 472 | 'collection' => array( |
473 | 473 | array( |
474 | 474 | 'href' => $this->get_versioned_link_to( |
475 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) |
|
475 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
476 | 476 | ) |
477 | 477 | ) |
478 | 478 | ), |
@@ -480,24 +480,24 @@ discard block |
||
480 | 480 | |
481 | 481 | //add link to the wp core endpoint, if wp api is active |
482 | 482 | global $wp_rest_server; |
483 | - if( $model instanceof \EEM_CPT_Base && |
|
483 | + if ($model instanceof \EEM_CPT_Base && |
|
484 | 484 | $wp_rest_server instanceof \WP_REST_Server && |
485 | - $wp_rest_server->get_route_options( '/wp/v2/posts' ) ) { |
|
486 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . 'self_wp_post' ] = array( |
|
485 | + $wp_rest_server->get_route_options('/wp/v2/posts')) { |
|
486 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.'self_wp_post'] = array( |
|
487 | 487 | array( |
488 | - 'href' => rest_url( '/wp/v2/posts/' . $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ), |
|
488 | + 'href' => rest_url('/wp/v2/posts/'.$db_row[$model->get_primary_key_field()->get_qualified_column()]), |
|
489 | 489 | 'single' => true |
490 | 490 | ) |
491 | 491 | ); |
492 | 492 | } |
493 | 493 | |
494 | 494 | //add links to related models |
495 | - foreach( $this->get_model_version_info()->relation_settings( $model ) as $relation_name => $relation_obj ) { |
|
496 | - $related_model_part = $this->get_related_entity_name( $relation_name, $relation_obj ); |
|
497 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array( |
|
495 | + foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) { |
|
496 | + $related_model_part = $this->get_related_entity_name($relation_name, $relation_obj); |
|
497 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.$related_model_part] = array( |
|
498 | 498 | array( |
499 | 499 | 'href' => $this->get_versioned_link_to( |
500 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] . '/' . $related_model_part |
|
500 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()].'/'.$related_model_part |
|
501 | 501 | ), |
502 | 502 | 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false |
503 | 503 | ) |
@@ -513,50 +513,50 @@ discard block |
||
513 | 513 | * @param array $entity_array |
514 | 514 | * @return array the modified entity |
515 | 515 | */ |
516 | - protected function _include_requested_models( \EEM_Base $model, \WP_REST_Request $rest_request, $entity_array ) { |
|
517 | - $includes_for_this_model = $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'include' ), '' ); |
|
518 | - $includes_for_this_model = $this->_remove_model_names_from_array( $includes_for_this_model ); |
|
516 | + protected function _include_requested_models(\EEM_Base $model, \WP_REST_Request $rest_request, $entity_array) { |
|
517 | + $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), ''); |
|
518 | + $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model); |
|
519 | 519 | //if they passed in * or didn't specify any includes, return everything |
520 | - if( ! in_array( '*', $includes_for_this_model ) |
|
521 | - && ! empty( $includes_for_this_model ) ) { |
|
522 | - if( $model->has_primary_key_field() ) { |
|
520 | + if ( ! in_array('*', $includes_for_this_model) |
|
521 | + && ! empty($includes_for_this_model)) { |
|
522 | + if ($model->has_primary_key_field()) { |
|
523 | 523 | //always include the primary key. ya just gotta know that at least |
524 | 524 | $includes_for_this_model[] = $model->primary_key_name(); |
525 | 525 | } |
526 | - if( $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'calculate' ), '' ) ) { |
|
526 | + if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) { |
|
527 | 527 | $includes_for_this_model[] = '_calculated_fields'; |
528 | 528 | } |
529 | - $entity_array = array_intersect_key( $entity_array, array_flip( $includes_for_this_model ) ); |
|
529 | + $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model)); |
|
530 | 530 | } |
531 | - $relation_settings = $this->get_model_version_info()->relation_settings( $model ); |
|
532 | - foreach( $relation_settings as $relation_name => $relation_obj ) { |
|
531 | + $relation_settings = $this->get_model_version_info()->relation_settings($model); |
|
532 | + foreach ($relation_settings as $relation_name => $relation_obj) { |
|
533 | 533 | $related_fields_to_include = $this->explode_and_get_items_prefixed_with( |
534 | - $rest_request->get_param( 'include' ), |
|
534 | + $rest_request->get_param('include'), |
|
535 | 535 | $relation_name |
536 | 536 | ); |
537 | 537 | $related_fields_to_calculate = $this->explode_and_get_items_prefixed_with( |
538 | - $rest_request->get_param( 'calculate' ), |
|
538 | + $rest_request->get_param('calculate'), |
|
539 | 539 | $relation_name |
540 | 540 | ); |
541 | 541 | //did they specify they wanted to include a related model, or |
542 | 542 | //specific fields from a related model? |
543 | 543 | //or did they specify to calculate a field from a related model? |
544 | - if( $related_fields_to_include || $related_fields_to_calculate ) { |
|
544 | + if ($related_fields_to_include || $related_fields_to_calculate) { |
|
545 | 545 | //if so, we should include at least some part of the related model |
546 | 546 | $pretend_related_request = new \WP_REST_Request(); |
547 | 547 | $pretend_related_request->set_query_params( |
548 | 548 | array( |
549 | - 'caps' => $rest_request->get_param( 'caps' ), |
|
549 | + 'caps' => $rest_request->get_param('caps'), |
|
550 | 550 | 'include' => $related_fields_to_include, |
551 | 551 | 'calculate' => $related_fields_to_calculate, |
552 | 552 | ) |
553 | 553 | ); |
554 | 554 | $related_results = $this->get_entities_from_relation( |
555 | - $entity_array[ $model->primary_key_name() ], |
|
555 | + $entity_array[$model->primary_key_name()], |
|
556 | 556 | $relation_obj, |
557 | 557 | $pretend_related_request |
558 | 558 | ); |
559 | - $entity_array[ $this->get_related_entity_name( $relation_name, $relation_obj ) ] = $related_results instanceof \WP_Error ? null : $related_results; |
|
559 | + $entity_array[$this->get_related_entity_name($relation_name, $relation_obj)] = $related_results instanceof \WP_Error ? null : $related_results; |
|
560 | 560 | } |
561 | 561 | } |
562 | 562 | return $entity_array; |
@@ -568,8 +568,8 @@ discard block |
||
568 | 568 | * @param array $arr |
569 | 569 | * @return array |
570 | 570 | */ |
571 | - private function _remove_model_names_from_array( $arr ) { |
|
572 | - return array_diff( $arr, array_keys( \EE_Registry::instance()->non_abstract_db_models ) ); |
|
571 | + private function _remove_model_names_from_array($arr) { |
|
572 | + return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models)); |
|
573 | 573 | } |
574 | 574 | /** |
575 | 575 | * Gets the calculated fields for the response |
@@ -579,16 +579,16 @@ discard block |
||
579 | 579 | * @param \WP_REST_Request $rest_request |
580 | 580 | * @return array the _calculations item in the entity |
581 | 581 | */ |
582 | - protected function _get_entity_calculations( $model, $wpdb_row, $rest_request ) { |
|
582 | + protected function _get_entity_calculations($model, $wpdb_row, $rest_request) { |
|
583 | 583 | $calculated_fields = $this->explode_and_get_items_prefixed_with( |
584 | - $rest_request->get_param( 'calculate' ), |
|
584 | + $rest_request->get_param('calculate'), |
|
585 | 585 | '' |
586 | 586 | ); |
587 | 587 | //note: setting calculate=* doesn't do anything |
588 | 588 | $calculated_fields_to_return = array(); |
589 | - foreach( $calculated_fields as $field_to_calculate ) { |
|
590 | - try{ |
|
591 | - $calculated_fields_to_return[ $field_to_calculate ] = Model_Data_Translator::prepare_field_value_for_json( |
|
589 | + foreach ($calculated_fields as $field_to_calculate) { |
|
590 | + try { |
|
591 | + $calculated_fields_to_return[$field_to_calculate] = Model_Data_Translator::prepare_field_value_for_json( |
|
592 | 592 | null, |
593 | 593 | $this->_fields_calculator->retrieve_calculated_field_value( |
594 | 594 | $model, |
@@ -599,10 +599,10 @@ discard block |
||
599 | 599 | ), |
600 | 600 | $this->get_model_version_info()->requested_version() |
601 | 601 | ); |
602 | - } catch( Rest_Exception $e ) { |
|
602 | + } catch (Rest_Exception $e) { |
|
603 | 603 | //if we don't have permission to read it, just leave it out. but let devs know about the problem |
604 | 604 | $this->_set_response_header( |
605 | - 'Notices-Field-Calculation-Errors[' . $e->get_string_code() . '][' . $model->get_this_model_name() . '][' . $field_to_calculate . ']', |
|
605 | + 'Notices-Field-Calculation-Errors['.$e->get_string_code().']['.$model->get_this_model_name().']['.$field_to_calculate.']', |
|
606 | 606 | $e->getMessage(), |
607 | 607 | true |
608 | 608 | ); |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | * @param string $link_part_after_version_and_slash eg "events/10/datetimes" |
617 | 617 | * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes" |
618 | 618 | */ |
619 | - public function get_versioned_link_to( $link_part_after_version_and_slash ) { |
|
619 | + public function get_versioned_link_to($link_part_after_version_and_slash) { |
|
620 | 620 | return rest_url( |
621 | 621 | \EED_Core_Rest_Api::ee_api_namespace |
622 | 622 | . $this->get_model_version_info()->requested_version() |
@@ -632,11 +632,11 @@ discard block |
||
632 | 632 | * @param \EE_Model_Relation_Base $relation_obj |
633 | 633 | * @return string |
634 | 634 | */ |
635 | - public static function get_related_entity_name( $relation_name, $relation_obj ){ |
|
636 | - if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
|
637 | - return strtolower( $relation_name ); |
|
638 | - }else{ |
|
639 | - return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
|
635 | + public static function get_related_entity_name($relation_name, $relation_obj) { |
|
636 | + if ($relation_obj instanceof \EE_Belongs_To_Relation) { |
|
637 | + return strtolower($relation_name); |
|
638 | + } else { |
|
639 | + return \EEH_Inflector::pluralize_and_lower($relation_name); |
|
640 | 640 | } |
641 | 641 | } |
642 | 642 | |
@@ -649,43 +649,43 @@ discard block |
||
649 | 649 | * @param \WP_REST_Request $request |
650 | 650 | * @return array |
651 | 651 | */ |
652 | - public function get_entity_from_model( $model, $request ) { |
|
653 | - $query_params = array( array( $model->primary_key_name() => $request->get_param( 'id' ) ),'limit' => 1); |
|
654 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
652 | + public function get_entity_from_model($model, $request) { |
|
653 | + $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1); |
|
654 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
655 | 655 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
656 | 656 | } |
657 | 657 | $restricted_query_params = $query_params; |
658 | - $restricted_query_params[ 'caps' ] = $this->validate_context( $request->get_param( 'caps' ) ); |
|
659 | - $this->_set_debug_info( 'model query params', $restricted_query_params ); |
|
660 | - $model_rows = $model->get_all_wpdb_results( $restricted_query_params ); |
|
661 | - if ( ! empty ( $model_rows ) ) { |
|
658 | + $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
|
659 | + $this->_set_debug_info('model query params', $restricted_query_params); |
|
660 | + $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
|
661 | + if ( ! empty ($model_rows)) { |
|
662 | 662 | return $this->create_entity_from_wpdb_result( |
663 | 663 | $model, |
664 | - array_shift( $model_rows ), |
|
664 | + array_shift($model_rows), |
|
665 | 665 | $request ); |
666 | 666 | } else { |
667 | 667 | //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
668 | - $lowercase_model_name = strtolower( $model->get_this_model_name() ); |
|
669 | - $model_rows_found_sans_restrictions = $model->get_all_wpdb_results( $query_params ); |
|
670 | - if( ! empty( $model_rows_found_sans_restrictions ) ) { |
|
668 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
669 | + $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
|
670 | + if ( ! empty($model_rows_found_sans_restrictions)) { |
|
671 | 671 | //you got shafted- it existed but we didn't want to tell you! |
672 | 672 | return new \WP_Error( |
673 | 673 | 'rest_user_cannot_read', |
674 | 674 | sprintf( |
675 | - __( 'Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso' ), |
|
676 | - strtolower( $model->get_this_model_name() ), |
|
675 | + __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), |
|
676 | + strtolower($model->get_this_model_name()), |
|
677 | 677 | Capabilities::get_missing_permissions_string( |
678 | 678 | $model, |
679 | - $this->validate_context( $request->get_param( 'caps' ) ) ) |
|
679 | + $this->validate_context($request->get_param('caps')) ) |
|
680 | 680 | ), |
681 | - array( 'status' => 403 ) |
|
681 | + array('status' => 403) |
|
682 | 682 | ); |
683 | 683 | } else { |
684 | 684 | //it's not you. It just doesn't exist |
685 | 685 | return new \WP_Error( |
686 | - sprintf( 'rest_%s_invalid_id', $lowercase_model_name ), |
|
687 | - sprintf( __( 'Invalid %s ID.', 'event_espresso' ), $lowercase_model_name ), |
|
688 | - array( 'status' => 404 ) |
|
686 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
687 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
688 | + array('status' => 404) |
|
689 | 689 | ); |
690 | 690 | } |
691 | 691 | } |
@@ -698,14 +698,14 @@ discard block |
||
698 | 698 | * @param string $context |
699 | 699 | * @return string array key of EEM_Base::cap_contexts_to_cap_action_map() |
700 | 700 | */ |
701 | - public function validate_context( $context ) { |
|
702 | - if( ! $context ) { |
|
701 | + public function validate_context($context) { |
|
702 | + if ( ! $context) { |
|
703 | 703 | $context = \EEM_Base::caps_read; |
704 | 704 | } |
705 | 705 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
706 | - if( in_array( $context, $valid_contexts ) ){ |
|
706 | + if (in_array($context, $valid_contexts)) { |
|
707 | 707 | return $context; |
708 | - }else{ |
|
708 | + } else { |
|
709 | 709 | return \EEM_Base::caps_read; |
710 | 710 | } |
711 | 711 | } |
@@ -724,77 +724,77 @@ discard block |
||
724 | 724 | * that absolutely no results should be returned |
725 | 725 | * @throws \EE_Error |
726 | 726 | */ |
727 | - public function create_model_query_params( $model, $query_parameters ) { |
|
727 | + public function create_model_query_params($model, $query_parameters) { |
|
728 | 728 | $model_query_params = array( ); |
729 | - if ( isset( $query_parameters[ 'where' ] ) ) { |
|
730 | - $model_query_params[ 0 ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
731 | - $query_parameters[ 'where' ], |
|
729 | + if (isset($query_parameters['where'])) { |
|
730 | + $model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
731 | + $query_parameters['where'], |
|
732 | 732 | $model, |
733 | 733 | $this->get_model_version_info()->requested_version() |
734 | 734 | ); |
735 | 735 | } |
736 | - if ( isset( $query_parameters[ 'order_by' ] ) ) { |
|
737 | - $order_by = $query_parameters[ 'order_by' ]; |
|
738 | - } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
|
739 | - $order_by = $query_parameters[ 'orderby' ]; |
|
740 | - }else{ |
|
736 | + if (isset($query_parameters['order_by'])) { |
|
737 | + $order_by = $query_parameters['order_by']; |
|
738 | + } elseif (isset($query_parameters['orderby'])) { |
|
739 | + $order_by = $query_parameters['orderby']; |
|
740 | + } else { |
|
741 | 741 | $order_by = null; |
742 | 742 | } |
743 | - if( $order_by !== null ){ |
|
744 | - $model_query_params[ 'order_by' ] = $order_by; |
|
743 | + if ($order_by !== null) { |
|
744 | + $model_query_params['order_by'] = $order_by; |
|
745 | 745 | } |
746 | - if ( isset( $query_parameters[ 'group_by' ] ) ) { |
|
747 | - $group_by = $query_parameters[ 'group_by' ]; |
|
748 | - } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
|
749 | - $group_by = $query_parameters[ 'groupby' ]; |
|
750 | - }else{ |
|
746 | + if (isset($query_parameters['group_by'])) { |
|
747 | + $group_by = $query_parameters['group_by']; |
|
748 | + } elseif (isset($query_parameters['groupby'])) { |
|
749 | + $group_by = $query_parameters['groupby']; |
|
750 | + } else { |
|
751 | 751 | $group_by = null; |
752 | 752 | } |
753 | - if( $group_by !== null ){ |
|
754 | - $model_query_params[ 'group_by' ] = $group_by; |
|
753 | + if ($group_by !== null) { |
|
754 | + $model_query_params['group_by'] = $group_by; |
|
755 | 755 | } |
756 | - if ( isset( $query_parameters[ 'having' ] ) ) { |
|
757 | - $model_query_params[ 'having' ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
758 | - $query_parameters[ 'having' ], |
|
756 | + if (isset($query_parameters['having'])) { |
|
757 | + $model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
758 | + $query_parameters['having'], |
|
759 | 759 | $model, |
760 | 760 | $this->get_model_version_info()->requested_version() |
761 | 761 | ); |
762 | 762 | } |
763 | - if ( isset( $query_parameters[ 'order' ] ) ) { |
|
764 | - $model_query_params[ 'order' ] = $query_parameters[ 'order' ]; |
|
763 | + if (isset($query_parameters['order'])) { |
|
764 | + $model_query_params['order'] = $query_parameters['order']; |
|
765 | 765 | } |
766 | - if ( isset( $query_parameters[ 'mine' ] ) ){ |
|
767 | - $model_query_params = $model->alter_query_params_to_only_include_mine( $model_query_params ); |
|
766 | + if (isset($query_parameters['mine'])) { |
|
767 | + $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params); |
|
768 | 768 | } |
769 | - if( isset( $query_parameters[ 'limit' ] ) ) { |
|
769 | + if (isset($query_parameters['limit'])) { |
|
770 | 770 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
771 | - if( ! is_array( $query_parameters[ 'limit' ] ) ) { |
|
772 | - $limit_array = explode(',', (string)$query_parameters['limit']); |
|
773 | - }else { |
|
774 | - $limit_array = $query_parameters[ 'limit' ]; |
|
771 | + if ( ! is_array($query_parameters['limit'])) { |
|
772 | + $limit_array = explode(',', (string) $query_parameters['limit']); |
|
773 | + } else { |
|
774 | + $limit_array = $query_parameters['limit']; |
|
775 | 775 | } |
776 | 776 | $sanitized_limit = array(); |
777 | - foreach( $limit_array as $key => $limit_part ) { |
|
778 | - if( $this->_debug_mode && ( ! is_numeric( $limit_part ) || count( $sanitized_limit ) > 2 ) ) { |
|
777 | + foreach ($limit_array as $key => $limit_part) { |
|
778 | + if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
779 | 779 | throw new \EE_Error( |
780 | 780 | sprintf( |
781 | - __( 'An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso' ), |
|
782 | - json_encode( $query_parameters[ 'limit' ] ) |
|
781 | + __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso'), |
|
782 | + json_encode($query_parameters['limit']) |
|
783 | 783 | ) |
784 | 784 | ); |
785 | 785 | } |
786 | - $sanitized_limit[] = intval( $limit_part ); |
|
786 | + $sanitized_limit[] = intval($limit_part); |
|
787 | 787 | } |
788 | - $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
|
789 | - }else{ |
|
790 | - $model_query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
788 | + $model_query_params['limit'] = implode(',', $sanitized_limit); |
|
789 | + } else { |
|
790 | + $model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
791 | 791 | } |
792 | - if( isset( $query_parameters[ 'caps' ] ) ) { |
|
793 | - $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
|
794 | - }else{ |
|
795 | - $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
|
792 | + if (isset($query_parameters['caps'])) { |
|
793 | + $model_query_params['caps'] = $this->validate_context($query_parameters['caps']); |
|
794 | + } else { |
|
795 | + $model_query_params['caps'] = \EEM_Base::caps_read; |
|
796 | 796 | } |
797 | - return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
|
797 | + return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model); |
|
798 | 798 | } |
799 | 799 | |
800 | 800 | |
@@ -806,13 +806,13 @@ discard block |
||
806 | 806 | * @param array $query_params sub-array from @see EEM_Base::get_all() |
807 | 807 | * @return array |
808 | 808 | */ |
809 | - public function prepare_rest_query_params_key_for_models( $model, $query_params ) { |
|
809 | + public function prepare_rest_query_params_key_for_models($model, $query_params) { |
|
810 | 810 | $model_ready_query_params = array(); |
811 | - foreach( $query_params as $key => $value ) { |
|
812 | - if( is_array( $value ) ) { |
|
813 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
|
814 | - }else{ |
|
815 | - $model_ready_query_params[ $key ] = $value; |
|
811 | + foreach ($query_params as $key => $value) { |
|
812 | + if (is_array($value)) { |
|
813 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value); |
|
814 | + } else { |
|
815 | + $model_ready_query_params[$key] = $value; |
|
816 | 816 | } |
817 | 817 | } |
818 | 818 | return $model_ready_query_params; |
@@ -826,13 +826,13 @@ discard block |
||
826 | 826 | * @param $query_params |
827 | 827 | * @return array |
828 | 828 | */ |
829 | - public function prepare_rest_query_params_values_for_models( $model, $query_params ) { |
|
829 | + public function prepare_rest_query_params_values_for_models($model, $query_params) { |
|
830 | 830 | $model_ready_query_params = array(); |
831 | - foreach( $query_params as $key => $value ) { |
|
832 | - if( is_array( $value ) ) { |
|
833 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_values_for_models( $model, $value ); |
|
831 | + foreach ($query_params as $key => $value) { |
|
832 | + if (is_array($value)) { |
|
833 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value); |
|
834 | 834 | } else { |
835 | - $model_ready_query_params[ $key ] = $value; |
|
835 | + $model_ready_query_params[$key] = $value; |
|
836 | 836 | } |
837 | 837 | } |
838 | 838 | return $model_ready_query_params; |
@@ -847,33 +847,33 @@ discard block |
||
847 | 847 | * we only return strings starting with that and a period; if no prefix was specified |
848 | 848 | * we return all items containing NO periods |
849 | 849 | */ |
850 | - public function explode_and_get_items_prefixed_with( $string_to_explode, $prefix ) { |
|
851 | - if( is_string( $string_to_explode ) ) { |
|
852 | - $exploded_contents = explode( ',', $string_to_explode ); |
|
853 | - } else if( is_array( $string_to_explode ) ) { |
|
850 | + public function explode_and_get_items_prefixed_with($string_to_explode, $prefix) { |
|
851 | + if (is_string($string_to_explode)) { |
|
852 | + $exploded_contents = explode(',', $string_to_explode); |
|
853 | + } else if (is_array($string_to_explode)) { |
|
854 | 854 | $exploded_contents = $string_to_explode; |
855 | 855 | } else { |
856 | 856 | $exploded_contents = array(); |
857 | 857 | } |
858 | 858 | //if the string was empty, we want an empty array |
859 | - $exploded_contents = array_filter( $exploded_contents ); |
|
859 | + $exploded_contents = array_filter($exploded_contents); |
|
860 | 860 | $contents_with_prefix = array(); |
861 | - foreach( $exploded_contents as $item ) { |
|
862 | - $item = trim( $item ); |
|
861 | + foreach ($exploded_contents as $item) { |
|
862 | + $item = trim($item); |
|
863 | 863 | //if no prefix was provided, so we look for items with no "." in them |
864 | - if( ! $prefix ) { |
|
864 | + if ( ! $prefix) { |
|
865 | 865 | //does this item have a period? |
866 | - if( strpos( $item, '.' ) === false ) { |
|
866 | + if (strpos($item, '.') === false) { |
|
867 | 867 | //if not, then its what we're looking for |
868 | 868 | $contents_with_prefix[] = $item; |
869 | 869 | } |
870 | - } else if( strpos( $item, $prefix . '.' ) === 0 ) { |
|
870 | + } else if (strpos($item, $prefix.'.') === 0) { |
|
871 | 871 | //this item has the prefix and a period, grab it |
872 | 872 | $contents_with_prefix[] = substr( |
873 | 873 | $item, |
874 | - strpos( $item, $prefix . '.' ) + strlen( $prefix . '.' ) |
|
874 | + strpos($item, $prefix.'.') + strlen($prefix.'.') |
|
875 | 875 | ); |
876 | - } else if( $item === $prefix ) { |
|
876 | + } else if ($item === $prefix) { |
|
877 | 877 | //this item is JUST the prefix |
878 | 878 | //so let's grab everything after, which is a blank string |
879 | 879 | $contents_with_prefix[] = ''; |
@@ -896,33 +896,33 @@ discard block |
||
896 | 896 | * the fields for that model, with the model's name removed from each. |
897 | 897 | * If $include_string was blank or '*' returns an empty array |
898 | 898 | */ |
899 | - public function extract_includes_for_this_model( $include_string, $model_name = null ) { |
|
900 | - if( is_array( $include_string ) ) { |
|
901 | - $include_string = implode( ',', $include_string ); |
|
899 | + public function extract_includes_for_this_model($include_string, $model_name = null) { |
|
900 | + if (is_array($include_string)) { |
|
901 | + $include_string = implode(',', $include_string); |
|
902 | 902 | } |
903 | - if( $include_string === '*' || $include_string === '' ) { |
|
903 | + if ($include_string === '*' || $include_string === '') { |
|
904 | 904 | return array(); |
905 | 905 | } |
906 | - $includes = explode( ',', $include_string ); |
|
906 | + $includes = explode(',', $include_string); |
|
907 | 907 | $extracted_fields_to_include = array(); |
908 | - if( $model_name ){ |
|
909 | - foreach( $includes as $field_to_include ) { |
|
910 | - $field_to_include = trim( $field_to_include ); |
|
911 | - if( strpos( $field_to_include, $model_name . '.' ) === 0 ) { |
|
908 | + if ($model_name) { |
|
909 | + foreach ($includes as $field_to_include) { |
|
910 | + $field_to_include = trim($field_to_include); |
|
911 | + if (strpos($field_to_include, $model_name.'.') === 0) { |
|
912 | 912 | //found the model name at the exact start |
913 | - $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
|
913 | + $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include); |
|
914 | 914 | $extracted_fields_to_include[] = $field_sans_model_name; |
915 | - }elseif( $field_to_include == $model_name ){ |
|
915 | + }elseif ($field_to_include == $model_name) { |
|
916 | 916 | $extracted_fields_to_include[] = '*'; |
917 | 917 | } |
918 | 918 | } |
919 | - }else{ |
|
919 | + } else { |
|
920 | 920 | //look for ones with no period |
921 | - foreach( $includes as $field_to_include ) { |
|
922 | - $field_to_include = trim( $field_to_include ); |
|
921 | + foreach ($includes as $field_to_include) { |
|
922 | + $field_to_include = trim($field_to_include); |
|
923 | 923 | if ( |
924 | - strpos( $field_to_include, '.' ) === false |
|
925 | - && ! $this->get_model_version_info()->is_model_name_in_this_version( $field_to_include ) |
|
924 | + strpos($field_to_include, '.') === false |
|
925 | + && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include) |
|
926 | 926 | ) { |
927 | 927 | $extracted_fields_to_include[] = $field_to_include; |
928 | 928 | } |
@@ -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 |
@@ -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,37 +105,37 @@ 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 | - $value = $query_param_value[ 1 ]; |
|
120 | - $new_value = self::prepare_field_values_from_json( $field, $value, $requested_version ); |
|
121 | - $translated_value = array( $op, $new_value ); |
|
117 | + if (is_array($query_param_value)) { |
|
118 | + $op = $query_param_value[0]; |
|
119 | + $value = $query_param_value[1]; |
|
120 | + $new_value = self::prepare_field_values_from_json($field, $value, $requested_version); |
|
121 | + $translated_value = array($op, $new_value); |
|
122 | 122 | } else { |
123 | - $translated_value = self::prepare_field_value_from_json( $field, $query_param_value, $requested_version ); |
|
123 | + $translated_value = self::prepare_field_value_from_json($field, $query_param_value, $requested_version); |
|
124 | 124 | } |
125 | - $query_param_for_models[ $query_param_key ] = $translated_value; |
|
125 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
126 | 126 | } else { |
127 | 127 | //so it's not for a field, assume it's a logic query param key |
128 | - $query_param_for_models[ $query_param_key ] = self::prepare_conditions_query_params_for_models( $query_param_value, $model, $requested_version ); |
|
128 | + $query_param_for_models[$query_param_key] = self::prepare_conditions_query_params_for_models($query_param_value, $model, $requested_version); |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | return $query_param_for_models; |
132 | 132 | } |
133 | 133 | |
134 | - public static function remove_stars_and_anything_after_from_condition_query_param_key( $condition_query_param_key ) { |
|
134 | + public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
135 | 135 | $pos_of_star = strpos($condition_query_param_key, '*'); |
136 | - if($pos_of_star === FALSE){ |
|
136 | + if ($pos_of_star === FALSE) { |
|
137 | 137 | return $condition_query_param_key; |
138 | - }else{ |
|
138 | + } else { |
|
139 | 139 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
140 | 140 | return $condition_query_param_sans_star; |
141 | 141 | } |
@@ -147,26 +147,26 @@ discard block |
||
147 | 147 | * @throws EE_Error |
148 | 148 | * @return EE_Model_Field_Base |
149 | 149 | */ |
150 | - public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model){ |
|
150 | + public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model) { |
|
151 | 151 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
152 | 152 | //which will help us find the database table and column |
153 | 153 | |
154 | - $query_param_parts = explode(".",$query_param_name); |
|
155 | - if(empty($query_param_parts)){ |
|
156 | - throw new \EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s",'event_espresso'),$query_param_name)); |
|
154 | + $query_param_parts = explode(".", $query_param_name); |
|
155 | + if (empty($query_param_parts)) { |
|
156 | + throw new \EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s", 'event_espresso'), $query_param_name)); |
|
157 | 157 | } |
158 | 158 | $number_of_parts = count($query_param_parts); |
159 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
160 | - if($number_of_parts == 1){ |
|
159 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
160 | + if ($number_of_parts == 1) { |
|
161 | 161 | $field_name = $last_query_param_part; |
162 | - }else{// $number_of_parts >= 2 |
|
162 | + } else {// $number_of_parts >= 2 |
|
163 | 163 | //the last part is the column name, and there are only 2parts. therefore... |
164 | 164 | $field_name = $last_query_param_part; |
165 | - $model = \EE_Registry::instance()->load_model( $query_param_parts[ $number_of_parts - 2 ]); |
|
165 | + $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]); |
|
166 | 166 | } |
167 | - try{ |
|
167 | + try { |
|
168 | 168 | return $model->field_settings_for($field_name); |
169 | - }catch(\EE_Error $e){ |
|
169 | + } catch (\EE_Error $e) { |
|
170 | 170 | return null; |
171 | 171 | } |
172 | 172 | } |
@@ -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 | } |
@@ -13,19 +13,19 @@ discard block |
||
13 | 13 | * @since $VID:$ |
14 | 14 | * |
15 | 15 | */ |
16 | -if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
17 | - exit( 'No direct script access allowed' ); |
|
16 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
17 | + exit('No direct script access allowed'); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | class Base { |
21 | - protected static function _verify_current_user_can( $required_permission, $attempted_calculation ) { |
|
22 | - if( ! current_user_can( $required_permission ) ) { |
|
21 | + protected static function _verify_current_user_can($required_permission, $attempted_calculation) { |
|
22 | + if ( ! current_user_can($required_permission)) { |
|
23 | 23 | throw new Rest_Exception( |
24 | 24 | 'permission_denied', |
25 | 25 | sprintf( |
26 | - __( 'Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"', 'event_espresso' ), |
|
26 | + __('Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"', 'event_espresso'), |
|
27 | 27 | $attempted_calculation, |
28 | - \EEH_Inflector::pluralize_and_lower( self::get_resource_name() ), |
|
28 | + \EEH_Inflector::pluralize_and_lower(self::get_resource_name()), |
|
29 | 29 | $required_permission |
30 | 30 | ) |
31 | 31 | ); |
@@ -38,6 +38,6 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public static function get_resource_name() { |
40 | 40 | $classname = get_called_class(); |
41 | - return substr( $classname, strrpos( $classname, '\\' ) + 1 ); |
|
41 | + return substr($classname, strrpos($classname, '\\') + 1); |
|
42 | 42 | } |
43 | 43 | } |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | * @since 4.8.35.rc.001 |
16 | 16 | * |
17 | 17 | */ |
18 | -if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
19 | - exit( 'No direct script access allowed' ); |
|
18 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
19 | + exit('No direct script access allowed'); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | class Calculated_Model_Fields { |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | * the WP_Request object, |
39 | 39 | * the controller object |
40 | 40 | */ |
41 | - public function mapping( $refresh = false ) { |
|
42 | - if( ! $this->_mapping || $refresh ) { |
|
41 | + public function mapping($refresh = false) { |
|
42 | + if ( ! $this->_mapping || $refresh) { |
|
43 | 43 | $this->_mapping = $this->_generate_new_mapping(); |
44 | 44 | } |
45 | 45 | return $this->_mapping; |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | */ |
53 | 53 | protected function _generate_new_mapping() { |
54 | 54 | $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\'; |
55 | - $event_calculations_class = $rest_api_calculations_namespace . 'Event'; |
|
56 | - $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime'; |
|
55 | + $event_calculations_class = $rest_api_calculations_namespace.'Event'; |
|
56 | + $datetime_calculations_class = $rest_api_calculations_namespace.'Datetime'; |
|
57 | 57 | return apply_filters( |
58 | 58 | 'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping', |
59 | 59 | array( |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | * @param \EEM_Base $model |
82 | 82 | * @return array allowable values for this field |
83 | 83 | */ |
84 | - public function retrieve_calculated_fields_for_model( \EEM_Base $model ) { |
|
84 | + public function retrieve_calculated_fields_for_model(\EEM_Base $model) { |
|
85 | 85 | $mapping = $this->mapping(); |
86 | - if( isset( $mapping[ $model->get_this_model_name() ] ) ) { |
|
87 | - return array_keys( $mapping[ $model->get_this_model_name() ] ); |
|
86 | + if (isset($mapping[$model->get_this_model_name()])) { |
|
87 | + return array_keys($mapping[$model->get_this_model_name()]); |
|
88 | 88 | } else { |
89 | 89 | return array(); |
90 | 90 | } |
@@ -103,17 +103,17 @@ discard block |
||
103 | 103 | * @return mixed|null |
104 | 104 | * @throws \EE_Error |
105 | 105 | */ |
106 | - public function retrieve_calculated_field_value( \EEM_Base $model, $field_name, $wpdb_row, $rest_request, Base $controller ) { |
|
106 | + public function retrieve_calculated_field_value(\EEM_Base $model, $field_name, $wpdb_row, $rest_request, Base $controller) { |
|
107 | 107 | $mapping = $this->mapping(); |
108 | - if( isset( $mapping[ $model->get_this_model_name() ] ) |
|
109 | - && isset( $mapping[ $model->get_this_model_name() ][ $field_name ] ) ) { |
|
110 | - $classname = $mapping[ $model->get_this_model_name() ][ $field_name ]; |
|
111 | - return call_user_func( array( $classname, $field_name ), $wpdb_row, $rest_request, $controller ); |
|
108 | + if (isset($mapping[$model->get_this_model_name()]) |
|
109 | + && isset($mapping[$model->get_this_model_name()][$field_name])) { |
|
110 | + $classname = $mapping[$model->get_this_model_name()][$field_name]; |
|
111 | + return call_user_func(array($classname, $field_name), $wpdb_row, $rest_request, $controller); |
|
112 | 112 | } |
113 | 113 | throw new Rest_Exception( |
114 | 114 | 'calculated_field_does_not_exist', |
115 | 115 | sprintf( |
116 | - __( 'There is no calculated field %1$s on resource %2$s', 'event_espresso' ), |
|
116 | + __('There is no calculated field %1$s on resource %2$s', 'event_espresso'), |
|
117 | 117 | $field_name, |
118 | 118 | $model->get_this_model_name() |
119 | 119 | ) |
@@ -13,8 +13,8 @@ discard block |
||
13 | 13 | * @since $VID:$ |
14 | 14 | * |
15 | 15 | */ |
16 | -if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
17 | - exit( 'No direct script access allowed' ); |
|
16 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
17 | + exit('No direct script access allowed'); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | class Rest_Exception extends \EE_Error { |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | protected $_wp_error_data = array(); |
26 | 26 | protected $_wp_error_code = ''; |
27 | - public function __construct( $string_code, $message, $wp_error_data = array(), $previous = null ) { |
|
27 | + public function __construct($string_code, $message, $wp_error_data = array(), $previous = null) { |
|
28 | 28 | parent::__construct( |
29 | 29 | $message, |
30 | 30 | 500, |
@@ -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 Datetime extends Calculations_Base { |
@@ -32,20 +32,20 @@ discard block |
||
32 | 32 | * @return int |
33 | 33 | * @throws \EE_Error |
34 | 34 | */ |
35 | - public static function spaces_remaining_considering_tickets( $wpdb_row, $request, $controller ){ |
|
36 | - if( is_array( $wpdb_row ) && isset( $wpdb_row[ 'Datetime.DTT_ID' ] ) ) { |
|
37 | - $dtt_obj = \EEM_Datetime::instance()->get_one_by_ID( $wpdb_row[ 'Datetime.DTT_ID' ] ); |
|
35 | + public static function spaces_remaining_considering_tickets($wpdb_row, $request, $controller) { |
|
36 | + if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) { |
|
37 | + $dtt_obj = \EEM_Datetime::instance()->get_one_by_ID($wpdb_row['Datetime.DTT_ID']); |
|
38 | 38 | } else { |
39 | 39 | $dtt_obj = null; |
40 | 40 | } |
41 | - if( $dtt_obj instanceof \EE_Datetime ) { |
|
42 | - return $dtt_obj->spaces_remaining( true ); |
|
41 | + if ($dtt_obj instanceof \EE_Datetime) { |
|
42 | + return $dtt_obj->spaces_remaining(true); |
|
43 | 43 | } else { |
44 | 44 | throw new \EE_Error( |
45 | 45 | sprintf( |
46 | - __( 'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found', 'event_espresso' ), |
|
47 | - $wpdb_row[ 'Datetime.DTT_ID' ], |
|
48 | - print_r( $wpdb_row, true ) |
|
46 | + __('Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found', 'event_espresso'), |
|
47 | + $wpdb_row['Datetime.DTT_ID'], |
|
48 | + print_r($wpdb_row, true) |
|
49 | 49 | ) |
50 | 50 | ); |
51 | 51 | } |
@@ -63,17 +63,17 @@ discard block |
||
63 | 63 | * @throws \EE_Error |
64 | 64 | * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
65 | 65 | */ |
66 | - public static function registrations_checked_in_count( $wpdb_row, $request, $controller ){ |
|
67 | - if( ! is_array( $wpdb_row ) || ! isset( $wpdb_row[ 'Datetime.DTT_ID' ] ) ) { |
|
66 | + public static function registrations_checked_in_count($wpdb_row, $request, $controller) { |
|
67 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
68 | 68 | throw new \EE_Error( |
69 | 69 | sprintf( |
70 | - __( 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', 'event_espresso' ), |
|
71 | - print_r( $wpdb_row, true ) |
|
70 | + __('Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', 'event_espresso'), |
|
71 | + print_r($wpdb_row, true) |
|
72 | 72 | ) |
73 | 73 | ); |
74 | 74 | } |
75 | - self::_verify_current_user_can( 'ee_read_checkins', 'registrations_checked_in_count' ); |
|
76 | - return \EEM_Registration::instance()->count_registrations_checked_into_datetime( $wpdb_row[ 'Datetime.DTT_ID' ], true ); |
|
75 | + self::_verify_current_user_can('ee_read_checkins', 'registrations_checked_in_count'); |
|
76 | + return \EEM_Registration::instance()->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | |
@@ -88,17 +88,17 @@ discard block |
||
88 | 88 | * @throws \EE_Error |
89 | 89 | * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
90 | 90 | */ |
91 | - public static function registrations_checked_out_count( $wpdb_row, $request, $controller ){ |
|
92 | - if( ! is_array( $wpdb_row ) || ! isset( $wpdb_row[ 'Datetime.DTT_ID' ] ) ) { |
|
91 | + public static function registrations_checked_out_count($wpdb_row, $request, $controller) { |
|
92 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
93 | 93 | throw new \EE_Error( |
94 | 94 | sprintf( |
95 | - __( 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', 'event_espresso' ), |
|
96 | - print_r( $wpdb_row, true ) |
|
95 | + __('Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', 'event_espresso'), |
|
96 | + print_r($wpdb_row, true) |
|
97 | 97 | ) |
98 | 98 | ); |
99 | 99 | } |
100 | - self::_verify_current_user_can( 'ee_read_checkins', 'registrations_checked_out_count' ); |
|
101 | - return \EEM_Registration::instance()->count_registrations_checked_into_datetime( $wpdb_row[ 'Datetime.DTT_ID' ], false ); |
|
100 | + self::_verify_current_user_can('ee_read_checkins', 'registrations_checked_out_count'); |
|
101 | + return \EEM_Registration::instance()->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | |
@@ -114,20 +114,20 @@ discard block |
||
114 | 114 | * @throws \EE_Error |
115 | 115 | * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
116 | 116 | */ |
117 | - public static function spots_taken_pending_payment( $wpdb_row, $request, $controller ){ |
|
118 | - if( ! is_array( $wpdb_row ) || ! isset( $wpdb_row[ 'Datetime.DTT_ID' ] ) ) { |
|
117 | + public static function spots_taken_pending_payment($wpdb_row, $request, $controller) { |
|
118 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
119 | 119 | throw new \EE_Error( |
120 | 120 | sprintf( |
121 | - __( 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"', 'event_espresso' ), |
|
122 | - print_r( $wpdb_row, true ) |
|
121 | + __('Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"', 'event_espresso'), |
|
122 | + print_r($wpdb_row, true) |
|
123 | 123 | ) |
124 | 124 | ); |
125 | 125 | } |
126 | - self::_verify_current_user_can( 'ee_read_registrations', 'spots_taken_pending_payment' ); |
|
126 | + self::_verify_current_user_can('ee_read_registrations', 'spots_taken_pending_payment'); |
|
127 | 127 | return \EEM_Registration::instance()->count( |
128 | 128 | array( |
129 | 129 | array( |
130 | - 'Ticket.Datetime.DTT_ID' => $wpdb_row[ 'Datetime.DTT_ID' ], |
|
130 | + 'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'], |
|
131 | 131 | 'STS_ID' => \EEM_Registration::status_id_pending_payment |
132 | 132 | ) |
133 | 133 | ), |