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
Groups.php
268 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 | 'type' => 'string', |
| 36 | ]; |
| 37 | |
| 38 | $POST_defaults = [ |
| 39 | 'in' => 'body', |
| 40 | 'default' => '', |
| 41 | 'type' => 'string', |
| 42 | ]; |
| 43 | |
| 44 | return [ |
| 45 | 'get' => [ |
| 46 | 'summary' => 'Retrieve a collection of Groups', |
| 47 | 'parameters' => $this->swaggerize_args( $this->READ_args(), $GET_defaults ), |
| 48 | 'responses' => [ |
| 49 | '200' => [ |
| 50 | 'description' => 'Returns a collection of Groups matching the request', |
| 51 | 'content' => [ |
| 52 | 'application/json' => [ |
| 53 | 'schema' => [ |
| 54 | 'type' => 'object', |
| 55 | 'properties' => [ |
| 56 | 'rest_url' => [ |
| 57 | 'type' => 'string', |
| 58 | 'format' => 'uri', |
| 59 | 'description' => __( 'This results page REST URL.', 'pods' ), |
| 60 | ], |
| 61 | 'total' => [ |
| 62 | 'type' => 'integer', |
| 63 | 'description' => __( 'The total number of results across all pages.', 'pods' ), |
| 64 | ], |
| 65 | 'total_pages' => [ |
| 66 | 'type' => 'integer', |
| 67 | 'description' => __( 'The total number of result pages matching the search criteria.', 'pods' ), |
| 68 | ], |
| 69 | 'groups' => [ |
| 70 | 'type' => 'array', |
| 71 | 'items' => [ '$ref' => '#/components/schemas/Group' ], |
| 72 | ], |
| 73 | ], |
| 74 | ], |
| 75 | ], |
| 76 | ], |
| 77 | ], |
| 78 | '400' => [ |
| 79 | 'description' => 'The request was invalid or cannot be otherwise served', |
| 80 | 'content' => [ |
| 81 | 'application/json' => [ |
| 82 | 'schema' => [ |
| 83 | 'type' => 'object', |
| 84 | ], |
| 85 | ], |
| 86 | ], |
| 87 | ], |
| 88 | '401' => [ |
| 89 | 'description' => 'Unauthorized access - user does not have permission to access Groups', |
| 90 | 'content' => [ |
| 91 | 'application/json' => [ |
| 92 | 'schema' => [ |
| 93 | 'type' => 'object', |
| 94 | ], |
| 95 | ], |
| 96 | ], |
| 97 | ], |
| 98 | ], |
| 99 | ], |
| 100 | 'post' => [ |
| 101 | 'summary' => 'Create a new Group', |
| 102 | 'parameters' => $this->swaggerize_args( $this->CREATE_args(), $POST_defaults ), |
| 103 | 'responses' => [ |
| 104 | '201' => [ |
| 105 | 'description' => 'Returns the newly created Group', |
| 106 | 'content' => [ |
| 107 | 'application/json' => [ |
| 108 | 'schema' => [ |
| 109 | '$ref' => '#/components/schemas/Group', |
| 110 | ], |
| 111 | ], |
| 112 | ], |
| 113 | ], |
| 114 | '400' => [ |
| 115 | 'description' => 'The request was invalid or cannot be otherwise served', |
| 116 | 'content' => [ |
| 117 | 'application/json' => [ |
| 118 | 'schema' => [ |
| 119 | 'type' => 'object', |
| 120 | ], |
| 121 | ], |
| 122 | ], |
| 123 | ], |
| 124 | '401' => [ |
| 125 | 'description' => 'Unauthorized access - user does not have permission to create Groups', |
| 126 | 'content' => [ |
| 127 | 'application/json' => [ |
| 128 | 'schema' => [ |
| 129 | 'type' => 'object', |
| 130 | ], |
| 131 | ], |
| 132 | ], |
| 133 | ], |
| 134 | '403' => [ |
| 135 | 'description' => 'Forbidden - creation of this Group is not allowed', |
| 136 | 'content' => [ |
| 137 | 'application/json' => [ |
| 138 | 'schema' => [ |
| 139 | 'type' => 'object', |
| 140 | ], |
| 141 | ], |
| 142 | ], |
| 143 | ], |
| 144 | ], |
| 145 | ], |
| 146 | ]; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * {@inheritdoc} |
| 151 | * |
| 152 | * @since 2.8.0 |
| 153 | */ |
| 154 | public function READ_args() { |
| 155 | return [ |
| 156 | 'return_type' => [ |
| 157 | 'description' => __( 'The type of data to return.', 'pods' ), |
| 158 | 'type' => 'string', |
| 159 | 'default' => 'full', |
| 160 | 'required' => false, |
| 161 | 'enum' => [ |
| 162 | 'full', |
| 163 | 'names', |
| 164 | 'names_ids', |
| 165 | 'ids', |
| 166 | 'key_names', |
| 167 | 'count', |
| 168 | ], |
| 169 | ], |
| 170 | 'types' => [ |
| 171 | 'required' => false, |
| 172 | 'description' => __( 'A list of types to filter by.', 'pods' ), |
| 173 | 'swagger_type' => 'array', |
| 174 | 'items' => [ |
| 175 | 'type' => 'string', |
| 176 | ], |
| 177 | 'collectionFormat' => 'csv', |
| 178 | ], |
| 179 | 'ids' => [ |
| 180 | 'required' => false, |
| 181 | 'description' => __( 'A list of IDs to filter by.', 'pods' ), |
| 182 | 'swagger_type' => 'array', |
| 183 | 'items' => [ |
| 184 | 'type' => 'integer', |
| 185 | ], |
| 186 | 'collectionFormat' => 'csv', |
| 187 | ], |
| 188 | 'args' => [ |
| 189 | 'required' => false, |
| 190 | 'description' => __( 'A list of arguments to filter by.', 'pods' ), |
| 191 | 'swagger_type' => 'array', |
| 192 | ], |
| 193 | ]; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * {@inheritdoc} |
| 198 | * |
| 199 | * @since 2.8.0 |
| 200 | */ |
| 201 | public function get( WP_REST_Request $request ) { |
| 202 | return $this->archive_by_args( $request ); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Determine whether access to READ is available. |
| 207 | * |
| 208 | * @since 2.8.0 |
| 209 | * |
| 210 | * @return bool Whether access to READ is available. |
| 211 | */ |
| 212 | public function can_read() { |
| 213 | return pods_is_admin( 'pods' ); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * {@inheritdoc} |
| 218 | * |
| 219 | * @since 2.8.0 |
| 220 | */ |
| 221 | public function CREATE_args() { |
| 222 | return [ |
| 223 | 'pod_id' => [ |
| 224 | 'type' => 'string', |
| 225 | 'description' => __( 'The Pod ID.', 'pods' ), |
| 226 | 'validate_callback' => [ $this->validator, 'is_pod_id' ], |
| 227 | ], |
| 228 | 'pod' => [ |
| 229 | 'type' => 'string', |
| 230 | 'description' => __( 'The Pod name.', 'pods' ), |
| 231 | 'validate_callback' => [ $this->validator, 'is_pod_slug' ], |
| 232 | ], |
| 233 | 'name' => [ |
| 234 | 'type' => 'string', |
| 235 | 'description' => __( 'The name of the Group.', 'pods' ), |
| 236 | ], |
| 237 | 'label' => [ |
| 238 | 'type' => 'string', |
| 239 | 'description' => __( 'The singular label of the Group.', 'pods' ), |
| 240 | 'required' => true, |
| 241 | ], |
| 242 | 'args' => [ |
| 243 | 'required' => false, |
| 244 | 'description' => __( 'A list of additional options to save to the Group.', 'pods' ), |
| 245 | 'swagger_type' => 'array', |
| 246 | ], |
| 247 | ]; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * {@inheritdoc} |
| 252 | * |
| 253 | * @since 2.8.0 |
| 254 | */ |
| 255 | public function create( WP_REST_REQUEST $request, $return_id = false ) { |
| 256 | return $this->create_by_args( $request, $return_id ); |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * {@inheritdoc} |
| 261 | * |
| 262 | * @since 2.8.0 |
| 263 | */ |
| 264 | public function can_create() { |
| 265 | return pods_is_admin( 'pods' ); |
| 266 | } |
| 267 | } |
| 268 |