Subversion Repositories Sites.obs-saisons.fr

Rev

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

Rev 284 Rev 289
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
	private $mode = 'normal';
33
	private $mode = 'normal';
34
	
34
	
35
	/**
35
	/**
36
	 * Méthode appelée avec une requête de type GET.
36
	 * Méthode appelée avec une requête de type GET.
37
	 */
37
	 */
38
	public function getElement($params = array()) {
38
	public function getElement($params = array()) {
39
		// Initialisation des variables
39
		// Initialisation des variables
40
		$this->parametres_origines = $params;
40
		$this->parametres_origines = $params;
41
		$info = array();
41
		$info = array();
42
		$contenu = '';
42
		$contenu = '';
43
		
43
		
44
		if (! $this->etreFluxAdmin() || $this->authentifier()) {
44
		if (! $this->etreFluxAdmin() || $this->authentifier()) {
45
			// Pré traitement des paramêtres
45
			// Pré traitement des paramêtres
46
			$pour_bdd = false;
46
			$pour_bdd = false;
47
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
47
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
48
			extract($p);
48
			extract($p);
49
			$this->parametres = $params;
49
			$this->parametres = $params;
50
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
50
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
51
					
51
					
52
			// Récupération de la liste des flux
52
			// Récupération de la liste des flux
53
			$this->chargerListeDesFlux();
53
			$this->chargerListeDesFlux();
54
			
54
			
55
			// Chargement du bon type de service demandé
55
			// Chargement du bon type de service demandé
56
			if (isset($service)) {
56
			if (isset($service)) {
57
				$this->service = $this->traiterNomService($service);
57
				$this->service = $this->traiterNomService($service);
58
				$methode = $this->getNomMethodeService();
58
				$methode = $this->getNomMethodeService();
59
				if (method_exists($this, $methode)) {
59
				if (method_exists($this, $methode)) {
60
					if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
60
					if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
61
						// Mise en minuscule de l'indication du format
61
						// Mise en minuscule de l'indication du format
62
						$this->format = strtolower($format);
62
						$this->format = strtolower($format);
63
						// Définition du fichier squelette demandé
63
						// Définition du fichier squelette demandé
64
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
64
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
65
					} else if (isset($this->flux[$this->service])) {
65
					} else if (isset($this->flux[$this->service])) {
66
						$this->format = '';
66
						$this->format = '';
67
						$this->messages[] = "Le service ODS Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
67
						$this->messages[] = "Le service ODS Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
68
					}
68
					}
69
	
69
	
70
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
70
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
71
						// Suppression des paramêtres inutile pour le reste des méthodes
71
						// Suppression des paramêtres inutile pour le reste des méthodes
72
						array_shift($this->parametres);
72
						array_shift($this->parametres);
73
						array_shift($this->parametres);
73
						array_shift($this->parametres);
74
						
74
						
75
						// Récupération du contenu à renvoyer
75
						// Récupération du contenu à renvoyer
76
						$contenu = $this->$methode();
76
						$contenu = $this->$methode();
77
					}
77
					}
78
				} else {
78
				} else {
79
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
79
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
80
				}
80
				}
81
			} else {
81
			} else {
82
				$this->messages[] = "Le service ODS Syndication Observation nécessite d'indiquer en premier paramètre le type d'information demandé.";
82
				$this->messages[] = "Le service ODS Syndication Observation nécessite d'indiquer en premier paramètre le type d'information demandé.";
83
			}
83
			}
84
		}
84
		}
85
		
85
		
86
		// Envoie sur la sortie standard
86
		// Envoie sur la sortie standard
87
		$encodage = 'utf-8';
87
		$encodage = 'utf-8';
88
		$mime = $this->getTypeMime();
88
		$mime = $this->getTypeMime();
89
		$formatage_json = $this->getFormatageJson();
89
		$formatage_json = $this->getFormatageJson();
90
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
90
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
91
	}
91
	}
92
	
92
	
