fix: specific function call `get_value_as_string` of metadata type

This commit is contained in:
vnmedeiros 2023-03-03 09:29:08 -03:00
parent 6e7f7f7134
commit 178aececca
2 changed files with 39 additions and 0 deletions

View File

@ -182,6 +182,15 @@ class Item_Metadata_Entity extends Entity {
* @return string
*/
public function get_value_as_string() {
$metadatum = $this->get_metadatum();
if (is_object($metadatum)) {
$fto = $metadatum->get_metadata_type_object();
if (is_object($fto)) {
if ( method_exists($fto, 'get_value_as_string') ) {
return $fto->get_value_as_string($this);
}
}
}
return strip_tags($this->get_value_as_html());
}

View File

@ -89,6 +89,36 @@ class GeoCoordinate extends Metadata_Type {
}
return true;
}
/**
* Return the value of an Item_Metadata_Entity using a metadatum of this metadatum type as a string
* @param Item_Metadata_Entity $item_metadata
* @return string The String representation of the value, containing one or multiple items names, linked to the item page
*/
public function get_value_as_string(\Tainacan\Entities\Item_Metadata_Entity $item_metadata) {
$value = $item_metadata->get_value();
$return = '';
if ( $item_metadata->is_multiple() ) {
$prefix = $item_metadata->get_multivalue_prefix();
$suffix = $item_metadata->get_multivalue_suffix();
$separator = $item_metadata->get_multivalue_separator();
$total = count($value);
$count = 0;
foreach ($value as $v) {
$return .= $prefix;
$return .= (string) $v;
$return .= $suffix;
$count ++;
if ($count < $total)
$return .= $separator;
}
} else {
$return = (string) $value;
}
return $return;
}
/**
* Get the value as a HTML string with proper date format set in admin