3092 |
delphine |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Service fournissant des informations sur les widgets existants et permettant d'en créer d'autres.
|
|
|
5 |
*
|
|
|
6 |
* Format du service :
|
|
|
7 |
* /CelWidgetExport/format
|
|
|
8 |
* /CelWidgetExport/csv
|
|
|
9 |
*
|
|
|
10 |
* Les paramêtres :
|
|
|
11 |
* - "start" indique le numéro du premier item à afficher
|
|
|
12 |
* - "limit" nombre d'items à afficher
|
|
|
13 |
*
|
|
|
14 |
* @internal Mininum PHP version : 5.2
|
|
|
15 |
* @category CEL
|
|
|
16 |
* @package Services
|
|
|
17 |
* @subpackage Widget
|
|
|
18 |
* @version 0.1
|
|
|
19 |
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
|
|
|
20 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
21 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
22 |
* @copyright 1999-2017 Tela Botanica <accueil@tela-botanica.org>
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
class CelWidgetManager extends Cel {
|
|
|
27 |
|
3193 |
delphine |
28 |
// correspondance entre les champs de l'interface et les champs de la BD (format 2018 / 2019)
|
3092 |
delphine |
29 |
private $parametres_autorises = array(
|
3193 |
delphine |
30 |
'projet' => 'project',
|
|
|
31 |
'type' => 'type',
|
3486 |
delphine |
32 |
'esttype' => 'is_type',
|
3193 |
delphine |
33 |
'langue' => 'language',
|
|
|
34 |
'order' => 'order'
|
3092 |
delphine |
35 |
);
|
3193 |
delphine |
36 |
|
|
|
37 |
private $correspondance_config_widget= array(
|
|
|
38 |
'projet' => 'project',
|
|
|
39 |
'langue' => 'language',
|
|
|
40 |
'titre' => 'title',
|
|
|
41 |
'logo' => 'logo',
|
|
|
42 |
'description' => 'description',
|
|
|
43 |
'type' => 'type',
|
|
|
44 |
'est_type' => 'is_type',
|
|
|
45 |
'style_css' => 'css_style',
|
|
|
46 |
'image_fond' => 'image_font',
|
|
|
47 |
'date_creation' => 'date_created',
|
|
|
48 |
'type_especes' => 'taxo_restriction_type',
|
|
|
49 |
'referentiel' => 'taxo_restriction_value',
|
|
|
50 |
'type_localisation' => 'location_type',
|
|
|
51 |
'localisation' => 'location',
|
3875 |
delphine |
52 |
'fond_carte' => 'basemap',
|
3876 |
delphine |
53 |
'adresse' => 'is_mandatory_address',
|
3875 |
delphine |
54 |
'photo_obligatoire' => 'is_mandatory_photo',
|
3517 |
delphine |
55 |
'milieux' => 'environment',
|
3216 |
delphine |
56 |
'motscles' => 'project_tag_name',
|
3531 |
delphine |
57 |
'info' => 'info',
|
|
|
58 |
'id_projet' => 'project_id'
|
3193 |
delphine |
59 |
);
|
|
|
60 |
|
|
|
61 |
private $correspondance_champs_etendus = array(
|
|
|
62 |
"key" => "field_id",
|
|
|
63 |
"element" => "data_type",
|
|
|
64 |
"mandatory" => "is_mandatory",
|
|
|
65 |
"unit" => "unit"
|
|
|
66 |
);
|
|
|
67 |
|
|
|
68 |
private $correspondance_champs_etendus_trad = array(
|
|
|
69 |
"key" => "extended_field_id",
|
|
|
70 |
"name" => "label",
|
|
|
71 |
"description" => "description",
|
3216 |
delphine |
72 |
"fieldValues" => "default_value",
|
|
|
73 |
"help" => "help"
|
3193 |
delphine |
74 |
);
|
3092 |
delphine |
75 |
|
|
|
76 |
public function getRessource() {
|
|
|
77 |
return $this->getElement(array());
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* Méthode appelée avec une requête de type GET.
|
|
|
82 |
*/
|
3193 |
delphine |
83 |
public function getElement($params = array()) {
|
|
|
84 |
switch(@strtolower($params[0])) {
|
3092 |
delphine |
85 |
case 'widget':
|
|
|
86 |
$this->getWidget();
|
|
|
87 |
break;
|
3193 |
delphine |
88 |
case 'champsetendus';
|
|
|
89 |
$this->getChampsEtendus();
|
|
|
90 |
break;
|
3092 |
delphine |
91 |
default:
|
|
|
92 |
$this->getWidget();
|
|
|
93 |
}
|
|
|
94 |
}
|
3193 |
delphine |
95 |
|
|
|
96 |
|
3092 |
delphine |
97 |
public function createElement($requeteDonnees) {
|
|
|
98 |
unset($requeteDonnees['signup_submit']);
|
3193 |
delphine |
99 |
if (isset($requeteDonnees['champs-supp'])) {
|
|
|
100 |
$gestionchamps = new GestionChampsEtendus2($this->config);
|
|
|
101 |
$champs = $this->traiterCorrespondanceChampsEtendusInterfaceBD($requeteDonnees); //var_dump($champs);exit;
|
|
|
102 |
$liste = $gestionchamps->ajouterParProjet($champs);
|
|
|
103 |
unset($requeteDonnees['champs-supp']);
|
|
|
104 |
}
|
3283 |
delphine |
105 |
$requeteDonnees['est_type'] = (isset($requeteDonnees['est_type']) && $requeteDonnees['est_type']== "on") ? 1 : 0;
|
3092 |
delphine |
106 |
$manager = new GestionWidget($this->config);
|
3193 |
delphine |
107 |
$requeteDonnees = $this->traiterCorresponceConfigWidgetInterfaceBD($requeteDonnees);
|
3092 |
delphine |
108 |
$retour = $manager->ajouterWidget($requeteDonnees);
|
3193 |
delphine |
109 |
|
3092 |
delphine |
110 |
$this->envoyerJson($retour);
|
|
|
111 |
|
|
|
112 |
}
|
3193 |
delphine |
113 |
|
3121 |
delphine |
114 |
public function updateElement($uid,$params) {
|
|
|
115 |
$retour = "";
|
|
|
116 |
if (isset($params['projet']) && isset($params['langue'])) {
|
3883 |
delphine |
117 |
if (isset($requeteDonnees['champs-supp'])) {
|
|
|
118 |
$gestionchamps = new GestionChampsEtendus2($this->config);
|
|
|
119 |
$champs = $this->traiterCorrespondanceChampsEtendusInterfaceBD($requeteDonnees); //var_dump($champs);exit;
|
|
|
120 |
$liste = $gestionchamps->modifierParProjet($champs);
|
|
|
121 |
unset($requeteDonnees['champs-supp']);
|
|
|
122 |
}
|
3283 |
delphine |
123 |
$manager = new GestionWidget($this->config);
|
|
|
124 |
$params['est_type'] = (isset($params['est_type']) && $params['est_type']== "on") ? 1 : 0;
|
|
|
125 |
$requeteDonnees = $this->traiterCorresponceConfigWidgetInterfaceBD($params);
|
3193 |
delphine |
126 |
$retour = $manager->modifierWidget($params['projet'], $params['langue'], $requeteDonnees);
|
|
|
127 |
|
3121 |
delphine |
128 |
}
|
|
|
129 |
$this->envoyerJson($retour);
|
|
|
130 |
return "ff";
|
3193 |
delphine |
131 |
|
3092 |
delphine |
132 |
}
|
|
|
133 |
|
|
|
134 |
private function getWidget() {
|
3193 |
delphine |
135 |
$criteres = $this->traiterParametresAutorises($_GET);
|
3092 |
delphine |
136 |
$manager = new GestionWidget($this->config);
|
|
|
137 |
$liste = $manager->obtenirWidget($criteres);
|
3193 |
delphine |
138 |
$liste = $this->traiterCorresponceConfigWidgetBDInterface($liste);
|
3092 |
delphine |
139 |
|
|
|
140 |
$this->envoyerJson($liste);
|
|
|
141 |
}
|
3193 |
delphine |
142 |
|
|
|
143 |
private function getChampsEtendus() {
|
|
|
144 |
$champs = new GestionChampsEtendus2($this->config);
|
|
|
145 |
$projet = (isset($_GET['projet'])) ? $_GET['projet'] : "";
|
|
|
146 |
$langue = (isset($_GET['langue'])) ? $_GET['langue'] : "fr";
|
|
|
147 |
$liste = $champs->consulterProjetChampsEtendus($projet, $langue);
|
3743 |
delphine |
148 |
$liste = $this->traiterCorrespondanceChampsEtendusBDInterface($liste, $projet);
|
3193 |
delphine |
149 |
|
|
|
150 |
$this->envoyerJson($liste);
|
|
|
151 |
}
|
3092 |
delphine |
152 |
|
|
|
153 |
|
|
|
154 |
protected function traiterParametresAutorises(Array $parametres) {
|
|
|
155 |
$parametres_traites = array();
|
3193 |
delphine |
156 |
|
3092 |
delphine |
157 |
foreach($parametres as $cle => $valeur) {
|
|
|
158 |
if(is_string($valeur) && !trim($valeur)) continue;
|
|
|
159 |
if(isset($this->parametres_autorises[$cle])) {
|
|
|
160 |
$parametres_traites[$this->parametres_autorises[$cle]] = $valeur;
|
|
|
161 |
}
|
|
|
162 |
}
|
|
|
163 |
return $parametres_traites;
|
|
|
164 |
}
|
3193 |
delphine |
165 |
|
|
|
166 |
protected function traiterCorresponceConfigWidgetBDInterface(Array $widgets) {
|
|
|
167 |
$parametres_traites = array();
|
|
|
168 |
$corresp = array_flip($this->correspondance_config_widget);
|
|
|
169 |
foreach($widgets as $id => $widget) {
|
|
|
170 |
foreach($widget as $cle => $valeur) {
|
|
|
171 |
if(is_string($valeur) && !trim($valeur)) continue;
|
|
|
172 |
if(isset($corresp[$cle])) {
|
|
|
173 |
$parametres_traites[$id][$corresp[$cle]] = $valeur;
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
return $parametres_traites;
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
protected function traiterCorresponceConfigWidgetInterfaceBD(Array $parametres) {
|
|
|
181 |
$parametres_traites = array();
|
|
|
182 |
$corresp = $this->correspondance_config_widget;
|
|
|
183 |
foreach($parametres as $cle => $valeur) {
|
3283 |
delphine |
184 |
if(is_string($valeur) && !trim($valeur)) $valeur=NULL;
|
3193 |
delphine |
185 |
if(isset($corresp[$cle])) {
|
|
|
186 |
$parametres_traites[$corresp[$cle]] = $valeur;
|
|
|
187 |
}
|
|
|
188 |
}
|
|
|
189 |
return $parametres_traites;
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
protected function traiterCorrespondanceChampsEtendusInterfaceBD(Array $champsinterface) {
|
|
|
193 |
$champsrequete = array(); $i = 0;
|
|
|
194 |
$champssupp = json_decode($champsinterface['champs-supp'], true);
|
|
|
195 |
// pour chaque champs-supp, mettre correspondance extended field et extended field trad
|
|
|
196 |
foreach ($champssupp as $champ) {
|
|
|
197 |
$champsrequete['ce'][$i]['project'] = $champsrequete['cet'][$i]['project'] = $champsinterface['projet'];
|
3874 |
delphine |
198 |
$champsrequete['cet'][$i]['language_iso_code'] = isset($champsinterface['langue']) && $champsinterface['langue'] != "" ? $champsinterface['langue'] : "fr";
|
3193 |
delphine |
199 |
// pour la table extended fiels champs interface => champs bd
|
|
|
200 |
foreach ($this->correspondance_champs_etendus as $ci => $ce) {
|
|
|
201 |
if (isset($champ[$ci]) && $champ[$ci] != "") {
|
|
|
202 |
$champsrequete['ce'][$i][$ce] = $champ[$ci];
|
|
|
203 |
} else {
|
|
|
204 |
if ($ci == "mandatory") {
|
|
|
205 |
$champsrequete['ce'][$i][$ce] = "0";
|
|
|
206 |
} else {
|
|
|
207 |
$champsrequete['ce'][$i][$ce] = "";
|
|
|
208 |
}
|
|
|
209 |
}
|
|
|
210 |
}
|
3874 |
delphine |
211 |
$champsrequete['ce'][$i]["is_visible"] = "1";
|
3193 |
delphine |
212 |
// pour la table extended fiels trad champs interface => champs bd
|
|
|
213 |
foreach ($this->correspondance_champs_etendus_trad as $cit => $cr) {
|
|
|
214 |
if (isset($champ[$cit]) && is_array($champ[$cit])) {
|
|
|
215 |
$champsrequete['cet'][$i][$cr] = json_encode($champ[$cit]);
|
|
|
216 |
} elseif (isset($champ[$cit]) && $champ[$cit] != "") {
|
|
|
217 |
$champsrequete['cet'][$i][$cr] = $champ[$cit];
|
|
|
218 |
} else {
|
|
|
219 |
$champsrequete['cet'][$i][$cr] = "";
|
|
|
220 |
}
|
|
|
221 |
}
|
|
|
222 |
$i++;
|
|
|
223 |
}
|
|
|
224 |
return $champsrequete;
|
|
|
225 |
}
|
3743 |
delphine |
226 |
protected function traiterCorrespondanceChampsEtendusBDInterface(Array $champsrequete, $projet = "null") {
|
3193 |
delphine |
227 |
$champssupp = array(); $i = 0;
|
|
|
228 |
foreach ($champsrequete as $champ) {
|
3743 |
delphine |
229 |
$champssupp[$projet]['projet'] = $champ['project'];
|
|
|
230 |
$champssupp[$projet]['langue'] = $champ['language_iso_code'];
|
3193 |
delphine |
231 |
// pour la table extended fiels champs interface => champs bd
|
|
|
232 |
foreach ($this->correspondance_champs_etendus as $ci => $ce) {
|
|
|
233 |
if (isset($champ[$ce]) && $champ[$ce] != "") {
|
3743 |
delphine |
234 |
$champssupp[$projet]['champs-supp'][$i][$ci] = $champ[$ce];
|
3193 |
delphine |
235 |
} else {
|
3743 |
delphine |
236 |
$champssupp[$projet]['champs-supp'][$i][$ci]= "";
|
3193 |
delphine |
237 |
}
|
|
|
238 |
}
|
|
|
239 |
// pour la table extended fiels trad champs interface => champs bd
|
|
|
240 |
foreach ($this->correspondance_champs_etendus_trad as $cet => $cr) {
|
|
|
241 |
if (isset($champ[$cr]) && $champ[$cr] != "") {
|
3743 |
delphine |
242 |
$champssupp[$projet]['champs-supp'][$i][$cet]= $champ[$cr];
|
3193 |
delphine |
243 |
} else {
|
3743 |
delphine |
244 |
$champssupp[$projet]['champs-supp'][$i][$cet]="";
|
3193 |
delphine |
245 |
}
|
|
|
246 |
}$i++;
|
|
|
247 |
}
|
|
|
248 |
return $champssupp;
|
|
|
249 |
}
|
3092 |
delphine |
250 |
|
|
|
251 |
|
|
|
252 |
}
|
3193 |
delphine |
253 |
?>
|