Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1997 Rev 2006
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Service fournissant des informations concernant les commentaire de DEL au format RSS1, RSS2 ou ATOM.
4
 * Service fournissant des informations concernant les commentaire de DEL au format RSS1, RSS2 ou ATOM.
5
 *
5
 *
6
 * @category   DEL
6
 * @category   DEL
7
 * @package    Services
7
 * @package    Services
8
 * @subpackage Syndication
8
 * @subpackage Syndication
9
 * @version    0.1
9
 * @version    0.1
10
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
10
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
11
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
11
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
12
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
13
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
13
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
14
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
14
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
15
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
15
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
16
 */
16
 */
17
class Commentaires {
17
class Commentaires {
18
 
18
 
19
	private $categorie = 'Commentaires';
19
	private $categorie = 'Commentaires';
20
	private $conteneur;
20
	private $conteneur;
21
	private $contexte;
21
	private $contexte;
22
	private $bdd;
22
	private $bdd;
23
	private $navigation;
23
	private $navigation;
24
	private $mapping = array();
24
	private $mapping = array();
25
	private $syndication;
25
	private $syndication;
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->contexte = $this->conteneur->getContexte();
29
		$this->contexte = $this->conteneur->getContexte();
30
		$this->bdd = $this->conteneur->getBdd();
30
		$this->bdd = $this->conteneur->getBdd();
31
		$this->navigation = $this->conteneur->getNavigation();
31
		$this->navigation = $this->conteneur->getNavigation();
32
		$this->syndication = $this->conteneur->getSyndicationOutils();
32
		$this->syndication = $this->conteneur->getSyndicationOutils();
33
		$this->mapping = $this->conteneur->getParametreTableau('syndication.mapping');
33
		$this->mapping = $this->conteneur->getParametreTableau('syndication.mapping');
34
	}
34
	}
35
 
35
 
36
	public function consulter() {
36
	public function consulter() {
37
		if ($this->syndication->fluxAdminDemande()) {
37
		if ($this->syndication->fluxAdminDemande()) {
38
			$this->syndication->demanderAutorisationAdmin();
38
			$this->syndication->demanderAutorisationAdmin();
39
		}
39
		}
40
 
40
 
41
		$donnees_brutes = $this->getDerniersCommentaires();
41
		$donnees_brutes = $this->getDerniersCommentaires();
42
		$commentaires_formates = $this->formaterPourRss($donnees_brutes) ;
42
		$commentaires_formates = $this->formaterPourRss($donnees_brutes) ;
43
		return $commentaires_formates;
43
		return $commentaires_formates;
44
	}
44
	}
45
 
45
 
46
	private function formaterPourRss($elements) {
46
	private function formaterPourRss($elements) {
47
		$derniere_info_en_date = reset($elements);
47
		$derniere_info_en_date = reset($elements);
48
		$donnees = $this->syndication->construireDonneesCommunesAuFlux('commentaire', $derniere_info_en_date['date']);
48
		$donnees = $this->syndication->construireDonneesCommunesAuFlux('commentaire', $derniere_info_en_date['date']);
49
		foreach ($elements as $element) {
49
		foreach ($elements as $element) {
50
			$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
50
			$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
51
		}
51
		}
52
		return $donnees;
52
		return $donnees;
53
	}
53
	}
54
 
54
 
55
	private function construireDonneesCommunesAuxItems($info) {
55
	private function construireDonneesCommunesAuxItems($info) {
56
		$item = array();
56
		$item = array();
57
		$date_modification_timestamp = $this->syndication->convertirDateHeureMysqlEnTimestamp($info['date']);
57
		$date_modification_timestamp = $this->syndication->convertirDateHeureMysqlEnTimestamp($info['date']);
58
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
58
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
59
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
59
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
60
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
60
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
61
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
61
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
62
		$item['titre'] = $this->creerTitre($info);
62
		$item['titre'] = $this->creerTitre($info);
63
		$item['guid'] = $this->creerGuidItem($info);
63
		$item['guid'] = $this->creerGuidItem($info);
64
		$item['lien'] = $this->creerLienItem($info);
64
		$item['lien'] = $this->creerLienItem($info);
65
		$item['categorie'] = htmlentities($this->categorie);
65
		$item['categorie'] = htmlentities($this->categorie);
66
		$item['description'] = $this->creerDescription($info, $item);
66
		$item['description'] = $this->creerDescription($info, $item);
67
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item));
67
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($info, $item));
68
		$item['modifier_par'] = $this->creerAuteur($info);
