Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1309 Rev 1318
1
<?php
1
<?php
2
/**
2
/**
3
 * Service fournissant des informations concernant les commentaire de DEL au format RSS1, RSS2 ou ATOM.
3
 * Service fournissant des informations concernant les commentaire de DEL 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
 *
6
 *
7
 * @author Aurélien PERONNET <aurelien@tela-botanica.org>
7
 * @author Aurélien PERONNET <aurelien@tela-botanica.org>
8
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
8
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
9
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
9
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
10
 * @version $Id$
10
 * @version $Id$
11
 * @copyright 2010
11
 * @copyright 2010
12
 */
12
 */
13
class SyndicationCommentaires {
13
class SyndicationCommentaires {
14
 
14
 
15
	private $ressources = null;
15
	private $ressources = null;
16
	private $parametres = null;
16
	private $parametres = null;
17
	private $format = null;
17
	private $format = null;
18
	private $service = null;
18
	private $service = null;
19
	private $squelette = null;
19
	private $squelette = null;
20
	private $squelette_dossier = null;
20
	private $squelette_dossier = null;
21
	private $masque = array();
21
	private $masque = array();
22
	private $mappingFiltre = array();
22
	private $mappingFiltre = array();
23
	private $conteneur = null;
23
	private $conteneur = null;
24
	private $gestionBdd = null;
24
	private $gestionBdd = null;
25
	private $navigation = null;
25
	private $navigation = null;
26
 
26
 
27
	public function __construct(Conteneur $conteneur = null) {
27
	public function __construct(Conteneur $conteneur = null) {
28
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
28
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
29
		$this->conteneur->chargerConfiguration('config_syndication_commentaires.ini');
29
		$this->conteneur->chargerConfiguration('config_syndication_commentaires.ini');
30
		$this->mappingFiltre = $this->conteneur->getParametre('mapping_masque');
30
		$this->mappingFiltre = $this->conteneur->getParametre('mapping_masque');
31
		$this->masque = $conteneur->getMasque();
31
		$this->masque = $conteneur->getMasque();
32
		$this->gestionBdd = $conteneur->getGestionBdd();
32
		$this->gestionBdd = $conteneur->getGestionBdd();
33
		$this->navigation = $conteneur->getNavigation();
33
		$this->navigation = $conteneur->getNavigation();
34
	}
34
	}
35
 
35
 
36
	public function consulter($params = array()) {
36
	public function consulter($params = array()) {
37
		$this->verifierConfiguration();
37
		$this->verifierConfiguration();
38
 
38
 
39
		if ($this->fluxAdminDemande()) {
39
		if ($this->fluxAdminDemande()) {
40
			$this->demanderAutorisationAdmin();
40
			$this->demanderAutorisationAdmin();
41
		}
41
		}
42
 
42
 
43
		$donnees_brutes = $this->getDerniersCommentaires();
43
		$donnees_brutes = $this->getDerniersCommentaires();
44
		$commentaires_formates = $this->formaterPourRss($donnees_brutes) ;
44
		$commentaires_formates = $this->formaterPourRss($donnees_brutes) ;
45
		return $commentaires_formates;
45
		return $commentaires_formates;
46
	}
46
	}
47
 
47
 
48
	/**
48
	/**
49
	* Vérifier que le service est bien configuré
49
	* Vérifier que le service est bien configuré
50
	* */
50
	* */
51
	public function verifierConfiguration() {
51
	public function verifierConfiguration() {
52
		$erreurs = array();
52
		$erreurs = array();
53
 
53
 
54
		if (empty($this->mappingFiltre)) {
54
		if (empty($this->mappingFiltre)) {
55
			$erreurs[] = 'Le fichier de configuration ne contient pas le tableau [mapping_masque] ou celui-ci est vide.';
55
			$erreurs[] = 'Le fichier de configuration ne contient pas le tableau [mapping_masque] ou celui-ci est vide.';
56
		}
56
		}
57
 
57
 
58
		if (!empty($erreurs)) {
58
		if (!empty($erreurs)) {
59
			$e = 'Erreur lors de la configuration : '."\n";
59
			$e = 'Erreur lors de la configuration : '."\n";
60
			$e .= implode("\n", $erreurs);
60
			$e .= implode("\n", $erreurs);
61
			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
61
			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
62
		}
62
		}
63
	}
63
	}
64
 
64
 
65
	/**
65
	/**
66
	 * Verifier si le flux admin est demande
66
	 * Verifier si le flux admin est demande
67
	 */
67
	 */
68
	private function fluxAdminDemande() {
68
	private function fluxAdminDemande() {
69
		return $this->conteneur->getParametre('admin') != null && $this->conteneur->getParametre('admin') == 1;
69
		return $this->conteneur->getParametre('admin') != null && $this->conteneur->getParametre('admin') == 1;
70
	}
70
	}
71
 
71
 
72
	private function demanderAutorisationAdmin() {
72
	private function demanderAutorisationAdmin() {
73
		$verification = new ControleAcces($this->conteneur);
73
		$verification = new ControleAcces($this->conteneur);
74
		$verification->demanderAuthentificationAdmin();
74
		$verification->demanderAuthentificationAdmin();
75
	}
75
	}
76
 
76
 
77
	private function formaterPourRss($elements) {
77
	private function formaterPourRss($elements) {
78
		$donnees = $this->construireDonneesCommunesAuFlux($elements);
78
		$donnees = $this->construireDonneesCommunesAuFlux($elements);
79
		foreach ($elements as $element) {
79
		foreach ($elements as $element) {
80
			$identifiants[$element['id_commentaire']] = $element['id_commentaire'];
80
			$identifiants[$element['id_commentaire']] = $element['id_commentaire'];
81
		}
81
		}
82
		foreach ($elements as $element) {
82
		foreach ($elements as $element) {
83
			$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
83
			$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
84
		}
84
		}
85
		return $donnees;
85
		return $donnees;
86
	}
86
	}
87
 
87
 
88
	private function construireDonneesCommunesAuFlux($infos) {
88
	private function construireDonneesCommunesAuFlux($infos) {
89
		$donnees = array();
89
		$donnees = array();
90
		$donnees['guid'] = htmlspecialchars($this->creerUrlService());
90
		$donnees['guid'] = htmlspecialchars($this->creerUrlService());
91
		$donnees['titre'] = 'identiPlante : commentaires et propositions';
91
		$donnees['titre'] = 'identiPlante : commentaires et propositions';
92
		$donnees['description'] = 'Ce flux regroupe les dernières déterminations et commentaires rédigés dans l\'application identiPlante';
92
		$donnees['description'] = 'Ce flux regroupe les dernières déterminations et commentaires rédigés dans l\'application identiPlante';
93
		$donnees['lien_service'] = htmlspecialchars($this->creerUrlService());
93
		$donnees['lien_service'] = htmlspecialchars($this->creerUrlService());
94
		$donnees['lien_del'] = $this->conteneur->getParametre('delAppliLien');
94
		$donnees['lien_del'] = $this->conteneur->getParametre('delAppliLien');
95
		$donnees['editeur'] = $this->conteneur->getParametre('editeur');
95
		$donnees['editeur'] = $this->conteneur->getParametre('editeur');
96
		$derniere_info_en_date = reset($infos);
96
		$derniere_info_en_date = reset($infos);
97
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($derniere_info_en_date['date']);
97
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($derniere_info_en_date['date']);
98
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
98
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
99
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
99
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
100
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
100
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
101
		$donnees['annee_courante'] = date('Y');
101
		$donnees['annee_courante'] = date('Y');
102
		$donnees['generateur'] = 'DEL - SyndicationCommentaire';
102
		$donnees['generateur'] = 'DEL - SyndicationCommentaire';
103
		$donnees['generateur_version'] = (preg_match('/([0-9]+)/', '$Revision$', $match)) ?  $match[1] : '0';
103
		$donnees['generateur_version'] = (preg_match('/([0-9]+)/', '$Revision$', $match)) ?  $match[1] : '0';
104
		return $donnees;
104
		return $donnees;
105
	}
105
	}
106
 
106
 
107
	private function creerUrlService() {
107
	private function creerUrlService() {
108
		$url_service = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
108
		$url_service = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
109
		return $url_service;
109
		return $url_service;
110
	}
110
	}
111
 
111
 
112
	private function construireDonneesCommunesAuxItems($info) {
112
	private function construireDonneesCommunesAuxItems($info) {
113
		$item = array();
113
		$item = array();
114
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($info['date']);
114
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($info['date']);
115
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
115
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
116
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
116
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
117
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
117
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
118
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
118
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
119
		$item['titre'] = $this->creerTitre($info);
119
		$item['titre'] = $this->creerTitre($info);
120
		$item['guid'] = $this->creerGuidItem($info);
120
		$item['guid'] = $this->creerGuidItem($info);
121
		$item['lien'] = $this->creerLienItem($info);
121
		$item['lien'] = $this->creerLienItem($info);
122
		$item['categorie'] = $this->creerCategorie($item);
122
		$item['categorie'] = $this->creerCategorie($item);
123
		$item['description'] = $this->creerDescription($info, $item);
123
		$item['description'] = $this->creerDescription($info, $item);
124
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item));
124
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item));
125
		$item['modifier_par'] = $this->creerAuteur($info);
