Subversion Repositories eFlore/Applications.cel

Rev

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

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