@@ 50-80 (lines=31) @@ | ||
47 | * @param \WP_REST_Request $request |
|
48 | * @return \WP_REST_Response|\WP_Error |
|
49 | */ |
|
50 | public static function handle_request_get_all( \WP_REST_Request $request) { |
|
51 | $controller = new Read(); |
|
52 | try{ |
|
53 | $matches = $controller->parse_route( |
|
54 | $request->get_route(), |
|
55 | '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
56 | array( 'version', 'model' ) |
|
57 | ); |
|
58 | $controller->set_requested_version( $matches[ 'version' ] ); |
|
59 | $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
60 | if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
61 | return $controller->send_response( |
|
62 | new \WP_Error( |
|
63 | 'endpoint_parsing_error', |
|
64 | sprintf( |
|
65 | __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
66 | $model_name_singular |
|
67 | ) |
|
68 | ) |
|
69 | ); |
|
70 | } |
|
71 | return $controller->send_response( |
|
72 | $controller->get_entities_from_model( |
|
73 | $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
74 | $request |
|
75 | ) |
|
76 | ); |
|
77 | } catch( \Exception $e ) { |
|
78 | return $controller->send_response( $e ); |
|
79 | } |
|
80 | } |
|
81 | ||
82 | /** |
|
83 | * Gets a single entity related to the model indicated in the path and its id |
|
@@ 88-117 (lines=30) @@ | ||
85 | * @param \WP_REST_Request $request |
|
86 | * @return \WP_REST_Response|\WP_Error |
|
87 | */ |
|
88 | public static function handle_request_get_one( \WP_REST_Request $request ) { |
|
89 | $controller = new Read(); |
|
90 | try{ |
|
91 | $matches = $controller->parse_route( |
|
92 | $request->get_route(), |
|
93 | '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
94 | array( 'version', 'model', 'id' ) ); |
|
95 | $controller->set_requested_version( $matches[ 'version' ] ); |
|
96 | $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
97 | if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
98 | return $controller->send_response( |
|
99 | new \WP_Error( |
|
100 | 'endpoint_parsing_error', |
|
101 | sprintf( |
|
102 | __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
103 | $model_name_singular |
|
104 | ) |
|
105 | ) |
|
106 | ); |
|
107 | } |
|
108 | return $controller->send_response( |
|
109 | $controller->get_entity_from_model( |
|
110 | $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
111 | $request |
|
112 | ) |
|
113 | ); |
|
114 | } catch( \Exception $e ) { |
|
115 | return $controller->send_response( $e ); |
|
116 | } |
|
117 | } |
|
118 | ||
119 | /** |
|
120 | * |