68
		$item['modifier_par'] = $this->creerAuteur($info);
69
		return $item;
69
		return $item;
70
	}
70
	}
71
 
71
 
72
	private function creerTitre($element) {
72
	private function creerTitre($element) {
73
		$nomPropose = htmlspecialchars($element['nom_sel']);
73
		$nomPropose = htmlspecialchars($element['nom_sel']);
74
		$intitule = ($element['nom_sel'] != '') ? "Proposition $nomPropose" : 'Commentaire';
74
		$intitule = ($element['nom_sel'] != '') ? "Proposition $nomPropose" : 'Commentaire';
75
		$auteur = htmlspecialchars($this->creerAuteur($element));
75
		$auteur = htmlspecialchars($this->creerAuteur($element));
76
		$nomSelActuel = htmlspecialchars($element['dob_nom_sel']);
76
		$nomSelActuel = htmlspecialchars($element['dob_nom_sel']);
77
		$zoneGeo = htmlspecialchars((($element['dob_zone_geo'] != '') ? $element['dob_zone_geo'] : '?'));
77
		$zoneGeo = htmlspecialchars((($element['dob_zone_geo'] != '') ? $element['dob_zone_geo'] : '?'));
-
 
78
		$dateObs = '?';
-
 
79
		if (strpos($element['dob_date_observation'], '0000') === false) {
78
		$dateObs = htmlspecialchars(strftime('%d %B %Y', strtotime($element['dob_date_observation'])));
80
			$dateObs = htmlspecialchars(strftime('%d %B %Y', strtotime($element['dob_date_observation'])));
-
 
81
		}
79
 
82
 
80
		$titre = "$intitule par $auteur pour $nomSelActuel à $zoneGeo le $dateObs";
83
		$titre = "$intitule par $auteur pour $nomSelActuel à $zoneGeo le $dateObs";
81
		return $titre;
84
		return $titre;
82
	}
85
	}
83
 
86
 
84
	private function creerAuteur($info) {
87
	private function creerAuteur($info) {
85
		$auteur = 'Anonyme';
88
		$auteur = 'Anonyme';
86
		if ($info['utilisateur_prenom'] != '' && $info['utilisateur_nom'] != '') {
89
		if ($info['utilisateur_prenom'] != '' && $info['utilisateur_nom'] != '') {
87
			$auteur = $info['utilisateur_prenom'].' '.$info['utilisateur_nom'];
90
			$auteur = $info['utilisateur_prenom'].' '.$info['utilisateur_nom'];
88
		}
91
		}
89
		return $auteur;
92
		return $auteur;
90
	}
93
	}
91
 
94
 
92
	private function creerGuidItem($element) {
95
	private function creerGuidItem($element) {
93
		$guid = sprintf($this->conteneur->getParametre('syndication.commentaire_guid_tpl'), $element['id_commentaire']);
96
		$guid = sprintf($this->conteneur->getParametre('syndication.commentaire_guid_tpl'), $element['id_commentaire']);
94
		return $guid;
97
		return $guid;
95
	}
98
	}
96
 
99
 
97
	private function creerLienItem($element) {
100
	private function creerLienItem($element) {
98
		$lien = sprintf($this->conteneur->getParametre('obs_fiche_tpl'), $element['dob_id_observation']);
101
		$lien = sprintf($this->conteneur->getParametre('obs_fiche_tpl'), $element['dob_id_observation']);
99
		return $lien;
102
		return $lien;
100
	}
103
	}
101
 
104
 
