Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1294 Rev 1304
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
		} else {
56
		} else {
57
			$champsMappingFiltre = array('espece', 'observation');
57
			$champsMappingFiltre = array('espece', 'observation');
58
			foreach ($champsMappingFiltre as $champ) {
58
			foreach ($champsMappingFiltre as $champ) {
59
				if (!isset($this->mappingFiltre[$champ])) {
59
				if (!isset($this->mappingFiltre[$champ])) {
60
					$erreurs[] = '- le mapping du champ "'.$champ.'" pour le commentaire est manquant ;';
60
					$erreurs[] = '- le mapping du champ "'.$champ.'" pour le commentaire est manquant ;';
61
				}
61
				}
62
			}
62
			}
63
		}
63
		}
64
 
64
 
65
		if (!empty($erreurs)) {
65
		if (!empty($erreurs)) {
66
			$e = 'Erreur lors de la configuration : '."\n";
66
			$e = 'Erreur lors de la configuration : '."\n";
67
			$e .= implode("\n", $erreurs);
67
			$e .= implode("\n", $erreurs);
68
			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
68
			throw new Exception($e, RestServeur::HTTP_CODE_ERREUR);
69
		}
69
		}
70
	}
70
	}
71
 
71
 
72
	/**
72
	/**
73
	 * Verifier si le flux admin est demande
73
	 * Verifier si le flux admin est demande
74
	 */
74
	 */
75
	private function fluxAdminDemande() {
75
	private function fluxAdminDemande() {
76
		return $this->conteneur->getParametre('admin') != null && $this->conteneur->getParametre('admin') == 1;
76
		return $this->conteneur->getParametre('admin') != null && $this->conteneur->getParametre('admin') == 1;
77
	}
77
	}
78
 
78
 
79
	private function demanderAutorisationAdmin() {
79
	private function demanderAutorisationAdmin() {
80
		$verification = new ControleAcces($this->conteneur);
80
		$verification = new ControleAcces($this->conteneur);
81
		$verification->demanderAuthentificationAdmin();
81
		$verification->demanderAuthentificationAdmin();
82
	}
82
	}
83
 
83
 
84
	private function formaterPourRss($elements) {
84
	private function formaterPourRss($elements) {
85
		$donnees = $this->construireDonneesCommunesAuFlux($elements);
85
		$donnees = $this->construireDonneesCommunesAuFlux($elements);
86
		foreach ($elements as $element) {
86
		foreach ($elements as $element) {
87
			$identifiants[$element['id_commentaire']] = $element['id_commentaire'];
87
			$identifiants[$element['id_commentaire']] = $element['id_commentaire'];
88
		}
88
		}
89
		foreach ($elements as $element) {
89
		foreach ($elements as $element) {
90
			$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
90
			$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
91
		}
91
		}
92
		return $donnees;
92
		return $donnees;
93
	}
93
	}
94
 
94
 
95
	private function construireDonneesCommunesAuFlux($infos) {
95
	private function construireDonneesCommunesAuFlux($infos) {
96
		$donnees = array();
96
		$donnees = array();
97
		$donnees['guid'] = $this->creerUrlService();
97
		$donnees['guid'] = $this->creerUrlService();
98
		$donnees['titre'] = 'identiPlante : commentaires et propositions';
98
		$donnees['titre'] = 'identiPlante : commentaires et propositions';
99
		$donnees['description'] = 'Ce flux regroupe les dernières déterminations et commentaires rédigés dans l\'application identiPlante';
99
		$donnees['description'] = 'Ce flux regroupe les dernières déterminations et commentaires rédigés dans l\'application identiPlante';
100
		$donnees['lien_service'] = $this->creerUrlService();
100
		$donnees['lien_service'] = $this->creerUrlService();
101
		$donnees['lien_del'] = $this->conteneur->getParametre('delAppliLien');
101
		$donnees['lien_del'] = $this->conteneur->getParametre('delAppliLien');
102
		$donnees['editeur'] = $this->conteneur->getParametre('editeur');
102
		$donnees['editeur'] = $this->conteneur->getParametre('editeur');
103
		$derniere_info_en_date = reset($infos);
103
		$derniere_info_en_date = reset($infos);
104
		$date_modification_timestamp = strtotime($derniere_info_en_date['date']);
104
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($derniere_info_en_date['date']);
105
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
105
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
106
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
106
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
107
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
107
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
108
		$donnees['annee_courante'] = date('Y');
108
		$donnees['annee_courante'] = date('Y');
109
		$donnees['generateur'] = 'DEL - SyndicationCommentaire';
109
		$donnees['generateur'] = 'DEL - SyndicationCommentaire';
110
		$donnees['generateur_version'] = (preg_match('/([0-9]+)/', '$Revision$', $match)) ?  $match[1] : '0';
110
		$donnees['generateur_version'] = (preg_match('/([0-9]+)/', '$Revision$', $match)) ?  $match[1] : '0';
111
		return $donnees;
111
		return $donnees;
112
	}
112
	}