93
	private function getUrlBase() {
93
	private function getUrlBase() {
94
		$url_base = sprintf($this->config['settings']['baseURLAbsoluDyn'], get_class($this).'/');
94
		$url_base = sprintf($this->config['settings']['baseURLAbsoluDyn'], get_class($this).'/');
95
		return $url_base;
95
		return $url_base;
96
	}
96
	}
97
	
97
	
98
	private function getUrlServiceBase() {
98
	private function getUrlServiceBase() {
99
		$url_service = $this->getUrlBase().implode('/', $this->parametres_origines);
99
		$url_service = $this->getUrlBase().implode('/', $this->parametres_origines);
100
		return $url_service;
100
		return $url_service;
101
	}
101
	}
102
	
102
	
103
	private function traiterNomService($nom) {
103
	private function traiterNomService($nom) {
104
		$nom = strtolower($nom);
104
		$nom = strtolower($nom);
105
		return $nom;
105
		return $nom;
106
	}
106
	}
107
	
107
	
108
	private function getNomMethodeService() {
108
	private function getNomMethodeService() {
109
		$methode = '';
109
		$methode = '';
110
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
110
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
111
		$methode = 'getService'.$service_formate;
111
		$methode = 'getService'.$service_formate;
112
		return $methode;
112
		return $methode;
113
	}
113
	}
114
	
114
	
115
	private function getTypeMime() {
115
	private function getTypeMime() {
116
		$mime = '';
116
		$mime = '';
117
		$test = isset($this->format) ? $this->format : $this->service; 
117
		$test = isset($this->format) ? $this->format : $this->service; 
118
		switch ($test) {
118
		switch ($test) {
119
			case 'atom' :
119
			case 'atom' :
120
				$mime = 'application/atom+xml';
120
				$mime = 'application/atom+xml';
121
				break;
121
				break;
122
			case 'rss1' :
122
			case 'rss1' :
123
			case 'rss2' :
123
			case 'rss2' :
124
				$mime = 'application/rss+xml';
124
				$mime = 'application/rss+xml';
125
				break;
125
				break;
126
			case 'opml' :
126
			case 'opml' :
127
				$mime = 'text/x-opml';
127
				$mime = 'text/x-opml';
128
				break;
128
				break;
129
			default:
129
			default:
130
				$mime = 'text/html';
130
				$mime = 'text/html';
131
		}
131
		}
132
		return $mime;
132
		return $mime;
133
	}
133
	}
134
	
134
	
135
	private function getFormatageJson() {
135
	private function getFormatageJson() {
136
		$json = false;
136
		$json = false;
137
		switch ($this->service) {
137
		switch ($this->service) {
138
			case 'liste-des-flux' :
138
			case 'liste-des-flux' :
139
				$json = true;
139
				$json = true;
140
				break;
140
				break;
141
			default:
141
			default:
142
				$json = false;
142
				$json = false;
143
		}
143
		}
144
		return $json;
144
		return $json;
145
	}
145
	}
146
	
146
	
147
	private function getFlux($nom) {
147
	private function getFlux($nom) {
148
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
148
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
149
	}
149
	}
150
 
150
 
151
	private function setFlux($nom, $titre, $description) {
151
	private function setFlux($nom, $titre, $description) {
152
		$url_base = $this->getUrlBase();
152
		$url_base = $this->getUrlBase();
153
		$formats = array('atom', 'rss2', 'rss1');
153
		$formats = array('atom', 'rss2', 'rss1');
154
		$flux = array();
154
		$flux = array();
155
		foreach ($formats as $format) {
155
		foreach ($formats as $format) {
156
			$url = $url_base.$nom.'/'.$format;
156
			$url = $url_base.$nom.'/'.$format;
157
			$flux[$format] = $url;
157
			$flux[$format] = $url;
158
		}
158
		}
159
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
159
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
160
	}
160
	}
161
	
161
	