102
	private function creerDescription($donnees, $item) {
105
	private function creerDescription($donnees, $item) {
103
		$idCommentaire = $donnees['id_commentaire'];
106
		$idCommentaire = $donnees['id_commentaire'];
104
		$idObs = $donnees['dob_id_observation'];
107
		$idObs = $donnees['dob_id_observation'];
105
		$nomPropose = ($donnees['nom_sel'] != '') ? htmlspecialchars($donnees['nom_sel']) : '';
108
		$nomPropose = ($donnees['nom_sel'] != '') ? htmlspecialchars($donnees['nom_sel']) : '';
106
		$dateCommentaire = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', $this->syndication->convertirDateHeureMysqlEnTimestamp($donnees['date'])));
109
		$dateCommentaire = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', $this->syndication->convertirDateHeureMysqlEnTimestamp($donnees['date'])));
107
		$nomSelActuel = htmlspecialchars($donnees['dob_nom_sel']);
110
		$nomSelActuel = htmlspecialchars($donnees['dob_nom_sel']);
108
		$etreProposition = ($nomPropose != '') ? true : false;
111
		$etreProposition = ($nomPropose != '') ? true : false;
109
		$intitule = ($etreProposition) ? 'Proposition' : 'Commentaire';
112
		$intitule = ($etreProposition) ? 'Proposition' : 'Commentaire';
110
		$txt = ($donnees['texte'] != '') ? htmlspecialchars($donnees['texte']) : '';
113
		$txt = ($donnees['texte'] != '') ? htmlspecialchars($donnees['texte']) : '';
111
		$auteur = htmlspecialchars($this->creerAuteur($donnees)).
114
		$auteur = htmlspecialchars($this->creerAuteur($donnees)).
112
			($this->syndication->fluxAdminDemande() ? ' ('.$donnees['utilisateur_courriel'].')' : '');
115
			($this->syndication->fluxAdminDemande() ? ' ('.$donnees['utilisateur_courriel'].')' : '');
113
		$lieuObs = htmlspecialchars((($donnees['dob_zone_geo'] != '') ? $donnees['dob_zone_geo'] : '?'));
116
		$lieuObs = htmlspecialchars((($donnees['dob_zone_geo'] != '') ? $donnees['dob_zone_geo'] : '?'));
114
		$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['dob_date_observation']));
117
		$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['dob_date_observation']));
115
		$observateur = htmlspecialchars($this->creerObservateur($donnees));
118
		$observateur = htmlspecialchars($this->creerObservateur($donnees));
116
 
119
 
117
		$contenuCommentaire = '';
120
		$contenuCommentaire = '';
118
		if ($etreProposition) {
121
		if ($etreProposition) {
119
			$contenuCommentaire =
122
			$contenuCommentaire =
120
				'<li><span class="champ">'."Nom proposé :</span> <em>$nomPropose</em></li>".
123
				'<li><span class="champ">'."Nom proposé :</span> <em>$nomPropose</em></li>".
121
				((!empty($txt)) ? '<li><span class="champ">'."Argumentaire :</span> $txt</li>" : '').
124
				((!empty($txt)) ? '<li><span class="champ">'."Argumentaire :</span> $txt</li>" : '').
122
				'<li><span class="champ">'."Auteur de la proposition :</span> $auteur</li>".
125
				'<li><span class="champ">'."Auteur de la proposition :</span> $auteur</li>".
123
				'<li><span class="champ">'."Proposé le :</span> $dateCommentaire</li>";
126
				'<li><span class="champ">'."Proposé le :</span> $dateCommentaire</li>";
124
		} else {
127
		} else {
125
			$contenuCommentaire =
128
			$contenuCommentaire =
126
				'<li><span class="champ">'."Commentaire #$idCommentaire :</span> <pre>$txt</pre></li>".
129
				'<li><span class="champ">'."Commentaire #$idCommentaire :</span> <pre>$txt</pre></li>".
127
				'<li><span class="champ">'."Auteur du commentaire :</span> $auteur</li>".
130
				'<li><span class="champ">'."Auteur du commentaire :</span> $auteur</li>".
128
				'<li><span class="champ">'."Commenté le :</span> $dateCommentaire</li>";
131
				'<li><span class="champ">'."Commenté le :</span> $dateCommentaire</li>";
129
		}
132
		}
130
 
133
 
131
		$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'.
134
		$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'.
132
			'<h2>'."$intitule identiPlante #$idCommentaire pour l'observation #$idObs".'</h2>'.
135
			'<h2>'."$intitule identiPlante #$idCommentaire pour l'observation #$idObs".'</h2>'.
133
			'<div class="gauche">'.
136
			'<div class="gauche">'.
134
			"	<h3>Observation #$idObs</h3>".
137
			"	<h3>Observation #$idObs</h3>".
135
			'	<ul>'.
138
			'	<ul>'.
136
			'		<li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>".
139
			'		<li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>".
137
			'		<li><span class="champ">'."Lieu :</span> $lieuObs</li>".
140
			'		<li><span class="champ">'."Lieu :</span> $lieuObs</li>".
138
			'		<li><span class="champ">'."Date :</span> $dateObs</li>".
141
			'		<li><span class="champ">'."Date :</span> $dateObs</li>".
139
			'		<li><span class="champ">'."Auteur :</span> $observateur</li>".
142
			'		<li><span class="champ">'."Auteur :</span> $observateur</li>".
140
			'	</ul>'.
143
			'	</ul>'.
141
			'</div>'.
144
			'</div>'.
142
			'<div class="gauche">'.
145
			'<div class="gauche">'.
143
			"	<h3>$intitule #$idCommentaire</h3>".
146
			"	<h3>$intitule #$idCommentaire</h3>".
144
			"	<ul>$contenuCommentaire</ul>".
147
			"	<ul>$contenuCommentaire</ul>".
145
			'</div>';
148
			'</div>';
146
		return $description;
149
		return $description;
147
	}
150
	}
148
 
151
 
149
	private function creerObservateur($info) {
152
	private function creerObservateur($info) {
150
		$observateur = 'Anonyme';
153
		$observateur = 'Anonyme';
151
		if ($info['observateur_prenom'] != '' && $info['observateur_nom'] != '') {
154
		if ($info['observateur_prenom'] != '' && $info['observateur_nom'] != '') {
152
			$observateur = $info['observateur_prenom'].' '.$info['observateur_nom'];
155
			$observateur = $info['observateur_prenom'].' '.$info['observateur_nom'];
153
		}
156
		}
154
		return $observateur;
157
		return $observateur;
155
	}
158
	}
156
 
159
 
157
	private function getDerniersCommentaires() {
160
	private function getDerniersCommentaires() {
158
		$commentaires = array();
161
		$commentaires = array();
159
		$idsCommentaires = $this->getIdsDerniersCommentaires();
162
		$idsCommentaires = $this->getIdsDerniersCommentaires();
160
		if (!empty($idsCommentaires)) {
163
		if (!empty($idsCommentaires)) {
161
			$idsCommentairesconcat = implode(', ', $idsCommentaires);
164
			$idsCommentairesconcat = implode(', ', $idsCommentaires);
162
			$requete = 'SELECT DISTINCT dc.*, '.
165
			$requete = 'SELECT DISTINCT dc.*, '.
163
				'	dob.id_observation AS dob_id_observation, dob.ce_zone_geo AS dob_ce_zone_geo, '.
166
				'	dob.id_observation AS dob_id_observation, dob.ce_zone_geo AS dob_ce_zone_geo, '.
164
				'	dob.zone_geo AS dob_zone_geo, dob.date_observation AS dob_date_observation, dob.nom_sel AS dob_nom_sel, '.
167
				'	dob.zone_geo AS dob_zone_geo, dob.date_observation AS dob_date_observation, dob.nom_sel AS dob_nom_sel, '.
165
				'	duo.prenom AS observateur_prenom, duo.nom AS observateur_nom, duo.courriel AS observateur_courriel '.
168
				'	duo.prenom AS observateur_prenom, duo.nom AS observateur_nom, duo.courriel AS observateur_courriel '.
166
				'FROM del_commentaire AS dc '.
169
				'FROM del_commentaire AS dc '.
167
				'	INNER JOIN del_observation AS dob '.
170
				'	INNER JOIN del_observation AS dob '.
168
				'		ON dob.id_observation = dc.ce_observation '.
171
				'		ON dob.id_observation = dc.ce_observation '.
169
				'	LEFT JOIN del_utilisateur AS duo '.
172
				'	LEFT JOIN del_utilisateur AS duo '.
170
				'		ON dob.ce_utilisateur = duo.id_utilisateur '.
173
				'		ON dob.ce_utilisateur = duo.id_utilisateur '.
171
				"WHERE id_commentaire IN ($idsCommentairesconcat) ".
174
				"WHERE id_commentaire IN ($idsCommentairesconcat) ".
172
				'ORDER BY dc.date DESC '.
175
				'ORDER BY dc.date DESC '.
173
				'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '.
176
				'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '.
174
				' -- '.__FILE__.' : '.__LINE__;
177
				' -- '.__FILE__.' : '.__LINE__;
175
			$commentaires = $this->bdd->recupererTous($requete);
178
			$commentaires = $this->bdd->recupererTous($requete);
176
		}
179
		}
177
		return $commentaires;
180
		return $commentaires;
178
	}
181
	}
179
 
182
 
180
	private function getIdsDerniersCommentaires() {
183
	private function getIdsDerniersCommentaires() {
181
		$clauseWhere = $this->chargerClauseWhere();
184
		$clauseWhere = $this->chargerClauseWhere();
182
		$requete = 'SELECT DISTINCT dc.id_commentaire '.
185
		$requete = 'SELECT DISTINCT dc.id_commentaire '.
183
			'FROM del_commentaire AS dc '.
186
			'FROM del_commentaire AS dc '.
184
			'	INNER JOIN del_observation AS dob ON (dc.ce_observation = dob.id_observation) '.
187
			'	INNER JOIN del_observation AS dob ON (dc.ce_observation = dob.id_observation) '.
185
			'	LEFT JOIN del_utilisateur AS duo ON (dob.ce_utilisateur = duo.id_utilisateur) '.
188
			'	LEFT JOIN del_utilisateur AS duo ON (dob.ce_utilisateur = duo.id_utilisateur) '.
186
			'WHERE proposition_initiale != 1 '.
189
			'WHERE proposition_initiale != 1 '.
187
			($clauseWhere != '' ? "AND $clauseWhere " : '').
190
			($clauseWhere != '' ? "AND $clauseWhere " : '').
188
			'ORDER BY dc.date DESC '.
191
			'ORDER BY dc.date DESC '.
189
			'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '.
192
			'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '.
190
			' -- '.__FILE__.' : '.__LINE__;
193
			' -- '.__FILE__.' : '.__LINE__;
191
		//echo $requete;
194
		//echo $requete;
192
		$resultats = $this->bdd->recupererTous($requete);
195
		$resultats = $this->bdd->recupererTous($requete);
193
 
196
 
194
		$idsCommentaires = array();
197
		$idsCommentaires = array();
195
		if ($resultats != false && is_array($resultats)) {
198
		if ($resultats != false && is_array($resultats)) {
196
			foreach ($resultats as $infos) {
199
			foreach ($resultats as $infos) {
197
				$idsCommentaires[] = $infos['id_commentaire'];
200
				$idsCommentaires[] = $infos['id_commentaire'];
198
			}
201
			}
199
		}
202
		}
200
		return $idsCommentaires;
203
		return $idsCommentaires;
201
	}
204
	}
202
 
205
 
203
	/**
206
	/**
204
	* Charger la clause WHERE en fonction des paramètres de masque
207
	* Charger la clause WHERE en fonction des paramètres de masque
205
	* */
208
	* */
206
	private function chargerClauseWhere() {
209
	private function chargerClauseWhere() {
207
		$where = array();
210
		$where = array();
208
		$filtres = $this->navigation->getFiltre();
211
		$filtres = $this->navigation->getFiltre();
209
		if (!empty($filtres)) {
212
		if (!empty($filtres)) {
210
			$filtrePossibles = $this->conteneur->getParametreTableau('syndication.commentaire_filtres');
213
			$filtrePossibles = $this->conteneur->getParametreTableau('syndication.commentaire_filtres');
211
			foreach ($filtres as $cleFiltre => $valeur) {
214
			foreach ($filtres as $cleFiltre => $valeur) {
212
				if (in_array($cleFiltre, $filtrePossibles)) {
215
				if (in_array($cleFiltre, $filtrePossibles)) {
213
					if (isset($this->mapping[$cleFiltre])) {
216
					if (isset($this->mapping[$cleFiltre])) {
214
						$champ = $this->mapping[$cleFiltre];
217
						$champ = $this->mapping[$cleFiltre];
215
					}
218
					}
216
					switch ($cleFiltre) {
219
					switch ($cleFiltre) {
217
						case 'espece':
220
						case 'espece':
218
							$valeurP = $this->bdd->proteger($valeur.'%');
221
							$valeurP = $this->bdd->proteger($valeur.'%');
219
							$where[] = " (dob.$champ LIKE $valeurP OR dc.$champ LIKE $valeurP) ";
222
							$where[] = " (dob.$champ LIKE $valeurP OR dc.$champ LIKE $valeurP) ";
220
							break;
223
							break;
221
						case 'auteur':
224
						case 'auteur':
222
							$where[] = $this->creerFiltreAuteur($valeur);
225
							$where[] = $this->creerFiltreAuteur($valeur);
223
							break;
226
							break;
224
						default:
227
						default:
225
							$valeurP = $this->bdd->proteger($valeur);
228
							$valeurP = $this->bdd->proteger($valeur);
226
							$where[] = " $champ = $valeurP ";
229
							$where[] = " $champ = $valeurP ";
227
					}
230
					}
228
				}
231
				}
229
			}
232
			}
230
		}
233
		}
231
		return (!empty($where)) ? implode(' AND ', $where) : '';
234
		return (!empty($where)) ? implode(' AND ', $where) : '';
232
	}
235
	}
