feat: add test if relationship metadata is valid. #358

This commit is contained in:
vnmedeiros 2021-06-16 10:11:12 -03:00
parent 856ee25ea3
commit d5072ff486
2 changed files with 27 additions and 0 deletions

View File

@ -599,6 +599,9 @@ class Items extends Repository {
foreach($metadatas as $metadata) {
$collection = $metadata->get_collection();
if (!$collection instanceof \Tainacan\Entities\Collection || !$metadata instanceof \Tainacan\Entities\Metadatum || !$Tainacan_Metadata->metadata_is_enabled($current_collection, $metadata))
continue;
$prepared_items = array();
$items = $this->fetch([
'meta_query' => [

View File

@ -1681,4 +1681,28 @@ class Metadata extends Repository {
}
/**
* Test if a metadata is enabled on collection.
*
* @param \Tainacan\Entities\Collection $collection
* @param \Tainacan\Entities\Metadatum $metadata
*
* @return boolean
*/
public function metadata_is_enabled($collection, $metadata) {
$order = $collection->get_metadata_order();
if($order == false) return true;
$order = ( is_array( $order ) ) ? $order : unserialize( $order );
if( is_array($order) ) {
foreach ($order as $metadata_order) {
if($metadata_order['id'] == $metadata->get_id()) {
if($metadata_order['enabled'] == false)
return false;
return true;
}
}
}
return false;
}
}