162
	private function chargerListeDesFlux() {
162
	private function chargerListeDesFlux() {
163
		$this->setFlux('par-defaut', 'Flux de syndication des observations d\'ODS', 
163
		$this->setFlux('par-defaut', 'Flux de syndication des observations d\'ODS', 
164
			'Ce flux fournit des informations sur les observations d\'ODS');
164
			'Ce flux fournit des informations sur les observations d\'ODS');
165
	}
165
	}
166
	
166
	
167
	private function getServiceListeDesFlux() {
167
	private function getServiceListeDesFlux() {
168
		return $this->flux;
168
		return $this->flux;
169
	}
169
	}
170
	
170
	
171
	private function getServiceOpml() {
171
	private function getServiceOpml() {
172
		$donnees = array();
172
		$donnees = array();
173
		$id = 1;
173
		$id = 1;
174
		foreach ($this->flux as $flux_nom => $flux){
174
		foreach ($this->flux as $flux_nom => $flux){
175
			$info = array();
175
			$info = array();
176
			$info['type'] = 'atom';
176
			$info['type'] = 'atom';
177
			$info['titre'] = $flux['titre'];
177
			$info['titre'] = $flux['titre'];
178
			$info['texte'] = "ODS - Obs - $flux_nom";
178
			$info['texte'] = "ODS - Obs - $flux_nom";
179
			$info['description'] = $flux['description'];
179
			$info['description'] = $flux['description'];
180
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
180
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
181
			$donnees['liste_flux'][] = $info;
181
			$donnees['liste_flux'][] = $info;
182
		}
182
		}
183
		
183
		
184
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
184
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
185
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
185
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
186
		return $contenu;
186
		return $contenu;
187
	}
187
	}
188
	
188
	
189
	private function getServiceParDefaut() {
189
	private function getServiceParDefaut() {
190
		// Construction de la requête
190
		// Construction de la requête
191
		$requete = 	'SELECT oo.* '.
191
		$requete = 	'SELECT oo.* '.
192
			'FROM ods_observations oo '.
192
			'FROM ods_observations oo '.
193
			'INNER JOIN ods_individus oi '.
193
			'INNER JOIN ods_individus oi '.
194
			'ON oo.oo_ce_individu = oi.oi_id_individu '.
194
			'ON oo.oo_ce_individu = oi.oi_id_individu '.
195
			'INNER JOIN ods_especes oe '.
195
			'INNER JOIN ods_especes oe '.
196
			'ON oe.oe_espece_active = 1 '.
196
			'ON oe.oe_espece_active = 1 '.
197
			'AND oi.oi_ce_espece = oe.oe_id_espece '.
197
			'AND oi.oi_ce_espece = oe.oe_id_espece '.
198
			'WHERE oo_ce_participant != '.$this->config['appli']['id_participant_demo'].' '.
198
			'WHERE oo_ce_participant != '.$this->config['appli']['id_participant_demo'].' '.
199
			'AND oo_ce_participant != '.$this->config['appli']['id_participant_admin'].' '.
199
			'AND oo_ce_participant != '.$this->config['appli']['id_participant_admin'].' '.
200
			'AND DAY(oo_date) != "00" '.
200
			'AND DAY(oo_date) != "00" '.
201
			'ORDER BY oo_date_modification DESC '.
201
			'ORDER BY oo_date_modification DESC '.
202
			"LIMIT $this->start,$this->limit ";
202
			"LIMIT $this->start,$this->limit ";
203
		
203
 
204
		$elements = $this->executerRequete($requete);
204
		$elements = $this->executerRequete($requete);
205
		
205
		
206
		// Création du contenu
206
		// Création du contenu
207
		$contenu = $this->executerService($elements);
207
		$contenu = $this->executerService($elements);
208
		return $contenu;
208
		return $contenu;
209
	}
209
	}
210
	
210
	
