Merge branch 'feature/compount-metadata-type-refactor' of https://github.com/tainacan/tainacan into feature/compount-metadata-type-refactor
This commit is contained in:
commit
eb6f0c89f0
|
@ -183,7 +183,7 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
$item_id = $request['item_id'];
|
||||
$metadatum_id = $request['metadatum_id'];
|
||||
$value = $body['values'];
|
||||
$parent_meta_id = isset( $body['parent_meta_id'] ) && $parent_meta_id > 0 ? $body['parent_meta_id'] : null;
|
||||
$parent_meta_id = isset( $body['parent_meta_id'] ) && $body['parent_meta_id'] > 0 ? $body['parent_meta_id'] : null;
|
||||
|
||||
$item = $this->item_repository->fetch( $item_id );
|
||||
$metadatum = $this->metadatum_repository->fetch( $metadatum_id );
|
||||
|
@ -279,6 +279,11 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
],
|
||||
'description' => __('The value(s) of item metadata')
|
||||
];
|
||||
$endpoint_args['parent_meta_id'] = [
|
||||
'type' => 'array/string/object/integer',
|
||||
'items' => ['type' => 'array/string/object/integer'],
|
||||
'description' => __('The parent meta ID for group children item metadatas')
|
||||
];
|
||||
}
|
||||
|
||||
return $endpoint_args;
|
||||
|
|
|
@ -746,38 +746,10 @@ class Collection extends Entity {
|
|||
return true;
|
||||
}
|
||||
|
||||
return $this->validate_metadata_order() && parent::validate();
|
||||
return parent::validate();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate metadata order collection
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function validate_metadata_order() {
|
||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||
$metadata_order = $this->get_metadata_order();
|
||||
if( empty($metadata_order) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$parent = 0;
|
||||
for($pos = 0; $pos < sizeof($metadata_order); $pos++ ) {
|
||||
$metadatum_id = $metadata_order[$pos]['id'];
|
||||
$metadatum = $Tainacan_Metadata->fetch( $metadatum_id );
|
||||
if ($metadatum->get_parent() != 0) {
|
||||
if ($parent != $metadatum->get_parent()) {
|
||||
$this->add_error('metadata_order', __('collection metadata order is invalid', 'tainacan'));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$parent = $metadatum_id;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an user have permission on any of the collections capabilities
|
||||
* defined in Tainacan\Roles class.
|
||||
|
|
|
@ -30,10 +30,10 @@ class Item_Metadata_Entity extends Entity {
|
|||
* @param Metadatum $metadatum Metadatum Entity
|
||||
* @param int $meta_id ID for a specific meta row
|
||||
*/
|
||||
function __construct(Item $item = null, Metadatum $metadatum = null, $meta_id = null, $parent_meta_id = null) {
|
||||
function __construct(Item $item = null, Metadatum $metadatum = null, $meta_id = null, $parent_meta_id = null) {
|
||||
|
||||
$this->set_item($item);
|
||||
$this->set_metadatum($metadatum);
|
||||
$this->set_item($item);
|
||||
$this->set_metadatum($metadatum);
|
||||
|
||||
if (!is_null($meta_id) && is_int($meta_id)) {
|
||||
$this->set_meta_id($meta_id);
|
||||
|
@ -42,9 +42,7 @@ class Item_Metadata_Entity extends Entity {
|
|||
if (!is_null($parent_meta_id) && is_int($parent_meta_id)) {
|
||||
$this->set_parent_meta_id($parent_meta_id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string used before each value when concatenating multiple values
|
||||
|
@ -214,7 +212,7 @@ class Item_Metadata_Entity extends Entity {
|
|||
$metadata = new Metadatum( $child['id'] );
|
||||
$itemMetadata = new self( $this->get_item(), $metadata );
|
||||
$child_primitive_type = $metadata->get_metadata_type_object()->get_primitive_type();
|
||||
if ( $itemMetadata instanceof ItemMetadataEntity && $child_primitive_type === 'term' ) {
|
||||
if ( $itemMetadata instanceof Item_Metadata_Entity && $child_primitive_type === 'term' ) {
|
||||
$compounds[$child['id']] = $itemMetadata->_toArray();
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +221,7 @@ class Item_Metadata_Entity extends Entity {
|
|||
if( is_array($value) ) {
|
||||
foreach ($value as $itemMetadata) {
|
||||
$child_primitive_type = $itemMetadata->get_metadatum()->get_metadata_type_object()->get_primitive_type();
|
||||
if ( $itemMetadata instanceof ItemMetadataEntity && $child_primitive_type !== 'term' ) {
|
||||
if ( $itemMetadata instanceof Item_Metadata_Entity && $child_primitive_type !== 'term' ) {
|
||||
$compounds[$itemMetadata->get_metadatum()->get_id()] = $itemMetadata->_toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -415,8 +415,8 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
|
|||
|
||||
$order = [
|
||||
['id' => $metadatum->get_id(), 'enabled' => true],
|
||||
['id' => $metadatum_child1->get_id(), 'enabled' => true],
|
||||
['id' => $metadatum_child2->get_id(), 'enabled' => true],
|
||||
//['id' => $metadatum_child1->get_id(), 'enabled' => true],
|
||||
//['id' => $metadatum_child2->get_id(), 'enabled' => true],
|
||||
['id' => $metadatum1->get_id(), 'enabled' => true],
|
||||
['id' => $metadatum2->get_id(), 'enabled' => true]
|
||||
];
|
||||
|
@ -427,17 +427,17 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
|
|||
|
||||
$metadata_order = $Tainacan_Collections->fetch( $collection->get_id(), 'OBJECT' )->get_metadata_order();
|
||||
$this->assertEquals($metadata_order[0]['id'], $order[0]['id']);
|
||||
//$this->assertEquals($metadata_order[1]['id'], $order[1]['id']);
|
||||
//$this->assertEquals($metadata_order[2]['id'], $order[2]['id']);
|
||||
$this->assertEquals($metadata_order[1]['id'], $order[1]['id']);
|
||||
$this->assertEquals($metadata_order[2]['id'], $order[2]['id']);
|
||||
$this->assertEquals($metadata_order[3]['id'], $order[3]['id']);
|
||||
$this->assertEquals($metadata_order[4]['id'], $order[4]['id']);
|
||||
|
||||
$order = [
|
||||
['id' => $metadatum1->get_id(), 'enabled' => true],
|
||||
['id' => $metadatum2->get_id(), 'enabled' => true],
|
||||
['id' => $metadatum->get_id(), 'enabled' => true],
|
||||
['id' => $metadatum_child1->get_id(), 'enabled' => true],
|
||||
['id' => $metadatum_child2->get_id(), 'enabled' => true]
|
||||
//['id' => $metadatum_child1->get_id(), 'enabled' => true],
|
||||
//['id' => $metadatum_child2->get_id(), 'enabled' => true]
|
||||
];
|
||||
|
||||
$collection->set_metadata_order($order);
|
||||
|
@ -448,19 +448,18 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
|
|||
$this->assertEquals($metadata_order[0]['id'], $order[0]['id']);
|
||||
$this->assertEquals($metadata_order[1]['id'], $order[1]['id']);
|
||||
$this->assertEquals($metadata_order[2]['id'], $order[2]['id']);
|
||||
$this->assertEquals($metadata_order[3]['id'], $order[3]['id']);
|
||||
$this->assertEquals($metadata_order[4]['id'], $order[4]['id']);
|
||||
//$this->assertEquals($metadata_order[3]['id'], $order[3]['id']);
|
||||
//$this->assertEquals($metadata_order[4]['id'], $order[4]['id']);
|
||||
|
||||
// $order = [
|
||||
// ['id' => $metadatum1->get_id(), 'enabled' => true],
|
||||
// ['id' => $metadatum->get_id(), 'enabled' => true],
|
||||
// ['id' => $metadatum2->get_id(), 'enabled' => true],
|
||||
// //['id' => $metadatum_child1->get_id(), 'enabled' => true],
|
||||
// //['id' => $metadatum_child2->get_id(), 'enabled' => true]
|
||||
// ];
|
||||
|
||||
$order = [
|
||||
['id' => $metadatum1->get_id(), 'enabled' => true],
|
||||
['id' => $metadatum->get_id(), 'enabled' => true],
|
||||
['id' => $metadatum2->get_id(), 'enabled' => true],
|
||||
['id' => $metadatum_child1->get_id(), 'enabled' => true],
|
||||
['id' => $metadatum_child2->get_id(), 'enabled' => true]
|
||||
];
|
||||
|
||||
$collection->set_metadata_order($order);
|
||||
$this->assertFalse($collection->validate());
|
||||
// $collection->set_metadata_order($order);
|
||||
// $this->assertFalse($collection->validate());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue