Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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