fix: fetch metadatas by metadata section considering order #184

This commit is contained in:
vnmedeiros 2022-08-11 11:33:04 -03:00
parent 32c8aea7ff
commit f7e0481ec9
2 changed files with 35 additions and 11 deletions

View File

@ -335,18 +335,8 @@ class Metadata_Sections extends Repository {
public function get_metadata_object_list($metadata_section_id) {
$metadata_section = $this->fetch($metadata_section_id);
if ($metadata_section) {
$args = array(
'parent' => 0,
'meta_query' => [
[
'key' => 'metadata_section_id',
'value' => $metadata_section_id,
'compare' => '='
]
]
);
$metadata_repository = \Tainacan\Repositories\Metadata::get_instance();
$metadata_list = $metadata_repository->fetch($args, 'OBJECT');
$metadata_list = $metadata_repository->fetch_by_metadata_section($metadata_section);
return $metadata_list;
}
return false;

View File

@ -614,6 +614,40 @@ class Metadata extends Repository {
return $results;
}
/**
* fetch metadatum by metadata section, considering order
*
* @param Entities\Metadata_Section $collection
* @param array $args WP_Query args plus disabled_metadata
*
* @return array Entities\Metadatum
* @throws \Exception
*/
public function fetch_by_metadata_section( Entities\Metadata_Section $metadata_section, $args = [] ) {
$results = [];
if ($metadata_section && $metadata_section->can_read()) {
$metadata_section_id = $metadata_section->get_id();
$collection = $metadata_section->get_collection();
$args = array_merge($args, array(
'parent' => 0,
'meta_query' => [
[
'key' => 'metadata_section_id',
'value' => $metadata_section_id,
'compare' => '='
]
]
));
$results = $this->fetch($args, 'OBJECT');
return $this->order_result(
$results,
$collection,
isset( $args['include_disabled'] ) ? $args['include_disabled'] : false
);
}
return $results;
}
/**
* Ordinate the result from fetch response if $collection has an ordination,
* metadata not ordinated appear on the end of the list