Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 536 Rev 837
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
	static $cache_ontologies = array();
31
 
32
 
32
 
33
 
33
	public function consulter($ressources, $parametres) {
34
	public function consulter($ressources, $parametres) {
34
		$this->ressources = $ressources;
35
		$this->ressources = $ressources;
35
		$this->parametres = $parametres;
36
		$this->parametres = $parametres;
36
		$this->service = 'meta-donnees';
37
		$this->service = 'meta-donnees';
37
 
38
 
38
		$resultats = '';
39
		$resultats = '';
39
		// on traite en premier la version dans le cas ou un langage est demandé pr une version
40
		// on traite en premier la version dans le cas ou un langage est demandé pr une version
40
		$this->traiterVersionProjet();
41
		$this->traiterVersionProjet();
41
		$this->traiterParametres($parametres);
42
		$this->traiterParametres($parametres);
42
		$this->traiterRessources($ressources);
43
		$this->traiterRessources($ressources);
43
		if ($this->corps_http == '' && $this->entete_http == '') {
44
		if ($this->corps_http == '' && $this->entete_http == '') {
44
			$requete_meta  = $this->assemblerLaRequete();
45
			$requete_meta  = $this->assemblerLaRequete();
45
			$resultat_meta = $this->getBdd()->recupererTous($requete_meta);
46
			$resultat_meta = $this->getBdd()->recupererTous($requete_meta);
46
			$resultats = $this->formerResultat($resultat_meta, $requete_meta);
47
			$resultats = $this->formerResultat($resultat_meta, $requete_meta);
47
		}
48
		}
48
		return $resultats;
49
		return $resultats;
49
	}
50
	}
50
 
51
 
51
	public function formerResultat($resultat_meta, $requete_meta) {
52
	public function formerResultat($resultat_meta, $requete_meta) {
52
		if ($resultat_meta == '') {
53
		if ($resultat_meta == '') {
53
			$e = 'La requête formée comporte une erreur!';
54
			$e = 'La requête formée comporte une erreur!';
54
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE,$e);
55
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE,$e);
55
			Debug::printr($requete);
56
			Debug::printr($requete);
56
		} elseif ($resultat_meta) {
57
		} elseif ($resultat_meta) {
57
			$resultat_formate = $this->retournerResultatFormate($resultat_meta);
58
			$resultat_formate = $this->retournerResultatFormate($resultat_meta);
58
		} else {
59
		} else {
59
			$m = "Données introuvables dans la base $this->table";
60
			$m = "Données introuvables dans la base $this->table";
60
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $m);
61
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $m);
61
			Debug::printr($requete_meta);
62
			Debug::printr($requete_meta);
62
		}
63
		}
63
		return $resultat_formate;
64
		return $resultat_formate;
64
	}
65
	}
65
 
66
 
66
//--------------------FONCTIONS TRAITEMENT DES PARAMETRES---------------------------------------------------------------
67
//--------------------FONCTIONS TRAITEMENT DES PARAMETRES---------------------------------------------------------------
67
 
68
 
68
	public function traiterParametres($parametres) {
69
	public function traiterParametres($parametres) {
69
		if (isset($parametres) && !empty($parametres)) {
70
		if (isset($parametres) && !empty($parametres)) {
70
			foreach ($parametres as $param => $val) {
71
			foreach ($parametres as $param => $val) {
71
				switch ($param) {
72
				switch ($param) {
72
					case 'version.projet' : $this->ajouterFiltreVersion($val);	break;
73
					case 'version.projet' : $this->ajouterFiltreVersion($val);	break;
73
					case 'retour.langue' : $this->rechercherLangueDispo($val);	break;
74
					case 'retour.langue' : $this->rechercherLangueDispo($val);	break;
74
					case 'retour.format' : $this->retour_format = $val;			break;
75
					case 'retour.format' : $this->retour_format = $val;			break;
75
					default				 :
76
					default				 :
76
						$e = 'Erreur dans les paramètres de recherche de votre requête : </br> Le paramètre " '
77
						$e = 'Erreur dans les paramètres de recherche de votre requête : </br> Le paramètre " '
77
							.$param.' " n\'existe pas.';
78
							.$param.' " n\'existe pas.';
78
						$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
79
						$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
79
						break;
80
						break;
80
				}
81
				}
81
			}
82
			}
82
		}
83
		}
83
	}
84
	}
