Merge branch 'hotfix/0.16.3' of https://github.com/tainacan/tainacan into hotfix/0.16.3

This commit is contained in:
mateuswetah 2020-06-27 18:20:32 -03:00
commit c9289bf54d
1 changed files with 68 additions and 12 deletions

View File

@ -50,6 +50,8 @@ class CSV extends Exporter {
$line[] = implode( $this->get_option('multivalued_delimiter'), $rel ); $line[] = implode( $this->get_option('multivalued_delimiter'), $rel );
else else
$line[] = $rel; $line[] = $rel;
} elseif ($meta->get_metadatum()->get_metadata_type() == 'Tainacan\Metadata_Types\Compound') {
$line[] = $this->get_compound_metadata_cell($meta);
} else { } else {
$line[] = $meta->get_value_as_string(); $line[] = $meta->get_value_as_string();
} }
@ -83,6 +85,37 @@ class CSV extends Exporter {
} }
function get_compound_metadata_cell($meta) {
$enclosure = $this->get_option('enclosure');
$delimiter = $this->get_option('delimiter');
$multivalued_delimiter = $this->get_option('multivalued_delimiter');
$metadata_type_options = $meta->get_metadatum()->get_metadata_type_options();
$initial_values = [];
foreach($metadata_type_options['children_order'] as $order) {
$initial_values[$order['id']] = "";
}
$values = $meta->get_value();
$array_meta = [];
foreach($values as $value) {
$assoc_arr = array_reduce($value, function ($result, $item) {
$metadatum_id = $item->get_metadatum()->get_id();
if ($item->get_metadatum()->get_metadata_type() == 'Tainacan\Metadata_Types\Relationship') {
$result[$metadatum_id] = $item->get_value();
} else {
$result[$metadatum_id] = $item->get_value_as_string();
}
return $result;
}, $initial_values);
$temp = implode($delimiter, $assoc_arr);
$array_meta[] = $temp;
//$array_meta[] = "${enclosure}${temp}${enclosure}";
}
return implode($multivalued_delimiter, $array_meta);
}
function get_document_cell($item) { function get_document_cell($item) {
$type = $item->get_document_type(); $type = $item->get_document_type();
if ($type == 'attachment') $type = 'file'; if ($type == 'attachment') $type = 'file';
@ -128,6 +161,39 @@ class CSV extends Exporter {
return $response; return $response;
} }
private function get_description_title_meta($meta) {
$meta_type = explode('\\', $meta->get_metadata_type()) ;
$meta_type = strtolower($meta_type[sizeof($meta_type)-1]);
if($meta_type == 'compound') {
$enclosure = $this->get_option('enclosure');
$delimiter = $this->get_option('delimiter');
$metadata_type_options = $meta->get_metadata_type_options();
$desc_childrens = [];
foreach($metadata_type_options['children_objects'] as $children) {
$children_meta_type = explode('\\', $children['metadata_type']);
$children_meta_type = strtolower($children_meta_type[sizeof($children_meta_type)-1]);
$children_meta_type .= ($children['collection_key'] === 'yes' ? '|collection_key_yes' : '');
$desc_childrens[] = $children['name'] . '|' . $children_meta_type;
}
$meta_type .= "(" . implode($delimiter, $desc_childrens) . ")";
$desc_title_meta =
$meta->get_name() .
('|' . $meta_type) .
($meta->is_multiple() ? '|multiple': '') .
('|display_' . $meta->get_display());
} else {
$desc_title_meta =
$meta->get_name() .
('|' . $meta_type) .
($meta->is_multiple() ? '|multiple': '') .
($meta->is_required() ? '|required': '') .
('|display_' . $meta->get_display()) .
($meta->is_collection_key() ? '|collection_key_yes' : '');
}
return $desc_title_meta;
}
public function output_header() { public function output_header() {
$mapper = $this->get_current_mapper(); $mapper = $this->get_current_mapper();
@ -145,17 +211,7 @@ class CSV extends Exporter {
$metadata = $collection->get_metadata(); $metadata = $collection->get_metadata();
foreach ($metadata as $meta) { foreach ($metadata as $meta) {
$meta_type = explode('\\', $meta->get_metadata_type()) ; $desc_title_meta = $this->get_description_title_meta($meta);
$meta_type = strtolower($meta_type[sizeof($meta_type)-1]);
$desc_title_meta =
$meta->get_name() .
('|' . $meta_type) .
($meta->is_multiple() ? '|multiple': '') .
($meta->is_required() ? '|required': '') .
('|display_' . $meta->get_display()) .
($meta->is_collection_key() ? '|collection_key_yes' : '');
$line[] = $desc_title_meta; $line[] = $desc_title_meta;
} }
} }