125
		$item['modifier_par'] = $this->creerAuteur($info);
126
		return $item;
126
		return $item;
127
	}
127
	}
128
 
128
 
129
	protected function convertirDateHeureMysqlEnTimestamp($date_heure_mysql){
129
	protected function convertirDateHeureMysqlEnTimestamp($date_heure_mysql){
130
		$timestamp = 1;
130
		$timestamp = 0;
-
 
131
		// Le date de 1970-01-01 pose problème dans certains lecteur de Flux, on met donc la date de création de Tela
-
 
132
		$date_heure_mysql = ($date_heure_mysql == '0000-00-00 00:00:00') ? '1999-12-14 00:00:00' : $date_heure_mysql;
131
		if ($date_heure_mysql != '0000-00-00 00:00:00') {
133
		if ($date_heure_mysql != '0000-00-00 00:00:00') {
132
			$val = explode(' ', $date_heure_mysql);
134
			$val = explode(' ', $date_heure_mysql);
133
			$date = explode('-', $val[0]);
135
			$date = explode('-', $val[0]);
134
			$heure = explode(':', $val[1]);
136
			$heure = explode(':', $val[1]);
135
			$timestamp = mktime((int) $heure[0], (int) $heure[1], (int) $heure[2], (int) $date[1], (int) $date[2], (int) $date[0]);
137
			$timestamp = mktime((int) $heure[0], (int) $heure[1], (int) $heure[2], (int) $date[1], (int) $date[2], (int) $date[0]);
136
		}
138
		}
137
		return $timestamp;
139
		return $timestamp;
138
	}
140
	}