211
	private function getServiceModificationObservations() {
211
	private function getServiceModificationObservations() {
212
		
212
		
213
		$this->mode = 'admin';
213
		$this->mode = 'admin';
214
		
214
		
215
		// Construction de la requête
215
		// Construction de la requête
216
		$requete = 	'SELECT * '.
216
		$requete = 	'SELECT * '.
217
			'FROM ods_observations oo '.
217
			'FROM ods_observations oo '.
218
			'INNER JOIN ods_individus oi '.
218
			'INNER JOIN ods_individus oi '.
219
			'ON oo.oo_ce_individu = oi.oi_id_individu '.
219
			'ON oo.oo_ce_individu = oi.oi_id_individu '.
220
			'INNER JOIN ods_especes oe '.
220
			'INNER JOIN ods_especes oe '.
221
			'ON oe.oe_espece_active = 1 '.
221
			'ON oe.oe_espece_active = 1 '.
222
			'AND oi.oi_ce_espece = oe.oe_id_espece '.
222
			'AND oi.oi_ce_espece = oe.oe_id_espece '.
223
			'LEFT JOIN ods_stations os '.
223
			'LEFT JOIN ods_stations os '.
224
			'ON oi.oi_ce_station = os.os_id_station '.
224
			'ON oi.oi_ce_station = os.os_id_station '.
225
			'WHERE oo_ce_participant != '.$this->config['appli']['id_participant_demo'].' '.
225
			'WHERE oo_ce_participant != '.$this->config['appli']['id_participant_demo'].' '.
226
			'AND oo_ce_participant != '.$this->config['appli']['id_participant_admin'].' '.
226
			'AND oo_ce_participant != '.$this->config['appli']['id_participant_admin'].' '.
227
			'AND oo_date_saisie != oo_date_modification '.
227
			'AND oo_date_saisie != oo_date_modification '.
228
			'ORDER BY oo_date_modification DESC '.
228
			'ORDER BY oo_date_modification DESC '.
229
			"LIMIT $this->start,$this->limit ";
229
			"LIMIT $this->start,$this->limit ";
230
 
230
 
231
		$elements = $this->executerRequete($requete);
231
		$elements = $this->executerRequete($requete);
232
		
232
		
233
		// Création du contenu
233
		// Création du contenu
234
		$contenu = $this->executerService($elements);
234
		$contenu = $this->executerService($elements);
235
		return $contenu;
235
		return $contenu;
236
	}
236
	}
237
	
237
	
238
	private function executerService($elements) {
238
	private function executerService($elements) {
239
		$contenu = '';
239
		$contenu = '';
240
		if (is_array($elements)) {
240
		if (is_array($elements)) {
241
			// Prétraitement des données
241
			// Prétraitement des données
242
			$donnees = $this->construireDonneesCommunesAuFlux($elements);
242
			$donnees = $this->construireDonneesCommunesAuFlux($elements);
243
			
243
			
244
			foreach ($elements as $element) {
244
			foreach ($elements as $element) {
245
				$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
245
				$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
246
			}
246
			}
247
			
247
			
248
			// Création du contenu à partir d'un template PHP
248
			// Création du contenu à partir d'un template PHP
249
			if (isset($this->squelette)) {
249
			if (isset($this->squelette)) {
250
				$contenu = JrestService::traiterSquelettePhp($this->squelette, $donnees);
250
				$contenu = JrestService::traiterSquelettePhp($this->squelette, $donnees);
251
			}
251
			}
252
		}		
252
		}		
253
		return $contenu;
253
		return $contenu;
254
	}
254
	}
255
	
255
	
