Merge branch 'develop' of https://github.com/tainacan/tainacan into develop
This commit is contained in:
commit
b24c08c471
|
@ -25,6 +25,7 @@ import Checkbox from '../../classes/field-types/checkbox/Checkbox.vue';
|
|||
import Radio from '../../classes/field-types/radio/Radio.vue';
|
||||
import Numeric from '../../classes/field-types/numeric/Numeric.vue';
|
||||
import Date from '../../classes/field-types/date/Date.vue';
|
||||
import Relationship from '../../classes/field-types/relationship/Relationship.vue';
|
||||
|
||||
import TaincanFormItem from '../../classes/field-types/tainacan-form-item.vue';
|
||||
|
||||
|
@ -36,6 +37,7 @@ Vue.component('tainacan-checkbox', Checkbox);
|
|||
Vue.component('tainacan-radio', Radio);
|
||||
Vue.component('tainacan-numeric', Numeric);
|
||||
Vue.component('tainacan-date', Date);
|
||||
Vue.component('tainacan-relationship', Relationship);
|
||||
|
||||
Vue.component('tainacan-form-item', TaincanFormItem);
|
||||
|
||||
|
|
|
@ -13,11 +13,20 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
|
|||
$entity_prepared = [
|
||||
'id' => $entity->get_id(),
|
||||
'description' => $entity->get_description(),
|
||||
'author_id' => $entity->get_author_id(),
|
||||
'creation_date' => $entity->get_creation_date(),
|
||||
'modification_date' => $entity->get_modification_date(),
|
||||
];
|
||||
|
||||
if(array_key_exists('modification_date', $map)){
|
||||
$entity_prepared['modification_date'] = $entity->get_modification_date();
|
||||
}
|
||||
|
||||
if(array_key_exists('creation_date', $map)){
|
||||
$entity_prepared['creation_date'] = $entity->get_creation_date();
|
||||
}
|
||||
|
||||
if(array_key_exists('author_id', $map)){
|
||||
$entity_prepared['author_id'] = $entity->get_author_id();
|
||||
}
|
||||
|
||||
if(array_key_exists('name', $map)){
|
||||
$entity_prepared['name'] = $entity->get_name();
|
||||
} elseif(array_key_exists('title', $map)){
|
||||
|
@ -35,6 +44,24 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
|
|||
return $entity_prepared;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filters
|
||||
* @param $map
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function unmap_filters($filters, $map){
|
||||
$unmapped = [];
|
||||
|
||||
if(!empty($filters)) {
|
||||
foreach ( $filters as $filter => $value ) {
|
||||
$unmapped[ $map[ $filter ]['map'] ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $unmapped;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -41,20 +41,20 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_item_schema()
|
||||
//'args' => $this->get_item_schema()
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
'permission_callback' => array($this, 'create_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
|
||||
//'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
|
||||
),
|
||||
));
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<collection_id>[\d]+)', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item'),
|
||||
'args' => $this->get_collection_params(),
|
||||
//'args' => $this->get_collection_params(),
|
||||
'permission_callback' => array($this, 'get_item_permissions_check'),
|
||||
),
|
||||
array(
|
||||
|
@ -78,7 +78,19 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
|||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_items($request){
|
||||
$collections = $this->collections_repository->fetch();
|
||||
$args = [];
|
||||
|
||||
$map = $this->collections_repository->get_map();
|
||||
|
||||
foreach ($map as $key => $value){
|
||||
if(isset($request[$key])){
|
||||
$args[$value['map']] = $request[$key];
|
||||
}
|
||||
}
|
||||
|
||||
//$args = $this->unmap_filters($args, $map);
|
||||
|
||||
$collections = $this->collections_repository->fetch($args);
|
||||
|
||||
$response = $this->prepare_item_for_response($collections, $request);
|
||||
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
use Tainacan\Entities;
|
||||
use Tainacan\Repositories;
|
||||
|
||||
class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
|
||||
class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
|
||||
private $field;
|
||||
private $item_metadata_repository;
|
||||
private $item_repository;
|
||||
private $collection_repository;
|
||||
private $field_repository;
|
||||
|
||||
public function __construct() {
|
||||
$this->namespace = 'tainacan/v2';
|
||||
|
@ -22,7 +23,7 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
*/
|
||||
public function init_objects() {
|
||||
$this->field = new Entities\Field();
|
||||
$this->metadata_repository = new Repositories\Fields();
|
||||
$this->field_repository = new Repositories\Fields();
|
||||
$this->item_metadata_repository = new Repositories\Item_Metadata();
|
||||
$this->item_repository = new Repositories\Items();
|
||||
$this->collection_repository = new Repositories\Collections();
|
||||
|
@ -58,7 +59,7 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params(),
|
||||
//'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
|
@ -103,7 +104,7 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
if($this->field->validate()) {
|
||||
$this->metadata_repository->insert( $this->field );
|
||||
$this->field_repository->insert( $this->field );
|
||||
|
||||
$items = $this->item_repository->fetch([], $collection_id, 'WP_Query');
|
||||
|
||||
|
@ -173,9 +174,21 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
public function get_items( $request ) {
|
||||
$collection_id = $request['collection_id'];
|
||||
|
||||
$args = [];
|
||||
|
||||
$map = $this->field_repository->get_map();
|
||||
|
||||
foreach ($map as $key => $value){
|
||||
if(isset($request[$key], $map[$key])){
|
||||
$args[$value['map']] = $request[$key];
|
||||
}
|
||||
}
|
||||
|
||||
//$args = $this->unmap_filters($args, $map);
|
||||
|
||||
$collection = new Entities\Collection($collection_id);
|
||||
|
||||
$collection_metadata = $this->metadata_repository->fetch_by_collection($collection, [], 'OBJECT');
|
||||
$collection_metadata = $this->field_repository->fetch_by_collection($collection, $args, 'OBJECT');
|
||||
|
||||
$prepared_item = $this->prepare_item_for_response($collection_metadata, $request);
|
||||
|
||||
|
@ -259,9 +272,9 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
$attributes[$att] = $value;
|
||||
}
|
||||
|
||||
$field = $this->metadata_repository->fetch($field_id);
|
||||
$field = $this->field_repository->fetch($field_id);
|
||||
|
||||
$updated_metadata = $this->metadata_repository->update($field, $attributes);
|
||||
$updated_metadata = $this->field_repository->update($field, $attributes);
|
||||
|
||||
if(!($updated_metadata instanceof Entities\Field)){
|
||||
return new WP_REST_Response($updated_metadata, 400);
|
|
@ -207,13 +207,19 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
$body = json_decode($request->get_body(), true);
|
||||
|
||||
if(!empty($body)){
|
||||
$attributes = ['ID' => $filter_id];
|
||||
$attributes = [];
|
||||
|
||||
foreach ($body as $att => $value){
|
||||
$attributes[$att] = $value;
|
||||
}
|
||||
|
||||
$updated_filter = $this->filter_repository->update($attributes);
|
||||
$filter = $this->filter_repository->fetch($filter_id);
|
||||
|
||||
$updated_filter = $this->filter_repository->update($filter, $attributes);
|
||||
|
||||
if(!($updated_filter instanceof Entities\Filter)){
|
||||
return new WP_REST_Response($updated_filter, 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response($updated_filter->__toArray(), 200);
|
||||
}
|
||||
|
@ -267,7 +273,19 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
|
|||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$filters = $this->filter_repository->fetch([], 'OBJECT');
|
||||
$args = [];
|
||||
|
||||
$map = $this->filter_repository->get_map();
|
||||
|
||||
foreach ($map as $key => $value){
|
||||
if(isset($request[$key], $map[$key])){
|
||||
$args[$value['map']] = $request[$key];
|
||||
}
|
||||
}
|
||||
|
||||
//$args = $this->unmap_filters($args, $map);
|
||||
|
||||
$filters = $this->filter_repository->fetch($args, 'OBJECT');
|
||||
|
||||
$response = $this->prepare_item_for_response($filters, $request);
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
private $item_metadata_repository;
|
||||
private $item_repository;
|
||||
private $collection_repository;
|
||||
private $field_repository;
|
||||
|
||||
public function __construct() {
|
||||
$this->namespace = 'tainacan/v2';
|
||||
|
@ -53,7 +54,7 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params(),
|
||||
//'args' => $this->get_collection_params(),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
|
@ -47,15 +47,15 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => $this->get_collection_params(),
|
||||
//'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
'permission_callback' => array($this, 'create_item_permissions_check'),
|
||||
'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
|
||||
//'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
|
||||
),
|
||||
'schema' => array($this, 'get_public_item_schema'),
|
||||
//'schema' => array($this, 'get_public_item_schema'),
|
||||
));
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/(?P<item_id>[\d]+)',
|
||||
|
@ -105,7 +105,7 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
return $items;
|
||||
} elseif(!empty($item)){
|
||||
return $this->get_only_needed_attributes($item, $map);
|
||||
return $item->__toArray();
|
||||
}
|
||||
|
||||
return $item;
|
||||
|
@ -132,8 +132,20 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$args = [];
|
||||
|
||||
$map = $this->items_repository->get_map();
|
||||
|
||||
foreach ($map as $key => $value){
|
||||
if(isset($request[$key], $map[$key])){
|
||||
$args[$value['map']] = $request[$key];
|
||||
}
|
||||
}
|
||||
|
||||
//$args = $this->unmap_filters($args, $map);
|
||||
|
||||
$collection_id = $request['collection_id'];
|
||||
$items = $this->items_repository->fetch([], $collection_id, 'WP_Query');
|
||||
$items = $this->items_repository->fetch($args, $collection_id, 'WP_Query');
|
||||
|
||||
$response = $this->prepare_item_for_response($items, $request);
|
||||
|
||||
|
@ -169,6 +181,7 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return object|Entities\Item|WP_Error
|
||||
* @throws Exception
|
||||
*/
|
||||
public function prepare_item_for_database( $request ) {
|
||||
|
||||
|
@ -206,6 +219,7 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create_item( $request ) {
|
||||
$collection_id = $request['collection_id'];
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
|
||||
use Tainacan\Entities;
|
||||
use Tainacan\Repositories;
|
||||
|
||||
class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
||||
private $logs_repository;
|
||||
private $log;
|
||||
|
||||
/**
|
||||
* TAINACAN_REST_Logs_Controller constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->namespace = 'tainacan/v2';
|
||||
$this->rest_base = 'logs';
|
||||
|
||||
add_action('rest_api_init', array($this, 'register_routes'));
|
||||
add_action('init', array($this, 'init_objects'));
|
||||
}
|
||||
|
||||
public function init_objects(){
|
||||
$this->logs_repository = new Repositories\Logs();
|
||||
$this->log = new Entities\Log();
|
||||
}
|
||||
|
||||
public function register_routes() {
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
)
|
||||
)
|
||||
);
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<log_id>[\d]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item'),
|
||||
'permission_callback' => array($this, 'get_item_permissions_check'),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $item
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
return $item->__toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$args = [];
|
||||
|
||||
$map = $this->logs_repository->get_map();
|
||||
|
||||
foreach ($map as $key => $value){
|
||||
if(isset($request[$key], $map[$key])){
|
||||
$args[$value['map']] = $request[$key];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$logs = $this->logs_repository->fetch($args, 'OBJECT');
|
||||
|
||||
if(!empty($logs)) {
|
||||
$prepared_logs = $this->prepare_item_for_response( $logs, $request );
|
||||
|
||||
return new WP_REST_Response($prepared_logs, 200);
|
||||
}
|
||||
|
||||
return new WP_REST_Response($logs, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
return $this->logs_repository->can_read($this->log);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
$log_id = $request['log_id'];
|
||||
|
||||
$log = $this->logs_repository->fetch($log_id);
|
||||
|
||||
if(!empty($log)) {
|
||||
$prepared_log = $this->prepare_item_for_response( $log, $request );
|
||||
|
||||
return new WP_REST_Response($prepared_log, 200);
|
||||
}
|
||||
|
||||
return new WP_REST_Response($log, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
public function get_item_permissions_check( $request ) {
|
||||
$log = $this->logs_repository->fetch($request['log_id']);
|
||||
|
||||
if($log instanceof Entities\Log){
|
||||
return $log->can_read();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -62,6 +62,16 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
)
|
||||
)
|
||||
);
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/(?P<taxonomy_id>[\d]+)/collection/(?P<collection_id>[\d]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'update_item'),
|
||||
'permission_callback' => array($this, 'update_item_permissions_check')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,7 +204,19 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$taxonomies = $this->taxonomy_repository->fetch([], 'OBJECT');
|
||||
$args = [];
|
||||
|
||||
$map = $this->taxonomy_repository->get_map();
|
||||
|
||||
foreach ($map as $key => $value){
|
||||
if(isset($request[$key], $map[$key])){
|
||||
$args[$value['map']] = $request[$key];
|
||||
}
|
||||
}
|
||||
|
||||
//$args = $this->unmap_filters($args, $map);
|
||||
|
||||
$taxonomies = $this->taxonomy_repository->fetch($args, 'OBJECT');
|
||||
|
||||
$taxonomies_prepared = $this->prepare_item_for_response($taxonomies, $request);
|
||||
|
||||
|
@ -259,14 +281,26 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$body = json_decode($request->get_body(), true);
|
||||
|
||||
if(!empty($body)){
|
||||
$attributes = ['ID' => $taxonomy_id];
|
||||
if(!empty($body) || isset($request['collection_id'])){
|
||||
$attributes = [];
|
||||
|
||||
foreach ($body as $att => $value){
|
||||
$attributes[$att] = $value;
|
||||
if(isset($request['collection_id'])) {
|
||||
$collection_id = $request['collection_id'];
|
||||
|
||||
$attributes = [ 'collection' => $collection_id ];
|
||||
} else {
|
||||
foreach ( $body as $att => $value ) {
|
||||
$attributes[ $att ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$updated_taxonomy = $this->taxonomy_repository->update($attributes);
|
||||
$taxonomy = $this->taxonomy_repository->fetch($taxonomy_id);
|
||||
|
||||
$updated_taxonomy = $this->taxonomy_repository->update($taxonomy, $attributes);
|
||||
|
||||
if(!($updated_taxonomy instanceof Entities\Taxonomy)){
|
||||
return new WP_REST_Response($updated_taxonomy, 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response($updated_taxonomy->__toArray(), 200);
|
||||
}
|
||||
|
|
|
@ -190,12 +190,8 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
$body = json_decode($request->get_body(), true);
|
||||
|
||||
if(!empty($body)){
|
||||
$taxonomy_name = $this->taxonomy_repository->fetch($taxonomy_id)->get_db_identifier();
|
||||
|
||||
$identifiers = [
|
||||
'term_id' => $term_id,
|
||||
'tax_name' => $taxonomy_name
|
||||
];
|
||||
$taxonomy = $this->taxonomy_repository->fetch($taxonomy_id);
|
||||
$tax_name = $taxonomy->get_db_identifier();
|
||||
|
||||
$attributes = [];
|
||||
|
||||
|
@ -203,7 +199,13 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
$attributes[$att] = $value;
|
||||
}
|
||||
|
||||
$updated_term = $this->terms_repository->update([$attributes, $identifiers]);
|
||||
$term = $this->terms_repository->fetch($term_id, $taxonomy);
|
||||
|
||||
$updated_term = $this->terms_repository->update([$term, $tax_name], $attributes);
|
||||
|
||||
if(!($updated_term instanceof Entities\Term)){
|
||||
return new WP_REST_Response($updated_term, 400);
|
||||
}
|
||||
|
||||
return new WP_REST_Response($updated_term->__toArray(), 200);
|
||||
}
|
||||
|
@ -260,7 +262,17 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$taxonomy = $this->taxonomy_repository->fetch($taxonomy_id);
|
||||
|
||||
$args = json_decode($request->get_body(), true);
|
||||
$args = [];
|
||||
|
||||
$map = $this->terms_repository->get_map();
|
||||
|
||||
foreach ($map as $key => $value){
|
||||
if(isset($request[$key], $map[$key])){
|
||||
$args[$value['map']] = $request[$key];
|
||||
}
|
||||
}
|
||||
|
||||
//$args = $this->unmap_filters($args, $map);
|
||||
|
||||
$terms = $this->terms_repository->fetch($args, $taxonomy);
|
||||
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
$rest_controller = new TAINACAN_REST_Controller();
|
||||
$rest_collections_controller = new TAINACAN_REST_Collections_Controller();
|
||||
$rest_items_controller = new TAINACAN_REST_Items_Controller();
|
||||
$rest_metadata_controller = new TAINACAN_REST_Metadata_Controller();
|
||||
$rest_fields_controller = new TAINACAN_REST_Fields_Controller();
|
||||
$rest_taxonomies_controller = new TAINACAN_REST_Taxonomies_Controller();
|
||||
$rest_terms_controller = new TAINACAN_REST_Terms_Controller();
|
||||
$rest_filters_controller = new TAINACAN_REST_Filters_Controller();
|
||||
$rest_item_metadata_controller = new TAINACAN_REST_Item_Metadata_Controller();
|
||||
$rest_logs_controller = new TAINACAN_REST_Logs_Controller();
|
||||
// Add here other endpoints imports
|
||||
|
||||
?>
|
|
@ -1,83 +1,47 @@
|
|||
<template>
|
||||
<div class="component">
|
||||
<label
|
||||
v-for="option in getOptions"
|
||||
:for="option.replace(' ','-') + '-checkbox'">
|
||||
<input
|
||||
type="checkbox"
|
||||
:id="option.replace(' ','-') + '-checkbox'"
|
||||
:value="option"
|
||||
:checked="isChecked(option)"
|
||||
@change="sendValue($event)"> {{ option }} <br>
|
||||
</label>
|
||||
<div>
|
||||
<el-checkbox-group v-model="checked">
|
||||
<el-checkbox
|
||||
v-for="option,index in getOptions"
|
||||
:key="index"
|
||||
v-model="checked"
|
||||
@change="onChecked(option)"
|
||||
:label="option"
|
||||
border>{{ option }}</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import store from '../../../js/store/store';
|
||||
|
||||
export default {
|
||||
store,
|
||||
data(){
|
||||
return {
|
||||
checked:[]
|
||||
}
|
||||
},
|
||||
props: {
|
||||
name: {
|
||||
type: String
|
||||
},
|
||||
options: {
|
||||
type: String
|
||||
},
|
||||
item_id: {
|
||||
type: Number
|
||||
},
|
||||
field_id: {
|
||||
type: Number
|
||||
},
|
||||
value: {
|
||||
type: [ String,Number ]
|
||||
},
|
||||
},
|
||||
created(){
|
||||
this.setInitValueOnStore();
|
||||
field: {
|
||||
type: Object
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
getOptions(){
|
||||
const values = ( this.options ) ? this.options.split("\n") : '';
|
||||
return values;
|
||||
if (this.field) {
|
||||
const fields = this.field.field.field_type_options.options;
|
||||
return ( fields ) ? fields.split("\n") : [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
setInitValueOnStore (){
|
||||
const array_values = JSON.parse( this.value );
|
||||
if ( array_values.length > 0 ){
|
||||
this.checked = array_values;
|
||||
this.$store.dispatch('item/setSingleMetadata', { item_id: this.item_id, field_id: this.field_id, values: array_values });
|
||||
}
|
||||
onChecked(option) {
|
||||
this.$emit('blur');
|
||||
this.onInput(this.checked)
|
||||
},
|
||||
sendValue ( event ){
|
||||
let index = this.checked.indexOf( event.target.value );
|
||||
if( index >= 0 ){
|
||||
this.checked.splice(index,1);
|
||||
}else{
|
||||
this.checked.push( event.target.value );
|
||||
}
|
||||
this.$store.dispatch('item/sendMetadata', { item_id: this.item_id, field_id: this.field_id, values: this.checked });
|
||||
},
|
||||
isChecked ( value ){
|
||||
let index = this.checked.indexOf( value );
|
||||
return index >= 0;
|
||||
onInput($event) {
|
||||
this.inputValue = $event;
|
||||
this.$emit('input', this.inputValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped="">
|
||||
#postcustomstuff table input, #postcustomstuff table select, #postcustomstuff table textarea {
|
||||
width: auto;
|
||||
margin: 8px;
|
||||
}
|
||||
</style>
|
|
@ -1,15 +1,11 @@
|
|||
<template>
|
||||
<div class="block">
|
||||
<el-date-picker
|
||||
v-model="valueDate"
|
||||
@blur="changeValue()"
|
||||
type="date"
|
||||
format="dd/MM/yyyy"
|
||||
value-format="dd/MM/yyyy"
|
||||
placeholder="Selecione a data...">
|
||||
</el-date-picker>
|
||||
<div class="demonstration">{{ valueDate }}</div>
|
||||
</div>
|
||||
<el-date-picker
|
||||
type="date"
|
||||
format="dd/MM/yyyy"
|
||||
value-format="dd/MM/yyyy"
|
||||
:value="dateValue"
|
||||
@blur="onBlur"
|
||||
@input="onInput($event)"></el-date-picker>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
@ -19,40 +15,18 @@
|
|||
locale.use(lang)
|
||||
|
||||
export default {
|
||||
props: {
|
||||
name: { type: String },
|
||||
item_id: { type: Number },
|
||||
field_id: { type: Number },
|
||||
value: { type: [ String,Number ] },
|
||||
errorsMsg: { type: [ String,Number ] },
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
valueDate:''
|
||||
}
|
||||
},
|
||||
created(){
|
||||
this.getValue();
|
||||
data() {
|
||||
return {
|
||||
dateValue: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
changeValue(){
|
||||
this.$emit('input', { item_id: this.item_id, field_id: this.field_id, values: event.target.value } );
|
||||
onBlur() {
|
||||
this.$emit('blur');
|
||||
},
|
||||
getValue(){
|
||||
try{
|
||||
let val = JSON.parse( this.value );
|
||||
this.valueDate = val;
|
||||
}catch(e){
|
||||
console.log('invalid json value');
|
||||
}
|
||||
},
|
||||
getErrors(){
|
||||
try{
|
||||
return JSON.parse( this.errorsMsg );
|
||||
}catch(e){
|
||||
console.log('invalid json error');
|
||||
}
|
||||
return this.errorsMsg;
|
||||
onInput($event) {
|
||||
this.dateValue = $event;
|
||||
this.$emit('input', this.dateValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,59 +1,27 @@
|
|||
<template>
|
||||
<div class="component">
|
||||
<p>{{ name }}</p>
|
||||
<input type="text" @blur="changeValue($event)" :value="getValue()">
|
||||
<p v-for="error in getErrors()">
|
||||
{{ error }}
|
||||
</p>
|
||||
</div>
|
||||
<el-input-number
|
||||
controls-position="right"
|
||||
:value="inputValue"
|
||||
@blur="onBlur"
|
||||
@change="onBlur"
|
||||
@input="onInput($event)"></el-input-number>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
name: { type: String },
|
||||
item_id: { type: Number },
|
||||
field_id: { type: Number },
|
||||
value: { type: [ String,Number ] },
|
||||
errorsMsg: { type: [ String,Number ] },
|
||||
data() {
|
||||
return {
|
||||
inputValue: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
changeValue( event ){
|
||||
this.$emit('changeValue', { item_id: this.item_id, field_id: this.field_id, values: event.target.value } );
|
||||
onBlur() {
|
||||
this.$emit('blur');
|
||||
},
|
||||
getValue(){
|
||||
try{
|
||||
return JSON.parse( this.value );
|
||||
}catch(e){
|
||||
console.log('invalid json value');
|
||||
}
|
||||
return this.value;
|
||||
},
|
||||
getErrors(){
|
||||
try{
|
||||
return JSON.parse( this.errorsMsg );
|
||||
}catch(e){
|
||||
console.log('invalid json error msg');
|
||||
}
|
||||
return this.errorsMsg;
|
||||
onInput($event) {
|
||||
this.inputValue = $event;
|
||||
this.$emit('input', this.inputValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
input[type="text"] {
|
||||
display: block;
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
border-radius: 6px;
|
||||
font-family: sans-serif;
|
||||
font-size: 18px;
|
||||
appearance: none;
|
||||
box-shadow: none;
|
||||
color:green;
|
||||
}
|
||||
input[type="text"]:focus {
|
||||
outline: none;
|
||||
}
|
||||
</style>
|
|
@ -1,14 +1,12 @@
|
|||
<template>
|
||||
<div class="component">
|
||||
<label
|
||||
v-for="option in getOptions"
|
||||
:for="option.replace(' ','-') + '-checkbox'">
|
||||
<input
|
||||
type="radio"
|
||||
:id="option.replace(' ','-') + '-checkbox'"
|
||||
:value="option"
|
||||
v-model="checked"> {{ option }}<br>
|
||||
</label>
|
||||
<div>
|
||||
<el-radio
|
||||
v-for="option,index in getOptions"
|
||||
:key="index"
|
||||
v-model="checked"
|
||||
@change="onChecked(option)"
|
||||
:label="option"
|
||||
border>{{ option }}</el-radio>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -20,25 +18,28 @@
|
|||
}
|
||||
},
|
||||
props: {
|
||||
name: {
|
||||
type: String
|
||||
},
|
||||
options: {
|
||||
type: String
|
||||
field: {
|
||||
type: Object
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
getOptions(){
|
||||
const values = ( this.options ) ? this.options.split("\n") : '';
|
||||
return values;
|
||||
if (this.field) {
|
||||
const fields = this.field.field.field_type_options.options;
|
||||
return ( fields ) ? fields.split("\n") : [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onChecked(option) {
|
||||
this.$emit('blur');
|
||||
this.onInput(this.checked)
|
||||
},
|
||||
onInput($event) {
|
||||
this.inputValue = $event;
|
||||
this.$emit('input', this.inputValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped="">
|
||||
#postcustomstuff table input, #postcustomstuff table select, #postcustomstuff table textarea {
|
||||
width: auto;
|
||||
margin: 8px;
|
||||
}
|
||||
</style>
|
|
@ -22,7 +22,11 @@ class Radio extends Field_Type {
|
|||
|
||||
public function render( $itemMetadata ){
|
||||
$options = ( isset( $this->options['options'] ) ) ? $this->options['options'] : '';
|
||||
return '<tainacan-radio options="'.$options.'" name="'.$itemMetadata->get_field()->get_name().'"></tainacan-radio>';
|
||||
return '<tainacan-radio
|
||||
field_id ="'.$itemMetadata->get_field()->get_id().'"
|
||||
item_id="'.$itemMetadata->get_item()->get_id().'"
|
||||
value=\''.json_encode( $itemMetadata->get_value() ).'\'
|
||||
options="'.$options.'" name="'.$itemMetadata->get_field()->get_name().'"></tainacan-radio>';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,77 +1,76 @@
|
|||
<template>
|
||||
<div class="component">
|
||||
<p>{{ name }}</p>
|
||||
<select
|
||||
class="form-control"
|
||||
:disabled="!getOptions"
|
||||
v-model="manageValue">
|
||||
<option
|
||||
v-for="option in getOptions"
|
||||
:selected="option == ''">
|
||||
{{ option }}
|
||||
</option>
|
||||
</select>
|
||||
<div>
|
||||
<el-select
|
||||
v-model="selected"
|
||||
multiple
|
||||
filterable
|
||||
remote
|
||||
reserve-keyword
|
||||
:remote-method="search"
|
||||
:loading="loading"
|
||||
@change="onChecked()">
|
||||
<el-option
|
||||
v-for="option,index in options"
|
||||
:key="option.value"
|
||||
:label="option.label"
|
||||
:value="option.value"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import store from '../../../js/store/store';
|
||||
import axios from '../../../js/axios/axios'
|
||||
|
||||
export default {
|
||||
store,
|
||||
data(){
|
||||
return {
|
||||
selected:''
|
||||
selected:[],
|
||||
options: [],
|
||||
loading: false,
|
||||
collectionId: 0,
|
||||
inputValue: null
|
||||
}
|
||||
},
|
||||
props: {
|
||||
name: {
|
||||
type: String
|
||||
},
|
||||
options: {
|
||||
type: String
|
||||
},
|
||||
item_id: {
|
||||
type: Number
|
||||
},
|
||||
field_id: {
|
||||
type: Number
|
||||
},
|
||||
value: {
|
||||
type: [ String,Number ]
|
||||
},
|
||||
},
|
||||
created(){
|
||||
this.setInitValueOnStore();
|
||||
},
|
||||
computed: {
|
||||
getOptions(){
|
||||
const values = ( this.options ) ? this.options.split("\n") : false;
|
||||
return values;
|
||||
},
|
||||
manageValue : {
|
||||
get(){
|
||||
let field = this.$store.getters['item/getMetadata'].find(field => field.field_id === this.field_id );
|
||||
if( field ){
|
||||
return field.values;
|
||||
}else if( this.value ){
|
||||
return JSON.parse( this.value );
|
||||
}
|
||||
},
|
||||
set( value ){
|
||||
this.$store.dispatch('item/sendMetadata', { item_id: this.item_id, field_id: this.field_id, values: value });
|
||||
}
|
||||
field: {
|
||||
type: Object
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
setInitValueOnStore(){
|
||||
if ( this.value ){
|
||||
this.$store.dispatch('item/setSingleMetadata', { item_id: this.item_id, field_id: this.field_id, values: JSON.parse( this.value ) });
|
||||
onChecked() {
|
||||
this.$emit('blur');
|
||||
this.onInput(this.selected)
|
||||
},
|
||||
onInput($event) {
|
||||
this.inputValue = $event;
|
||||
this.$emit('input', this.inputValue);
|
||||
},
|
||||
search(query) {
|
||||
if (query !== '') {
|
||||
this.loading = true;
|
||||
this.options = [];
|
||||
let collectionId = this.field.field.field_type_options.collection_id;
|
||||
axios.get('/collection/'+collectionId+'/items')
|
||||
.then( res => {
|
||||
let result = [];
|
||||
this.loading = false;
|
||||
result = res.data.filter(item => {
|
||||
return item.title.toLowerCase()
|
||||
.indexOf(query.toLowerCase()) > -1;
|
||||
});
|
||||
|
||||
for (let item of result) {
|
||||
this.options.push({ label: item.title, value: item.id })
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
} else {
|
||||
this.options = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
</style>
|
|
@ -23,7 +23,11 @@ class Relationship extends Field_Type {
|
|||
*/
|
||||
|
||||
public function render( $itemMetadata ){
|
||||
return '<tainacan-relationship name="'.$itemMetadata->get_field()->get_name().'"></tainacan-relationship>';
|
||||
return '<tainacan-relationship
|
||||
field_id ="'.$itemMetadata->get_field()->get_id().'"
|
||||
item_id="'.$itemMetadata->get_item()->get_id().'"
|
||||
value=\''.json_encode( $itemMetadata->get_value() ).'\'
|
||||
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-relationship>';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,77 +1,46 @@
|
|||
<template>
|
||||
<div class="component">
|
||||
<p>{{ name }}</p>
|
||||
<select
|
||||
class="form-control"
|
||||
:disabled="!getOptions"
|
||||
v-model="manageValue">
|
||||
<option
|
||||
v-for="option in getOptions"
|
||||
:selected="option == ''">
|
||||
{{ option }}
|
||||
</option>
|
||||
</select>
|
||||
<div>
|
||||
<el-select v-model="selected" @change="onChecked()">
|
||||
<el-option
|
||||
v-for="option,index in getOptions"
|
||||
:key="index"
|
||||
:label="option"
|
||||
:value="option"
|
||||
border>{{ option }}</el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import store from '../../../js/store/store';
|
||||
|
||||
export default {
|
||||
store,
|
||||
data(){
|
||||
return {
|
||||
selected:''
|
||||
}
|
||||
},
|
||||
props: {
|
||||
name: {
|
||||
type: String
|
||||
},
|
||||
options: {
|
||||
type: String
|
||||
},
|
||||
item_id: {
|
||||
type: Number
|
||||
},
|
||||
field_id: {
|
||||
type: Number
|
||||
},
|
||||
value: {
|
||||
type: [ String,Number ]
|
||||
},
|
||||
},
|
||||
created(){
|
||||
this.setInitValueOnStore();
|
||||
field: {
|
||||
type: Object
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
getOptions(){
|
||||
const values = ( this.options ) ? this.options.split("\n") : false;
|
||||
return values;
|
||||
},
|
||||
manageValue : {
|
||||
get(){
|
||||
let field = this.$store.getters['item/getMetadata'].find(field => field.field_id === this.field_id );
|
||||
if( field ){
|
||||
return field.values;
|
||||
}else if( this.value ){
|
||||
return JSON.parse( this.value );
|
||||
}
|
||||
},
|
||||
set( value ){
|
||||
this.$store.dispatch('item/sendMetadata', { item_id: this.item_id, field_id: this.field_id, values: value });
|
||||
if (this.field && this.field.field.field_type_options.options) {
|
||||
const fields = this.field.field.field_type_options.options;
|
||||
return ( fields ) ? fields.split("\n") : [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
setInitValueOnStore(){
|
||||
if ( this.value ){
|
||||
this.$store.dispatch('item/updateMetadata', { item_id: this.item_id, field_id: this.field_id, values: JSON.parse( this.value ) });
|
||||
}
|
||||
onChecked(option) {
|
||||
this.$emit('blur');
|
||||
this.onInput(this.selected)
|
||||
},
|
||||
onInput($event) {
|
||||
this.$emit('input', $event);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
</style>
|
|
@ -22,7 +22,7 @@ class Selectbox extends Field_Type {
|
|||
|
||||
public function render( $itemMetadata ){
|
||||
$options = ( isset( $this->options['options'] ) ) ? $this->options['options'] : '';
|
||||
return '<tainacan-selectbox options="'.$options.'"
|
||||
return '<tainacan-selectbox
|
||||
field_id ="'.$itemMetadata->get_field()->get_id().'"
|
||||
item_id="'.$itemMetadata->get_item()->get_id().'"
|
||||
value=\''.json_encode( $itemMetadata->get_value() ).'\'
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<template>
|
||||
<div>
|
||||
<el-form-item :label="field.field.name" :prop="validateObject()">
|
||||
<component :is="extractFieldType(field.field.field_type)" v-model="inputs[0]" @blur="changeValue()"></component>
|
||||
<component :is="extractFieldType(field.field.field_type)" v-model="inputs[0]" :field="field" @blur="changeValue()"></component>
|
||||
<div v-if="field.field.multiple == 'yes'">
|
||||
<div v-if="index > 0" v-for="(input, index) in inputsList " v-bind:key="index" class="multiple-inputs">
|
||||
<component :is="extractFieldType(field.field.field_type)" v-model="inputs[index]" @blur="changeValue()"></component><el-button v-if="index > 0" @click="removeInput(index)">-</el-button>
|
||||
<component :is="extractFieldType(field.field.field_type)" v-model="inputs[index]" :field="field" @blur="changeValue()"></component><el-button v-if="index > 0" @click="removeInput(index)">-</el-button>
|
||||
</div>
|
||||
<el-button @click="addInput">+</el-button>
|
||||
</div>
|
||||
|
|
|
@ -1,31 +1,26 @@
|
|||
<template>
|
||||
<div class="component">
|
||||
<p>{{ name }}</p>
|
||||
<textarea cols="30" rows="10"></textarea>
|
||||
</div>
|
||||
<el-input type="textarea"
|
||||
:autosize="{ minRows: 2, maxRows: 4}"
|
||||
:value="inputValue"
|
||||
@blur="onBlur"
|
||||
@input="onInput($event)"></el-input>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
name: { type: String }
|
||||
data() {
|
||||
return {
|
||||
inputValue: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onBlur() {
|
||||
this.$emit('blur');
|
||||
},
|
||||
onInput($event) {
|
||||
this.inputValue = $event;
|
||||
this.$emit('input', this.inputValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
textarea {
|
||||
display: block;
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
border-radius: 6px;
|
||||
font-family: sans-serif;
|
||||
font-size: 18px;
|
||||
appearance: none;
|
||||
box-shadow: none;
|
||||
color:green;
|
||||
}
|
||||
textarea:focus {
|
||||
outline: none;
|
||||
}
|
||||
</style>
|
|
@ -21,7 +21,11 @@ class Textarea extends Field_Type {
|
|||
*/
|
||||
|
||||
public function render( $itemMetadata ){
|
||||
return '<tainacan-textarea name="'.$itemMetadata->get_field()->get_name().'"></tainacan-textarea>';
|
||||
return '<tainacan-textarea
|
||||
field_id ="'.$itemMetadata->get_field()->get_id().'"
|
||||
item_id="'.$itemMetadata->get_item()->get_id().'"
|
||||
value=\''.json_encode( $itemMetadata->get_value() ).'\'
|
||||
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-textarea>';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -218,18 +218,20 @@ class Fields extends Repository {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* fetch field based on ID or WP_Query args
|
||||
*
|
||||
* field are stored as posts. Check WP_Query docs
|
||||
* to learn all args accepted in the $args parameter (@see https://developer.wordpress.org/reference/classes/wp_query/)
|
||||
* You can also use a mapped property, such as name and description, as an argument and it will be mapped to the
|
||||
* appropriate WP_Query argument
|
||||
*
|
||||
* @param array $args WP_Query args || int $args the field id
|
||||
* @param string $output The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
|
||||
* @return \WP_Query|Array an instance of wp query OR array of entities;
|
||||
*/
|
||||
/**
|
||||
* fetch field based on ID or WP_Query args
|
||||
*
|
||||
* field are stored as posts. Check WP_Query docs
|
||||
* to learn all args accepted in the $args parameter (@see https://developer.wordpress.org/reference/classes/wp_query/)
|
||||
* You can also use a mapped property, such as name and description, as an argument and it will be mapped to the
|
||||
* appropriate WP_Query argument
|
||||
*
|
||||
* @param array $args WP_Query args || int $args the field id
|
||||
* @param string $output The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
|
||||
*
|
||||
* @return \WP_Query|Array an instance of wp query OR array of entities;
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function fetch( $args, $output = null ) {
|
||||
|
||||
if( is_numeric($args) ){
|
||||
|
@ -253,14 +255,16 @@ class Fields extends Repository {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch field by collection, searches all field available
|
||||
*
|
||||
* @param Entities\Collection $collection
|
||||
* @param array $args
|
||||
* @param string $output The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
|
||||
* @return Array Entities\Field
|
||||
*/
|
||||
/**
|
||||
* fetch field by collection, searches all field available
|
||||
*
|
||||
* @param Entities\Collection $collection
|
||||
* @param array $args
|
||||
* @param string $output The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
|
||||
*
|
||||
* @return Array Entities\Field
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function fetch_by_collection(Entities\Collection $collection, $args = [], $output = null){
|
||||
$collection_id = $collection->get_id();
|
||||
|
||||
|
|
|
@ -169,19 +169,20 @@ class Filters extends Repository {
|
|||
}
|
||||
|
||||
public function update($object, $new_values = null){
|
||||
$map = $this->get_map();
|
||||
|
||||
$entity = [];
|
||||
|
||||
foreach ($object as $key => $value) {
|
||||
if($key != 'ID') {
|
||||
$entity[$map[$key]['map']] = $value ;
|
||||
} elseif ($key == 'ID'){
|
||||
$entity[$key] = (int) $value;
|
||||
foreach ($new_values as $key => $value) {
|
||||
try {
|
||||
$set_ = 'set_' . $key;
|
||||
$object->$set_( $value );
|
||||
} catch (\Error $error){
|
||||
return $error->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
return new Entities\Filter(wp_update_post($entity));
|
||||
if($object->validate()){
|
||||
return $this->insert($object);
|
||||
}
|
||||
|
||||
return $object->get_errors();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -78,7 +78,10 @@ abstract class Repository {
|
|||
}
|
||||
}
|
||||
$obj->WP_Post->post_type = $obj::get_post_type();
|
||||
//$obj->WP_Post->post_status = 'publish';
|
||||
|
||||
if($obj instanceof Entities\Log) {
|
||||
$obj->WP_Post->post_status = 'publish';
|
||||
}
|
||||
|
||||
// TODO verificar se salvou mesmo
|
||||
$id = wp_insert_post($obj->WP_Post);
|
||||
|
|
|
@ -107,10 +107,11 @@ class Taxonomies extends Repository {
|
|||
register_post_type(Entities\Taxonomy::get_post_type(), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Entities\Taxonomy $taxonomy
|
||||
* @return int
|
||||
*/
|
||||
/**
|
||||
* @param Entities\Taxonomy $taxonomy
|
||||
*
|
||||
* @return Entities\Entity
|
||||
*/
|
||||
public function insert($taxonomy) {
|
||||
|
||||
$new_taxonomy = parent::insert($taxonomy);
|
||||
|
@ -185,22 +186,20 @@ class Taxonomies extends Repository {
|
|||
}
|
||||
|
||||
public function update($object, $new_values = null){
|
||||
$map = $this->get_map();
|
||||
|
||||
$entity = [];
|
||||
|
||||
foreach ($object as $key => $value) {
|
||||
if($key != 'ID') {
|
||||
$entity[$map[$key]['map']] = $value ;
|
||||
} elseif ($key == 'ID'){
|
||||
$entity[$key] = (int) $value;
|
||||
foreach ($new_values as $key => $value) {
|
||||
try {
|
||||
$set_ = 'set_' . $key;
|
||||
$object->$set_( $value );
|
||||
} catch (\Error $error){
|
||||
return $error->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
$updated_taxonomy = new Entities\Taxonomy(wp_update_post($entity));
|
||||
$updated_taxonomy->register_taxonomy();
|
||||
if($object->validate()){
|
||||
return $this->insert($object);
|
||||
}
|
||||
|
||||
return $updated_taxonomy;
|
||||
return $object->get_errors();
|
||||
}
|
||||
|
||||
public function delete($args){
|
||||
|
|
|
@ -61,6 +61,10 @@ class Terms extends Repository {
|
|||
'on_error' => __('The user is empty or invalid', 'tainacan'),
|
||||
'validation' => v::numeric()->positive(),
|
||||
],
|
||||
'hide_empty' => [
|
||||
'map' => 'hide_empty',
|
||||
'type' => 'bool'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -156,20 +160,23 @@ class Terms extends Repository {
|
|||
}
|
||||
|
||||
public function update($object, $new_values = null){
|
||||
$map = $this->get_map();
|
||||
$tax_name = $object[1];
|
||||
$object = $object[0];
|
||||
|
||||
$entity = [];
|
||||
|
||||
foreach ($object[0] as $key => $value) {
|
||||
if($key != 'ID') {
|
||||
$entity[$map[$key]['map']] = $value ;
|
||||
foreach ($new_values as $key => $value) {
|
||||
try {
|
||||
$set_ = 'set_' . $key;
|
||||
$object->$set_( $value );
|
||||
} catch (\Error $error){
|
||||
return $error->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
$term_tax_ids = wp_update_term($object[1]['term_id'], $object[1]['tax_name'], $entity);
|
||||
$term_id = (int) $term_tax_ids['term_id'];
|
||||
if($object->validate()){
|
||||
return new Entities\Term($this->insert($object), $tax_name);
|
||||
}
|
||||
|
||||
return new Entities\Term($term_id, $object[1]['tax_name']);
|
||||
return $object->get_errors();
|
||||
}
|
||||
|
||||
public function delete($args){
|
||||
|
|
|
@ -48,4 +48,12 @@ trait Entity_Collections_Relation {
|
|||
$this->set_collections_ids($collections_ids);
|
||||
}
|
||||
|
||||
public function set_collection($new_collection_id){
|
||||
$this->collections = $this->get_mapped_property('collections_ids');
|
||||
|
||||
$collections[] = $new_collection_id;
|
||||
|
||||
$this->set_collections_ids($collections);
|
||||
}
|
||||
|
||||
}
|
|
@ -22,16 +22,19 @@ export const eventBus = new Vue({
|
|||
listener(){
|
||||
const components = this.getAllComponents();
|
||||
for (let eventElement of components){
|
||||
eventElement.addEventListener('changeValues', (event) => {
|
||||
eventElement.addEventListener('input', (event) => {
|
||||
if ( event.detail[0] ){
|
||||
const promisse = this.$store.dispatch('item/updateMetadata', event.detail[0] );
|
||||
const promisse = this.$store.dispatch('item/updateMetadata',
|
||||
{ item_id: $(eventElement).attr("item_id"), field_id: $(eventElement).attr("field_id"), values: event.detail });
|
||||
|
||||
promisse.then( response => {
|
||||
eventElement.errorsMsg = JSON.stringify( [] );
|
||||
eventElement.value = response.value;
|
||||
// eventElement.errorsMsg = JSON.stringify( [] );
|
||||
// eventElement.value = response.value;
|
||||
$(eventElement).val(response.value);
|
||||
}, error => {
|
||||
const field = this.errors.find(error => error.field_id === event.detail[0].field_id );
|
||||
eventElement.errorsMsg = JSON.stringify( field.error );
|
||||
eventElement.value = event.detail[0].values;
|
||||
// eventElement.errorsMsg = JSON.stringify( field.error );
|
||||
// eventElement.value = event.detail[0].values;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@ import VueCustomElement from 'vue-custom-element';
|
|||
import ElementUI from 'element-ui'
|
||||
import { eventBus } from './event-bus-web-components';
|
||||
|
||||
Vue.use(ElementUI)
|
||||
Vue.use(ElementUI);
|
||||
Vue.use(VueCustomElement);
|
||||
|
||||
import Text from '../classes/field-types/text/Text.vue';
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Tests;
|
||||
|
||||
/**
|
||||
*
|
||||
* @group api
|
||||
*
|
||||
*/
|
||||
class TAINACAN_REST_Logs_Controller extends TAINACAN_UnitApiTestCase {
|
||||
|
||||
public function test_get_logs(){
|
||||
$this->tainacan_entity_factory->create_entity(
|
||||
'log',
|
||||
[
|
||||
'title' => 'Log 1',
|
||||
'description' => 'Log number 1',
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
$this->tainacan_entity_factory->create_entity(
|
||||
'log',
|
||||
[
|
||||
'title' => 'Log 2',
|
||||
'description' => 'Log number 2',
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->namespace . '/logs'
|
||||
);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals('Log 1', $data[1]['title']);
|
||||
$this->assertEquals('Log 2', $data[0]['title']);
|
||||
}
|
||||
|
||||
public function test_get_a_log(){
|
||||
$log = $this->tainacan_entity_factory->create_entity(
|
||||
'log',
|
||||
[
|
||||
'title' => 'Log',
|
||||
'description' => 'A description',
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->namespace . '/logs/' . $log->get_id()
|
||||
);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals('Log', $data['title']);
|
||||
$this->assertEquals($log->get_id(), $data['id']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -148,15 +148,13 @@ class TAINACAN_REST_Terms extends TAINACAN_UnitApiTestCase {
|
|||
true
|
||||
);
|
||||
|
||||
$show_empty = json_encode([
|
||||
'hide_empty' => false
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms'
|
||||
);
|
||||
|
||||
$request->set_body($show_empty);
|
||||
$request->set_query_params([
|
||||
'hide_empty' => false
|
||||
]);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
|
|
Loading…
Reference in New Issue