@@ -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 | __( |
@@ -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'])) { |
|
| 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(true); |
|
| 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'])) { |
|
| 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(false); |
|
| 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'])) { |
|
| 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'])) { |
|
| 156 | - throw new EE_Error( |
|
| 157 | - sprintf( |
|
| 158 | - __( |
|
| 159 | - // @codingStandardsIgnoreStart |
|
| 160 | - 'Cannot calculate spots_taken because the database row %1$s does not have an 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'])) { |
|
| 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(true); |
|
| 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'])) { |
|
| 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(false); |
|
| 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'])) { |
|
| 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'])) { |
|
| 156 | + throw new EE_Error( |
|
| 157 | + sprintf( |
|
| 158 | + __( |
|
| 159 | + // @codingStandardsIgnoreStart |
|
| 160 | + 'Cannot calculate spots_taken because the database row %1$s does not have an 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'])) { |
|
| 155 | + if ( ! is_array($wpdb_row) || ! isset($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])) { |
@@ -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 | |