113
 
113
 
114
	private function creerUrlService() {
114
	private function creerUrlService() {
115
		$url_service = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
115
		$url_service = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
116
		return $url_service;
116
		return $url_service;
117
	}
117
	}
118
 
118
 
119
	private function construireDonneesCommunesAuxItems($info) {
119
	private function construireDonneesCommunesAuxItems($info) {
120
		$item = array();
120
		$item = array();
121
		$date_modification_timestamp = strtotime($info['date']);
121
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($info['date']);
122
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
122
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
123
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
123
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
124
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
124
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
125
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
125
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
126
		$item['titre'] = $this->creerTitre($info);
126
		$item['titre'] = $this->creerTitre($info);
127
		$item['guid'] = $this->creerGuidItem($info);
127
		$item['guid'] = $this->creerGuidItem($info);
128
		$item['lien'] = $this->creerLienItem($info);
128
		$item['lien'] = $this->creerLienItem($info);
129
		$item['categorie'] = $this->creerCategorie($item);
129
		$item['categorie'] = $this->creerCategorie($item);
130
		$item['description'] = $this->creerDescription($info, $item);
130
		$item['description'] = $this->creerDescription($info, $item);
131
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item));
131
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item));
132
		$item['modifier_par'] = $this->creerAuteur($info);
132
		$item['modifier_par'] = $this->creerAuteur($info);
133
		return $item;
133
		return $item;
134
	}
134
	}
-
 
135
 
-
 
136
	protected function convertirDateHeureMysqlEnTimestamp($date_heure_mysql){
-
 
137
		$timestamp = 1;
-
 
138
		if ($date_heure_mysql != '0000-00-00 00:00:00') {
-
 
139
			$val = explode(' ', $date_heure_mysql);
-
 
140
			$date = explode('-', $val[0]);
-
 
141
			$heure = explode(':', $val[1]);
-
 
142
			$timestamp = mktime((int) $heure[0], (int) $heure[1], (int) $heure[2], (int) $date[1], (int) $date[2], (int) $date[0]);
-
 
143
		}
-
 
144
		return $timestamp;
-
 
145
	}
135
 
146
 
136
	private function creerTitre($element) {
147
	private function creerTitre($element) {
137
		$nomPropose = htmlspecialchars($element['nom_sel']);
148
		$nomPropose = htmlspecialchars($element['nom_sel']);
138
		$intitule = ($element['nom_sel'] != '') ? "Proposition $nomPropose" : 'Commentaire';
149
		$intitule = ($element['nom_sel'] != '') ? "Proposition $nomPropose" : 'Commentaire';
139
		$auteur = htmlspecialchars($this->creerAuteur($element));
150
		$auteur = htmlspecialchars($this->creerAuteur($element));
140
		$nomSelActuel = htmlspecialchars($element['dob_nom_sel']);
151
		$nomSelActuel = htmlspecialchars($element['dob_nom_sel']);
141
		$zoneGeo = htmlspecialchars((($element['dob_zone_geo'] != '') ? $element['dob_zone_geo'] : '?'));
152
		$zoneGeo = htmlspecialchars((($element['dob_zone_geo'] != '') ? $element['dob_zone_geo'] : '?'));
142
		$dateObs = htmlspecialchars(strftime('%d %B %Y', strtotime($element['dob_date_observation'])));
153
		$dateObs = htmlspecialchars(strftime('%d %B %Y', strtotime($element['dob_date_observation'])));
143
 
154
 
144
		$titre = "$intitule par $auteur pour $nomSelActuel à $zoneGeo le $dateObs";
155
		$titre = "$intitule par $auteur pour $nomSelActuel à $zoneGeo le $dateObs";
145
		return $titre;
156
		return $titre;
146
	}
157
	}
