Subversion Repositories eFlore/Applications.cel

Rev

Rev 3875 | Rev 3883 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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'])) {
3283 delphine 117
		    $manager = new GestionWidget($this->config);
118
		    $params['est_type'] = (isset($params['est_type']) && $params['est_type']== "on") ? 1 : 0;
119
		    $requeteDonnees = $this->traiterCorresponceConfigWidgetInterfaceBD($params);
3193 delphine 120
			$retour = $manager->modifierWidget($params['projet'], $params['langue'], $requeteDonnees);
121
 
3121 delphine 122
		}
123
		$this->envoyerJson($retour);
124
		return "ff";
3193 delphine 125
 
3092 delphine 126
	}
127
 
128
	private function getWidget() {
3193 delphine 129
		$criteres = $this->traiterParametresAutorises($_GET);
3092 delphine 130
		$manager = new GestionWidget($this->config);
131
		$liste = $manager->obtenirWidget($criteres);
3193 delphine 132
		$liste = $this->traiterCorresponceConfigWidgetBDInterface($liste);
3092 delphine 133
 
134
		$this->envoyerJson($liste);
135
	}
3193 delphine 136
 
137
	private function getChampsEtendus() {
138
		$champs = new GestionChampsEtendus2($this->config);
139
		$projet = (isset($_GET['projet'])) ? $_GET['projet'] : "";
140
		$langue = (isset($_GET['langue'])) ? $_GET['langue'] : "fr";
141
		$liste = $champs->consulterProjetChampsEtendus($projet, $langue);
3743 delphine 142
		$liste = $this->traiterCorrespondanceChampsEtendusBDInterface($liste, $projet);
3193 delphine 143
 
144
		$this->envoyerJson($liste);
145
	}
3092 delphine 146
 
147
 
148
	protected function traiterParametresAutorises(Array $parametres) {
149
		$parametres_traites = array();
3193 delphine 150
 
3092 delphine 151
		foreach($parametres as $cle => $valeur) {
152
			if(is_string($valeur) && !trim($valeur)) continue;
153
			if(isset($this->parametres_autorises[$cle])) {
154
				$parametres_traites[$this->parametres_autorises[$cle]] = $valeur;
155
			}
156
		}
157
		return $parametres_traites;
158
	}
3193 delphine 159
 
160
	protected function traiterCorresponceConfigWidgetBDInterface(Array $widgets) {
161
		$parametres_traites = array();
162
		$corresp = array_flip($this->correspondance_config_widget);
163
		foreach($widgets as $id => $widget) {
164
			foreach($widget as $cle => $valeur) {
165
				if(is_string($valeur) && !trim($valeur)) continue;
166
				if(isset($corresp[$cle])) {
167
					$parametres_traites[$id][$corresp[$cle]] = $valeur;
168
				}
169
			}
170
		}
171
		return $parametres_traites;
172
	}
173
 
174
	protected function traiterCorresponceConfigWidgetInterfaceBD(Array $parametres) {
175
		$parametres_traites = array();
176
		$corresp = $this->correspondance_config_widget;
177
		foreach($parametres as $cle => $valeur) {
3283 delphine 178
				if(is_string($valeur) && !trim($valeur)) $valeur=NULL;
3193 delphine 179
				if(isset($corresp[$cle])) {
180
					$parametres_traites[$corresp[$cle]] = $valeur;
181
				}
182
			}
183
		return $parametres_traites;
184
	}
185
 
186
	protected function traiterCorrespondanceChampsEtendusInterfaceBD(Array $champsinterface) {
187
		$champsrequete = array(); $i = 0;
188
		$champssupp = json_decode($champsinterface['champs-supp'], true);
189
		// pour chaque champs-supp, mettre correspondance extended field et extended field trad
190
		foreach ($champssupp as $champ) {
191
			$champsrequete['ce'][$i]['project'] = $champsrequete['cet'][$i]['project'] = $champsinterface['projet'];
3874 delphine 192
			$champsrequete['cet'][$i]['language_iso_code'] = isset($champsinterface['langue']) && $champsinterface['langue'] != "" ? $champsinterface['langue'] : "fr";
3193 delphine 193
			// pour la table extended fiels champs interface => champs bd
194
			foreach ($this->correspondance_champs_etendus as $ci => $ce) {
195
				if (isset($champ[$ci]) && $champ[$ci] != "") {
196
					$champsrequete['ce'][$i][$ce] = $champ[$ci];
197
				} else {
198
					if ($ci == "mandatory") {
199
						$champsrequete['ce'][$i][$ce] = "0";
200
					} else {
201
						$champsrequete['ce'][$i][$ce] = "";
202
					}
203
				}
204
			}
3874 delphine 205
			$champsrequete['ce'][$i]["is_visible"] = "1";
3193 delphine 206
			// pour la table extended fiels trad champs interface => champs bd
207
			foreach ($this->correspondance_champs_etendus_trad as $cit => $cr) {
208
				if (isset($champ[$cit]) && is_array($champ[$cit])) {
209
					$champsrequete['cet'][$i][$cr] = json_encode($champ[$cit]);
210
				} elseif (isset($champ[$cit]) && $champ[$cit] != "") {
211
					$champsrequete['cet'][$i][$cr] = $champ[$cit];
212
				} else {
213
					$champsrequete['cet'][$i][$cr] = "";
214
				}
215
			}
216
			$i++;
217
		}
218
		return $champsrequete;
219
	}
3743 delphine 220
	protected function traiterCorrespondanceChampsEtendusBDInterface(Array $champsrequete, $projet = "null") {
3193 delphine 221
		$champssupp = array(); $i = 0;
222
		foreach ($champsrequete as $champ) {
3743 delphine 223
			$champssupp[$projet]['projet'] = $champ['project'];
224
			$champssupp[$projet]['langue'] = $champ['language_iso_code'];
3193 delphine 225
			// pour la table extended fiels champs interface => champs bd
226
			foreach ($this->correspondance_champs_etendus as $ci => $ce) {
227
				if (isset($champ[$ce]) && $champ[$ce] != "") {
3743 delphine 228
				    $champssupp[$projet]['champs-supp'][$i][$ci] = $champ[$ce];
3193 delphine 229
				} else {
3743 delphine 230
				    $champssupp[$projet]['champs-supp'][$i][$ci]= "";
3193 delphine 231
				}
232
			}
233
			// pour la table extended fiels trad champs interface => champs bd
234
			foreach ($this->correspondance_champs_etendus_trad as $cet => $cr) {
235
				if (isset($champ[$cr]) && $champ[$cr] != "") {
3743 delphine 236
				    $champssupp[$projet]['champs-supp'][$i][$cet]= $champ[$cr];
3193 delphine 237
				} else {
3743 delphine 238
				    $champssupp[$projet]['champs-supp'][$i][$cet]="";
3193 delphine 239
				}
240
			}$i++;
241
		}
242
		return $champssupp;
243
	}
3092 delphine 244
 
245
 
246
}
3193 delphine 247
?>