@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | use EventEspresso\core\libraries\rest_api\controllers\Base as Base; |
14 | 14 | use EventEspresso\core\libraries\rest_api\controllers\model\Read; |
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 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $force = false; |
64 | 64 | } |
65 | 65 | $reg = EEM_Registration::instance()->get_one_by_ID($reg_id); |
66 | - if (! $reg instanceof EE_Registration) { |
|
66 | + if ( ! $reg instanceof EE_Registration) { |
|
67 | 67 | return $this->sendResponse( |
68 | 68 | new WP_Error( |
69 | 69 | 'rest_registration_toggle_checkin_invalid_id', |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | ) |
77 | 77 | ); |
78 | 78 | } |
79 | - if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) { |
|
79 | + if ( ! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) { |
|
80 | 80 | return $this->sendResponse( |
81 | 81 | new WP_Error( |
82 | 82 | 'rest_user_cannot_toggle_checkin', |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $success = $reg->toggle_checkin_status($dtt_id, ! $force); |
92 | 92 | if ($success === false) { |
93 | 93 | //check if we know they can't check in because they're not approved and we aren't forcing |
94 | - if (! $reg->is_approved() && ! $force) { |
|
94 | + if ( ! $reg->is_approved() && ! $force) { |
|
95 | 95 | //rely on EE_Error::add_error messages to have been added to give more data about why it failed |
96 | 96 | return $this->sendResponse( |
97 | 97 | new WP_Error( |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | ), |
120 | 120 | ) |
121 | 121 | ); |
122 | - if (! $checkin instanceof EE_Checkin) { |
|
122 | + if ( ! $checkin instanceof EE_Checkin) { |
|
123 | 123 | return $this->sendResponse( |
124 | 124 | new WP_Error( |
125 | 125 | 'rest_toggle_checkin_error', |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | } |
135 | 135 | $get_request = new WP_REST_Request( |
136 | 136 | 'GET', |
137 | - '/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID() |
|
137 | + '/'.EED_Core_Rest_Api::ee_api_namespace.'v'.$version.'/checkins/'.$checkin->ID() |
|
138 | 138 | ); |
139 | 139 | $get_request->set_url_params( |
140 | 140 | array( |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | use EventEspresso\core\libraries\rest_api\controllers\model\Read; |
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 | |
@@ -31,126 +31,125 @@ discard block |
||
31 | 31 | class Checkin extends Base |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * @param WP_REST_Request $request |
|
36 | - * @param string $version |
|
37 | - * @return WP_Error|WP_REST_Response |
|
38 | - */ |
|
39 | - public static function handleRequestToggleCheckin(WP_REST_Request $request, $version) |
|
40 | - { |
|
41 | - $controller = new Checkin(); |
|
42 | - return $controller->createCheckinCheckoutObject($request, $version); |
|
43 | - } |
|
34 | + /** |
|
35 | + * @param WP_REST_Request $request |
|
36 | + * @param string $version |
|
37 | + * @return WP_Error|WP_REST_Response |
|
38 | + */ |
|
39 | + public static function handleRequestToggleCheckin(WP_REST_Request $request, $version) |
|
40 | + { |
|
41 | + $controller = new Checkin(); |
|
42 | + return $controller->createCheckinCheckoutObject($request, $version); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * Toggles whether the user is checked in or not. |
|
49 | - |
|
50 | - * |
|
51 | - * @param WP_REST_Request $request |
|
52 | - * @param string $version |
|
53 | - * @return WP_Error|WP_REST_Response |
|
54 | - */ |
|
55 | - protected function createCheckinCheckoutObject(WP_REST_Request $request, $version) |
|
56 | - { |
|
57 | - $reg_id = $request->get_param('REG_ID'); |
|
58 | - $dtt_id = $request->get_param('DTT_ID'); |
|
59 | - $force = $request->get_param('force'); |
|
60 | - if ($force == 'true') { |
|
61 | - $force = true; |
|
62 | - } else { |
|
63 | - $force = false; |
|
64 | - } |
|
65 | - $reg = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
66 | - if (! $reg instanceof EE_Registration) { |
|
67 | - return $this->sendResponse( |
|
68 | - new WP_Error( |
|
69 | - 'rest_registration_toggle_checkin_invalid_id', |
|
70 | - sprintf( |
|
71 | - __( |
|
72 | - 'You cannot checkin registration with ID %1$s because it doesn\'t exist.', |
|
73 | - 'event_espresso' |
|
74 | - ), |
|
75 | - $reg_id |
|
76 | - ), |
|
77 | - array('status' => 422) |
|
78 | - ) |
|
79 | - ); |
|
80 | - } |
|
81 | - if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) { |
|
82 | - return $this->sendResponse( |
|
83 | - new WP_Error( |
|
84 | - 'rest_user_cannot_toggle_checkin', |
|
85 | - sprintf( |
|
86 | - __('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'), |
|
87 | - $reg_id |
|
88 | - ), |
|
89 | - array('status' => 403) |
|
90 | - ) |
|
91 | - ); |
|
92 | - } |
|
93 | - $success = $reg->toggle_checkin_status($dtt_id, ! $force); |
|
94 | - if ($success === false) { |
|
95 | - //check if we know they can't check in because they're not approved and we aren't forcing |
|
96 | - if (! $reg->is_approved() && ! $force) { |
|
97 | - //rely on EE_Error::add_error messages to have been added to give more data about why it failed |
|
98 | - return $this->sendResponse( |
|
99 | - new WP_Error( |
|
100 | - 'rest_toggle_checkin_failed', |
|
101 | - __( |
|
102 | - // @codingStandardsIgnoreStart |
|
103 | - 'Registration check-in failed because the registration is not approved. You may attempt to force checking in though.', |
|
104 | - // @codingStandardsIgnoreEnd |
|
105 | - 'event_espresso' |
|
106 | - ) |
|
107 | - ) |
|
108 | - ); |
|
109 | - } |
|
110 | - return $this->sendResponse( |
|
111 | - new WP_Error( |
|
112 | - 'rest_toggle_checkin_failed_not_forceable', |
|
113 | - __('Registration checkin failed. Please see additional error data.', 'event_espresso') |
|
114 | - ) |
|
115 | - ); |
|
116 | - } |
|
117 | - $checkin = EEM_Checkin::instance()->get_one( |
|
118 | - array( |
|
119 | - array( |
|
120 | - 'REG_ID' => $reg_id, |
|
121 | - 'DTT_ID' => $dtt_id, |
|
122 | - ), |
|
123 | - 'order_by' => array( |
|
124 | - 'CHK_timestamp' => 'DESC', |
|
125 | - ), |
|
126 | - ) |
|
127 | - ); |
|
128 | - if (! $checkin instanceof EE_Checkin) { |
|
129 | - return $this->sendResponse( |
|
130 | - new WP_Error( |
|
131 | - 'rest_toggle_checkin_error', |
|
132 | - sprintf( |
|
133 | - __( |
|
134 | - // @codingStandardsIgnoreStart |
|
135 | - 'Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.', |
|
136 | - // @codingStandardsIgnoreEnd |
|
137 | - 'event_espresso' |
|
138 | - ), |
|
139 | - $reg_id, |
|
140 | - $dtt_id |
|
141 | - ) |
|
142 | - ) |
|
143 | - ); |
|
144 | - } |
|
145 | - $get_request = new WP_REST_Request( |
|
146 | - 'GET', |
|
147 | - '/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID() |
|
148 | - ); |
|
149 | - $get_request->set_url_params( |
|
150 | - array( |
|
151 | - 'id' => $checkin->ID(), |
|
152 | - ) |
|
153 | - ); |
|
154 | - return Read::handleRequestGetOne($get_request, $version, 'Checkin'); |
|
155 | - } |
|
47 | + /** |
|
48 | + * Toggles whether the user is checked in or not. |
|
49 | + * |
|
50 | + * @param WP_REST_Request $request |
|
51 | + * @param string $version |
|
52 | + * @return WP_Error|WP_REST_Response |
|
53 | + */ |
|
54 | + protected function createCheckinCheckoutObject(WP_REST_Request $request, $version) |
|
55 | + { |
|
56 | + $reg_id = $request->get_param('REG_ID'); |
|
57 | + $dtt_id = $request->get_param('DTT_ID'); |
|
58 | + $force = $request->get_param('force'); |
|
59 | + if ($force == 'true') { |
|
60 | + $force = true; |
|
61 | + } else { |
|
62 | + $force = false; |
|
63 | + } |
|
64 | + $reg = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
65 | + if (! $reg instanceof EE_Registration) { |
|
66 | + return $this->sendResponse( |
|
67 | + new WP_Error( |
|
68 | + 'rest_registration_toggle_checkin_invalid_id', |
|
69 | + sprintf( |
|
70 | + __( |
|
71 | + 'You cannot checkin registration with ID %1$s because it doesn\'t exist.', |
|
72 | + 'event_espresso' |
|
73 | + ), |
|
74 | + $reg_id |
|
75 | + ), |
|
76 | + array('status' => 422) |
|
77 | + ) |
|
78 | + ); |
|
79 | + } |
|
80 | + if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) { |
|
81 | + return $this->sendResponse( |
|
82 | + new WP_Error( |
|
83 | + 'rest_user_cannot_toggle_checkin', |
|
84 | + sprintf( |
|
85 | + __('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'), |
|
86 | + $reg_id |
|
87 | + ), |
|
88 | + array('status' => 403) |
|
89 | + ) |
|
90 | + ); |
|
91 | + } |
|
92 | + $success = $reg->toggle_checkin_status($dtt_id, ! $force); |
|
93 | + if ($success === false) { |
|
94 | + //check if we know they can't check in because they're not approved and we aren't forcing |
|
95 | + if (! $reg->is_approved() && ! $force) { |
|
96 | + //rely on EE_Error::add_error messages to have been added to give more data about why it failed |
|
97 | + return $this->sendResponse( |
|
98 | + new WP_Error( |
|
99 | + 'rest_toggle_checkin_failed', |
|
100 | + __( |
|
101 | + // @codingStandardsIgnoreStart |
|
102 | + 'Registration check-in failed because the registration is not approved. You may attempt to force checking in though.', |
|
103 | + // @codingStandardsIgnoreEnd |
|
104 | + 'event_espresso' |
|
105 | + ) |
|
106 | + ) |
|
107 | + ); |
|
108 | + } |
|
109 | + return $this->sendResponse( |
|
110 | + new WP_Error( |
|
111 | + 'rest_toggle_checkin_failed_not_forceable', |
|
112 | + __('Registration checkin failed. Please see additional error data.', 'event_espresso') |
|
113 | + ) |
|
114 | + ); |
|
115 | + } |
|
116 | + $checkin = EEM_Checkin::instance()->get_one( |
|
117 | + array( |
|
118 | + array( |
|
119 | + 'REG_ID' => $reg_id, |
|
120 | + 'DTT_ID' => $dtt_id, |
|
121 | + ), |
|
122 | + 'order_by' => array( |
|
123 | + 'CHK_timestamp' => 'DESC', |
|
124 | + ), |
|
125 | + ) |
|
126 | + ); |
|
127 | + if (! $checkin instanceof EE_Checkin) { |
|
128 | + return $this->sendResponse( |
|
129 | + new WP_Error( |
|
130 | + 'rest_toggle_checkin_error', |
|
131 | + sprintf( |
|
132 | + __( |
|
133 | + // @codingStandardsIgnoreStart |
|
134 | + 'Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.', |
|
135 | + // @codingStandardsIgnoreEnd |
|
136 | + 'event_espresso' |
|
137 | + ), |
|
138 | + $reg_id, |
|
139 | + $dtt_id |
|
140 | + ) |
|
141 | + ) |
|
142 | + ); |
|
143 | + } |
|
144 | + $get_request = new WP_REST_Request( |
|
145 | + 'GET', |
|
146 | + '/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID() |
|
147 | + ); |
|
148 | + $get_request->set_url_params( |
|
149 | + array( |
|
150 | + 'id' => $checkin->ID(), |
|
151 | + ) |
|
152 | + ); |
|
153 | + return Read::handleRequestGetOne($get_request, $version, 'Checkin'); |
|
154 | + } |
|
156 | 155 | } |
@@ -7,59 +7,59 @@ |
||
7 | 7 | class ChangesIn40833 extends ChangesInBase |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * Adds hooks so requests to 4.8.29 don't have the checkin endpoints |
|
12 | - */ |
|
13 | - public function setHooks() |
|
14 | - { |
|
15 | - //set a hook to remove the checkout/checkout endpoints if the request |
|
16 | - //is for lower than 4.8.33 |
|
17 | - add_filter( |
|
18 | - 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
19 | - array($this, 'removeCheckinRoutesEarlierThan4833'), |
|
20 | - 10, |
|
21 | - 2 |
|
22 | - ); |
|
23 | - add_filter( |
|
24 | - 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return', |
|
25 | - array($this, 'dontAddHeadersFromEeNotices'), |
|
26 | - 10, |
|
27 | - 2 |
|
28 | - ); |
|
29 | - } |
|
10 | + /** |
|
11 | + * Adds hooks so requests to 4.8.29 don't have the checkin endpoints |
|
12 | + */ |
|
13 | + public function setHooks() |
|
14 | + { |
|
15 | + //set a hook to remove the checkout/checkout endpoints if the request |
|
16 | + //is for lower than 4.8.33 |
|
17 | + add_filter( |
|
18 | + 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
19 | + array($this, 'removeCheckinRoutesEarlierThan4833'), |
|
20 | + 10, |
|
21 | + 2 |
|
22 | + ); |
|
23 | + add_filter( |
|
24 | + 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return', |
|
25 | + array($this, 'dontAddHeadersFromEeNotices'), |
|
26 | + 10, |
|
27 | + 2 |
|
28 | + ); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * Removes the checkin and checkout endpoints from the index for requests |
|
35 | - * to api versions lowers than 4.8.33 |
|
36 | - * |
|
37 | - * @param array $routes_on_this_version |
|
38 | - * @param string $version |
|
39 | - * @return array like $routes_on_this_version |
|
40 | - */ |
|
41 | - public function removeCheckinRoutesEarlierThan4833($routes_on_this_version, $version) |
|
42 | - { |
|
43 | - if ($this->appliesToVersion($version)) { |
|
44 | - unset($routes_on_this_version['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)']); |
|
45 | - } |
|
46 | - return $routes_on_this_version; |
|
47 | - } |
|
33 | + /** |
|
34 | + * Removes the checkin and checkout endpoints from the index for requests |
|
35 | + * to api versions lowers than 4.8.33 |
|
36 | + * |
|
37 | + * @param array $routes_on_this_version |
|
38 | + * @param string $version |
|
39 | + * @return array like $routes_on_this_version |
|
40 | + */ |
|
41 | + public function removeCheckinRoutesEarlierThan4833($routes_on_this_version, $version) |
|
42 | + { |
|
43 | + if ($this->appliesToVersion($version)) { |
|
44 | + unset($routes_on_this_version['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)']); |
|
45 | + } |
|
46 | + return $routes_on_this_version; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * We just added headers for notices in this version |
|
53 | - * |
|
54 | - * @param array $headers_from_ee_notices |
|
55 | - * @param string $requested_version |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function dontAddHeadersFromEeNotices($headers_from_ee_notices, $requested_version) |
|
59 | - { |
|
60 | - if ($this->appliesToVersion($requested_version)) { |
|
61 | - return array(); |
|
62 | - } |
|
63 | - return $headers_from_ee_notices; |
|
64 | - } |
|
51 | + /** |
|
52 | + * We just added headers for notices in this version |
|
53 | + * |
|
54 | + * @param array $headers_from_ee_notices |
|
55 | + * @param string $requested_version |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function dontAddHeadersFromEeNotices($headers_from_ee_notices, $requested_version) |
|
59 | + { |
|
60 | + if ($this->appliesToVersion($requested_version)) { |
|
61 | + return array(); |
|
62 | + } |
|
63 | + return $headers_from_ee_notices; |
|
64 | + } |
|
65 | 65 | } |
@@ -12,39 +12,39 @@ |
||
12 | 12 | class ChangesIn40834 extends ChangesInBase |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Adds hooks so requests to 4.8.29 don't have the checkin endpoints |
|
17 | - */ |
|
18 | - public function setHooks() |
|
19 | - { |
|
20 | - //set a hook to remove the checkout/checkout endpoints if the request |
|
21 | - //is for lower than 4.8.33 |
|
22 | - add_filter( |
|
23 | - 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
|
24 | - array($this, 'removeResponseHeaders'), |
|
25 | - 10, |
|
26 | - 3 |
|
27 | - ); |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * Removes the checkin and checkout endpoints from the index for requests |
|
34 | - * to api versions lowers than 4.8.33 |
|
35 | - * |
|
36 | - * @param array $response_headers |
|
37 | - * @param Base $controller |
|
38 | - * @param string $requested_version |
|
39 | - * @return array like $routes_on_this_version |
|
40 | - */ |
|
41 | - public function removeResponseHeaders($response_headers, $controller, $requested_version) |
|
42 | - { |
|
43 | - if ($controller instanceof Base |
|
44 | - && $this->appliesToVersion($requested_version) |
|
45 | - ) { |
|
46 | - return array(); |
|
47 | - } |
|
48 | - return $response_headers; |
|
49 | - } |
|
15 | + /** |
|
16 | + * Adds hooks so requests to 4.8.29 don't have the checkin endpoints |
|
17 | + */ |
|
18 | + public function setHooks() |
|
19 | + { |
|
20 | + //set a hook to remove the checkout/checkout endpoints if the request |
|
21 | + //is for lower than 4.8.33 |
|
22 | + add_filter( |
|
23 | + 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
|
24 | + array($this, 'removeResponseHeaders'), |
|
25 | + 10, |
|
26 | + 3 |
|
27 | + ); |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * Removes the checkin and checkout endpoints from the index for requests |
|
34 | + * to api versions lowers than 4.8.33 |
|
35 | + * |
|
36 | + * @param array $response_headers |
|
37 | + * @param Base $controller |
|
38 | + * @param string $requested_version |
|
39 | + * @return array like $routes_on_this_version |
|
40 | + */ |
|
41 | + public function removeResponseHeaders($response_headers, $controller, $requested_version) |
|
42 | + { |
|
43 | + if ($controller instanceof Base |
|
44 | + && $this->appliesToVersion($requested_version) |
|
45 | + ) { |
|
46 | + return array(); |
|
47 | + } |
|
48 | + return $response_headers; |
|
49 | + } |
|
50 | 50 | } |
@@ -16,179 +16,179 @@ |
||
16 | 16 | class ChangesIn40836 extends ChangesInBase |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Adds hooks so requests to 4.8.29 don't have the checkin endpoints |
|
21 | - */ |
|
22 | - public function setHooks() |
|
23 | - { |
|
24 | - //set a hook to remove the "calculate" query param |
|
25 | - add_filter( |
|
26 | - 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
27 | - array($this, 'removeCalculateQueryParam'), |
|
28 | - 10, |
|
29 | - 3 |
|
30 | - ); |
|
31 | - //don't add the _calculated_fields either |
|
32 | - add_filter( |
|
33 | - 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
|
34 | - array($this, 'removeCalculatedFieldsFromResponse'), |
|
35 | - 10, |
|
36 | - 5 |
|
37 | - ); |
|
38 | - //and also don't add the count headers |
|
39 | - add_filter( |
|
40 | - 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
|
41 | - array($this, 'removeHeadersNewInThisVersion'), |
|
42 | - 10, |
|
43 | - 3 |
|
44 | - ); |
|
45 | - //remove the old featured_image part of the response... |
|
46 | - add_filter( |
|
47 | - 'FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models', |
|
48 | - array($this, 'addOldFeaturedImagePartOfCptEntities'), |
|
49 | - 10, |
|
50 | - 5 |
|
51 | - ); |
|
52 | - //assuming ticket 9425's change gets pushed with 9406, we don't need to |
|
53 | - //remove it from the calculated fields on older requests (because this will |
|
54 | - //be the first version with calculated fields) |
|
55 | - //before this, infinity was -1, now it's null |
|
56 | - add_filter( |
|
57 | - 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
58 | - array($this, 'useNegativeOneForInfinityBeforeThisVersion'), |
|
59 | - 10, |
|
60 | - 4 |
|
61 | - ); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * Don't show "calculate" as an query param option in the index |
|
68 | - * |
|
69 | - * @param array $query_params |
|
70 | - * @param EEM_Base $model |
|
71 | - * @param string $version |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function removeCalculateQueryParam($query_params, EEM_Base $model, $version) |
|
75 | - { |
|
76 | - if ($this->appliesToVersion($version)) { |
|
77 | - unset($query_params['calculate']); |
|
78 | - } |
|
79 | - return $query_params; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Removes the "_calculate_fields" part of entity responses before 4.8.36 |
|
86 | - * |
|
87 | - * @param array $entity_response_array |
|
88 | - * @param EEM_Base $model |
|
89 | - * @param string $request_context |
|
90 | - * @param WP_REST_Request $request |
|
91 | - * @param Read $controller |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function removeCalculatedFieldsFromResponse( |
|
95 | - $entity_response_array, |
|
96 | - EEM_Base $model, |
|
97 | - $request_context, |
|
98 | - WP_REST_Request $request, |
|
99 | - Read $controller |
|
100 | - ) { |
|
101 | - if ($this->appliesToVersion($controller->getModelVersionInfo()->requestedVersion())) { |
|
102 | - unset($entity_response_array['_calculated_fields']); |
|
103 | - } |
|
104 | - return $entity_response_array; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * Removes the new headers for requests before 4.8.36 |
|
111 | - * |
|
112 | - * @param array $headers |
|
113 | - * @param Controller_Base $controller |
|
114 | - * @param string $version |
|
115 | - * @return array |
|
116 | - */ |
|
117 | - public function removeHeadersNewInThisVersion( |
|
118 | - $headers, |
|
119 | - Controller_Base $controller, |
|
120 | - $version |
|
121 | - ) { |
|
122 | - if ($this->appliesToVersion($version)) { |
|
123 | - $headers = array_diff_key( |
|
124 | - $headers, |
|
125 | - array_flip( |
|
126 | - array( |
|
127 | - Base::HEADER_PREFIX_FOR_WP . 'Total', |
|
128 | - Base::HEADER_PREFIX_FOR_WP . 'TotalPages', |
|
129 | - Base::HEADER_PREFIX_FOR_WP . 'PageSize', |
|
130 | - ) |
|
131 | - ) |
|
132 | - ); |
|
133 | - } |
|
134 | - return $headers; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * Puts the 'featured_image_url' back in for responses before 4.8.36. |
|
141 | - * |
|
142 | - * @param array $entity_response_array |
|
143 | - * @param EEM_Base $model |
|
144 | - * @param string $request_context |
|
145 | - * @param WP_REST_Request $request |
|
146 | - * @param Read $controller |
|
147 | - * @return array |
|
148 | - */ |
|
149 | - public function addOldFeaturedImagePartOfCptEntities( |
|
150 | - $entity_response_array, |
|
151 | - EEM_Base $model, |
|
152 | - $request_context, |
|
153 | - WP_REST_Request $request, |
|
154 | - Read $controller |
|
155 | - ) { |
|
156 | - if ($this->appliesToVersion($controller->getModelVersionInfo()->requestedVersion()) |
|
157 | - && $model instanceof \EEM_CPT_Base |
|
158 | - ) { |
|
159 | - $attachment = wp_get_attachment_image_src( |
|
160 | - get_post_thumbnail_id($entity_response_array[$model->primary_key_name()]), |
|
161 | - 'full' |
|
162 | - ); |
|
163 | - $entity_response_array['featured_image_url'] = ! empty($attachment) ? $attachment[0] : null; |
|
164 | - } |
|
165 | - return $entity_response_array; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * If the value was infinity, we now use null in our JSON responses, |
|
172 | - * but before this version we used -1. |
|
173 | - * |
|
174 | - * @param mixed $new_value |
|
175 | - * @param \EE_Model_Field_Base $field_obj |
|
176 | - * @param mixed $original_value |
|
177 | - * @param string $requested_value |
|
178 | - * @return mixed |
|
179 | - */ |
|
180 | - public function useNegativeOneForInfinityBeforeThisVersion( |
|
181 | - $new_value, |
|
182 | - $field_obj, |
|
183 | - $original_value, |
|
184 | - $requested_value |
|
185 | - ) { |
|
186 | - if ($this->appliesToVersion($requested_value) |
|
187 | - && $original_value === EE_INF |
|
188 | - ) { |
|
189 | - //return the old representation of infinity in the JSON |
|
190 | - return -1; |
|
191 | - } |
|
192 | - return $new_value; |
|
193 | - } |
|
19 | + /** |
|
20 | + * Adds hooks so requests to 4.8.29 don't have the checkin endpoints |
|
21 | + */ |
|
22 | + public function setHooks() |
|
23 | + { |
|
24 | + //set a hook to remove the "calculate" query param |
|
25 | + add_filter( |
|
26 | + 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
27 | + array($this, 'removeCalculateQueryParam'), |
|
28 | + 10, |
|
29 | + 3 |
|
30 | + ); |
|
31 | + //don't add the _calculated_fields either |
|
32 | + add_filter( |
|
33 | + 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
|
34 | + array($this, 'removeCalculatedFieldsFromResponse'), |
|
35 | + 10, |
|
36 | + 5 |
|
37 | + ); |
|
38 | + //and also don't add the count headers |
|
39 | + add_filter( |
|
40 | + 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
|
41 | + array($this, 'removeHeadersNewInThisVersion'), |
|
42 | + 10, |
|
43 | + 3 |
|
44 | + ); |
|
45 | + //remove the old featured_image part of the response... |
|
46 | + add_filter( |
|
47 | + 'FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models', |
|
48 | + array($this, 'addOldFeaturedImagePartOfCptEntities'), |
|
49 | + 10, |
|
50 | + 5 |
|
51 | + ); |
|
52 | + //assuming ticket 9425's change gets pushed with 9406, we don't need to |
|
53 | + //remove it from the calculated fields on older requests (because this will |
|
54 | + //be the first version with calculated fields) |
|
55 | + //before this, infinity was -1, now it's null |
|
56 | + add_filter( |
|
57 | + 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
58 | + array($this, 'useNegativeOneForInfinityBeforeThisVersion'), |
|
59 | + 10, |
|
60 | + 4 |
|
61 | + ); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * Don't show "calculate" as an query param option in the index |
|
68 | + * |
|
69 | + * @param array $query_params |
|
70 | + * @param EEM_Base $model |
|
71 | + * @param string $version |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function removeCalculateQueryParam($query_params, EEM_Base $model, $version) |
|
75 | + { |
|
76 | + if ($this->appliesToVersion($version)) { |
|
77 | + unset($query_params['calculate']); |
|
78 | + } |
|
79 | + return $query_params; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Removes the "_calculate_fields" part of entity responses before 4.8.36 |
|
86 | + * |
|
87 | + * @param array $entity_response_array |
|
88 | + * @param EEM_Base $model |
|
89 | + * @param string $request_context |
|
90 | + * @param WP_REST_Request $request |
|
91 | + * @param Read $controller |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function removeCalculatedFieldsFromResponse( |
|
95 | + $entity_response_array, |
|
96 | + EEM_Base $model, |
|
97 | + $request_context, |
|
98 | + WP_REST_Request $request, |
|
99 | + Read $controller |
|
100 | + ) { |
|
101 | + if ($this->appliesToVersion($controller->getModelVersionInfo()->requestedVersion())) { |
|
102 | + unset($entity_response_array['_calculated_fields']); |
|
103 | + } |
|
104 | + return $entity_response_array; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * Removes the new headers for requests before 4.8.36 |
|
111 | + * |
|
112 | + * @param array $headers |
|
113 | + * @param Controller_Base $controller |
|
114 | + * @param string $version |
|
115 | + * @return array |
|
116 | + */ |
|
117 | + public function removeHeadersNewInThisVersion( |
|
118 | + $headers, |
|
119 | + Controller_Base $controller, |
|
120 | + $version |
|
121 | + ) { |
|
122 | + if ($this->appliesToVersion($version)) { |
|
123 | + $headers = array_diff_key( |
|
124 | + $headers, |
|
125 | + array_flip( |
|
126 | + array( |
|
127 | + Base::HEADER_PREFIX_FOR_WP . 'Total', |
|
128 | + Base::HEADER_PREFIX_FOR_WP . 'TotalPages', |
|
129 | + Base::HEADER_PREFIX_FOR_WP . 'PageSize', |
|
130 | + ) |
|
131 | + ) |
|
132 | + ); |
|
133 | + } |
|
134 | + return $headers; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * Puts the 'featured_image_url' back in for responses before 4.8.36. |
|
141 | + * |
|
142 | + * @param array $entity_response_array |
|
143 | + * @param EEM_Base $model |
|
144 | + * @param string $request_context |
|
145 | + * @param WP_REST_Request $request |
|
146 | + * @param Read $controller |
|
147 | + * @return array |
|
148 | + */ |
|
149 | + public function addOldFeaturedImagePartOfCptEntities( |
|
150 | + $entity_response_array, |
|
151 | + EEM_Base $model, |
|
152 | + $request_context, |
|
153 | + WP_REST_Request $request, |
|
154 | + Read $controller |
|
155 | + ) { |
|
156 | + if ($this->appliesToVersion($controller->getModelVersionInfo()->requestedVersion()) |
|
157 | + && $model instanceof \EEM_CPT_Base |
|
158 | + ) { |
|
159 | + $attachment = wp_get_attachment_image_src( |
|
160 | + get_post_thumbnail_id($entity_response_array[$model->primary_key_name()]), |
|
161 | + 'full' |
|
162 | + ); |
|
163 | + $entity_response_array['featured_image_url'] = ! empty($attachment) ? $attachment[0] : null; |
|
164 | + } |
|
165 | + return $entity_response_array; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * If the value was infinity, we now use null in our JSON responses, |
|
172 | + * but before this version we used -1. |
|
173 | + * |
|
174 | + * @param mixed $new_value |
|
175 | + * @param \EE_Model_Field_Base $field_obj |
|
176 | + * @param mixed $original_value |
|
177 | + * @param string $requested_value |
|
178 | + * @return mixed |
|
179 | + */ |
|
180 | + public function useNegativeOneForInfinityBeforeThisVersion( |
|
181 | + $new_value, |
|
182 | + $field_obj, |
|
183 | + $original_value, |
|
184 | + $requested_value |
|
185 | + ) { |
|
186 | + if ($this->appliesToVersion($requested_value) |
|
187 | + && $original_value === EE_INF |
|
188 | + ) { |
|
189 | + //return the old representation of infinity in the JSON |
|
190 | + return -1; |
|
191 | + } |
|
192 | + return $new_value; |
|
193 | + } |
|
194 | 194 | } |
@@ -124,9 +124,9 @@ |
||
124 | 124 | $headers, |
125 | 125 | array_flip( |
126 | 126 | array( |
127 | - Base::HEADER_PREFIX_FOR_WP . 'Total', |
|
128 | - Base::HEADER_PREFIX_FOR_WP . 'TotalPages', |
|
129 | - Base::HEADER_PREFIX_FOR_WP . 'PageSize', |
|
127 | + Base::HEADER_PREFIX_FOR_WP.'Total', |
|
128 | + Base::HEADER_PREFIX_FOR_WP.'TotalPages', |
|
129 | + Base::HEADER_PREFIX_FOR_WP.'PageSize', |
|
130 | 130 | ) |
131 | 131 | ) |
132 | 132 | ); |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @since $VID:$ |
18 | 18 | */ |
19 | 19 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
20 | - exit('No direct script access allowed'); |
|
20 | + exit('No direct script access allowed'); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | |
@@ -25,144 +25,144 @@ discard block |
||
25 | 25 | class Datetime extends Calculations_Base |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Calculates the total spaces available on the datetime, taking into account |
|
30 | - * ticket limits too. |
|
31 | - * |
|
32 | - * @see EE_Datetime::spaces_remaining( true ) |
|
33 | - * @param array $wpdb_row |
|
34 | - * @param \WP_REST_Request $request |
|
35 | - * @param Controller_Base $controller |
|
36 | - * @return int |
|
37 | - * @throws \EE_Error |
|
38 | - */ |
|
39 | - public static function spacesRemainingConsideringTickets($wpdb_row, $request, $controller) |
|
40 | - { |
|
41 | - if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) { |
|
42 | - $dtt_obj = EEM_Datetime::instance()->get_one_by_ID($wpdb_row['Datetime.DTT_ID']); |
|
43 | - } else { |
|
44 | - $dtt_obj = null; |
|
45 | - } |
|
46 | - if ($dtt_obj instanceof EE_Datetime) { |
|
47 | - return $dtt_obj->spaces_remaining(true); |
|
48 | - } else { |
|
49 | - throw new \EE_Error( |
|
50 | - sprintf( |
|
51 | - __( |
|
52 | - // @codingStandardsIgnoreStart |
|
53 | - 'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found', |
|
54 | - // @codingStandardsIgnoreEnd |
|
55 | - 'event_espresso' |
|
56 | - ), |
|
57 | - $wpdb_row['Datetime.DTT_ID'], |
|
58 | - print_r($wpdb_row, true) |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
62 | - } |
|
28 | + /** |
|
29 | + * Calculates the total spaces available on the datetime, taking into account |
|
30 | + * ticket limits too. |
|
31 | + * |
|
32 | + * @see EE_Datetime::spaces_remaining( true ) |
|
33 | + * @param array $wpdb_row |
|
34 | + * @param \WP_REST_Request $request |
|
35 | + * @param Controller_Base $controller |
|
36 | + * @return int |
|
37 | + * @throws \EE_Error |
|
38 | + */ |
|
39 | + public static function spacesRemainingConsideringTickets($wpdb_row, $request, $controller) |
|
40 | + { |
|
41 | + if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) { |
|
42 | + $dtt_obj = EEM_Datetime::instance()->get_one_by_ID($wpdb_row['Datetime.DTT_ID']); |
|
43 | + } else { |
|
44 | + $dtt_obj = null; |
|
45 | + } |
|
46 | + if ($dtt_obj instanceof EE_Datetime) { |
|
47 | + return $dtt_obj->spaces_remaining(true); |
|
48 | + } else { |
|
49 | + throw new \EE_Error( |
|
50 | + sprintf( |
|
51 | + __( |
|
52 | + // @codingStandardsIgnoreStart |
|
53 | + 'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found', |
|
54 | + // @codingStandardsIgnoreEnd |
|
55 | + 'event_espresso' |
|
56 | + ), |
|
57 | + $wpdb_row['Datetime.DTT_ID'], |
|
58 | + print_r($wpdb_row, true) |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * Counts registrations who have checked into this datetime |
|
68 | - * |
|
69 | - * @param array $wpdb_row |
|
70 | - * @param \WP_REST_Request $request |
|
71 | - * @param Controller_Base $controller |
|
72 | - * @return int |
|
73 | - * @throws \EE_Error |
|
74 | - * @throws \EventEspresso\core\libraries\rest_api\RestException |
|
75 | - */ |
|
76 | - public static function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
77 | - { |
|
78 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
79 | - throw new \EE_Error( |
|
80 | - sprintf( |
|
81 | - __( |
|
82 | - // @codingStandardsIgnoreStart |
|
83 | - 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
84 | - // @codingStandardsIgnoreEnd |
|
85 | - 'event_espresso' |
|
86 | - ), |
|
87 | - print_r($wpdb_row, true) |
|
88 | - ) |
|
89 | - ); |
|
90 | - } |
|
91 | - self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
92 | - return EEM_Registration::instance() |
|
93 | - ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true); |
|
94 | - } |
|
66 | + /** |
|
67 | + * Counts registrations who have checked into this datetime |
|
68 | + * |
|
69 | + * @param array $wpdb_row |
|
70 | + * @param \WP_REST_Request $request |
|
71 | + * @param Controller_Base $controller |
|
72 | + * @return int |
|
73 | + * @throws \EE_Error |
|
74 | + * @throws \EventEspresso\core\libraries\rest_api\RestException |
|
75 | + */ |
|
76 | + public static function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
77 | + { |
|
78 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
79 | + throw new \EE_Error( |
|
80 | + sprintf( |
|
81 | + __( |
|
82 | + // @codingStandardsIgnoreStart |
|
83 | + 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
84 | + // @codingStandardsIgnoreEnd |
|
85 | + 'event_espresso' |
|
86 | + ), |
|
87 | + print_r($wpdb_row, true) |
|
88 | + ) |
|
89 | + ); |
|
90 | + } |
|
91 | + self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
92 | + return EEM_Registration::instance() |
|
93 | + ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true); |
|
94 | + } |
|
95 | 95 | |
96 | 96 | |
97 | 97 | |
98 | - /** |
|
99 | - * Counts registrations who have checked out of this datetime |
|
100 | - * |
|
101 | - * @param array $wpdb_row |
|
102 | - * @param \WP_REST_Request $request |
|
103 | - * @param Controller_Base $controller |
|
104 | - * @return int |
|
105 | - * @throws \EE_Error |
|
106 | - * @throws \EventEspresso\core\libraries\rest_api\RestException |
|
107 | - */ |
|
108 | - public static function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
109 | - { |
|
110 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
111 | - throw new \EE_Error( |
|
112 | - sprintf( |
|
113 | - __( |
|
114 | - // @codingStandardsIgnoreStart |
|
115 | - 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
116 | - // @codingStandardsIgnoreEnd |
|
117 | - 'event_espresso' |
|
118 | - ), |
|
119 | - print_r($wpdb_row, true) |
|
120 | - ) |
|
121 | - ); |
|
122 | - } |
|
123 | - self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
124 | - return EEM_Registration::instance() |
|
125 | - ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false); |
|
126 | - } |
|
98 | + /** |
|
99 | + * Counts registrations who have checked out of this datetime |
|
100 | + * |
|
101 | + * @param array $wpdb_row |
|
102 | + * @param \WP_REST_Request $request |
|
103 | + * @param Controller_Base $controller |
|
104 | + * @return int |
|
105 | + * @throws \EE_Error |
|
106 | + * @throws \EventEspresso\core\libraries\rest_api\RestException |
|
107 | + */ |
|
108 | + public static function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
109 | + { |
|
110 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
111 | + throw new \EE_Error( |
|
112 | + sprintf( |
|
113 | + __( |
|
114 | + // @codingStandardsIgnoreStart |
|
115 | + 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
116 | + // @codingStandardsIgnoreEnd |
|
117 | + 'event_espresso' |
|
118 | + ), |
|
119 | + print_r($wpdb_row, true) |
|
120 | + ) |
|
121 | + ); |
|
122 | + } |
|
123 | + self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
124 | + return EEM_Registration::instance() |
|
125 | + ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false); |
|
126 | + } |
|
127 | 127 | |
128 | 128 | |
129 | 129 | |
130 | - /** |
|
131 | - * Counts the number of pending-payment registrations for this event (regardless |
|
132 | - * of how many datetimes each registrations' ticket purchase is for) |
|
133 | - * |
|
134 | - * @param array $wpdb_row |
|
135 | - * @param \WP_REST_Request $request |
|
136 | - * @param Controller_Base $controller |
|
137 | - * @return int |
|
138 | - * @throws \EE_Error |
|
139 | - * @throws \EventEspresso\core\libraries\rest_api\RestException |
|
140 | - */ |
|
141 | - public static function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
142 | - { |
|
143 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
144 | - throw new \EE_Error( |
|
145 | - sprintf( |
|
146 | - __( |
|
147 | - // @codingStandardsIgnoreStart |
|
148 | - 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
149 | - // @codingStandardsIgnoreEnd |
|
150 | - 'event_espresso' |
|
151 | - ), |
|
152 | - print_r($wpdb_row, true) |
|
153 | - ) |
|
154 | - ); |
|
155 | - } |
|
156 | - self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
157 | - return EEM_Registration::instance()->count( |
|
158 | - array( |
|
159 | - array( |
|
160 | - 'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'], |
|
161 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
162 | - ), |
|
163 | - ), |
|
164 | - 'REG_ID', |
|
165 | - true |
|
166 | - ); |
|
167 | - } |
|
130 | + /** |
|
131 | + * Counts the number of pending-payment registrations for this event (regardless |
|
132 | + * of how many datetimes each registrations' ticket purchase is for) |
|
133 | + * |
|
134 | + * @param array $wpdb_row |
|
135 | + * @param \WP_REST_Request $request |
|
136 | + * @param Controller_Base $controller |
|
137 | + * @return int |
|
138 | + * @throws \EE_Error |
|
139 | + * @throws \EventEspresso\core\libraries\rest_api\RestException |
|
140 | + */ |
|
141 | + public static function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
142 | + { |
|
143 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
144 | + throw new \EE_Error( |
|
145 | + sprintf( |
|
146 | + __( |
|
147 | + // @codingStandardsIgnoreStart |
|
148 | + 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
149 | + // @codingStandardsIgnoreEnd |
|
150 | + 'event_espresso' |
|
151 | + ), |
|
152 | + print_r($wpdb_row, true) |
|
153 | + ) |
|
154 | + ); |
|
155 | + } |
|
156 | + self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
157 | + return EEM_Registration::instance()->count( |
|
158 | + array( |
|
159 | + array( |
|
160 | + 'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'], |
|
161 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
162 | + ), |
|
163 | + ), |
|
164 | + 'REG_ID', |
|
165 | + true |
|
166 | + ); |
|
167 | + } |
|
168 | 168 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @author Mike Nelson |
17 | 17 | * @since $VID:$ |
18 | 18 | */ |
19 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
19 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
20 | 20 | exit('No direct script access allowed'); |
21 | 21 | } |
22 | 22 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public static function registrationsCheckedInCount($wpdb_row, $request, $controller) |
77 | 77 | { |
78 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
78 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
79 | 79 | throw new \EE_Error( |
80 | 80 | sprintf( |
81 | 81 | __( |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public static function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
109 | 109 | { |
110 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
110 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
111 | 111 | throw new \EE_Error( |
112 | 112 | sprintf( |
113 | 113 | __( |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public static function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
142 | 142 | { |
143 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
143 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
144 | 144 | throw new \EE_Error( |
145 | 145 | sprintf( |
146 | 146 | __( |
@@ -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,54 +20,54 @@ discard block |
||
20 | 20 | class RestException 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 | - if (is_array($wp_error_data) |
|
35 | - && isset($wp_error_data['status']) |
|
36 | - ) { |
|
37 | - $http_status_number = $wp_error_data['status']; |
|
38 | - } else { |
|
39 | - $http_status_number = 500; |
|
40 | - } |
|
41 | - parent::__construct( |
|
42 | - $message, |
|
43 | - $http_status_number, |
|
44 | - $previous |
|
45 | - ); |
|
46 | - $this->wp_error_data = $wp_error_data; |
|
47 | - $this->wp_error_code = $string_code; |
|
48 | - } |
|
32 | + public function __construct($string_code, $message, $wp_error_data = array(), $previous = null) |
|
33 | + { |
|
34 | + if (is_array($wp_error_data) |
|
35 | + && isset($wp_error_data['status']) |
|
36 | + ) { |
|
37 | + $http_status_number = $wp_error_data['status']; |
|
38 | + } else { |
|
39 | + $http_status_number = 500; |
|
40 | + } |
|
41 | + parent::__construct( |
|
42 | + $message, |
|
43 | + $http_status_number, |
|
44 | + $previous |
|
45 | + ); |
|
46 | + $this->wp_error_data = $wp_error_data; |
|
47 | + $this->wp_error_code = $string_code; |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * Array of data that may have been set during the constructor, intended for WP_Error's data |
|
54 | - * |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - public function getData() |
|
58 | - { |
|
59 | - return $this->wp_error_data; |
|
60 | - } |
|
52 | + /** |
|
53 | + * Array of data that may have been set during the constructor, intended for WP_Error's data |
|
54 | + * |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + public function getData() |
|
58 | + { |
|
59 | + return $this->wp_error_data; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | 63 | |
64 | - /** |
|
65 | - * Gets the error string |
|
66 | - * |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function getStringCode() |
|
70 | - { |
|
71 | - return $this->wp_error_code; |
|
72 | - } |
|
64 | + /** |
|
65 | + * Gets the error string |
|
66 | + * |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function getStringCode() |
|
70 | + { |
|
71 | + return $this->wp_error_code; |
|
72 | + } |
|
73 | 73 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | use EEH_Inflector; |
6 | 6 | |
7 | 7 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
8 | - exit('No direct script access allowed'); |
|
8 | + exit('No direct script access allowed'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | |
@@ -20,158 +20,158 @@ discard block |
||
20 | 20 | class Capabilities |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * The current user can see at least SOME of these entities. |
|
25 | - * |
|
26 | - * @param EEM_Base $model |
|
27 | - * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
|
28 | - * @return boolean |
|
29 | - */ |
|
30 | - public static function currentUserHasPartialAccessTo($model, $model_context = EEM_Base::caps_read) |
|
31 | - { |
|
32 | - if (apply_filters( |
|
33 | - 'FHEE__Capabilities__current_user_has_partial_access_to__override_begin', |
|
34 | - false, |
|
35 | - $model, |
|
36 | - $model |
|
37 | - )) { |
|
38 | - return true; |
|
39 | - } |
|
40 | - foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) { |
|
41 | - if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) { |
|
42 | - return false; |
|
43 | - } |
|
44 | - } |
|
45 | - if (apply_filters( |
|
46 | - 'FHEE__Capabilities__current_user_has_partial_access_to__override_end', |
|
47 | - false, |
|
48 | - $model, |
|
49 | - $model |
|
50 | - )) { |
|
51 | - return false; |
|
52 | - } |
|
53 | - return true; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * Gets an array of all the capabilities the current user is missing that affected |
|
60 | - * the query |
|
61 | - * |
|
62 | - * @param EEM_Base $model |
|
63 | - * @param string $request_type one of the constants on WP_JSON_Server |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public static function getMissingPermissions($model, $request_type = EEM_Base::caps_read) |
|
67 | - { |
|
68 | - return $model->caps_missing($request_type); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Gets a string of all the capabilities the current user is missing that affected |
|
75 | - * the query |
|
76 | - * |
|
77 | - * @param EEM_Base $model |
|
78 | - * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public static function getMissingPermissionsString($model, $model_context = EEM_Base::caps_read) |
|
82 | - { |
|
83 | - return implode(',', array_keys(self::getMissingPermissions($model, $model_context))); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * Takes a entity that's ready to be returned and removes fields which the user shouldn't be able to access. |
|
90 | - * |
|
91 | - * @param array $entity |
|
92 | - * @param EEM_Base $model |
|
93 | - * @param string $request_type one of the return values from EEM_Base::valid_cap_contexts() |
|
94 | - * @param ModelVersionInfo $model_version_info |
|
95 | - * @param string $primary_key_string result of EEM_Base::get_index_primary_key_string(), so that we can |
|
96 | - * use this with models that have no primary key |
|
97 | - * @return array ready for converting into json |
|
98 | - */ |
|
99 | - public static function filterOutInaccessibleEntityFields( |
|
100 | - $entity, |
|
101 | - $model, |
|
102 | - $request_type, |
|
103 | - $model_version_info, |
|
104 | - $primary_key_string = null |
|
105 | - ) { |
|
106 | - //if they didn't provide the primary key string, we'll just hope we can figure it out |
|
107 | - //from the entity (although it's preferred client code does it, because the entity might be missing |
|
108 | - //necessary fields for creating the primary key string, or they could be named differently) |
|
109 | - if ($primary_key_string === null) { |
|
110 | - $primary_key_string = $model->get_index_primary_key_string( |
|
111 | - $model->deduce_fields_n_values_from_cols_n_values($entity) |
|
112 | - ); |
|
113 | - } |
|
114 | - //we only care to do this for frontend reads and when the user can't edit the item |
|
115 | - if ($request_type !== EEM_Base::caps_read |
|
116 | - || $model->exists( |
|
117 | - $model->alter_query_params_to_restrict_by_ID( |
|
118 | - $primary_key_string, |
|
119 | - array( |
|
120 | - 'default_where_conditions' => 'none', |
|
121 | - 'caps' => EEM_Base::caps_edit, |
|
122 | - ) |
|
123 | - ) |
|
124 | - ) |
|
125 | - ) { |
|
126 | - return $entity; |
|
127 | - } |
|
128 | - foreach ($model->field_settings() as $field_name => $field_obj) { |
|
129 | - if ($model_version_info->fieldHasRenderedFormat($field_obj) |
|
130 | - && isset($entity[$field_name]) |
|
131 | - && is_array($entity[$field_name]) |
|
132 | - && isset($entity[$field_name]['raw']) |
|
133 | - ) { |
|
134 | - unset($entity[$field_name]['raw']); |
|
135 | - } |
|
136 | - } |
|
137 | - //theoretically we may want to filter out specific fields for specific models |
|
138 | - return apply_filters( |
|
139 | - 'FHEE__Capabilities__filter_out_inaccessible_entity_fields', |
|
140 | - $entity, |
|
141 | - $model, |
|
142 | - $request_type |
|
143 | - ); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * Verifies the current user has at least partial access to do this action on this model. |
|
150 | - * If not, throws an exception (so we can define the code that sets up this error object |
|
151 | - * once) |
|
152 | - * |
|
153 | - * @param EEM_Base $model |
|
154 | - * @param string $model_action_context |
|
155 | - * @param string $action_name |
|
156 | - * @return void |
|
157 | - * @throws RestException |
|
158 | - */ |
|
159 | - public static function verifyAtLeastPartialAccessTo($model, $model_action_context, $action_name = 'list') |
|
160 | - { |
|
161 | - if (! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) { |
|
162 | - $model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
163 | - throw new RestException( |
|
164 | - sprintf('rest_cannot_%s_%s', strtolower($action_name), $model_name_plural), |
|
165 | - sprintf( |
|
166 | - __('Sorry, you are not allowed to %1$s %2$s. Missing permissions: %3$s', 'event_espresso'), |
|
167 | - $action_name, |
|
168 | - $model_name_plural, |
|
169 | - Capabilities::getMissingPermissionsString($model, $model_action_context) |
|
170 | - ), |
|
171 | - array('status' => 403) |
|
172 | - ); |
|
173 | - } |
|
174 | - } |
|
23 | + /** |
|
24 | + * The current user can see at least SOME of these entities. |
|
25 | + * |
|
26 | + * @param EEM_Base $model |
|
27 | + * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
|
28 | + * @return boolean |
|
29 | + */ |
|
30 | + public static function currentUserHasPartialAccessTo($model, $model_context = EEM_Base::caps_read) |
|
31 | + { |
|
32 | + if (apply_filters( |
|
33 | + 'FHEE__Capabilities__current_user_has_partial_access_to__override_begin', |
|
34 | + false, |
|
35 | + $model, |
|
36 | + $model |
|
37 | + )) { |
|
38 | + return true; |
|
39 | + } |
|
40 | + foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) { |
|
41 | + if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) { |
|
42 | + return false; |
|
43 | + } |
|
44 | + } |
|
45 | + if (apply_filters( |
|
46 | + 'FHEE__Capabilities__current_user_has_partial_access_to__override_end', |
|
47 | + false, |
|
48 | + $model, |
|
49 | + $model |
|
50 | + )) { |
|
51 | + return false; |
|
52 | + } |
|
53 | + return true; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * Gets an array of all the capabilities the current user is missing that affected |
|
60 | + * the query |
|
61 | + * |
|
62 | + * @param EEM_Base $model |
|
63 | + * @param string $request_type one of the constants on WP_JSON_Server |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public static function getMissingPermissions($model, $request_type = EEM_Base::caps_read) |
|
67 | + { |
|
68 | + return $model->caps_missing($request_type); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Gets a string of all the capabilities the current user is missing that affected |
|
75 | + * the query |
|
76 | + * |
|
77 | + * @param EEM_Base $model |
|
78 | + * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public static function getMissingPermissionsString($model, $model_context = EEM_Base::caps_read) |
|
82 | + { |
|
83 | + return implode(',', array_keys(self::getMissingPermissions($model, $model_context))); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * Takes a entity that's ready to be returned and removes fields which the user shouldn't be able to access. |
|
90 | + * |
|
91 | + * @param array $entity |
|
92 | + * @param EEM_Base $model |
|
93 | + * @param string $request_type one of the return values from EEM_Base::valid_cap_contexts() |
|
94 | + * @param ModelVersionInfo $model_version_info |
|
95 | + * @param string $primary_key_string result of EEM_Base::get_index_primary_key_string(), so that we can |
|
96 | + * use this with models that have no primary key |
|
97 | + * @return array ready for converting into json |
|
98 | + */ |
|
99 | + public static function filterOutInaccessibleEntityFields( |
|
100 | + $entity, |
|
101 | + $model, |
|
102 | + $request_type, |
|
103 | + $model_version_info, |
|
104 | + $primary_key_string = null |
|
105 | + ) { |
|
106 | + //if they didn't provide the primary key string, we'll just hope we can figure it out |
|
107 | + //from the entity (although it's preferred client code does it, because the entity might be missing |
|
108 | + //necessary fields for creating the primary key string, or they could be named differently) |
|
109 | + if ($primary_key_string === null) { |
|
110 | + $primary_key_string = $model->get_index_primary_key_string( |
|
111 | + $model->deduce_fields_n_values_from_cols_n_values($entity) |
|
112 | + ); |
|
113 | + } |
|
114 | + //we only care to do this for frontend reads and when the user can't edit the item |
|
115 | + if ($request_type !== EEM_Base::caps_read |
|
116 | + || $model->exists( |
|
117 | + $model->alter_query_params_to_restrict_by_ID( |
|
118 | + $primary_key_string, |
|
119 | + array( |
|
120 | + 'default_where_conditions' => 'none', |
|
121 | + 'caps' => EEM_Base::caps_edit, |
|
122 | + ) |
|
123 | + ) |
|
124 | + ) |
|
125 | + ) { |
|
126 | + return $entity; |
|
127 | + } |
|
128 | + foreach ($model->field_settings() as $field_name => $field_obj) { |
|
129 | + if ($model_version_info->fieldHasRenderedFormat($field_obj) |
|
130 | + && isset($entity[$field_name]) |
|
131 | + && is_array($entity[$field_name]) |
|
132 | + && isset($entity[$field_name]['raw']) |
|
133 | + ) { |
|
134 | + unset($entity[$field_name]['raw']); |
|
135 | + } |
|
136 | + } |
|
137 | + //theoretically we may want to filter out specific fields for specific models |
|
138 | + return apply_filters( |
|
139 | + 'FHEE__Capabilities__filter_out_inaccessible_entity_fields', |
|
140 | + $entity, |
|
141 | + $model, |
|
142 | + $request_type |
|
143 | + ); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * Verifies the current user has at least partial access to do this action on this model. |
|
150 | + * If not, throws an exception (so we can define the code that sets up this error object |
|
151 | + * once) |
|
152 | + * |
|
153 | + * @param EEM_Base $model |
|
154 | + * @param string $model_action_context |
|
155 | + * @param string $action_name |
|
156 | + * @return void |
|
157 | + * @throws RestException |
|
158 | + */ |
|
159 | + public static function verifyAtLeastPartialAccessTo($model, $model_action_context, $action_name = 'list') |
|
160 | + { |
|
161 | + if (! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) { |
|
162 | + $model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
163 | + throw new RestException( |
|
164 | + sprintf('rest_cannot_%s_%s', strtolower($action_name), $model_name_plural), |
|
165 | + sprintf( |
|
166 | + __('Sorry, you are not allowed to %1$s %2$s. Missing permissions: %3$s', 'event_espresso'), |
|
167 | + $action_name, |
|
168 | + $model_name_plural, |
|
169 | + Capabilities::getMissingPermissionsString($model, $model_action_context) |
|
170 | + ), |
|
171 | + array('status' => 403) |
|
172 | + ); |
|
173 | + } |
|
174 | + } |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | // End of file Capabilities.php |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EEM_Base; |
5 | 5 | use EEH_Inflector; |
6 | 6 | |
7 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
8 | 8 | exit('No direct script access allowed'); |
9 | 9 | } |
10 | 10 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public static function verifyAtLeastPartialAccessTo($model, $model_action_context, $action_name = 'list') |
160 | 160 | { |
161 | - if (! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) { |
|
161 | + if ( ! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) { |
|
162 | 162 | $model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
163 | 163 | throw new RestException( |
164 | 164 | sprintf('rest_cannot_%s_%s', strtolower($action_name), $model_name_plural), |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | use EventEspresso\core\libraries\rest_api\ModelDataTranslator; |
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 | |
@@ -29,124 +29,124 @@ discard block |
||
29 | 29 | { |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * @param \WP_REST_Request $request |
|
34 | - * @param string $version |
|
35 | - * @return array|\WP_REST_Response |
|
36 | - */ |
|
37 | - public static function handleRequestModelsMeta(\WP_REST_Request $request, $version) |
|
38 | - { |
|
39 | - $controller = new Meta(); |
|
40 | - try { |
|
41 | - $controller->setRequestedVersion($version); |
|
42 | - return $controller->sendResponse($controller->getModelsMetadataEntity()); |
|
43 | - } catch (Exception $e) { |
|
44 | - return $controller->sendResponse($e); |
|
45 | - } |
|
46 | - } |
|
32 | + /** |
|
33 | + * @param \WP_REST_Request $request |
|
34 | + * @param string $version |
|
35 | + * @return array|\WP_REST_Response |
|
36 | + */ |
|
37 | + public static function handleRequestModelsMeta(\WP_REST_Request $request, $version) |
|
38 | + { |
|
39 | + $controller = new Meta(); |
|
40 | + try { |
|
41 | + $controller->setRequestedVersion($version); |
|
42 | + return $controller->sendResponse($controller->getModelsMetadataEntity()); |
|
43 | + } catch (Exception $e) { |
|
44 | + return $controller->sendResponse($e); |
|
45 | + } |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | 49 | |
50 | - /* |
|
50 | + /* |
|
51 | 51 | * Gets the model metadata resource entity |
52 | 52 | * @return array for JSON response, describing all the models available in teh requested version |
53 | 53 | */ |
54 | - protected function getModelsMetadataEntity() |
|
55 | - { |
|
56 | - $response = array(); |
|
57 | - foreach ($this->getModelVersionInfo()->modelsForRequestedVersion() as $model_name => $model_classname) { |
|
58 | - $model = $this->getModelVersionInfo()->loadModel($model_name); |
|
59 | - $fields_json = array(); |
|
60 | - foreach ($this->getModelVersionInfo()->fieldsOnModelInThisVersion($model) as $field_name => $field_obj) { |
|
61 | - if ($this->getModelVersionInfo()->fieldIsIgnored($field_obj)) { |
|
62 | - continue; |
|
63 | - } |
|
64 | - if ($field_obj instanceof EE_Boolean_Field) { |
|
65 | - $datatype = 'Boolean'; |
|
66 | - } elseif ($field_obj->get_wpdb_data_type() == '%d') { |
|
67 | - $datatype = 'Number'; |
|
68 | - } elseif ($field_name instanceof EE_Serialized_Text_Field) { |
|
69 | - $datatype = 'Object'; |
|
70 | - } else { |
|
71 | - $datatype = 'String'; |
|
72 | - } |
|
73 | - $default_value = ModelDataTranslator::prepareFieldValueForJson( |
|
74 | - $field_obj, |
|
75 | - $field_obj->get_default_value(), |
|
76 | - $this->getModelVersionInfo()->requestedVersion() |
|
77 | - ); |
|
78 | - $field_json = array( |
|
79 | - 'name' => $field_name, |
|
80 | - 'nicename' => $field_obj->get_nicename(), |
|
81 | - 'has_rendered_format' => $this->getModelVersionInfo()->fieldHasRenderedFormat($field_obj), |
|
82 | - 'has_pretty_format' => $this->getModelVersionInfo()->fieldHasPrettyFormat($field_obj), |
|
83 | - 'type' => str_replace('EE_', '', get_class($field_obj)), |
|
84 | - 'datatype' => $datatype, |
|
85 | - 'nullable' => $field_obj->is_nullable(), |
|
86 | - 'default' => $default_value, |
|
87 | - 'table_alias' => $field_obj->get_table_alias(), |
|
88 | - 'table_column' => $field_obj->get_table_column(), |
|
89 | - ); |
|
90 | - $fields_json[$field_json['name']] = $field_json; |
|
91 | - } |
|
92 | - $fields_json = array_merge( |
|
93 | - $fields_json, |
|
94 | - $this->getModelVersionInfo()->extraResourcePropertiesForModel($model) |
|
95 | - ); |
|
96 | - $response[$model_name]['fields'] = apply_filters( |
|
97 | - 'FHEE__Meta__handle_request_models_meta__fields', |
|
98 | - $fields_json, |
|
99 | - $model |
|
100 | - ); |
|
101 | - $relations_json = array(); |
|
102 | - foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
103 | - $relation_json = array( |
|
104 | - 'name' => $relation_name, |
|
105 | - 'type' => str_replace('EE_', '', get_class($relation_obj)), |
|
106 | - 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false, |
|
107 | - ); |
|
108 | - $relations_json[$relation_name] = $relation_json; |
|
109 | - } |
|
110 | - $response[$model_name]['relations'] = apply_filters( |
|
111 | - 'FHEE__Meta__handle_request_models_meta__relations', |
|
112 | - $relations_json, |
|
113 | - $model |
|
114 | - ); |
|
115 | - } |
|
116 | - return $response; |
|
117 | - } |
|
54 | + protected function getModelsMetadataEntity() |
|
55 | + { |
|
56 | + $response = array(); |
|
57 | + foreach ($this->getModelVersionInfo()->modelsForRequestedVersion() as $model_name => $model_classname) { |
|
58 | + $model = $this->getModelVersionInfo()->loadModel($model_name); |
|
59 | + $fields_json = array(); |
|
60 | + foreach ($this->getModelVersionInfo()->fieldsOnModelInThisVersion($model) as $field_name => $field_obj) { |
|
61 | + if ($this->getModelVersionInfo()->fieldIsIgnored($field_obj)) { |
|
62 | + continue; |
|
63 | + } |
|
64 | + if ($field_obj instanceof EE_Boolean_Field) { |
|
65 | + $datatype = 'Boolean'; |
|
66 | + } elseif ($field_obj->get_wpdb_data_type() == '%d') { |
|
67 | + $datatype = 'Number'; |
|
68 | + } elseif ($field_name instanceof EE_Serialized_Text_Field) { |
|
69 | + $datatype = 'Object'; |
|
70 | + } else { |
|
71 | + $datatype = 'String'; |
|
72 | + } |
|
73 | + $default_value = ModelDataTranslator::prepareFieldValueForJson( |
|
74 | + $field_obj, |
|
75 | + $field_obj->get_default_value(), |
|
76 | + $this->getModelVersionInfo()->requestedVersion() |
|
77 | + ); |
|
78 | + $field_json = array( |
|
79 | + 'name' => $field_name, |
|
80 | + 'nicename' => $field_obj->get_nicename(), |
|
81 | + 'has_rendered_format' => $this->getModelVersionInfo()->fieldHasRenderedFormat($field_obj), |
|
82 | + 'has_pretty_format' => $this->getModelVersionInfo()->fieldHasPrettyFormat($field_obj), |
|
83 | + 'type' => str_replace('EE_', '', get_class($field_obj)), |
|
84 | + 'datatype' => $datatype, |
|
85 | + 'nullable' => $field_obj->is_nullable(), |
|
86 | + 'default' => $default_value, |
|
87 | + 'table_alias' => $field_obj->get_table_alias(), |
|
88 | + 'table_column' => $field_obj->get_table_column(), |
|
89 | + ); |
|
90 | + $fields_json[$field_json['name']] = $field_json; |
|
91 | + } |
|
92 | + $fields_json = array_merge( |
|
93 | + $fields_json, |
|
94 | + $this->getModelVersionInfo()->extraResourcePropertiesForModel($model) |
|
95 | + ); |
|
96 | + $response[$model_name]['fields'] = apply_filters( |
|
97 | + 'FHEE__Meta__handle_request_models_meta__fields', |
|
98 | + $fields_json, |
|
99 | + $model |
|
100 | + ); |
|
101 | + $relations_json = array(); |
|
102 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
103 | + $relation_json = array( |
|
104 | + 'name' => $relation_name, |
|
105 | + 'type' => str_replace('EE_', '', get_class($relation_obj)), |
|
106 | + 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false, |
|
107 | + ); |
|
108 | + $relations_json[$relation_name] = $relation_json; |
|
109 | + } |
|
110 | + $response[$model_name]['relations'] = apply_filters( |
|
111 | + 'FHEE__Meta__handle_request_models_meta__relations', |
|
112 | + $relations_json, |
|
113 | + $model |
|
114 | + ); |
|
115 | + } |
|
116 | + return $response; |
|
117 | + } |
|
118 | 118 | |
119 | 119 | |
120 | 120 | |
121 | - /** |
|
122 | - * Adds EE metadata to the index |
|
123 | - * |
|
124 | - * @param \WP_REST_Response $rest_response_obj |
|
125 | - * @return \WP_REST_Response |
|
126 | - */ |
|
127 | - public static function filterEeMetadataIntoIndex(\WP_REST_Response $rest_response_obj) |
|
128 | - { |
|
129 | - $response_data = $rest_response_obj->get_data(); |
|
130 | - $addons = array(); |
|
131 | - foreach (EE_Registry::instance()->addons as $addon) { |
|
132 | - $addon_json = array( |
|
133 | - 'name' => $addon->name(), |
|
134 | - 'version' => $addon->version(), |
|
135 | - ); |
|
136 | - $addons[$addon_json['name']] = $addon_json; |
|
137 | - } |
|
138 | - $response_data['ee'] = array( |
|
139 | - 'version' => EEM_System_Status::instance()->get_ee_version(), |
|
140 | - // @codingStandardsIgnoreStart |
|
141 | - 'documentation_url' => 'https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API', |
|
142 | - // @codingStandardsIgnoreEnd |
|
143 | - 'addons' => $addons, |
|
144 | - 'maintenance_mode' => EE_Maintenance_Mode::instance()->real_level(), |
|
145 | - 'served_core_versions' => array_keys(EED_Core_Rest_Api::versions_served()), |
|
146 | - ); |
|
147 | - $rest_response_obj->set_data($response_data); |
|
148 | - return $rest_response_obj; |
|
149 | - } |
|
121 | + /** |
|
122 | + * Adds EE metadata to the index |
|
123 | + * |
|
124 | + * @param \WP_REST_Response $rest_response_obj |
|
125 | + * @return \WP_REST_Response |
|
126 | + */ |
|
127 | + public static function filterEeMetadataIntoIndex(\WP_REST_Response $rest_response_obj) |
|
128 | + { |
|
129 | + $response_data = $rest_response_obj->get_data(); |
|
130 | + $addons = array(); |
|
131 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
132 | + $addon_json = array( |
|
133 | + 'name' => $addon->name(), |
|
134 | + 'version' => $addon->version(), |
|
135 | + ); |
|
136 | + $addons[$addon_json['name']] = $addon_json; |
|
137 | + } |
|
138 | + $response_data['ee'] = array( |
|
139 | + 'version' => EEM_System_Status::instance()->get_ee_version(), |
|
140 | + // @codingStandardsIgnoreStart |
|
141 | + 'documentation_url' => 'https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API', |
|
142 | + // @codingStandardsIgnoreEnd |
|
143 | + 'addons' => $addons, |
|
144 | + 'maintenance_mode' => EE_Maintenance_Mode::instance()->real_level(), |
|
145 | + 'served_core_versions' => array_keys(EED_Core_Rest_Api::versions_served()), |
|
146 | + ); |
|
147 | + $rest_response_obj->set_data($response_data); |
|
148 | + return $rest_response_obj; |
|
149 | + } |
|
150 | 150 | } |
151 | 151 | |
152 | 152 |
@@ -11,7 +11,7 @@ |
||
11 | 11 | use EEM_System_Status; |
12 | 12 | use EventEspresso\core\libraries\rest_api\ModelDataTranslator; |
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 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use EE_Error; |
7 | 7 | |
8 | 8 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
9 | - exit('No direct script access allowed'); |
|
9 | + exit('No direct script access allowed'); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | |
@@ -22,69 +22,69 @@ discard block |
||
22 | 22 | class Base extends Controller_Base |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Holds reference to the model version info, which knows the requested version |
|
27 | - * |
|
28 | - * @var ModelVersionInfo |
|
29 | - */ |
|
30 | - protected $model_version_info; |
|
25 | + /** |
|
26 | + * Holds reference to the model version info, which knows the requested version |
|
27 | + * |
|
28 | + * @var ModelVersionInfo |
|
29 | + */ |
|
30 | + protected $model_version_info; |
|
31 | 31 | |
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * Sets the version the user requested |
|
36 | - * |
|
37 | - * @param string $version eg '4.8' |
|
38 | - */ |
|
39 | - public function setRequestedVersion($version) |
|
40 | - { |
|
41 | - parent::setRequestedVersion($version); |
|
42 | - $this->model_version_info = new ModelVersionInfo($version); |
|
43 | - } |
|
34 | + /** |
|
35 | + * Sets the version the user requested |
|
36 | + * |
|
37 | + * @param string $version eg '4.8' |
|
38 | + */ |
|
39 | + public function setRequestedVersion($version) |
|
40 | + { |
|
41 | + parent::setRequestedVersion($version); |
|
42 | + $this->model_version_info = new ModelVersionInfo($version); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * Gets the object that should be used for getting any info from the models, |
|
49 | - * because it's takes the requested and current core version into account |
|
50 | - * |
|
51 | - * @return \EventEspresso\core\libraries\rest_api\ModelVersionInfo |
|
52 | - * @throws EE_Error |
|
53 | - */ |
|
54 | - public function getModelVersionInfo() |
|
55 | - { |
|
56 | - if (! $this->model_version_info) { |
|
57 | - throw new EE_Error( |
|
58 | - sprintf( |
|
59 | - __( |
|
60 | - 'Cannot use model version info before setting the requested version in the controller', |
|
61 | - 'event_espresso' |
|
62 | - ) |
|
63 | - ) |
|
64 | - ); |
|
65 | - } |
|
66 | - return $this->model_version_info; |
|
67 | - } |
|
47 | + /** |
|
48 | + * Gets the object that should be used for getting any info from the models, |
|
49 | + * because it's takes the requested and current core version into account |
|
50 | + * |
|
51 | + * @return \EventEspresso\core\libraries\rest_api\ModelVersionInfo |
|
52 | + * @throws EE_Error |
|
53 | + */ |
|
54 | + public function getModelVersionInfo() |
|
55 | + { |
|
56 | + if (! $this->model_version_info) { |
|
57 | + throw new EE_Error( |
|
58 | + sprintf( |
|
59 | + __( |
|
60 | + 'Cannot use model version info before setting the requested version in the controller', |
|
61 | + 'event_espresso' |
|
62 | + ) |
|
63 | + ) |
|
64 | + ); |
|
65 | + } |
|
66 | + return $this->model_version_info; |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * Determines if $object is of one of the classes of $classes. Similar to |
|
73 | - * in_array(), except this checks if $object is a subclass of the classnames provided |
|
74 | - * in $classnames |
|
75 | - * |
|
76 | - * @param object $object |
|
77 | - * @param array $classnames |
|
78 | - * @return boolean |
|
79 | - */ |
|
80 | - public function isSubclassOfOne($object, $classnames) |
|
81 | - { |
|
82 | - foreach ($classnames as $classname) { |
|
83 | - if (is_a($object, $classname)) { |
|
84 | - return true; |
|
85 | - } |
|
86 | - } |
|
87 | - return false; |
|
88 | - } |
|
71 | + /** |
|
72 | + * Determines if $object is of one of the classes of $classes. Similar to |
|
73 | + * in_array(), except this checks if $object is a subclass of the classnames provided |
|
74 | + * in $classnames |
|
75 | + * |
|
76 | + * @param object $object |
|
77 | + * @param array $classnames |
|
78 | + * @return boolean |
|
79 | + */ |
|
80 | + public function isSubclassOfOne($object, $classnames) |
|
81 | + { |
|
82 | + foreach ($classnames as $classname) { |
|
83 | + if (is_a($object, $classname)) { |
|
84 | + return true; |
|
85 | + } |
|
86 | + } |
|
87 | + return false; |
|
88 | + } |
|
89 | 89 | } |
90 | 90 | // End of file Base.php |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | use EventEspresso\core\libraries\rest_api\ModelVersionInfo; |
6 | 6 | use EE_Error; |
7 | 7 | |
8 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
8 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
9 | 9 | exit('No direct script access allowed'); |
10 | 10 | } |
11 | 11 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function getModelVersionInfo() |
55 | 55 | { |
56 | - if (! $this->model_version_info) { |
|
56 | + if ( ! $this->model_version_info) { |
|
57 | 57 | throw new EE_Error( |
58 | 58 | sprintf( |
59 | 59 | __( |