feat: add option `only_repository` in control metadata #114

This commit is contained in:
vnmedeiros 2020-10-30 20:12:18 -03:00
parent c2d060950c
commit 386dceeb83
5 changed files with 43 additions and 19 deletions

View File

@ -382,6 +382,12 @@ class REST_Filters_Controller extends REST_Controller {
} else {
$collection = $this->collection_repository->fetch($request['collection_id']);
$filters = $this->filter_repository->fetch_by_collection($collection, $args);
$filters = array_filter($filters, function($filter) {
return ( $filter->get_metadatum() !== null && (
!isset($filter->get_metadatum()->get_metadata_type_options()['only_repository']) ||
$filter->get_metadatum()->get_metadata_type_options()['only_repository'] == 'no' )
);
});
}
$response = [];

View File

@ -387,6 +387,10 @@ class REST_Metadata_Controller extends REST_Controller {
]
];
if ($request['include_control_metadata_types'] === 'true') {
$args['include_control_metadata_types'] = true;
}
$result = $this->metadatum_repository->fetch( $args, 'OBJECT' );
}

View File

@ -110,7 +110,7 @@ class Cli_Control_Metadata {
$progress->finish();
$this->result_count['items'] += $this->result_count['items_collection'];
$msg = "\n" . $this->result_count['items_collection'] . " items recalculated in collection";
$msg = $this->result_count['items_collection'] . " items recalculated in collection";
\WP_CLI::success( $msg );
}

View File

@ -458,7 +458,9 @@ class Metadata extends Repository {
$results = $this->fetch( $args, 'OBJECT' );
}
$results = array_filter($results, function($meta) {
return ( !isset($meta->get_metadata_type_options()['only_repository']) || $meta->get_metadata_type_options()['only_repository'] == 'no' );
});
return $this->order_result(
$results,
@ -793,22 +795,26 @@ class Metadata extends Repository {
return;
}
$metadata = $this->fetch_by_collection( $collection, [
$metadata = $this->fetch( [
'meta_query' => [
[
'key' => 'metadata_type',
'value' => [ 'Tainacan\Metadata_Types\Control' ],
'compare' => 'IN'
'value' => 'Tainacan\Metadata_Types\Control',
'compare' => '='
],[
'key' => 'collection_id',
'value' => 'default',
'compare' => '='
]
],
'include_disabled' => true,
'include_control_metadata_types' => true
] );
], 'OBJECT' );
$data_control_metadata = [
'document_type' => [
'name' => 'DocumentType',
'description' => 'The item main document type',
'name' => __('Document type', 'tainacan'),
'description' => __('The item main document type', 'tainacan'),
'collection_id' => 'default',
'metadata_type' => 'Tainacan\Metadata_Types\Control',
'status' => 'publish',
@ -816,22 +822,25 @@ class Metadata extends Repository {
'metadata_type_options' => [ 'control_metadatum' => 'document_type' ]
],
'collection_id' => [
'name' => 'CollectionID',
'description' => 'The item collection ID',
'name' => __('Collection', 'tainacan'),
'description' => __('The item collection ID', 'tainacan'),
'collection_id' => 'default',
'metadata_type' => 'Tainacan\Metadata_Types\Control',
'status' => 'publish',
'display' => 'never',
'metadata_type_options' => [ 'control_metadatum' => 'collection_id' ]
'metadata_type_options' => [
'control_metadatum' => 'collection_id',
'only_repository' => 'yes'
]
],
'have_thumbnail' => [
'name' => 'HaveThumbnail',
'description' => 'Does the item have a thumbnail?',
'has_thumbnail' => [
'name' => __('Has thumbnail', 'tainacan'),
'description' => __('Does the item has a thumbnail set?', 'tainacan'),
'collection_id' => 'default',
'metadata_type' => 'Tainacan\Metadata_Types\Control',
'status' => 'publish',
'display' => 'never',
'metadata_type_options' => [ 'control_metadatum' => 'have_thumbnail' ]
'metadata_type_options' => [ 'control_metadatum' => 'has_thumbnail' ]
],
];

View File

@ -52,7 +52,7 @@ class MetadataTypeControlHelper {
$update_item_metadatum->set_value( $item->get_collection_id() );
break;
case 'have_thumbnail':
case 'has_thumbnail':
$update_item_metadatum->set_value( !empty($item->get__thumbnail_id()) ? 'yes':'no' );
break;
@ -87,8 +87,9 @@ class Control extends Metadata_Type {
$this->set_name( __('Control Type', 'tainacan') );
$this->set_description( __('A special metadata type, used to map certain item properties such as collection id and document type to metadata in order to easily create filters.', 'tainacan') );
$this->set_default_options([
'control_metadatum_options' => ['document_type', 'collection_id', 'have_thumbnail'],
'control_metadatum' => 'document_type'
'control_metadatum_options' => ['document_type', 'collection_id', 'has_thumbnail'],
'control_metadatum' => 'document_type',
'only_repository' => 'no'
]);
$metadataTypeControlHelper = MetadataTypeControlHelper::get_instance();
}
@ -121,7 +122,7 @@ class Control extends Metadata_Type {
$return = ($format == 'html' ? $this->get_collection_as_html( $value ) : $this->get_collection_as_string( $value ));
break;
case 'have_thumbnail':
case 'has_thumbnail':
$return = ( $value == 'yes' ? __( 'yes', 'tainacan' ) : __( 'no', 'tainacan' ) );
break;
@ -174,6 +175,10 @@ class Control extends Metadata_Type {
return __( 'URL', 'tainacan' );
break;
case 'empty':
return __( 'Empty', 'tainacan' );
break;
default:
return $value;
}