@@ -122,9 +122,9 @@ |
||
122 | 122 | $headers, |
123 | 123 | array_flip( |
124 | 124 | array( |
125 | - Base::header_prefix_for_wp . 'Total', |
|
126 | - Base::header_prefix_for_wp . 'TotalPages', |
|
127 | - Base::header_prefix_for_wp . 'PageSize', |
|
125 | + Base::header_prefix_for_wp.'Total', |
|
126 | + Base::header_prefix_for_wp.'TotalPages', |
|
127 | + Base::header_prefix_for_wp.'PageSize', |
|
128 | 128 | ))); |
129 | 129 | } |
130 | 130 | return $headers; |
@@ -14,179 +14,179 @@ |
||
14 | 14 | class Changes_In_4_8_36 extends Changes_In_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Adds hooks so requests to 4.8.29 don't have the checkin endpoints |
|
19 | - */ |
|
20 | - public function set_hooks() |
|
21 | - { |
|
22 | - //set a hook to remove the "calculate" query param |
|
23 | - add_filter( |
|
24 | - 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
25 | - array($this, 'remove_calculate_query_param'), |
|
26 | - 10, |
|
27 | - 3 |
|
28 | - ); |
|
29 | - //don't add the _calculated_fields either |
|
30 | - add_filter( |
|
31 | - 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
|
32 | - array($this, 'remove_calculated_fields_from_response'), |
|
33 | - 10, |
|
34 | - 5 |
|
35 | - ); |
|
36 | - //and also don't add the count headers |
|
37 | - add_filter( |
|
38 | - 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
|
39 | - array($this, 'remove_headers_new_in_this_version'), |
|
40 | - 10, |
|
41 | - 3 |
|
42 | - ); |
|
43 | - //remove the old featured_image part of the response... |
|
44 | - add_filter( |
|
45 | - 'FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models', |
|
46 | - array($this, 'add_old_featured_image_part_of_cpt_entities'), |
|
47 | - 10, |
|
48 | - 5 |
|
49 | - ); |
|
50 | - //assuming ticket 9425's change gets pushed with 9406, we don't need to |
|
51 | - //remove it from the calculated fields on older requests (because this will |
|
52 | - //be the first version with calculated fields) |
|
53 | - //before this, infinity was -1, now it's null |
|
54 | - add_filter( |
|
55 | - 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
56 | - array($this, 'use_negative_one_for_infinity_before_this_version'), |
|
57 | - 10, |
|
58 | - 4 |
|
59 | - ); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Dont show "calculate" as an query param option in the index |
|
66 | - * |
|
67 | - * @param array $query_params |
|
68 | - * @param \EEM_base $model |
|
69 | - * @param string $version |
|
70 | - * @return array |
|
71 | - */ |
|
72 | - public function remove_calculate_query_param($query_params, \EEM_Base $model, $version) |
|
73 | - { |
|
74 | - if ($this->applies_to_version($version)) { |
|
75 | - unset($query_params['calculate']); |
|
76 | - } |
|
77 | - return $query_params; |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * Removes the "_calculate_fields" part of entity responses before 4.8.36 |
|
84 | - * |
|
85 | - * @param array $entity_response_array |
|
86 | - * @param \EEM_Base $model |
|
87 | - * @param string $request_context |
|
88 | - * @param \WP_REST_Request $request |
|
89 | - * @param Read $controller |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function remove_calculated_fields_from_response( |
|
93 | - $entity_response_array, |
|
94 | - \EEM_Base $model, |
|
95 | - $request_context, |
|
96 | - \WP_REST_Request $request, |
|
97 | - Read $controller |
|
98 | - ) { |
|
99 | - if ($this->applies_to_version($controller->get_model_version_info()->requested_version())) { |
|
100 | - unset($entity_response_array['_calculated_fields']); |
|
101 | - } |
|
102 | - return $entity_response_array; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Removes the new headers for requests before 4.8.36 |
|
109 | - * |
|
110 | - * @param array $headers |
|
111 | - * @param Base $controller |
|
112 | - * @param string $version |
|
113 | - * @return array |
|
114 | - */ |
|
115 | - public function remove_headers_new_in_this_version( |
|
116 | - $headers, |
|
117 | - Controller_Base $controller, |
|
118 | - $version |
|
119 | - ) { |
|
120 | - if ($this->applies_to_version($version)) { |
|
121 | - $headers = array_diff_key( |
|
122 | - $headers, |
|
123 | - array_flip( |
|
124 | - array( |
|
125 | - Base::header_prefix_for_wp . 'Total', |
|
126 | - Base::header_prefix_for_wp . 'TotalPages', |
|
127 | - Base::header_prefix_for_wp . 'PageSize', |
|
128 | - ))); |
|
129 | - } |
|
130 | - return $headers; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * Puts the 'featured_image_url' back in for responses before 4.8.36. |
|
137 | - * |
|
138 | - * @param array $entity_response_array |
|
139 | - * @param \EEM_Base $model |
|
140 | - * @param string $request_context |
|
141 | - * @param \WP_REST_Request $request |
|
142 | - * @param Read $controller |
|
143 | - * @return array |
|
144 | - */ |
|
145 | - public function add_old_featured_image_part_of_cpt_entities( |
|
146 | - $entity_response_array, |
|
147 | - \EEM_Base $model, |
|
148 | - $request_context, |
|
149 | - \WP_REST_Request $request, |
|
150 | - Read $controller |
|
151 | - ) { |
|
152 | - if ($this->applies_to_version($controller->get_model_version_info()->requested_version()) |
|
153 | - && $model instanceof \EEM_CPT_Base |
|
154 | - ) { |
|
155 | - $attachment = wp_get_attachment_image_src( |
|
156 | - get_post_thumbnail_id($entity_response_array[$model->primary_key_name()]), |
|
157 | - 'full' |
|
158 | - ); |
|
159 | - $entity_response_array['featured_image_url'] = ! empty($attachment) ? $attachment[0] : null; |
|
160 | - } |
|
161 | - return $entity_response_array; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * If the value was infinity, we now use null in our JSON responses, |
|
168 | - * but before this version we used -1. |
|
169 | - * |
|
170 | - * @param mixed $new_value |
|
171 | - * @param \EE_Model_Field_Base $field_obj |
|
172 | - * @param mixed $original_value |
|
173 | - * @param string $requested_value |
|
174 | - * @return mixed |
|
175 | - */ |
|
176 | - public function use_negative_one_for_infinity_before_this_version( |
|
177 | - $new_value, |
|
178 | - $field_obj, |
|
179 | - $original_value, |
|
180 | - $requested_value |
|
181 | - ) { |
|
182 | - if ($this->applies_to_version($requested_value) |
|
183 | - && $original_value === EE_INF |
|
184 | - ) { |
|
185 | - //return the old representation of infinity in the JSON |
|
186 | - return -1; |
|
187 | - } |
|
188 | - return $new_value; |
|
189 | - } |
|
17 | + /** |
|
18 | + * Adds hooks so requests to 4.8.29 don't have the checkin endpoints |
|
19 | + */ |
|
20 | + public function set_hooks() |
|
21 | + { |
|
22 | + //set a hook to remove the "calculate" query param |
|
23 | + add_filter( |
|
24 | + 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
25 | + array($this, 'remove_calculate_query_param'), |
|
26 | + 10, |
|
27 | + 3 |
|
28 | + ); |
|
29 | + //don't add the _calculated_fields either |
|
30 | + add_filter( |
|
31 | + 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
|
32 | + array($this, 'remove_calculated_fields_from_response'), |
|
33 | + 10, |
|
34 | + 5 |
|
35 | + ); |
|
36 | + //and also don't add the count headers |
|
37 | + add_filter( |
|
38 | + 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
|
39 | + array($this, 'remove_headers_new_in_this_version'), |
|
40 | + 10, |
|
41 | + 3 |
|
42 | + ); |
|
43 | + //remove the old featured_image part of the response... |
|
44 | + add_filter( |
|
45 | + 'FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models', |
|
46 | + array($this, 'add_old_featured_image_part_of_cpt_entities'), |
|
47 | + 10, |
|
48 | + 5 |
|
49 | + ); |
|
50 | + //assuming ticket 9425's change gets pushed with 9406, we don't need to |
|
51 | + //remove it from the calculated fields on older requests (because this will |
|
52 | + //be the first version with calculated fields) |
|
53 | + //before this, infinity was -1, now it's null |
|
54 | + add_filter( |
|
55 | + 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
56 | + array($this, 'use_negative_one_for_infinity_before_this_version'), |
|
57 | + 10, |
|
58 | + 4 |
|
59 | + ); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Dont show "calculate" as an query param option in the index |
|
66 | + * |
|
67 | + * @param array $query_params |
|
68 | + * @param \EEM_base $model |
|
69 | + * @param string $version |
|
70 | + * @return array |
|
71 | + */ |
|
72 | + public function remove_calculate_query_param($query_params, \EEM_Base $model, $version) |
|
73 | + { |
|
74 | + if ($this->applies_to_version($version)) { |
|
75 | + unset($query_params['calculate']); |
|
76 | + } |
|
77 | + return $query_params; |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * Removes the "_calculate_fields" part of entity responses before 4.8.36 |
|
84 | + * |
|
85 | + * @param array $entity_response_array |
|
86 | + * @param \EEM_Base $model |
|
87 | + * @param string $request_context |
|
88 | + * @param \WP_REST_Request $request |
|
89 | + * @param Read $controller |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function remove_calculated_fields_from_response( |
|
93 | + $entity_response_array, |
|
94 | + \EEM_Base $model, |
|
95 | + $request_context, |
|
96 | + \WP_REST_Request $request, |
|
97 | + Read $controller |
|
98 | + ) { |
|
99 | + if ($this->applies_to_version($controller->get_model_version_info()->requested_version())) { |
|
100 | + unset($entity_response_array['_calculated_fields']); |
|
101 | + } |
|
102 | + return $entity_response_array; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Removes the new headers for requests before 4.8.36 |
|
109 | + * |
|
110 | + * @param array $headers |
|
111 | + * @param Base $controller |
|
112 | + * @param string $version |
|
113 | + * @return array |
|
114 | + */ |
|
115 | + public function remove_headers_new_in_this_version( |
|
116 | + $headers, |
|
117 | + Controller_Base $controller, |
|
118 | + $version |
|
119 | + ) { |
|
120 | + if ($this->applies_to_version($version)) { |
|
121 | + $headers = array_diff_key( |
|
122 | + $headers, |
|
123 | + array_flip( |
|
124 | + array( |
|
125 | + Base::header_prefix_for_wp . 'Total', |
|
126 | + Base::header_prefix_for_wp . 'TotalPages', |
|
127 | + Base::header_prefix_for_wp . 'PageSize', |
|
128 | + ))); |
|
129 | + } |
|
130 | + return $headers; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * Puts the 'featured_image_url' back in for responses before 4.8.36. |
|
137 | + * |
|
138 | + * @param array $entity_response_array |
|
139 | + * @param \EEM_Base $model |
|
140 | + * @param string $request_context |
|
141 | + * @param \WP_REST_Request $request |
|
142 | + * @param Read $controller |
|
143 | + * @return array |
|
144 | + */ |
|
145 | + public function add_old_featured_image_part_of_cpt_entities( |
|
146 | + $entity_response_array, |
|
147 | + \EEM_Base $model, |
|
148 | + $request_context, |
|
149 | + \WP_REST_Request $request, |
|
150 | + Read $controller |
|
151 | + ) { |
|
152 | + if ($this->applies_to_version($controller->get_model_version_info()->requested_version()) |
|
153 | + && $model instanceof \EEM_CPT_Base |
|
154 | + ) { |
|
155 | + $attachment = wp_get_attachment_image_src( |
|
156 | + get_post_thumbnail_id($entity_response_array[$model->primary_key_name()]), |
|
157 | + 'full' |
|
158 | + ); |
|
159 | + $entity_response_array['featured_image_url'] = ! empty($attachment) ? $attachment[0] : null; |
|
160 | + } |
|
161 | + return $entity_response_array; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * If the value was infinity, we now use null in our JSON responses, |
|
168 | + * but before this version we used -1. |
|
169 | + * |
|
170 | + * @param mixed $new_value |
|
171 | + * @param \EE_Model_Field_Base $field_obj |
|
172 | + * @param mixed $original_value |
|
173 | + * @param string $requested_value |
|
174 | + * @return mixed |
|
175 | + */ |
|
176 | + public function use_negative_one_for_infinity_before_this_version( |
|
177 | + $new_value, |
|
178 | + $field_obj, |
|
179 | + $original_value, |
|
180 | + $requested_value |
|
181 | + ) { |
|
182 | + if ($this->applies_to_version($requested_value) |
|
183 | + && $original_value === EE_INF |
|
184 | + ) { |
|
185 | + //return the old representation of infinity in the JSON |
|
186 | + return -1; |
|
187 | + } |
|
188 | + return $new_value; |
|
189 | + } |
|
190 | 190 | |
191 | 191 | } |
192 | 192 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @since $VID:$ |
13 | 13 | */ |
14 | 14 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
15 | - exit('No direct script access allowed'); |
|
15 | + exit('No direct script access allowed'); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | |
@@ -20,46 +20,46 @@ discard block |
||
20 | 20 | class Rest_Exception extends \EE_Error |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var array |
|
25 | - */ |
|
26 | - protected $_wp_error_data = array(); |
|
23 | + /** |
|
24 | + * @var array |
|
25 | + */ |
|
26 | + protected $_wp_error_data = array(); |
|
27 | 27 | |
28 | - protected $_wp_error_code = ''; |
|
28 | + protected $_wp_error_code = ''; |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | - public function __construct($string_code, $message, $wp_error_data = array(), $previous = null) |
|
33 | - { |
|
34 | - parent::__construct( |
|
35 | - $message, |
|
36 | - 500, |
|
37 | - $previous); |
|
38 | - $this->_wp_error_data = $wp_error_data; |
|
39 | - $this->_wp_error_code = $string_code; |
|
40 | - } |
|
32 | + public function __construct($string_code, $message, $wp_error_data = array(), $previous = null) |
|
33 | + { |
|
34 | + parent::__construct( |
|
35 | + $message, |
|
36 | + 500, |
|
37 | + $previous); |
|
38 | + $this->_wp_error_data = $wp_error_data; |
|
39 | + $this->_wp_error_code = $string_code; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * Array of data that may have been set during the constructor, intended for WP_Error's data |
|
46 | - * |
|
47 | - * @return array |
|
48 | - */ |
|
49 | - public function get_data() |
|
50 | - { |
|
51 | - return $this->_wp_error_data; |
|
52 | - } |
|
44 | + /** |
|
45 | + * Array of data that may have been set during the constructor, intended for WP_Error's data |
|
46 | + * |
|
47 | + * @return array |
|
48 | + */ |
|
49 | + public function get_data() |
|
50 | + { |
|
51 | + return $this->_wp_error_data; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Gets the error string |
|
58 | - * |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function get_string_code() |
|
62 | - { |
|
63 | - return $this->_wp_error_code; |
|
64 | - } |
|
56 | + /** |
|
57 | + * Gets the error string |
|
58 | + * |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function get_string_code() |
|
62 | + { |
|
63 | + return $this->_wp_error_code; |
|
64 | + } |
|
65 | 65 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * @author Mike Nelson |
12 | 12 | * @since $VID:$ |
13 | 13 | */ |
14 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
14 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
15 | 15 | exit('No direct script access allowed'); |
16 | 16 | } |
17 | 17 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * @since $VID:$ |
15 | 15 | */ |
16 | 16 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
17 | - exit('No direct script access allowed'); |
|
17 | + exit('No direct script access allowed'); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | |
@@ -22,128 +22,128 @@ discard block |
||
22 | 22 | class Datetime extends Calculations_Base |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Calculates the total spaces available on the datetime, taking into account |
|
27 | - * ticket limits too. |
|
28 | - * |
|
29 | - * @see EE_Datetime::spaces_remaining( true ) |
|
30 | - * @param array $wpdb_row |
|
31 | - * @param \WP_REST_Request $request |
|
32 | - * @param Controller_Base $controller |
|
33 | - * @return int |
|
34 | - * @throws \EE_Error |
|
35 | - */ |
|
36 | - public static function spaces_remaining_considering_tickets($wpdb_row, $request, $controller) |
|
37 | - { |
|
38 | - if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) { |
|
39 | - $dtt_obj = \EEM_Datetime::instance()->get_one_by_ID($wpdb_row['Datetime.DTT_ID']); |
|
40 | - } else { |
|
41 | - $dtt_obj = null; |
|
42 | - } |
|
43 | - if ($dtt_obj instanceof \EE_Datetime) { |
|
44 | - return $dtt_obj->spaces_remaining(true); |
|
45 | - } else { |
|
46 | - throw new \EE_Error( |
|
47 | - sprintf( |
|
48 | - __('Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found', |
|
49 | - 'event_espresso'), |
|
50 | - $wpdb_row['Datetime.DTT_ID'], |
|
51 | - print_r($wpdb_row, true) |
|
52 | - ) |
|
53 | - ); |
|
54 | - } |
|
55 | - } |
|
25 | + /** |
|
26 | + * Calculates the total spaces available on the datetime, taking into account |
|
27 | + * ticket limits too. |
|
28 | + * |
|
29 | + * @see EE_Datetime::spaces_remaining( true ) |
|
30 | + * @param array $wpdb_row |
|
31 | + * @param \WP_REST_Request $request |
|
32 | + * @param Controller_Base $controller |
|
33 | + * @return int |
|
34 | + * @throws \EE_Error |
|
35 | + */ |
|
36 | + public static function spaces_remaining_considering_tickets($wpdb_row, $request, $controller) |
|
37 | + { |
|
38 | + if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) { |
|
39 | + $dtt_obj = \EEM_Datetime::instance()->get_one_by_ID($wpdb_row['Datetime.DTT_ID']); |
|
40 | + } else { |
|
41 | + $dtt_obj = null; |
|
42 | + } |
|
43 | + if ($dtt_obj instanceof \EE_Datetime) { |
|
44 | + return $dtt_obj->spaces_remaining(true); |
|
45 | + } else { |
|
46 | + throw new \EE_Error( |
|
47 | + sprintf( |
|
48 | + __('Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found', |
|
49 | + 'event_espresso'), |
|
50 | + $wpdb_row['Datetime.DTT_ID'], |
|
51 | + print_r($wpdb_row, true) |
|
52 | + ) |
|
53 | + ); |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Counts registrations who have checked into this datetime |
|
61 | - * |
|
62 | - * @param array $wpdb_row |
|
63 | - * @param \WP_REST_Request $request |
|
64 | - * @param Controller_Base $controller |
|
65 | - * @return int |
|
66 | - * @throws \EE_Error |
|
67 | - * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
|
68 | - */ |
|
69 | - public static function registrations_checked_in_count($wpdb_row, $request, $controller) |
|
70 | - { |
|
71 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
72 | - throw new \EE_Error( |
|
73 | - sprintf( |
|
74 | - __('Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
75 | - 'event_espresso'), |
|
76 | - print_r($wpdb_row, true) |
|
77 | - ) |
|
78 | - ); |
|
79 | - } |
|
80 | - self::_verify_current_user_can('ee_read_checkins', 'registrations_checked_in_count'); |
|
81 | - return \EEM_Registration::instance() |
|
82 | - ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true); |
|
83 | - } |
|
59 | + /** |
|
60 | + * Counts registrations who have checked into this datetime |
|
61 | + * |
|
62 | + * @param array $wpdb_row |
|
63 | + * @param \WP_REST_Request $request |
|
64 | + * @param Controller_Base $controller |
|
65 | + * @return int |
|
66 | + * @throws \EE_Error |
|
67 | + * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
|
68 | + */ |
|
69 | + public static function registrations_checked_in_count($wpdb_row, $request, $controller) |
|
70 | + { |
|
71 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
72 | + throw new \EE_Error( |
|
73 | + sprintf( |
|
74 | + __('Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
75 | + 'event_espresso'), |
|
76 | + print_r($wpdb_row, true) |
|
77 | + ) |
|
78 | + ); |
|
79 | + } |
|
80 | + self::_verify_current_user_can('ee_read_checkins', 'registrations_checked_in_count'); |
|
81 | + return \EEM_Registration::instance() |
|
82 | + ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true); |
|
83 | + } |
|
84 | 84 | |
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * Counts registrations who have checked out of this datetime |
|
89 | - * |
|
90 | - * @param array $wpdb_row |
|
91 | - * @param \WP_REST_Request $request |
|
92 | - * @param Controller_Base $controller |
|
93 | - * @return int |
|
94 | - * @throws \EE_Error |
|
95 | - * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
|
96 | - */ |
|
97 | - public static function registrations_checked_out_count($wpdb_row, $request, $controller) |
|
98 | - { |
|
99 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
100 | - throw new \EE_Error( |
|
101 | - sprintf( |
|
102 | - __('Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
103 | - 'event_espresso'), |
|
104 | - print_r($wpdb_row, true) |
|
105 | - ) |
|
106 | - ); |
|
107 | - } |
|
108 | - self::_verify_current_user_can('ee_read_checkins', 'registrations_checked_out_count'); |
|
109 | - return \EEM_Registration::instance() |
|
110 | - ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false); |
|
111 | - } |
|
87 | + /** |
|
88 | + * Counts registrations who have checked out of this datetime |
|
89 | + * |
|
90 | + * @param array $wpdb_row |
|
91 | + * @param \WP_REST_Request $request |
|
92 | + * @param Controller_Base $controller |
|
93 | + * @return int |
|
94 | + * @throws \EE_Error |
|
95 | + * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
|
96 | + */ |
|
97 | + public static function registrations_checked_out_count($wpdb_row, $request, $controller) |
|
98 | + { |
|
99 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
100 | + throw new \EE_Error( |
|
101 | + sprintf( |
|
102 | + __('Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
103 | + 'event_espresso'), |
|
104 | + print_r($wpdb_row, true) |
|
105 | + ) |
|
106 | + ); |
|
107 | + } |
|
108 | + self::_verify_current_user_can('ee_read_checkins', 'registrations_checked_out_count'); |
|
109 | + return \EEM_Registration::instance() |
|
110 | + ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false); |
|
111 | + } |
|
112 | 112 | |
113 | 113 | |
114 | 114 | |
115 | - /** |
|
116 | - * Counts the number of pending-payment registrations for this event (regardless |
|
117 | - * of how many datetimes each registrations' ticket purchase is for) |
|
118 | - * |
|
119 | - * @param array $wpdb_row |
|
120 | - * @param \WP_REST_Request $request |
|
121 | - * @param Controller_Base $controller |
|
122 | - * @return int |
|
123 | - * @throws \EE_Error |
|
124 | - * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
|
125 | - */ |
|
126 | - public static function spots_taken_pending_payment($wpdb_row, $request, $controller) |
|
127 | - { |
|
128 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
129 | - throw new \EE_Error( |
|
130 | - sprintf( |
|
131 | - __('Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
132 | - 'event_espresso'), |
|
133 | - print_r($wpdb_row, true) |
|
134 | - ) |
|
135 | - ); |
|
136 | - } |
|
137 | - self::_verify_current_user_can('ee_read_registrations', 'spots_taken_pending_payment'); |
|
138 | - return \EEM_Registration::instance()->count( |
|
139 | - array( |
|
140 | - array( |
|
141 | - 'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'], |
|
142 | - 'STS_ID' => \EEM_Registration::status_id_pending_payment, |
|
143 | - ), |
|
144 | - ), |
|
145 | - 'REG_ID', |
|
146 | - true |
|
147 | - ); |
|
148 | - } |
|
115 | + /** |
|
116 | + * Counts the number of pending-payment registrations for this event (regardless |
|
117 | + * of how many datetimes each registrations' ticket purchase is for) |
|
118 | + * |
|
119 | + * @param array $wpdb_row |
|
120 | + * @param \WP_REST_Request $request |
|
121 | + * @param Controller_Base $controller |
|
122 | + * @return int |
|
123 | + * @throws \EE_Error |
|
124 | + * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
|
125 | + */ |
|
126 | + public static function spots_taken_pending_payment($wpdb_row, $request, $controller) |
|
127 | + { |
|
128 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
129 | + throw new \EE_Error( |
|
130 | + sprintf( |
|
131 | + __('Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
132 | + 'event_espresso'), |
|
133 | + print_r($wpdb_row, true) |
|
134 | + ) |
|
135 | + ); |
|
136 | + } |
|
137 | + self::_verify_current_user_can('ee_read_registrations', 'spots_taken_pending_payment'); |
|
138 | + return \EEM_Registration::instance()->count( |
|
139 | + array( |
|
140 | + array( |
|
141 | + 'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'], |
|
142 | + 'STS_ID' => \EEM_Registration::status_id_pending_payment, |
|
143 | + ), |
|
144 | + ), |
|
145 | + 'REG_ID', |
|
146 | + true |
|
147 | + ); |
|
148 | + } |
|
149 | 149 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @author Mike Nelson |
14 | 14 | * @since $VID:$ |
15 | 15 | */ |
16 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
16 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
17 | 17 | exit('No direct script access allowed'); |
18 | 18 | } |
19 | 19 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public static function registrations_checked_in_count($wpdb_row, $request, $controller) |
70 | 70 | { |
71 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
71 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
72 | 72 | throw new \EE_Error( |
73 | 73 | sprintf( |
74 | 74 | __('Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public static function registrations_checked_out_count($wpdb_row, $request, $controller) |
98 | 98 | { |
99 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
99 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
100 | 100 | throw new \EE_Error( |
101 | 101 | sprintf( |
102 | 102 | __('Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public static function spots_taken_pending_payment($wpdb_row, $request, $controller) |
127 | 127 | { |
128 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
128 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
129 | 129 | throw new \EE_Error( |
130 | 130 | sprintf( |
131 | 131 | __('Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @since $VID:$ |
14 | 14 | */ |
15 | 15 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
16 | - exit('No direct script access allowed'); |
|
16 | + exit('No direct script access allowed'); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | |
@@ -21,37 +21,37 @@ discard block |
||
21 | 21 | class Base |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @param $required_permission |
|
26 | - * @param $attempted_calculation |
|
27 | - * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
|
28 | - */ |
|
29 | - protected static function _verify_current_user_can($required_permission, $attempted_calculation) |
|
30 | - { |
|
31 | - if (! current_user_can($required_permission)) { |
|
32 | - throw new Rest_Exception( |
|
33 | - 'permission_denied', |
|
34 | - sprintf( |
|
35 | - __('Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"', |
|
36 | - 'event_espresso'), |
|
37 | - $attempted_calculation, |
|
38 | - \EEH_Inflector::pluralize_and_lower(self::get_resource_name()), |
|
39 | - $required_permission |
|
40 | - ) |
|
41 | - ); |
|
42 | - } |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Gets the name of the resource of the called class |
|
49 | - * |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public static function get_resource_name() |
|
53 | - { |
|
54 | - $classname = get_called_class(); |
|
55 | - return substr($classname, strrpos($classname, '\\') + 1); |
|
56 | - } |
|
24 | + /** |
|
25 | + * @param $required_permission |
|
26 | + * @param $attempted_calculation |
|
27 | + * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
|
28 | + */ |
|
29 | + protected static function _verify_current_user_can($required_permission, $attempted_calculation) |
|
30 | + { |
|
31 | + if (! current_user_can($required_permission)) { |
|
32 | + throw new Rest_Exception( |
|
33 | + 'permission_denied', |
|
34 | + sprintf( |
|
35 | + __('Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"', |
|
36 | + 'event_espresso'), |
|
37 | + $attempted_calculation, |
|
38 | + \EEH_Inflector::pluralize_and_lower(self::get_resource_name()), |
|
39 | + $required_permission |
|
40 | + ) |
|
41 | + ); |
|
42 | + } |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Gets the name of the resource of the called class |
|
49 | + * |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public static function get_resource_name() |
|
53 | + { |
|
54 | + $classname = get_called_class(); |
|
55 | + return substr($classname, strrpos($classname, '\\') + 1); |
|
56 | + } |
|
57 | 57 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @author Mike Nelson |
13 | 13 | * @since $VID:$ |
14 | 14 | */ |
15 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
15 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
16 | 16 | exit('No direct script access allowed'); |
17 | 17 | } |
18 | 18 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | protected static function _verify_current_user_can($required_permission, $attempted_calculation) |
30 | 30 | { |
31 | - if (! current_user_can($required_permission)) { |
|
31 | + if ( ! current_user_can($required_permission)) { |
|
32 | 32 | throw new Rest_Exception( |
33 | 33 | 'permission_denied', |
34 | 34 | sprintf( |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @author Mike Nelson |
13 | 13 | * @since $VID:$ |
14 | 14 | */ |
15 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
15 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
16 | 16 | exit('No direct script access allowed'); |
17 | 17 | } |
18 | 18 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | } else { |
38 | 38 | $reg = null; |
39 | 39 | } |
40 | - if (! $reg instanceof \EE_Registration |
|
40 | + if ( ! $reg instanceof \EE_Registration |
|
41 | 41 | ) { |
42 | 42 | throw new \EE_Error( |
43 | 43 | sprintf( |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @since $VID:$ |
14 | 14 | */ |
15 | 15 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
16 | - exit('No direct script access allowed'); |
|
16 | + exit('No direct script access allowed'); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | |
@@ -21,58 +21,58 @@ discard block |
||
21 | 21 | class Registration extends Calculations_Base |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Calculates the checkin status for each datetime this registration has access to |
|
26 | - * |
|
27 | - * @param array $wpdb_row |
|
28 | - * @param \WP_REST_Request $request |
|
29 | - * @param Base $controller |
|
30 | - * @return int |
|
31 | - * @throws \EE_Error |
|
32 | - */ |
|
33 | - public static function datetime_checkin_stati($wpdb_row, $request, $controller) |
|
34 | - { |
|
35 | - if (is_array($wpdb_row) && isset($wpdb_row['Registration.REG_ID'])) { |
|
36 | - $reg = \EEM_Registration::instance()->get_one_by_ID($wpdb_row['Registration.REG_ID']); |
|
37 | - } else { |
|
38 | - $reg = null; |
|
39 | - } |
|
40 | - if (! $reg instanceof \EE_Registration |
|
41 | - ) { |
|
42 | - throw new \EE_Error( |
|
43 | - sprintf( |
|
44 | - __('Cannot calculate datetime_checkin_stati because the registration with ID %1$s (from database row %2$s) was not found', |
|
45 | - 'event_espresso'), |
|
46 | - $wpdb_row['Registration.REG_ID'], |
|
47 | - print_r($wpdb_row, true) |
|
48 | - ) |
|
49 | - ); |
|
50 | - } |
|
51 | - $datetime_ids = \EEM_Datetime::instance()->get_col( |
|
52 | - array( |
|
53 | - array( |
|
54 | - 'Ticket.TKT_ID' => $reg->ticket_ID(), |
|
55 | - ), |
|
56 | - 'default_where_conditions' => \EEM_Base::default_where_conditions_minimum_all |
|
57 | - ) |
|
58 | - ); |
|
59 | - $checkin_stati = array(); |
|
60 | - foreach ($datetime_ids as $datetime_id) { |
|
61 | - $status = $reg->check_in_status_for_datetime($datetime_id); |
|
62 | - switch ($status) { |
|
63 | - case \EE_Registration::checkin_status_out: |
|
64 | - $status_pretty = 'OUT'; |
|
65 | - break; |
|
66 | - case \EE_Registration::checkin_status_in: |
|
67 | - $status_pretty = 'IN'; |
|
68 | - break; |
|
69 | - case \EE_Registration::checkin_status_never: |
|
70 | - default: |
|
71 | - $status_pretty = 'NEVER'; |
|
72 | - break; |
|
73 | - } |
|
74 | - $checkin_stati[$datetime_id] = $status_pretty; |
|
75 | - } |
|
76 | - return $checkin_stati; |
|
77 | - } |
|
24 | + /** |
|
25 | + * Calculates the checkin status for each datetime this registration has access to |
|
26 | + * |
|
27 | + * @param array $wpdb_row |
|
28 | + * @param \WP_REST_Request $request |
|
29 | + * @param Base $controller |
|
30 | + * @return int |
|
31 | + * @throws \EE_Error |
|
32 | + */ |
|
33 | + public static function datetime_checkin_stati($wpdb_row, $request, $controller) |
|
34 | + { |
|
35 | + if (is_array($wpdb_row) && isset($wpdb_row['Registration.REG_ID'])) { |
|
36 | + $reg = \EEM_Registration::instance()->get_one_by_ID($wpdb_row['Registration.REG_ID']); |
|
37 | + } else { |
|
38 | + $reg = null; |
|
39 | + } |
|
40 | + if (! $reg instanceof \EE_Registration |
|
41 | + ) { |
|
42 | + throw new \EE_Error( |
|
43 | + sprintf( |
|
44 | + __('Cannot calculate datetime_checkin_stati because the registration with ID %1$s (from database row %2$s) was not found', |
|
45 | + 'event_espresso'), |
|
46 | + $wpdb_row['Registration.REG_ID'], |
|
47 | + print_r($wpdb_row, true) |
|
48 | + ) |
|
49 | + ); |
|
50 | + } |
|
51 | + $datetime_ids = \EEM_Datetime::instance()->get_col( |
|
52 | + array( |
|
53 | + array( |
|
54 | + 'Ticket.TKT_ID' => $reg->ticket_ID(), |
|
55 | + ), |
|
56 | + 'default_where_conditions' => \EEM_Base::default_where_conditions_minimum_all |
|
57 | + ) |
|
58 | + ); |
|
59 | + $checkin_stati = array(); |
|
60 | + foreach ($datetime_ids as $datetime_id) { |
|
61 | + $status = $reg->check_in_status_for_datetime($datetime_id); |
|
62 | + switch ($status) { |
|
63 | + case \EE_Registration::checkin_status_out: |
|
64 | + $status_pretty = 'OUT'; |
|
65 | + break; |
|
66 | + case \EE_Registration::checkin_status_in: |
|
67 | + $status_pretty = 'IN'; |
|
68 | + break; |
|
69 | + case \EE_Registration::checkin_status_never: |
|
70 | + default: |
|
71 | + $status_pretty = 'NEVER'; |
|
72 | + break; |
|
73 | + } |
|
74 | + $checkin_stati[$datetime_id] = $status_pretty; |
|
75 | + } |
|
76 | + return $checkin_stati; |
|
77 | + } |
|
78 | 78 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * @since $VID:$ |
15 | 15 | */ |
16 | 16 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
17 | - exit('No direct script access allowed'); |
|
17 | + exit('No direct script access allowed'); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | |
@@ -22,350 +22,350 @@ discard block |
||
22 | 22 | class Event extends Calculations_Base |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Calculates the total spaces on the event (not subtracting sales, but taking |
|
27 | - * sales into account; so this is the optimum sales that CAN still be achieved) |
|
28 | - * See EE_Event::total_available_spaces( true ); |
|
29 | - * |
|
30 | - * @param array $wpdb_row |
|
31 | - * @param \WP_REST_Request $request |
|
32 | - * @param Base $controller |
|
33 | - * @return int |
|
34 | - * @throws \EE_Error |
|
35 | - */ |
|
36 | - public static function optimum_sales_at_start($wpdb_row, $request, $controller) |
|
37 | - { |
|
38 | - if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID'])) { |
|
39 | - $event_obj = \EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
40 | - } else { |
|
41 | - $event_obj = null; |
|
42 | - } |
|
43 | - if ($event_obj instanceof \EE_Event) { |
|
44 | - return $event_obj->total_available_spaces(true); |
|
45 | - } else { |
|
46 | - throw new \EE_Error( |
|
47 | - sprintf( |
|
48 | - __('Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', |
|
49 | - 'event_espresso'), |
|
50 | - $wpdb_row['Event_CPT.ID'], |
|
51 | - print_r($wpdb_row, true) |
|
52 | - ) |
|
53 | - ); |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * Calculates the total spaces on the event (ignoring all sales; so this is the optimum |
|
61 | - * sales that COULD have been achieved) |
|
62 | - * See EE_Event::total_available_spaces( true ); |
|
63 | - * |
|
64 | - * @param array $wpdb_row |
|
65 | - * @param \WP_REST_Request $request |
|
66 | - * @param Base $controller |
|
67 | - * @return int |
|
68 | - * @throws \EE_Error |
|
69 | - */ |
|
70 | - public static function optimum_sales_now($wpdb_row, $request, $controller) |
|
71 | - { |
|
72 | - if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID'])) { |
|
73 | - $event_obj = \EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
74 | - } else { |
|
75 | - $event_obj = null; |
|
76 | - } |
|
77 | - if ($event_obj instanceof \EE_Event) { |
|
78 | - return $event_obj->total_available_spaces(false); |
|
79 | - } else { |
|
80 | - throw new \EE_Error( |
|
81 | - sprintf( |
|
82 | - __('Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', |
|
83 | - 'event_espresso'), |
|
84 | - $wpdb_row['Event_CPT.ID'], |
|
85 | - print_r($wpdb_row, true) |
|
86 | - ) |
|
87 | - ); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Like optimum_sales_now, but minus total sales so far. |
|
95 | - * See EE_Event::spaces_remaining_for_sale( true ); |
|
96 | - * |
|
97 | - * @param array $wpdb_row |
|
98 | - * @param \WP_REST_Request $request |
|
99 | - * @param Base $controller |
|
100 | - * @return int |
|
101 | - * @throws \EE_Error |
|
102 | - */ |
|
103 | - public static function spaces_remaining($wpdb_row, $request, $controller) |
|
104 | - { |
|
105 | - if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID'])) { |
|
106 | - $event_obj = \EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
107 | - } else { |
|
108 | - $event_obj = null; |
|
109 | - } |
|
110 | - if ($event_obj instanceof \EE_Event) { |
|
111 | - return $event_obj->spaces_remaining_for_sale(); |
|
112 | - } else { |
|
113 | - throw new \EE_Error( |
|
114 | - sprintf( |
|
115 | - __('Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', |
|
116 | - 'event_espresso'), |
|
117 | - $wpdb_row['Event_CPT.ID'], |
|
118 | - print_r($wpdb_row, true) |
|
119 | - ) |
|
120 | - ); |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Counts the number of approved registrations for this event (regardless |
|
128 | - * of how many datetimes each registrations' ticket purchase is for) |
|
129 | - * |
|
130 | - * @param array $wpdb_row |
|
131 | - * @param \WP_REST_Request $request |
|
132 | - * @param Base $controller |
|
133 | - * @return int |
|
134 | - * @throws \EE_Error |
|
135 | - */ |
|
136 | - public static function spots_taken($wpdb_row, $request, $controller) |
|
137 | - { |
|
138 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
139 | - throw new \EE_Error( |
|
140 | - sprintf( |
|
141 | - __('Cannot calculate spots_taken because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
142 | - 'event_espresso'), |
|
143 | - print_r($wpdb_row, true) |
|
144 | - ) |
|
145 | - ); |
|
146 | - } |
|
147 | - return \EEM_Registration::instance()->count( |
|
148 | - array( |
|
149 | - array( |
|
150 | - 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
151 | - 'STS_ID' => \EEM_Registration::status_id_approved, |
|
152 | - ), |
|
153 | - ), |
|
154 | - 'REG_ID', |
|
155 | - true |
|
156 | - ); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Counts the number of pending-payment registrations for this event (regardless |
|
163 | - * of how many datetimes each registrations' ticket purchase is for) |
|
164 | - * |
|
165 | - * @param array $wpdb_row |
|
166 | - * @param \WP_REST_Request $request |
|
167 | - * @param Base $controller |
|
168 | - * @return int |
|
169 | - * @throws \EE_Error |
|
170 | - * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
|
171 | - */ |
|
172 | - public static function spots_taken_pending_payment($wpdb_row, $request, $controller) |
|
173 | - { |
|
174 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
175 | - throw new \EE_Error( |
|
176 | - sprintf( |
|
177 | - __('Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
178 | - 'event_espresso'), |
|
179 | - print_r($wpdb_row, true) |
|
180 | - ) |
|
181 | - ); |
|
182 | - } |
|
183 | - self::_verify_current_user_can('ee_read_registrations', 'spots_taken_pending_payment'); |
|
184 | - return \EEM_Registration::instance()->count( |
|
185 | - array( |
|
186 | - array( |
|
187 | - 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
188 | - 'STS_ID' => \EEM_Registration::status_id_pending_payment, |
|
189 | - ), |
|
190 | - ), |
|
191 | - 'REG_ID', |
|
192 | - true |
|
193 | - ); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * Counts all the registrations who have checked into one of this events' datetimes |
|
200 | - * See EE_Event::total_available_spaces( false ); |
|
201 | - * |
|
202 | - * @param array $wpdb_row |
|
203 | - * @param \WP_REST_Request $request |
|
204 | - * @param Base $controller |
|
205 | - * @return int|null if permission denied |
|
206 | - * @throws \EE_Error |
|
207 | - * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
|
208 | - */ |
|
209 | - public static function registrations_checked_in_count($wpdb_row, $request, $controller) |
|
210 | - { |
|
211 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
212 | - throw new \EE_Error( |
|
213 | - sprintf( |
|
214 | - __('Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
215 | - 'event_espresso'), |
|
216 | - print_r($wpdb_row, true) |
|
217 | - ) |
|
218 | - ); |
|
219 | - } |
|
220 | - self::_verify_current_user_can('ee_read_checkins', 'registrations_checked_in_count'); |
|
221 | - return \EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * Counts all the registrations who have checked out of one of this events' datetimes |
|
228 | - * See EE_Event::total_available_spaces( false ); |
|
229 | - * |
|
230 | - * @param array $wpdb_row |
|
231 | - * @param \WP_REST_Request $request |
|
232 | - * @param Base $controller |
|
233 | - * @return int |
|
234 | - * @throws \EE_Error |
|
235 | - * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
|
236 | - */ |
|
237 | - public static function registrations_checked_out_count($wpdb_row, $request, $controller) |
|
238 | - { |
|
239 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
240 | - throw new \EE_Error( |
|
241 | - sprintf( |
|
242 | - __('Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
243 | - 'event_espresso'), |
|
244 | - print_r($wpdb_row, true) |
|
245 | - ) |
|
246 | - ); |
|
247 | - } |
|
248 | - self::_verify_current_user_can('ee_read_checkins', 'registrations_checked_out_count'); |
|
249 | - return \EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false); |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * Gets the thumbnail image |
|
256 | - * |
|
257 | - * @param array $wpdb_row |
|
258 | - * @param \WP_REST_Request $request |
|
259 | - * @param Base $controller |
|
260 | - * @return array |
|
261 | - */ |
|
262 | - public static function image_thumbnail($wpdb_row, $request, $controller) |
|
263 | - { |
|
264 | - return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'thumbnail'); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * Gets the medium image |
|
271 | - * |
|
272 | - * @param array $wpdb_row |
|
273 | - * @param \WP_REST_Request $request |
|
274 | - * @param Base $controller |
|
275 | - * @return array |
|
276 | - */ |
|
277 | - public static function image_medium($wpdb_row, $request, $controller) |
|
278 | - { |
|
279 | - return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'medium'); |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * Gets the medium-large image |
|
286 | - * |
|
287 | - * @param array $wpdb_row |
|
288 | - * @param \WP_REST_Request $request |
|
289 | - * @param Base $controller |
|
290 | - * @return array |
|
291 | - */ |
|
292 | - public static function image_medium_large($wpdb_row, $request, $controller) |
|
293 | - { |
|
294 | - return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'medium_large'); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * Gets the large image |
|
301 | - * |
|
302 | - * @param array $wpdb_row |
|
303 | - * @param \WP_REST_Request $request |
|
304 | - * @param Base $controller |
|
305 | - * @return array |
|
306 | - */ |
|
307 | - public static function image_large($wpdb_row, $request, $controller) |
|
308 | - { |
|
309 | - return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'large'); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * Gets the post-thumbnail image |
|
316 | - * |
|
317 | - * @param array $wpdb_row |
|
318 | - * @param \WP_REST_Request $request |
|
319 | - * @param Base $controller |
|
320 | - * @return array |
|
321 | - */ |
|
322 | - public static function image_post_thumbnail($wpdb_row, $request, $controller) |
|
323 | - { |
|
324 | - return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'post-thumbnail'); |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Gets the full size image |
|
331 | - * |
|
332 | - * @param array $wpdb_row |
|
333 | - * @param \WP_REST_Request $request |
|
334 | - * @param Base $controller |
|
335 | - * @return array |
|
336 | - */ |
|
337 | - public static function image_full($wpdb_row, $request, $controller) |
|
338 | - { |
|
339 | - return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'full'); |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * Gets image specs and formats them for the display in the API, |
|
346 | - * according to the image size requested |
|
347 | - * |
|
348 | - * @param int $EVT_ID |
|
349 | - * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full |
|
350 | - * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original' |
|
351 | - */ |
|
352 | - protected static function _calculate_image_data($EVT_ID, $image_size) |
|
353 | - { |
|
354 | - $attachment_id = get_post_thumbnail_id($EVT_ID); |
|
355 | - $data = wp_get_attachment_image_src($attachment_id, $image_size); |
|
356 | - if (! $data) { |
|
357 | - return null; |
|
358 | - } |
|
359 | - if (isset($data[3])) { |
|
360 | - $generated = $data[3]; |
|
361 | - } else { |
|
362 | - $generated = true; |
|
363 | - } |
|
364 | - return array( |
|
365 | - 'url' => $data[0], |
|
366 | - 'width' => $data[1], |
|
367 | - 'height' => $data[2], |
|
368 | - 'generated' => $generated, |
|
369 | - ); |
|
370 | - } |
|
25 | + /** |
|
26 | + * Calculates the total spaces on the event (not subtracting sales, but taking |
|
27 | + * sales into account; so this is the optimum sales that CAN still be achieved) |
|
28 | + * See EE_Event::total_available_spaces( true ); |
|
29 | + * |
|
30 | + * @param array $wpdb_row |
|
31 | + * @param \WP_REST_Request $request |
|
32 | + * @param Base $controller |
|
33 | + * @return int |
|
34 | + * @throws \EE_Error |
|
35 | + */ |
|
36 | + public static function optimum_sales_at_start($wpdb_row, $request, $controller) |
|
37 | + { |
|
38 | + if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID'])) { |
|
39 | + $event_obj = \EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
40 | + } else { |
|
41 | + $event_obj = null; |
|
42 | + } |
|
43 | + if ($event_obj instanceof \EE_Event) { |
|
44 | + return $event_obj->total_available_spaces(true); |
|
45 | + } else { |
|
46 | + throw new \EE_Error( |
|
47 | + sprintf( |
|
48 | + __('Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', |
|
49 | + 'event_espresso'), |
|
50 | + $wpdb_row['Event_CPT.ID'], |
|
51 | + print_r($wpdb_row, true) |
|
52 | + ) |
|
53 | + ); |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * Calculates the total spaces on the event (ignoring all sales; so this is the optimum |
|
61 | + * sales that COULD have been achieved) |
|
62 | + * See EE_Event::total_available_spaces( true ); |
|
63 | + * |
|
64 | + * @param array $wpdb_row |
|
65 | + * @param \WP_REST_Request $request |
|
66 | + * @param Base $controller |
|
67 | + * @return int |
|
68 | + * @throws \EE_Error |
|
69 | + */ |
|
70 | + public static function optimum_sales_now($wpdb_row, $request, $controller) |
|
71 | + { |
|
72 | + if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID'])) { |
|
73 | + $event_obj = \EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
74 | + } else { |
|
75 | + $event_obj = null; |
|
76 | + } |
|
77 | + if ($event_obj instanceof \EE_Event) { |
|
78 | + return $event_obj->total_available_spaces(false); |
|
79 | + } else { |
|
80 | + throw new \EE_Error( |
|
81 | + sprintf( |
|
82 | + __('Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', |
|
83 | + 'event_espresso'), |
|
84 | + $wpdb_row['Event_CPT.ID'], |
|
85 | + print_r($wpdb_row, true) |
|
86 | + ) |
|
87 | + ); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Like optimum_sales_now, but minus total sales so far. |
|
95 | + * See EE_Event::spaces_remaining_for_sale( true ); |
|
96 | + * |
|
97 | + * @param array $wpdb_row |
|
98 | + * @param \WP_REST_Request $request |
|
99 | + * @param Base $controller |
|
100 | + * @return int |
|
101 | + * @throws \EE_Error |
|
102 | + */ |
|
103 | + public static function spaces_remaining($wpdb_row, $request, $controller) |
|
104 | + { |
|
105 | + if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID'])) { |
|
106 | + $event_obj = \EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
107 | + } else { |
|
108 | + $event_obj = null; |
|
109 | + } |
|
110 | + if ($event_obj instanceof \EE_Event) { |
|
111 | + return $event_obj->spaces_remaining_for_sale(); |
|
112 | + } else { |
|
113 | + throw new \EE_Error( |
|
114 | + sprintf( |
|
115 | + __('Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', |
|
116 | + 'event_espresso'), |
|
117 | + $wpdb_row['Event_CPT.ID'], |
|
118 | + print_r($wpdb_row, true) |
|
119 | + ) |
|
120 | + ); |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Counts the number of approved registrations for this event (regardless |
|
128 | + * of how many datetimes each registrations' ticket purchase is for) |
|
129 | + * |
|
130 | + * @param array $wpdb_row |
|
131 | + * @param \WP_REST_Request $request |
|
132 | + * @param Base $controller |
|
133 | + * @return int |
|
134 | + * @throws \EE_Error |
|
135 | + */ |
|
136 | + public static function spots_taken($wpdb_row, $request, $controller) |
|
137 | + { |
|
138 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
139 | + throw new \EE_Error( |
|
140 | + sprintf( |
|
141 | + __('Cannot calculate spots_taken because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
142 | + 'event_espresso'), |
|
143 | + print_r($wpdb_row, true) |
|
144 | + ) |
|
145 | + ); |
|
146 | + } |
|
147 | + return \EEM_Registration::instance()->count( |
|
148 | + array( |
|
149 | + array( |
|
150 | + 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
151 | + 'STS_ID' => \EEM_Registration::status_id_approved, |
|
152 | + ), |
|
153 | + ), |
|
154 | + 'REG_ID', |
|
155 | + true |
|
156 | + ); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Counts the number of pending-payment registrations for this event (regardless |
|
163 | + * of how many datetimes each registrations' ticket purchase is for) |
|
164 | + * |
|
165 | + * @param array $wpdb_row |
|
166 | + * @param \WP_REST_Request $request |
|
167 | + * @param Base $controller |
|
168 | + * @return int |
|
169 | + * @throws \EE_Error |
|
170 | + * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
|
171 | + */ |
|
172 | + public static function spots_taken_pending_payment($wpdb_row, $request, $controller) |
|
173 | + { |
|
174 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
175 | + throw new \EE_Error( |
|
176 | + sprintf( |
|
177 | + __('Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
178 | + 'event_espresso'), |
|
179 | + print_r($wpdb_row, true) |
|
180 | + ) |
|
181 | + ); |
|
182 | + } |
|
183 | + self::_verify_current_user_can('ee_read_registrations', 'spots_taken_pending_payment'); |
|
184 | + return \EEM_Registration::instance()->count( |
|
185 | + array( |
|
186 | + array( |
|
187 | + 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
188 | + 'STS_ID' => \EEM_Registration::status_id_pending_payment, |
|
189 | + ), |
|
190 | + ), |
|
191 | + 'REG_ID', |
|
192 | + true |
|
193 | + ); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * Counts all the registrations who have checked into one of this events' datetimes |
|
200 | + * See EE_Event::total_available_spaces( false ); |
|
201 | + * |
|
202 | + * @param array $wpdb_row |
|
203 | + * @param \WP_REST_Request $request |
|
204 | + * @param Base $controller |
|
205 | + * @return int|null if permission denied |
|
206 | + * @throws \EE_Error |
|
207 | + * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
|
208 | + */ |
|
209 | + public static function registrations_checked_in_count($wpdb_row, $request, $controller) |
|
210 | + { |
|
211 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
212 | + throw new \EE_Error( |
|
213 | + sprintf( |
|
214 | + __('Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
215 | + 'event_espresso'), |
|
216 | + print_r($wpdb_row, true) |
|
217 | + ) |
|
218 | + ); |
|
219 | + } |
|
220 | + self::_verify_current_user_can('ee_read_checkins', 'registrations_checked_in_count'); |
|
221 | + return \EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * Counts all the registrations who have checked out of one of this events' datetimes |
|
228 | + * See EE_Event::total_available_spaces( false ); |
|
229 | + * |
|
230 | + * @param array $wpdb_row |
|
231 | + * @param \WP_REST_Request $request |
|
232 | + * @param Base $controller |
|
233 | + * @return int |
|
234 | + * @throws \EE_Error |
|
235 | + * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception |
|
236 | + */ |
|
237 | + public static function registrations_checked_out_count($wpdb_row, $request, $controller) |
|
238 | + { |
|
239 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
240 | + throw new \EE_Error( |
|
241 | + sprintf( |
|
242 | + __('Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
243 | + 'event_espresso'), |
|
244 | + print_r($wpdb_row, true) |
|
245 | + ) |
|
246 | + ); |
|
247 | + } |
|
248 | + self::_verify_current_user_can('ee_read_checkins', 'registrations_checked_out_count'); |
|
249 | + return \EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false); |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * Gets the thumbnail image |
|
256 | + * |
|
257 | + * @param array $wpdb_row |
|
258 | + * @param \WP_REST_Request $request |
|
259 | + * @param Base $controller |
|
260 | + * @return array |
|
261 | + */ |
|
262 | + public static function image_thumbnail($wpdb_row, $request, $controller) |
|
263 | + { |
|
264 | + return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'thumbnail'); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * Gets the medium image |
|
271 | + * |
|
272 | + * @param array $wpdb_row |
|
273 | + * @param \WP_REST_Request $request |
|
274 | + * @param Base $controller |
|
275 | + * @return array |
|
276 | + */ |
|
277 | + public static function image_medium($wpdb_row, $request, $controller) |
|
278 | + { |
|
279 | + return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'medium'); |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * Gets the medium-large image |
|
286 | + * |
|
287 | + * @param array $wpdb_row |
|
288 | + * @param \WP_REST_Request $request |
|
289 | + * @param Base $controller |
|
290 | + * @return array |
|
291 | + */ |
|
292 | + public static function image_medium_large($wpdb_row, $request, $controller) |
|
293 | + { |
|
294 | + return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'medium_large'); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * Gets the large image |
|
301 | + * |
|
302 | + * @param array $wpdb_row |
|
303 | + * @param \WP_REST_Request $request |
|
304 | + * @param Base $controller |
|
305 | + * @return array |
|
306 | + */ |
|
307 | + public static function image_large($wpdb_row, $request, $controller) |
|
308 | + { |
|
309 | + return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'large'); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * Gets the post-thumbnail image |
|
316 | + * |
|
317 | + * @param array $wpdb_row |
|
318 | + * @param \WP_REST_Request $request |
|
319 | + * @param Base $controller |
|
320 | + * @return array |
|
321 | + */ |
|
322 | + public static function image_post_thumbnail($wpdb_row, $request, $controller) |
|
323 | + { |
|
324 | + return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'post-thumbnail'); |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Gets the full size image |
|
331 | + * |
|
332 | + * @param array $wpdb_row |
|
333 | + * @param \WP_REST_Request $request |
|
334 | + * @param Base $controller |
|
335 | + * @return array |
|
336 | + */ |
|
337 | + public static function image_full($wpdb_row, $request, $controller) |
|
338 | + { |
|
339 | + return self::_calculate_image_data($wpdb_row['Event_CPT.ID'], 'full'); |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * Gets image specs and formats them for the display in the API, |
|
346 | + * according to the image size requested |
|
347 | + * |
|
348 | + * @param int $EVT_ID |
|
349 | + * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full |
|
350 | + * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original' |
|
351 | + */ |
|
352 | + protected static function _calculate_image_data($EVT_ID, $image_size) |
|
353 | + { |
|
354 | + $attachment_id = get_post_thumbnail_id($EVT_ID); |
|
355 | + $data = wp_get_attachment_image_src($attachment_id, $image_size); |
|
356 | + if (! $data) { |
|
357 | + return null; |
|
358 | + } |
|
359 | + if (isset($data[3])) { |
|
360 | + $generated = $data[3]; |
|
361 | + } else { |
|
362 | + $generated = true; |
|
363 | + } |
|
364 | + return array( |
|
365 | + 'url' => $data[0], |
|
366 | + 'width' => $data[1], |
|
367 | + 'height' => $data[2], |
|
368 | + 'generated' => $generated, |
|
369 | + ); |
|
370 | + } |
|
371 | 371 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @author Mike Nelson |
14 | 14 | * @since $VID:$ |
15 | 15 | */ |
16 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
16 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
17 | 17 | exit('No direct script access allowed'); |
18 | 18 | } |
19 | 19 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public static function spots_taken($wpdb_row, $request, $controller) |
137 | 137 | { |
138 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
138 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
139 | 139 | throw new \EE_Error( |
140 | 140 | sprintf( |
141 | 141 | __('Cannot calculate spots_taken because the database row %1$s does not have an entry for "Event_CPT.ID"', |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public static function spots_taken_pending_payment($wpdb_row, $request, $controller) |
173 | 173 | { |
174 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
174 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
175 | 175 | throw new \EE_Error( |
176 | 176 | sprintf( |
177 | 177 | __('Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public static function registrations_checked_in_count($wpdb_row, $request, $controller) |
210 | 210 | { |
211 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
211 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
212 | 212 | throw new \EE_Error( |
213 | 213 | sprintf( |
214 | 214 | __('Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public static function registrations_checked_out_count($wpdb_row, $request, $controller) |
238 | 238 | { |
239 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
239 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
240 | 240 | throw new \EE_Error( |
241 | 241 | sprintf( |
242 | 242 | __('Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | { |
354 | 354 | $attachment_id = get_post_thumbnail_id($EVT_ID); |
355 | 355 | $data = wp_get_attachment_image_src($attachment_id, $image_size); |
356 | - if (! $data) { |
|
356 | + if ( ! $data) { |
|
357 | 357 | return null; |
358 | 358 | } |
359 | 359 | if (isset($data[3])) { |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * @since 4.8.35.rc.001 |
16 | 16 | */ |
17 | 17 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
18 | - exit('No direct script access allowed'); |
|
18 | + exit('No direct script access allowed'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | |
@@ -23,127 +23,127 @@ discard block |
||
23 | 23 | class Calculated_Model_Fields |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $_mapping; |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @param bool $refresh |
|
35 | - * @return array top-level-keys are model names (eg "Event") |
|
36 | - * next-level are the calculated field names AND method names on classes |
|
37 | - * which perform calculations, values are the fully qualified classnames which do the calculationss |
|
38 | - * These callbacks should accept as arguments: |
|
39 | - * the wpdb row results, |
|
40 | - * the WP_Request object, |
|
41 | - * the controller object |
|
42 | - */ |
|
43 | - public function mapping($refresh = false) |
|
44 | - { |
|
45 | - if (! $this->_mapping || $refresh) { |
|
46 | - $this->_mapping = $this->_generate_new_mapping(); |
|
47 | - } |
|
48 | - return $this->_mapping; |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * Generates anew mapping between model calculated fields and their callbacks |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - protected function _generate_new_mapping() |
|
59 | - { |
|
60 | - $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\'; |
|
61 | - $event_calculations_class = $rest_api_calculations_namespace . 'Event'; |
|
62 | - $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime'; |
|
63 | - $registration_class = $rest_api_calculations_namespace . 'Registration'; |
|
64 | - return apply_filters( |
|
65 | - 'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping', |
|
66 | - array( |
|
67 | - 'Event' => array( |
|
68 | - 'optimum_sales_at_start' => $event_calculations_class, |
|
69 | - 'optimum_sales_now' => $event_calculations_class, |
|
70 | - 'spots_taken' => $event_calculations_class, |
|
71 | - 'spots_taken_pending_payment' => $event_calculations_class, |
|
72 | - 'spaces_remaining' => $event_calculations_class, |
|
73 | - 'registrations_checked_in_count' => $event_calculations_class, |
|
74 | - 'registrations_checked_out_count' => $event_calculations_class, |
|
75 | - 'image_thumbnail' => $event_calculations_class, |
|
76 | - 'image_medium' => $event_calculations_class, |
|
77 | - 'image_medium_large' => $event_calculations_class, |
|
78 | - 'image_large' => $event_calculations_class, |
|
79 | - 'image_post_thumbnail' => $event_calculations_class, |
|
80 | - 'image_full' => $event_calculations_class, |
|
81 | - ), |
|
82 | - 'Datetime' => array( |
|
83 | - 'spaces_remaining_considering_tickets' => $datetime_calculations_class, |
|
84 | - 'registrations_checked_in_count' => $datetime_calculations_class, |
|
85 | - 'registrations_checked_out_count' => $datetime_calculations_class, |
|
86 | - 'spots_taken_pending_payment' => $datetime_calculations_class, |
|
87 | - ), |
|
88 | - 'Registration' => array( |
|
89 | - 'datetime_checkin_stati' => $registration_class, |
|
90 | - ), |
|
91 | - ) |
|
92 | - ); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * Gets the known calculated fields for model |
|
99 | - * |
|
100 | - * @param \EEM_Base $model |
|
101 | - * @return array allowable values for this field |
|
102 | - */ |
|
103 | - public function retrieve_calculated_fields_for_model(\EEM_Base $model) |
|
104 | - { |
|
105 | - $mapping = $this->mapping(); |
|
106 | - if (isset($mapping[$model->get_this_model_name()])) { |
|
107 | - return array_keys($mapping[$model->get_this_model_name()]); |
|
108 | - } else { |
|
109 | - return array(); |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * Retrieves the value for this calculation |
|
117 | - * |
|
118 | - * @param \EEM_Base type $model |
|
119 | - * @param string $field_name |
|
120 | - * @param array $wpdb_row |
|
121 | - * @param \WP_REST_Request |
|
122 | - * @param \EventEspresso\core\libraries\rest_api\controllers\Base $controller |
|
123 | - * @return mixed|null |
|
124 | - * @throws \EE_Error |
|
125 | - */ |
|
126 | - public function retrieve_calculated_field_value( |
|
127 | - \EEM_Base $model, |
|
128 | - $field_name, |
|
129 | - $wpdb_row, |
|
130 | - $rest_request, |
|
131 | - Base $controller |
|
132 | - ) { |
|
133 | - $mapping = $this->mapping(); |
|
134 | - if (isset($mapping[$model->get_this_model_name()]) |
|
135 | - && isset($mapping[$model->get_this_model_name()][$field_name]) |
|
136 | - ) { |
|
137 | - $classname = $mapping[$model->get_this_model_name()][$field_name]; |
|
138 | - return call_user_func(array($classname, $field_name), $wpdb_row, $rest_request, $controller); |
|
139 | - } |
|
140 | - throw new Rest_Exception( |
|
141 | - 'calculated_field_does_not_exist', |
|
142 | - sprintf( |
|
143 | - __('There is no calculated field %1$s on resource %2$s', 'event_espresso'), |
|
144 | - $field_name, |
|
145 | - $model->get_this_model_name() |
|
146 | - ) |
|
147 | - ); |
|
148 | - } |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $_mapping; |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @param bool $refresh |
|
35 | + * @return array top-level-keys are model names (eg "Event") |
|
36 | + * next-level are the calculated field names AND method names on classes |
|
37 | + * which perform calculations, values are the fully qualified classnames which do the calculationss |
|
38 | + * These callbacks should accept as arguments: |
|
39 | + * the wpdb row results, |
|
40 | + * the WP_Request object, |
|
41 | + * the controller object |
|
42 | + */ |
|
43 | + public function mapping($refresh = false) |
|
44 | + { |
|
45 | + if (! $this->_mapping || $refresh) { |
|
46 | + $this->_mapping = $this->_generate_new_mapping(); |
|
47 | + } |
|
48 | + return $this->_mapping; |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * Generates anew mapping between model calculated fields and their callbacks |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + protected function _generate_new_mapping() |
|
59 | + { |
|
60 | + $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\'; |
|
61 | + $event_calculations_class = $rest_api_calculations_namespace . 'Event'; |
|
62 | + $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime'; |
|
63 | + $registration_class = $rest_api_calculations_namespace . 'Registration'; |
|
64 | + return apply_filters( |
|
65 | + 'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping', |
|
66 | + array( |
|
67 | + 'Event' => array( |
|
68 | + 'optimum_sales_at_start' => $event_calculations_class, |
|
69 | + 'optimum_sales_now' => $event_calculations_class, |
|
70 | + 'spots_taken' => $event_calculations_class, |
|
71 | + 'spots_taken_pending_payment' => $event_calculations_class, |
|
72 | + 'spaces_remaining' => $event_calculations_class, |
|
73 | + 'registrations_checked_in_count' => $event_calculations_class, |
|
74 | + 'registrations_checked_out_count' => $event_calculations_class, |
|
75 | + 'image_thumbnail' => $event_calculations_class, |
|
76 | + 'image_medium' => $event_calculations_class, |
|
77 | + 'image_medium_large' => $event_calculations_class, |
|
78 | + 'image_large' => $event_calculations_class, |
|
79 | + 'image_post_thumbnail' => $event_calculations_class, |
|
80 | + 'image_full' => $event_calculations_class, |
|
81 | + ), |
|
82 | + 'Datetime' => array( |
|
83 | + 'spaces_remaining_considering_tickets' => $datetime_calculations_class, |
|
84 | + 'registrations_checked_in_count' => $datetime_calculations_class, |
|
85 | + 'registrations_checked_out_count' => $datetime_calculations_class, |
|
86 | + 'spots_taken_pending_payment' => $datetime_calculations_class, |
|
87 | + ), |
|
88 | + 'Registration' => array( |
|
89 | + 'datetime_checkin_stati' => $registration_class, |
|
90 | + ), |
|
91 | + ) |
|
92 | + ); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * Gets the known calculated fields for model |
|
99 | + * |
|
100 | + * @param \EEM_Base $model |
|
101 | + * @return array allowable values for this field |
|
102 | + */ |
|
103 | + public function retrieve_calculated_fields_for_model(\EEM_Base $model) |
|
104 | + { |
|
105 | + $mapping = $this->mapping(); |
|
106 | + if (isset($mapping[$model->get_this_model_name()])) { |
|
107 | + return array_keys($mapping[$model->get_this_model_name()]); |
|
108 | + } else { |
|
109 | + return array(); |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * Retrieves the value for this calculation |
|
117 | + * |
|
118 | + * @param \EEM_Base type $model |
|
119 | + * @param string $field_name |
|
120 | + * @param array $wpdb_row |
|
121 | + * @param \WP_REST_Request |
|
122 | + * @param \EventEspresso\core\libraries\rest_api\controllers\Base $controller |
|
123 | + * @return mixed|null |
|
124 | + * @throws \EE_Error |
|
125 | + */ |
|
126 | + public function retrieve_calculated_field_value( |
|
127 | + \EEM_Base $model, |
|
128 | + $field_name, |
|
129 | + $wpdb_row, |
|
130 | + $rest_request, |
|
131 | + Base $controller |
|
132 | + ) { |
|
133 | + $mapping = $this->mapping(); |
|
134 | + if (isset($mapping[$model->get_this_model_name()]) |
|
135 | + && isset($mapping[$model->get_this_model_name()][$field_name]) |
|
136 | + ) { |
|
137 | + $classname = $mapping[$model->get_this_model_name()][$field_name]; |
|
138 | + return call_user_func(array($classname, $field_name), $wpdb_row, $rest_request, $controller); |
|
139 | + } |
|
140 | + throw new Rest_Exception( |
|
141 | + 'calculated_field_does_not_exist', |
|
142 | + sprintf( |
|
143 | + __('There is no calculated field %1$s on resource %2$s', 'event_espresso'), |
|
144 | + $field_name, |
|
145 | + $model->get_this_model_name() |
|
146 | + ) |
|
147 | + ); |
|
148 | + } |
|
149 | 149 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * @author Mike Nelson |
15 | 15 | * @since 4.8.35.rc.001 |
16 | 16 | */ |
17 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
17 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
18 | 18 | exit('No direct script access allowed'); |
19 | 19 | } |
20 | 20 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function mapping($refresh = false) |
44 | 44 | { |
45 | - if (! $this->_mapping || $refresh) { |
|
45 | + if ( ! $this->_mapping || $refresh) { |
|
46 | 46 | $this->_mapping = $this->_generate_new_mapping(); |
47 | 47 | } |
48 | 48 | return $this->_mapping; |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | protected function _generate_new_mapping() |
59 | 59 | { |
60 | 60 | $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\'; |
61 | - $event_calculations_class = $rest_api_calculations_namespace . 'Event'; |
|
62 | - $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime'; |
|
63 | - $registration_class = $rest_api_calculations_namespace . 'Registration'; |
|
61 | + $event_calculations_class = $rest_api_calculations_namespace.'Event'; |
|
62 | + $datetime_calculations_class = $rest_api_calculations_namespace.'Datetime'; |
|
63 | + $registration_class = $rest_api_calculations_namespace.'Registration'; |
|
64 | 64 | return apply_filters( |
65 | 65 | 'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping', |
66 | 66 | array( |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
3 | 3 | |
4 | 4 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -17,134 +17,134 @@ discard block |
||
17 | 17 | class Capabilities |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * The current user can see at least SOME of these entities. |
|
22 | - * |
|
23 | - * @param \EEM_Base $model |
|
24 | - * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
|
25 | - * @return boolean |
|
26 | - */ |
|
27 | - public static function current_user_has_partial_access_to($model, $model_context = \EEM_Base::caps_read) |
|
28 | - { |
|
29 | - if ( |
|
30 | - apply_filters( |
|
31 | - 'FHEE__Capabilities__current_user_has_partial_access_to__override_begin', |
|
32 | - false, |
|
33 | - $model, |
|
34 | - $model |
|
35 | - ) |
|
36 | - ) { |
|
37 | - return true; |
|
38 | - } |
|
39 | - foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) { |
|
40 | - if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) { |
|
41 | - return false; |
|
42 | - } |
|
43 | - } |
|
44 | - if ( |
|
45 | - apply_filters( |
|
46 | - 'FHEE__Capabilities__current_user_has_partial_access_to__override_end', |
|
47 | - false, |
|
48 | - $model, |
|
49 | - $model |
|
50 | - ) |
|
51 | - ) { |
|
52 | - return false; |
|
53 | - } |
|
54 | - return true; |
|
55 | - } |
|
20 | + /** |
|
21 | + * The current user can see at least SOME of these entities. |
|
22 | + * |
|
23 | + * @param \EEM_Base $model |
|
24 | + * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
|
25 | + * @return boolean |
|
26 | + */ |
|
27 | + public static function current_user_has_partial_access_to($model, $model_context = \EEM_Base::caps_read) |
|
28 | + { |
|
29 | + if ( |
|
30 | + apply_filters( |
|
31 | + 'FHEE__Capabilities__current_user_has_partial_access_to__override_begin', |
|
32 | + false, |
|
33 | + $model, |
|
34 | + $model |
|
35 | + ) |
|
36 | + ) { |
|
37 | + return true; |
|
38 | + } |
|
39 | + foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) { |
|
40 | + if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) { |
|
41 | + return false; |
|
42 | + } |
|
43 | + } |
|
44 | + if ( |
|
45 | + apply_filters( |
|
46 | + 'FHEE__Capabilities__current_user_has_partial_access_to__override_end', |
|
47 | + false, |
|
48 | + $model, |
|
49 | + $model |
|
50 | + ) |
|
51 | + ) { |
|
52 | + return false; |
|
53 | + } |
|
54 | + return true; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Gets an array of all the capabilities the current user is missing that affected |
|
61 | - * the query |
|
62 | - * |
|
63 | - * @param \EEM_Base $model |
|
64 | - * @param string $request_type one of the constants on WP_JSON_Server |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - public static function get_missing_permissions($model, $request_type = \EEM_Base::caps_read) |
|
68 | - { |
|
69 | - return $model->caps_missing($request_type); |
|
70 | - } |
|
59 | + /** |
|
60 | + * Gets an array of all the capabilities the current user is missing that affected |
|
61 | + * the query |
|
62 | + * |
|
63 | + * @param \EEM_Base $model |
|
64 | + * @param string $request_type one of the constants on WP_JSON_Server |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + public static function get_missing_permissions($model, $request_type = \EEM_Base::caps_read) |
|
68 | + { |
|
69 | + return $model->caps_missing($request_type); |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * Gets a string of all the capabilities the current user is missing that affected |
|
76 | - * the query |
|
77 | - * |
|
78 | - * @param \EEM_Base $model |
|
79 | - * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public static function get_missing_permissions_string($model, $model_context = \EEM_Base::caps_read) |
|
83 | - { |
|
84 | - return implode(',', array_keys(self::get_missing_permissions($model, $model_context))); |
|
85 | - } |
|
74 | + /** |
|
75 | + * Gets a string of all the capabilities the current user is missing that affected |
|
76 | + * the query |
|
77 | + * |
|
78 | + * @param \EEM_Base $model |
|
79 | + * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public static function get_missing_permissions_string($model, $model_context = \EEM_Base::caps_read) |
|
83 | + { |
|
84 | + return implode(',', array_keys(self::get_missing_permissions($model, $model_context))); |
|
85 | + } |
|
86 | 86 | |
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * Takes a entity that's ready to be returned and removes fields which the user shouldn't be able to access. |
|
91 | - * |
|
92 | - * @param array $entity |
|
93 | - * @param \EEM_Base $model |
|
94 | - * @param string $request_type one of the return values from EEM_Base::valid_cap_contexts() |
|
95 | - * @param Model_Version_Info $model_version_info |
|
96 | - * @param string $primary_key_string result of EEM_Base::get_index_primary_key_string(), so that we can |
|
97 | - * use this with models that have no primary key |
|
98 | - * @return array ready for converting into json |
|
99 | - */ |
|
100 | - public static function filter_out_inaccessible_entity_fields( |
|
101 | - $entity, |
|
102 | - $model, |
|
103 | - $request_type, |
|
104 | - $model_version_info, |
|
105 | - $primary_key_string = null |
|
106 | - ) { |
|
107 | - //if they didn't provide the primary key string, we'll just hope we can figure it out |
|
108 | - //from the entity (although it's preferred client code does it, because the entity might be missing |
|
109 | - //necessary fields for creating the primary key string, or they could be named differently) |
|
110 | - if ($primary_key_string === null) { |
|
111 | - $primary_key_string = $model->get_index_primary_key_string( |
|
112 | - $model->deduce_fields_n_values_from_cols_n_values($entity) |
|
113 | - ); |
|
114 | - } |
|
115 | - //we only care to do this for frontend reads and when the user can't edit the item |
|
116 | - if ( |
|
117 | - $request_type !== \EEM_Base::caps_read |
|
118 | - || $model->exists( |
|
119 | - $model->alter_query_params_to_restrict_by_ID( |
|
120 | - $primary_key_string, |
|
121 | - array( |
|
122 | - 'default_where_conditions' => 'none', |
|
123 | - 'caps' => \EEM_Base::caps_edit, |
|
124 | - ) |
|
125 | - ) |
|
126 | - ) |
|
127 | - ) { |
|
128 | - return $entity; |
|
129 | - } |
|
130 | - foreach ($model->field_settings() as $field_name => $field_obj) { |
|
131 | - if ( |
|
132 | - $model_version_info->field_has_rendered_format($field_obj) |
|
133 | - && isset($entity[$field_name]) |
|
134 | - && is_array($entity[$field_name]) |
|
135 | - && isset($entity[$field_name]['raw']) |
|
136 | - ) { |
|
137 | - unset($entity[$field_name]['raw']); |
|
138 | - } |
|
139 | - } |
|
140 | - //theoretically we may want to filter out specific fields for specific models |
|
141 | - return apply_filters( |
|
142 | - 'FHEE__Capabilities__filter_out_inaccessible_entity_fields', |
|
143 | - $entity, |
|
144 | - $model, |
|
145 | - $request_type |
|
146 | - ); |
|
147 | - } |
|
89 | + /** |
|
90 | + * Takes a entity that's ready to be returned and removes fields which the user shouldn't be able to access. |
|
91 | + * |
|
92 | + * @param array $entity |
|
93 | + * @param \EEM_Base $model |
|
94 | + * @param string $request_type one of the return values from EEM_Base::valid_cap_contexts() |
|
95 | + * @param Model_Version_Info $model_version_info |
|
96 | + * @param string $primary_key_string result of EEM_Base::get_index_primary_key_string(), so that we can |
|
97 | + * use this with models that have no primary key |
|
98 | + * @return array ready for converting into json |
|
99 | + */ |
|
100 | + public static function filter_out_inaccessible_entity_fields( |
|
101 | + $entity, |
|
102 | + $model, |
|
103 | + $request_type, |
|
104 | + $model_version_info, |
|
105 | + $primary_key_string = null |
|
106 | + ) { |
|
107 | + //if they didn't provide the primary key string, we'll just hope we can figure it out |
|
108 | + //from the entity (although it's preferred client code does it, because the entity might be missing |
|
109 | + //necessary fields for creating the primary key string, or they could be named differently) |
|
110 | + if ($primary_key_string === null) { |
|
111 | + $primary_key_string = $model->get_index_primary_key_string( |
|
112 | + $model->deduce_fields_n_values_from_cols_n_values($entity) |
|
113 | + ); |
|
114 | + } |
|
115 | + //we only care to do this for frontend reads and when the user can't edit the item |
|
116 | + if ( |
|
117 | + $request_type !== \EEM_Base::caps_read |
|
118 | + || $model->exists( |
|
119 | + $model->alter_query_params_to_restrict_by_ID( |
|
120 | + $primary_key_string, |
|
121 | + array( |
|
122 | + 'default_where_conditions' => 'none', |
|
123 | + 'caps' => \EEM_Base::caps_edit, |
|
124 | + ) |
|
125 | + ) |
|
126 | + ) |
|
127 | + ) { |
|
128 | + return $entity; |
|
129 | + } |
|
130 | + foreach ($model->field_settings() as $field_name => $field_obj) { |
|
131 | + if ( |
|
132 | + $model_version_info->field_has_rendered_format($field_obj) |
|
133 | + && isset($entity[$field_name]) |
|
134 | + && is_array($entity[$field_name]) |
|
135 | + && isset($entity[$field_name]['raw']) |
|
136 | + ) { |
|
137 | + unset($entity[$field_name]['raw']); |
|
138 | + } |
|
139 | + } |
|
140 | + //theoretically we may want to filter out specific fields for specific models |
|
141 | + return apply_filters( |
|
142 | + 'FHEE__Capabilities__filter_out_inaccessible_entity_fields', |
|
143 | + $entity, |
|
144 | + $model, |
|
145 | + $request_type |
|
146 | + ); |
|
147 | + } |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | // End of file Capabilities.php |
151 | 151 | \ No newline at end of file |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
3 | 3 | |
4 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | 5 | exit('No direct script access allowed'); |
6 | 6 | } |
7 | 7 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\libraries\rest_api\Model_Data_Translator; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -21,123 +21,123 @@ discard block |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @param \WP_REST_Request $request |
|
26 | - * @return array|\WP_REST_Response |
|
27 | - */ |
|
28 | - public static function handle_request_models_meta(\WP_REST_Request $request) |
|
29 | - { |
|
30 | - $controller = new Meta(); |
|
31 | - try { |
|
32 | - $matches = $controller->parse_route( |
|
33 | - $request->get_route(), |
|
34 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . 'resources~', |
|
35 | - array('version')); |
|
36 | - if ($matches instanceof \WP_REST_Response) { |
|
37 | - return $matches; |
|
38 | - } |
|
39 | - $controller->set_requested_version($matches['version']); |
|
40 | - return $controller->send_response($controller->_get_models_metadata_entity()); |
|
41 | - } catch (\Exception $e) { |
|
42 | - return $controller->send_response($e); |
|
43 | - } |
|
44 | - } |
|
24 | + /** |
|
25 | + * @param \WP_REST_Request $request |
|
26 | + * @return array|\WP_REST_Response |
|
27 | + */ |
|
28 | + public static function handle_request_models_meta(\WP_REST_Request $request) |
|
29 | + { |
|
30 | + $controller = new Meta(); |
|
31 | + try { |
|
32 | + $matches = $controller->parse_route( |
|
33 | + $request->get_route(), |
|
34 | + '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . 'resources~', |
|
35 | + array('version')); |
|
36 | + if ($matches instanceof \WP_REST_Response) { |
|
37 | + return $matches; |
|
38 | + } |
|
39 | + $controller->set_requested_version($matches['version']); |
|
40 | + return $controller->send_response($controller->_get_models_metadata_entity()); |
|
41 | + } catch (\Exception $e) { |
|
42 | + return $controller->send_response($e); |
|
43 | + } |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | 47 | |
48 | - /* |
|
48 | + /* |
|
49 | 49 | * Gets the model metadata resource entity |
50 | 50 | * @return array for JSON response, describing all the models available in teh requested version |
51 | 51 | */ |
52 | - protected function _get_models_metadata_entity() |
|
53 | - { |
|
54 | - $response = array(); |
|
55 | - foreach ($this->get_model_version_info()->models_for_requested_version() as $model_name => $model_classname) { |
|
56 | - $model = $this->get_model_version_info()->load_model($model_name); |
|
57 | - $fields_json = array(); |
|
58 | - foreach ( |
|
59 | - $this->get_model_version_info()->fields_on_model_in_this_version($model) as $field_name => |
|
60 | - $field_obj |
|
61 | - ) { |
|
62 | - if ($this->get_model_version_info()->field_is_ignored($field_obj)) { |
|
63 | - continue; |
|
64 | - } |
|
65 | - if ($field_obj instanceof \EE_Boolean_Field) { |
|
66 | - $datatype = 'Boolean'; |
|
67 | - } elseif ($field_obj->get_wpdb_data_type() == '%d') { |
|
68 | - $datatype = 'Number'; |
|
69 | - } elseif ($field_name instanceof \EE_Serialized_Text_Field) { |
|
70 | - $datatype = 'Object'; |
|
71 | - } else { |
|
72 | - $datatype = 'String'; |
|
73 | - } |
|
74 | - $default_value = Model_Data_Translator::prepare_field_value_for_json( |
|
75 | - $field_obj, |
|
76 | - $field_obj->get_default_value(), |
|
77 | - $this->get_model_version_info()->requested_version() |
|
78 | - ); |
|
79 | - $field_json = array( |
|
80 | - 'name' => $field_name, |
|
81 | - 'nicename' => $field_obj->get_nicename(), |
|
82 | - 'has_rendered_format' => $this->get_model_version_info()->field_has_rendered_format($field_obj), |
|
83 | - 'has_pretty_format' => $this->get_model_version_info()->field_has_pretty_format($field_obj), |
|
84 | - 'type' => str_replace('EE_', '', get_class($field_obj)), |
|
85 | - 'datatype' => $datatype, |
|
86 | - 'nullable' => $field_obj->is_nullable(), |
|
87 | - 'default' => $default_value, |
|
88 | - 'table_alias' => $field_obj->get_table_alias(), |
|
89 | - 'table_column' => $field_obj->get_table_column(), |
|
90 | - ); |
|
91 | - $fields_json[$field_json['name']] = $field_json; |
|
92 | - } |
|
93 | - $fields_json = array_merge($fields_json, |
|
94 | - $this->get_model_version_info()->extra_resource_properties_for_model($model)); |
|
95 | - $response[$model_name]['fields'] = apply_filters('FHEE__Meta__handle_request_models_meta__fields', |
|
96 | - $fields_json, $model); |
|
97 | - $relations_json = array(); |
|
98 | - foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
99 | - $relation_json = array( |
|
100 | - 'name' => $relation_name, |
|
101 | - 'type' => str_replace('EE_', '', get_class($relation_obj)), |
|
102 | - 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false, |
|
103 | - ); |
|
104 | - $relations_json[$relation_name] = $relation_json; |
|
105 | - } |
|
106 | - $response[$model_name]['relations'] = apply_filters('FHEE__Meta__handle_request_models_meta__relations', |
|
107 | - $relations_json, $model); |
|
108 | - } |
|
109 | - return $response; |
|
110 | - } |
|
52 | + protected function _get_models_metadata_entity() |
|
53 | + { |
|
54 | + $response = array(); |
|
55 | + foreach ($this->get_model_version_info()->models_for_requested_version() as $model_name => $model_classname) { |
|
56 | + $model = $this->get_model_version_info()->load_model($model_name); |
|
57 | + $fields_json = array(); |
|
58 | + foreach ( |
|
59 | + $this->get_model_version_info()->fields_on_model_in_this_version($model) as $field_name => |
|
60 | + $field_obj |
|
61 | + ) { |
|
62 | + if ($this->get_model_version_info()->field_is_ignored($field_obj)) { |
|
63 | + continue; |
|
64 | + } |
|
65 | + if ($field_obj instanceof \EE_Boolean_Field) { |
|
66 | + $datatype = 'Boolean'; |
|
67 | + } elseif ($field_obj->get_wpdb_data_type() == '%d') { |
|
68 | + $datatype = 'Number'; |
|
69 | + } elseif ($field_name instanceof \EE_Serialized_Text_Field) { |
|
70 | + $datatype = 'Object'; |
|
71 | + } else { |
|
72 | + $datatype = 'String'; |
|
73 | + } |
|
74 | + $default_value = Model_Data_Translator::prepare_field_value_for_json( |
|
75 | + $field_obj, |
|
76 | + $field_obj->get_default_value(), |
|
77 | + $this->get_model_version_info()->requested_version() |
|
78 | + ); |
|
79 | + $field_json = array( |
|
80 | + 'name' => $field_name, |
|
81 | + 'nicename' => $field_obj->get_nicename(), |
|
82 | + 'has_rendered_format' => $this->get_model_version_info()->field_has_rendered_format($field_obj), |
|
83 | + 'has_pretty_format' => $this->get_model_version_info()->field_has_pretty_format($field_obj), |
|
84 | + 'type' => str_replace('EE_', '', get_class($field_obj)), |
|
85 | + 'datatype' => $datatype, |
|
86 | + 'nullable' => $field_obj->is_nullable(), |
|
87 | + 'default' => $default_value, |
|
88 | + 'table_alias' => $field_obj->get_table_alias(), |
|
89 | + 'table_column' => $field_obj->get_table_column(), |
|
90 | + ); |
|
91 | + $fields_json[$field_json['name']] = $field_json; |
|
92 | + } |
|
93 | + $fields_json = array_merge($fields_json, |
|
94 | + $this->get_model_version_info()->extra_resource_properties_for_model($model)); |
|
95 | + $response[$model_name]['fields'] = apply_filters('FHEE__Meta__handle_request_models_meta__fields', |
|
96 | + $fields_json, $model); |
|
97 | + $relations_json = array(); |
|
98 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
99 | + $relation_json = array( |
|
100 | + 'name' => $relation_name, |
|
101 | + 'type' => str_replace('EE_', '', get_class($relation_obj)), |
|
102 | + 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false, |
|
103 | + ); |
|
104 | + $relations_json[$relation_name] = $relation_json; |
|
105 | + } |
|
106 | + $response[$model_name]['relations'] = apply_filters('FHEE__Meta__handle_request_models_meta__relations', |
|
107 | + $relations_json, $model); |
|
108 | + } |
|
109 | + return $response; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | |
113 | 113 | |
114 | - /** |
|
115 | - * Adds EE metadata to the index |
|
116 | - * |
|
117 | - * @param \WP_REST_Response $rest_response_obj |
|
118 | - * @return \WP_REST_Response |
|
119 | - */ |
|
120 | - public static function filter_ee_metadata_into_index(\WP_REST_Response $rest_response_obj) |
|
121 | - { |
|
122 | - $response_data = $rest_response_obj->get_data(); |
|
123 | - $addons = array(); |
|
124 | - foreach (\EE_Registry::instance()->addons as $addon) { |
|
125 | - $addon_json = array( |
|
126 | - 'name' => $addon->name(), |
|
127 | - 'version' => $addon->version(), |
|
128 | - ); |
|
129 | - $addons[$addon_json['name']] = $addon_json; |
|
130 | - } |
|
131 | - $response_data['ee'] = array( |
|
132 | - 'version' => \EEM_System_Status::instance()->get_ee_version(), |
|
133 | - 'documentation_url' => 'https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API', |
|
134 | - 'addons' => $addons, |
|
135 | - 'maintenance_mode' => \EE_Maintenance_Mode::instance()->real_level(), |
|
136 | - 'served_core_versions' => array_keys(\EED_Core_Rest_Api::versions_served()), |
|
137 | - ); |
|
138 | - $rest_response_obj->set_data($response_data); |
|
139 | - return $rest_response_obj; |
|
140 | - } |
|
114 | + /** |
|
115 | + * Adds EE metadata to the index |
|
116 | + * |
|
117 | + * @param \WP_REST_Response $rest_response_obj |
|
118 | + * @return \WP_REST_Response |
|
119 | + */ |
|
120 | + public static function filter_ee_metadata_into_index(\WP_REST_Response $rest_response_obj) |
|
121 | + { |
|
122 | + $response_data = $rest_response_obj->get_data(); |
|
123 | + $addons = array(); |
|
124 | + foreach (\EE_Registry::instance()->addons as $addon) { |
|
125 | + $addon_json = array( |
|
126 | + 'name' => $addon->name(), |
|
127 | + 'version' => $addon->version(), |
|
128 | + ); |
|
129 | + $addons[$addon_json['name']] = $addon_json; |
|
130 | + } |
|
131 | + $response_data['ee'] = array( |
|
132 | + 'version' => \EEM_System_Status::instance()->get_ee_version(), |
|
133 | + 'documentation_url' => 'https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API', |
|
134 | + 'addons' => $addons, |
|
135 | + 'maintenance_mode' => \EE_Maintenance_Mode::instance()->real_level(), |
|
136 | + 'served_core_versions' => array_keys(\EED_Core_Rest_Api::versions_served()), |
|
137 | + ); |
|
138 | + $rest_response_obj->set_data($response_data); |
|
139 | + return $rest_response_obj; |
|
140 | + } |
|
141 | 141 | } |
142 | 142 | |
143 | 143 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | |
4 | 4 | use EventEspresso\core\libraries\rest_api\Model_Data_Translator; |
5 | 5 | |
6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | 7 | exit('No direct script access allowed'); |
8 | 8 | } |
9 | 9 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | try { |
32 | 32 | $matches = $controller->parse_route( |
33 | 33 | $request->get_route(), |
34 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . 'resources~', |
|
34 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'resources~', |
|
35 | 35 | array('version')); |
36 | 36 | if ($matches instanceof \WP_REST_Response) { |
37 | 37 | return $matches; |