From 12762a96f10d198f7558280d3b8d99729ba1efe1 Mon Sep 17 00:00:00 2001 From: Sebastian Castro <sebastian.castro@protonmail.com> Date: Sat, 3 Aug 2019 16:58:04 +0200 Subject: [PATCH] Import: detect new ontology and new taxonomy and alert user --- .../GeoDirectoryBundle/Admin/ImportAdmin.php | 8 ++- .../Admin/ImportAdminController.php | 2 + .../GeoDirectoryBundle/Document/Import.php | 54 +++++++++++++++++++ .../admin/core_custom/base_edit.html.twig | 8 +-- .../import/list_non_visibles_count.html.twig | 12 ++++- .../Services/ElementImportMappingService.php | 10 ++-- .../Services/ElementImportOneService.php | 2 +- 7 files changed, 84 insertions(+), 12 deletions(-) diff --git a/src/Biopen/GeoDirectoryBundle/Admin/ImportAdmin.php b/src/Biopen/GeoDirectoryBundle/Admin/ImportAdmin.php index fa766bef1..268abfb24 100755 --- a/src/Biopen/GeoDirectoryBundle/Admin/ImportAdmin.php +++ b/src/Biopen/GeoDirectoryBundle/Admin/ImportAdmin.php @@ -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() diff --git a/src/Biopen/GeoDirectoryBundle/Controller/Admin/ImportAdminController.php b/src/Biopen/GeoDirectoryBundle/Controller/Admin/ImportAdminController.php index d8896a788..8c2a1d4c9 100755 --- a/src/Biopen/GeoDirectoryBundle/Controller/Admin/ImportAdminController.php +++ b/src/Biopen/GeoDirectoryBundle/Controller/Admin/ImportAdminController.php @@ -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 ------ diff --git a/src/Biopen/GeoDirectoryBundle/Document/Import.php b/src/Biopen/GeoDirectoryBundle/Document/Import.php index f8532e1e2..12dc5bd6f 100644 --- a/src/Biopen/GeoDirectoryBundle/Document/Import.php +++ b/src/Biopen/GeoDirectoryBundle/Document/Import.php @@ -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; + } } diff --git a/src/Biopen/GeoDirectoryBundle/Resources/views/admin/core_custom/base_edit.html.twig b/src/Biopen/GeoDirectoryBundle/Resources/views/admin/core_custom/base_edit.html.twig index 247cbf310..b4ffcc7d9 100644 --- a/src/Biopen/GeoDirectoryBundle/Resources/views/admin/core_custom/base_edit.html.twig +++ b/src/Biopen/GeoDirectoryBundle/Resources/views/admin/core_custom/base_edit.html.twig @@ -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 diff --git a/src/Biopen/GeoDirectoryBundle/Resources/views/admin/partials/import/list_non_visibles_count.html.twig b/src/Biopen/GeoDirectoryBundle/Resources/views/admin/partials/import/list_non_visibles_count.html.twig index 437c50e6a..4825ff82c 100644 --- a/src/Biopen/GeoDirectoryBundle/Resources/views/admin/partials/import/list_non_visibles_count.html.twig +++ b/src/Biopen/GeoDirectoryBundle/Resources/views/admin/partials/import/list_non_visibles_count.html.twig @@ -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 %} diff --git a/src/Biopen/GeoDirectoryBundle/Services/ElementImportMappingService.php b/src/Biopen/GeoDirectoryBundle/Services/ElementImportMappingService.php index 2ced41106..42499334d 100644 --- a/src/Biopen/GeoDirectoryBundle/Services/ElementImportMappingService.php +++ b/src/Biopen/GeoDirectoryBundle/Services/ElementImportMappingService.php @@ -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) diff --git a/src/Biopen/GeoDirectoryBundle/Services/ElementImportOneService.php b/src/Biopen/GeoDirectoryBundle/Services/ElementImportOneService.php index f3c62cf4b..8e83f00fa 100755 --- a/src/Biopen/GeoDirectoryBundle/Services/ElementImportOneService.php +++ b/src/Biopen/GeoDirectoryBundle/Services/ElementImportOneService.php @@ -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) { -- GitLab