Revert some features
This commit is contained in:
parent
0fddaa0833
commit
d9416118da
|
@ -22,57 +22,57 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @param $entity
|
// * @param $entity
|
||||||
*
|
// *
|
||||||
* @param $map
|
// * @param $map
|
||||||
* @param $context
|
// * @param $context
|
||||||
*
|
// *
|
||||||
* @return array
|
// * @return array
|
||||||
*/
|
// */
|
||||||
protected function get_only_needed_attributes($entity, $map, $context = null){
|
// protected function get_only_needed_attributes($entity, $map, $context = null){
|
||||||
|
//
|
||||||
$entity_prepared = [
|
// $entity_prepared = [
|
||||||
'id' => $entity->get_id(),
|
// 'id' => $entity->get_id(),
|
||||||
'description' => $entity->get_description(),
|
// 'description' => $entity->get_description(),
|
||||||
];
|
// ];
|
||||||
|
//
|
||||||
if($context === 'edit'){
|
// if($context === 'edit'){
|
||||||
$entity_prepared['current_user_can_edit'] = $entity->can_edit();
|
// $entity_prepared['current_user_can_edit'] = $entity->can_edit();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if(array_key_exists('modification_date', $map)){
|
// if(array_key_exists('modification_date', $map)){
|
||||||
$entity_prepared['modification_date'] = $entity->get_modification_date();
|
// $entity_prepared['modification_date'] = $entity->get_modification_date();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if(array_key_exists('creation_date', $map)){
|
// if(array_key_exists('creation_date', $map)){
|
||||||
$entity_prepared['creation_date'] = $entity->get_creation_date();
|
// $entity_prepared['creation_date'] = $entity->get_creation_date();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if(array_key_exists('author_id', $map)){
|
// if(array_key_exists('author_id', $map)){
|
||||||
$entity_prepared['author_id'] = $entity->get_author_id();
|
// $entity_prepared['author_id'] = $entity->get_author_id();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if(array_key_exists('name', $map)){
|
// if(array_key_exists('name', $map)){
|
||||||
$entity_prepared['name'] = $entity->get_name();
|
// $entity_prepared['name'] = $entity->get_name();
|
||||||
} elseif(array_key_exists('title', $map)){
|
// } elseif(array_key_exists('title', $map)){
|
||||||
$entity_prepared['title'] = $entity->get_title();
|
// $entity_prepared['title'] = $entity->get_title();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if(array_key_exists('featured_image', $map)){
|
// if(array_key_exists('featured_image', $map)){
|
||||||
$entity_prepared['featured_image'] = $entity->get_featured_img();
|
// $entity_prepared['featured_image'] = $entity->get_featured_img();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if(array_key_exists('columns', $map)){
|
// if(array_key_exists('columns', $map)){
|
||||||
$entity_prepared['columns'] = $entity->get_columns();
|
// $entity_prepared['columns'] = $entity->get_columns();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if(array_key_exists('status', $map)){
|
// if(array_key_exists('status', $map)){
|
||||||
$entity_prepared['status'] = $entity->get_status();
|
// $entity_prepared['status'] = $entity->get_status();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return $entity_prepared;
|
// return $entity_prepared;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $request
|
* @param $request
|
||||||
|
|
|
@ -82,9 +82,6 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
||||||
|
|
||||||
$collections = $this->collections_repository->fetch($args);
|
$collections = $this->collections_repository->fetch($args);
|
||||||
|
|
||||||
$map = $this->collections_repository->get_map();
|
|
||||||
|
|
||||||
|
|
||||||
$response = [];
|
$response = [];
|
||||||
if($collections->have_posts()){
|
if($collections->have_posts()){
|
||||||
while ($collections->have_posts()){
|
while ($collections->have_posts()){
|
||||||
|
@ -92,7 +89,7 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
|
||||||
|
|
||||||
$collection = new Entities\Collection($collections->post);
|
$collection = new Entities\Collection($collections->post);
|
||||||
|
|
||||||
array_push($response, $this->get_only_needed_attributes($collection, $map, $request['context']));
|
array_push($response, $this->prepare_item_for_response($collection, $request));
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_reset_postdata();
|
wp_reset_postdata();
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Tainacan\Field_Types;
|
|
||||||
|
|
||||||
class TAINACAN_REST_Field_Types_Controller extends TAINACAN_REST_Controller {
|
class TAINACAN_REST_Field_Types_Controller extends TAINACAN_REST_Controller {
|
||||||
private $field_type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TAINACAN_REST_Field_Types_Controller constructor.
|
* TAINACAN_REST_Field_Types_Controller constructor.
|
||||||
|
|
|
@ -78,27 +78,6 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $item_object
|
|
||||||
* @param $item_array
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
private function add_terms_to_item($item_object, $item_array){
|
|
||||||
$item_terms = $item_object->get_terms();
|
|
||||||
|
|
||||||
foreach ($item_terms as $index => $term){
|
|
||||||
$term_id = $term['term_id'];
|
|
||||||
|
|
||||||
$item_array['terms'][$term_id]['name'] = $term['name'];
|
|
||||||
$item_array['terms'][$term_id]['description'] = $term['description'];
|
|
||||||
$item_array['terms'][$term_id]['taxonomy'] = $term['taxonomy'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $item_array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $item_object
|
* @param $item_object
|
||||||
* @param $item_array
|
* @param $item_array
|
||||||
|
@ -134,8 +113,7 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
||||||
$item_arr['current_user_can_edit'] = $item->can_edit();
|
$item_arr['current_user_can_edit'] = $item->can_edit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$prep = $this->add_metadata_to_item($item, $item_arr);
|
return $this->add_metadata_to_item($item, $item_arr);
|
||||||
return $this->add_terms_to_item($item, $prep);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
|
@ -167,8 +145,6 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
||||||
$collection_id = $request['collection_id'];
|
$collection_id = $request['collection_id'];
|
||||||
$items = $this->items_repository->fetch($args, $collection_id, 'WP_Query');
|
$items = $this->items_repository->fetch($args, $collection_id, 'WP_Query');
|
||||||
|
|
||||||
$map = $this->items_repository->get_map();
|
|
||||||
|
|
||||||
$response = [];
|
$response = [];
|
||||||
if ($items->have_posts()) {
|
if ($items->have_posts()) {
|
||||||
while ( $items->have_posts() ) {
|
while ( $items->have_posts() ) {
|
||||||
|
@ -176,11 +152,9 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
||||||
|
|
||||||
$item = new Entities\Item($items->post);
|
$item = new Entities\Item($items->post);
|
||||||
|
|
||||||
$limited_item = $this->get_only_needed_attributes($item, $map, $request['context']);
|
$prepared_item = $this->prepare_item_for_response($item, $request);
|
||||||
$limited_item = $this->add_metadata_to_item($item, $limited_item);
|
|
||||||
$limited_item = $this->add_terms_to_item($item, $limited_item);
|
|
||||||
|
|
||||||
array_push($response, $limited_item);
|
array_push($response, $prepared_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_reset_postdata();
|
wp_reset_postdata();
|
||||||
|
|
|
@ -68,16 +68,14 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
|
||||||
|
|
||||||
$logs = $this->logs_repository->fetch($args);
|
$logs = $this->logs_repository->fetch($args);
|
||||||
|
|
||||||
$map = $this->logs_repository->get_map();
|
|
||||||
|
|
||||||
$response = [];
|
$response = [];
|
||||||
if($logs->have_posts()){
|
if($logs->have_posts()){
|
||||||
while ($logs->have_posts()){
|
while ($logs->have_posts()){
|
||||||
$logs->the_post();
|
$logs->the_post();
|
||||||
|
|
||||||
$collection = new Entities\Log($logs->post);
|
$log = new Entities\Log($logs->post);
|
||||||
|
|
||||||
array_push($response, $this->get_only_needed_attributes($collection, $map));
|
array_push($response, $this->prepare_item_for_response($log, $request));
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_reset_postdata();
|
wp_reset_postdata();
|
||||||
|
|
|
@ -118,8 +118,6 @@ class Items extends Repository {
|
||||||
|
|
||||||
public function insert($item) {
|
public function insert($item) {
|
||||||
|
|
||||||
global $Tainacan_Fields;
|
|
||||||
|
|
||||||
$map = $this->get_map();
|
$map = $this->get_map();
|
||||||
|
|
||||||
// get collection to determine post type
|
// get collection to determine post type
|
||||||
|
@ -159,22 +157,7 @@ class Items extends Repository {
|
||||||
add_post_meta($id, $prop, wp_slash( $value ));
|
add_post_meta($id, $prop, wp_slash( $value ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif($mapped['map'] == 'terms'){
|
}
|
||||||
$values = $item->get_mapped_property($prop);
|
|
||||||
|
|
||||||
if($values) {
|
|
||||||
$res = [];
|
|
||||||
|
|
||||||
foreach ($values as $value){
|
|
||||||
$taxonomy = get_term($value)->taxonomy;
|
|
||||||
$res[] = wp_set_post_terms( $item->WP_Post->ID, $value, $taxonomy );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! is_array( $res ) ) {
|
|
||||||
throw new \InvalidArgumentException( 'The id of post or taxonomy name or term name may be invalid. Response = ' . $res );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do_action('tainacan-insert', $item);
|
do_action('tainacan-insert', $item);
|
||||||
|
|
|
@ -314,24 +314,6 @@ abstract class Repository {
|
||||||
|
|
||||||
$property = $attachments_prepared;
|
$property = $attachments_prepared;
|
||||||
}
|
}
|
||||||
} elseif ($mapped === 'terms'){
|
|
||||||
$taxonomies = get_taxonomies('', 'names');
|
|
||||||
|
|
||||||
$terms_prepared = [];
|
|
||||||
foreach($taxonomies as $taxonomy){
|
|
||||||
if(stristr($taxonomy, 'tnc_tax_')) {
|
|
||||||
$terms = isset( $entity->WP_Post->ID ) ? wp_get_post_terms( $entity->WP_Post->ID, $taxonomy ) : null;
|
|
||||||
|
|
||||||
if ( is_array( $terms ) ) {
|
|
||||||
foreach ( $terms as $term ) {
|
|
||||||
$term = new Entities\Term( $term->term_id, $term->taxonomy );
|
|
||||||
array_push( $terms_prepared, $term->__toArray() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$property = $terms_prepared;
|
|
||||||
} else {
|
} else {
|
||||||
$property = isset($entity->WP_Post->$mapped) ? $entity->WP_Post->$mapped : null;
|
$property = isset($entity->WP_Post->$mapped) ? $entity->WP_Post->$mapped : null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace Tainacan\Tests;
|
namespace Tainacan\Tests;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group queries
|
* @group api
|
||||||
* **/
|
* **/
|
||||||
class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
||||||
|
|
||||||
|
@ -78,7 +78,6 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
||||||
'description' => 'Item in collection A',
|
'description' => 'Item in collection A',
|
||||||
'status' => 'publish',
|
'status' => 'publish',
|
||||||
'collection' => $collectionA,
|
'collection' => $collectionA,
|
||||||
'terms' => [$termA]
|
|
||||||
],
|
],
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
@ -90,7 +89,6 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
||||||
'description' => 'Item in collection A',
|
'description' => 'Item in collection A',
|
||||||
'status' => 'private',
|
'status' => 'private',
|
||||||
'collection' => $collectionA,
|
'collection' => $collectionA,
|
||||||
'terms' => [$termA]
|
|
||||||
],
|
],
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
@ -285,6 +283,9 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
wp_set_post_terms($itemA1->get_id(), $termA, $taxonomyA->get_db_identifier());
|
||||||
|
wp_set_post_terms($itemA2->get_id(), $termA, $taxonomyA->get_db_identifier());
|
||||||
|
|
||||||
$tax_query_request_collections = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $collectionA->get_id() . '/items');
|
$tax_query_request_collections = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $collectionA->get_id() . '/items');
|
||||||
$tax_query_request_collections->set_query_params($tax_query);
|
$tax_query_request_collections->set_query_params($tax_query);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue