Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 236 Rev 239
1
<?php
1
<?php
2
/**
2
/**
3
* Description :
3
* Description :
4
* Classe MetaDonnees.php fournit des informations sur le projet.
4
* Classe MetaDonnees.php fournit des informations sur le projet.
5
* Le but étant de fournir un ensemble minimal d'information comprenant :
5
* Le but étant de fournir un ensemble minimal d'information comprenant :
6
* la version, la langue, le nom, le créateur et l'éditeur du projet.
6
* la version, la langue, le nom, le créateur et l'éditeur du projet.
7
* Si l'url finit par /meta-donnees on retourne une liste de termes (seulement les 100 premières par défaut).
7
* Si l'url finit par /meta-donnees on retourne une liste de termes (seulement les 100 premières par défaut).
8
* L'url peut contenir des paramètres optionnels passés après le ? : /meta-donnees?param1=val1&param2=val2&...
8
* L'url peut contenir des paramètres optionnels passés après le ? : /meta-donnees?param1=val1&param2=val2&...
9
*
9
*
10
* Les paramètres de requête disponibles sont : masque, , recherche,
10
* Les paramètres de requête disponibles sont : masque, , recherche,
11
* distinct, retour.format, navigation.depart et navigation.limite.
11
* distinct, retour.format, navigation.depart et navigation.limite.
12
*
12
*
13
* Encodage en entrée : utf8
13
* Encodage en entrée : utf8
14
* Encodage en sortie : utf8
14
* Encodage en sortie : utf8
15
* @package framework-v3
15
* @package framework-v3
16
* @author Jennifer Dhé <jennifer.dhe@tela-botanica.org>
16
* @author Jennifer Dhé <jennifer.dhe@tela-botanica.org>
17
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
17
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
18
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
18
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
19
* @version 1.0
19
* @version 1.0
20
* @copyright 1999-${year} Tela Botanica (accueil@tela-botanica.org)
20
* @copyright 1999-${year} Tela Botanica (accueil@tela-botanica.org)
21
*/
21
*/
22
 
22
 
23
class MetaDonnees extends Commun {
23
class MetaDonnees extends Commun {
24
 
24
 
25
	protected $requete_champ = '*';
25
	protected $requete_champ = '*';
26
	protected $requete_condition = null;
26
	protected $requete_condition = null;
27
	protected $retour_format = 'max';
27
	protected $retour_format = 'max';
28
	protected $table_retour = array();
28
	protected $table_retour = array();
29
	protected $format_reponse = 'metaDonnees';
29
	protected $format_reponse = 'metaDonnees';
30
	protected $table_ressources;
30
	protected $table_ressources;
31
 
31
 
32
 
32
 
33
	public function consulter($ressources, $parametres) {
33
	public function consulter($ressources, $parametres) {
34
		$this->ressources = $ressources;
34
		$this->ressources = $ressources;
35
		$this->parametres = $parametres;
35
		$this->parametres = $parametres;
36
		$this->serviceNom = 'meta-donnees';
36
		$this->serviceNom = 'meta-donnees';
37
		
37
		
38
		$resultats = '';
38
		$resultats = '';
39
		// on traite en premier la version dans le cas ou un langage est demandé pr une version
39
		// on traite en premier la version dans le cas ou un langage est demandé pr une version
40
		$this->traiterVersionProjet();
40
		$this->traiterVersionProjet();
41
		$this->traiterParametres($parametres);
41
		$this->traiterParametres($parametres);
42
		$this->traiterRessources($ressources);
42
		$this->traiterRessources($ressources);
43
		if ($this->corps_http == '' && $this->entete_http == '') {
43
		if ($this->corps_http == '' && $this->entete_http == '') {
44
			$requete_meta  = $this->assemblerLaRequete();
44
			$requete_meta  = $this->assemblerLaRequete();
45
			$resultat_meta = $this->getBdd()->recupererTous($requete_meta);
45
			$resultat_meta = $this->getBdd()->recupererTous($requete_meta);
46
			$resultats = $this->formerResultat($resultat_meta, $requete_meta);
46
			$resultats = $this->formerResultat($resultat_meta, $requete_meta);
47
		}
47
		}
48
		return $resultats;
48
		return $resultats;
49
	}
49
	}
50
 
50
 
51
	public function formerResultat($resultat_meta, $requete_meta) {
51
	public function formerResultat($resultat_meta, $requete_meta) {
52
		if ($resultat_meta == '') {
52
		if ($resultat_meta == '') {
53
			$e = 'La requête formée comporte une erreur!';
53
			$e = 'La requête formée comporte une erreur!';
54
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE,$e);
54
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE,$e);
55
			Debug::printr($requete);
55
			Debug::printr($requete);
56
		} elseif ($resultat_meta) {
56
		} elseif ($resultat_meta) {
57
			$resultat_formate = $this->retournerResultatFormate($resultat_meta);
57
			$resultat_formate = $this->retournerResultatFormate($resultat_meta);
58
		} else {
58
		} else {
59
			$m = "Données introuvables dans la base $this->table";
59
			$m = "Données introuvables dans la base $this->table";
60
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $m);
60
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $m);
61
			Debug::printr($requete_meta);
61
			Debug::printr($requete_meta);
62
		}
62
		}
63
		return $resultat_formate;
63
		return $resultat_formate;
64
	}
64
	}
65
 
65
 
66
//--------------------FONCTIONS TRAITEMENT DES PARAMETRES---------------------------------------------------------------
66
//--------------------FONCTIONS TRAITEMENT DES PARAMETRES---------------------------------------------------------------
67
 
67
 
