Commit 3edcd00c by Frédéric

Field Mapping

parent dc7a6ad6
tourinsoft:
url: 'http://wcf.tourinsoft.com/Syndication/3.0/'
ot_key: 'cdt64'
ot_key: ''
cdn_url: ''
field_mapping:
SyndicObjectID:
label: Identifiant de l'offre
Published:
label: Date de création de l’offre
Updated:
label: Date de mise à jour de l’offre
SyndicObjectName:
label: Le nom de l’offre touristique
SyndicStructureId:
label: Identifiant de la structure
GmapLatitude:
label: Coordonnées Latitude google map
GmapLongitude:
label: Coordonnées Longitude google map
ObjectTypeFix:
label: Identifiant du bordereau
ObjectTypeName:
label: Nom du bordereau
SyndicObjectOrder:
label: Ordre d’affichage
ACCES:
label: Point d'accès
ACCESHANDI:
label: Accessible aux personnes à mobilité réduite
AD1:
label: Adresse 1
AD1SUITE:
label: Adresse 1 suite
AD2:
label: Adresse 2
AD3:
label: Adresse 3
COMMUNE:
label: Commune touristique
COMMUNEINSEE:
label: INSEE Commune
CP:
label: Code Postal
DESCRIPTIF:
label: Description commerciale
FACEBOOK:
label: Facebook
FICHIER:
label: Fichier
FICHIER_NOM:
label: Fichier
FLICKR:
label: Flickr URL de la Galerie
GOOGLE_AD:
label: Google Adresses
LANG_PARLE:
label: Langues parlées
LAT:
label: Latitude
LOCALISATION:
label: Type de localisation
LON:
label: Longitude
MAILCOMPLET:
label: Coordonnées Télécom
NOM_OFFRE:
label: Raison sociale
OUVERTURE:
label: Ouverture
OUVERTURECOMPLETAVECJOURS:
label: Ouverture avec jours
PHOTO:
label: Photo
PHOTOCOMPLET:
label: Photo complet
QRCODE:
label: QR Code
TEL_COMPLET:
label: Téléphone
TEL_MOB_COMPLET:
label: Téléphone mobile
TWITTER:
label: Twitter
TYPE:
label: Type de commerces et services
VIDEO_CODE:
label: Code de la vidéo
VIDEO_URL:
label: URL vidéo
VISITE_VIRT:
label: Visite virtuelle
......@@ -6,6 +6,7 @@ use Bolt\Application;
use Bolt\Extension\Appolo\Tourinsoft\Storage\Entity\Flux;
use Bolt\Extension\Appolo\Tourinsoft\Utils\ContentTypeFile;
use Bolt\Extension\Appolo\Tourinsoft\Utils\Parser;
use Bolt\Extension\Appolo\Tourinsoft\Utils\Schema;
class Synchronisation
{
......@@ -23,7 +24,7 @@ class Synchronisation
private $application;
/**
* TourinsoftParser constructor.
* Synchornisation constructor.
* @param array $config
* @param Flux $flux
* @throws \Exception
......@@ -44,18 +45,30 @@ class Synchronisation
public function sync() {
$options = $this->config['tourinsoft'];
$options['key'] = $this->flux->getKey();
// Parse tourinsoft flux
$parser = new Parser($options);
$keys = $parser->getKeys();
$file = new ContentTypeFile($this->application, $this->flux->getContentType(), $keys);
// Write in contenttypes.yml file
$file = new ContentTypeFile($this->application, $this->flux->getContentType(), $keys, $options);
$file->updateInFile();
// Sync database
$schema = new Schema($this->application);
$schema->update();
}
/**
*
*/
public function delete() {
// Write in contenttypes.yml file
$file = new ContentTypeFile($this->application, $this->flux->getContentType(), []);
$file->deleteInFile();
// Sync database
$schema = new Schema($this->application);
$schema->update();
}
}
\ No newline at end of file
......@@ -20,15 +20,20 @@ class ContentTypeFile
* @var Application
*/
private $application;
/**
* @var array
*/
private $options;
/**
* ContentTypeFile constructor.
* @param Application $application
* @param string $contentType
* @param array $keys
* @param array $options
* @throws \Exception
*/
public function __construct(Application $application, $contentType = '', array $keys = [])
public function __construct(Application $application, $contentType = '', array $keys = [], array $options = [])
{
if(empty($contentType)) {
throw new \Exception('Le content type est requis.');
......@@ -36,6 +41,7 @@ class ContentTypeFile
$this->contentType = $contentType;
$this->keys = $keys;
$this->application = $application;
$this->options = $options;
}
/**
......@@ -68,7 +74,10 @@ class ContentTypeFile
$fields = [];
foreach ($this->keys as $key) {
$fields[$key] = ['type' => 'text'];
$fields[$key] = [
'type' => 'text',
'label' => $this->getFieldLabel($key)
];
}
$fields['slug'] = [
......@@ -93,11 +102,30 @@ class ContentTypeFile
if($delete) {
unset($yamlData[$this->contentType]);
} else {
if(!empty($yamlData[$this->contentType])) {
unset($yamlData[$this->contentType]);
}
$yamlData += $data;
}
$file->dump($yamlData, ['inline' => 4]);
}
}
/**
* @param $key
* @return mixed
*/
private function getFieldLabel($key) {
if(
empty($this->options) ||
empty($this->options['field_mapping']) ||
empty($this->options['field_mapping'][$key]) ||
empty($this->options['field_mapping'][$key]['label'])
) {
return $key;
}
return $this->options['field_mapping'][$key]['label'];
}
}
\ No newline at end of file
......@@ -2,7 +2,26 @@
namespace Bolt\Extension\Appolo\Tourinsoft\Utils;
use Bolt\Application;
class Schema
{
/**
* @var Application
*/
private $application;
/**
* Schema constructor.
* @param Application $application
*/
public function __construct(Application $application)
{
$this->application = $application;
}
public function update() {
$output = $this->application['schema']->update();
$this->application['session']->set('dbupdate_result', $output->getResponseStrings());
}
}
\ No newline at end of file
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