Subversion Repositories Sites.obs-saisons.fr

Rev

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

Rev 138 Rev 207
1
<?php
1
<?php
2
/**
2
/**
3
 * Service fournissant des informations concernant le CEL au format RSS1, RSS2 ou ATOM.
3
 * Service fournissant des informations concernant le CEL au format RSS1, RSS2 ou ATOM.
4
 * Encodage en entrée : utf8
4
 * Encodage en entrée : utf8
5
 * Encodage en sortie : utf8
5
 * Encodage en sortie : utf8
6
 * Format du service :
6
 * Format du service :
7
 * /CelSyndicationObservation/liste-des-flux
7
 * /CelSyndicationObservation/liste-des-flux
8
 * /CelSyndicationObservation/opml
8
 * /CelSyndicationObservation/opml
9
 * /CelSyndicationObservation/par-defaut/(rss1|rss2|atom)?start=0&limit=150
9
 * /CelSyndicationObservation/par-defaut/(rss1|rss2|atom)?start=0&limit=150
10
 * /CelSyndicationObservation/pour-admin/(rss1|rss2|atom)?start=0&limit=150
10
 * /CelSyndicationObservation/pour-admin/(rss1|rss2|atom)?start=0&limit=150
11
 * /CelSyndicationObservation/par-mots-cles/(rss1|rss2|atom)/mot-cle?start=0&limit=150
11
 * /CelSyndicationObservation/par-mots-cles/(rss1|rss2|atom)/mot-cle?start=0&limit=150
12
 * /CelSyndicationObservation/par-commune/(rss1|rss2|atom)/nom-commune?start=0&limit=150
12
 * /CelSyndicationObservation/par-commune/(rss1|rss2|atom)/nom-commune?start=0&limit=150
13
 * 
13
 * 
14
 * Les paramêtres :
14
 * Les paramêtres :
15
 *  - "start" indique le numéro du premier item à afficher
15
 *  - "start" indique le numéro du premier item à afficher
16
 *  - "limit" nombre d'items à afficher
16
 *  - "limit" nombre d'items à afficher
17
 * 
17
 * 
18
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
18
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
19
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
19
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
20
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
20
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
21
 * @version $Id$
21
 * @version $Id$
22
 * @copyright 2010
22
 * @copyright 2010
23
 */
23
 */
24
class OdsSyndicationObservation extends OdsTriple {
24
class OdsSyndicationObservation extends OdsTriple {
25
	
25
	
26
	private $parametres_origines = null;
26
	private $parametres_origines = null;
27
	private $format = null;
27
	private $format = null;
28
	private $service = null;
28
	private $service = null;
29
	private $squelette = null;
29
	private $squelette = null;
30
	private $squelette_dossier = null;
30
	private $squelette_dossier = null;
31
	private $flux = array();
31
	private $flux = array();
32
	
32
	
33
	/**
33
	/**
34
	 * Méthode appelée avec une requête de type GET.
34
	 * Méthode appelée avec une requête de type GET.
35
	 */
35
	 */
36
	public function getElement($params = array()) {
36
	public function getElement($params = array()) {
37
		// Initialisation des variables
37
		// Initialisation des variables
38
		$this->parametres_origines = $params;
38
		$this->parametres_origines = $params;
39
		$info = array();
39
		$info = array();
40
		$contenu = '';
40
		$contenu = '';
41
		
41
		
42
		if (! $this->etreFluxAdmin() || $this->authentifier()) {
42
		if (! $this->etreFluxAdmin() || $this->authentifier()) {
43
			// Pré traitement des paramêtres
43
			// Pré traitement des paramêtres
44
			$pour_bdd = false;
44
			$pour_bdd = false;
45
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
45
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
46
			extract($p);
46
			extract($p);
47
			$this->parametres = $params;
47
			$this->parametres = $params;
48
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
48
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
49
					
49
					
50
			// Récupération de la liste des flux
50
			// Récupération de la liste des flux
51
			$this->chargerListeDesFlux();
51
			$this->chargerListeDesFlux();
52
			
52
			
53
			// Chargement du bon type de service demandé
53
			// Chargement du bon type de service demandé
54
			if (isset($service)) {
54
			if (isset($service)) {
55
				$this->service = $this->traiterNomService($service);
55
				$this->service = $this->traiterNomService($service);
56
				$methode = $this->getNomMethodeService();
56
				$methode = $this->getNomMethodeService();
57
				if (method_exists($this, $methode)) {
57
				if (method_exists($this, $methode)) {
58
					if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
58
					if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
59
						// Mise en minuscule de l'indication du format
59
						// Mise en minuscule de l'indication du format
60
						$this->format = strtolower($format);
60
						$this->format = strtolower($format);
61
						// Définition du fichier squelette demandé
61
						// Définition du fichier squelette demandé
62
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
62
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
63
					} else if (isset($this->flux[$this->service])) {
63
					} else if (isset($this->flux[$this->service])) {
64
						$this->format = '';
64
						$this->format = '';
65
						$this->messages[] = "Le service ODS Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
65
						$this->messages[] = "Le service ODS Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
66
					}
66
					}
67
	
67
	
68
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
68
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
69
						// Suppression des paramêtres inutile pour le reste des méthodes
69
						// Suppression des paramêtres inutile pour le reste des méthodes
70
						array_shift($this->parametres);
70
						array_shift($this->parametres);
71
						array_shift($this->parametres);
71
						array_shift($this->parametres);
72
						
72
						
73
						// Récupération du contenu à renvoyer
73
						// Récupération du contenu à renvoyer
74
						$contenu = $this->$methode();
74
						$contenu = $this->$methode();
75
					}
75
					}
76
				} else {
76
				} else {
77
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
77
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
78
				}
78
				}
79
			} else {
79
			} else {
80
				$this->messages[] = "Le service ODS Syndication Observation nécessite d'indiquer en premier paramètre le type d'information demandé.";
80
				$this->messages[] = "Le service ODS Syndication Observation nécessite d'indiquer en premier paramètre le type d'information demandé.";
81
			}
81
			}
82
		}
82
		}
