PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.4
Pods – Custom Content Types and Fields v3.3.4
trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / src / Pods / REST / V1 / Endpoints / Group.php
pods / src / Pods / REST / V1 / Endpoints Last commit date
Base.php 1 year ago Field.php 1 year ago Field_Slug.php 4 years ago Fields.php 1 year ago Group.php 1 year ago Group_Slug.php 4 years ago Groups.php 1 year ago Pod.php 1 year ago Pod_Slug.php 4 years ago Pods.php 1 year ago Swagger_Documentation.php 1 year ago
Group.php
335 lines
1 <?php
2
3 namespace Pods\REST\V1\Endpoints;
4
5 use Pods\REST\Interfaces\Endpoints\DELETE_Interface;
6 use Pods\REST\Interfaces\Endpoints\READ_Interface;
7 use Pods\REST\Interfaces\Endpoints\UPDATE_Interface;
8 use Pods\REST\Interfaces\Swagger\Provider_Interface;
9 use WP_REST_Request;
10
11 class Group extends Base implements READ_Interface, UPDATE_Interface, DELETE_Interface, Provider_Interface {
12
13 /**
14 * {@inheritdoc}
15 *
16 * @since 2.8.0
17 */
18 public $route = '/groups/%1$d';
19
20 /**
21 * {@inheritdoc}
22 *
23 * @since 2.8.11
24 */
25 public $rest_route = '/groups/(?P<id>\\d+)';
26
27 /**
28 * {@inheritdoc}
29 *
30 * @since 2.8.11
31 */
32 public $rest_doc_route = '/groups/{id}';
33
34 /**
35 * {@inheritdoc}
36 *
37 * @since 2.8.0
38 */
39 public $object = 'group';
40
41 /**
42 * {@inheritdoc}
43 *
44 * @since 2.8.0
45 */
46 public function get_documentation() {
47 $GET_defaults = [
48 'in' => 'query',
49 'default' => '',
50 'type' => 'string',
51 ];
52
53 $POST_defaults = [
54 'in' => 'body',
55 'default' => '',
56 'type' => 'string',
57 ];
58
59 return [
60 'get' => [
61 'summary' => 'Retrieve a specific Group',
62 'parameters' => $this->swaggerize_args( $this->READ_args(), $GET_defaults ),
63 'responses' => [
64 '200' => [
65 'description' => 'Returns the requested Group with its details',
66 'content' => [
67 'application/json' => [
68 'schema' => [
69 '$ref' => '#/components/schemas/Group',
70 ],
71 ],
72 ],
73 ],
74 '400' => [
75 'description' => 'The request was invalid or cannot be otherwise served',
76 'content' => [
77 'application/json' => [
78 'schema' => [
79 'type' => 'object',
80 ],
81 ],
82 ],
83 ],
84 '401' => [
85 'description' => 'Unauthorized access - user does not have permission to access this Group',
86 'content' => [
87 'application/json' => [
88 'schema' => [
89 'type' => 'object',
90 ],
91 ],
92 ],
93 ],
94 '404' => [
95 'description' => 'The requested Group was not found',
96 'content' => [
97 'application/json' => [
98 'schema' => [
99 'type' => 'object',
100 ],
101 ],
102 ],
103 ],
104 ],
105 ],
106 'put' => [
107 'summary' => 'Update a specific Group',
108 'parameters' => $this->swaggerize_args( $this->EDIT_args(), $POST_defaults ),
109 'responses' => [
110 '200' => [
111 'description' => 'Returns the updated Group',
112 'content' => [
113 'application/json' => [
114 'schema' => [
115 '$ref' => '#/components/schemas/Group',
116 ],
117 ],
118 ],
119 ],
120 '400' => [
121 'description' => 'The request was invalid or cannot be otherwise served',
122 'content' => [
123 'application/json' => [
124 'schema' => [
125 'type' => 'object',
126 ],
127 ],
128 ],
129 ],
130 '401' => [
131 'description' => 'Unauthorized access - user does not have permission to update this Group',
132 'content' => [
133 'application/json' => [
134 'schema' => [
135 'type' => 'object',
136 ],
137 ],
138 ],
139 ],
140 '404' => [
141 'description' => 'The Group to update was not found',
142 'content' => [
143 'application/json' => [
144 'schema' => [
145 'type' => 'object',
146 ],
147 ],
148 ],
149 ],
150 ],
151 ],
152 'delete' => [
153 'summary' => 'Delete a specific Group',
154 'parameters' => $this->swaggerize_args( $this->DELETE_args(), $POST_defaults ),
155 'responses' => [
156 '200' => [
157 'description' => 'Returns the deleted Group details',
158 'content' => [
159 'application/json' => [
160 'schema' => [
161 '$ref' => '#/components/schemas/Group',
162 ],
163 ],
164 ],
165 ],
166 '400' => [
167 'description' => 'The request was invalid or cannot be otherwise served',
168 'content' => [
169 'application/json' => [
170 'schema' => [
171 'type' => 'object',
172 ],
173 ],
174 ],
175 ],
176 '401' => [
177 'description' => 'Unauthorized access - user does not have permission to delete this Group',
178 'content' => [
179 'application/json' => [
180 'schema' => [
181 'type' => 'object',
182 ],
183 ],
184 ],
185 ],
186 '404' => [
187 'description' => 'The Group to delete was not found',
188 'content' => [
189 'application/json' => [
190 'schema' => [
191 'type' => 'object',
192 ],
193 ],
194 ],
195 ],
196 ],
197 ],
198 ];
199 }
200
201 /**
202 * {@inheritdoc}
203 *
204 * @since 2.8.0
205 */
206 public function READ_args() {
207 return [
208 'id' => [
209 'type' => 'integer',
210 'in' => 'path',
211 'description' => __( 'The Group ID.', 'pods' ),
212 'required' => true,
213 'validate_callback' => [ $this->validator, 'is_group_id' ],
214 ],
215 'include_fields' => [
216 'type' => 'boolean',
217 'description' => __( 'Whether to include fields (default: off).', 'pods' ),
218 'default' => false,
219 'cli_boolean' => true,
220 ],
221 ];
222 }
223
224 /**
225 * {@inheritdoc}
226 *
227 * @since 2.8.0
228 */
229 public function get( WP_REST_Request $request ) {
230 return $this->get_by_args( 'id', 'id', $request );
231 }
232
233 /**
234 * Determine whether access to READ is available.
235 *
236 * @since 2.8.0
237 *
238 * @return bool Whether access to READ is available.
239 */
240 public function can_read() {
241 return pods_is_admin( 'pods' );
242 }
243
244 /**
245 * {@inheritdoc}
246 *
247 * @since 2.8.0
248 */
249 public function EDIT_args() {
250 return [
251 'id' => [
252 'type' => 'integer',
253 'in' => 'path',
254 'description' => __( 'The Group ID.', 'pods' ),
255 'required' => true,
256 'validate_callback' => [ $this->validator, 'is_group_id' ],
257 ],
258 'name' => [
259 'type' => 'string',
260 'description' => __( 'The new name of the Group.', 'pods' ),
261 ],
262 'label' => [
263 'type' => 'string',
264 'description' => __( 'The singular label of the Group.', 'pods' ),
265 ],
266 'type' => [
267 'type' => 'string',
268 'description' => __( 'The type of the Group.', 'pods' ),
269 ],
270 'args' => [
271 'required' => false,
272 'description' => __( 'A list of additional options to save to the Group.', 'pods' ),
273 'swagger_type' => 'array',
274 ],
275 ];
276 }
277
278 /**
279 * {@inheritdoc}
280 *
281 * @since 2.8.0
282 */
283 public function update( WP_REST_Request $request ) {
284 if ( ! empty( $request['fields'] ) ) {
285 $request->set_param( 'fields', null );
286 }
287
288 return $this->update_by_args( 'id', 'id', $request );
289 }
290
291 /**
292 * {@inheritdoc}
293 *
294 * @since 2.8.0
295 */
296 public function can_edit() {
297 return pods_is_admin( 'pods' );
298 }
299
300 /**
301 * {@inheritdoc}
302 *
303 * @since 2.8.0
304 */
305 public function DELETE_args() {
306 return [
307 'id' => [
308 'type' => 'integer',
309 'in' => 'path',
310 'description' => __( 'The Group ID.', 'pods' ),
311 'required' => true,
312 'validate_callback' => [ $this->validator, 'is_group_id' ],
313 ],
314 ];
315 }
316
317 /**
318 * {@inheritdoc}
319 *
320 * @since 2.8.0
321 */
322 public function delete( WP_REST_Request $request ) {
323 return $this->delete_by_args( 'id', 'id', $request );
324 }
325
326 /**
327 * {@inheritdoc}
328 *
329 * @since 2.8.0
330 */
331 public function can_delete() {
332 return pods_is_admin( 'pods' );
333 }
334 }
335