139
 
141
 
140
	private function creerTitre($element) {
142
	private function creerTitre($element) {
141
		$nomPropose = htmlspecialchars($element['nom_sel']);
143
		$nomPropose = htmlspecialchars($element['nom_sel']);
142
		$intitule = ($element['nom_sel'] != '') ? "Proposition $nomPropose" : 'Commentaire';
144
		$intitule = ($element['nom_sel'] != '') ? "Proposition $nomPropose" : 'Commentaire';
143
		$auteur = htmlspecialchars($this->creerAuteur($element));
145
		$auteur = htmlspecialchars($this->creerAuteur($element));
144
		$nomSelActuel = htmlspecialchars($element['dob_nom_sel']);
146
		$nomSelActuel = htmlspecialchars($element['dob_nom_sel']);
145
		$zoneGeo = htmlspecialchars((($element['dob_zone_geo'] != '') ? $element['dob_zone_geo'] : '?'));
147
		$zoneGeo = htmlspecialchars((($element['dob_zone_geo'] != '') ? $element['dob_zone_geo'] : '?'));
146
		$dateObs = htmlspecialchars(strftime('%d %B %Y', strtotime($element['dob_date_observation'])));
148
		$dateObs = htmlspecialchars(strftime('%d %B %Y', strtotime($element['dob_date_observation'])));
147
 
149
 
148
		$titre = "$intitule par $auteur pour $nomSelActuel à $zoneGeo le $dateObs";
150
		$titre = "$intitule par $auteur pour $nomSelActuel à $zoneGeo le $dateObs";
149
		return $titre;
151
		return $titre;
150
	}
152
	}
151
 