256
	private function construireDonneesCommunesAuFlux($observations) {
256
	private function construireDonneesCommunesAuFlux($observations) {
257
		$donnees = $this->getFlux($this->service);
257
		$donnees = $this->getFlux($this->service);
258
		$donnees['guid'] = $this->getUrlServiceBase();
258
		$donnees['guid'] = $this->getUrlServiceBase();
259
		$donnees['titre'] = $this->creerTitreService();
259
		$donnees['titre'] = $this->creerTitreService();
260
		$donnees['description'] = $this->creerDescriptionService();
260
		$donnees['description'] = $this->creerDescriptionService();
261
		$donnees['lien_service'] = $this->creerUrlService();
261
		$donnees['lien_service'] = $this->creerUrlService();
262
		$donnees['lien_ods'] = $this->config['settings']['odsSaisieUrlAbsolu'];
262
		$donnees['lien_ods'] = $this->config['settings']['odsSaisieUrlAbsolu'];
263
		$donnees['editeur'] = $this->config['settings']['editeur'];
263
		$donnees['editeur'] = $this->config['settings']['editeur'];
264
		$derniere_info_en_date = reset($observations);
264
		$derniere_info_en_date = reset($observations);
265
		$date_modification_timestamp = strtotime($derniere_info_en_date['oo_date_modification']);
265
		$date_modification_timestamp = strtotime($derniere_info_en_date['oo_date_modification']);
266
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
266
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
267
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
267
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
268
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
268
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
269
		$donnees['annee_courante'] = date('Y');
269
		$donnees['annee_courante'] = date('Y');
270
		$donnees['generateur'] = 'ODS - Jrest - OdsSyndicationObservation';
270
		$donnees['generateur'] = 'ODS - Jrest - OdsSyndicationObservation';
271
		preg_match('/([0-9]+)/', '$Revision$', $match);
271
		preg_match('/([0-9]+)/', '$Revision$', $match);
272
		$donnees['generateur_version'] = isset($match[1]) ? $match[1] : 'Inconnue';
272
		$donnees['generateur_version'] = isset($match[1]) ? $match[1] : 'Inconnue';
273
		return $donnees; 
273
		return $donnees; 
274
	}
274
	}
275
	
275
	
276
	private function construireDonneesCommunesAuxItems($observation) {
276
	private function construireDonneesCommunesAuxItems($observation) {
277
		$item = array();
277
		$item = array();
278
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($observation['oo_date_modification']);
278
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($observation['oo_date_modification']);
279
		$item['date_maj_simple'] = strftime('%A %d %B %Y', $date_modification_timestamp);
279
		$item['date_maj_simple'] = strftime('%A %d %B %Y', $date_modification_timestamp);
280
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
280
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
281
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
281
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
282
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
282
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
283
		$item['date_creation_simple'] = strftime('%A %d %B %Y', strtotime($observation['oo_date_saisie']));
283
		$item['date_creation_simple'] = strftime('%A %d %B %Y', strtotime($observation['oo_date_saisie']));
284
		$item['titre'] = $this->creerTitre($observation);
284
		$item['titre'] = $this->creerTitre($observation);
285
		$item['guid'] = $this->creerGuidItem($observation);
285
		$item['guid'] = $this->creerGuidItem($observation);
286
		$item['lien'] = $this->creerUrlService();
286
		$item['lien'] = $this->creerUrlService();
287
		$item['categorie'] = $this->creerCategorie($item);
287
		$item['categorie'] = $this->creerCategorie($item);
288
		$item['description'] = $this->creerDescription($this->protegerCaracteresHtmlDansChamps($observation), $item);
288
		$item['description'] = $this->creerDescription($this->protegerCaracteresHtmlDansChamps($observation), $item);
289
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($observation, $item));
289
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($observation, $item));
290
		$item['modifier_par'] = $this->creerAuteur($observation['oo_ce_participant'], $this->etreFluxAdmin());
290
		$item['modifier_par'] = $this->creerAuteur($observation['oo_ce_participant'], $this->etreFluxAdmin());
291
		return $item;
291
		return $item;
292
	}
292
	}
293
	
293
	
294
	private function creerTitreService() {
294
	private function creerTitreService() {
295
		$titre = '';
295
		$titre = '';
296
		switch($this->service) {
296
		switch($this->service) {
297
			case 'modification-observations':
297
			case 'modification-observations':
298
				$titre = 'Flux rss des dernières modifications d\'observations de l\'observatoire des saisons';
298
				$titre = 'Flux rss des dernières modifications d\'observations de l\'observatoire des saisons';
299
			break;
299
			break;
300
			default:
300
			default:
301
				$titre = 'Flux rss de l\'observatoire des saisons';
301
				$titre = 'Flux rss de l\'observatoire des saisons';
302
		}
302
		}
303
		return $titre;
303
		return $titre;
304
	}
304
	}
