| Line 24... |
Line 24... |
| 24 |
private $gestionBdd;
|
24 |
private $gestionBdd;
|
| 25 |
private $bdd;
|
25 |
private $bdd;
|
| Line 26... |
Line 26... |
| 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_departements.ini');
|
29 |
$this->conteneur->chargerConfiguration('config_departements_bruts.ini');
|
| 30 |
$this->conteneur->chargerConfiguration('config_observations.ini');
|
30 |
$this->conteneur->chargerConfiguration('config_observations.ini');
|
| 31 |
$this->conteneur->chargerConfiguration('config_votes.ini');
|
31 |
$this->conteneur->chargerConfiguration('config_votes.ini');
|
| 32 |
$this->navigation = $conteneur->getNavigation();
|
32 |
$this->navigation = $conteneur->getNavigation();
|
| 33 |
$this->masque = $conteneur->getMasque();
|
33 |
$this->masque = $conteneur->getMasque();
|
| Line 143... |
Line 143... |
| 143 |
* Charger la clause WHERE en fonction des paramètres de masque
|
143 |
* Charger la clause WHERE en fonction des paramètres de masque
|
| 144 |
* */
|
144 |
* */
|
| 145 |
private function chargerClauseWhere() {
|
145 |
private function chargerClauseWhere() {
|
| 146 |
$where = array();
|
146 |
$where = array();
|
| 147 |
$tableauMasque = $this->masque->getMasque();
|
147 |
$tableauMasque = $this->masque->getMasque();
|
| 148 |
// FIXME : Les communes avec une apostrophe (ex: saint michel d'euzet) arrivent dans les paramètres sans l'apostrophe
|
- |
|
| 149 |
if (!empty($tableauMasque)) {
|
148 |
if (!empty($tableauMasque)) {
|
| 150 |
foreach($tableauMasque as $idMasque => $valeurMasque) {
|
149 |
foreach($tableauMasque as $idMasque => $valeurMasque) {
|
| Line 151... |
Line 150... |
| 151 |
|
150 |
|
| 152 |
$idMasque = str_replace('masque.', '', $idMasque);
|
151 |
$idMasque = str_replace('masque.', '', $idMasque);
|
| 153 |
switch ($idMasque) {
|
152 |
switch ($idMasque) {
|
| 154 |
// nom du masque => nom BDD
|
153 |
// nom du masque => nom BDD
|
| 155 |
case 'auteur' :
|
154 |
case 'auteur' :
|
| 156 |
$auteurId = $this->masque->getMasque('auteur');
|
- |
|
| 157 |
if (is_numeric($auteurId)) {
|
- |
|
| 158 |
$where[] = ' ce_utilisateur = '.$auteurId;
|
155 |
$where[] = $this->creerFiltreAuteur($this->masque->getMasque('auteur'));
|
| 159 |
} else {
|
- |
|
| 160 |
if (strpos($auteurId, '@') === false) {
|
- |
|
| 161 |
$chaineNomPrenom = $this->getChaineNomPrenom($auteurId);
|
- |
|
| 162 |
$where[] = '((nom IN ('.$chaineNomPrenom.')) OR (prenom IN ('.$chaineNomPrenom.')))';
|
156 |
break;
|
| 163 |
} else {
|
157 |
case 'date' :
|
| 164 |
$where[] = " courriel LIKE ".$this->proteger($this->masque->getMasque('auteur').'%')." ";
|
- |
|
| 165 |
}
|
- |
|
| 166 |
}
|
158 |
$where[] = $this->creerFiltreDate($valeurMasque);
|
| 167 |
break;
|
- |
|
| 168 |
|
- |
|
| 169 |
//TODO : gérer le format de la date ?
|
- |
|
| 170 |
// rechercher sur LIKE DATE % ?
|
- |
|
| 171 |
// TODO : recherche sur JOUR MOIS ou ANNEE
|
159 |
break;
|
| 172 |
case 'departement' :
|
- |
|
| 173 |
$dept = $valeurMasque;
|
- |
|
| 174 |
if (is_numeric($dept)) {
|
- |
|
| 175 |
$dept = sprintf('%02s', $dept);
|
- |
|
| 176 |
$dept = sprintf("%-'_5s", $dept);
|
- |
|
| 177 |
$where[] = " ce_zone_geo LIKE ".$this->proteger('INSEE-C:'.$dept);
|
- |
|
| 178 |
} else {
|
- |
|
| 179 |
|
- |
|
| 180 |
//FIXME : et les apostrophes dans les départements ?
|
- |
|
| 181 |
|
160 |
case 'departement' :
|
| 182 |
$deptId = $this->conteneur->getParametre($dept);
|
- |
|
| 183 |
if ($deptId != null) {
|
- |
|
| 184 |
$where[] = " ce_zone_geo LIKE ".$this->proteger('INSEE-C:'.$deptId.'%');
|
- |
|
| 185 |
}
|
- |
|
| 186 |
}
|
161 |
$where[] = $this->creerFiltreIdZoneGeo($valeurMasque);
|
| 187 |
break;
|
162 |
break;
|
| 188 |
case 'genre' :
|
163 |
case 'genre' :
|
| 189 |
$where[] = ' '.$this->mappingFiltre['ns'].' LIKE '.$this->proteger('%'.$valeurMasque.'% %');
|
164 |
$where[] = ' '.$this->mappingFiltre['ns'].' LIKE '.$this->proteger('%'.$valeurMasque.'% %');
|
| 190 |
break;
|
165 |
break;
|
| 191 |
case 'tag' :
|
166 |
case 'tag' :
|
| 192 |
$where[] = " mots_cles_texte LIKE ".$this->proteger($valeurMasque);
|
167 |
$where[] = $this->creerFiltreMotsCles($valeurMasque);
|
| 193 |
break;
|
168 |
break;
|
| 194 |
case 'nn' :
|
169 |
case 'nn' :
|
| 195 |
$where[] = ' '.$this->mappingFiltre['nn'].' = '.$this->proteger($valeurMasque);
|
170 |
$where[] = ' '.$this->mappingFiltre['nn'].' = '.$this->proteger($valeurMasque);
|
| 196 |
break;
|
171 |
break;
|
| 197 |
case 'ns' :
|
172 |
case 'ns' :
|
| - |
|
173 |
$where[] = " nom_sel LIKE ".$this->proteger($valeurMasque.'%');
|
| - |
|
174 |
break;
|
| - |
|
175 |
case 'commune' :
|
| - |
|
176 |
$where[] = ' '.$this->mappingFiltre[$idMasque].' LIKE '.$this->proteger($this->remplacerParJokerCaractere($valeurMasque).'%');
|
| - |
|
177 |
break;
|
| - |
|
178 |
case 'masque' :
|
| 198 |
$where[] = " nom_sel LIKE ".$this->proteger($valeurMasque.'%');
|
179 |
$where[] = $this->creerFiltreMasqueGeneral($valeurMasque);
|
| 199 |
break;
|
180 |
break;
|
| 200 |
default:
|
181 |
default:
|
| 201 |
$where[] = ' '.$this->mappingFiltre[$idMasque].' LIKE '.$this->proteger('%'.$valeurMasque.'%');
|
182 |
$where[] = ' '.$this->mappingFiltre[$idMasque].' LIKE '.$this->proteger('%'.$valeurMasque.'%');
|
| 202 |
}
|
183 |
}
|
| Line 208... |
Line 189... |
| 208 |
} else {
|
189 |
} else {
|
| 209 |
return;
|
190 |
return;
|
| 210 |
}
|
191 |
}
|
| 211 |
}
|
192 |
}
|
| Line -... |
Line 193... |
| - |
|
193 |
|
| - |
|
194 |
private function creerFiltreMasqueGeneral($valeurMasque) {
|
| - |
|
195 |
|
| - |
|
196 |
// créer filtre auteur et idzone géo peuvent renvoyer des valeurs vides
|
| - |
|
197 |
$whereAuteur = $this->creerFiltreAuteur($valeurMasque);
|
| - |
|
198 |
$whereIdZoneGeo = $this->creerFiltreIdZoneGeo($valeurMasque);
|
| - |
|
199 |
|
| - |
|
200 |
$masqueGeneral = '( '.
|
| - |
|
201 |
(($whereAuteur != '') ? $whereAuteur.' OR ' : '' ).
|
| - |
|
202 |
(($whereIdZoneGeo != '') ? $whereIdZoneGeo.' OR ' : '' ).
|
| - |
|
203 |
'zone_geo LIKE '.$this->proteger($this->remplacerParJokerCaractere($valeurMasque).'%').' OR '.
|
| - |
|
204 |
$this->creerFiltreMotsCles($valeurMasque).' OR '.
|
| - |
|
205 |
'nom_sel LIKE '.$this->proteger($valeurMasque.'%').' OR '.
|
| - |
|
206 |
'famille LIKE '.$this->proteger($valeurMasque.'%').' OR '.
|
| - |
|
207 |
'milieu LIKE '.$this->proteger($valeurMasque).' OR '.
|
| - |
|
208 |
$this->mappingFiltre['ns'].' LIKE '.$this->proteger('%'.$valeurMasque.'% %').' OR '.
|
| - |
|
209 |
$this->creerFiltreDate($valeurMasque).
|
| - |
|
210 |
') ';
|
| - |
|
211 |
|
| - |
|
212 |
return $masqueGeneral;
|
| - |
|
213 |
}
|
| - |
|
214 |
|
| - |
|
215 |
private function creerFiltreAuteur($valeurMasque) {
|
| - |
|
216 |
$masque = '';
|
| - |
|
217 |
$auteurId = $valeurMasque;
|
| - |
|
218 |
if (is_numeric($auteurId)) {
|
| - |
|
219 |
$masque = ' ce_utilisateur = '.$auteurId;
|
| - |
|
220 |
} else {
|
| - |
|
221 |
if (strpos($auteurId, '@') === false) {
|
| - |
|
222 |
$tableauNomPrenom = explode(' ',$auteurId, 2);
|
| - |
|
223 |
if(count($tableauNomPrenom) == 2) {
|
| - |
|
224 |
// on teste potentiellement un nom prenom ou bien un prénom nom
|
| - |
|
225 |
$masque = '('.
|
| - |
|
226 |
'(nom LIKE '.$this->proteger($tableauNomPrenom[0].'%').' AND '.
|
| - |
|
227 |
'prenom LIKE '.$this->proteger($tableauNomPrenom[1].'%').') OR '.
|
| - |
|
228 |
'(nom LIKE '.$this->proteger($tableauNomPrenom[1].'%').' AND '.
|
| - |
|
229 |
'prenom LIKE '.$this->proteger($tableauNomPrenom[0].'%').')'.
|
| - |
|
230 |
')';
|
| - |
|
231 |
} else {
|
| - |
|
232 |
$masque = '(
|
| - |
|
233 |
(nom LIKE '.$this->proteger($auteurId.'%').' OR '.
|
| - |
|
234 |
'prenom LIKE '.$this->proteger($auteurId.'%').')'.
|
| - |
|
235 |
')';
|
| - |
|
236 |
}
|
| - |
|
237 |
} else {
|
| - |
|
238 |
$masque = " courriel LIKE ".$this->proteger($valeurMasque.'%')." ";
|
| - |
|
239 |
}
|
| - |
|
240 |
}
|
| - |
|
241 |
return $masque;
|
| - |
|
242 |
}
|
| - |
|
243 |
|
| - |
|
244 |
private function remplacerParJokerCaractere($valeurMasque) {
|
| - |
|
245 |
return str_replace(array('-',' '), '_', $valeurMasque);
|
| - |
|
246 |
}
|
| - |
|
247 |
//TODO: déplacer les fonctions ci dessus et dessous dans une classe
|
| - |
|
248 |
// utilitaire
|
| - |
|
249 |
function supprimerAccents($str, $charset='utf-8')
|
| - |
|
250 |
{
|
| - |
|
251 |
$str = htmlentities($str, ENT_NOQUOTES, $charset);
|
| - |
|
252 |
|
| - |
|
253 |
$str = preg_replace('#&([A-za-z])(?:acute|cedil|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $str);
|
| - |
|
254 |
$str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str); // pour les ligatures e.g. 'œ'
|
| - |
|
255 |
$str = preg_replace('#&[^;]+;#', '', $str); // supprime les autres caractères
|
| - |
|
256 |
|
| - |
|
257 |
return $str;
|
| - |
|
258 |
}
|
| - |
|
259 |
|
| - |
|
260 |
private function obtenirIdDepartement($nomDpt) {
|
| - |
|
261 |
|
| - |
|
262 |
$nomDpt = $this->supprimerAccents($nomDpt);
|
| - |
|
263 |
$nomDpt = strtolower(str_replace(' ','-',$nomDpt));
|
| - |
|
264 |
|
| - |
|
265 |
$idDpt = $this->conteneur->getParametre($nomDpt);
|
| - |
|
266 |
if($idDpt == null || $idDpt == ' ') {
|
| - |
|
267 |
$idDpt = ' ';
|
| - |
|
268 |
}
|
| - |
|
269 |
return $idDpt;
|
| - |
|
270 |
}
|
| - |
|
271 |
|
| - |
|
272 |
private function creerFiltreIdZoneGeo($valeurMasque) {
|
| - |
|
273 |
$masque = '';
|
| - |
|
274 |
$dept = $valeurMasque;
|
| - |
|
275 |
if (is_numeric($dept)) {
|
| - |
|
276 |
$dept = sprintf('%02s', $dept);
|
| - |
|
277 |
$dept = sprintf("%-'_5s", $dept);
|
| - |
|
278 |
$masque = " ce_zone_geo LIKE ".$this->proteger('INSEE-C:'.$dept);
|
| - |
|
279 |
} else {
|
| - |
|
280 |
$deptId = $this->conteneur->getParametre($dept);
|
| - |
|
281 |
if ($deptId != null) {
|
| - |
|
282 |
$masque = " ce_zone_geo LIKE ".$this->proteger('INSEE-C:'.$deptId.'%');
|
| - |
|
283 |
} else {
|
| - |
|
284 |
$id = $this->obtenirIdDepartement($valeurMasque);
|
| - |
|
285 |
$masque = " ce_zone_geo LIKE ".$this->proteger('INSEE-C:'.$id.'%');
|
| - |
|
286 |
}
|
| - |
|
287 |
}
|
| - |
|
288 |
return $masque;
|
| - |
|
289 |
}
|
| - |
|
290 |
|
| - |
|
291 |
private function creerFiltreDate($valeurMasque) {
|
| - |
|
292 |
//TODO: définir dans le fichier de config un tableau contenant plusieurs format de date
|
| - |
|
293 |
// autorisés pour la recherche, qui seraient ajoutés au OR
|
| - |
|
294 |
$masque = '(';
|
| - |
|
295 |
$masque .= (is_numeric($valeurMasque)) ? ' YEAR(date_observation) = '.$this->proteger($valeurMasque).' OR ' : '';
|
| - |
|
296 |
$masque .= " DATE_FORMAT(date_observation, '%d/%m/%Y') = ".$this->proteger($valeurMasque).' '.
|
| - |
|
297 |
')';
|
| - |
|
298 |
return $masque;
|
| - |
|
299 |
}
|
| - |
|
300 |
|
| - |
|
301 |
private function creerFiltreMotsCles($valeurMasque) {
|
| - |
|
302 |
$masque = '(di.mots_cles_texte LIKE '.$this->proteger('%'.$valeurMasque.'%').' OR '.
|
| - |
|
303 |
' dob.mots_cles_texte LIKE '.$this->proteger('%'.$valeurMasque.'%').') ';
|
| - |
|
304 |
return $masque;
|
| - |
|
305 |
}
|
| 212 |
|
306 |
|
| 213 |
/*-------------------------------------------------------------------------------
|
307 |
/*-------------------------------------------------------------------------------
|
| 214 |
CHARGEMENT DES OBSERVATIONS
|
308 |
CHARGEMENT DES OBSERVATIONS
|
| 215 |
--------------------------------------------------------------------------------*/
|
309 |
--------------------------------------------------------------------------------*/
|
| 216 |
/**
|
310 |
/**
|
| 217 |
* Chargement depuis la bdd de toutes les liaisons entre images et observations
|
311 |
* Chargement depuis la bdd de toutes les liaisons entre images et observations
|
| 218 |
* */
|
312 |
* */
|
| 219 |
private function chargerLiaisons() {
|
- |
|
| - |
|
313 |
private function chargerLiaisons() {
|
| - |
|
314 |
// ajout seulement du champ mot clés de la table image liée, pour rechercher
|
| 220 |
|
315 |
// sur les mots clés obs et images
|
| 221 |
$requeteLiaisons = 'SELECT SQL_CALC_FOUND_ROWS * '.
|
316 |
$requeteLiaisons = 'SELECT SQL_CALC_FOUND_ROWS *, di.mots_cles_texte '.
|
| 222 |
'FROM '.$this->gestionBdd->formaterTable('del_observation', 'dob').
|
317 |
'FROM '.$this->gestionBdd->formaterTable('del_observation', 'dob').
|
| 223 |
'INNER JOIN '.$this->gestionBdd->formaterTable('del_obs_image', 'doi').
|
318 |
'INNER JOIN '.$this->gestionBdd->formaterTable('del_obs_image', 'doi').
|
| 224 |
'ON doi.id_observation = dob.id_observation '.
|
319 |
'ON doi.id_observation = dob.id_observation '.
|
| 225 |
'INNER JOIN del_utilisateur du '.
|
320 |
'INNER JOIN del_utilisateur du '.
|
| - |
|
321 |
'ON du.id_utilisateur = doi.id_utilisateur '.
|
| - |
|
322 |
'INNER JOIN '.$this->gestionBdd->formaterTable('del_image', 'di').
|
| 226 |
'ON du.id_utilisateur = doi.id_utilisateur ';
|
323 |
'ON di.id_image = doi.id_image ';
|
| 227 |
$requeteLiaisons .= $this->chargerClauseWhere();
|
324 |
$requeteLiaisons .= $this->chargerClauseWhere();
|
| 228 |
$requeteLiaisons .= ' GROUP BY doi.id_observation';
|
325 |
$requeteLiaisons .= ' GROUP BY doi.id_observation';
|
| 229 |
$requeteLiaisons .= ' ORDER BY date_transmission DESC ';
|
326 |
$requeteLiaisons .= ' ORDER BY date_transmission DESC ';
|
| 230 |
$requeteLiaisons .= $this->gestionBdd->getLimitSql();
|
327 |
$requeteLiaisons .= $this->gestionBdd->getLimitSql();
|
| 231 |
|
328 |
|
| 232 |
return $this->bdd->recupererTous($requeteLiaisons);
|
329 |
return $this->bdd->recupererTous($requeteLiaisons);
|
| Line 233... |
Line 330... |
| 233 |
}
|
330 |
}
|
| 234 |
|
331 |
|