68
	public function traiterParametres($parametres) {
68
	public function traiterParametres($parametres) {
69
		if (isset($parametres) && !empty($parametres)) {
69
		if (isset($parametres) && !empty($parametres)) {
70
			foreach ($parametres as $param => $val) {
70
			foreach ($parametres as $param => $val) {
71
				switch ($param) {
71
				switch ($param) {
-
 
72
					case 'version.projet' : $this->ajouterFiltreVersion($val);	break;
72
					case 'retour.langue' : $this->rechercherLangueDispo($val);	break;
73
					case 'retour.langue' : $this->rechercherLangueDispo($val);	break;
73
					case 'retour.format' : $this->retour_format = $val;			break;
74
					case 'retour.format' : $this->retour_format = $val;			break;
74
					default				 :
75
					default				 :
75
						$e = 'Erreur dans les paramètres de recherche de votre requête : </br> Le paramètre " '
76
						$e = 'Erreur dans les paramètres de recherche de votre requête : </br> Le paramètre " '
76
							.$param.' " n\'existe pas.';
77
							.$param.' " n\'existe pas.';
77
						$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
78
						$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
78
						break;
79
						break;
79
				}
80
				}
80
			}
81
			}
81
		}
82
		}
82
	}
83
	}
83
 
-
 
84
//----------------------FONCTIONS TRAITEMENT DES RESSOURCES-------------------------------------------------------------
-
 
85
 
-
 
86
	public function traiterRessources($ressources) {
-
 
87
		// /meta-donnees (liste des meta-données. Toutes les info de la table sont affichées) ou /meta-donnees/#champ
-
 
88
		if (isset($ressources) && !empty($ressources)) {
-
 
89
			$this->table_ressources = $ressources;
-
 
90
			if (isset($ressources) && !empty($ressources)) {
-
 
91
				$this->format_reponse = 'metaDonnees/champ';
-
 
92
			}
-
 
93
		}
-
 
94
	}
-
 
95
 
84
 
96
	/** Détermine quelles métadonnées doivent etre retournées :
85
	/** Détermine quelles métadonnées doivent etre retournées :
97
	 *  - "*" : (/#projet/* /meta-donnees) Renvoi les meta-données de toutes les versions du projet
86
	*  - "*" : (/#projet/* /meta-donnees) Renvoi les meta-données de toutes les versions du projet
98
	 *  - "numero de la version" : (/#projet/2.00/meta-donnees) Renvoi les meta-données de la version 2.00 du projet
87
	*  - "numero de la version" : (/#projet/2.00/meta-donnees) Renvoi les meta-données de la version 2.00 du projet
99
	 *  - non renseignée : (/#projet/meta-donnees) Renvoi les meta-données de la dernière version du projet
88
	*  - non renseignée : (/#projet/meta-donnees) Renvoi les meta-données de la dernière version du projet
100
	 *  Cette info est stockée dans par la classe RestServeur dans la variable $ressources ($ressources[0])
89
	*  Cette info est stockée dans par la classe RestServeur dans la variable $ressources ($ressources[0])
101
	 */
90
	*/
102
	public function traiterVersionProjet() {
-
 
103
		if (isset($this->ressources[0]) && !empty($this->ressources[0])) {
91
	public function ajouterFiltreVersion($val) {
104
			if (preg_match('/(?:[0-9]+(?:_|[.])[0-9]+|[*]| )/', $this->ressources[0])) {
92
		if (preg_match('/(?:[0-9]+(?:_|[.])[0-9]+|[*]| )/', $val)) {
105
				$this->version_projet = array_shift($this->ressources);
-
 
106
				if ($this->version_projet == ' ') $this->version_projet = '+';
93
			$this->version_projet = ($val == ' ') ? '+' : $val;
107
			}
94
		}
108
			switch ($this->version_projet) {
95
		switch ($this->version_projet) {
109
				case '+' :
96
			case '+' :
110
					$this->requete_condition[] = 'version = (SELECT MAX(version) FROM '.Config::get('bdd_table_meta').')';
97
				$this->requete_condition[] = 'version = (SELECT MAX(version) FROM '.Config::get('bdd_table_meta').')';
111
					break;
98
				break;
112
				case '*' :
99
			case '*' :
113
					break;
100
				break;
114
				default :
101
			default :
-
 
102
				if (is_numeric($this->version_projet)) {
-
 
103
					$versions_dispo = $this->rechercherVersionsDispos();
-
 
104
					if (in_array($val, $versions_dispo)) {
-
 
105
						$this->requete_condition[] = 'version = '.$this->getBdd()->proteger($val);
-
 
106
					} else {
115
					if (is_numeric($this->version_projet)) {
107
						$e = 'La version demandée n\'existe pas actuellement. </br>Les versions disponibles sont : '
-
 
108
						.implode(', ', $versions_dispo);
116
						$this->ajouterFiltreVersion();
109
						$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
117
					}
110
					}
118
					break;
111
				}
119
			}
112
				break;
120
		}
-
 
121
 
113
		}
122
	}
-
 
123
 
114
	}
124
 
115
	
125
	/**
116
	/**
126
	 * Vérifie que le numéro de la version passée en paramètre correspond à une version existante.
117
	* Vérifie que le numéro de la version passée en paramètre correspond à une version existante.
127
	 * Si oui remplit la condition de la requete SQL
118
	* Si oui remplit la condition de la requete SQL
128
	 */
119
	*/
129
	public function ajouterFiltreVersion() {
120
	public function rechercherVersionsDispos() {
130
		$val = str_replace('_', '.', $this->version_projet);
121
		$val = str_replace('_', '.', $this->version_projet);
131
		$req_version = 'SELECT version FROM '.Config::get('bdd_table_meta');
122
		$req_version = 'SELECT version FROM '.Config::get('bdd_table_meta');
132
		$res_version = $this->getBdd()->recupererTous($req_version);
123
		$res_version = $this->getBdd()->recupererTous($req_version);
133
		foreach ($res_version as $version) {
124
		foreach ($res_version as $version) {
134
			$versions_dispo[] = $version['version'];
125
			$versions_dispo[] = $version['version'];
135
		}
126
		}
136
		if (in_array($val, $versions_dispo)) {
-
 
137
			$this->requete_condition[] = 'version = '.$this->getBdd()->proteger($val);
-
 
138
		} else {
-
 
139
			$e = 'La version demandée n\'existe pas actuellement. </br>Les versions disponibles sont : '
-
 
140
				.implode($versions_dispo);
127
		return $versions_dispo;
141
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
-
 
142
		}
-
 
143
	}
128
	}