84
 
85
 
85
	/** Détermine quelles métadonnées doivent etre retournées :
86
	/** 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
87
	*  - "*" : (/#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
88
	*  - "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
89
	*  - 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])
90
	*  Cette info est stockée dans par la classe RestServeur dans la variable $ressources ($ressources[0])
90
	*/
91
	*/
91
	public function ajouterFiltreVersion($val) {
92
	public function ajouterFiltreVersion($val) {
92
		if (preg_match('/(?:[0-9]+(?:_|[.])[0-9]+|[*]| )/', $val)) {
93
		if (preg_match('/(?:[0-9]+(?:_|[.])[0-9]+|[*]| )/', $val)) {
93
			$this->version_projet = ($val == ' ') ? '+' : $val;
94
			$this->version_projet = ($val == ' ') ? '+' : $val;
94
		}
95
		}
95
		switch ($this->version_projet) {
96
		switch ($this->version_projet) {
96
			case '+' :
97
			case '+' :
97
				$this->requete_condition[] = 'version = (SELECT MAX(version) FROM '.Config::get('bdd_table_meta').')';
98
				$this->requete_condition[] = 'version = (SELECT MAX(version) FROM '.Config::get('bdd_table_meta').')';
98
				break;
99
				break;
99
			case '*' :
100
			case '*' :
100
				break;
101
				break;
101
			default :
102
			default :
102
				if (is_numeric($this->version_projet)) {
103
				if (is_numeric($this->version_projet)) {
103
					$versions_dispo = $this->rechercherVersionsDispos();
104
					$versions_dispo = $this->rechercherVersionsDispos();
104
					if (in_array($val, $versions_dispo)) {
105
					if (in_array($val, $versions_dispo)) {
105
						$this->requete_condition[] = 'version = '.$this->getBdd()->proteger($val);
106
						$this->requete_condition[] = 'version = '.$this->getBdd()->proteger($val);
106
					} else {
107
					} else {
107
						$e = 'La version demandée n\'existe pas actuellement. </br>Les versions disponibles sont : '
108
						$e = 'La version demandée n\'existe pas actuellement. </br>Les versions disponibles sont : '
108
						.implode(', ', $versions_dispo);
109
						.implode(', ', $versions_dispo);
109
						$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
110
						$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
110
					}
111
					}
111
				}
112
				}
112
				break;
113
				break;
113
		}
114
		}
114
	}
115
	}
115
 
116
 
116
	/**
117
	/**
117
	* Vérifie que le numéro de la version passée en paramètre correspond à une version existante.
118
	* 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
119
	* Si oui remplit la condition de la requete SQL
119
	*/
120
	*/
120
	public function rechercherVersionsDispos() {
121
	public function rechercherVersionsDispos() {
121
		$val = str_replace('_', '.', $this->version_projet);
122
		$val = str_replace('_', '.', $this->version_projet);
122
		$req_version = 'SELECT version FROM '.Config::get('bdd_table_meta');
123
		$req_version = 'SELECT version FROM '.Config::get('bdd_table_meta');
123
		$res_version = $this->getBdd()->recupererTous($req_version);
124
		$res_version = $this->getBdd()->recupererTous($req_version);
124
		foreach ($res_version as $version) {
125
		foreach ($res_version as $version) {
125
			$versions_dispo[] = $version['version'];
126
			$versions_dispo[] = $version['version'];
126
		}
127
		}
127
		return $versions_dispo;
128
		return $versions_dispo;
128
	}
129
	}
129
 
