fix: order of data on value get as html or string

This commit is contained in:
vnmedeiros 2020-10-23 16:16:37 -03:00
parent d9d483e77d
commit c7a26a6c74
1 changed files with 26 additions and 17 deletions

View File

@ -169,6 +169,8 @@ class Compound extends Metadata_Type {
public function get_value_as_html(Item_Metadata_Entity $item_metadata) { public function get_value_as_html(Item_Metadata_Entity $item_metadata) {
$value = $item_metadata->get_value(); $value = $item_metadata->get_value();
$separator = $item_metadata->get_multivalue_separator(); $separator = $item_metadata->get_multivalue_separator();
$options = $item_metadata->get_metadatum()->get_metadata_type_object()->get_options();
$order = $options['children_order'];
$return = ''; $return = '';
if ( empty($value) ) if ( empty($value) )
@ -178,29 +180,36 @@ class Compound extends Metadata_Type {
$elements = []; $elements = [];
foreach ( $value as $compound_element ) { foreach ( $value as $compound_element ) {
if ( !empty($compound_element) ) { if ( !empty($compound_element) ) {
$metadata_value = ''; $metadata_value = array_fill(0, count($compound_element), null);
foreach ( $compound_element as $meta ) { $metadata_value_not_ordinate = [];
foreach ( $compound_element as $meta_id => $meta ) {
$index = array_search( $meta_id, array_column( $order, 'id' ) );
if ( $meta instanceof Item_Metadata_Entity && $meta->get_value_as_html() != '' ) { if ( $meta instanceof Item_Metadata_Entity && $meta->get_value_as_html() != '' ) {
$metadata_value .= '<label class="label">' . $meta->get_metadatum()->get_name() . '</label> <p>' . $meta->get_value_as_html() . "</p> \n"; if ( $index !== false ) {
$metadata_value[$index] = '<div class="tainacan-metadatum"><label class="label">' . $meta->get_metadatum()->get_name() . '</label> <p>' . $meta->get_value_as_html() . "</p></div>";
} else {
$metadata_value_not_ordinate[] = '<div class="tainacan-metadatum"><label class="label">' . $meta->get_metadatum()->get_name() . '</label> <p>' . $meta->get_value_as_html() . "</p></div>";
}
} }
} }
$elements[] = '<div class="tainacan-compound-metadatum">' . $metadata_value . "</div> \n" ; $elements[] = '<div class="tainacan-compound-metadatum">' . implode("\n", array_merge($metadata_value, $metadata_value_not_ordinate)) . "</div> \n" ;
} }
} }
$return .= '<div class="tainacan-compound-group">' . implode($separator, $elements) . '</div>'; $return = '<div class="tainacan-compound-group">' . implode($separator, $elements) . '</div>';
} else { } else {
$return .= '<div class="tainacan-compound-group">'; $metadata_value = array_fill(0, count($value), null);
foreach ( $value as $meta ) { $metadata_value_not_ordinate = [];
if ( $meta->get_value_as_html() != '' ) { foreach ( $value as $meta_id => $meta ) {
$return .= '<div class="tainacan-metadatum">'; $index = array_search( $meta_id, array_column( $order, 'id' ) );
if ( $meta instanceof Item_Metadata_Entity ) { if ( $meta instanceof Item_Metadata_Entity && $meta->get_value_as_html() != '' ) {
$return .= '<label class="label">' . $meta->get_metadatum()->get_name() . "</label>\n"; if ( $index !== false ) {
$return .= '<p>' . $meta->get_value_as_html() . '</p>'; $metadata_value[intval($index)] = '<div class="tainacan-metadatum"><label class="label">' . $meta->get_metadatum()->get_name() . '</label> <p>' . $meta->get_value_as_html() . "</p></div>";
} } else {
$return .= '</div>' . "\n\n"; $metadata_value_not_ordinate[] = '<div class="tainacan-metadatum"><label class="label">' . $meta->get_metadatum()->get_name() . '</label> <p>' . $meta->get_value_as_html() . "</p></div>";
} }
} }
$return .= '</div>' . "\n\n"; }
$return = '<div class="tainacan-compound-group">' . implode("\n", array_merge($metadata_value, $metadata_value_not_ordinate)) . "</div> \n";
} }
return $return; return $return;