144
 
-
 
145
 
129
	
146
	/** Vérifie que les meta-donnees existe dans la langue passée en paramètre, Si oui remplit la condition de la requete SQL */
130
	/** Vérifie que les meta-donnees existe dans la langue passée en paramètre, Si oui remplit la condition de la requete SQL */
147
	public function rechercherLangueDispo($val) {
131
	public function rechercherLangueDispo($val) {
148
		//on recherche les langues_meta disponibles pour la version demandée : (d'ou ajout de la condition)
132
		//on recherche les langues_meta disponibles pour la version demandée : (d'ou ajout de la condition)
149
		$req_langue = 'SELECT langue_meta FROM '
133
		$req_langue = 'SELECT langue_meta FROM '
150
						.Config::get('bdd_table_meta')
134
		.Config::get('bdd_table_meta')
151
						.' WHERE '.implode(' AND ', $this->requete_condition);
135
		.$this->formerRequeteCondition();
152
		$res_langue = $this->getBdd()->recupererTous($req_langue);
136
		$res_langue = $this->getBdd()->recupererTous($req_langue);
153
		foreach ($res_langue as $langue) {
137
		foreach ($res_langue as $langue) {
154
			$langue_dispo[] = $langue['langue_meta'];
138
			$langue_dispo[] = $langue['langue_meta'];
155
		}
139
		}
156
		if (in_array($val, $langue_dispo)) {
140
		if (in_array($val, $langue_dispo)) {
157
			$this->requete_condition[] = 'langue_meta = '.$this->getBdd()->proteger($val);
141
			$this->requete_condition[] = 'langue_meta = '.$this->getBdd()->proteger($val);
158
		} else {
142
		} else {
159
			$e = 'La langue demandée n\'existe pas actuellement. </br>Les langues disponibles sont : '
143
			$e = 'La langue demandée n\'existe pas actuellement. </br>Les langues disponibles sont : '
160
				.implode($langue_dispo);
144
			.implode($langue_dispo);
161
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
145
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
162
		}
146
		}
163
	}
147
	}
-
 
148
//----------------------FONCTIONS TRAITEMENT DES RESSOURCES-------------------------------------------------------------
-
 
149
 
-
 
150
	public function traiterRessources($ressources) {
-
 
151
		// /meta-donnees (liste des meta-données. Toutes les info de la table sont affichées) ou /meta-donnees/#champ
-
 
152
		if (isset($ressources) && !empty($ressources)) {
-
 
153
			$this->table_ressources = $ressources;
-
 
154
			if (isset($ressources) && !empty($ressources)) {
-
 
155
				$this->format_reponse = 'metaDonnees/champ';
-
 
156
			}
-
 
157
		}
-
 
158
	}
164
 
159
 
165
//------------------------------Fonction d'assemblage de la requete------------------------------------------------------
160
//------------------------------Fonction d'assemblage de la requete------------------------------------------------------
166
 
161
 
167
	public function assemblerLaRequete() {
162
	public function assemblerLaRequete() {
-
 
163
		$req = 'SELECT '.$this->requete_champ.' FROM '.Config::get('bdd_table_meta').$this->formerRequeteCondition();
-
 
164
		return $req;
-
 
165
	}
-
 
166
	
-
 
167
	public  function formerRequeteCondition() {
168
		$condition = '';
168
		$condition = '';
169
		if (isset($this->requete_condition)) {
169
		if ($this->requete_condition != null) {
170
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
170
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
171
		}
171
		}
172
		$req = 'SELECT '.$this->requete_champ.' FROM '.Config::get('bdd_table_meta').$condition;
-
 
173
		return $req;
172
		return $condition;
174
	}
173
	}
175
 
174
 
176
//--------------------------------------Fonction de formatage des resultats ---------------------------------------------
175
//--------------------------------------Fonction de formatage des resultats ---------------------------------------------
177
 
176
 
178
	public function retournerResultatFormate($resultat) {
177
	public function retournerResultatFormate($resultat) {
179
		switch ($this->format_reponse) {
178
		switch ($this->format_reponse) {
180
			case 'metaDonnees/champ' : $reponse = $this->formaterMetaDonneesChamp($resultat);  	break;
179
			case 'metaDonnees/champ' : $reponse = $this->formaterMetaDonneesChamp($resultat);  	break;
181
			case 'metaDonnees'		 : $reponse = $this->formaterMetaDonnees($resultat); 		break;
180
			case 'metaDonnees'		 : $reponse = $this->formaterMetaDonnees($resultat); 		break;
182
			default					 : 															break;
181
			default					 : 															break;
183
		}
182
		}
184
		return $reponse;
183
		return $reponse;
185
	}
184
	}
186
 
185
 
187
//--------------------------------------Fonction de formatage des resultats de /metaDonnees/----------------------------
186
//--------------------------------------Fonction de formatage des resultats de /metaDonnees/----------------------------
188
 
187
 
189
	public function formaterMetaDonnees($resultat) {
188
	public function formaterMetaDonnees($resultat) {
190
		foreach ($resultat as $version) {
189
		foreach ($resultat as $version) {
191
			foreach ($version as $key => $val) {
190
			foreach ($version as $key => $val) {
192
				if ($val != '') {
191
				if ($val != '') {
193
					$this->afficherDonnees($key, $val);
192
					$this->afficherDonnees($key, $val);
194
				}
193
				}
195
			}
194
			}
196
			if ($this->retour_format == 'max' && $this->version_projet == '*') {
195
			if ($this->retour_format == 'max' && $this->version_projet == '*') {
197
				$this->table_retour['href'] = Config::get('url_service_base').Config::get('nom_projet')
196
				$this->table_retour['href'] = Config::get('url_service_base').Config::get('nom_projet')
198
											 .'/'.$version['version'].'/'.$this->serviceNom;
197
											 .'/'.$version['version'].'/'.$this->serviceNom;
199
			}
198
			}
200
			$table[] = $this->table_retour;
199
			$table[] = $this->table_retour;
201
			$this->table_retour = array();
200
			$this->table_retour = array();
202
		}
201
		}
203
		return $table;
202
		return $table;
204
	}
203
	}
205
 
204
 
206
 
205
 
207
	public function afficherDonnees($key, $valeur) {
206
	public function afficherDonnees($key, $valeur) {
208
		if ($valeur != '') {
207
		if ($valeur != '') {
209
			$tab = array();
208
			$tab = array();
210
			if ($this->retour_format == 'min') {
209
			if ($this->retour_format == 'min') {
211
				if (in_array($key, array('editeur','createurs',	'contributeurs','couverture_spatiale','couverture_temporelle'))) {
210
				if (in_array($key, array('editeur','createurs',	'contributeurs','couverture_spatiale','couverture_temporelle'))) {
212
					//Pour les données comprenant plusieurs infos (...=...,...=...;...)
211
					//Pour les données comprenant plusieurs infos (...=...,...=...;...)
213
					$tab = $this->recupererTableauResultat($valeur);
212
					$tab = $this->recupererTableauResultat($valeur);
214
					$this->afficherConcatenationValeur($key, $tab);
213
					$this->afficherConcatenationValeur($key, $tab);
215
				} else {
214
				} else {
216
					$this->table_retour[$key] = trim($valeur);
215
					$this->table_retour[$key] = trim($valeur);
217
				}
216
				}
218
			} else {
217
			} else {
219
				if (in_array($key, array('editeur','createurs',	'contributeurs','couverture_spatiale','couverture_temporelle','langue','langue_meta'))) {
218
				if (in_array($key, array('editeur','createurs',	'contributeurs','couverture_spatiale','couverture_temporelle','langue','langue_meta'))) {
220
					$tab = $this->recupererTableauResultat($valeur);
219
					$tab = $this->recupererTableauResultat($valeur);
221
					$this->afficherConcatenationValeur($key, $tab);
220
					$this->afficherConcatenationValeur($key, $tab);
222
					$this->afficherDonneesMax($key,$valeur,$tab);
221
					$this->afficherDonneesMax($key,$valeur,$tab);
223
				} else {
222
				} else {
224
					$this->table_retour[$key] = trim($valeur);
223
					$this->table_retour[$key] = trim($valeur);
225
				}
224
				}
226
			}
225
			}
227
		}
226
		}
228
	}
227
	}
229
 
228
 
230
	/**
229
	/**
231
	 * Recupère à partir de la valeur du champ les différentes informations séparées par ';' (stocke ds un tableau)
230
	 * Recupère à partir de la valeur du champ les différentes informations séparées par ';' (stocke ds un tableau)
232
	 * pour éditeurs, créateurs, contributeurs,...
231
	 * pour éditeurs, créateurs, contributeurs,...
233
	 * (ex : nom=Tela Botanica,guid=urn:lsid:tela-botanica.org,courriel=accueil@tela-botanica.org,...
232
	 * (ex : nom=Tela Botanica,guid=urn:lsid:tela-botanica.org,courriel=accueil@tela-botanica.org,...
234
	 */
233
	 */
235
	public function recupererTableauResultat($val) {
234
	public function recupererTableauResultat($val) {
236
		$tab = array();
235
		$tab = array();
237
		$num_entite = 0;
236
		$num_entite = 0;
238
		// découpe chaque participant
237
		// découpe chaque participant
239
		$tab_entites = explode(';', $val);
238
		$tab_entites = explode(';', $val);
240
		foreach ($tab_entites as $entite) {
239
		foreach ($tab_entites as $entite) {
241
			$tab[$num_entite] = array();
240
			$tab[$num_entite] = array();
242
			if ($entite != '') { // découpe les informations du participant
241
			if ($entite != '') { // découpe les informations du participant
243
				$entite_detail = explode(',', $entite);
242
				$entite_detail = explode(',', $entite);
244
				foreach ($entite_detail as $detail) {
243
				foreach ($entite_detail as $detail) {
245
					if ($detail != '') {
244
					if ($detail != '') {
246
						if (preg_match('/^([^=]+)=([^=]*)$/', $detail, $match)) {
245
						if (preg_match('/^([^=]+)=([^=]*)$/', $detail, $match)) {
247
							$tab[$num_entite][$match[1]] = $match[2];
246
							$tab[$num_entite][$match[1]] = $match[2];
248
						} else {
247
						} else {
249
							$tab[$num_entite][] = $detail;
248
							$tab[$num_entite][] = $detail;
250
						}
249
						}
251
					}
250
					}
252
				}
251
				}
253
			}
252
			}
254
			$num_entite++;
253
			$num_entite++;
255
		}
254
		}
256
		return $tab;
255
		return $tab;
257
	}
256
	}
258
 
257
 
259
 
258
 
260
	/** Retourne :
259
	/** Retourne :
261
	 *  - le nom de l'editeur
260
	 *  - le nom de l'editeur
262
	 *  - les coordonnées de l'éditeur sous la forme [latitude]N,[longitude]S [datum]
261
	 *  - les coordonnées de l'éditeur sous la forme [latitude]N,[longitude]S [datum]
263
	 *  - la couverture temporelle sous la forme xxxx à xxxx
262
	 *  - la couverture temporelle sous la forme xxxx à xxxx
264
	 *  - la concaténation des noms pour les contributeurs et les créateurs (machin chouette, truc bidule...)
263
	 *  - la concaténation des noms pour les contributeurs et les créateurs (machin chouette, truc bidule...)
265
	 *  - la liste des liste des couvertures spatiales (le nom et pas le code) (France, allemagne..) */
264
	 *  - la liste des liste des couvertures spatiales (le nom et pas le code) (France, allemagne..) */
266
	public function afficherConcatenationValeur($champ, $tab) {
265
	public function afficherConcatenationValeur($champ, $tab) {
267
		if (strrpos($champ, '.coordonnees') !== false) {
266
		if (strrpos($champ, '.coordonnees') !== false) {
268
			if (isset($tab[0]['latitude']) && isset($tab[0]['longitude']) && isset($tab[0]['datum'])) {
267
			if (isset($tab[0]['latitude']) && isset($tab[0]['longitude']) && isset($tab[0]['datum'])) {
269
				$this->table_retour[$champ] = $tab[0]['latitude'].' N, '.$tab[0]['longitude'].' S ['.$tab[0]['datum'].']';
268
				$this->table_retour[$champ] = $tab[0]['latitude'].' N, '.$tab[0]['longitude'].' S ['.$tab[0]['datum'].']';
270
			}
269
			}
271
		} else {
270
		} else {
272
			$concat = '';
271
			$concat = '';
273
			foreach ($tab as $entite) {
272
			foreach ($tab as $entite) {
274
				foreach ($entite as $key => $val) {
273
				foreach ($entite as $key => $val) {
275
					if ($champ == 'couverture_spatiale') {
274
					if ($champ == 'couverture_spatiale') {
276
							$concat .= ', '.$this->ajouterSignification($champ, $val);
275
							$concat .= ', '.$this->ajouterSignification($champ, $val);
277
					} else {
276
					} else {
278
						if (strrpos($key, '.prenom') !== false) {
277
						if (strrpos($key, '.prenom') !== false) {
279
							$concat .= ', '.$val;
278
							$concat .= ', '.$val;
280
						} elseif (strrpos($key, 'nom') !== false) {
279
						} elseif (strrpos($key, 'nom') !== false) {
281
 
280
 
282
							$concat .= ' '.$val;
281
							$concat .= ' '.$val;
283
							break;
282
							break;
284
						}
283
						}
285
					}
284
					}
286
				}
285
				}
287
			}
286
			}
288
			$res = trim($concat, ',');
287
			$res = trim($concat, ',');
289
			$res = trim($res);
288
			$res = trim($res);
290
			if ($champ == 'couverture_temporelle') $res = str_replace(' ', ' à ',$res);
289
			if ($champ == 'couverture_temporelle') $res = str_replace(' ', ' à ',$res);
291
			$this->table_retour[$champ] = $res;
290
			$this->table_retour[$champ] = $res;
292
		}
291
		}
293
	}
292
	}
294
 
293
 
295
 
294
 
296
	public function afficherDonneesMax($champ,$valeur,$tab) {
295
	public function afficherDonneesMax($champ,$valeur,$tab) {
297
		switch ($champ) {
296
		switch ($champ) {
298
			case 'couverture_temporelle' : $this->afficherInfosPrecises($champ, 'start,end', $valeur, $tab); 		break;
297
			case 'couverture_temporelle' : $this->afficherInfosPrecises($champ, 'start,end', $valeur, $tab); 		break;
299
			case 'langue' 				 : $this->afficherInfosPrecises($champ,'signification,code,href', $valeur); break;
298
			case 'langue' 				 : $this->afficherInfosPrecises($champ,'signification,code,href', $valeur); break;
300
			case 'langue_meta' 			 : $this->afficherInfosPrecises($champ,'signification,code,href', $valeur); break;
299
			case 'langue_meta' 			 : $this->afficherInfosPrecises($champ,'signification,code,href', $valeur); break;
301
			case 'couverture_spatiale' 	 : $this->afficherInfosPrecises($champ, 'details', $valeur, $tab); 			break;
300
			case 'couverture_spatiale' 	 : $this->afficherInfosPrecises($champ, 'details', $valeur, $tab); 			break;
302
			case 'createurs' 			 : $this->afficherInfosPrecises($champ, 'details', $valeur, $tab);			break;
301
			case 'createurs' 			 : $this->afficherInfosPrecises($champ, 'details', $valeur, $tab);			break;
303
			case 'contributeurs' 		 : $this->afficherInfosPrecises($champ, 'details', $valeur, $tab); 			break;
302
			case 'contributeurs' 		 : $this->afficherInfosPrecises($champ, 'details', $valeur, $tab); 			break;
304
			case 'editeur' 				 : $this->afficherEditeur($champ, $tab);									break;
303
			case 'editeur' 				 : $this->afficherEditeur($champ, $tab);									break;
305
			default 					 : $this->table_retour[$champ] = $valeur; 									break;
304
			default 					 : $this->table_retour[$champ] = $valeur; 									break;
306
		}
305
		}
307
	}
306
	}
308
 
307
 
309
 
308
 
310
	public function afficherEditeur($key, $tab) {
309
	public function afficherEditeur($key, $tab) {
311
		// infos générales sur l'éditeur
310
		// infos générales sur l'éditeur
312
		foreach ($tab[0] as $k => $val) {
311
		foreach ($tab[0] as $k => $val) {
313
			if ((strrpos($k, 'contact.') === false) && (strrpos($k, '.wgs84') === false)) {
312
			if ((strrpos($k, 'contact.') === false) && (strrpos($k, '.wgs84') === false)) {
314
				$this->table_retour[$key.'.'.$k] = $val;
313
				$this->table_retour[$key.'.'.$k] = $val;
315
			}
314
			}
316
		}
315
		}
317
		//on récupère dans un premier temps les tableaux des coordonnées.
316
		//on récupère dans un premier temps les tableaux des coordonnées.
318
		$table_coordonnees = $this->recupererTableCoordonnees($tab);
317
		$table_coordonnees = $this->recupererTableCoordonnees($tab);
319
		//on affiche les informations sur les coordonnees : concaténation + détails
318
		//on affiche les informations sur les coordonnees : concaténation + détails
320
		if ($table_coordonnees[0] != array()) {
319
		if ($table_coordonnees[0] != array()) {
321
			$this->afficherConcatenationValeur($key.'.coordonnees', $table_coordonnees);
320
			$this->afficherConcatenationValeur($key.'.coordonnees', $table_coordonnees);
322
			if (isset($table_coordonnees[0]['datum'])) {
321
			if (isset($table_coordonnees[0]['datum'])) {
323
				$this->afficherInfosPrecises($key.'.coordonnees.datum',
322
				$this->afficherInfosPrecises($key.'.coordonnees.datum',
324
					'signification,code,href',$table_coordonnees[0]['datum'],
323
					'signification,code,href',$table_coordonnees[0]['datum'],
325
					$table_coordonnees);
324
					$table_coordonnees);
326
			}
325
			}
327
		}
326
		}
328
		$table_contact = $this->recupererTableContact($tab);
327
		$table_contact = $this->recupererTableContact($tab);
329
		//on affiche le premier contact en dehors de la table de détail:
328
		//on affiche le premier contact en dehors de la table de détail:
330
		if ($table_contact[0] != array()) {
329
		if ($table_contact[0] != array()) {
331
			$this->table_retour[$key.'.contact'] = '';
330
			$this->table_retour[$key.'.contact'] = '';
332
			foreach ($table_contact as $info => $valeur) {
331
			foreach ($table_contact as $info => $valeur) {
333
				$this->table_retour[$key.'.contact'] .= $valeur['contact.prenom']." ".$valeur['contact.nom'];
332
				$this->table_retour[$key.'.contact'] .= $valeur['contact.prenom']." ".$valeur['contact.nom'];
334
			}
333
			}
335
			//on affiche les détails des autres contacts :
334
			//on affiche les détails des autres contacts :
336
			$this->afficherTableDetails($key.'.contact', $table_contact);
335
			$this->afficherTableDetails($key.'.contact', $table_contact);
337
		}
336
		}
338
	}
337
	}
339
 
338
 
340
 
339
 
341
 
340
 
342
	public function afficherInfosPrecises($champ, $pts, $val, $tab = null) {
341
	public function afficherInfosPrecises($champ, $pts, $val, $tab = null) {
343
		//permet d'afficher les informations précises telles que les .details, .start, .end...
342
		//permet d'afficher les informations précises telles que les .details, .start, .end...
344
		$pts = explode(',', $pts);
343
		$pts = explode(',', $pts);
345
		foreach ($pts as $pt) {
344
		foreach ($pts as $pt) {
346
			switch ($pt) {
345
			switch ($pt) {
347
				case 'start'   		 : 	$this->table_retour[$champ.'.start'] = $tab['start']; 					 break;
346
				case 'start'   		 : 	$this->table_retour[$champ.'.start'] = $tab['start']; 					 break;
348
				case 'end' 			 : 	$this->table_retour[$champ.'.end'] = $tab[' end']; 						 break;
347
				case 'end' 			 : 	$this->table_retour[$champ.'.end'] = $tab[' end']; 						 break;
349
				case 'code' 		 : 	$this->table_retour[$champ.'.code'] = $val; 							 break;
348
				case 'code' 		 : 	$this->table_retour[$champ.'.code'] = $val; 							 break;
350
				case 'href' 		 : 	$this->table_retour[$champ.'.href'] =
349
				case 'href' 		 : 	$this->table_retour[$champ.'.href'] =
351
										$this->ajouterHrefAutreProjet($champ, '', $val);  				 	 break;
350
										$this->ajouterHrefAutreProjet($champ, '', $val);  				 	 break;
352
				case 'signification' :  $this->table_retour[$champ] = $this->ajouterSignification($champ, $val); break;
351
				case 'signification' :  $this->table_retour[$champ] = $this->ajouterSignification($champ, $val); break;
353
				case 'details' 		 :  if ($champ == 'couverture_spatiale') {
352
				case 'details' 		 :  if ($champ == 'couverture_spatiale') {
354
											$this->afficherCouvertureSpatiale($champ, $tab);
353
											$this->afficherCouvertureSpatiale($champ, $tab);
355
										} else {
354
										} else {
356
											$this->afficherTableDetails($champ, $tab);
355
											$this->afficherTableDetails($champ, $tab);
357
										}																		 break;
356
										}																		 break;
358
				default 			 :  $this->table_retour[$champ.'.'.$pt] = $tab[$pt]; 						 break;
357
				default 			 :  $this->table_retour[$champ.'.'.$pt] = $tab[$pt]; 						 break;
359
			}
358
			}
360
		}
359
		}
361
	}
360
	}
362
 
361
 
363
 
362
 
364
 
363
 
365
	public function afficherCouvertureSpatiale($key, $tab) {
364
	public function afficherCouvertureSpatiale($key, $tab) {
366
		$res = $this->table_retour;
365
		$res = $this->table_retour;
367
		$this->table_retour = array();
366
		$this->table_retour = array();
368
		foreach ($tab as $iso) {
367
		foreach ($tab as $iso) {
369
			foreach ($iso as $val) {
368
			foreach ($iso as $val) {
370
				$this->afficherInfosPrecises($key, 'signification,code,href',$val);
369
				$this->afficherInfosPrecises($key, 'signification,code,href',$val);
371
				$res[$key.'.detail'][] = $this->table_retour;
370
				$res[$key.'.detail'][] = $this->table_retour;
372
				$this->table_retour = array();
371
				$this->table_retour = array();
373
			}
372
			}
374
		}
373
		}
375
		$this->table_retour = $res;
374
		$this->table_retour = $res;
376
	}
375
	}
377
 
376
 
378
	public function afficherTableDetails($champ, $tab) {
377
	public function afficherTableDetails($champ, $tab) {
379
		$res = $this->table_retour;
378
		$res = $this->table_retour;
380
		$this->table_retour = array();
379
		$this->table_retour = array();
381
		foreach ($tab as $num_entite => $entite) { // $t et $type valent p ou o
380
		foreach ($tab as $num_entite => $entite) { // $t et $type valent p ou o
382
			$t = '';
381
			$t = '';
383
			$type = '.';
382
			$type = '.';
384
			foreach ($entite as $key => $infos) {
383
			foreach ($entite as $key => $infos) {
385
				list($type, $info) = explode('.', trim($key));
384
				list($type, $info) = explode('.', trim($key));
386
				if ($type == 'contact') $type = 'p';
385
				if ($type == 'contact') $type = 'p';
387
				if ($type != $t) { // cherche et ajoute la signification du type
386
				if ($type != $t) { // cherche et ajoute la signification du type
388
					$this->afficherInfosPrecises('type', 'signification,code,href', trim($type));
387
					$this->afficherInfosPrecises('type', 'signification,code,href', trim($type));
389
					foreach ($this->table_retour as $k => $val) {
388
					foreach ($this->table_retour as $k => $val) {
390
						$res[$champ.'.details'][$num_entite][$type.'.'.$k] = $val;
389
						$res[$champ.'.details'][$num_entite][$type.'.'.$k] = $val;
391
					}
390
					}
392
					$table_retour = array();
391
					$table_retour = array();
393
					$this->table_retour = array(); // rempli par afficherInfosPrecises
392
					$this->table_retour = array(); // rempli par afficherInfosPrecises
394
					$t = $type;
393
					$t = $type;
395
				}
394
				}
396
				$res[$champ.'.details'][$num_entite][$key] = $infos;
395
				$res[$champ.'.details'][$num_entite][$key] = $infos;
397
			}
396
			}
398
		}
397
		}
399
		$this->table_retour = $res;
398
		$this->table_retour = $res;
400
	}
399
	}
401
 
400
 
402
	public function ajouterSignification($champ, $val, $nom = 'nom') {
401
	public function ajouterSignification($champ, $val, $nom = 'nom') {
403
		$url = $this->ajouterHrefAutreProjet($champ, '', $val);
402
		$url = $this->ajouterHrefAutreProjet($champ, '', $val);
404
		if (in_array($champ, array('langue', 'langue_meta', 'couverture_spatiale'))) {
403
		if (in_array($champ, array('langue', 'langue_meta', 'couverture_spatiale'))) {
405
			$url .= '/'.$nom;
404
			$url .= '/'.$nom;
406
		}
405
		}
407
		$signification = $this->consulterHref($url);
406
		$signification = $this->consulterHref($url);
408
		if (isset($signification->$nom)) {
407
		if (isset($signification->$nom)) {
409
			$res = $signification->$nom;
408
			$res = $signification->$nom;
410
		} else {
409
		} else {
411
			$nom = 'nom.fr';
410
			$nom = 'nom.fr';
412
			$res = $signification->$nom;
411
			$res = $signification->$nom;
413
		}
412
		}
414
		return $res ;
413
		return $res ;
415
	}
414
	}
416
 
415
 
417
 
416
 
418
	public function recupererTableContact(&$tab) {
417
	public function recupererTableContact(&$tab) {
419
		$res = array();
418
		$res = array();
420
		foreach ($tab[0] as $key => $val) {
419
		foreach ($tab[0] as $key => $val) {
421
			if (strrpos($key, 'contact.') !== false) {
420
			if (strrpos($key, 'contact.') !== false) {
422
				while (array_key_exists($key, $res)) { $key = ' '.$key; }
421
				while (array_key_exists($key, $res)) { $key = ' '.$key; }
423
				$res[$key] = $val;
422
				$res[$key] = $val;
424
				unset($tab[0][$key]); //suppression des premiers contacts qui seront affichés après
423
				unset($tab[0][$key]); //suppression des premiers contacts qui seront affichés après
425
			}
424
			}
426
		}
425
		}
427
		$resultat[0] = $res;
426
		$resultat[0] = $res;
428
		return $resultat;
427
		return $resultat;
429
	}
428
	}
430
 
429
 
431
 
430
 
432
	public function recupererTableCoordonnees(&$tab) {
431
	public function recupererTableCoordonnees(&$tab) {
433
		$res = array();
432
		$res = array();
434
		foreach ($tab[0] as $key => $val) {
433
		foreach ($tab[0] as $key => $val) {
435
			if (strrpos($key, 'latitude') !== false || strrpos($key, 'longitude') !== false) {
434
			if (strrpos($key, 'latitude') !== false || strrpos($key, 'longitude') !== false) {
436
				list ($coord, $datum) = explode('.', $key);
435
				list ($coord, $datum) = explode('.', $key);
437
				$res[$coord]  = $val;
436
				$res[$coord]  = $val;
438
				$res['datum'] = $datum;
437
				$res['datum'] = $datum;
439
			}
438
			}
440
		}
439
		}
441
		$resultat[0] = $res;
440
		$resultat[0] = $res;
442
		return $resultat;
441
		return $resultat;
443
	}
442
	}
444
 
443
 
445
//-------------------------------------Fonction de formatage des resultats de /metaDonnees/#champs+champs----------------
444
//-------------------------------------Fonction de formatage des resultats de /metaDonnees/#champs+champs----------------
446
 
