Commit c2189701 authored by Sebastian Castro's avatar Sebastian Castro

Element import: use lower case to map with core fields

parent 21eb6cf7
......@@ -48,24 +48,24 @@
var formProperties = {{ form.vars.attr["data-form-props"]|raw }};
var dataProperties = {{ form.vars.attr["data-props"]|raw }};
var coreFields = ['id', 'name', 'categories', 'streetAddress', 'addressLocality', 'postalCode', 'addressCountry', 'latitude', 'longitude', 'images', 'owner', 'source']
var coreFields = ['id', 'name', 'categories', 'streetaddress', 'addresslocality', 'postalcode', 'addresscountry', 'latitude', 'longitude', 'images', 'owner', 'source']
var coreData = [], allProperties = [], otherData = []; var importedData = [];
coreData.push({id: 'id', text: 'Identifiant unique'});
coreData.push({id: 'name', text: 'Titre de la fiche'});
coreData.push({id: 'categories', text: 'Liste des catégories (en tableau ou séparées par des virgules)'});
coreData.push({id: 'fullAddress', text: 'Adresse complète'});
coreData.push({id: 'streetNumber', text: 'Adresse: numéro de rue'});
coreData.push({id: 'streetAddress', text: 'Adresse: rue'});
coreData.push({id: 'addressLocality', text: 'Adresse: ville'});
coreData.push({id: 'postalCode', text: 'Adresse: code postal'});
coreData.push({id: 'addressCountry', text: 'Adresse: pays'});
coreData.push({id: 'fulladdress', text: 'Adresse complète'});
coreData.push({id: 'streetnumber', text: 'Adresse: numéro de rue'});
coreData.push({id: 'streetaddress', text: 'Adresse: rue'});
coreData.push({id: 'addresslocality', text: 'Adresse: ville'});
coreData.push({id: 'postalcode', text: 'Adresse: code postal'});
coreData.push({id: 'addresscountry', text: 'Adresse: pays'});
coreData.push({id: 'latitude', text: 'Latitude'});
coreData.push({id: 'longitude', text: 'Longitude'});
coreData.push({id: 'images', text: "Image(s) sous forme d'url, en tableau, ou séparés par des virgules"});
coreData.push({id: 'email', text: "Email de l'élement"});
coreData.push({id: 'owner', text: "Email de l'utilisateur propriétaire de la fiche"});
coreData.push({id: 'source', text: "Origine de l'élément (source)"});
coreData.push({id: 'openHours', text: "Horaire d'ouvertues (format GoGoCarto)"});
coreData.push({id: 'openhours', text: "Horaire d'ouvertues (format GoGoCarto)"});
allProperties = $.map(coreData, function(el) { return el.id });
......
......@@ -27,14 +27,14 @@ class ElementImportMappingService
protected $em;
protected $ontologyMapping;
protected $allNewFields;
protected $coreFields = ['id', 'name', 'categories', 'streetAddress', 'addressLocality', 'postalCode', 'addressCountry', 'latitude', 'longitude', 'images', 'owner', 'source', 'openHours'];
protected $coreFields = ['id', 'name', 'categories', 'streetaddress', 'addresslocality', 'postalcode', 'addresscountry', 'latitude', 'longitude', 'images', 'owner', 'source', 'openhours'];
protected $mappedCoreFields = [
'title' => 'name', 'nom' => 'name',
'taxonomy' => 'categories',
'address' => 'streetAddress',
'city' => 'addressLocatily',
'postcode' => 'postalCode',
'country' => 'addressCountry',
'address' => 'streetaddress',
'city' => 'addresslocatily',
'postcode' => 'postalcode',
'country' => 'addresscountry',
'lat' => 'latitude',
'long' => 'longitude', 'lng' => 'longitude', 'lon' => 'longitude'
];
......@@ -134,10 +134,14 @@ class ElementImportMappingService
$keyName = $parentKey ? $parentKey . '/' . $key : $key;
if (!in_array($keyName, $this->allNewFields)) $this->allNewFields[] = $keyName;
if (!array_key_exists($keyName, $this->ontologyMapping)) {
$value = in_array($keyName, $this->coreFields) ? $key : "";
if (!$value && array_key_exists($key, $this->mappedCoreFields) && in_array($this->mappedCoreFields[$key], $this->coreFields))
$value = $this->mappedCoreFields[$key];
if (!$value || !in_array($value, array_values($this->ontologyMapping))) $this->ontologyMapping[$keyName] = $value;
$keyLower = str_replace('_', '', strtolower($key));
$value = in_array($keyLower, $this->coreFields) ? $keyLower : "";
// use alternative name, like lat instead of latitude
if (!$value && array_key_exists($keyLower, $this->mappedCoreFields) && in_array($this->mappedCoreFields[$keyLower], $this->coreFields))
$value = $this->mappedCoreFields[$keyLower];
// Asign mapping
if (!$value || !in_array($value, array_values($this->ontologyMapping)))
$this->ontologyMapping[$keyName] = $value;
}
}
......
......@@ -22,7 +22,7 @@ class ElementImportOneService
protected $optionIdsToAddToEachElement = [];
protected $coreFields = ['id', 'name', 'categories', 'streetAddress', 'addressLocality', 'postalCode', 'addressCountry', 'latitude', 'longitude', 'images', 'owner', 'source', 'openHours'];
protected $coreFields = ['id', 'name', 'categories', 'streetaddress', 'addresslocality', 'postalcode', 'addresscountry', 'latitude', 'longitude', 'images', 'owner', 'source', 'openhours'];
protected $privateDataProps;
/**
......@@ -100,7 +100,7 @@ class ElementImportOneService
$element->setOldId($row['id']);
$element->setName($row['name']);
$address = new PostalAddress($row['streetAddress'], $row['addressLocality'], $row['postalCode'], $row["addressCountry"]);
$address = new PostalAddress($row['streetaddress'], $row['addresslocality'], $row['postalcode'], $row["addresscountry"]);
$element->setAddress($address);
$defaultSourceName = $import ? $import->getSourceName() : 'Inconnu';
......@@ -196,7 +196,7 @@ class ElementImportOneService
private function createOpenHours($element, $row)
{
if (!isset($row['openHours']) || !$this->isAssociativeArray($row['openHours'])) return;
if (!isset($row['openhours']) || !$this->isAssociativeArray($row['openhours'])) return;
$element->setOpenHours(new OpenHours($row['openHours']));
}
......
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