@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @since $VID:$ |
20 | 20 | */ |
21 | 21 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
22 | - exit('No direct script access allowed'); |
|
22 | + exit('No direct script access allowed'); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | |
@@ -27,378 +27,378 @@ discard block |
||
27 | 27 | class Event extends Calculations_Base |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Calculates the total spaces on the event (not subtracting sales, but taking |
|
32 | - * sales into account; so this is the optimum sales that CAN still be achieved) |
|
33 | - * See EE_Event::total_available_spaces( true ); |
|
34 | - * |
|
35 | - * @param array $wpdb_row |
|
36 | - * @param \WP_REST_Request $request |
|
37 | - * @param Base $controller |
|
38 | - * @return int |
|
39 | - * @throws EE_Error |
|
40 | - */ |
|
41 | - public static function optimumSalesAtStart($wpdb_row, $request, $controller) |
|
42 | - { |
|
43 | - if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID'])) { |
|
44 | - $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
45 | - } else { |
|
46 | - $event_obj = null; |
|
47 | - } |
|
48 | - if ($event_obj instanceof EE_Event) { |
|
49 | - return $event_obj->total_available_spaces(); |
|
50 | - } else { |
|
51 | - throw new EE_Error( |
|
52 | - sprintf( |
|
53 | - __( |
|
54 | - // @codingStandardsIgnoreStart |
|
55 | - 'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', |
|
56 | - // @codingStandardsIgnoreEnd |
|
57 | - 'event_espresso' |
|
58 | - ), |
|
59 | - $wpdb_row['Event_CPT.ID'], |
|
60 | - print_r($wpdb_row, true) |
|
61 | - ) |
|
62 | - ); |
|
63 | - } |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * Calculates the total spaces on the event (ignoring all sales; so this is the optimum |
|
70 | - * sales that COULD have been achieved) |
|
71 | - * See EE_Event::total_available_spaces( true ); |
|
72 | - * |
|
73 | - * @param array $wpdb_row |
|
74 | - * @param \WP_REST_Request $request |
|
75 | - * @param Base $controller |
|
76 | - * @return int |
|
77 | - * @throws EE_Error |
|
78 | - */ |
|
79 | - public static function optimumSalesNow($wpdb_row, $request, $controller) |
|
80 | - { |
|
81 | - if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID'])) { |
|
82 | - $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
83 | - } else { |
|
84 | - $event_obj = null; |
|
85 | - } |
|
86 | - if ($event_obj instanceof EE_Event) { |
|
87 | - return $event_obj->total_available_spaces(true); |
|
88 | - } else { |
|
89 | - throw new EE_Error( |
|
90 | - sprintf( |
|
91 | - __( |
|
92 | - // @codingStandardsIgnoreStart |
|
93 | - 'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', |
|
94 | - // @codingStandardsIgnoreEnd |
|
95 | - 'event_espresso' |
|
96 | - ), |
|
97 | - $wpdb_row['Event_CPT.ID'], |
|
98 | - print_r($wpdb_row, true) |
|
99 | - ) |
|
100 | - ); |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Like optimum_sales_now, but minus total sales so far. |
|
108 | - * See EE_Event::spaces_remaining_for_sale( true ); |
|
109 | - * |
|
110 | - * @param array $wpdb_row |
|
111 | - * @param \WP_REST_Request $request |
|
112 | - * @param Base $controller |
|
113 | - * @return int |
|
114 | - * @throws EE_Error |
|
115 | - */ |
|
116 | - public static function spacesRemaining($wpdb_row, $request, $controller) |
|
117 | - { |
|
118 | - if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID'])) { |
|
119 | - $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
120 | - } else { |
|
121 | - $event_obj = null; |
|
122 | - } |
|
123 | - if ($event_obj instanceof EE_Event) { |
|
124 | - return $event_obj->spaces_remaining_for_sale(); |
|
125 | - } else { |
|
126 | - throw new EE_Error( |
|
127 | - sprintf( |
|
128 | - __( |
|
129 | - // @codingStandardsIgnoreStart |
|
130 | - 'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', |
|
131 | - // @codingStandardsIgnoreEnd |
|
132 | - 'event_espresso' |
|
133 | - ), |
|
134 | - $wpdb_row['Event_CPT.ID'], |
|
135 | - print_r($wpdb_row, true) |
|
136 | - ) |
|
137 | - ); |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * Counts the number of approved registrations for this event (regardless |
|
145 | - * of how many datetimes each registrations' ticket purchase is for) |
|
146 | - * |
|
147 | - * @param array $wpdb_row |
|
148 | - * @param \WP_REST_Request $request |
|
149 | - * @param Base $controller |
|
150 | - * @return int |
|
151 | - * @throws EE_Error |
|
152 | - */ |
|
153 | - public static function spotsTaken($wpdb_row, $request, $controller) |
|
154 | - { |
|
155 | - if (! (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']))) { |
|
156 | - throw new EE_Error( |
|
157 | - sprintf( |
|
158 | - __( |
|
159 | - // @codingStandardsIgnoreStart |
|
160 | - 'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"', |
|
161 | - // @codingStandardsIgnoreEnd |
|
162 | - 'event_espresso' |
|
163 | - ), |
|
164 | - print_r($wpdb_row, true) |
|
165 | - ) |
|
166 | - ); |
|
167 | - } |
|
168 | - return EEM_Registration::instance()->count( |
|
169 | - array( |
|
170 | - array( |
|
171 | - 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
172 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
173 | - ), |
|
174 | - ), |
|
175 | - 'REG_ID', |
|
176 | - true |
|
177 | - ); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Counts the number of pending-payment registrations for this event (regardless |
|
184 | - * of how many datetimes each registrations' ticket purchase is for) |
|
185 | - * |
|
186 | - * @param array $wpdb_row |
|
187 | - * @param \WP_REST_Request $request |
|
188 | - * @param Base $controller |
|
189 | - * @return int |
|
190 | - * @throws EE_Error |
|
191 | - * @throws RestException |
|
192 | - */ |
|
193 | - public static function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
194 | - { |
|
195 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
196 | - throw new EE_Error( |
|
197 | - sprintf( |
|
198 | - __( |
|
199 | - // @codingStandardsIgnoreStart |
|
200 | - 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
201 | - // @codingStandardsIgnoreEnd |
|
202 | - 'event_espresso' |
|
203 | - ), |
|
204 | - print_r($wpdb_row, true) |
|
205 | - ) |
|
206 | - ); |
|
207 | - } |
|
208 | - self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
209 | - return EEM_Registration::instance()->count( |
|
210 | - array( |
|
211 | - array( |
|
212 | - 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
213 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
214 | - ), |
|
215 | - ), |
|
216 | - 'REG_ID', |
|
217 | - true |
|
218 | - ); |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * Counts all the registrations who have checked into one of this events' datetimes |
|
225 | - * See EE_Event::total_available_spaces( false ); |
|
226 | - * |
|
227 | - * @param array $wpdb_row |
|
228 | - * @param \WP_REST_Request $request |
|
229 | - * @param Base $controller |
|
230 | - * @return int|null if permission denied |
|
231 | - * @throws EE_Error |
|
232 | - * @throws RestException |
|
233 | - */ |
|
234 | - public static function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
235 | - { |
|
236 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
237 | - throw new EE_Error( |
|
238 | - sprintf( |
|
239 | - __( |
|
240 | - // @codingStandardsIgnoreStart |
|
241 | - 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
242 | - // @codingStandardsIgnoreEnd |
|
243 | - 'event_espresso' |
|
244 | - ), |
|
245 | - print_r($wpdb_row, true) |
|
246 | - ) |
|
247 | - ); |
|
248 | - } |
|
249 | - self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
250 | - return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * Counts all the registrations who have checked out of one of this events' datetimes |
|
257 | - * See EE_Event::total_available_spaces( false ); |
|
258 | - * |
|
259 | - * @param array $wpdb_row |
|
260 | - * @param \WP_REST_Request $request |
|
261 | - * @param Base $controller |
|
262 | - * @return int |
|
263 | - * @throws EE_Error |
|
264 | - * @throws RestException |
|
265 | - */ |
|
266 | - public static function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
267 | - { |
|
268 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
269 | - throw new EE_Error( |
|
270 | - sprintf( |
|
271 | - __( |
|
272 | - // @codingStandardsIgnoreStart |
|
273 | - 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
274 | - // @codingStandardsIgnoreEnd |
|
275 | - 'event_espresso' |
|
276 | - ), |
|
277 | - print_r($wpdb_row, true) |
|
278 | - ) |
|
279 | - ); |
|
280 | - } |
|
281 | - self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
282 | - return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * Gets the thumbnail image |
|
289 | - * |
|
290 | - * @param array $wpdb_row |
|
291 | - * @param \WP_REST_Request $request |
|
292 | - * @param Base $controller |
|
293 | - * @return array |
|
294 | - */ |
|
295 | - public static function imageThumbnail($wpdb_row, $request, $controller) |
|
296 | - { |
|
297 | - return self::calculateImageData($wpdb_row['Event_CPT.ID'], 'thumbnail'); |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * Gets the medium image |
|
304 | - * |
|
305 | - * @param array $wpdb_row |
|
306 | - * @param \WP_REST_Request $request |
|
307 | - * @param Base $controller |
|
308 | - * @return array |
|
309 | - */ |
|
310 | - public static function imageMedium($wpdb_row, $request, $controller) |
|
311 | - { |
|
312 | - return self::calculateImageData($wpdb_row['Event_CPT.ID'], 'medium'); |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * Gets the medium-large image |
|
319 | - * |
|
320 | - * @param array $wpdb_row |
|
321 | - * @param \WP_REST_Request $request |
|
322 | - * @param Base $controller |
|
323 | - * @return array |
|
324 | - */ |
|
325 | - public static function imageMediumLarge($wpdb_row, $request, $controller) |
|
326 | - { |
|
327 | - return self::calculateImageData($wpdb_row['Event_CPT.ID'], 'medium_large'); |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * Gets the large image |
|
334 | - * |
|
335 | - * @param array $wpdb_row |
|
336 | - * @param \WP_REST_Request $request |
|
337 | - * @param Base $controller |
|
338 | - * @return array |
|
339 | - */ |
|
340 | - public static function imageLarge($wpdb_row, $request, $controller) |
|
341 | - { |
|
342 | - return self::calculateImageData($wpdb_row['Event_CPT.ID'], 'large'); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Gets the post-thumbnail image |
|
349 | - * |
|
350 | - * @param array $wpdb_row |
|
351 | - * @param \WP_REST_Request $request |
|
352 | - * @param Base $controller |
|
353 | - * @return array |
|
354 | - */ |
|
355 | - public static function imagePostThumbnail($wpdb_row, $request, $controller) |
|
356 | - { |
|
357 | - return self::calculateImageData($wpdb_row['Event_CPT.ID'], 'post-thumbnail'); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * Gets the full size image |
|
364 | - * |
|
365 | - * @param array $wpdb_row |
|
366 | - * @param \WP_REST_Request $request |
|
367 | - * @param Base $controller |
|
368 | - * @return array |
|
369 | - */ |
|
370 | - public static function imageFull($wpdb_row, $request, $controller) |
|
371 | - { |
|
372 | - return self::calculateImageData($wpdb_row['Event_CPT.ID'], 'full'); |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Gets image specs and formats them for the display in the API, |
|
379 | - * according to the image size requested |
|
380 | - * |
|
381 | - * @param int $EVT_ID |
|
382 | - * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full |
|
383 | - * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original' |
|
384 | - */ |
|
385 | - protected static function calculateImageData($EVT_ID, $image_size) |
|
386 | - { |
|
387 | - $attachment_id = get_post_thumbnail_id($EVT_ID); |
|
388 | - $data = wp_get_attachment_image_src($attachment_id, $image_size); |
|
389 | - if (! $data) { |
|
390 | - return null; |
|
391 | - } |
|
392 | - if (isset($data[3])) { |
|
393 | - $generated = $data[3]; |
|
394 | - } else { |
|
395 | - $generated = true; |
|
396 | - } |
|
397 | - return array( |
|
398 | - 'url' => $data[0], |
|
399 | - 'width' => $data[1], |
|
400 | - 'height' => $data[2], |
|
401 | - 'generated' => $generated, |
|
402 | - ); |
|
403 | - } |
|
30 | + /** |
|
31 | + * Calculates the total spaces on the event (not subtracting sales, but taking |
|
32 | + * sales into account; so this is the optimum sales that CAN still be achieved) |
|
33 | + * See EE_Event::total_available_spaces( true ); |
|
34 | + * |
|
35 | + * @param array $wpdb_row |
|
36 | + * @param \WP_REST_Request $request |
|
37 | + * @param Base $controller |
|
38 | + * @return int |
|
39 | + * @throws EE_Error |
|
40 | + */ |
|
41 | + public static function optimumSalesAtStart($wpdb_row, $request, $controller) |
|
42 | + { |
|
43 | + if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID'])) { |
|
44 | + $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
45 | + } else { |
|
46 | + $event_obj = null; |
|
47 | + } |
|
48 | + if ($event_obj instanceof EE_Event) { |
|
49 | + return $event_obj->total_available_spaces(); |
|
50 | + } else { |
|
51 | + throw new EE_Error( |
|
52 | + sprintf( |
|
53 | + __( |
|
54 | + // @codingStandardsIgnoreStart |
|
55 | + 'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', |
|
56 | + // @codingStandardsIgnoreEnd |
|
57 | + 'event_espresso' |
|
58 | + ), |
|
59 | + $wpdb_row['Event_CPT.ID'], |
|
60 | + print_r($wpdb_row, true) |
|
61 | + ) |
|
62 | + ); |
|
63 | + } |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * Calculates the total spaces on the event (ignoring all sales; so this is the optimum |
|
70 | + * sales that COULD have been achieved) |
|
71 | + * See EE_Event::total_available_spaces( true ); |
|
72 | + * |
|
73 | + * @param array $wpdb_row |
|
74 | + * @param \WP_REST_Request $request |
|
75 | + * @param Base $controller |
|
76 | + * @return int |
|
77 | + * @throws EE_Error |
|
78 | + */ |
|
79 | + public static function optimumSalesNow($wpdb_row, $request, $controller) |
|
80 | + { |
|
81 | + if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID'])) { |
|
82 | + $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
83 | + } else { |
|
84 | + $event_obj = null; |
|
85 | + } |
|
86 | + if ($event_obj instanceof EE_Event) { |
|
87 | + return $event_obj->total_available_spaces(true); |
|
88 | + } else { |
|
89 | + throw new EE_Error( |
|
90 | + sprintf( |
|
91 | + __( |
|
92 | + // @codingStandardsIgnoreStart |
|
93 | + 'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', |
|
94 | + // @codingStandardsIgnoreEnd |
|
95 | + 'event_espresso' |
|
96 | + ), |
|
97 | + $wpdb_row['Event_CPT.ID'], |
|
98 | + print_r($wpdb_row, true) |
|
99 | + ) |
|
100 | + ); |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Like optimum_sales_now, but minus total sales so far. |
|
108 | + * See EE_Event::spaces_remaining_for_sale( true ); |
|
109 | + * |
|
110 | + * @param array $wpdb_row |
|
111 | + * @param \WP_REST_Request $request |
|
112 | + * @param Base $controller |
|
113 | + * @return int |
|
114 | + * @throws EE_Error |
|
115 | + */ |
|
116 | + public static function spacesRemaining($wpdb_row, $request, $controller) |
|
117 | + { |
|
118 | + if (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID'])) { |
|
119 | + $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
120 | + } else { |
|
121 | + $event_obj = null; |
|
122 | + } |
|
123 | + if ($event_obj instanceof EE_Event) { |
|
124 | + return $event_obj->spaces_remaining_for_sale(); |
|
125 | + } else { |
|
126 | + throw new EE_Error( |
|
127 | + sprintf( |
|
128 | + __( |
|
129 | + // @codingStandardsIgnoreStart |
|
130 | + 'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', |
|
131 | + // @codingStandardsIgnoreEnd |
|
132 | + 'event_espresso' |
|
133 | + ), |
|
134 | + $wpdb_row['Event_CPT.ID'], |
|
135 | + print_r($wpdb_row, true) |
|
136 | + ) |
|
137 | + ); |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * Counts the number of approved registrations for this event (regardless |
|
145 | + * of how many datetimes each registrations' ticket purchase is for) |
|
146 | + * |
|
147 | + * @param array $wpdb_row |
|
148 | + * @param \WP_REST_Request $request |
|
149 | + * @param Base $controller |
|
150 | + * @return int |
|
151 | + * @throws EE_Error |
|
152 | + */ |
|
153 | + public static function spotsTaken($wpdb_row, $request, $controller) |
|
154 | + { |
|
155 | + if (! (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']))) { |
|
156 | + throw new EE_Error( |
|
157 | + sprintf( |
|
158 | + __( |
|
159 | + // @codingStandardsIgnoreStart |
|
160 | + 'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"', |
|
161 | + // @codingStandardsIgnoreEnd |
|
162 | + 'event_espresso' |
|
163 | + ), |
|
164 | + print_r($wpdb_row, true) |
|
165 | + ) |
|
166 | + ); |
|
167 | + } |
|
168 | + return EEM_Registration::instance()->count( |
|
169 | + array( |
|
170 | + array( |
|
171 | + 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
172 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
173 | + ), |
|
174 | + ), |
|
175 | + 'REG_ID', |
|
176 | + true |
|
177 | + ); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Counts the number of pending-payment registrations for this event (regardless |
|
184 | + * of how many datetimes each registrations' ticket purchase is for) |
|
185 | + * |
|
186 | + * @param array $wpdb_row |
|
187 | + * @param \WP_REST_Request $request |
|
188 | + * @param Base $controller |
|
189 | + * @return int |
|
190 | + * @throws EE_Error |
|
191 | + * @throws RestException |
|
192 | + */ |
|
193 | + public static function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
194 | + { |
|
195 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
196 | + throw new EE_Error( |
|
197 | + sprintf( |
|
198 | + __( |
|
199 | + // @codingStandardsIgnoreStart |
|
200 | + 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
201 | + // @codingStandardsIgnoreEnd |
|
202 | + 'event_espresso' |
|
203 | + ), |
|
204 | + print_r($wpdb_row, true) |
|
205 | + ) |
|
206 | + ); |
|
207 | + } |
|
208 | + self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
209 | + return EEM_Registration::instance()->count( |
|
210 | + array( |
|
211 | + array( |
|
212 | + 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
213 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
214 | + ), |
|
215 | + ), |
|
216 | + 'REG_ID', |
|
217 | + true |
|
218 | + ); |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * Counts all the registrations who have checked into one of this events' datetimes |
|
225 | + * See EE_Event::total_available_spaces( false ); |
|
226 | + * |
|
227 | + * @param array $wpdb_row |
|
228 | + * @param \WP_REST_Request $request |
|
229 | + * @param Base $controller |
|
230 | + * @return int|null if permission denied |
|
231 | + * @throws EE_Error |
|
232 | + * @throws RestException |
|
233 | + */ |
|
234 | + public static function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
235 | + { |
|
236 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
237 | + throw new EE_Error( |
|
238 | + sprintf( |
|
239 | + __( |
|
240 | + // @codingStandardsIgnoreStart |
|
241 | + 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
242 | + // @codingStandardsIgnoreEnd |
|
243 | + 'event_espresso' |
|
244 | + ), |
|
245 | + print_r($wpdb_row, true) |
|
246 | + ) |
|
247 | + ); |
|
248 | + } |
|
249 | + self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
250 | + return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true); |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * Counts all the registrations who have checked out of one of this events' datetimes |
|
257 | + * See EE_Event::total_available_spaces( false ); |
|
258 | + * |
|
259 | + * @param array $wpdb_row |
|
260 | + * @param \WP_REST_Request $request |
|
261 | + * @param Base $controller |
|
262 | + * @return int |
|
263 | + * @throws EE_Error |
|
264 | + * @throws RestException |
|
265 | + */ |
|
266 | + public static function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
267 | + { |
|
268 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
269 | + throw new EE_Error( |
|
270 | + sprintf( |
|
271 | + __( |
|
272 | + // @codingStandardsIgnoreStart |
|
273 | + 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
274 | + // @codingStandardsIgnoreEnd |
|
275 | + 'event_espresso' |
|
276 | + ), |
|
277 | + print_r($wpdb_row, true) |
|
278 | + ) |
|
279 | + ); |
|
280 | + } |
|
281 | + self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
282 | + return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * Gets the thumbnail image |
|
289 | + * |
|
290 | + * @param array $wpdb_row |
|
291 | + * @param \WP_REST_Request $request |
|
292 | + * @param Base $controller |
|
293 | + * @return array |
|
294 | + */ |
|
295 | + public static function imageThumbnail($wpdb_row, $request, $controller) |
|
296 | + { |
|
297 | + return self::calculateImageData($wpdb_row['Event_CPT.ID'], 'thumbnail'); |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * Gets the medium image |
|
304 | + * |
|
305 | + * @param array $wpdb_row |
|
306 | + * @param \WP_REST_Request $request |
|
307 | + * @param Base $controller |
|
308 | + * @return array |
|
309 | + */ |
|
310 | + public static function imageMedium($wpdb_row, $request, $controller) |
|
311 | + { |
|
312 | + return self::calculateImageData($wpdb_row['Event_CPT.ID'], 'medium'); |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * Gets the medium-large image |
|
319 | + * |
|
320 | + * @param array $wpdb_row |
|
321 | + * @param \WP_REST_Request $request |
|
322 | + * @param Base $controller |
|
323 | + * @return array |
|
324 | + */ |
|
325 | + public static function imageMediumLarge($wpdb_row, $request, $controller) |
|
326 | + { |
|
327 | + return self::calculateImageData($wpdb_row['Event_CPT.ID'], 'medium_large'); |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * Gets the large image |
|
334 | + * |
|
335 | + * @param array $wpdb_row |
|
336 | + * @param \WP_REST_Request $request |
|
337 | + * @param Base $controller |
|
338 | + * @return array |
|
339 | + */ |
|
340 | + public static function imageLarge($wpdb_row, $request, $controller) |
|
341 | + { |
|
342 | + return self::calculateImageData($wpdb_row['Event_CPT.ID'], 'large'); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Gets the post-thumbnail image |
|
349 | + * |
|
350 | + * @param array $wpdb_row |
|
351 | + * @param \WP_REST_Request $request |
|
352 | + * @param Base $controller |
|
353 | + * @return array |
|
354 | + */ |
|
355 | + public static function imagePostThumbnail($wpdb_row, $request, $controller) |
|
356 | + { |
|
357 | + return self::calculateImageData($wpdb_row['Event_CPT.ID'], 'post-thumbnail'); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * Gets the full size image |
|
364 | + * |
|
365 | + * @param array $wpdb_row |
|
366 | + * @param \WP_REST_Request $request |
|
367 | + * @param Base $controller |
|
368 | + * @return array |
|
369 | + */ |
|
370 | + public static function imageFull($wpdb_row, $request, $controller) |
|
371 | + { |
|
372 | + return self::calculateImageData($wpdb_row['Event_CPT.ID'], 'full'); |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Gets image specs and formats them for the display in the API, |
|
379 | + * according to the image size requested |
|
380 | + * |
|
381 | + * @param int $EVT_ID |
|
382 | + * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full |
|
383 | + * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original' |
|
384 | + */ |
|
385 | + protected static function calculateImageData($EVT_ID, $image_size) |
|
386 | + { |
|
387 | + $attachment_id = get_post_thumbnail_id($EVT_ID); |
|
388 | + $data = wp_get_attachment_image_src($attachment_id, $image_size); |
|
389 | + if (! $data) { |
|
390 | + return null; |
|
391 | + } |
|
392 | + if (isset($data[3])) { |
|
393 | + $generated = $data[3]; |
|
394 | + } else { |
|
395 | + $generated = true; |
|
396 | + } |
|
397 | + return array( |
|
398 | + 'url' => $data[0], |
|
399 | + 'width' => $data[1], |
|
400 | + 'height' => $data[2], |
|
401 | + 'generated' => $generated, |
|
402 | + ); |
|
403 | + } |
|
404 | 404 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @author Mike Nelson |
19 | 19 | * @since $VID:$ |
20 | 20 | */ |
21 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
21 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
22 | 22 | exit('No direct script access allowed'); |
23 | 23 | } |
24 | 24 | |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public static function spotsTaken($wpdb_row, $request, $controller) |
154 | 154 | { |
155 | - if (! (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']))) { |
|
155 | + if ( ! (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']))) { |
|
156 | 156 | throw new EE_Error( |
157 | 157 | sprintf( |
158 | 158 | __( |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | */ |
193 | 193 | public static function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
194 | 194 | { |
195 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
195 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
196 | 196 | throw new EE_Error( |
197 | 197 | sprintf( |
198 | 198 | __( |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | */ |
234 | 234 | public static function registrationsCheckedInCount($wpdb_row, $request, $controller) |
235 | 235 | { |
236 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
236 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
237 | 237 | throw new EE_Error( |
238 | 238 | sprintf( |
239 | 239 | __( |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public static function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
267 | 267 | { |
268 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
268 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Event_CPT.ID'])) { |
|
269 | 269 | throw new EE_Error( |
270 | 270 | sprintf( |
271 | 271 | __( |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | { |
387 | 387 | $attachment_id = get_post_thumbnail_id($EVT_ID); |
388 | 388 | $data = wp_get_attachment_image_src($attachment_id, $image_size); |
389 | - if (! $data) { |
|
389 | + if ( ! $data) { |
|
390 | 390 | return null; |
391 | 391 | } |
392 | 392 | if (isset($data[3])) { |