Commit 2bd5dc16 authored by Sebastian Castro's avatar Sebastian Castro

Import: some improvements

Create parent categories
parent 3c9ee3ec
......@@ -63,7 +63,7 @@
}
for(var i = 0; i < dataProperties.length; i++) {
var prop = dataProperties[i];
if (allProperties.indexOf(prop) == -1) {
if (allProperties.indexOf(prop) == -1 && prop != '/') {
allProperties.push(prop);
otherData.push({id: prop, text: prop});
}
......@@ -71,13 +71,13 @@
{% for originName, mappedName in mapping %}
var originName = '{{ originName }}';
if (originName && allProperties.indexOf(originName) == -1 && coreFields.indexOf(originName) == -1)
if (originName && allProperties.indexOf(originName) == -1 && coreFields.indexOf(originName) == -1 && originName != '/')
{
importedData.push({id: originName, text: originName});
allProperties.push(originName);
}
var mappedName = '{{ mappedName }}';
if (mappedName && allProperties.indexOf(mappedName) == -1 && coreFields.indexOf(originName) == -1)
if (mappedName && allProperties.indexOf(mappedName) == -1 && coreFields.indexOf(mappedName) == -1 && mappedName != '/')
{
otherData.push({id: mappedName, text: mappedName});
allProperties.push(mappedName);
......
......@@ -14,7 +14,7 @@
{% include '@BiopenAdmin/partials/list__action_refresh.html.twig' with {'class': 'btn-primary'} %}
{% set class = object.ontologyMapping|length > 0 ? 'btn-default' : 'btn-primary' %}
{% if object.id != "" %}
<a href="{{ admin.generateObjectUrl('collect', object) }}" class="btn {{ class }} view_link">
<a href="{{ admin.generateObjectUrl('collect', object) }}" class="btn {{ class }} view_link" title="Met à jour les tables de correspondance sans réellement importer les données">
<i class="fa fa-eye" aria-hidden="true"></i>
Lire les données
</a>
......
......@@ -54,7 +54,6 @@ class ElementImportMappingService
// remove empty row, i.e. without name
$data = array_filter($data, function($row) { return array_key_exists('name', $row); });
// $data = $this->addMissingFieldsToData($data);
if ($import->isCategoriesFieldMapped())
{
......@@ -62,6 +61,8 @@ class ElementImportMappingService
$data = $this->mapTaxonomy($data);
}
$data = $this->addMissingFieldsToData($data);
$this->em->persist($import);
$this->em->flush();
return $data;
......@@ -77,7 +78,8 @@ class ElementImportMappingService
if (!in_array($key, $allNewFields)) $allNewFields[] = $key;
if (!array_key_exists($key, $ontologyMapping)) {
$value = in_array($key, $this->coreFields) ? $key : "";
if (!$value && in_array($this->mappedCoreFields[$key], $this->coreFields)) $value = $this->mappedCoreFields[$key];
if (!$value && array_key_exists($key, $this->mappedCoreFields) && in_array($this->mappedCoreFields[$key], $this->coreFields))
$value = $this->mappedCoreFields[$key];
$ontologyMapping[$key] = $value;
}
}
......@@ -162,13 +164,20 @@ class ElementImportMappingService
foreach ($data as $key => $row)
{
if (is_string($row['categories'])) $row['categories'] = explode(',', $row['categories']);
$data[$key]['categories'] = array_map(function($el) use ($mapping) {
return array_key_exists($el, $mapping) ? $mapping[$el] : '';
$categories = array_map(function($el) use ($mapping) {
return array_key_exists($el, $mapping) ? $this->mappingTableIds[$mapping[$el]]['idAndParentsId'] : [];
}, $row['categories']);
$data[$key]['categories'] = array_unique($this->array_flatten($categories));
}
return $data;
}
private function array_flatten(array $array) {
$return = array();
array_walk_recursive($array, function($a) use (&$return) { $return[] = $a; });
return $return;
}
private function createOptionsMappingTable($options = null)
{
if ($options === null) $options = $this->em->getRepository('BiopenGeoDirectoryBundle:Option')->findAll();
......
......@@ -10,7 +10,7 @@
"address":{"streetAddress":"5 rue Georges Jacquet Grenoble"},
"createdAt":"21/12/2018 à 18:26",
"updatedAt":"17/03/2019 à 13:38",
"taxonomy": ["bleu", "tandem"],
"taxonomy": ["vert foncé", "tandem"],
"abstract": "Ateliers bricole",
"openHoursString": "",
"openHours": null,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment