Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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