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
Group.php
239 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 | // @todo Handle get/post/delete |
| 54 | |
| 55 | return [ |
| 56 | 'get' => [ |
| 57 | 'summary' => '', // @todo Fill this out |
| 58 | 'parameters' => $this->swaggerize_args( $this->READ_args(), $GET_defaults ), |
| 59 | 'responses' => [ |
| 60 | '200' => [ |
| 61 | 'description' => '', // @todo Fill this out |
| 62 | 'content' => [ |
| 63 | 'application/json' => [ |
| 64 | 'schema' => [ |
| 65 | '$ref' => '#/components/schemas/Group', |
| 66 | ], |
| 67 | ], |
| 68 | ], |
| 69 | ], |
| 70 | '400' => [ |
| 71 | 'description' => '', // @todo Fill this out |
| 72 | 'content' => [ |
| 73 | 'application/json' => [ |
| 74 | 'schema' => [ |
| 75 | 'type' => 'object', |
| 76 | ], |
| 77 | ], |
| 78 | ], |
| 79 | ], |
| 80 | '401' => [ |
| 81 | 'description' => '', // @todo Fill this out |
| 82 | 'content' => [ |
| 83 | 'application/json' => [ |
| 84 | 'schema' => [ |
| 85 | 'type' => 'object', |
| 86 | ], |
| 87 | ], |
| 88 | ], |
| 89 | ], |
| 90 | '404' => [ |
| 91 | 'description' => '', // @todo Fill this out |
| 92 | 'content' => [ |
| 93 | 'application/json' => [ |
| 94 | 'schema' => [ |
| 95 | 'type' => 'object', |
| 96 | ], |
| 97 | ], |
| 98 | ], |
| 99 | ], |
| 100 | ], |
| 101 | ], |
| 102 | ]; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * {@inheritdoc} |
| 107 | * |
| 108 | * @since 2.8.0 |
| 109 | */ |
| 110 | public function READ_args() { |
| 111 | return [ |
| 112 | 'id' => [ |
| 113 | 'type' => 'integer', |
| 114 | 'in' => 'path', |
| 115 | 'description' => __( 'The Group ID.', 'pods' ), |
| 116 | 'required' => true, |
| 117 | 'validate_callback' => [ $this->validator, 'is_group_id' ], |
| 118 | ], |
| 119 | 'include_fields' => [ |
| 120 | 'type' => 'boolean', |
| 121 | 'description' => __( 'Whether to include fields (default: off).', 'pods' ), |
| 122 | 'default' => false, |
| 123 | 'cli_boolean' => true, |
| 124 | ], |
| 125 | ]; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * {@inheritdoc} |
| 130 | * |
| 131 | * @since 2.8.0 |
| 132 | */ |
| 133 | public function get( WP_REST_Request $request ) { |
| 134 | return $this->get_by_args( 'id', 'id', $request ); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Determine whether access to READ is available. |
| 139 | * |
| 140 | * @since 2.8.0 |
| 141 | * |
| 142 | * @return bool Whether access to READ is available. |
| 143 | */ |
| 144 | public function can_read() { |
| 145 | return pods_is_admin( 'pods' ); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * {@inheritdoc} |
| 150 | * |
| 151 | * @since 2.8.0 |
| 152 | */ |
| 153 | public function EDIT_args() { |
| 154 | return [ |
| 155 | 'id' => [ |
| 156 | 'type' => 'integer', |
| 157 | 'in' => 'path', |
| 158 | 'description' => __( 'The Group ID.', 'pods' ), |
| 159 | 'required' => true, |
| 160 | 'validate_callback' => [ $this->validator, 'is_group_id' ], |
| 161 | ], |
| 162 | 'name' => [ |
| 163 | 'type' => 'string', |
| 164 | 'description' => __( 'The new name of the Group.', 'pods' ), |
| 165 | ], |
| 166 | 'label' => [ |
| 167 | 'type' => 'string', |
| 168 | 'description' => __( 'The singular label of the Group.', 'pods' ), |
| 169 | ], |
| 170 | 'type' => [ |
| 171 | 'type' => 'string', |
| 172 | 'description' => __( 'The type of the Group.', 'pods' ), |
| 173 | ], |
| 174 | 'args' => [ |
| 175 | 'required' => false, |
| 176 | 'description' => __( 'A list of additional options to save to the Group.', 'pods' ), |
| 177 | 'swagger_type' => 'array', |
| 178 | ], |
| 179 | ]; |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * {@inheritdoc} |
| 184 | * |
| 185 | * @since 2.8.0 |
| 186 | */ |
| 187 | public function update( WP_REST_Request $request ) { |
| 188 | if ( ! empty( $request['fields'] ) ) { |
| 189 | $request->set_param( 'fields', null ); |
| 190 | } |
| 191 | |
| 192 | return $this->update_by_args( 'id', 'id', $request ); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * {@inheritdoc} |
| 197 | * |
| 198 | * @since 2.8.0 |
| 199 | */ |
| 200 | public function can_edit() { |
| 201 | return pods_is_admin( 'pods' ); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * {@inheritdoc} |
| 206 | * |
| 207 | * @since 2.8.0 |
| 208 | */ |
| 209 | public function DELETE_args() { |
| 210 | return [ |
| 211 | 'id' => [ |
| 212 | 'type' => 'integer', |
| 213 | 'in' => 'path', |
| 214 | 'description' => __( 'The Group ID.', 'pods' ), |
| 215 | 'required' => true, |
| 216 | 'validate_callback' => [ $this->validator, 'is_group_id' ], |
| 217 | ], |
| 218 | ]; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * {@inheritdoc} |
| 223 | * |
| 224 | * @since 2.8.0 |
| 225 | */ |
| 226 | public function delete( WP_REST_Request $request ) { |
| 227 | return $this->delete_by_args( 'id', 'id', $request ); |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * {@inheritdoc} |
| 232 | * |
| 233 | * @since 2.8.0 |
| 234 | */ |
| 235 | public function can_delete() { |
| 236 | return pods_is_admin( 'pods' ); |
| 237 | } |
| 238 | } |
| 239 |