Now metadata multiple and status of entities is working through API

This commit is contained in:
weryques 2018-02-14 16:15:19 -02:00
parent 74d0009609
commit 60e362e624
3 changed files with 38 additions and 9 deletions

View File

@ -11,8 +11,8 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
protected function get_only_needed_attributes($entity, $map){
$entity_prepared = [
'id' => $entity->get_id(),
'description' => $entity->get_description(),
'id' => $entity->get_id(),
'description' => $entity->get_description(),
];
if(array_key_exists('modification_date', $map)){
@ -41,6 +41,10 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
$entity_prepared['columns'] = $entity->get_columns();
}
if(array_key_exists('status', $map)){
$entity_prepared['status'] = $entity->get_status();
}
return $entity_prepared;
}

View File

@ -55,7 +55,11 @@ class Item_Metadata extends Repository {
$values = $item_metadata->get_value();
foreach ($values as $value){
update_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id(), wp_slash( $value ));
if(array_key_exists('prev', $value)) {
update_post_meta( $item_metadata->item->get_id(), $item_metadata->field->get_id(), wp_slash( $value['new'] ), wp_slash($value['prev']) );
} else {
add_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id(), wp_slash( $value ));
}
}
}
}
@ -100,12 +104,14 @@ class Item_Metadata extends Repository {
}
}
/**
* Fetch Item Field objects related to an Item
*
* @param Entities\Item $object
* @return array
*/
/**
* Fetch Item Field objects related to an Item
*
* @param Entities\Item $object
*
* @return array
* @throws \Exception
*/
public function fetch($object, $output = null ){
if($object instanceof Entities\Item){
global $Tainacan_Items, $Tainacan_Fields;

View File

@ -0,0 +1,19 @@
<?php
namespace Tainacan\Tests;
/**
* @group queries
* **/
class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
public function test_collections_queries(){
$this->tainacan_entity_factory->create_entity(
'collection',
[],
true
);
}
}
?>