153
 
152
	private function creerAuteur($info) {
154
	private function creerAuteur($info) {
153
		$auteur = 'Anonyme';
155
		$auteur = 'Anonyme';
154
		if ($info['utilisateur_prenom'] != '' && $info['utilisateur_nom'] != '') {
156
		if ($info['utilisateur_prenom'] != '' && $info['utilisateur_nom'] != '') {
155
			$auteur = $info['utilisateur_prenom'].' '.$info['utilisateur_nom'];
157
			$auteur = $info['utilisateur_prenom'].' '.$info['utilisateur_nom'];
156
		}
158
		}
157
		return $auteur;
159
		return $auteur;
158
	}
160
	}
159
 
161
 
160
	private function creerGuidItem($element) {
162
	private function creerGuidItem($element) {
161
		$guid = sprintf($this->conteneur->getParametre('guidObsTpl'), $element['id_commentaire']);
163
		$guid = sprintf($this->conteneur->getParametre('guidObsTpl'), $element['id_commentaire']);
162
		return $guid;
164
		return $guid;
163
	}
165
	}
164
 
166
 
165
	private function creerLienItem($element) {
167
	private function creerLienItem($element) {
166
		$lien = sprintf($this->conteneur->getParametre('delFicheObsTpl'), $element['dob_id_observation']);
168
		$lien = sprintf($this->conteneur->getParametre('delFicheObsTpl'), $element['dob_id_observation']);
167
		return $lien;
169
		return $lien;
168
	}
170
	}
169
 
171
 
170
	private function creerCategorie($element) {
172
	private function creerCategorie($element) {
171
		$categorie = 'Commentaires';
173
		$categorie = 'Commentaires';
172
		$categorie = htmlentities($categorie);
174
		$categorie = htmlentities($categorie);
173
		return $categorie;
175
		return $categorie;
174
	}
176
	}
175
 
177
 
176
	private function creerDescription($donnees, $item) {
178
	private function creerDescription($donnees, $item) {
177
		$idCommentaire = $donnees['id_commentaire'];
179
		$idCommentaire = $donnees['id_commentaire'];
178
		$idObs = $donnees['dob_id_observation'];
180
		$idObs = $donnees['dob_id_observation'];
179
		$nomPropose = ($donnees['nom_sel'] != '') ? htmlspecialchars($donnees['nom_sel']) : '';
181
		$nomPropose = ($donnees['nom_sel'] != '') ? htmlspecialchars($donnees['nom_sel']) : '';
180
		$dateCommentaire = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', $this->convertirDateHeureMysqlEnTimestamp($donnees['date'])));
182
		$dateCommentaire = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', $this->convertirDateHeureMysqlEnTimestamp($donnees['date'])));
181
		$nomSelActuel = htmlspecialchars($donnees['dob_nom_sel']);
183
		$nomSelActuel = htmlspecialchars($donnees['dob_nom_sel']);
182
		$etreProposition = ($nomPropose != '') ? true : false;
184
		$etreProposition = ($nomPropose != '') ? true : false;
183
		$intitule = ($etreProposition) ? 'Proposition' : 'Commentaire';
185
		$intitule = ($etreProposition) ? 'Proposition' : 'Commentaire';
184
		$txt = ($donnees['texte'] != '') ? htmlspecialchars($donnees['texte']) : '';
186
		$txt = ($donnees['texte'] != '') ? htmlspecialchars($donnees['texte']) : '';
185
		$auteur = htmlspecialchars($this->creerAuteur($donnees)).
187
		$auteur = htmlspecialchars($this->creerAuteur($donnees)).
186
			($this->fluxAdminDemande() ? ' ('.$donnees['utilisateur_courriel'].')' : '');
188
			($this->fluxAdminDemande() ? ' ('.$donnees['utilisateur_courriel'].')' : '');
187
		$lieuObs = htmlspecialchars((($donnees['dob_zone_geo'] != '') ? $donnees['dob_zone_geo'] : '?'));
189
		$lieuObs = htmlspecialchars((($donnees['dob_zone_geo'] != '') ? $donnees['dob_zone_geo'] : '?'));
188
		$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['dob_date_observation']));
190
		$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['dob_date_observation']));