83
		
83
		
84
		// Envoie sur la sortie standard
84
		// Envoie sur la sortie standard
85
		$encodage = 'utf-8';
85
		$encodage = 'utf-8';
86
		$mime = $this->getTypeMime();
86
		$mime = $this->getTypeMime();
87
		$formatage_json = $this->getFormatageJson();
87
		$formatage_json = $this->getFormatageJson();
88
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
88
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
89
	}
89
	}
90
	
90
	
91
	private function getUrlBase() {
91
	private function getUrlBase() {
92
		$url_base = sprintf($this->config['settings']['baseURLAbsoluDyn'], get_class($this).'/');
92
		$url_base = sprintf($this->config['settings']['baseURLAbsoluDyn'], get_class($this).'/');
93
		return $url_base;
93
		return $url_base;
94
	}
94
	}
95
	
95
	
96
	private function getUrlServiceBase() {
96
	private function getUrlServiceBase() {
97
		$url_service = $this->getUrlBase().implode('/', $this->parametres_origines);
97
		$url_service = $this->getUrlBase().implode('/', $this->parametres_origines);
98
		return $url_service;
98
		return $url_service;
99
	}
99
	}
100
	
100
	
101
	private function traiterNomService($nom) {
101
	private function traiterNomService($nom) {
102
		$nom = strtolower($nom);
102
		$nom = strtolower($nom);
103
		return $nom;
103
		return $nom;
104
	}
104
	}
105
	
105
	
106
	private function getNomMethodeService() {
106
	private function getNomMethodeService() {
107
		$methode = '';
107
		$methode = '';
108
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
108
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
109
		$methode = 'getService'.$service_formate;
109
		$methode = 'getService'.$service_formate;
110
		return $methode;
110
		return $methode;
111
	}
111
	}
112
	
112
	
113
	private function getTypeMime() {
113
	private function getTypeMime() {
114
		$mime = '';
114
		$mime = '';
115
		$test = isset($this->format) ? $this->format : $this->service; 
115
		$test = isset($this->format) ? $this->format : $this->service; 
116
		switch ($test) {
116
		switch ($test) {
117
			case 'atom' :
117
			case 'atom' :
118
				$mime = 'application/atom+xml';
118
				$mime = 'application/atom+xml';
119
				break;
119
				break;
120
			case 'rss1' :
120
			case 'rss1' :
121
			case 'rss2' :
121
			case 'rss2' :
122
				$mime = 'application/rss+xml';
122
				$mime = 'application/rss+xml';
123
				break;
123
				break;
124
			case 'opml' :
124
			case 'opml' :
125
				$mime = 'text/x-opml';
125
				$mime = 'text/x-opml';
126
				break;
126
				break;
127
			default:
127
			default:
128
				$mime = 'text/html';
128
				$mime = 'text/html';
129
		}
129
		}
130
		return $mime;
130
		return $mime;
131
	}
131
	}