130
 
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
	/** 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) {
132
	public function rechercherLangueDispo($val) {
132
		//on recherche les langues_meta disponibles pour la version demandée : (d'ou ajout de la condition)
133
		//on recherche les langues_meta disponibles pour la version demandée : (d'ou ajout de la condition)
133
		$req_langue = 'SELECT langue_meta FROM '
134
		$req_langue = 'SELECT langue_meta FROM '
134
		.Config::get('bdd_table_meta')
135
		.Config::get('bdd_table_meta')
135
		.$this->formerRequeteCondition();
136
		.$this->formerRequeteCondition();
136
		$res_langue = $this->getBdd()->recupererTous($req_langue);
137
		$res_langue = $this->getBdd()->recupererTous($req_langue);
137
		foreach ($res_langue as $langue) {
138
		foreach ($res_langue as $langue) {
138
			$langue_dispo[] = $langue['langue_meta'];
139
			$langue_dispo[] = $langue['langue_meta'];
139
		}
140
		}
140
		if (in_array($val, $langue_dispo)) {
141
		if (in_array($val, $langue_dispo)) {
141
			$this->requete_condition[] = 'langue_meta = '.$this->getBdd()->proteger($val);
142
			$this->requete_condition[] = 'langue_meta = '.$this->getBdd()->proteger($val);
142
		} else {
143
		} else {
143
			$e = 'La langue demandée n\'existe pas actuellement. </br>Les langues disponibles sont : '
144
			$e = 'La langue demandée n\'existe pas actuellement. </br>Les langues disponibles sont : '
144
			.implode($langue_dispo);
145
			.implode($langue_dispo);
145
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
146
			$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e);
146
		}
147
		}
147
	}
148
	}
148
//----------------------FONCTIONS TRAITEMENT DES RESSOURCES-------------------------------------------------------------
149
//----------------------FONCTIONS TRAITEMENT DES RESSOURCES-------------------------------------------------------------
149
 
150
 
150
	public function traiterRessources($ressources) {
151
	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
		// /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
		if (isset($ressources) && !empty($ressources)) {
153
			$this->table_ressources = $ressources;
154
			$this->table_ressources = $ressources;
154
			if (isset($ressources) && !empty($ressources)) {
155
			if (isset($ressources) && !empty($ressources)) {
155
				$this->format_reponse = 'metaDonnees/champ';
156
				$this->format_reponse = 'metaDonnees/champ';
156
			}
157
			}
157
		}
158
		}
158
	}
159
	}
159
 
160
 
160
//------------------------------Fonction d'assemblage de la requete------------------------------------------------------
161
//------------------------------Fonction d'assemblage de la requete------------------------------------------------------
161
 
162
 
162
	public function assemblerLaRequete() {
163
	public function assemblerLaRequete() {
163
		$req = 'SELECT '.$this->requete_champ.' FROM '.Config::get('bdd_table_meta').$this->formerRequeteCondition();
164
		$req = 'SELECT '.$this->requete_champ.' FROM '.Config::get('bdd_table_meta').$this->formerRequeteCondition();
164
		return $req;
165
		return $req;
165
	}
166
	}
166
 
167
 
167
	public  function formerRequeteCondition() {
168
	public  function formerRequeteCondition() {
168
		$condition = '';
169
		$condition = '';
169
		if ($this->requete_condition != null) {
170
		if ($this->requete_condition != null) {
170
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
171
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
171
		}
172
		}
172
		return $condition;
173
		return $condition;
173
	}
174
	}
174
 
175
 
175
//--------------------------------------Fonction de formatage des resultats ---------------------------------------------
176
//--------------------------------------Fonction de formatage des resultats ---------------------------------------------
176
 
177
 
177
	public function retournerResultatFormate($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 $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->serviceNom;
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' :
347
				case 'start' :
347
					if (isset($this->table_retour[$champ.'.start'])) {
348
					if (isset($this->table_retour[$champ.'.start'])) {
348
						$this->table_retour[$champ.'.start'] = $tab['start'];
349
						$this->table_retour[$champ.'.start'] = $tab['start'];
349
					}
350
					}
350
					break;
351
					break;
351
				case 'end' :
352
				case 'end' :
352
					if (isset($this->table_retour[$champ.'.end'])) {
353
					if (isset($this->table_retour[$champ.'.end'])) {
353
						$this->table_retour[$champ.'.end'] = $tab['end'];
354
						$this->table_retour[$champ.'.end'] = $tab['end'];
354
					}
355
					}
355
					break;
356
					break;
356
				case 'code' :
357
				case 'code' :
357
					$this->table_retour[$champ.'.code'] = $val;
358
					$this->table_retour[$champ.'.code'] = $val;
358
					break;
359
					break;
359
				case 'href' :
360
				case 'href' :
360
					$this->table_retour[$champ.'.href'] = $this->ajouterHrefAutreProjet($champ, '', $val);
361
					$this->table_retour[$champ.'.href'] = $this->ajouterHrefAutreProjet($champ, '', $val);
361
					break;
362
					break;
362
				case 'signification' :
363
				case 'signification' :
363
					$this->table_retour[$champ] = $this->ajouterSignification($champ, $val);
364
					$this->table_retour[$champ] = $this->ajouterSignification($champ, $val);
364
					break;
365
					break;
365
				case 'details' :
366
				case 'details' :
366
					if ($champ == 'couverture_spatiale') {
367
					if ($champ == 'couverture_spatiale') {
367
						$this->afficherCouvertureSpatiale($champ, $tab);
368
						$this->afficherCouvertureSpatiale($champ, $tab);
368
					} else {
369
					} else {
369
						$this->afficherTableDetails($champ, $tab);
370
						$this->afficherTableDetails($champ, $tab);
370
					}
371
					}
371
					break;
372
					break;
372
				default :
373
				default :
373
					$this->table_retour[$champ.'.'.$pt] = $tab[$pt];
374
					$this->table_retour[$champ.'.'.$pt] = $tab[$pt];
374
			}
375
			}
375
		}
376
		}
376
	}
377
	}
377
 
378
 
378
 
379
 
379
 
380
 
380
	public function afficherCouvertureSpatiale($key, $tab) {
381
	public function afficherCouvertureSpatiale($key, $tab) {
381
		$res = $this->table_retour;
382
		$res = $this->table_retour;
382
		$this->table_retour = array();
383
		$this->table_retour = array();
383
		foreach ($tab as $iso) {
384
		foreach ($tab as $iso) {
384
			foreach ($iso as $val) {
385
			foreach ($iso as $val) {
385
				$this->afficherInfosPrecises($key, 'signification,code,href',$val);
386
				$this->afficherInfosPrecises($key, 'signification,code,href',$val);
386
				$res[$key.'.detail'][] = $this->table_retour;
387
				$res[$key.'.detail'][] = $this->table_retour;
387
				$this->table_retour = array();
388
				$this->table_retour = array();
388
			}
389
			}
389
		}
390
		}
390
		$this->table_retour = $res;
391
		$this->table_retour = $res;
391
	}
392
	}
392
 
393
 
393
	public function afficherTableDetails($champ, $tab) {
394
	public function afficherTableDetails($champ, $tab) {
394
		$res = $this->table_retour;
395
		$res = $this->table_retour;
395
		$this->table_retour = array();
396
		$this->table_retour = array();
396
		foreach ($tab as $num_entite => $entite) { // $t et $type valent p ou o
397
		foreach ($tab as $num_entite => $entite) { // $t et $type valent p ou o
397
			$t = '';
398
			$t = '';
398
			$type = '.';
399
			$type = '.';
399
			foreach ($entite as $key => $infos) {
400
			foreach ($entite as $key => $infos) {
400
				list($type, $info) = explode('.', trim($key));
401
				list($type, $info) = explode('.', trim($key));
401
				if ($type == 'contact') $type = 'p';
402
				if ($type == 'contact') $type = 'p';
402
				if ($type != $t) { // cherche et ajoute la signification du type
403
				if ($type != $t) { // cherche et ajoute la signification du type
403
					$this->afficherInfosPrecises('type', 'signification,code,href', trim($type));
404
					$this->afficherInfosPrecises('type', 'signification,code,href', trim($type));
404
					foreach ($this->table_retour as $k => $val) {
405
					foreach ($this->table_retour as $k => $val) {
405
						$res[$champ.'.details'][$num_entite][$type.'.'.$k] = $val;
406
						$res[$champ.'.details'][$num_entite][$type.'.'.$k] = $val;
406
					}
407
					}
407
					$table_retour = array();
408
					$table_retour = array();
408
					$this->table_retour = array(); // rempli par afficherInfosPrecises
409
					$this->table_retour = array(); // rempli par afficherInfosPrecises
409
					$t = $type;
410
					$t = $type;
410
				}
411
				}
411
				$res[$champ.'.details'][$num_entite][$key] = $infos;
412
				$res[$champ.'.details'][$num_entite][$key] = $infos;
412
			}
413
			}
413
		}
414
		}
414
		$this->table_retour = $res;
415
		$this->table_retour = $res;
415
	}
416
	}
416
 
417
 
417
	public function ajouterSignification($champ, $val, $nom = 'nom') {
418
	public function ajouterSignification($champ, $val, $nom = 'nom') {
418
		$url = $this->ajouterHrefAutreProjet($champ, '', $val);
419
		$url = $this->ajouterHrefAutreProjet($champ, '', $val);
419
		if (in_array($champ, array('langue', 'langue_meta', 'couverture_spatiale'))) {
420
		if (in_array($champ, array('langue', 'langue_meta', 'couverture_spatiale'))) {
420
			$url .= '/'.$nom;
421
			$url .= '/'.$nom;
421
		}
422
		}
-
 
423
		if(array_key_exists($url, self::$cache_ontologies)) {
-
 
424
			return self::$cache_ontologies[$url];
-
 
425
		}
422
		$signification = $this->consulterHref($url);
426
		$signification = $this->consulterHref($url);
423
		if (isset($signification->$nom)) {
427
		if (isset($signification->$nom)) {
424
			$res = $signification->$nom;
428
			$res = $signification->$nom;
425
		} else {
429
		} else {
426
			$nom = 'nom.fr';
430
			$nom = 'nom.fr';
427
			$res = $signification->$nom;
431
			$res = $signification->$nom;
428
		}
432
		}
-
 
433
		self::$cache_ontologies[$url] = $res;
429
		return $res ;
434
		return $res ;
430
	}
435
	}
431
 
436
 
432
 
437
 
433
	public function recupererTableContact(&$tab) {
438
	public function recupererTableContact(&$tab) {
434
		$res = array();
439
		$res = array();
435
		foreach ($tab[0] as $key => $val) {
440
		foreach ($tab[0] as $key => $val) {
436
			if (strrpos($key, 'contact.') !== false) {
441
			if (strrpos($key, 'contact.') !== false) {
437
				while (array_key_exists($key, $res)) { $key = ' '.$key; }
442
				while (array_key_exists($key, $res)) { $key = ' '.$key; }
438
				$res[$key] = $val;
443
				$res[$key] = $val;
439
				unset($tab[0][$key]); //suppression des premiers contacts qui seront affichés après
444
				unset($tab[0][$key]); //suppression des premiers contacts qui seront affichés après
440
			}
445
			}
441
		}
446
		}
442
		$resultat[0] = $res;
447
		$resultat[0] = $res;
443
		return $resultat;
448
		return $resultat;
444
	}
449
	}
445
 
450
 
446
 
451
 
447
	public function recupererTableCoordonnees(&$tab) {
452
	public function recupererTableCoordonnees(&$tab) {
448
		$res = array();
453
		$res = array();
449
		foreach ($tab[0] as $key => $val) {
454
		foreach ($tab[0] as $key => $val) {
450
			if (strrpos($key, 'latitude') !== false || strrpos($key, 'longitude') !== false) {
455
			if (strrpos($key, 'latitude') !== false || strrpos($key, 'longitude') !== false) {
451
				list ($coord, $datum) = explode('.', $key);
456
				list ($coord, $datum) = explode('.', $key);
452
				$res[$coord]  = $val;
457
				$res[$coord]  = $val;
453
				$res['datum'] = $datum;
458
				$res['datum'] = $datum;
454
			}
459
			}
455
		}
460
		}
456
		$resultat[0] = $res;
461
		$resultat[0] = $res;
457
		return $resultat;
462
		return $resultat;
458
	}
463
	}
459
 
464
 
460
//-------------------------------------Fonction de formatage des resultats de /metaDonnees/#champs+champs----------------
465
//-------------------------------------Fonction de formatage des resultats de /metaDonnees/#champs+champs----------------
461
 
466
 
462
	public function formaterMetaDonneesChamp($resultat) {
467
	public function formaterMetaDonneesChamp($resultat) {
463
		$this->recupererNomChamp(Config::get('bdd_table_meta'));
468
		$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
469
		//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);
470
		$table_Meta = $this->formaterMetaDonnees($resultat);
466
		foreach ($table_Meta as $version) {
471
		foreach ($table_Meta as $version) {
467
			//on affiche les informations par defaut : la version, la langue_meta et le guid :
472
			//on affiche les informations par defaut : la version, la langue_meta et le guid :
468
			$this->afficherVersionLangueMetaGuid($version);
473
			$this->afficherVersionLangueMetaGuid($version);
469
			$tab_ress = explode(' ', $this->table_ressources[0]);
474
			$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 :
475
			foreach ($tab_ress as $champ) {//on recupere le radical pour comparaison avec les nom des champs de la bdd :
471
				$this->afficherChampRecherche($champ, $version);
476
				$this->afficherChampRecherche($champ, $version);
472
			}
477
			}
473
			$table[] = $this->table_retour;
478
			$table[] = $this->table_retour;
474
			$this->table_retour = array();
479
			$this->table_retour = array();
475
		}
480
		}
476
		return $table;
481
		return $table;
477
	}
482
	}
478
 
483
 
479
	public function afficherChampRecherche(&$champ, &$version) {
484
	public function afficherChampRecherche(&$champ, &$version) {
480
		preg_match('/^([^.]+)(?:[.][^.]+)?$/', $champ, $match);
485
		preg_match('/^([^.]+)(?:[.][^.]+)?$/', $champ, $match);
481
		if (preg_match('/(.+)[.][*]$/', $champ, $match_2)) {
486
		if (preg_match('/(.+)[.][*]$/', $champ, $match_2)) {
482
			$this->afficherPointEtoile($match_2, $version, $champ);
487
			$this->afficherPointEtoile($match_2, $version, $champ);
483
		} elseif (array_key_exists($champ, $version)) {
488
		} elseif (array_key_exists($champ, $version)) {
484
			$this->table_retour[$champ] = $version[$champ];
489
			$this->table_retour[$champ] = $version[$champ];
485
		} elseif (in_array($match[1], $this->champs_table)) {
490
		} 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)
491
			//si le champ est vide dans cette version on retourne null (comparaison avec les champs existants)
487
			$this->table_retour[$champ] = null;
492
			$this->table_retour[$champ] = null;
488
		} else {
493
		} else {
489
			$champs = implode('</li><li>', array_keys($version));
494
			$champs = implode('</li><li>', array_keys($version));
490
			$e = 'Erreur dans votre requête : </br> Le champ "'.$champ.'" n\'existe pas'.
495
			$e = 'Erreur dans votre requête : </br> Le champ "'.$champ.'" n\'existe pas'.
491
				'. Les champs disponibles sont : <li>'.$champs.'</li>';
496
				'. Les champs disponibles sont : <li>'.$champs.'</li>';
492
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
497
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
493
		}
498
		}
494
	}
499
	}
495
 
500
 
496
	public function afficherPointEtoile($match, $version, $ressource) {
501
	public function afficherPointEtoile($match, $version, $ressource) {
497
		$existe = false;
502
		$existe = false;
498
		foreach ($version as $key => $valeur) {
503
		foreach ($version as $key => $valeur) {
499
			if (strrpos($key, $match[1].'.') !== false) {
504
			if (strrpos($key, $match[1].'.') !== false) {
500
				$this->table_retour[$key] = $valeur;
505
				$this->table_retour[$key] = $valeur;
501
				$existe = true;
506
				$existe = true;
502
			}
507
			}
503
		}
508
		}
504
		if (!$existe) {
509
		if (!$existe) {
505
			$champs = implode('</li><li>', array_keys($version));
510
			$champs = implode('</li><li>', array_keys($version));
506
			$e = 'Erreur dans votre requête : </br> Le champ " '.$ressource.' " n\'existe pas dans la version '
511
			$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>';
512
				.$version['version'].'. Les champs disponibles sont : <li>'.$champs.'</li>';
508
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
513
			$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e);
509
		}
514
		}
510
	}
515
	}
511
 
516
 
512
	public function afficherVersionLangueMetaGuid(&$version) {
517
	public function afficherVersionLangueMetaGuid(&$version) {
513
		$this->table_retour['version'] = $version['version'];
518
		$this->table_retour['version'] = $version['version'];
514
		$this->table_retour['langue_meta'] = $version['langue_meta'];
519
		$this->table_retour['langue_meta'] = $version['langue_meta'];
515
		$this->table_retour['guid'] = $version['guid'];
520
		$this->table_retour['guid'] = $version['guid'];
516
	}
521
	}
517
 
-
 
518
 
-
 
519
 
-
 
520
 
-
 
521
}
522
}
522
 
-
 
523
?>
-
 
524
523