feat: add metadata of control have_thumbnail #114

This commit is contained in:
vnmedeiros 2020-10-28 18:37:09 -03:00
parent 7b55a3686d
commit 39ad193946
2 changed files with 23 additions and 3 deletions

View File

@ -824,6 +824,15 @@ class Metadata extends Repository {
'display' => 'never',
'metadata_type_options' => [ 'control_metadatum' => 'collection_id' ]
],
'have_thumbnail' => [
'name' => 'HaveThumbnail',
'description' => 'Does the item have a thumbnail?',
'collection_id' => 'default',
'metadata_type' => 'Tainacan\Metadata_Types\Control',
'status' => 'publish',
'display' => 'never',
'metadata_type_options' => [ 'control_metadatum' => 'have_thumbnail' ]
],
];
foreach ( $data_control_metadata as $index => $data_control_metadatum ) {
@ -832,7 +841,10 @@ class Metadata extends Repository {
} else {
$exists = false;
foreach ( $metadata as $metadatum ) {
if ( $metadatum->get_metadata_type() === $data_control_metadatum['metadata_type'] ) {
if (
$metadatum->get_metadata_type() === $data_control_metadatum['metadata_type'] &&
$metadatum->get_metadata_type_options()['control_metadatum'] == $data_control_metadatum['metadata_type_options']['control_metadatum']
) {
$exists = true;
}
}

View File

@ -51,6 +51,10 @@ class MetadataTypeControlHelperHook {
case 'collection_id':
$update_item_metadatum->set_value( $item->get_collection_id() );
break;
case 'have_thumbnail':
$update_item_metadatum->set_value( !empty($item->get__thumbnail_id()) ? 'yes':'no' );
break;
default:
// What the hell am I doing here?
@ -83,7 +87,7 @@ 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'],
'control_metadatum_options' => ['document_type', 'collection_id', 'have_thumbnail'],
'control_metadatum' => 'document_type'
]);
$metadataTypeControlHelperHook = MetadataTypeControlHelperHook::get_instance();
@ -114,9 +118,13 @@ class Control extends Metadata_Type {
case 'collection_id':
$return = ($format == 'html' ? $this->get_collection_as_html( $value ) : $this->get_collection_as_string( $value ));
break;
case 'have_thumbnail':
$return = ( $value == 'yes' ? __( 'yes', 'tainacan' ) : __( 'no', 'tainacan' ) );
break;
default:
// What the hell am I doing here?
$return = $value;// What the hell am I doing here?
break;
}
return $return;