132
	
132
	
133
	private function getFormatageJson() {
133
	private function getFormatageJson() {
134
		$json = false;
134
		$json = false;
135
		switch ($this->service) {
135
		switch ($this->service) {
136
			case 'liste-des-flux' :
136
			case 'liste-des-flux' :
137
				$json = true;
137
				$json = true;
138
				break;
138
				break;
139
			default:
139
			default:
140
				$json = false;
140
				$json = false;
141
		}
141
		}
142
		return $json;
142
		return $json;
143
	}
143
	}
144
	
144
	
145
	private function getFlux($nom) {
145
	private function getFlux($nom) {
146
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
146
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
147
	}
147
	}
148
 
148
 
149
	private function setFlux($nom, $titre, $description) {
149
	private function setFlux($nom, $titre, $description) {
150
		$url_base = $this->getUrlBase();
150
		$url_base = $this->getUrlBase();
151
		$formats = array('atom', 'rss2', 'rss1');
151
		$formats = array('atom', 'rss2', 'rss1');
152
		$flux = array();
152
		$flux = array();
153
		foreach ($formats as $format) {
153
		foreach ($formats as $format) {
154
			$url = $url_base.$nom.'/'.$format;
154
			$url = $url_base.$nom.'/'.$format;
155
			$flux[$format] = $url;
155
			$flux[$format] = $url;
156
		}
156
		}
157
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
157
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
158
	}
158
	}
159
	
159
	
160
	private function chargerListeDesFlux() {
160
	private function chargerListeDesFlux() {
161
		$this->setFlux('par-defaut', 'Flux de syndication des observations d\'ODS', 
161
		$this->setFlux('par-defaut', 'Flux de syndication des observations d\'ODS', 
162
			'Ce flux fournit des informations sur les observations d\'ODS');
162
			'Ce flux fournit des informations sur les observations d\'ODS');
163
	}
163
	}
164
	
164
	
165
	private function getServiceListeDesFlux() {
165
	private function getServiceListeDesFlux() {
166
		return $this->flux;
166
		return $this->flux;
167
	}
167
	}
168
	
168
	
169
	private function getServiceOpml() {
169
	private function getServiceOpml() {
170
		$donnees = array();
170
		$donnees = array();
171
		$id = 1;
171
		$id = 1;
172
		foreach ($this->flux as $flux_nom => $flux){
172
		foreach ($this->flux as $flux_nom => $flux){
173
			$info = array();
173
			$info = array();
174
			$info['type'] = 'atom';
174
			$info['type'] = 'atom';
175
			$info['titre'] = $flux['titre'];
175
			$info['titre'] = $flux['titre'];
176
			$info['texte'] = "ODS - Obs - $flux_nom";
176
			$info['texte'] = "ODS - Obs - $flux_nom";
177
			$info['description'] = $flux['description'];
177
			$info['description'] = $flux['description'];
178
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
178
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
179
			$donnees['liste_flux'][] = $info;
179
			$donnees['liste_flux'][] = $info;
180
		}
180
		}
181
		
181
		
182
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
182
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
183
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
183
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
184
		return $contenu;
184
		return $contenu;
185
	}
185
	}
186
	
186
	
187
	private function getServiceParDefaut() {
187
	private function getServiceParDefaut() {
188
		// Construction de la requête
188
		// Construction de la requête
189
		$requete = 	'SELECT * '.
189
		$requete = 	'SELECT * '.
190
			'FROM ods_observations '.
190
			'FROM ods_observations '.
-
 
191
			'WHERE oo_ce_participant != '.$this->config['appli']['id_participant_demo'].' '.
191
			'ORDER BY oo_date_modification DESC '.
192
			'ORDER BY oo_date_modification DESC '.
192
			"LIMIT $this->start,$this->limit ";
193
			"LIMIT $this->start,$this->limit ";
193
		
194
		
194
		$elements = $this->executerRequete($requete);
195
		$elements = $this->executerRequete($requete);
195
		
196
		
196
		// Création du contenu
197
		// Création du contenu
197
		$contenu = $this->executerService($elements);
198
		$contenu = $this->executerService($elements);
198
		return $contenu;
199
		return $contenu;
199
	}
200
	}
200
	
201
	