233
 
236
 
234
	private function creerFiltreAuteur($auteurId) {
237
	private function creerFiltreAuteur($auteurId) {
235
		$whereAuteur = '';
238
		$whereAuteur = '';
236
		if (is_numeric($auteurId)) {
239
		if (is_numeric($auteurId)) {
237
			$whereAuteur = " dc.ce_utilisateur = $auteurId ";
240
			$whereAuteur = " dc.ce_utilisateur = $auteurId ";
238
		} else {
241
		} else {
239
			$auteurIdMotif = $this->bdd->proteger($auteurId.'%');
242
			$auteurIdMotif = $this->bdd->proteger($auteurId.'%');
240
 
243
 
241
			if (strpos($auteurId, '@') !== false) {
244
			if (strpos($auteurId, '@') !== false) {
242
				$whereAuteur = " dc.utilisateur_courriel LIKE $auteurIdMotif ";
245
				$whereAuteur = " dc.utilisateur_courriel LIKE $auteurIdMotif ";
243
			} else {
246
			} else {
244
				$tableauNomPrenom = explode(' ', $auteurId, 2);
247
				$tableauNomPrenom = explode(' ', $auteurId, 2);
245
				if (count($tableauNomPrenom) == 1) {
248
				if (count($tableauNomPrenom) == 1) {
246
					$whereAuteur = " (dc.utilisateur_nom LIKE $auteurIdMotif OR dc.utilisateur_prenom LIKE $auteurIdMotif) ";
249
					$whereAuteur = " (dc.utilisateur_nom LIKE $auteurIdMotif OR dc.utilisateur_prenom LIKE $auteurIdMotif) ";
247
				} else if (count($tableauNomPrenom) == 2) {
250
				} else if (count($tableauNomPrenom) == 2) {
248
					// on teste potentiellement un nom prenom ou bien un prénom nom
251
					// on teste potentiellement un nom prenom ou bien un prénom nom
249
					$nomMotif = $this->bdd->proteger($tableauNomPrenom[0].'%');
252
					$nomMotif = $this->bdd->proteger($tableauNomPrenom[0].'%');
250
					$prenomMotif = $this->bdd->proteger($tableauNomPrenom[1].'%');
253
					$prenomMotif = $this->bdd->proteger($tableauNomPrenom[1].'%');
251
 
254
 
252
					$whereAuteur = ' ('.
255
					$whereAuteur = ' ('.
253
						"(dc.utilisateur_nom LIKE $nomMotif AND dc.utilisateur_prenom LIKE $prenomMotif) ".
256
						"(dc.utilisateur_nom LIKE $nomMotif AND dc.utilisateur_prenom LIKE $prenomMotif) ".
254
						'OR '.
257
						'OR '.
255
						"(dc.utilisateur_nom LIKE $prenomMotif AND dc.utilisateur_prenom LIKE $nomMotif) ".
258
						"(dc.utilisateur_nom LIKE $prenomMotif AND dc.utilisateur_prenom LIKE $nomMotif) ".
256
					') ';
259
					') ';
257
				}
260
				}
258
			}
261
			}
259
		}
262
		}
260
		return $whereAuteur;
263
		return $whereAuteur;
261
	}
264
	}
262
}
265
}