Commit 12762a96 authored by Sebastian Castro's avatar Sebastian Castro

Import: detect new ontology and new taxonomy and alert user

parent c8ceeb02
......@@ -90,15 +90,19 @@ class ImportAdmin extends AbstractAdmin
if ($this->getSubject()->getId())
{
$title = 'Table de correspondance des champs';
if ($this->getSubject()->getNewOntologyToMap()) $title .= ' <label class="label label-info">Nouveaux champs</label>';
$formMapper
->tab('Table de correspondance des champs')
->tab($title)
->with('Transformer les données à importer')
->add('ontologyMapping', 'hidden', array('attr' => ['class' => 'gogo-mapping-ontology', 'data-form-props' => $formProperties, 'data-props' => $elementProperties]))
->end()
->end();
if (count($this->getSubject()->getOntologyMapping()) > 0)
{
$formMapper->tab('Table de correspondance des catégories')
$title = 'Table de correspondance des catégories';
if ($this->getSubject()->getNewTaxonomyToMap()) $title .= ' <label class="label label-info">Nouvelles catégories</label>';
$formMapper->tab($title)
->with('Faites correspondre les catégories')
->add('taxonomyMapping', 'hidden', array('attr' => ['class' => 'gogo-mapping-taxonomy', 'data-options' => $optionsList]))
->end()
......
......@@ -94,6 +94,8 @@ class ImportAdminController extends Controller
// ----- CUSTOM -------
$object->setOntologyMapping($request->get('ontology'));
$object->setTaxonomyMapping($request->get('taxonomy'));
$object->setNewOntologyToMap(false);
$object->setNewTaxonomyToMap(false);
// ---- END CUSTOM ------
......
......@@ -119,11 +119,21 @@ class Import extends AbstractFile
*/
private $ontologyMapping = [];
/**
* @MongoDB\Field(type="bool")
*/
private $newOntologyToMap = false;
/**
* @MongoDB\Field(type="hash")
*/
private $taxonomyMapping = [];
/**
* @MongoDB\Field(type="bool")
*/
private $newTaxonomyToMap = false;
/**
* Custom code made by the user to be run on the $data object when importing
* @MongoDB\Field(type="string")
......@@ -581,4 +591,48 @@ class Import extends AbstractFile
{
return $this->createdAt;
}
/**
* Set newOntologyToMap
*
* @param bool $newOntologyToMap
* @return $this
*/
public function setNewOntologyToMap($newOntologyToMap)
{
$this->newOntologyToMap = $newOntologyToMap;
return $this;
}
/**
* Get newOntologyToMap
*
* @return bool $newOntologyToMap
*/
public function getNewOntologyToMap()
{
return $this->newOntologyToMap;
}
/**
* Set newTaxonomyToMap
*
* @param bool $newTaxonomyToMap
* @return $this
*/
public function setNewTaxonomyToMap($newTaxonomyToMap)
{
$this->newTaxonomyToMap = $newTaxonomyToMap;
return $this;
}
/**
* Get newTaxonomyToMap
*
* @return bool $newTaxonomyToMap
*/
public function getNewTaxonomyToMap()
{
return $this->newTaxonomyToMap;
}
}
......@@ -8,7 +8,7 @@
<div class="nav-tabs-custom">
<ul class="nav nav-tabs" role="tablist">
{% for name, form_tab in admin.formtabs %}
<li{% if loop.index == 1 %} class="tab-first"{% endif %}><a href="#tab_{{ loop.index }}" data-toggle="tab"><i class="fa fa-exclamation-circle has-errors hide" aria-hidden="true"></i> {{ name|trans({}, form_tab.translation_domain ?: admin.translationDomain) }}</a></li>
<li{% if loop.index == 1 %} class="tab-first"{% endif %}><a href="#tab_{{ loop.index }}" data-toggle="tab"><i class="fa fa-exclamation-circle has-errors hide" aria-hidden="true"></i> {{ name|trans({}, form_tab.translation_domain ?: admin.translationDomain)|raw }}</a></li>
{% endfor %}
</ul>
<div class="tab-content">
......@@ -35,9 +35,9 @@
<script>
$(document).ready(function() {
$('.nav-tabs li a').click(function() {
$('.nav-tabs li a').click(function() {
var newHash = $(this).attr('href');
window.location.hash = newHash;
window.location.hash = newHash;
var url = $('form').attr('action');
$('form').attr('action', url.split('#')[0] + newHash);
});
......@@ -48,7 +48,7 @@
} else {
$('li.tab-first').addClass('active');
}
});
</script>
{% endblock %}
\ No newline at end of file
......@@ -2,15 +2,23 @@
{% block field %}
{% spaceless %}
{% if object.newOntologyToMap %}
<span class="label label-info log-label">Nouveaux champs à mapper</span>
{% endif %}
{% if object.newTaxonomyToMap %}
<span class="label label-info log-label">Nouvelles caatégories à mapper</span>
{% endif %}
{% set deletedCount = field_description.options.choices[object.id] is defined ? field_description.options.choices[object.id] : 0 %}
{% if deletedCount > 0 %}
<span class="label label-danger log-label">{{ deletedCount }} localement supprimés</span>
{% endif %}
{% endif %}
{% if object.logs|length > 0 %}
{% set log = object.logs[0] %}
{% if log.getDataProp('elementsMissingGeoCount') > 0 %}
<span class="label label-warning log-label">{{ log.getDataProp('elementsMissingGeoCount') }} sans geoloc</span>
{% endif %}
{% endif %}
{% if log.getDataProp('elementsMissingTaxoCount') > 0 %}
<span class="label label-warning log-label">{{ log.getDataProp('elementsMissingTaxoCount') }} sans categories</span>
{% endif %}
......
......@@ -115,9 +115,9 @@ class ElementImportMappingService
foreach($data as $row)
{
foreach ($row as $key => $value) {
$this->collectKey($key);
$this->collectKey($key, null, $import);
if ($this->isAssociativeArray($value) && !in_array($key, ['openHours', 'modifiedElement'])) {
foreach ($value as $subkey => $subvalue) { $this->collectKey($subkey, $key); }
foreach ($value as $subkey => $subvalue) { $this->collectKey($subkey, $key, $import); }
}
}
}
......@@ -129,7 +129,7 @@ class ElementImportMappingService
$import->setOntologyMapping($this->ontologyMapping);
}
private function collectKey($key, $parentKey = null) {
private function collectKey($key, $parentKey = null, $import) {
if (in_array($key, ['__initializer__', '__cloner__', '__isInitialized__'])) return;
$keyName = $parentKey ? $parentKey . '/' . $key : $key;
if (!$keyName || strlen($keyName) == 0) return;
......@@ -142,7 +142,10 @@ class ElementImportMappingService
$value = $this->mappedCoreFields[$keyLower];
// Asign mapping
if (!$value || !in_array($value, array_values($this->ontologyMapping)))
{
$this->ontologyMapping[$keyName] = $value;
$import->setNewOntologyToMap(true);
}
}
}
......@@ -176,6 +179,7 @@ class ElementImportMappingService
if ($value == '' && $this->createMissingOptions) $value = $this->createOption($category);
$taxonomyMapping[$category] = $value;
$import->setNewTaxonomyToMap(true);
}
// create options for previously imported non mapped options
if (array_key_exists($category, $taxonomyMapping)
......
......@@ -197,7 +197,7 @@ class ElementImportOneService
private function createOpenHours($element, $row)
{
if (!isset($row['openhours']) || !$this->isAssociativeArray($row['openhours'])) return;
$element->setOpenHours(new OpenHours($row['openHours']));
$element->setOpenHours(new OpenHours($row['openhours']));
}
private function isAssociativeArray($a) {
......
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