Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 3395 → Rev 3401

/branches/v2.28-semoir/jrest/services/CelWidgetManager.php
25,15 → 25,49
 
class CelWidgetManager extends Cel {
 
// certains paramètres apparaissent plusieurs fois car ils ont des alias
// dans certains widgets
// correspondance entre les champs de l'interface et les champs de la BD (format 2018 / 2019)
private $parametres_autorises = array(
'projet' => 'projet',
'type' => 'type',
'esttype' => 'est_type',
'langue' => 'langue',
'order' => 'order'
'projet' => 'project',
'type' => 'type',
'esttype' => 'istype',
'langue' => 'language',
'order' => 'order'
);
private $correspondance_config_widget= array(
'projet' => 'project',
'langue' => 'language',
'titre' => 'title',
'logo' => 'logo',
'description' => 'description',
'type' => 'type',
'est_type' => 'is_type',
'style_css' => 'css_style',
'image_fond' => 'image_font',
'date_creation' => 'date_created',
'type_especes' => 'taxo_restriction_type',
'referentiel' => 'taxo_restriction_value',
'type_localisation' => 'location_type',
'localisation' => 'location',
'milieux' => 'environments',
'motscles' => 'project_tag_name',
'info' => 'info'
);
private $correspondance_champs_etendus = array(
"key" => "field_id",
"element" => "data_type",
"mandatory" => "is_mandatory",
"unit" => "unit"
);
private $correspondance_champs_etendus_trad = array(
"key" => "extended_field_id",
"name" => "label",
"description" => "description",
"fieldValues" => "default_value",
"help" => "help"
);
 
public function getRessource() {
return $this->getElement(array());
43,12 → 77,13
* Méthode appelée avec une requête de type GET.
*/
public function getElement($params = array()) {
switch(@strtolower($params[0])) {
switch(@strtolower($params[0])) {
case 'widget':
$this->getWidget();
break;
 
 
case 'champsetendus';
$this->getChampsEtendus();
break;
default:
$this->getWidget();
}
57,9 → 92,17
public function createElement($requeteDonnees) {
unset($requeteDonnees['signup_submit']);
$requeteDonnees['est_type'] = (isset($requeteDonnees['est_type']) && $requeteDonnees['est_type']== "on") ? '1' : '0';
if (isset($requeteDonnees['champs-supp'])) {
$gestionchamps = new GestionChampsEtendus2($this->config);
$champs = $this->traiterCorrespondanceChampsEtendusInterfaceBD($requeteDonnees); //var_dump($champs);exit;
$liste = $gestionchamps->ajouterParProjet($champs);
unset($requeteDonnees['champs-supp']);
}
$requeteDonnees['est_type'] = (isset($requeteDonnees['est_type']) && $requeteDonnees['est_type']== "on") ? 1 : 0;
$manager = new GestionWidget($this->config);
$requeteDonnees = $this->traiterCorresponceConfigWidgetInterfaceBD($requeteDonnees);
$retour = $manager->ajouterWidget($requeteDonnees);
 
$this->envoyerJson($retour);
 
}
67,9 → 110,10
public function updateElement($uid,$params) {
$retour = "";
if (isset($params['projet']) && isset($params['langue'])) {
$manager = new GestionWidget($this->config);
$params['est_type'] = (isset($params['est_type']) && $params['est_type']== "on") ? '1' : '0';
$retour = $manager->modifierWidget($params['projet'], $params['langue'], $params);
$manager = new GestionWidget($this->config);
$params['est_type'] = (isset($params['est_type']) && $params['est_type']== "on") ? 1 : 0;
$requeteDonnees = $this->traiterCorresponceConfigWidgetInterfaceBD($params);
$retour = $manager->modifierWidget($params['projet'], $params['langue'], $requeteDonnees);
}
$this->envoyerJson($retour);
78,13 → 122,23
}
 
private function getWidget() {
$criteres = $this->traiterParametresAutorises($_GET);
$criteres = $this->traiterParametresAutorises($_GET);
$manager = new GestionWidget($this->config);
$liste = $manager->obtenirWidget($criteres);
$liste = $this->traiterCorresponceConfigWidgetBDInterface($liste);
 
$this->envoyerJson($liste);
}
private function getChampsEtendus() {
$champs = new GestionChampsEtendus2($this->config);
$projet = (isset($_GET['projet'])) ? $_GET['projet'] : "";
$langue = (isset($_GET['langue'])) ? $_GET['langue'] : "fr";
$liste = $champs->consulterProjetChampsEtendus($projet, $langue);
$liste = $this->traiterCorrespondanceChampsEtendusBDInterface($liste);
$this->envoyerJson($liste);
}
 
 
protected function traiterParametresAutorises(Array $parametres) {
98,6 → 152,90
}
return $parametres_traites;
}
protected function traiterCorresponceConfigWidgetBDInterface(Array $widgets) {
$parametres_traites = array();
$corresp = array_flip($this->correspondance_config_widget);
foreach($widgets as $id => $widget) {
foreach($widget as $cle => $valeur) {
if(is_string($valeur) && !trim($valeur)) continue;
if(isset($corresp[$cle])) {
$parametres_traites[$id][$corresp[$cle]] = $valeur;
}
}
}
return $parametres_traites;
}
protected function traiterCorresponceConfigWidgetInterfaceBD(Array $parametres) {
$parametres_traites = array();
$corresp = $this->correspondance_config_widget;
foreach($parametres as $cle => $valeur) {
if(is_string($valeur) && !trim($valeur)) $valeur=NULL;
if(isset($corresp[$cle])) {
$parametres_traites[$corresp[$cle]] = $valeur;
}
}
return $parametres_traites;
}
protected function traiterCorrespondanceChampsEtendusInterfaceBD(Array $champsinterface) {
$champsrequete = array(); $i = 0;
$champssupp = json_decode($champsinterface['champs-supp'], true);
// pour chaque champs-supp, mettre correspondance extended field et extended field trad
foreach ($champssupp as $champ) {
$champsrequete['ce'][$i]['project'] = $champsrequete['cet'][$i]['project'] = $champsinterface['projet'];
$champsrequete['cet'][$i]['language_iso_code'] = $champsinterface['langue'];
// pour la table extended fiels champs interface => champs bd
foreach ($this->correspondance_champs_etendus as $ci => $ce) {
if (isset($champ[$ci]) && $champ[$ci] != "") {
$champsrequete['ce'][$i][$ce] = $champ[$ci];
} else {
if ($ci == "mandatory") {
$champsrequete['ce'][$i][$ce] = "0";
} else {
$champsrequete['ce'][$i][$ce] = "";
}
}
}
// pour la table extended fiels trad champs interface => champs bd
foreach ($this->correspondance_champs_etendus_trad as $cit => $cr) {
if (isset($champ[$cit]) && is_array($champ[$cit])) {
$champsrequete['cet'][$i][$cr] = json_encode($champ[$cit]);
} elseif (isset($champ[$cit]) && $champ[$cit] != "") {
$champsrequete['cet'][$i][$cr] = $champ[$cit];
} else {
$champsrequete['cet'][$i][$cr] = "";
}
}
$i++;
}
return $champsrequete;
}
protected function traiterCorrespondanceChampsEtendusBDInterface(Array $champsrequete) {
$champssupp = array(); $i = 0;
foreach ($champsrequete as $champ) {
$champssupp[$champ['project']]['projet'] = $champ['project'];
$champssupp[$champ['project']]['langue'] = $champ['language_iso_code'];
// pour la table extended fiels champs interface => champs bd
foreach ($this->correspondance_champs_etendus as $ci => $ce) {
if (isset($champ[$ce]) && $champ[$ce] != "") {
$champssupp[$champ['project']]['champs-supp'][$i][$ci] = $champ[$ce];
} else {
$champssupp[$champ['project']]['champs-supp'][$i][$ci]= "";
}
}
// pour la table extended fiels trad champs interface => champs bd
foreach ($this->correspondance_champs_etendus_trad as $cet => $cr) {
if (isset($champ[$cr]) && $champ[$cr] != "") {
$champssupp[$champ['project']]['champs-supp'][$i][$cet]= $champ[$cr];
} else {
$champssupp[$champ['project']]['champs-supp'][$i][$cet]="";
}
}$i++;
}
return $champssupp;
}
 
 
}
/branches/v2.28-semoir/jrest/services/CelWidgetSaisie.php
117,6 → 117,9
$obsAAjouter['date_observation'] = $this->transormerDateFrVersMysql($obs['date']);
$obsAAjouter['commentaire'] = isset($obs['notes']) ? $obs['notes'] : null;
 
// Pays est pour le moment sur un varchar(2) dans la base
// alors qu'il est envoyé complet par le script WidgetSaisie
$obsAAjouter['pays'] = $obs['pays'];
$obsAAjouter['zone_geo'] = $obs['commune_nom'];
$obsAAjouter['ce_zone_geo'] = 'INSEE-C:'. (isset($obs['commune_code_insee']) ? $obs['commune_code_insee'] : '');
$obsAAjouter['lieudit'] = isset($obs['lieudit']) ? $obs['lieudit'] : null;
464,7 → 467,7
$cle = isset($infosChamp['cle']) ? $infosChamp['cle'] : '';
$valeur = isset($infosChamp['valeur']) ? $infosChamp['valeur'] : '';
 
if (!empty($cle) && !empty($valeur)) {
if (!empty($cle) && $valeur !== '') {
$champEtendu = new ChampEtendu();
$champEtendu->id = $id_obs;
$champEtendu->cle = $cle;
772,7 → 775,7
*/
protected function nettoyerImagesUploades($nomsDeFichiers=false) {
// mode de suppression
$suppressionParNom = (is_array($nomsDeFichiers) && count($nomsDeFichiers > 0));
$suppressionParNom = (is_array($nomsDeFichiers) && count($nomsDeFichiers) > 0);
 
$dossierStockage = $this->config['cel']['chemin_stockage_temp'].'/';
if (is_dir($dossierStockage)) {