305
	
305
	
306
	private function creerDescriptionService() {
306
	private function creerDescriptionService() {
307
		$description = '';
307
		$description = '';
308
		switch($this->service) {
308
		switch($this->service) {
309
			case 'modification-observations':
309
			case 'modification-observations':
310
				$description = 'Flux rss des dernières modifications d\'observations de l\'observatoire des saisons';
310
				$description = 'Flux rss des dernières modifications d\'observations de l\'observatoire des saisons';
311
			break;
311
			break;
312
			default:
312
			default:
313
				$description = 'Flux rss de l\'observatoire des saisons';
313
				$description = 'Flux rss de l\'observatoire des saisons';
314
		}
314
		}
315
		return $description;
315
		return $description;
316
	}
316
	}
317
	
317
	
318
	private function creerTitre($obs) {
318
	private function creerTitre($obs) {
319
		
319
		
320
		$stade_obs = $this->obtenirValeurTripleParId($obs['oo_ce_evenement']);
320
		$stade_obs = $this->obtenirValeurTripleParId($obs['oo_ce_evenement']);
321
		$nom_plante = $this->obtenirNomEspecePourIdIndividu($obs['oo_ce_individu']);
321
		$nom_plante = $this->obtenirNomEspecePourIdIndividu($obs['oo_ce_individu']);
322
		$utilisateur = $this->creerAuteur($obs['oo_ce_participant'], $this->etreFluxAdmin());
322
		$utilisateur = $this->creerAuteur($obs['oo_ce_participant'], $this->etreFluxAdmin());
323
		$titre = "$stade_obs pour $nom_plante par $utilisateur";
323
		$titre = "$stade_obs pour $nom_plante par $utilisateur";
324
		$titre = $this->nettoyerTexte($titre);
324
		$titre = $this->nettoyerTexte($titre);
325
		return $titre;
325
		return $titre;
326
	}
326
	}
327
	
327
	
328
	private function obtenirNomEspecePourIdIndividu($id_individu) {
328
	private function obtenirNomEspecePourIdIndividu($id_individu) {
329
		
329
		
330
		$requete_id_espece_individu = 'SELECT oi_ce_espece FROM ods_individus '.
330
		$requete_id_espece_individu = 'SELECT oi_ce_espece FROM ods_individus '.
331
									  'WHERE oi_id_individu = '.$this->proteger($id_individu);
331
									  'WHERE oi_id_individu = '.$this->proteger($id_individu);
332
		
332
		
333
		$resultat_id_espece = $this->executerRequete($requete_id_espece_individu);
333
		$resultat_id_espece = $this->executerRequete($requete_id_espece_individu);
334
		$id_espece = $resultat_id_espece[0]['oi_ce_espece'];
334
		$id_espece = $resultat_id_espece[0]['oi_ce_espece'];
335
		
335
		
336
		$requete_nom_espece_individu = 'SELECT oe_nom_vernaculaire FROM ods_especes '.
336
		$requete_nom_espece_individu = 'SELECT oe_nom_vernaculaire FROM ods_especes '.
337
									  'WHERE oe_id_espece = '.$this->proteger($id_espece);
337
									  'WHERE oe_id_espece = '.$this->proteger($id_espece);
338
		
338
		
339
		$resultat_nom_espece = $this->executerRequete($requete_nom_espece_individu);
339
		$resultat_nom_espece = $this->executerRequete($requete_nom_espece_individu);
340
		$nom_espece = $resultat_nom_espece[0]['oe_nom_vernaculaire'];
340
		$nom_espece = $resultat_nom_espece[0]['oe_nom_vernaculaire'];
341
		
341
		
342
		return $nom_espece;
342
		return $nom_espece;
343
	}
343
	}
344
	
344
	
