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'] : null));
|
78 |
$dateObs = '?';
|
78 |
$dateObs = null;
|
79 |
if (strpos($element['dob_date_observation'], '0000') === false) {
|
79 |
if (strpos($element['dob_date_observation'], '0000') === false) {
|
80 |
$dateObs = htmlspecialchars(strftime('%d %B %Y', strtotime($element['dob_date_observation'])));
|
80 |
$dateObs = htmlspecialchars(strftime('%d %B %Y', strtotime($element['dob_date_observation'])));
|
81 |
}
|
81 |
}
|
82 |
|
82 |
|
- |
|
83 |
$titre = "$intitule par $auteur pour $nomSelActuel";
|
- |
|
84 |
$titre .= ($zoneGeo != null) ? " à $zoneGeo" : "";
|
83 |
$titre = "$intitule par $auteur pour $nomSelActuel à $zoneGeo le $dateObs";
|
85 |
$titre .= ($dateObs != null) ? " le $dateObs" : "";
|
84 |
return $titre;
|
86 |
return $titre;
|
85 |
}
|
87 |
}
|
86 |
|
88 |
|
87 |
private function creerAuteur($info) {
|
89 |
private function creerAuteur($info) {
|
88 |
$auteur = 'Anonyme';
|
90 |
$auteur = 'Anonyme';
|
89 |
if ($info['utilisateur_prenom'] != '' && $info['utilisateur_nom'] != '') {
|
91 |
if ($info['utilisateur_prenom'] != '' && $info['utilisateur_nom'] != '') {
|
90 |
$auteur = $info['utilisateur_prenom'].' '.$info['utilisateur_nom'];
|
92 |
$auteur = $info['utilisateur_prenom'].' '.$info['utilisateur_nom'];
|
91 |
}
|
93 |
}
|
92 |
return $auteur;
|
94 |
return $auteur;
|
93 |
}
|
95 |
}
|
94 |
|
96 |
|
95 |
private function creerGuidItem($element) {
|
97 |
private function creerGuidItem($element) {
|
96 |
$guid = sprintf($this->conteneur->getParametre('syndication.commentaire_guid_tpl'), $element['id_commentaire']);
|
98 |
$guid = sprintf($this->conteneur->getParametre('syndication.commentaire_guid_tpl'), $element['id_commentaire']);
|
97 |
return $guid;
|
99 |
return $guid;
|
98 |
}
|
100 |
}
|
99 |
|
101 |
|
100 |
private function creerLienItem($element) {
|
102 |
private function creerLienItem($element) {
|
101 |
$lien = sprintf($this->conteneur->getParametre('obs_fiche_tpl'), $element['dob_id_observation']);
|
103 |
$lien = sprintf($this->conteneur->getParametre('obs_fiche_tpl'), $element['dob_id_observation']);
|
102 |
return $lien;
|
104 |
return $lien;
|
103 |
}
|
105 |
}
|
104 |
|
106 |
|
105 |
private function creerDescription($donnees, $item) {
|
107 |
private function creerDescription($donnees, $item) {
|
106 |
$idCommentaire = $donnees['id_commentaire'];
|
108 |
$idCommentaire = $donnees['id_commentaire'];
|
107 |
$idObs = $donnees['dob_id_observation'];
|
109 |
$idObs = $donnees['dob_id_observation'];
|
108 |
$nomPropose = ($donnees['nom_sel'] != '') ? htmlspecialchars($donnees['nom_sel']) : '';
|
110 |
$nomPropose = ($donnees['nom_sel'] != '') ? htmlspecialchars($donnees['nom_sel']) : '';
|
109 |
$dateCommentaire = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', $this->syndication->convertirDateHeureMysqlEnTimestamp($donnees['date'])));
|
111 |
$dateCommentaire = htmlspecialchars(strftime('%A %d %B %Y à %H:%M', $this->syndication->convertirDateHeureMysqlEnTimestamp($donnees['date'])));
|
110 |
$nomSelActuel = htmlspecialchars($donnees['dob_nom_sel']);
|
112 |
$nomSelActuel = htmlspecialchars($donnees['dob_nom_sel']);
|
111 |
$etreProposition = ($nomPropose != '') ? true : false;
|
113 |
$etreProposition = ($nomPropose != '') ? true : false;
|
112 |
$intitule = ($etreProposition) ? 'Proposition' : 'Commentaire';
|
114 |
$intitule = ($etreProposition) ? 'Proposition' : 'Commentaire';
|
113 |
$txt = ($donnees['texte'] != '') ? htmlspecialchars($donnees['texte']) : '';
|
115 |
$txt = ($donnees['texte'] != '') ? htmlspecialchars($donnees['texte']) : '';
|
114 |
$auteur = htmlspecialchars($this->creerAuteur($donnees)).
|
116 |
$auteur = htmlspecialchars($this->creerAuteur($donnees)).
|
115 |
($this->syndication->fluxAdminDemande() ? ' ('.$donnees['utilisateur_courriel'].')' : '');
|
117 |
($this->syndication->fluxAdminDemande() ? ' ('.$donnees['utilisateur_courriel'].')' : '');
|
116 |
$lieuObs = htmlspecialchars((($donnees['dob_zone_geo'] != '') ? $donnees['dob_zone_geo'] : '?'));
|
118 |
$lieuObs = htmlspecialchars((($donnees['dob_zone_geo'] != '') ? $donnees['dob_zone_geo'] : '?'));
|
117 |
$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['dob_date_observation']));
|
119 |
$dateObs = htmlspecialchars(str_replace(' 00:00:00', '', $donnees['dob_date_observation']));
|
118 |
$observateur = htmlspecialchars($this->creerObservateur($donnees));
|
120 |
$observateur = htmlspecialchars($this->creerObservateur($donnees));
|
119 |
|
121 |
|
120 |
$contenuCommentaire = '';
|
122 |
$contenuCommentaire = '';
|
121 |
if ($etreProposition) {
|
123 |
if ($etreProposition) {
|
122 |
$contenuCommentaire =
|
124 |
$contenuCommentaire =
|
123 |
'<li><span class="champ">'."Nom proposé :</span> <em>$nomPropose</em></li>".
|
125 |
'<li><span class="champ">'."Nom proposé :</span> <em>$nomPropose</em></li>".
|
124 |
((!empty($txt)) ? '<li><span class="champ">'."Argumentaire :</span> $txt</li>" : '').
|
126 |
((!empty($txt)) ? '<li><span class="champ">'."Argumentaire :</span> $txt</li>" : '').
|
125 |
'<li><span class="champ">'."Auteur de la proposition :</span> $auteur</li>".
|
127 |
'<li><span class="champ">'."Auteur de la proposition :</span> $auteur</li>".
|
126 |
'<li><span class="champ">'."Proposé le :</span> $dateCommentaire</li>";
|
128 |
'<li><span class="champ">'."Proposé le :</span> $dateCommentaire</li>";
|
127 |
} else {
|
129 |
} else {
|
128 |
$contenuCommentaire =
|
130 |
$contenuCommentaire =
|
129 |
'<li><span class="champ">'."Commentaire #$idCommentaire :</span> <pre>$txt</pre></li>".
|
131 |
'<li><span class="champ">'."Commentaire #$idCommentaire :</span> <pre>$txt</pre></li>".
|
130 |
'<li><span class="champ">'."Auteur du commentaire :</span> $auteur</li>".
|
132 |
'<li><span class="champ">'."Auteur du commentaire :</span> $auteur</li>".
|
131 |
'<li><span class="champ">'."Commenté le :</span> $dateCommentaire</li>";
|
133 |
'<li><span class="champ">'."Commenté le :</span> $dateCommentaire</li>";
|
132 |
}
|
134 |
}
|
133 |
|
135 |
|
134 |
$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'.
|
136 |
$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'.
|
135 |
'<h2>'."$intitule identiPlante #$idCommentaire pour l'observation #$idObs".'</h2>'.
|
137 |
'<h2>'."$intitule identiPlante #$idCommentaire pour l'observation #$idObs".'</h2>'.
|
136 |
'<div class="gauche">'.
|
138 |
'<div class="gauche">'.
|
137 |
" <h3>Observation #$idObs</h3>".
|
139 |
" <h3>Observation #$idObs</h3>".
|
138 |
' <ul>'.
|
140 |
' <ul>'.
|
139 |
' <li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>".
|
141 |
' <li><span class="champ">'."Nom saisi actuel :</span> <em>$nomSelActuel</em></li>".
|
140 |
' <li><span class="champ">'."Lieu :</span> $lieuObs</li>".
|
142 |
' <li><span class="champ">'."Lieu :</span> $lieuObs</li>".
|
141 |
' <li><span class="champ">'."Date :</span> $dateObs</li>".
|
143 |
' <li><span class="champ">'."Date :</span> $dateObs</li>".
|
142 |
' <li><span class="champ">'."Auteur :</span> $observateur</li>".
|
144 |
' <li><span class="champ">'."Auteur :</span> $observateur</li>".
|
143 |
' </ul>'.
|
145 |
' </ul>'.
|
144 |
'</div>'.
|
146 |
'</div>'.
|
145 |
'<div class="gauche">'.
|
147 |
'<div class="gauche">'.
|
146 |
" <h3>$intitule #$idCommentaire</h3>".
|
148 |
" <h3>$intitule #$idCommentaire</h3>".
|
147 |
" <ul>$contenuCommentaire</ul>".
|
149 |
" <ul>$contenuCommentaire</ul>".
|
148 |
'</div>';
|
150 |
'</div>';
|
149 |
return $description;
|
151 |
return $description;
|
150 |
}
|
152 |
}
|
151 |
|
153 |
|
152 |
private function creerObservateur($info) {
|
154 |
private function creerObservateur($info) {
|
153 |
$observateur = 'Anonyme';
|
155 |
$observateur = 'Anonyme';
|
154 |
if ($info['observateur_prenom'] != '' && $info['observateur_nom'] != '') {
|
156 |
if ($info['observateur_prenom'] != '' && $info['observateur_nom'] != '') {
|
155 |
$observateur = $info['observateur_prenom'].' '.$info['observateur_nom'];
|
157 |
$observateur = $info['observateur_prenom'].' '.$info['observateur_nom'];
|
156 |
}
|
158 |
}
|
157 |
return $observateur;
|
159 |
return $observateur;
|
158 |
}
|
160 |
}
|
159 |
|
161 |
|
160 |
private function getDerniersCommentaires() {
|
162 |
private function getDerniersCommentaires() {
|
161 |
$commentaires = array();
|
163 |
$commentaires = array();
|
162 |
$idsCommentaires = $this->getIdsDerniersCommentaires();
|
164 |
$idsCommentaires = $this->getIdsDerniersCommentaires();
|
163 |
if (!empty($idsCommentaires)) {
|
165 |
if (!empty($idsCommentaires)) {
|
164 |
$idsCommentairesconcat = implode(', ', $idsCommentaires);
|
166 |
$idsCommentairesconcat = implode(', ', $idsCommentaires);
|
165 |
$requete = 'SELECT DISTINCT dc.*, '.
|
167 |
$requete = 'SELECT DISTINCT dc.*, '.
|
166 |
' dob.id_observation AS dob_id_observation, dob.ce_zone_geo AS dob_ce_zone_geo, '.
|
168 |
' dob.id_observation AS dob_id_observation, dob.ce_zone_geo AS dob_ce_zone_geo, '.
|
167 |
' dob.zone_geo AS dob_zone_geo, dob.date_observation AS dob_date_observation, dob.nom_sel AS dob_nom_sel, '.
|
169 |
' dob.zone_geo AS dob_zone_geo, dob.date_observation AS dob_date_observation, dob.nom_sel AS dob_nom_sel, '.
|
168 |
' duo.prenom AS observateur_prenom, duo.nom AS observateur_nom, duo.courriel AS observateur_courriel '.
|
170 |
' duo.prenom AS observateur_prenom, duo.nom AS observateur_nom, duo.courriel AS observateur_courriel '.
|
169 |
'FROM del_commentaire AS dc '.
|
171 |
'FROM del_commentaire AS dc '.
|
170 |
' INNER JOIN del_observation AS dob '.
|
172 |
' INNER JOIN del_observation AS dob '.
|
171 |
' ON dob.id_observation = dc.ce_observation '.
|
173 |
' ON dob.id_observation = dc.ce_observation '.
|
172 |
' LEFT JOIN del_utilisateur AS duo '.
|
174 |
' LEFT JOIN del_utilisateur AS duo '.
|
173 |
' ON dob.ce_utilisateur = duo.id_utilisateur '.
|
175 |
' ON dob.ce_utilisateur = duo.id_utilisateur '.
|
174 |
"WHERE id_commentaire IN ($idsCommentairesconcat) ".
|
176 |
"WHERE id_commentaire IN ($idsCommentairesconcat) ".
|
175 |
'ORDER BY dc.date DESC '.
|
177 |
'ORDER BY dc.date DESC '.
|
176 |
'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '.
|
178 |
'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '.
|
177 |
' -- '.__FILE__.' : '.__LINE__;
|
179 |
' -- '.__FILE__.' : '.__LINE__;
|
178 |
$commentaires = $this->bdd->recupererTous($requete);
|
180 |
$commentaires = $this->bdd->recupererTous($requete);
|
179 |
}
|
181 |
}
|
180 |
return $commentaires;
|
182 |
return $commentaires;
|
181 |
}
|
183 |
}
|
182 |
|
184 |
|
183 |
private function getIdsDerniersCommentaires() {
|
185 |
private function getIdsDerniersCommentaires() {
|
184 |
$clauseWhere = $this->chargerClauseWhere();
|
186 |
$clauseWhere = $this->chargerClauseWhere();
|
185 |
$requete = 'SELECT DISTINCT dc.id_commentaire '.
|
187 |
$requete = 'SELECT DISTINCT dc.id_commentaire '.
|
186 |
'FROM del_commentaire AS dc '.
|
188 |
'FROM del_commentaire AS dc '.
|
187 |
' INNER JOIN del_observation AS dob ON (dc.ce_observation = dob.id_observation) '.
|
189 |
' INNER JOIN del_observation AS dob ON (dc.ce_observation = dob.id_observation) '.
|
188 |
' LEFT JOIN del_utilisateur AS duo ON (dob.ce_utilisateur = duo.id_utilisateur) '.
|
190 |
' LEFT JOIN del_utilisateur AS duo ON (dob.ce_utilisateur = duo.id_utilisateur) '.
|
189 |
'WHERE proposition_initiale != 1 '.
|
191 |
'WHERE proposition_initiale != 1 '.
|
190 |
($clauseWhere != '' ? "AND $clauseWhere " : '').
|
192 |
($clauseWhere != '' ? "AND $clauseWhere " : '').
|
191 |
'ORDER BY dc.date DESC '.
|
193 |
'ORDER BY dc.date DESC '.
|
192 |
'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '.
|
194 |
'LIMIT '.$this->navigation->getDepart().','.$this->navigation->getLimite().' '.
|
193 |
' -- '.__FILE__.' : '.__LINE__;
|
195 |
' -- '.__FILE__.' : '.__LINE__;
|
194 |
//echo $requete;
|
196 |
//echo $requete;
|
195 |
$resultats = $this->bdd->recupererTous($requete);
|
197 |
$resultats = $this->bdd->recupererTous($requete);
|
196 |
|
198 |
|
197 |
$idsCommentaires = array();
|
199 |
$idsCommentaires = array();
|
198 |
if ($resultats != false && is_array($resultats)) {
|
200 |
if ($resultats != false && is_array($resultats)) {
|
199 |
foreach ($resultats as $infos) {
|
201 |
foreach ($resultats as $infos) {
|
200 |
$idsCommentaires[] = $infos['id_commentaire'];
|
202 |
$idsCommentaires[] = $infos['id_commentaire'];
|
201 |
}
|
203 |
}
|
202 |
}
|
204 |
}
|
203 |
return $idsCommentaires;
|
205 |
return $idsCommentaires;
|
204 |
}
|
206 |
}
|
205 |
|
207 |
|
206 |
/**
|
208 |
/**
|
207 |
* Charger la clause WHERE en fonction des paramètres de masque
|
209 |
* Charger la clause WHERE en fonction des paramètres de masque
|
208 |
* */
|
210 |
* */
|
209 |
private function chargerClauseWhere() {
|
211 |
private function chargerClauseWhere() {
|
210 |
$where = array();
|
212 |
$where = array();
|
211 |
$filtres = $this->navigation->getFiltre();
|
213 |
$filtres = $this->navigation->getFiltre();
|
212 |
if (!empty($filtres)) {
|
214 |
if (!empty($filtres)) {
|
213 |
$filtrePossibles = $this->conteneur->getParametreTableau('syndication.commentaire_filtres');
|
215 |
$filtrePossibles = $this->conteneur->getParametreTableau('syndication.commentaire_filtres');
|
214 |
foreach ($filtres as $cleFiltre => $valeur) {
|
216 |
foreach ($filtres as $cleFiltre => $valeur) {
|
215 |
if (in_array($cleFiltre, $filtrePossibles)) {
|
217 |
if (in_array($cleFiltre, $filtrePossibles)) {
|
216 |
if (isset($this->mapping[$cleFiltre])) {
|
218 |
if (isset($this->mapping[$cleFiltre])) {
|
217 |
$champ = $this->mapping[$cleFiltre];
|
219 |
$champ = $this->mapping[$cleFiltre];
|
218 |
}
|
220 |
}
|
219 |
switch ($cleFiltre) {
|
221 |
switch ($cleFiltre) {
|
220 |
case 'espece':
|
222 |
case 'espece':
|
221 |
$valeurP = $this->bdd->proteger($valeur.'%');
|
223 |
$valeurP = $this->bdd->proteger($valeur.'%');
|
222 |
$where[] = " (dob.$champ LIKE $valeurP OR dc.$champ LIKE $valeurP) ";
|
224 |
$where[] = " (dob.$champ LIKE $valeurP OR dc.$champ LIKE $valeurP) ";
|
223 |
break;
|
225 |
break;
|
224 |
case 'auteur':
|
226 |
case 'auteur':
|
225 |
$where[] = $this->creerFiltreAuteur($valeur);
|
227 |
$where[] = $this->creerFiltreAuteur($valeur);
|
226 |
break;
|
228 |
break;
|
227 |
default:
|
229 |
default:
|
228 |
$valeurP = $this->bdd->proteger($valeur);
|
230 |
$valeurP = $this->bdd->proteger($valeur);
|
229 |
$where[] = " $champ = $valeurP ";
|
231 |
$where[] = " $champ = $valeurP ";
|
230 |
}
|
232 |
}
|
231 |
}
|
233 |
}
|
232 |
}
|
234 |
}
|
233 |
}
|
235 |
}
|
234 |
return (!empty($where)) ? implode(' AND ', $where) : '';
|
236 |
return (!empty($where)) ? implode(' AND ', $where) : '';
|
235 |
}
|
237 |
}
|
236 |
|
238 |
|
237 |
private function creerFiltreAuteur($auteurId) {
|
239 |
private function creerFiltreAuteur($auteurId) {
|
238 |
$whereAuteur = '';
|
240 |
$whereAuteur = '';
|
239 |
if (is_numeric($auteurId)) {
|
241 |
if (is_numeric($auteurId)) {
|
240 |
$whereAuteur = " dc.ce_utilisateur = $auteurId ";
|
242 |
$whereAuteur = " dc.ce_utilisateur = $auteurId ";
|
241 |
} else {
|
243 |
} else {
|
242 |
$auteurIdMotif = $this->bdd->proteger($auteurId.'%');
|
244 |
$auteurIdMotif = $this->bdd->proteger($auteurId.'%');
|
243 |
|
245 |
|
244 |
if (strpos($auteurId, '@') !== false) {
|
246 |
if (strpos($auteurId, '@') !== false) {
|
245 |
$whereAuteur = " dc.utilisateur_courriel LIKE $auteurIdMotif ";
|
247 |
$whereAuteur = " dc.utilisateur_courriel LIKE $auteurIdMotif ";
|
246 |
} else {
|
248 |
} else {
|
247 |
$tableauNomPrenom = explode(' ', $auteurId, 2);
|
249 |
$tableauNomPrenom = explode(' ', $auteurId, 2);
|
248 |
if (count($tableauNomPrenom) == 1) {
|
250 |
if (count($tableauNomPrenom) == 1) {
|
249 |
$whereAuteur = " (dc.utilisateur_nom LIKE $auteurIdMotif OR dc.utilisateur_prenom LIKE $auteurIdMotif) ";
|
251 |
$whereAuteur = " (dc.utilisateur_nom LIKE $auteurIdMotif OR dc.utilisateur_prenom LIKE $auteurIdMotif) ";
|
250 |
} else if (count($tableauNomPrenom) == 2) {
|
252 |
} else if (count($tableauNomPrenom) == 2) {
|
251 |
// on teste potentiellement un nom prenom ou bien un prénom nom
|
253 |
// on teste potentiellement un nom prenom ou bien un prénom nom
|
252 |
$nomMotif = $this->bdd->proteger($tableauNomPrenom[0].'%');
|
254 |
$nomMotif = $this->bdd->proteger($tableauNomPrenom[0].'%');
|
253 |
$prenomMotif = $this->bdd->proteger($tableauNomPrenom[1].'%');
|
255 |
$prenomMotif = $this->bdd->proteger($tableauNomPrenom[1].'%');
|
254 |
|
256 |
|
255 |
$whereAuteur = ' ('.
|
257 |
$whereAuteur = ' ('.
|
256 |
"(dc.utilisateur_nom LIKE $nomMotif AND dc.utilisateur_prenom LIKE $prenomMotif) ".
|
258 |
"(dc.utilisateur_nom LIKE $nomMotif AND dc.utilisateur_prenom LIKE $prenomMotif) ".
|
257 |
'OR '.
|
259 |
'OR '.
|
258 |
"(dc.utilisateur_nom LIKE $prenomMotif AND dc.utilisateur_prenom LIKE $nomMotif) ".
|
260 |
"(dc.utilisateur_nom LIKE $prenomMotif AND dc.utilisateur_prenom LIKE $nomMotif) ".
|
259 |
') ';
|
261 |
') ';
|
260 |
}
|
262 |
}
|
261 |
}
|
263 |
}
|
262 |
}
|
264 |
}
|
263 |
return $whereAuteur;
|
265 |
return $whereAuteur;
|
264 |
}
|
266 |
}
|
265 |
}
|
267 |
}
|