Subversion Repositories eFlore/Applications.cel

Rev

Rev 3531 | Rev 3874 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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