189
		$observateur = htmlspecialchars($this->creerObservateur($donnees));
191
		$observateur = htmlspecialchars($this->creerObservateur($donnees));
190
 
192
 
191
		$contenuCommentaire = '';
193
		$contenuCommentaire = '';
192
		if ($etreProposition) {
194
		if ($etreProposition) {
193
			$contenuCommentaire =
195
			$contenuCommentaire =
194
				'<li><span class="champ">'."Nom proposé :</span> <em>$nomPropose</em></li>".
196
				'<li><span class="champ">'."Nom proposé :</span> <em>$nomPropose</em></li>".
195
				((!empty($txt)) ? '<li><span class="champ">'."Argumentaire :</span> $txt</li>" : '').
197
				((!empty($txt)) ? '<li><span class="champ">'."Argumentaire :</span> $txt</li>" : '').
196
				'<li><span class="champ">'."Auteur de la proposition :</span> $auteur</li>".
198
				'<li><span class="champ">'."Auteur de la proposition :</span> $auteur</li>".
197
				'<li><span class="champ">'."Proposé le :</span> $dateCommentaire</li>";
199
				'<li><span class="champ">'."Proposé le :</span> $dateCommentaire</li>";
198
		} else {
200
		} else {
199
			$contenuCommentaire =
201
			$contenuCommentaire =
200
				'<li><span class="champ">'."Commentaire #$idCommentaire :</span> <pre>$txt</pre></li>".
202
				'<li><span class="champ">'."Commentaire #$idCommentaire :</span> <pre>$txt</pre></li>".
201
				'<li><span class="champ">'."Auteur du commentaire :</span> $auteur</li>".
203
				'<li><span class="champ">'."Auteur du commentaire :</span> $auteur</li>".
202
				'<li><span class="champ">'."Commenté le :</span> $dateCommentaire</li>";
204
				'<li><span class="champ">'."Commenté le :</span> $dateCommentaire</li>";
203
		}
205
		}
204
 
206
 
205
		$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'.
207
		$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'.
206
			'<h2>'."$intitule identiPlante #$idCommentaire pour l'observation #$idObs".'</h2>'.
208
			'<h2>'."$intitule identiPlante #$idCommentaire pour l'observation #$idObs".'</h2>'.
207
			'<div class="gauche">'.
209
			'<div class="gauche">'.
208
			"	<h3>Observation #$idObs</h3>".
210
			"	<h3>Observation #$idObs</h3>".
209
			'	<ul>'.
211
			'	<ul>'.
210
			'		<li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>".
212
			'		<li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>".
211
			'		<li><span class="champ">'."Lieu :</span> $lieuObs</li>".
213
			'		<li><span class="champ">'."Lieu :</span> $lieuObs</li>".
212
			'		<li><span class="champ">'."Date :</span> $dateObs</li>".
214
			'		<li><span class="champ">'."Date :</span> $dateObs</li>".
213
			'		<li><span class="champ">'."Auteur :</span> $observateur</li>".
215
			'		<li><span class="champ">'."Auteur :</span> $observateur</li>".
214
			'	</ul>'.
216
			'	</ul>'.
215
			'</div>'.
217
			'</div>'.
216
			'<div class="gauche">'.
218
			'<div class="gauche">'.
217
			"	<h3>$intitule #$idCommentaire</h3>".
219
			"	<h3>$intitule #$idCommentaire</h3>".
218
			"	<ul>$contenuCommentaire</ul>".
220
			"	<ul>$contenuCommentaire</ul>".
219
			'</div>';
221
			'</div>';
220
		return $description;
222
		return $description;
221
	}
223
	}
222
 
224
 
223
	private function creerObservateur($info) {
225
	private function creerObservateur($info) {
224
		$observateur = 'Anonyme';
226
		$observateur = 'Anonyme';
225
		if ($info['observateur_prenom'] != '' && $info['observateur_nom'] != '') {
227
		if ($info['observateur_prenom'] != '' && $info['observateur_nom'] != '') {
226
			$observateur = $info['observateur_prenom'].' '.$info['observateur_nom'];
228
			$observateur = $info['observateur_prenom'].' '.$info['observateur_nom'];
227
		}
229
		}
228
		return $observateur;
230
		return $observateur;
229
	}
231
	}
