PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.2.5
Pods – Custom Content Types and Fields v3.2.5
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 / Groups.php
pods / src / Pods / REST / V1 / Endpoints Last commit date
Base.php 3 years ago Field.php 3 years ago Field_Slug.php 4 years ago Fields.php 3 years ago Group.php 3 years ago Group_Slug.php 4 years ago Groups.php 3 years ago Pod.php 3 years ago Pod_Slug.php 4 years ago Pods.php 3 years ago Swagger_Documentation.php 3 years ago
Groups.php
216 lines
1 <?php
2
3 namespace Pods\REST\V1\Endpoints;
4
5 use Pods\REST\Interfaces\Endpoints\CREATE_Interface;
6 use Pods\REST\Interfaces\Endpoints\READ_Interface;
7 use Pods\REST\Interfaces\Swagger\Provider_Interface;
8 use WP_REST_Request;
9
10 class Groups extends Base implements READ_Interface, CREATE_Interface, Provider_Interface {
11
12 /**
13 * {@inheritdoc}
14 *
15 * @since 2.8.0
16 */
17 public $route = '/groups';
18
19 /**
20 * {@inheritdoc}
21 *
22 * @since 2.8.0
23 */
24 public $object = 'group';
25
26 /**
27 * {@inheritdoc}
28 *
29 * @since 2.8.0
30 */
31 public function get_documentation() {
32 $GET_defaults = [
33 'in' => 'query',
34 'default' => '',
35 ];
36
37 // @todo Handle get/post
38
39 return [
40 'get' => [
41 'parameters' => $this->swaggerize_args( $this->READ_args(), $GET_defaults ),
42 'responses' => [
43 '200' => [
44 'description' => '', // @todo Fill this out
45 'content' => [
46 'application/json' => [
47 'schema' => [
48 'type' => 'object',
49 'properties' => [
50 'rest_url' => [
51 'type' => 'string',
52 'format' => 'uri',
53 'description' => __( 'This results page REST URL.', 'pods' ),
54 ],
55 'total' => [
56 'type' => 'integer',
57 'description' => __( 'The total number of results across all pages.', 'pods' ),
58 ],
59 'total_pages' => [
60 'type' => 'integer',
61 'description' => __( 'The total number of result pages matching the search criteria.', 'pods' ),
62 ],
63 'groups' => [
64 'type' => 'array',
65 'items' => [ '$ref' => '#/components/schemas/Group' ],
66 ],
67 ],
68 ],
69 ],
70 ],
71 ],
72 '400' => [
73 'description' => __( 'One or more of the specified query variables has a bad format.', 'pods' ),
74 'content' => [
75 'application/json' => [
76 'schema' => [
77 'type' => 'object',
78 ],
79 ],
80 ],
81 ],
82 '404' => [
83 'description' => __( 'The requested page was not found.', 'pods' ),
84 'content' => [
85 'application/json' => [
86 'schema' => [
87 'type' => 'object',
88 ],
89 ],
90 ],
91 ],
92 ],
93 ],
94 ];
95 }
96
97 /**
98 * {@inheritdoc}
99 *
100 * @since 2.8.0
101 */
102 public function READ_args() {
103 return [
104 'return_type' => [
105 'description' => __( 'The type of data to return.', 'pods' ),
106 'type' => 'string',
107 'default' => 'full',
108 'required' => false,
109 'enum' => [
110 'full',
111 'names',
112 'names_ids',
113 'ids',
114 'key_names',
115 'count',
116 ],
117 ],
118 'types' => [
119 'required' => false,
120 'description' => __( 'A list of types to filter by.', 'pods' ),
121 'swagger_type' => 'array',
122 'items' => [
123 'type' => 'string',
124 ],
125 'collectionFormat' => 'csv',
126 ],
127 'ids' => [
128 'required' => false,
129 'description' => __( 'A list of IDs to filter by.', 'pods' ),
130 'swagger_type' => 'array',
131 'items' => [
132 'type' => 'integer',
133 ],
134 'collectionFormat' => 'csv',
135 ],
136 'args' => [
137 'required' => false,
138 'description' => __( 'A list of arguments to filter by.', 'pods' ),
139 'swagger_type' => 'array',
140 ],
141 ];
142 }
143
144 /**
145 * {@inheritdoc}
146 *
147 * @since 2.8.0
148 */
149 public function get( WP_REST_Request $request ) {
150 return $this->archive_by_args( $request );
151 }
152
153 /**
154 * Determine whether access to READ is available.
155 *
156 * @since 2.8.0
157 *
158 * @return bool Whether access to READ is available.
159 */
160 public function can_read() {
161 return pods_is_admin( 'pods' );
162 }
163
164 /**
165 * {@inheritdoc}
166 *
167 * @since 2.8.0
168 */
169 public function CREATE_args() {
170 return [
171 'pod_id' => [
172 'type' => 'string',
173 'description' => __( 'The Pod ID.', 'pods' ),
174 'validate_callback' => [ $this->validator, 'is_pod_id' ],
175 ],
176 'pod' => [
177 'type' => 'string',
178 'description' => __( 'The Pod name.', 'pods' ),
179 'validate_callback' => [ $this->validator, 'is_pod_slug' ],
180 ],
181 'name' => [
182 'type' => 'string',
183 'description' => __( 'The name of the Group.', 'pods' ),
184 ],
185 'label' => [
186 'type' => 'string',
187 'description' => __( 'The singular label of the Group.', 'pods' ),
188 'required' => true,
189 ],
190 'args' => [
191 'required' => false,
192 'description' => __( 'A list of additional options to save to the Group.', 'pods' ),
193 'swagger_type' => 'array',
194 ],
195 ];
196 }
197
198 /**
199 * {@inheritdoc}
200 *
201 * @since 2.8.0
202 */
203 public function create( WP_REST_REQUEST $request, $return_id = false ) {
204 return $this->create_by_args( $request, $return_id );
205 }
206
207 /**
208 * {@inheritdoc}
209 *
210 * @since 2.8.0
211 */
212 public function can_create() {
213 return pods_is_admin( 'pods' );
214 }
215 }
216