147
 
158
 
148
	private function creerAuteur($info) {
159
	private function creerAuteur($info) {
149
		$auteur = 'Anonyme';
160
		$auteur = 'Anonyme';
150
		if ($info['utilisateur_prenom'] != '' && $info['utilisateur_nom'] != '') {
161
		if ($info['utilisateur_prenom'] != '' && $info['utilisateur_nom'] != '') {
151
			$auteur = $info['utilisateur_prenom'].' '.$info['utilisateur_nom'];
162
			$auteur = $info['utilisateur_prenom'].' '.$info['utilisateur_nom'];
152
		}
163
		}
153
		return $auteur;
164
		return $auteur;
154
	}
165
	}
155
 
166
 
156
	private function creerGuidItem($element) {
167
	private function creerGuidItem($element) {
157
		$guid = sprintf($this->conteneur->getParametre('guidObsTpl'), $element['id_commentaire']);
168
		$guid = sprintf($this->conteneur->getParametre('guidObsTpl'), $element['id_commentaire']);
158
		return $guid;
169
		return $guid;
159
	}
170
	}
160
 
171
 
161
	private function creerLienItem($element) {
172
	private function creerLienItem($element) {
162
		$lien = sprintf($this->conteneur->getParametre('delFicheObsTpl'), $element['dob_id_observation']);
173
		$lien = sprintf($this->conteneur->getParametre('delFicheObsTpl'), $element['dob_id_observation']);
163
		return $lien;
174
		return $lien;
164
	}
175
	}
165
 
176
 
166
	private function creerCategorie($element) {
177
	private function creerCategorie($element) {
167
		$categorie = 'Commentaires';
178
		$categorie = 'Commentaires';
168
		$categorie = htmlentities($categorie);
179
		$categorie = htmlentities($categorie);
169
		return $categorie;
180
		return $categorie;
170
	}
181
	}
171
 
182
 
172
	private function creerDescription($donnees, $item) {
183
	private function creerDescription($donnees, $item) {
173
		$idCommentaire = $donnees['id_commentaire'];
184
		$idCommentaire = $donnees['id_commentaire'];
174
		$idObs = $donnees['dob_id_observation'];
185
		$idObs = $donnees['dob_id_observation'];
175
		$nomPropose = ($donnees['nom_sel'] != '') ? htmlspecialchars($donnees['nom_sel']) : '';
186
		$nomPropose = ($donnees['nom_sel'] != '') ? htmlspecialchars($donnees['nom_sel']) : '';
176
		$dateCommentaire = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', strtotime($donnees['date'])));
187
		$dateCommentaire = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', $this->convertirDateHeureMysqlEnTimestamp($donnees['date'])));
177
		$nomSelActuel = htmlspecialchars($donnees['dob_nom_sel']);
188
		$nomSelActuel = htmlspecialchars($donnees['dob_nom_sel']);
178
		$etreProposition = ($nomPropose != '') ? true : false;
189
		$etreProposition = ($nomPropose != '') ? true : false;
179
		$intitule = ($etreProposition) ? 'Proposition' : 'Commentaire';
190
		$intitule = ($etreProposition) ? 'Proposition' : 'Commentaire';
180
		$txt = ($donnees['texte'] != '') ? htmlspecialchars($donnees['texte']) : '';
191
		$txt = ($donnees['texte'] != '') ? htmlspecialchars($donnees['texte']) : '';
181
		$auteur = htmlspecialchars($this->creerAuteur($donnees)).
192
		$auteur = htmlspecialchars($this->creerAuteur($donnees)).
182
			($this->fluxAdminDemande() ? ' ('.$donnees['utilisateur_courriel'].')' : '');
193
			($this->fluxAdminDemande() ? ' ('.$donnees['utilisateur_courriel'].')' : '');
183
		$lieuObs = htmlspecialchars((($donnees['dob_zone_geo'] != '') ? $donnees['dob_zone_geo'] : '?'));
194
		$lieuObs = htmlspecialchars((($donnees['dob_zone_geo'] != '') ? $donnees['dob_zone_geo'] : '?'));
184
		$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['dob_date_observation']));
195
		$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['dob_date_observation']));
185
		$observateur = htmlspecialchars($this->creerObservateur($donnees));
196
		$observateur = htmlspecialchars($this->creerObservateur($donnees));
186
 
197
 
187
		$contenuCommentaire = '';
198
		$contenuCommentaire = '';
188
		if ($etreProposition) {
199
		if ($etreProposition) {
189
			$contenuCommentaire =
200
			$contenuCommentaire =
190
				'<li><span class="champ">'."Nom proposé :</span> <em>$nomPropose</em></li>".
201
				'<li><span class="champ">'."Nom proposé :</span> <em>$nomPropose</em></li>".
191
				((!empty($txt)) ? '<li><span class="champ">'."Argumentaire :</span> $txt</li>" : '').
202
				((!empty($txt)) ? '<li><span class="champ">'."Argumentaire :</span> $txt</li>" : '').
192
				'<li><span class="champ">'."Auteur de la proposition :</span> $auteur</li>".
203
				'<li><span class="champ">'."Auteur de la proposition :</span> $auteur</li>".
193
				'<li><span class="champ">'."Proposé le :</span> $dateCommentaire</li>";
204
				'<li><span class="champ">'."Proposé le :</span> $dateCommentaire</li>";
194
		} else {
205
		} else {
195
			$contenuCommentaire =
206
			$contenuCommentaire =
196
				'<li><span class="champ">'."Commentaire #$idCommentaire :</span> <pre>$txt</pre></li>".
207
				'<li><span class="champ">'."Commentaire #$idCommentaire :</span> <pre>$txt</pre></li>".
197
				'<li><span class="champ">'."Auteur du commentaire :</span> $auteur</li>".
208
				'<li><span class="champ">'."Auteur du commentaire :</span> $auteur</li>".
198
				'<li><span class="champ">'."Commenté le :</span> $dateCommentaire</li>";
209
				'<li><span class="champ">'."Commenté le :</span> $dateCommentaire</li>";
199
		}
210
		}
200
 
211
 
201
		$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'.
212
		$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'.
202
			'<h2>'."$intitule identiPlante #$idCommentaire pour l'observation #$idObs".'</h2>'.
213
			'<h2>'."$intitule identiPlante #$idCommentaire pour l'observation #$idObs".'</h2>'.
203
			'<div class="gauche">'.
214
			'<div class="gauche">'.
204
			"	<h3>Observation #$idObs</h3>".
215
			"	<h3>Observation #$idObs</h3>".
205
			'	<ul>'.
216
			'	<ul>'.
206
			'		<li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>".
217
			'		<li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>".
207
			'		<li><span class="champ">'."Lieu :</span> $lieuObs</li>".
218
			'		<li><span class="champ">'."Lieu :</span> $lieuObs</li>".
208
			'		<li><span class="champ">'."Date :</span> $dateObs</li>".
219
			'		<li><span class="champ">'."Date :</span> $dateObs</li>".
209
			'		<li><span class="champ">'."Auteur :</span> $observateur</li>".
220
			'		<li><span class="champ">'."Auteur :</span> $observateur</li>".
210
			'	</ul>'.
221
			'	</ul>'.
211
			'</div>'.
222
			'</div>'.
212
			'<div class="gauche">'.
223
			'<div class="gauche">'.
213
			"	<h3>$intitule #$idCommentaire</h3>".
224
			"	<h3>$intitule #$idCommentaire</h3>".
214
			"	<ul>$contenuCommentaire</ul>".
225
			"	<ul>$contenuCommentaire</ul>".
215
			'</div>';
226
			'</div>';
216
		return $description;
227
		return $description;
217
	}
228
	}
218
 
229
 
219
	private function creerObservateur($info) {
230
	private function creerObservateur($info) {
220
		$observateur = 'Anonyme';
231
		$observateur = 'Anonyme';
221
		if ($info['observateur_prenom'] != '' && $info['observateur_nom'] != '') {
232
		if ($info['observateur_prenom'] != '' && $info['observateur_nom'] != '') {
222
			$observateur = $info['observateur_prenom'].' '.$info['observateur_nom'];
233
			$observateur = $info['observateur_prenom'].' '.$info['observateur_nom'];
223
		}
234
		}
224
		return $observateur;
235
		return $observateur;
225
	}
236
	}
226
 
237
 
227
	private function getDerniersCommentaires() {
238
	private function getDerniersCommentaires() {
228
		$requete = 'SELECT DISTINCT dc.*, '.
239
		$requete = 'SELECT DISTINCT dc.*, '.
229
			'	dob.id_observation AS dob_id_observation, dob.ce_zone_geo AS dob_ce_zone_geo, '.
240
			'	dob.id_observation AS dob_id_observation, dob.ce_zone_geo AS dob_ce_zone_geo, '.
230
			'	dob.zone_geo AS dob_zone_geo, dob.date_observation AS dob_date_observation, dob.nom_sel AS dob_nom_sel, '.
241
			'	dob.zone_geo AS dob_zone_geo, dob.date_observation AS dob_date_observation, dob.nom_sel AS dob_nom_sel, '.
231
			'	duo.prenom AS observateur_prenom, duo.nom AS observateur_nom, duo.courriel AS observateur_courriel '.
242
			'	duo.prenom AS observateur_prenom, duo.nom AS observateur_nom, duo.courriel AS observateur_courriel '.
232
			'FROM del_commentaire AS dc '.
243
			'FROM del_commentaire AS dc '.
233
			'	INNER JOIN del_observation AS dob '.
244
			'	INNER JOIN del_observation AS dob '.
234
			'		ON dob.id_observation = dc.ce_observation '.
245
			'		ON dob.id_observation = dc.ce_observation '.
235
			'	LEFT JOIN del_utilisateur AS duo '.
246
			'	LEFT JOIN del_utilisateur AS duo '.
236
			'		ON dob.ce_utilisateur = duo.id_utilisateur '.
247
			'		ON dob.ce_utilisateur = duo.id_utilisateur '.
237
			'WHERE ((dob.ce_utilisateur = dc.ce_utilisateur AND dob.nom_sel != dc.nom_sel) '.
248
			'WHERE ((dob.ce_utilisateur = dc.ce_utilisateur AND dob.nom_sel != dc.nom_sel) '.
238
			'	OR (dob.ce_utilisateur != dc.ce_utilisateur)) '.// Evite d'afficher les proposition initiale
249
			'	OR (dob.ce_utilisateur != dc.ce_utilisateur)) '.// Evite d'afficher les proposition initiale
239
			$this->chargerClauseWhere().' '.
250
			$this->chargerClauseWhere().' '.
240
			'ORDER BY dc.date DESC '.
251
			'ORDER BY dc.date DESC '.
241
			'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' ';
252
			'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' ';
242
 
253
 
243
		$elements = $this->gestionBdd->getBdd()->recupererTous($requete);
254
		$elements = $this->gestionBdd->getBdd()->recupererTous($requete);
244
		return $elements;
255
		return $elements;
245
	}
256
	}
246
 
257
 
247
	/**
258
	/**
248
	* Charger la clause WHERE en fonction des paramètres de masque
259
	* Charger la clause WHERE en fonction des paramètres de masque
249
	* */
260
	* */
250
	private function chargerClauseWhere() {
261
	private function chargerClauseWhere() {
251
		$where = array();
262
		$where = array();
252
		$tableauMasque = $this->masque->getMasque();
263
		$tableauMasque = $this->masque->getMasque();
253
		if (!empty($tableauMasque)) {
264
		if (!empty($tableauMasque)) {
254
			foreach($tableauMasque as $idMasque => $valeurMasque) {
265
			foreach($tableauMasque as $idMasque => $valeurMasque) {
255
				$idMasque = str_replace('masque.', '', $idMasque);
266
				$idMasque = str_replace('masque.', '', $idMasque);
256
				switch ($idMasque) {
267
				switch ($idMasque) {
257
					case 'espece':
268
					case 'espece':
258
						$where[] = ' dob.'.$this->mappingFiltre[$idMasque].
269
						$where[] = ' dob.'.$this->mappingFiltre[$idMasque].
259
							' LIKE '.$this->gestionBdd->getBdd()->proteger($valeurMasque.'%').' '.
270
							' LIKE '.$this->gestionBdd->getBdd()->proteger($valeurMasque.'%').' '.
260
							' OR '.' dc.'.$this->mappingFiltre[$idMasque].
271
							' OR '.' dc.'.$this->mappingFiltre[$idMasque].
261
							' LIKE '.$this->gestionBdd->getBdd()->proteger($valeurMasque.'%').' ';
272
							' LIKE '.$this->gestionBdd->getBdd()->proteger($valeurMasque.'%').' ';
262
						break;
273
						break;
263
					case 'auteur':
274
					case 'auteur':
264
						$where[] = $this->creerFiltreAuteur($valeurMasque).' ';
275
						$where[] = $this->creerFiltreAuteur($valeurMasque).' ';
265
						break;
276
						break;
266
					default:
277
					default:
267
						$where[] = ' '.$this->mappingFiltre[$idMasque].' = '.$this->gestionBdd->getBdd()->proteger($valeurMasque);
278
						$where[] = ' '.$this->mappingFiltre[$idMasque].' = '.$this->gestionBdd->getBdd()->proteger($valeurMasque);
268
				}
279
				}
269
			}
280
			}
270
		}
281
		}
271
		if (!empty($where)) {
282
		if (!empty($where)) {
272
			return ' AND '.implode('AND', $where);
283
			return ' AND '.implode('AND', $where);
273
		} else {
284
		} else {
274
			return;
285
			return;
275
		}
286
		}
276
	}
287
	}