230
 
232
 
231
	private function getDerniersCommentaires() {
233
	private function getDerniersCommentaires() {
232
		$requete = 'SELECT DISTINCT dc.*, '.
234
		$requete = 'SELECT DISTINCT dc.*, '.
233
			'	dob.id_observation AS dob_id_observation, dob.ce_zone_geo AS dob_ce_zone_geo, '.
235
			'	dob.id_observation AS dob_id_observation, dob.ce_zone_geo AS dob_ce_zone_geo, '.
234
			'	dob.zone_geo AS dob_zone_geo, dob.date_observation AS dob_date_observation, dob.nom_sel AS dob_nom_sel, '.
236
			'	dob.zone_geo AS dob_zone_geo, dob.date_observation AS dob_date_observation, dob.nom_sel AS dob_nom_sel, '.
235
			'	duo.prenom AS observateur_prenom, duo.nom AS observateur_nom, duo.courriel AS observateur_courriel '.
237
			'	duo.prenom AS observateur_prenom, duo.nom AS observateur_nom, duo.courriel AS observateur_courriel '.
236
			'FROM del_commentaire AS dc '.
238
			'FROM del_commentaire AS dc '.
237
			'	INNER JOIN del_observation AS dob '.
239
			'	INNER JOIN del_observation AS dob '.
238
			'		ON dob.id_observation = dc.ce_observation '.
240
			'		ON dob.id_observation = dc.ce_observation '.
239
			'	LEFT JOIN del_utilisateur AS duo '.
241
			'	LEFT JOIN del_utilisateur AS duo '.
240
			'		ON dob.ce_utilisateur = duo.id_utilisateur '.
242
			'		ON dob.ce_utilisateur = duo.id_utilisateur '.
241
			'WHERE proposition_initiale != 1 '.
243
			'WHERE proposition_initiale != 1 '.
242
			$this->chargerClauseWhere().' '.
244
			$this->chargerClauseWhere().' '.
243
			'ORDER BY dc.date DESC '.
245
			'ORDER BY dc.date DESC '.
244
			'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' ';
246
			'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' ';
245
 
247
 
246
		$elements = $this->gestionBdd->getBdd()->recupererTous($requete);
248
		$elements = $this->gestionBdd->getBdd()->recupererTous($requete);
247
		return $elements;
249
		return $elements;
248
	}
250
	}
249
 
251
 
250
	/**
252
	/**
251
	* Charger la clause WHERE en fonction des paramètres de masque
253
	* Charger la clause WHERE en fonction des paramètres de masque
252
	* */
254
	* */
253
	private function chargerClauseWhere() {
255
	private function chargerClauseWhere() {
254
		$where = array();
256
		$where = array();
255
 
257
 
256
		$tableauMasque = $this->masque->getMasque();
258
		$tableauMasque = $this->masque->getMasque();
257
		if (!empty($tableauMasque)) {
259
		if (!empty($tableauMasque)) {
258
			foreach ($tableauMasque as $idMasque => $valeurMasque) {
260
			foreach ($tableauMasque as $idMasque => $valeurMasque) {
259
				$idMasque = str_replace('masque.', '', $idMasque);
261
				$idMasque = str_replace('masque.', '', $idMasque);
260
				$champ = $this->mappingFiltre[$idMasque];
262
				$champ = $this->mappingFiltre[$idMasque];
261
				$valeurMasquePattern = $this->gestionBdd->getBdd()->proteger($valeurMasque.'%');
263
				$valeurMasquePattern = $this->gestionBdd->getBdd()->proteger($valeurMasque.'%');
262
				$valeurMasqueProtegee = $this->gestionBdd->getBdd()->proteger($valeurMasque);
264
				$valeurMasqueProtegee = $this->gestionBdd->getBdd()->proteger($valeurMasque);
263
 
265
 
264
				switch ($idMasque) {
266
				switch ($idMasque) {
265
					case 'espece':
267
					case 'espece':
266
						$where[] = " dob.$champ LIKE $valeurMasquePattern OR dc.$champ LIKE $valeurMasquePattern ";
268
						$where[] = " dob.$champ LIKE $valeurMasquePattern OR dc.$champ LIKE $valeurMasquePattern ";
267
						break;
269
						break;
268
					case 'auteur':
270
					case 'auteur':
269
						$where[] = $this->creerFiltreAuteur($valeurMasque);
271
						$where[] = $this->creerFiltreAuteur($valeurMasque);
270
						break;
272
						break;
271
					default:
273
					default:
272
						$where[] = " $champ = $valeurMasqueProtegee ";
274
						$where[] = " $champ = $valeurMasqueProtegee ";
273
				}
275
				}
274
			}
276
			}
275
		}
277
		}
276
 
278
 
277
		$whereSql = '';
279
		$whereSql = '';
278
		if (!empty($where)) {
280
		if (!empty($where)) {
279
			$whereSql = ' AND '.implode('AND', $where);
281
			$whereSql = ' AND '.implode('AND', $where);
280
		}
282
		}
281
		return $whereSql;
283
		return $whereSql;
282
	}
284
	}