345
	private function creerGuidItem($element) {
345
	private function creerGuidItem($element) {
346
		$guid = sprintf($this->config['settings']['guidObsTpl'], 'obs'.$element['oo_id_observation']);
346
		$guid = sprintf($this->config['settings']['guidObsTpl'], 'obs'.$element['oo_id_observation']);
347
		return $guid;
347
		return $guid;
348
	}
348
	}
349
	
349
	
350
	private function creerLienItem($element) {
350
	private function creerLienItem($element) {
351
		return $this->config['settings']['odsSaisieUrlAbsolu'];
351
		return $this->config['settings']['odsSaisieUrlAbsolu'];
352
	}
352
	}
353
	
353
	
354
	private function creerAuteur($element) {
354
	private function creerAuteur($element) {
355
		
355
		
356
		//TODO externaliser les champs dans le fichier de config
356
		//TODO externaliser les champs dans le fichier de config
357
		$requete_selection_auteur = 'SELECT * FROM ods_redesign.drupal_users '.
357
		$requete_selection_auteur = 'SELECT * FROM drupal_users '.
358
		'WHERE uid = '.$this->proteger($element);
358
		'WHERE uid = '.$this->proteger($element);
359
		
359
		
360
		$resultat_auteur = $this->executerRequete($requete_selection_auteur);
360
		$resultat_auteur = $this->executerRequete($requete_selection_auteur);
361
		
361
		
362
		$nom_auteur = $resultat_auteur[0]['name'];
362
		$nom_auteur = $resultat_auteur[0]['name'];
363
		
363
		
364
		if($this->mode == 'admin') {
364
		if($this->mode == 'admin') {
365
			$nom_auteur = $resultat_auteur[0]['mail'];
365
			$nom_auteur = $resultat_auteur[0]['mail'];
366
		}
366
		}
367
		
367
		
368
		return $nom_auteur;
368
		return $nom_auteur;
369
	}
369
	}
370
	
370
	
371
	private function creerDescription($obs, $item) {
371
	private function creerDescription($obs, $item) {
372
		
372
		
373
		$requete_commune_pour_station = 'SELECT os_ce_commune FROM ods_stations '.
373
		$requete_commune_pour_station = 'SELECT os_ce_commune FROM ods_stations '.
374
										'WHERE os_id_station = '.
374
										'WHERE os_id_station = '.
375
											'(SELECT oi_ce_station FROM ods_individus '. 
375
											'(SELECT oi_ce_station FROM ods_individus '. 
376
											'WHERE oi_id_individu = '.$this->proteger($obs['oo_ce_individu']).')';
376
											'WHERE oi_id_individu = '.$this->proteger($obs['oo_ce_individu']).')';
377
		
377
		
378
		$resultat_commune = $this->executerRequete($requete_commune_pour_station);
378
		$resultat_commune = $this->executerRequete($requete_commune_pour_station);
379
		$commune = $resultat_commune[0]['os_ce_commune'];
379
		$commune = $resultat_commune[0]['os_ce_commune'];
380
		
380
		
381
		if(is_numeric($commune)) {
381
		if(is_numeric($commune)) {
382
			$requete_lieu = 'SELECT * FROM ods_communes '.
382
			$requete_lieu = 'SELECT * FROM ods_communes '.
383
						'WHERE oc_code_insee = '.$this->proteger($commune);
383
						'WHERE oc_code_insee = '.$this->proteger($commune);
384
		
384
		
385
			$resultat_lieu = $this->executerRequete($requete_lieu);	
385
			$resultat_lieu = $this->executerRequete($requete_lieu);	
386
			$lieu = $resultat_lieu[0]['oc_nom']. ' ('.substr($commune,0,2).')';
386
			$lieu = $resultat_lieu[0]['oc_nom']. ' ('.substr($commune,0,2).')';
387
		} else {
387
		} else {
388
			$lieu = $commune;
388
			$lieu = $commune;
389
		}
389
		}
390
		
390
		
391
		$description = "Observé à $lieu".'<br />';
391
		$description = "Observé à $lieu".'<br />';
392
		
392
		
393
		if($this->mode == 'admin') {
393
		if($this->mode == 'admin') {
394
			$description .= ' Individu : '.$obs['oi_nom'].'<br />';	
394
			$description .= ' Individu : '.$obs['oi_nom'].'<br />';	
395
			$description .= 'Station : '.$obs['os_nom'].'<br />';
395
			$description .= 'Station : '.$obs['os_nom'].'<br />';
396
			if($this->estUneDateSqlInvalide($obs['oo_date'])) {
396
			if($this->estUneDateSqlInvalide($obs['oo_date'])) {
397
				$description .= ' Date d\'observation supprimée <br />';	
397
				$description .= ' Date d\'observation supprimée <br />';	
398
			} else {
398
			} else {
399
				$description .= ' Date de l\'observation changée en : '.strftime('%A %d %B %Y', strtotime($obs['oo_date'])).'<br />';	
399
				$description .= ' Date de l\'observation changée en : '.strftime('%A %d %B %Y', strtotime($obs['oo_date'])).'<br />';	
400
			}		
400
			}		
401
			$description .= 'Saisi le : '.$item['date_creation_simple'].'<br />';
401
			$description .= 'Saisi le : '.$item['date_creation_simple'].'<br />';
402
			$description .= 'Modifié le : '.$item['date_maj_simple'].'<br />';
402
			$description .= 'Modifié le : '.$item['date_maj_simple'].'<br />';
403
		}
403
		}
404
		
404
		
405
		$description = $this->nettoyerTexte($description);
405
		$description = $this->nettoyerTexte($description);
406
		
406
		
407
		return $description;
407
		return $description;
408
	}
408
	}
