Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 837 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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