283
 
285
 
284
	private function creerFiltreAuteur($auteurId) {
286
	private function creerFiltreAuteur($auteurId) {
285
		$whereAuteur = '';
287
		$whereAuteur = '';
286
		if (is_numeric($auteurId)) {
288
		if (is_numeric($auteurId)) {
287
			$whereAuteur = " dc.ce_utilisateur = $auteurId ";
289
			$whereAuteur = " dc.ce_utilisateur = $auteurId ";
288
		} else {
290
		} else {
289
			$auteurIdMotif = $this->gestionBdd->getBdd()->proteger($auteurId.'%');
291
			$auteurIdMotif = $this->gestionBdd->getBdd()->proteger($auteurId.'%');
290
 
292
 
291
			if (strpos($auteurId, '@') === false) {
293
			if (strpos($auteurId, '@') === false) {
292
				$tableauNomPrenom = explode(' ', $auteurId, 2);
294
				$tableauNomPrenom = explode(' ', $auteurId, 2);
293
				if (count($tableauNomPrenom) == 2) {
295
				if (count($tableauNomPrenom) == 2) {
294
					// on teste potentiellement un nom prenom ou bien un prénom nom
296
					// on teste potentiellement un nom prenom ou bien un prénom nom
295
					$nomMotif = $this->gestionBdd->getBdd()->proteger($tableauNomPrenom[0].'%');
297
					$nomMotif = $this->gestionBdd->getBdd()->proteger($tableauNomPrenom[0].'%');
296
					$prenomMotif = $this->gestionBdd->getBdd()->proteger($tableauNomPrenom[1].'%');
298
					$prenomMotif = $this->gestionBdd->getBdd()->proteger($tableauNomPrenom[1].'%');
297
 
299
 
298
					$whereAuteur = ' ('.
300
					$whereAuteur = ' ('.
299
						"(dc.utilisateur_nom LIKE $nomMotif AND dc.utilisateur_prenom LIKE $prenomMotif) ".
301
						"(dc.utilisateur_nom LIKE $nomMotif AND dc.utilisateur_prenom LIKE $prenomMotif) ".
300
						'OR '.
302
						'OR '.
301
						"(dc.utilisateur_nom LIKE $nomMotif AND dc.utilisateur_prenom LIKE $prenomMotif) ".
303
						"(dc.utilisateur_nom LIKE $nomMotif AND dc.utilisateur_prenom LIKE $prenomMotif) ".
302
					') ';
304
					') ';
303
				} else {
305
				} else {
304
					$whereAuteur = "(dc.utilisateur_nom LIKE $auteurIdMotif OR dc.utilisateur_prenom LIKE $auteurIdMotif) ";
306
					$whereAuteur = "(dc.utilisateur_nom LIKE $auteurIdMotif OR dc.utilisateur_prenom LIKE $auteurIdMotif) ";
305
				}
307
				}
306
			} else {
308
			} else {
307
				$whereAuteur = " dob.utilisateur_courriel LIKE $auteurIdMotif ";
309
				$whereAuteur = " dob.utilisateur_courriel LIKE $auteurIdMotif ";
308
			}
310
			}
309
		}
311
		}
310
		return $whereAuteur;
312
		return $whereAuteur;
311
	}
313
	}
312
}
314
}
313
?>
315
?>