409
	
409
	
410
	private function estUneDateSqlInvalide($date) {
410
	private function estUneDateSqlInvalide($date) {
411
		
411
		
412
		$date_tab = explode('-', $date);
412
		$date_tab = explode('-', $date);
413
		return ($date_tab[2] == '00' || $date_tab[1] == '00' || $date_tab[0] == '0000');
413
		return ($date_tab[2] == '00' || $date_tab[1] == '00' || $date_tab[0] == '0000');
414
	}
414
	}
415
	
415
	
416
	private function creerCategorie($element) {
416
	private function creerCategorie($element) {
417
		$categorie = '';
417
		$categorie = '';
418
		$categorie = 'Observation';
418
		$categorie = 'Observation';
419
		$categorie = $this->nettoyerTexte($categorie);
419
		$categorie = $this->nettoyerTexte($categorie);
420
		return $categorie;
420
		return $categorie;
421
	}
421
	}
422
	
422
	
423
	private function etreFluxAdmin() {
423
	private function etreFluxAdmin() {
424
		return (isset($_GET['admin']) && $_GET['admin'] == '1') ? true : false;
424
		return (isset($_GET['admin']) && $_GET['admin'] == '1') ? true : false;
425
	}
425
	}
426
	
426
	
427
	private function creerUrlService() {
427
	private function creerUrlService() {
428
		$url_service = $this->getUrlServiceBase();
428
		$url_service = $this->getUrlServiceBase();
429
		if (count($_GET) > 0) {
429
		if (count($_GET) > 0) {
430
			
430
			
431
			$url_service .= '?';
431
			$url_service .= '?';
432
			$requete = '';
432
			$requete = '';
433
			
433
			
434
			foreach($_GET as $cle => $valeur) {
434
			foreach($_GET as $cle => $valeur) {
435
				if($cle != '' && trim($valeur) != '') {
435
				if($cle != '' && trim($valeur) != '') {
436
					$requete .= '&'.$cle.'='.$valeur;
436
					$requete .= '&'.$cle.'='.$valeur;
437
				}
437
				}
438
			}
438
			}
439
 
439
 
440
			$url_service = $url_service.ltrim($requete, '&');
440
			$url_service = $url_service.ltrim($requete, '&');
441
		}
441
		}
442
		
442
		
443
		return $url_service;
443
		return $url_service;
444
	}
444
	}
445
}	
445
}	
446
 
446
 
447
?>
447
?>