201
	private function executerService($elements) {
202
	private function executerService($elements) {
202
		$contenu = '';
203
		$contenu = '';
203
		if (is_array($elements)) {
204
		if (is_array($elements)) {
204
			// Prétraitement des données
205
			// Prétraitement des données
205
			$donnees = $this->construireDonneesCommunesAuFlux($elements);
206
			$donnees = $this->construireDonneesCommunesAuFlux($elements);
206
			
207
			
207
			foreach ($elements as $element) {
208
			foreach ($elements as $element) {
208
				$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
209
				$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
209
			}
210
			}
210
			
211
			
211
			// Création du contenu à partir d'un template PHP
212
			// Création du contenu à partir d'un template PHP
212
			if (isset($this->squelette)) {
213
			if (isset($this->squelette)) {
213
				$contenu = JrestService::traiterSquelettePhp($this->squelette, $donnees);
214
				$contenu = JrestService::traiterSquelettePhp($this->squelette, $donnees);
214
			}
215
			}
215
		}		
216
		}		
216
		return $contenu;
217
		return $contenu;
217
	}
218
	}
218
	
219
	
219
	private function construireDonneesCommunesAuFlux($observations) {
220
	private function construireDonneesCommunesAuFlux($observations) {
220
		$donnees = $this->getFlux($this->service);
221
		$donnees = $this->getFlux($this->service);
221
		$donnees['guid'] = $this->getUrlServiceBase();
222
		$donnees['guid'] = $this->getUrlServiceBase();
222
		$donnees['lien_service'] = $this->creerUrlService();
223
		$donnees['lien_service'] = $this->creerUrlService();
223
		$donnees['lien_ods'] = $this->config['settings']['odsSaisieUrlAbsolu'];
224
		$donnees['lien_ods'] = $this->config['settings']['odsSaisieUrlAbsolu'];
224
		$donnees['editeur'] = $this->config['settings']['editeur'];
225
		$donnees['editeur'] = $this->config['settings']['editeur'];
225
		$derniere_info_en_date = reset($observations);
226
		$derniere_info_en_date = reset($observations);
226
		$date_modification_timestamp = strtotime($derniere_info_en_date['oo_date_modification']);
227
		$date_modification_timestamp = strtotime($derniere_info_en_date['oo_date_modification']);
227
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
228
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
228
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
229
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
229
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
230
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
230
		$donnees['annee_courante'] = date('Y');
231
		$donnees['annee_courante'] = date('Y');
231
		$donnees['generateur'] = 'ODS - Jrest - OdsSyndicationObservation';
232
		$donnees['generateur'] = 'ODS - Jrest - OdsSyndicationObservation';
232
		preg_match('/([0-9]+)/', '$Revision$', $match);
233
		preg_match('/([0-9]+)/', '$Revision$', $match);
233
		$donnees['generateur_version'] = $match[1];
234
		$donnees['generateur_version'] = $match[1];
234
		return $donnees; 
235
		return $donnees; 
235
	}
236
	}
236
	
237
	
237
	private function construireDonneesCommunesAuxItems($observation) {
238
	private function construireDonneesCommunesAuxItems($observation) {
238
		$item = array();
239
		$item = array();
239
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($observation['oo_date_modification']);
240
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($observation['oo_date_modification']);
240
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
241
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
241
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
242
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
242
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
243
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
243
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
244
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
244
		$item['date_creation_simple'] = strftime('%A %d %B %Y à %H:%M', strtotime($observation['oo_date_saisie']));
245
		$item['date_creation_simple'] = strftime('%A %d %B %Y à %H:%M', strtotime($observation['oo_date_saisie']));
245
		$item['titre'] = $this->creerTitre($observation);
246
		$item['titre'] = $this->creerTitre($observation);
246
		$item['guid'] = $this->creerGuidItem($observation);
247
		$item['guid'] = $this->creerGuidItem($observation);
247
		$item['lien'] = $this->creerLienItem($observation);
248
		$item['lien'] = $this->creerLienItem($observation);
248
		$item['categorie'] = $this->creerCategorie($item);
249
		$item['categorie'] = $this->creerCategorie($item);
249
		$item['description'] = $this->creerDescription($this->protegerCaracteresHtmlDansChamps($observation), $item);
250
		$item['description'] = $this->creerDescription($this->protegerCaracteresHtmlDansChamps($observation), $item);
250
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($observation, $item));
251
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($observation, $item));
251
		$item['modifier_par'] = $this->creerAuteur($observation['oo_ce_participant'], $this->etreFluxAdmin());