445
 
447
	public function formaterMetaDonneesChamp($resultat) {
446
	public function formaterMetaDonneesChamp($resultat) {
448
		$this->recupererNomChamp(Config::get('bdd_table_meta'));
447
		$this->recupererNomChamp(Config::get('bdd_table_meta'));
449
		//On récupère dans un premier temps toutes les données existantes puis on pioche les champs recherchés
448
		//On récupère dans un premier temps toutes les données existantes puis on pioche les champs recherchés
450
		$table_Meta = $this->formaterMetaDonnees($resultat);
449
		$table_Meta = $this->formaterMetaDonnees($resultat);
451
		foreach ($table_Meta as $version) {
450
		foreach ($table_Meta as $version) {
452
			//on affiche les informations par defaut : la version, la langue_meta et le guid :
451
			//on affiche les informations par defaut : la version, la langue_meta et le guid :
453
			$this->afficherVersionLangueMetaGuid($version);
452
			$this->afficherVersionLangueMetaGuid($version);
454
			$tab_ress = explode(' ', $this->table_ressources[0]);
453
			$tab_ress = explode(' ', $this->table_ressources[0]);
455
			foreach ($tab_ress as $champ) {//on recupere le radical pour comparaison avec les nom des champs de la bdd :
454
			foreach ($tab_ress as $champ) {//on recupere le radical pour comparaison avec les nom des champs de la bdd :
456
				$this->afficherChampRecherche($champ, $version);
455
				$this->afficherChampRecherche($champ, $version);
457
			}
456
			}
458
			$table[] = $this->table_retour;
457
			$table[] = $this->table_retour;
459
			$this->table_retour = array();
458
			$this->table_retour = array();
460
		}
459
		}
461
		return $table;
460
		return $table;
462
	}
461
	}
463
 
462
 
464
	public function afficherChampRecherche(&$champ, &$version) {
463
	public function afficherChampRecherche(&$champ, &$version) {
465
		preg_match('/^([^.]+)(?:[.][^.]+)?$/', $champ, $match);
464
		preg_match('/^([^.]+)(?:[.][^.]+)?$/', $champ, $match);
466
		if (preg_match('/(.+)[.][*]$/', $champ, $match_2)) {
465
		if (preg_match('/(.+)[.][*]$/', $champ, $match_2)) {
467
			$this->afficherPointEtoile($match_2, $version, $champ);
466
			$this->afficherPointEtoile($match_2, $version, $champ);
468
		} elseif (array_key_exists($champ, $version)) {
467
		} elseif (array_key_exists($champ, $version)) {
469
			$this->table_retour[$champ] = $version[$champ];
468
			$this->table_retour[$champ] = $version[$champ];
470
		} elseif (in_array($match[1], $this->champs_table)) {
469
		} elseif (in_array($match[1], $this->champs_table)) {
471
			//si le champ est vide dans cette version on retourne null (comparaison avec les champs existants)
470
			//si le champ est vide dans cette version on retourne null (comparaison avec les champs existants)
472
			$this->table_retour[$champ] = null;
471
			$this->table_retour[$champ] = null;
473
		} else {
472
		} else {
474
			$champs = implode('</li><li>', array_keys($version));
473
			$champs = implode('</li><li>', array_keys($version));
475
			$e = 'Erreur dans votre requête : </br> Le champ "'.$champ.'" n\'existe pas'.
474
			$e = 'Erreur dans votre requête : </br> Le champ "'.$champ.'" n\'existe pas'.
476
				'. Les champs disponibles sont : <li>'.$champs.'</li>';
475
				'. Les champs disponibles sont : <li>'.$champs.'</li>';
477
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
476
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
478
		}
477
		}
479
	}
478
	}
480
 
479
 
481
	public function afficherPointEtoile($match, $version, $ressource) {
480
	public function afficherPointEtoile($match, $version, $ressource) {
482
		$existe = false;
481
		$existe = false;
483
		foreach ($version as $key => $valeur) {
482
		foreach ($version as $key => $valeur) {
484
			if (strrpos($key, $match[1].'.') !== false) {
483
			if (strrpos($key, $match[1].'.') !== false) {
485
				$this->table_retour[$key] = $valeur;
484
				$this->table_retour[$key] = $valeur;
486
				$existe = true;
485
				$existe = true;
487
			}
486
			}
488
		}
487
		}
489
		if (!$existe) {
488
		if (!$existe) {
490
			$champs = implode('</li><li>', array_keys($version));
489
			$champs = implode('</li><li>', array_keys($version));
491
			$e = 'Erreur dans votre requête : </br> Le champ " '.$ressource.' " n\'existe pas dans la version '
490
			$e = 'Erreur dans votre requête : </br> Le champ " '.$ressource.' " n\'existe pas dans la version '
492
				.$version['version'].'. Les champs disponibles sont : <li>'.$champs.'</li>';
491
				.$version['version'].'. Les champs disponibles sont : <li>'.$champs.'</li>';
493
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
492
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
494
		}
493
		}
495
	}
494
	}
496
 
495
 
497
	public function afficherVersionLangueMetaGuid(&$version) {
496
	public function afficherVersionLangueMetaGuid(&$version) {
498
		$this->table_retour['version'] = $version['version'];
497
		$this->table_retour['version'] = $version['version'];
499
		$this->table_retour['langue_meta'] = $version['langue_meta'];
498
		$this->table_retour['langue_meta'] = $version['langue_meta'];
500
		$this->table_retour['guid'] = $version['guid'];
499
		$this->table_retour['guid'] = $version['guid'];
501
	}
500
	}
502
 
501
 
503
 
502
 
504
 
503
 
505
 
504
 
506
}
505
}
507
 
506
 
508
?>
507
?>