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',
|
3517 |
delphine |
52 |
'milieux' => 'environment',
|
3216 |
delphine |
53 |
'motscles' => 'project_tag_name',
|
3531 |
delphine |
54 |
'info' => 'info',
|
|
|
55 |
'id_projet' => 'project_id'
|
3193 |
delphine |
56 |
);
|
|
|
57 |
|
|
|
58 |
private $correspondance_champs_etendus = array(
|
|
|
59 |
"key" => "field_id",
|
|
|
60 |
"element" => "data_type",
|
|
|
61 |
"mandatory" => "is_mandatory",
|
|
|
62 |
"unit" => "unit"
|
|
|
63 |
);
|
|
|
64 |
|
|
|
65 |
private $correspondance_champs_etendus_trad = array(
|
|
|
66 |
"key" => "extended_field_id",
|
|
|
67 |
"name" => "label",
|
|
|
68 |
"description" => "description",
|
3216 |
delphine |
69 |
"fieldValues" => "default_value",
|
|
|
70 |
"help" => "help"
|
3193 |
delphine |
71 |
);
|
3092 |
delphine |
72 |
|
|
|
73 |
public function getRessource() {
|
|
|
74 |
return $this->getElement(array());
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Méthode appelée avec une requête de type GET.
|
|
|
79 |
*/
|
3193 |
delphine |
80 |
public function getElement($params = array()) {
|
|
|
81 |
switch(@strtolower($params[0])) {
|
3092 |
delphine |
82 |
case 'widget':
|
|
|
83 |
$this->getWidget();
|
|
|
84 |
break;
|
3193 |
delphine |
85 |
case 'champsetendus';
|
|
|
86 |
$this->getChampsEtendus();
|
|
|
87 |
break;
|
3092 |
delphine |
88 |
default:
|
|
|
89 |
$this->getWidget();
|
|
|
90 |
}
|
|
|
91 |
}
|
3193 |
delphine |
92 |
|
|
|
93 |
|
3092 |
delphine |
94 |
public function createElement($requeteDonnees) {
|
|
|
95 |
unset($requeteDonnees['signup_submit']);
|
3193 |
delphine |
96 |
if (isset($requeteDonnees['champs-supp'])) {
|
|
|
97 |
$gestionchamps = new GestionChampsEtendus2($this->config);
|
|
|
98 |
$champs = $this->traiterCorrespondanceChampsEtendusInterfaceBD($requeteDonnees); //var_dump($champs);exit;
|
|
|
99 |
$liste = $gestionchamps->ajouterParProjet($champs);
|
|
|
100 |
unset($requeteDonnees['champs-supp']);
|
|
|
101 |
}
|
3283 |
delphine |
102 |
$requeteDonnees['est_type'] = (isset($requeteDonnees['est_type']) && $requeteDonnees['est_type']== "on") ? 1 : 0;
|
3092 |
delphine |
103 |
$manager = new GestionWidget($this->config);
|
3193 |
delphine |
104 |
$requeteDonnees = $this->traiterCorresponceConfigWidgetInterfaceBD($requeteDonnees);
|
3092 |
delphine |
105 |
$retour = $manager->ajouterWidget($requeteDonnees);
|
3193 |
delphine |
106 |
|
3092 |
delphine |
107 |
$this->envoyerJson($retour);
|
|
|
108 |
|
|
|
109 |
}
|
3193 |
delphine |
110 |
|
3121 |
delphine |
111 |
public function updateElement($uid,$params) {
|
|
|
112 |
$retour = "";
|
|
|
113 |
if (isset($params['projet']) && isset($params['langue'])) {
|
3283 |
delphine |
114 |
$manager = new GestionWidget($this->config);
|
|
|
115 |
$params['est_type'] = (isset($params['est_type']) && $params['est_type']== "on") ? 1 : 0;
|
|
|
116 |
$requeteDonnees = $this->traiterCorresponceConfigWidgetInterfaceBD($params);
|
3193 |
delphine |
117 |
$retour = $manager->modifierWidget($params['projet'], $params['langue'], $requeteDonnees);
|
|
|
118 |
|
3121 |
delphine |
119 |
}
|
|
|
120 |
$this->envoyerJson($retour);
|
|
|
121 |
return "ff";
|
3193 |
delphine |
122 |
|
3092 |
delphine |
123 |
}
|
|
|
124 |
|
|
|
125 |
private function getWidget() {
|
3193 |
delphine |
126 |
$criteres = $this->traiterParametresAutorises($_GET);
|
3092 |
delphine |
127 |
$manager = new GestionWidget($this->config);
|
|
|
128 |
$liste = $manager->obtenirWidget($criteres);
|
3193 |
delphine |
129 |
$liste = $this->traiterCorresponceConfigWidgetBDInterface($liste);
|
3092 |
delphine |
130 |
|
|
|
131 |
$this->envoyerJson($liste);
|
|
|
132 |
}
|
3193 |
delphine |
133 |
|
|
|
134 |
private function getChampsEtendus() {
|
|
|
135 |
$champs = new GestionChampsEtendus2($this->config);
|
|
|
136 |
$projet = (isset($_GET['projet'])) ? $_GET['projet'] : "";
|
|
|
137 |
$langue = (isset($_GET['langue'])) ? $_GET['langue'] : "fr";
|
|
|
138 |
$liste = $champs->consulterProjetChampsEtendus($projet, $langue);
|
3728 |
delphine |
139 |
$liste = $this->traiterCorrespondanceChampsEtendusBDInterface($liste, $projet);
|
3193 |
delphine |
140 |
|
|
|
141 |
$this->envoyerJson($liste);
|
|
|
142 |
}
|
3092 |
delphine |
143 |
|
|
|
144 |
|
|
|
145 |
protected function traiterParametresAutorises(Array $parametres) {
|
|
|
146 |
$parametres_traites = array();
|
3193 |
delphine |
147 |
|
3092 |
delphine |
148 |
foreach($parametres as $cle => $valeur) {
|
|
|
149 |
if(is_string($valeur) && !trim($valeur)) continue;
|
|
|
150 |
if(isset($this->parametres_autorises[$cle])) {
|
|
|
151 |
$parametres_traites[$this->parametres_autorises[$cle]] = $valeur;
|
|
|
152 |
}
|
|
|
153 |
}
|
|
|
154 |
return $parametres_traites;
|
|
|
155 |
}
|
3193 |
delphine |
156 |
|
|
|
157 |
protected function traiterCorresponceConfigWidgetBDInterface(Array $widgets) {
|
|
|
158 |
$parametres_traites = array();
|
|
|
159 |
$corresp = array_flip($this->correspondance_config_widget);
|
|
|
160 |
foreach($widgets as $id => $widget) {
|
|
|
161 |
foreach($widget as $cle => $valeur) {
|
|
|
162 |
if(is_string($valeur) && !trim($valeur)) continue;
|
|
|
163 |
if(isset($corresp[$cle])) {
|
|
|
164 |
$parametres_traites[$id][$corresp[$cle]] = $valeur;
|
|
|
165 |
}
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
return $parametres_traites;
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
protected function traiterCorresponceConfigWidgetInterfaceBD(Array $parametres) {
|
|
|
172 |
$parametres_traites = array();
|
|
|
173 |
$corresp = $this->correspondance_config_widget;
|
|
|
174 |
foreach($parametres as $cle => $valeur) {
|
3283 |
delphine |
175 |
if(is_string($valeur) && !trim($valeur)) $valeur=NULL;
|
3193 |
delphine |
176 |
if(isset($corresp[$cle])) {
|
|
|
177 |
$parametres_traites[$corresp[$cle]] = $valeur;
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
return $parametres_traites;
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
protected function traiterCorrespondanceChampsEtendusInterfaceBD(Array $champsinterface) {
|
|
|
184 |
$champsrequete = array(); $i = 0;
|
|
|
185 |
$champssupp = json_decode($champsinterface['champs-supp'], true);
|
|
|
186 |
// pour chaque champs-supp, mettre correspondance extended field et extended field trad
|
|
|
187 |
foreach ($champssupp as $champ) {
|
|
|
188 |
$champsrequete['ce'][$i]['project'] = $champsrequete['cet'][$i]['project'] = $champsinterface['projet'];
|
|
|
189 |
$champsrequete['cet'][$i]['language_iso_code'] = $champsinterface['langue'];
|
|
|
190 |
// pour la table extended fiels champs interface => champs bd
|
|
|
191 |
foreach ($this->correspondance_champs_etendus as $ci => $ce) {
|
|
|
192 |
if (isset($champ[$ci]) && $champ[$ci] != "") {
|
|
|
193 |
$champsrequete['ce'][$i][$ce] = $champ[$ci];
|
|
|
194 |
} else {
|
|
|
195 |
if ($ci == "mandatory") {
|
|
|
196 |
$champsrequete['ce'][$i][$ce] = "0";
|
|
|
197 |
} else {
|
|
|
198 |
$champsrequete['ce'][$i][$ce] = "";
|
|
|
199 |
}
|
|
|
200 |
}
|
|
|
201 |
}
|
|
|
202 |
// pour la table extended fiels trad champs interface => champs bd
|
|
|
203 |
foreach ($this->correspondance_champs_etendus_trad as $cit => $cr) {
|
|
|
204 |
if (isset($champ[$cit]) && is_array($champ[$cit])) {
|
|
|
205 |
$champsrequete['cet'][$i][$cr] = json_encode($champ[$cit]);
|
|
|
206 |
} elseif (isset($champ[$cit]) && $champ[$cit] != "") {
|
|
|
207 |
$champsrequete['cet'][$i][$cr] = $champ[$cit];
|
|
|
208 |
} else {
|
|
|
209 |
$champsrequete['cet'][$i][$cr] = "";
|
|
|
210 |
}
|
|
|
211 |
}
|
|
|
212 |
$i++;
|
|
|
213 |
}
|
|
|
214 |
return $champsrequete;
|
|
|
215 |
}
|
3728 |
delphine |
216 |
protected function traiterCorrespondanceChampsEtendusBDInterface(Array $champsrequete, $projet = "null") {
|
3193 |
delphine |
217 |
$champssupp = array(); $i = 0;
|
|
|
218 |
foreach ($champsrequete as $champ) {
|
3728 |
delphine |
219 |
$champssupp[$projet]['projet'] = $champ['project'];
|
|
|
220 |
$champssupp[$projet]['langue'] = $champ['language_iso_code'];
|
3193 |
delphine |
221 |
// pour la table extended fiels champs interface => champs bd
|
|
|
222 |
foreach ($this->correspondance_champs_etendus as $ci => $ce) {
|
|
|
223 |
if (isset($champ[$ce]) && $champ[$ce] != "") {
|
3728 |
delphine |
224 |
$champssupp[$projet]['champs-supp'][$i][$ci] = $champ[$ce];
|
3193 |
delphine |
225 |
} else {
|
3728 |
delphine |
226 |
$champssupp[$projet]['champs-supp'][$i][$ci]= "";
|
3193 |
delphine |
227 |
}
|
|
|
228 |
}
|
|
|
229 |
// pour la table extended fiels trad champs interface => champs bd
|
|
|
230 |
foreach ($this->correspondance_champs_etendus_trad as $cet => $cr) {
|
|
|
231 |
if (isset($champ[$cr]) && $champ[$cr] != "") {
|
3728 |
delphine |
232 |
$champssupp[$projet]['champs-supp'][$i][$cet]= $champ[$cr];
|
3193 |
delphine |
233 |
} else {
|
3728 |
delphine |
234 |
$champssupp[$projet]['champs-supp'][$i][$cet]="";
|
3193 |
delphine |
235 |
}
|
|
|
236 |
}$i++;
|
|
|
237 |
}
|
|
|
238 |
return $champssupp;
|
|
|
239 |
}
|
3092 |
delphine |
240 |
|
|
|
241 |
|
|
|
242 |
}
|
3193 |
delphine |
243 |
?>
|