252
		$item['modifier_par'] = $this->creerAuteur($observation['oo_ce_participant'], $this->etreFluxAdmin());
252
		return $item;
253
		return $item;
253
	}
254
	}
254
	
255
	
255
	private function creerTitre($obs) {
256
	private function creerTitre($obs) {
256
		
257
		
257
		$stade_obs = $this->obtenirValeurTripleParId($obs['oo_ce_evenement']);
258
		$stade_obs = $this->obtenirValeurTripleParId($obs['oo_ce_evenement']);
258
		$nom_plante = $this->obtenirNomEspecePourIdIndividu($obs['oo_ce_individu']);
259
		$nom_plante = $this->obtenirNomEspecePourIdIndividu($obs['oo_ce_individu']);
259
		$utilisateur = $this->creerAuteur($obs['oo_ce_participant'], $this->etreFluxAdmin());
260
		$utilisateur = $this->creerAuteur($obs['oo_ce_participant'], $this->etreFluxAdmin());
260
		$titre = "$stade_obs pour $nom_plante par $utilisateur";
261
		$titre = "$stade_obs pour $nom_plante par $utilisateur";
261
		$titre = $this->nettoyerTexte($titre);
262
		$titre = $this->nettoyerTexte($titre);
262
		return $titre;
263
		return $titre;
263
	}
264
	}
264
	
265
	
265
	private function obtenirNomEspecePourIdIndividu($id_individu) {
266
	private function obtenirNomEspecePourIdIndividu($id_individu) {
266
		
267
		
267
		$requete_id_espece_individu = 'SELECT oi_ce_espece FROM ods_individus '.
268
		$requete_id_espece_individu = 'SELECT oi_ce_espece FROM ods_individus '.
268
									  'WHERE oi_id_individu = '.$this->proteger($id_individu);
269
									  'WHERE oi_id_individu = '.$this->proteger($id_individu);
269
		
270
		
270
		$resultat_id_espece = $this->executerRequete($requete_id_espece_individu);
271
		$resultat_id_espece = $this->executerRequete($requete_id_espece_individu);
271
		$id_espece = $resultat_id_espece[0]['oi_ce_espece'];
272
		$id_espece = $resultat_id_espece[0]['oi_ce_espece'];
272
		
273
		
273
		$requete_nom_espece_individu = 'SELECT oe_nom_vernaculaire FROM ods_especes '.
274
		$requete_nom_espece_individu = 'SELECT oe_nom_vernaculaire FROM ods_especes '.
274
									  'WHERE oe_id_espece = '.$this->proteger($id_espece);
275
									  'WHERE oe_id_espece = '.$this->proteger($id_espece);
275
		
276
		
276
		$resultat_nom_espece = $this->executerRequete($requete_nom_espece_individu);
277
		$resultat_nom_espece = $this->executerRequete($requete_nom_espece_individu);
277
		$nom_espece = $resultat_nom_espece[0]['oe_nom_vernaculaire'];
278
		$nom_espece = $resultat_nom_espece[0]['oe_nom_vernaculaire'];
278
		
279
		
279
		return $nom_espece;
280
		return $nom_espece;
280
	}
281
	}
281
	
282
	
282
	private function creerGuidItem($element) {
283
	private function creerGuidItem($element) {
283
		$guid = sprintf($this->config['settings']['guidObsTpl'], 'obs'.$element['oo_id_observation']);
284
		$guid = sprintf($this->config['settings']['guidObsTpl'], 'obs'.$element['oo_id_observation']);
284
		return $guid;
285
		return $guid;
285
	}
286
	}
286
	
287
	
287
	private function creerLienItem($element) {
288
	private function creerLienItem($element) {
288
		return $this->config['settings']['odsSaisieUrlAbsolu'];
289
		return $this->config['settings']['odsSaisieUrlAbsolu'];
289
	}
290
	}
290
	
291
	
291
	private function creerAuteur($element) {
292
	private function creerAuteur($element) {
292
		
293
		
293
		//TODO externaliser les champs dans le fichier de config
294
		//TODO externaliser les champs dans le fichier de config
294
		$requete_selection_auteur = 'SELECT name FROM ods_redesign.drupal_users '.
295
		$requete_selection_auteur = 'SELECT name FROM drupal_users '.
295
									'WHERE uid = '.$this->proteger($element);
296
									'WHERE uid = '.$this->proteger($element);
296
		
297
		
297
		$resultat_auteur = $this->executerRequete($requete_selection_auteur);
298
		$resultat_auteur = $this->executerRequete($requete_selection_auteur);
298
		$nom_auteur = $resultat_auteur[0]['name'];
299
		$nom_auteur = $resultat_auteur[0]['name'];
299
 
300
 
300
		return $nom_auteur;
301
		return $nom_auteur;
301
	}
302
	}
