From dd853552a7a61b1aae44690af6615c0f766aaa26 Mon Sep 17 00:00:00 2001 From: Weryques Date: Fri, 2 Feb 2018 12:29:51 -0200 Subject: [PATCH 01/68] Update tainacan-api.md --- docs/tainacan-api.md | 335 ++++++++++++++++++++++--------------------- 1 file changed, 168 insertions(+), 167 deletions(-) diff --git a/docs/tainacan-api.md b/docs/tainacan-api.md index a1bc42fa9..ee7700823 100644 --- a/docs/tainacan-api.md +++ b/docs/tainacan-api.md @@ -10,277 +10,278 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API. 1. Route `wp-json/tainacan/v2/collections/(?P[\d]+)` - 1.1. Endpoints supported: +1.1. Endpoints supported: - 1.1.1 GET (Fetch a collection) +1.1.1 GET (Fetch a collection) - 1.1.2 DELETE (Delete or Trash a collection and all your dependencies) +1.1.2 DELETE (Delete or Trash a collection and all your dependencies) - ``` - To delete pass in body of a requisition the parameter is_permanently as true. - To only trash pass false. - ``` - - 1.1.3 PATCH or PUT (Update a collection) - - Example of JSON passed in body for updating a collection: -     ``` - { -    "name": "string", -    "description": "string", - ... -  } +To delete pass in body of a requisition the parameter is_permanently as true. +To only trash pass false. +``` + +1.1.3 PATCH or PUT (Update a collection) + +Example of JSON passed in body for updating a collection: +     +```javascript +{ +"name": "string", +"description": "string", +... +} ``` 2. Route `wp-json/tainacan/v2/collections` - 2.1. Endpoints supported: +2.1. Endpoints supported: - 2.1.1 GET (Fetch all collections) +2.1.1 GET (Fetch all collections) - 2.1.2 POST (Create a collection). +2.1.2 POST (Create a collection). - Example of JSON passed in body for creating a collection: +Example of JSON passed in body for creating a collection: ```javascript - { -   "name": "string", -    "description": "string", -    "status": "string", -    "order": "string", -    "parent": "integer", -    "slug": "string", -    "default_orderby": "string", -    "default_order": "string", -    "columns": "string", -    "default_view_mode": "string" -  } +{ +"name": "string", +"description": "string", +"status": "string", +"order": "string", +"parent": "integer", +"slug": "string", +"default_orderby": "string", +"default_order": "string", +"columns": "string", +"default_view_mode": "string" +} ``` #### Items 1. Route `wp-json/tainacan/v2/collection/(?P[\d]+)/items` - 1.1. Endpoints supported: +1.1. Endpoints supported: - 1.1.1 GET (Fetch all items from a collection) +1.1.1 GET (Fetch all items from a collection) - 1.1.2 POST (Create a item in a collection) +1.1.2 POST (Create a item in a collection) - Example of JSON passed in body for creating a item: +Example of JSON passed in body for creating a item: ```javascript - { -   "title": "string", -    "description": "string", -    "status": "string", -  } +{ +"title": "string", +"description": "string", +"status": "string", +} ``` 2. Route `wp-json/tainacan/v2/items/(?P[\d]+)` - 2.1. Endpoints supported: +2.1. Endpoints supported: - 2.1.1 GET (Fetch a item) +2.1.1 GET (Fetch a item) - 2.1.2 DELETE (Delete or Trash a item and all your dependencies) +2.1.2 DELETE (Delete or Trash a item and all your dependencies) - ``` - To delete pass in body of a requisition the parameter is_permanently as true. - To only trash pass false. - ``` +``` +To delete pass in body of a requisition the parameter is_permanently as true. +To only trash pass false. +``` - 2.1.3 PATCH or PUT (Update a item) +2.1.3 PATCH or PUT (Update a item) - Example of JSON passed in body for updating a item: +Example of JSON passed in body for updating a item:     ``` - { -    "title": "string", -    "description": "string", - ... -  } +{ +"title": "string", +"description": "string", +... +} ``` #### Metadata 1. Route `wp-json/tainacan/v2/collection/(?P[\d]+)/metadata` - 1.1. Endpoints supported: +1.1. Endpoints supported: - 1.1.1 POST (Create a metadata in collection and all your items) +1.1.1 POST (Create a metadata in collection and all your items) - In body of requisition pass a JSON with the attributes of metadata like: +In body of requisition pass a JSON with the attributes of metadata like: ```javascript - { -       "name": "string", -       "description": "string", -       "field_type": "string", -       "order": "string", -       "parent": "integer", -       "required": "string", -       "collection_key": "string", -       "multiple": "string", -       "cardinality": "string", -       "privacy": "string", -       "mask": "string", -       "default_value": "string", -       "field_type_options": "string", -    } +{ +"name": "string", +"description": "string", +"field_type": "string", +"order": "string", +"parent": "integer", +"required": "string", +"collection_key": "string", +"multiple": "string", +"cardinality": "string", +"privacy": "string", +"mask": "string", +"default_value": "string", +"field_type_options": "string", +} ``` - 1.1.2 GET (Fetch all collection metadata) +1.1.2 GET (Fetch all collection metadata) 2. Route `wp-json/tainacan/v2/item/(?P[\d]+)/metadata` - 2.1. Endpoints supported: +2.1. Endpoints supported: - 2.1.1 POST (Set a value of item metadata) +2.1.1 POST (Set a value of item metadata) - In body of requisition pass a JSON with value e and id of metadata like: +In body of requisition pass a JSON with value e and id of metadata like: ```javascript - { -     "metadata_id": "integer", -     "values": "[any, type]" -  } +{ +"metadata_id": "integer", +"values": "[any, type]" +} ``` - - 2.1.2 GET (Fetch all item metadata, with your values) + +2.1.2 GET (Fetch all item metadata, with your values) #### Taxonomies 1. Route `wp-json/tainacan/v2/taxonomies` - 1.1. Endpoints supported: +1.1. Endpoints supported: - 1.1.1. GET (Fetch all taxonomies) +1.1.1. GET (Fetch all taxonomies) - 1.1.2. POST (Create a taxonomy) +1.1.2. POST (Create a taxonomy) - Example of JSON passed in body for creating a taxonomy: +Example of JSON passed in body for creating a taxonomy: ```javascript - { -   "name": "string", -    "description": "string", -    "status": "string", -    "parent": "string", -    "slug": "string", -    "allow_insert": "string", -    "collections_ids": "array" -  } +{ +"name": "string", +"description": "string", +"status": "string", +"parent": "string", +"slug": "string", +"allow_insert": "string", +"collections_ids": "array" +} ``` 2. Route `wp-json/tainacan/v2/taxonomies/(?P[\d]+)` - 2.1. Endpoints supported: +2.1. Endpoints supported: - 2.1.1 GET (Fetch a taxonomy) +2.1.1 GET (Fetch a taxonomy) - 2.1.2 DELETE (Delete or trash a taxonomy) +2.1.2 DELETE (Delete or trash a taxonomy) - ``` - To delete pass in body of requisition the parameter is_permanently as true. - To only trash pass false. - ``` +``` +To delete pass in body of requisition the parameter is_permanently as true. +To only trash pass false. +``` - 2.1.3 PATCH or PUT (Update a taxonomy) +2.1.3 PATCH or PUT (Update a taxonomy) - Example of JSON passed in body for updating a taxonomy: +Example of JSON passed in body for updating a taxonomy:     ```javascript - { -    "name": "string", -    "description": "string", - ... -  } +{ +"name": "string", +"description": "string", +... +} ``` #### Filters 1. Route `wp-json/tainacan/v2/filters` - 1.1 Endpoints supported: - 1.1.1 POST (Create a filter) +1.1 Endpoints supported: - Example of JSON passed in body for creating a filter: +1.1.1 POST (Create a filter) - ```javascript - { -   "collection_id": "int", -   "metadata_id": "int", - "filter_type": "string", -   "filter": { -     "name": "string", -     "description": "string", - ... -   } - } - ``` - - 1.1.2 GET (Fetch all filters) - - 2. Route `wp-json/tainacan/v2/filters/(?P[\d]+)` - - 2.1. Endpoints supported: - - 2.1.1 DELETE (Delete or trash a filter) - - ``` - To delete pass in body of requisition the parameter is_permanently as true. - To only trash pass false. - ``` - - 2.1.2 PATCH or PUT (Update a filter) - - Example of JSON passed in body for updating a filter: +Example of JSON passed in body for creating a filter: ```javascript - { - "name": "string", - ... - } +{ +"collection_id": "int", +"metadata_id": "int", +"filter_type": "string", +"filter": { +"name": "string", +"description": "string", +... +} +} +``` + +1.1.2 GET (Fetch all filters) + +2. Route `wp-json/tainacan/v2/filters/(?P[\d]+)` + +2.1. Endpoints supported: + +2.1.1 DELETE (Delete or trash a filter) + +``` +To delete pass in body of requisition the parameter is_permanently as true. +To only trash pass false. ``` - 2.1.3 GET (Fetch a filter) +2.1.2 PATCH or PUT (Update a filter) + +Example of JSON passed in body for updating a filter: + +```javascript +{ +"name": "string", +... +} +``` + +2.1.3 GET (Fetch a filter) #### Terms 1. Route `wp-json/tainacan/v2/taxonomy/(?P[\d]+)/terms` - 1.1 Endpoints supported: +1.1 Endpoints supported: - 1.1.1 POST (Create a term in a taxonomy) +1.1.1 POST (Create a term in a taxonomy) - Example of JSON passed in body for creating a term: +Example of JSON passed in body for creating a term: ```javascript - { -   "name": "string", -   "user": "int", - ... - } - ``` +{ +"name": "string", +"user": "int", +... +} +``` -    1.1.2 GET (Fetch all tems of a taxonomy) +1.1.2 GET (Fetch all tems of a taxonomy) 2. Route `wp-json/tainacan/v2/taxonomy/(?P[\d]+)/terms/(?P[\d]+)` - 2.1 Endpoints supported: +2.1 Endpoints supported: - 2.1.1 GET (Fecth a term of a taxonomy) +2.1.1 GET (Fecth a term of a taxonomy) - 2.1.2 PATCH or PUT (Update a term in a taxonomy) +2.1.2 PATCH or PUT (Update a term in a taxonomy) - Example of JSON passed in body for updating a term: +Example of JSON passed in body for updating a term: ```javascript - { -   "name": "string", - ... - } +{ +"name": "string", +... +} ``` - 2.1.3 DELETE (Delete a term of a taxonoy) +2.1.3 DELETE (Delete a term of a taxonoy) From 760de476306864ce296a8061cfc867fe7f13b26f Mon Sep 17 00:00:00 2001 From: Weryques Date: Fri, 2 Feb 2018 14:01:57 -0200 Subject: [PATCH 02/68] Update tainacan-api.md --- docs/tainacan-api.md | 126 +++++++++++++++++++++++++++++-------------- 1 file changed, 86 insertions(+), 40 deletions(-) diff --git a/docs/tainacan-api.md b/docs/tainacan-api.md index ee7700823..b1a71cea7 100644 --- a/docs/tainacan-api.md +++ b/docs/tainacan-api.md @@ -4,17 +4,18 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API. +------ ### Routes and Endpoints - +------ #### Collections 1. Route `wp-json/tainacan/v2/collections/(?P[\d]+)` 1.1. Endpoints supported: -1.1.1 GET (Fetch a collection) +1.1.1. GET (Fetch a collection) -1.1.2 DELETE (Delete or Trash a collection and all your dependencies) +1.1.2. DELETE (Delete or Trash a collection and all your dependencies) ``` To delete pass in body of a requisition the parameter is_permanently as true. @@ -37,9 +38,9 @@ Example of JSON passed in body for updating a collection: 2.1. Endpoints supported: -2.1.1 GET (Fetch all collections) +2.1.1. GET (Fetch all collections) -2.1.2 POST (Create a collection). +2.1.2. POST (Create a collection). Example of JSON passed in body for creating a collection: @@ -57,15 +58,16 @@ Example of JSON passed in body for creating a collection: "default_view_mode": "string" } ``` +------ #### Items 1. Route `wp-json/tainacan/v2/collection/(?P[\d]+)/items` 1.1. Endpoints supported: -1.1.1 GET (Fetch all items from a collection) +1.1.1. GET (Fetch all items from a collection) -1.1.2 POST (Create a item in a collection) +1.1.2. POST (Create a item in a collection) Example of JSON passed in body for creating a item: @@ -81,16 +83,16 @@ Example of JSON passed in body for creating a item: 2.1. Endpoints supported: -2.1.1 GET (Fetch a item) +2.1.1. GET (Fetch a item) -2.1.2 DELETE (Delete or Trash a item and all your dependencies) +2.1.2. DELETE (Delete or Trash a item and all your dependencies) ``` To delete pass in body of a requisition the parameter is_permanently as true. To only trash pass false. ``` -2.1.3 PATCH or PUT (Update a item) +2.1.3. PATCH or PUT (Update a item) Example of JSON passed in body for updating a item:     @@ -101,16 +103,16 @@ Example of JSON passed in body for updating a item: ... } ``` +------ +#### Fields -#### Metadata - -1. Route `wp-json/tainacan/v2/collection/(?P[\d]+)/metadata` +1. Route `wp-json/tainacan/v2/collection/(?P[\d]+)/fields` 1.1. Endpoints supported: -1.1.1 POST (Create a metadata in collection and all your items) +1.1.1. POST (Create a field in collection and all it items) -In body of requisition pass a JSON with the attributes of metadata like: +In body of requisition pass a JSON with the attributes of field like: ```javascript { @@ -130,25 +132,46 @@ In body of requisition pass a JSON with the attributes of metadata like: } ``` -1.1.2 GET (Fetch all collection metadata) - -2. Route `wp-json/tainacan/v2/item/(?P[\d]+)/metadata` +1.1.2 GET (Fetch all collection field) + +2. Route `wp-json/tainacan/v2/collection/(?P[\d]+)/fields/(?P[\d]+)` 2.1. Endpoints supported: + +2.1.1. PATCH or PUT (Update a field in a collection and all it items) + +In body of requisition pass a JSON with the attributes you need to update, like: + +```javascript +{ +"name": "string", +"description": "string", +} +``` +------ +#### Item Metadata + +1. Route `wp-json/tainacan/v2/item/(?P[\d]+)/metadata/(?P[\d]+)` + +1.1. Endpoints supported: -2.1.1 POST (Set a value of item metadata) +1.1.1. PATCH or PUT (Set value of a metadata) -In body of requisition pass a JSON with value e and id of metadata like: +In body of requisition pass a JSON with values of metadata, like: ```javascript { -"metadata_id": "integer", "values": "[any, type]" } ``` - -2.1.2 GET (Fetch all item metadata, with your values) - + +2. Route `wp-json/tainacan/v2/item/(?P[\d]+)/metadata` + +2.1. Enpoints supported: + +2.1.1. GET (Fetch all item metadata, with it values) + +------ #### Taxonomies 1. Route `wp-json/tainacan/v2/taxonomies` @@ -177,16 +200,16 @@ Example of JSON passed in body for creating a taxonomy: 2.1. Endpoints supported: -2.1.1 GET (Fetch a taxonomy) +2.1.1. GET (Fetch a taxonomy) -2.1.2 DELETE (Delete or trash a taxonomy) +2.1.2. DELETE (Delete or trash a taxonomy) ``` To delete pass in body of requisition the parameter is_permanently as true. To only trash pass false. ``` -2.1.3 PATCH or PUT (Update a taxonomy) +2.1.3. PATCH or PUT (Update a taxonomy) Example of JSON passed in body for updating a taxonomy:     @@ -198,13 +221,20 @@ Example of JSON passed in body for updating a taxonomy: } ``` +3. Route `wp-json/tainacan/v2/taxonomies/(?P[\d]+)/collection/(?P[\d]+)` + +3.1. Routes supported: + +3.1.1. PATCH or PUT (Add a Collection in a Taxonomy) + +------ #### Filters 1. Route `wp-json/tainacan/v2/filters` -1.1 Endpoints supported: +1.1. Endpoints supported: -1.1.1 POST (Create a filter) +1.1.1. POST (Create a filter) Example of JSON passed in body for creating a filter: @@ -221,20 +251,20 @@ Example of JSON passed in body for creating a filter: } ``` -1.1.2 GET (Fetch all filters) +1.1.2. GET (Fetch all filters) 2. Route `wp-json/tainacan/v2/filters/(?P[\d]+)` 2.1. Endpoints supported: -2.1.1 DELETE (Delete or trash a filter) +2.1.1. DELETE (Delete or trash a filter) ``` To delete pass in body of requisition the parameter is_permanently as true. To only trash pass false. ``` -2.1.2 PATCH or PUT (Update a filter) +2.1.2. PATCH or PUT (Update a filter) Example of JSON passed in body for updating a filter: @@ -245,15 +275,16 @@ Example of JSON passed in body for updating a filter: } ``` -2.1.3 GET (Fetch a filter) - +2.1.3. GET (Fetch a filter) + +------ #### Terms 1. Route `wp-json/tainacan/v2/taxonomy/(?P[\d]+)/terms` -1.1 Endpoints supported: +1.1. Endpoints supported: -1.1.1 POST (Create a term in a taxonomy) +1.1.1. POST (Create a term in a taxonomy) Example of JSON passed in body for creating a term: @@ -269,11 +300,11 @@ Example of JSON passed in body for creating a term: 2. Route `wp-json/tainacan/v2/taxonomy/(?P[\d]+)/terms/(?P[\d]+)` -2.1 Endpoints supported: +2.1. Endpoints supported: -2.1.1 GET (Fecth a term of a taxonomy) +2.1.1. GET (Fecth a term of a taxonomy) -2.1.2 PATCH or PUT (Update a term in a taxonomy) +2.1.2. PATCH or PUT (Update a term in a taxonomy) Example of JSON passed in body for updating a term: @@ -284,4 +315,19 @@ Example of JSON passed in body for updating a term: } ``` -2.1.3 DELETE (Delete a term of a taxonoy) +2.1.3. DELETE (Delete a term of a taxonoy) + +------ +#### Logs + +1. Route `wp-json/tainacan/v2/logs` + +1.1. Endpoints supported: + +1.1.1. GET (Get all logs) + +2. Route `wp-json/tainacan/v2/logs/(?P[\d]+)` + +2.1. Enpoints supported: + +2.1.1. GET (Get a log) From f7fc0a7707d1599523999f01178b59c955a331ec Mon Sep 17 00:00:00 2001 From: Weryques Date: Fri, 2 Feb 2018 14:14:46 -0200 Subject: [PATCH 03/68] Update tainacan-api.md --- docs/tainacan-api.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/tainacan-api.md b/docs/tainacan-api.md index b1a71cea7..c142da002 100644 --- a/docs/tainacan-api.md +++ b/docs/tainacan-api.md @@ -6,6 +6,18 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API. ------ ### Routes and Endpoints + +#### Sumary + +1. [Collections](#collections) +1. [Items](#items) +1. [Fields](#fields) +1. [Item Metadata](#item-metadata) +1. [Taxonomies](#taxonomies) +1. [Filters](#filters) +1. [Terms](#terms) +1. [Logs](#logs) + ------ #### Collections From 51c4f763a22979c0200afd19f6e36a24cf4a3b38 Mon Sep 17 00:00:00 2001 From: Weryques Date: Fri, 2 Feb 2018 14:36:11 -0200 Subject: [PATCH 04/68] Update tainacan-api.md --- docs/tainacan-api.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/tainacan-api.md b/docs/tainacan-api.md index c142da002..687e58411 100644 --- a/docs/tainacan-api.md +++ b/docs/tainacan-api.md @@ -17,6 +17,7 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API. 1. [Filters](#filters) 1. [Terms](#terms) 1. [Logs](#logs) +1. [Others](#others) ------ #### Collections @@ -343,3 +344,12 @@ Example of JSON passed in body for updating a term: 2.1. Enpoints supported: 2.1.1. GET (Get a log) + +------ +#### Others + +To Create, Read, Update or Delete Media or Users you can use the default routes of Wordpress. + +See about Media in [Media | REST API Handbook](https://developer.wordpress.org/rest-api/reference/media/); + +See about Users in [Users | REST API Handbook](https://developer.wordpress.org/rest-api/reference/users/). From dd0d5c037702c8486fae54dc454e7b0e4903c4a9 Mon Sep 17 00:00:00 2001 From: Weryques Date: Fri, 2 Feb 2018 14:37:06 -0200 Subject: [PATCH 05/68] Update tainacan-api.md --- docs/tainacan-api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tainacan-api.md b/docs/tainacan-api.md index 687e58411..93cfd7f30 100644 --- a/docs/tainacan-api.md +++ b/docs/tainacan-api.md @@ -7,7 +7,7 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API. ------ ### Routes and Endpoints -#### Sumary +#### Summary 1. [Collections](#collections) 1. [Items](#items) From b47d815a7452038ba8cbf0e7a132d96dff15625f Mon Sep 17 00:00:00 2001 From: Weryques Date: Wed, 14 Feb 2018 14:41:48 -0200 Subject: [PATCH 06/68] Update tainacan-api.md --- docs/tainacan-api.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/tainacan-api.md b/docs/tainacan-api.md index 93cfd7f30..d3d64121e 100644 --- a/docs/tainacan-api.md +++ b/docs/tainacan-api.md @@ -178,6 +178,15 @@ In body of requisition pass a JSON with values of metadata, like: } ``` +If you want to update a metadata with multiple values, you will need to pass a body like (attribute multiple with value 'yes'): + +```javascript +{ +"values": "[any, type]", +"multiple": "yes" +} +``` + 2. Route `wp-json/tainacan/v2/item/(?P[\d]+)/metadata` 2.1. Enpoints supported: From 50c219c383d45c776fc383264a99995d6d934a8c Mon Sep 17 00:00:00 2001 From: Weryques Date: Wed, 14 Feb 2018 16:16:39 -0200 Subject: [PATCH 07/68] Update tainacan-api.md --- docs/tainacan-api.md | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/docs/tainacan-api.md b/docs/tainacan-api.md index d3d64121e..3ca413699 100644 --- a/docs/tainacan-api.md +++ b/docs/tainacan-api.md @@ -174,16 +174,10 @@ In body of requisition pass a JSON with values of metadata, like: ```javascript { -"values": "[any, type]" -} -``` - -If you want to update a metadata with multiple values, you will need to pass a body like (attribute multiple with value 'yes'): - -```javascript -{ -"values": "[any, type]", -"multiple": "yes" +"values": "[ +{ "new": "any_type", "prev": "any_type"}, +{ "new": "any_type", "prev": ""} +]" } ``` From 4c63362d841de9c4df32340f9e791363672b611d Mon Sep 17 00:00:00 2001 From: Weryques Date: Wed, 14 Feb 2018 16:17:14 -0200 Subject: [PATCH 08/68] Update tainacan-api.md --- docs/tainacan-api.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tainacan-api.md b/docs/tainacan-api.md index 3ca413699..2fc80d3df 100644 --- a/docs/tainacan-api.md +++ b/docs/tainacan-api.md @@ -174,10 +174,10 @@ In body of requisition pass a JSON with values of metadata, like: ```javascript { -"values": "[ +"values": [ { "new": "any_type", "prev": "any_type"}, { "new": "any_type", "prev": ""} -]" +] } ``` From 8b449e4c9ff20a20bdbc1835d2cefa34719adb0c Mon Sep 17 00:00:00 2001 From: weryques Date: Fri, 16 Feb 2018 13:51:21 -0200 Subject: [PATCH 09/68] Refactoring prepare item for response --- src/api/class-tainacan-rest-controller.php | 36 +++++++------- ...class-tainacan-rest-filters-controller.php | 32 ++++++------ ...tainacan-rest-item-metadata-controller.php | 6 +-- .../class-tainacan-rest-logs-controller.php | 49 ++++++++++--------- ...ss-tainacan-rest-taxonomies-controller.php | 29 +++++------ .../class-tainacan-rest-terms-controller.php | 26 +++++----- .../entities/class-tainacan-filter.php | 18 +++++-- 7 files changed, 99 insertions(+), 97 deletions(-) diff --git a/src/api/class-tainacan-rest-controller.php b/src/api/class-tainacan-rest-controller.php index 289e1414d..9f68fb416 100644 --- a/src/api/class-tainacan-rest-controller.php +++ b/src/api/class-tainacan-rest-controller.php @@ -74,24 +74,24 @@ class TAINACAN_REST_Controller extends WP_REST_Controller { */ protected function prepare_filters($request){ $map = [ - 'name' => 'title', - 'title' => 'title', - 'id' => 'p', - 'pageid' => 'page_id', - 'authorid' => 'author_id', - 'authorname' => 'author_name', - 'search' => 's', - 'posttype' => 'post_type', - 'status' => 'post_status', - 'offset' => 'offset', - 'metaquery' => 'meta_query', - 'datequery' => 'date_query', - 'order' => 'order', - 'orderby' => 'orderby', - 'metakey' => 'meta_key', - 'hideempty' => 'hide_empty', - 'perpage' => 'posts_per_page', - 'paged' => 'paged' + 'name' => 'title', + 'title' => 'title', + 'id' => 'p', + 'pageid' => 'page_id', + 'authorid' => 'author_id', + 'authorname' => 'author_name', + 'search' => 's', + 'posttype' => 'post_type', + 'status' => 'post_status', + 'offset' => 'offset', + 'metaquery' => 'meta_query', + 'datequery' => 'date_query', + 'order' => 'order', + 'orderby' => 'orderby', + 'metakey' => 'meta_key', + 'hideempty' => 'hide_empty', + 'perpage' => 'posts_per_page', + 'paged' => 'paged' ]; $meta_query = [ diff --git a/src/api/endpoints/class-tainacan-rest-filters-controller.php b/src/api/endpoints/class-tainacan-rest-filters-controller.php index d28f1dc1b..26e31f35a 100644 --- a/src/api/endpoints/class-tainacan-rest-filters-controller.php +++ b/src/api/endpoints/class-tainacan-rest-filters-controller.php @@ -124,7 +124,7 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller { if ($this->filter->validate()){ $filter_inserted = $this->filter_repository->insert($this->filter); - return new WP_REST_Response($filter_inserted->__toArray(), 200); + return new WP_REST_Response($this->prepare_item_for_response($filter_inserted, $request), 200); } return new WP_REST_Response([ @@ -172,7 +172,7 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller { $filter = $this->filter_repository->delete($args); - return new WP_REST_Response($filter->__toArray(), 200); + return new WP_REST_Response($this->prepare_item_for_response($filter, $request), 200); } return new WP_REST_Response([ @@ -221,13 +221,13 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller { if($prepared_filter->validate()) { $updated_filter = $this->filter_repository->update( $prepared_filter ); - return new WP_REST_Response($updated_filter->__toArray(), 200); + return new WP_REST_Response($this->prepare_item_for_response($updated_filter, $request), 200); } return new WP_REST_Response([ 'error_message' => __('One or more values are invalid.', 'tainacan'), 'errors' => $prepared_filter->get_errors(), - 'filters' => $prepared_filter->__toArray() + 'filters' => $this->prepare_item_for_response($prepared_filter, $request) ], 400); } @@ -261,24 +261,17 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller { } /** - * @param mixed $object + * @param $item * @param WP_REST_Request $request * * @return array|mixed|WP_Error|WP_REST_Response */ - public function prepare_item_for_response( $object, $request ) { - - if(is_array($object)){ - $filters = []; - - foreach ($object as $item){ - $filters[] = $item->__toArray(); - } - - return $filters; + public function prepare_item_for_response( $item, $request ) { + if(!empty($item)) { + return $item->__toArray(); } - return $object; + return $item; } /** @@ -291,7 +284,10 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller { $filters = $this->filter_repository->fetch($args, 'OBJECT'); - $response = $this->prepare_item_for_response($filters, $request); + $response = []; + foreach ($filters as $filter){ + array_push($response, $this->prepare_item_for_response($filter, $request)); + } return new WP_REST_Response($response, 200); } @@ -315,7 +311,7 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller { $filter = $this->filter_repository->fetch($filter_id); - return new WP_REST_Response($filter->__toArray(), 200); + return new WP_REST_Response($this->prepare_item_for_response($filter, $request), 200); } /** diff --git a/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php b/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php index 0b558708e..69aa75dec 100644 --- a/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php +++ b/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php @@ -104,7 +104,7 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller { foreach ($items_metadata as $item_metadata){ $index = array_push($prepared_item, $this->prepare_item_for_response($item_metadata, $request)); - $prepared_item[$index-1]['field']['field_type_object'] = $item_metadata->get_field()->get_field_type_object()->__toArray(); + $prepared_item[$index-1]['field']['field_type_object'] = $this->prepare_item_for_response( $item_metadata->get_field()->get_field_type_object(), $request); } return new WP_REST_Response($prepared_item, 200); @@ -195,14 +195,14 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller { $field_updated = $this->item_metadata_repository->insert( $item_metadata ); $prepared_item = $this->prepare_item_for_response($field_updated, $request); - $prepared_item['field']['field_type_object'] = $field_updated->get_field()->get_field_type_object()->__toArray(); + $prepared_item['field']['field_type_object'] = $this->prepare_item_for_response($field_updated->get_field()->get_field_type_object(), $request); return new WP_REST_Response( $prepared_item, 200 ); } else { return new WP_REST_Response( [ 'error_message' => __( 'One or more values are invalid.', 'tainacan' ), 'errors' => $item_metadata->get_errors(), - 'item_metadata' => $item_metadata->__toArray(), + 'item_metadata' => $this->prepare_item_for_response($item_metadata, $request), ], 400 ); } } diff --git a/src/api/endpoints/class-tainacan-rest-logs-controller.php b/src/api/endpoints/class-tainacan-rest-logs-controller.php index b1864dc70..cb153d3c1 100644 --- a/src/api/endpoints/class-tainacan-rest-logs-controller.php +++ b/src/api/endpoints/class-tainacan-rest-logs-controller.php @@ -51,19 +51,11 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller { * @return array|WP_Error|WP_REST_Response */ public function prepare_item_for_response( $item, $request ) { - $prepared = []; - $map = $this->logs_repository->get_map(); - - - if(is_array($item)){ - foreach ($item as $it){ - $prepared[] = $this->get_only_needed_attributes($it, $map); - } - - return $prepared; + if(!empty($item)){ + return $item->__toArray(); } - return $item->__toArray(); + return $item; } /** @@ -74,15 +66,32 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller { public function get_items( $request ) { $args = $this->prepare_filters($request); - $logs = $this->logs_repository->fetch($args, 'OBJECT'); + $logs = $this->logs_repository->fetch($args); - if(!empty($logs)) { - $prepared_logs = $this->prepare_item_for_response( $logs, $request ); + $map = $this->logs_repository->get_map(); - return new WP_REST_Response($prepared_logs, 200); + $response = []; + if($logs->have_posts()){ + while ($logs->have_posts()){ + $logs->the_post(); + + $collection = new Entities\Log($logs->post); + + array_push($response, $this->get_only_needed_attributes($collection, $map)); + } + + wp_reset_postdata(); } - return new WP_REST_Response($logs, 200); + $total_logs = $logs->found_posts; + $max_pages = ceil($total_logs / (int) $logs->query_vars['posts_per_page']); + + $rest_response = new WP_REST_Response($response, 200); + + $rest_response->header('X-WP-Total', (int) $total_logs); + $rest_response->header('X-WP-TotalPages', (int) $max_pages); + + return $rest_response; } /** @@ -104,13 +113,9 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller { $log = $this->logs_repository->fetch($log_id); - if(!empty($log)) { - $prepared_log = $this->prepare_item_for_response( $log, $request ); + $prepared_log = $this->prepare_item_for_response( $log, $request ); - return new WP_REST_Response($prepared_log, 200); - } - - return new WP_REST_Response($log, 200); + return new WP_REST_Response($prepared_log, 200); } /** diff --git a/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php b/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php index a0d5b934a..5c28ec9ec 100644 --- a/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php +++ b/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php @@ -81,17 +81,11 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller { * @return array|WP_Error|WP_REST_Response */ public function prepare_item_for_response( $item, $request ) { - $taxonomies = []; - - if($request['taxonomy_id']){ + if(!empty($item)) { return $item->__toArray(); } - foreach ( $item as $it ) { - $taxonomies[] = $it->__toArray(); - } - - return $taxonomies; + return $item; } /** @@ -173,12 +167,12 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller { return new WP_REST_Response($deleted, 400); } - return new WP_REST_Response($deleted->__toArray(), 200); + return new WP_REST_Response($this->prepare_item_for_response($deleted, $request), 200); } return new WP_REST_Response([ 'error_message' => __('Taxonomy with this id ('. $taxonomy_id .') not found.', 'tainacan'), - 'taxonomy' => $taxonomy->__toArray() + 'taxonomy' => $this->prepare_item_for_response($taxonomy, $request) ], 400); } @@ -208,9 +202,12 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller { $taxonomies = $this->taxonomy_repository->fetch($args, 'OBJECT'); - $taxonomies_prepared = $this->prepare_item_for_response($taxonomies, $request); + $response = []; + foreach ($taxonomies as $taxonomy) { + array_push($response, $this->prepare_item_for_response( $taxonomy, $request )); + } - return new WP_REST_Response($taxonomies_prepared, 200); + return new WP_REST_Response($response, 200); } /** @@ -236,12 +233,12 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller { if($this->taxonomy->validate()){ $taxonomy = $this->taxonomy_repository->insert($this->taxonomy); - return new WP_REST_Response($taxonomy->__toArray(), 201); + return new WP_REST_Response($this->prepare_item_for_response($taxonomy, $request), 201); } else { return new WP_REST_Response([ 'error_message' => __('One or more values are invalid.', 'tainacan'), 'errors' => $this->taxonomy->get_errors(), - 'item_metadata' => $this->taxonomy->__toArray(), + 'item_metadata' => $this->prepare_item_for_response($this->taxonomy, $request), ], 400); } } else { @@ -292,13 +289,13 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller { if($prepared_taxonomy->validate()){ $updated_taxonomy = $this->taxonomy_repository->update($prepared_taxonomy); - return new WP_REST_Response($updated_taxonomy->__toArray(), 200); + return new WP_REST_Response($this->prepare_item_for_response($updated_taxonomy, $request), 200); } return new WP_REST_Response([ 'error_message' => __('One or more values are invalid.', 'tainacan'), 'errors' => $prepared_taxonomy->get_errors(), - 'taxonomy' => $prepared_taxonomy->__toArray() + 'taxonomy' => $this->prepare_item_for_response($prepared_taxonomy, $request) ], 400); } diff --git a/src/api/endpoints/class-tainacan-rest-terms-controller.php b/src/api/endpoints/class-tainacan-rest-terms-controller.php index b00a94182..6d99f8cb7 100644 --- a/src/api/endpoints/class-tainacan-rest-terms-controller.php +++ b/src/api/endpoints/class-tainacan-rest-terms-controller.php @@ -109,7 +109,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller { $term_inserted = $this->terms_repository->fetch($term_id, $taxonomy); - return new WP_REST_Response($term_inserted->__toArray(), 200); + return new WP_REST_Response($this->prepare_item_for_response($term_inserted, $request), 200); } else { return new WP_REST_Response([ 'error_message' => 'One or more attributes are invalid.', @@ -207,13 +207,13 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller { if($prepared_term->validate()){ $updated_term = $this->terms_repository->update($prepared_term, $tax_name); - return new WP_REST_Response($updated_term->__toArray(), 200); + return new WP_REST_Response($this->prepare_item_for_response($updated_term, $request), 200); } return new WP_REST_Response([ 'error_message' => __('One or more values are invalid.', 'tainacan'), 'errors' => $prepared_term->get_errors(), - 'term' => $prepared_term->__toArray() + 'term' => $this->prepare_item_for_response($prepared_term, $request) ], 400); } @@ -252,15 +252,8 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller { * @return array|mixed|WP_Error|WP_REST_Response */ public function prepare_item_for_response( $item, $request ) { - - if(is_array($item)){ - $prepared = []; - - foreach ($item as $term){ - $prepared[] = $term->__toArray(); - } - - return $prepared; + if(!empty($item)){ + return $item->__toArray(); } return $item; @@ -280,9 +273,12 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller { $terms = $this->terms_repository->fetch($args, $taxonomy); - $prepared_terms = $this->prepare_item_for_response($terms, $request); + $response = []; + foreach ($terms as $term) { + array_push($response, $this->prepare_item_for_response( $term, $request )); + } - return new WP_REST_Response($prepared_terms, 200); + return new WP_REST_Response($response, 200); } /** @@ -313,7 +309,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller { $term = $this->terms_repository->fetch($term_id, $taxonomy); - return new WP_REST_Response($term->__toArray(), 200); + return new WP_REST_Response($this->prepare_item_for_response($term, $request), 200); } /** diff --git a/src/classes/entities/class-tainacan-filter.php b/src/classes/entities/class-tainacan-filter.php index 873f0b533..6f9a3a028 100644 --- a/src/classes/entities/class-tainacan-filter.php +++ b/src/classes/entities/class-tainacan-filter.php @@ -32,6 +32,13 @@ class Filter extends Entity { return $this->get_mapped_property('name'); } + /** + * @return mixed|null + */ + function get_description(){ + return $this->get_mapped_property('description'); + } + /** * Return the filter order type * @@ -50,11 +57,12 @@ class Filter extends Entity { return $this->get_mapped_property('color'); } - /** - * Return the field - * - * @return Field - */ + /** + * Return the field + * + * @return Field + * @throws \Exception + */ function get_field() { $id = $this->get_mapped_property('field'); return new Field( $id ); From 343733ad27c93709d2ecdb8a8997d54eb2a2f5cf Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 16 Feb 2018 14:35:15 -0200 Subject: [PATCH 10/68] Adds pagination to item list. o/ --- src/admin/components/items-list.vue | 55 +++++++++++++++++----- src/admin/pages/collection-page.vue | 37 ++------------- src/js/store/modules/collection/actions.js | 7 ++- 3 files changed, 48 insertions(+), 51 deletions(-) diff --git a/src/admin/components/items-list.vue b/src/admin/components/items-list.vue index 4c5242020..fb1e77c29 100644 --- a/src/admin/components/items-list.vue +++ b/src/admin/components/items-list.vue @@ -1,14 +1,26 @@