277
 
288
 
278
	private function creerFiltreAuteur($auteurId) {
289
	private function creerFiltreAuteur($auteurId) {
279
		$masque = '';
290
		$masque = '';
280
		if (is_numeric($auteurId)) {
291
		if (is_numeric($auteurId)) {
281
			$masque = " dc.ce_utilisateur = $auteurId ";
292
			$masque = " dc.ce_utilisateur = $auteurId ";
282
		} else {
293
		} else {
283
			$auteurIdMotif = $this->gestionBdd->getBdd()->proteger($auteurId.'%');
294
			$auteurIdMotif = $this->gestionBdd->getBdd()->proteger($auteurId.'%');
284
 
295
 
285
			if (strpos($auteurId, '@') === false) {
296
			if (strpos($auteurId, '@') === false) {
286
				$tableauNomPrenom = explode(' ', $auteurId, 2);
297
				$tableauNomPrenom = explode(' ', $auteurId, 2);
287
				if (count($tableauNomPrenom) == 2) {
298
				if (count($tableauNomPrenom) == 2) {
288
					// on teste potentiellement un nom prenom ou bien un prénom nom
299
					// on teste potentiellement un nom prenom ou bien un prénom nom
289
					$nomMotif = $this->gestionBdd->getBdd()->proteger($tableauNomPrenom[0].'%');
300
					$nomMotif = $this->gestionBdd->getBdd()->proteger($tableauNomPrenom[0].'%');
290
					$prenomMotif = $this->gestionBdd->getBdd()->proteger($tableauNomPrenom[1].'%');
301
					$prenomMotif = $this->gestionBdd->getBdd()->proteger($tableauNomPrenom[1].'%');
291
 
302
 
292
					$masque = '('.
303
					$masque = '('.
293
						"(dc.utilisateur_nom LIKE $nomMotif AND dc.utilisateur_prenom LIKE $prenomMotif) ".
304
						"(dc.utilisateur_nom LIKE $nomMotif AND dc.utilisateur_prenom LIKE $prenomMotif) ".
294
						'OR '.
305
						'OR '.
295
						"(dc.utilisateur_nom LIKE $nomMotif AND dc.utilisateur_prenom LIKE $prenomMotif) ".
306
						"(dc.utilisateur_nom LIKE $nomMotif AND dc.utilisateur_prenom LIKE $prenomMotif) ".
296
					')';
307
					')';
297
				} else {
308
				} else {
298
					$masque = "(dc.utilisateur_nom LIKE $auteurIdMotif OR dc.utilisateur_prenom LIKE $auteurIdMotif) ";
309
					$masque = "(dc.utilisateur_nom LIKE $auteurIdMotif OR dc.utilisateur_prenom LIKE $auteurIdMotif) ";
299
				}
310
				}
300
			} else {
311
			} else {
301
				$masque = " dob.utilisateur_courriel LIKE $auteurIdMotif ";
312
				$masque = " dob.utilisateur_courriel LIKE $auteurIdMotif ";
302
			}
313
			}
303
		}
314
		}
304
		return $masque;
315
		return $masque;
305
	}
316
	}
306
}
317
}
307
?>
318
?>