302
	
303
	
303
	private function creerDescription($obs, $item) {
304
	private function creerDescription($obs, $item) {
304
		
305
		
305
		$requete_commune_pour_station = 'SELECT os_ce_commune FROM ods_stations '.
306
		$requete_commune_pour_station = 'SELECT os_ce_commune FROM ods_stations '.
306
										'WHERE os_id_station = '.
307
										'WHERE os_id_station = '.
307
											'(SELECT oi_ce_station FROM ods_individus '. 
308
											'(SELECT oi_ce_station FROM ods_individus '. 
308
											'WHERE oi_id_individu = '.$this->proteger($obs['oo_ce_individu']).')';
309
											'WHERE oi_id_individu = '.$this->proteger($obs['oo_ce_individu']).')';
309
		
310
		
310
		$resultat_commune = $this->executerRequete($requete_commune_pour_station);
311
		$resultat_commune = $this->executerRequete($requete_commune_pour_station);
311
		$commune = $resultat_commune[0]['os_ce_commune'];
312
		$commune = $resultat_commune[0]['os_ce_commune'];
-
 
313
		
312
		
314
		if(is_numeric($commune)) {
313
		$requete_lieu = 'SELECT * FROM ods.COMMUNE '.
315
			$requete_lieu = 'SELECT * FROM ods_communes '.
314
						'WHERE COMMUNE_NOM = '.$this->proteger($commune);
316
						'WHERE oc_code_insee = '.$this->proteger($commune);
315
		
317
		
316
		$resultat_lieu = $this->executerRequete($requete_lieu);
318
			$resultat_lieu = $this->executerRequete($requete_lieu);	
-
 
319
			$lieu = $resultat_lieu[0]['oc_nom']. ' ('.substr($commune,0,2).')';
-
 
320
		} else {
-
 
321
			$lieu = $commune;
317
		$lieu = $resultat_lieu[0]['COMMUNE_NOM']. ' ('.$resultat_lieu[0]['COMMUNE_CODEPOSTAL'].')';
322
		}
318
		
323
		
319
		$description = "Observé à $lieu";
324
		$description = "Observé à $lieu";
320
		$description = $this->nettoyerTexte($description);
325
		$description = $this->nettoyerTexte($description);
321
		return $description;
326
		return $description;
322
	}
327
	}
323
	
328
	
324
	private function creerCategorie($element) {
329
	private function creerCategorie($element) {
325
		$categorie = '';
330
		$categorie = '';
326
		$categorie = 'Observation';
331
		$categorie = 'Observation';
327
		$categorie = $this->nettoyerTexte($categorie);
332
		$categorie = $this->nettoyerTexte($categorie);
328
		return $categorie;
333
		return $categorie;
329
	}
334
	}
330
	
335
	
331
	private function etreFluxAdmin() {
336
	private function etreFluxAdmin() {
332
		return ($_GET['admin'] == '1') ? true : false;
337
		return ($_GET['admin'] == '1') ? true : false;
333
	}
338
	}
334
	
339
	
335
	private function creerUrlService() {
340
	private function creerUrlService() {
336
		$url_service = $this->getUrlServiceBase();
341
		$url_service = $this->getUrlServiceBase();
337
		if (count($_GET) > 0) {
342
		if (count($_GET) > 0) {
338
			
343
			
339
			$url_service .= '?';
344
			$url_service .= '?';
340
			$requete = '';
345
			$requete = '';
341
			
346
			
342
			foreach($_GET as $cle => $valeur) {
347
			foreach($_GET as $cle => $valeur) {
343
				if($cle != '' && trim($valeur) != '') {
348
				if($cle != '' && trim($valeur) != '') {
344
					$requete .= '&'.$cle.'='.$valeur;
349
					$requete .= '&'.$cle.'='.$valeur;
345
				}
350
				}
346
			}
351
			}
347
 
352
 
348
			$url_service = $url_service.ltrim($requete, '&');
353
			$url_service = $url_service.ltrim($requete, '&');
349
		}
354
		}
350
		
355
		
351
		return $url_service;
356
		return $url_service;
352
	}
357
	}
353
}	
358
}	
354
 
359
 
355
?>
360
?>