| Line 14... |
Line 14... |
| 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 Sql {
|
17 |
class Sql {
|
| Line -... |
Line 18... |
| - |
|
18 |
|
| - |
|
19 |
const APPLI_IMG = 'IMG';
|
| - |
|
20 |
const APPLI_OBS = 'OBS';
|
| 18 |
|
21 |
|
| 19 |
private $conteneur;
|
22 |
private $conteneur;
|
| 20 |
private $bdd;
|
23 |
private $bdd;
|
| - |
|
24 |
private $parametres = array();
|
| 21 |
private $parametres = array();
|
25 |
private $appli;
|
| 22 |
private $requete = array(
|
26 |
private $requete = array(
|
| 23 |
'select' => array(),
|
27 |
'select' => array(),
|
| 24 |
'join' => array(),
|
28 |
'join' => array(),
|
| 25 |
'where' => array(),
|
29 |
'where' => array(),
|
| 26 |
'groupby' => array(),
|
30 |
'groupby' => array(),
|
| Line 27... |
Line 31... |
| 27 |
'orderby' => array());
|
31 |
'orderby' => array());
|
| 28 |
|
32 |
|
| Line 29... |
Line 33... |
| 29 |
private $champsPrenom = array('du.prenom', 'vdi.prenom_utilisateur');
|
33 |
private $champsPrenom = array('du.prenom', 'prenom_utilisateur');
|
| 30 |
private $champsNom = array('du.nom', 'vdi.nom_utilisateur');
|
34 |
private $champsNom = array('du.nom', 'nom_utilisateur');
|
| 31 |
|
35 |
|
| Line 37... |
Line 41... |
| 37 |
|
41 |
|
| 38 |
public function setParametres(Array $parametres) {
|
42 |
public function setParametres(Array $parametres) {
|
| 39 |
$this->parametres = $parametres;
|
43 |
$this->parametres = $parametres;
|
| Line -... |
Line 44... |
| - |
|
44 |
}
|
| - |
|
45 |
|
| - |
|
46 |
public function setAppli($appliType) {
|
| - |
|
47 |
if ($appliType == 'IMG' || $appliType == 'OBS') {
|
| - |
|
48 |
$this->appli = $appliType;
|
| - |
|
49 |
} else {
|
| - |
|
50 |
throw new Exception("Les types d'appli disponible sont : IMG (pour PictoFlora) et OBS (pour IdentiPlante)");
|
| - |
|
51 |
}
|
| - |
|
52 |
}
|
| - |
|
53 |
|
| - |
|
54 |
private function getPrefixe() {
|
| - |
|
55 |
return $this->appli === 'IMG' ? 'di' : 'do';
|
| - |
|
56 |
}
|
| - |
|
57 |
|
| - |
|
58 |
private function etreAppliImg() {
|
| - |
|
59 |
return $this->appli === 'IMG' ? true : false;
|
| - |
|
60 |
}
|
| - |
|
61 |
|
| - |
|
62 |
private function etreAppliObs() {
|
| - |
|
63 |
return $this->appli === 'OBS' ? true : false;
|
| 40 |
}
|
64 |
}
|
| 41 |
|
65 |
|
| 42 |
public function getRequeteSql() {
|
66 |
public function getRequeteSql() {
|
| Line 43... |
Line 67... |
| 43 |
return $this->requete;
|
67 |
return $this->requete;
|
| - |
|
68 |
}
|
| 44 |
}
|
69 |
|
| - |
|
70 |
private function addJoin($join) {
|
| 45 |
|
71 |
if (!isset($this->requete['join'][$join])) {
|
| Line 46... |
Line 72... |
| 46 |
private function addJoin($join) {
|
72 |
$this->requete['join'][] = $join;
|
| 47 |
$this->requete['join'][] = $join;
|
73 |
}
|
| 48 |
}
|
74 |
}
|
| Line 137... |
Line 163... |
| 137 |
|
163 |
|
| 138 |
private function ajouterContrainteAuteur() {
|
164 |
private function ajouterContrainteAuteur() {
|
| 139 |
if (isset($this->parametres['masque.auteur'])) {
|
165 |
if (isset($this->parametres['masque.auteur'])) {
|
| 140 |
$auteur = $this->parametres['masque.auteur'];
|
166 |
$auteur = $this->parametres['masque.auteur'];
|
| 141 |
// id du poster de l'obs
|
- |
|
| 142 |
$this->addJoin('LEFT JOIN del_utilisateur AS du ON (du.id_utilisateur = vdi.ce_utilisateur) ');
|
167 |
// id du poster de l'obs
|
| 143 |
// id du poster de l'image... NON, c'est le même que le posteur de l'obs
|
- |
|
| 144 |
// Cette jointure de table est ignoré ci-dessous pour les recherches d'auteurs
|
168 |
$prefixe = $this->getPrefixe();
|
| Line 145... |
Line 169... |
| 145 |
// $req['join'][] = 'LEFT JOIN del_utilisateur AS dui ON dui.id_utilisateur = vdi.i_ce_utilisateur';
|
169 |
$this->addJoin("LEFT JOIN del_utilisateur AS du ON (du.id_utilisateur = $prefixe.ce_utilisateur) ");
|
| 146 |
|
170 |
|
| 147 |
if (is_numeric($auteur)) {
|
171 |
if (is_numeric($auteur)) {
|
| 148 |
$this->ajouterContrainteAuteurId();
|
172 |
$this->ajouterContrainteAuteurId();
|
| 149 |
} elseif(preg_match('/^.{5,}@[a-z0-9-.]{5,}$/i', $auteur)) {
|
173 |
} elseif(preg_match('/@[a-z0-9-]+(?:\.[a-z0-9-]+)*\.[a-z]{2,}$/i', $auteur)) {
|
| 150 |
$this->ajouterContrainteAuteurEmail();
|
174 |
$this->ajouterContrainteAuteurEmail();
|
| 151 |
} else {
|
175 |
} else {
|
| 152 |
$this->ajouterContrainteAuteurIntitule();
|
176 |
$this->ajouterContrainteAuteurIntitule();
|
| 153 |
}
|
177 |
}
|
| Line 154... |
Line 178... |
| 154 |
}
|
178 |
}
|
| 155 |
}
|
179 |
}
|
| - |
|
180 |
|
| 156 |
|
181 |
private function ajouterContrainteAuteurId() {
|
| 157 |
private function ajouterContrainteAuteurId() {
|
182 |
$id = $this->parametres['masque.auteur'];
|
| 158 |
$id = $this->parametres['masque.auteur'];
|
183 |
$prefixe = $this->getPrefixe();
|
| 159 |
$sqlTpl = '(du.id_utilisateur = %1$d OR vdi.ce_utilisateur = %1$d)';
|
184 |
$sqlTpl = "(du.id_utilisateur = %1\$d OR $prefixe.ce_utilisateur = %1\$d)";
|
| Line 160... |
Line 185... |
| 160 |
$whereAuteur = sprintf($sqlTpl, $id);
|
185 |
$whereAuteur = sprintf($sqlTpl, $id);
|
| 161 |
$this->addWhere('masque.auteur', $whereAuteur);
|
186 |
$this->addWhere('masque.auteur', $whereAuteur);
|
| - |
|
187 |
}
|
| 162 |
}
|
188 |
|
| 163 |
|
189 |
private function ajouterContrainteAuteurEmail() {
|
| 164 |
private function ajouterContrainteAuteurEmail() {
|
190 |
$email = $this->parametres['masque.auteur'];
|
| 165 |
$email = $this->parametres['masque.auteur'];
|
191 |
$prefixe = $this->getPrefixe();
|
| 166 |
$sqlTpl = '(du.courriel LIKE %1$s OR vdi.courriel LIKE %1$s )';
|
192 |
$sqlTpl = "(du.courriel LIKE %1\$s OR $prefixe.courriel_utilisateur LIKE %1\$s )";
|
| Line 188... |
Line 214... |
| 188 |
|
214 |
|
| 189 |
private function ajouterContrainteAuteurPrenomOuNom() {
|
215 |
private function ajouterContrainteAuteurPrenomOuNom() {
|
| Line 190... |
Line 216... |
| 190 |
$prenomOuNom = $this->parametres['masque.auteur'];
|
216 |
$prenomOuNom = $this->parametres['masque.auteur'];
|
| - |
|
217 |
|
| 191 |
|
218 |
$sqlTpl = 'CONCAT(%s,%s) LIKE %s';
|
| 192 |
$sqlTpl = 'CONCAT(%s,%s) LIKE %s';
|
219 |
$prefixe = $this->getPrefixe();
|
| 193 |
$champsPrenomSql = self::ajouterIfNullPourConcat($this->champsPrenom);
|
220 |
$champsPrenomSql = self::ajouterIfNullPourConcat($this->champsPrenom, $prefixe);
|
| Line 194... |
Line 221... |
| 194 |
$champsNomSql = self::ajouterIfNullPourConcat($this->champsNom);
|
221 |
$champsNomSql = self::ajouterIfNullPourConcat($this->champsNom, $prefixe);
|
| 195 |
$auteurMotif = $this->bdd->proteger("%$prenomOuNom%");
|
222 |
$auteurMotif = $this->bdd->proteger("%$prenomOuNom%");
|
| 196 |
|
223 |
|
| Line 197... |
Line 224... |
| 197 |
$auteurWhere = sprintf($sqlTpl, $champsPrenomSql, $champsNomSql, $auteurMotif);
|
224 |
$auteurWhere = sprintf($sqlTpl, $champsPrenomSql, $champsNomSql, $auteurMotif);
|
| 198 |
$this->addWhere('masque.auteur', $auteurWhere);
|
225 |
$this->addWhere('masque.auteur', $auteurWhere);
|
| Line 199... |
Line 226... |
| 199 |
}
|
226 |
}
|
| - |
|
227 |
|
| 200 |
|
228 |
private function ajouterContrainteAuteurPrenomEtNom() {
|
| 201 |
private function ajouterContrainteAuteurPrenomEtNom() {
|
229 |
list($prenom, $nom) = explode(' ', $this->parametres['masque.auteur']);
|
| 202 |
list($prenom, $nom) = explode(' ', $this->parametres['masque.auteur']);
|
230 |
|
| 203 |
|
231 |
$sqlTpl = '(CONCAT(%1$s,%2$s) LIKE %3$s AND CONCAT(%1$s,%2$s) LIKE %4$s)';
|
| Line 204... |
Line 232... |
| 204 |
$sqlTpl = '(CONCAT(%1$s,%2$s) LIKE %3$s AND CONCAT(%1$s,%2$s) LIKE %4$s)';
|
232 |
$prefixe = $this->getPrefixe();
|
| 205 |
$champsPrenomSql = self::ajouterIfNullPourConcat($this->champsPrenom);
|
233 |
$champsPrenomSql = self::ajouterIfNullPourConcat($this->champsPrenom, $prefixe);
|
| Line 214... |
Line 242... |
| 214 |
/**
|
242 |
/**
|
| 215 |
* Lorsque l'on concatène des champs, un seul NULL prend le dessus,
|
243 |
* Lorsque l'on concatène des champs, un seul NULL prend le dessus,
|
| 216 |
* Il faut donc utiliser la syntaxe IFNULL(%s, "").
|
244 |
* Il faut donc utiliser la syntaxe IFNULL(%s, "").
|
| 217 |
* (Cette fonction effectue aussi l'implode() "final"
|
245 |
* (Cette fonction effectue aussi l'implode() "final"
|
| 218 |
*/
|
246 |
*/
|
| 219 |
private static function ajouterIfNullPourConcat($champs) {
|
247 |
private static function ajouterIfNullPourConcat($champs, $prefixe) {
|
| 220 |
$champsProteges = array();
|
248 |
$champsProteges = array();
|
| 221 |
foreach ($champs as $champ) {
|
249 |
foreach ($champs as $champ) {
|
| - |
|
250 |
if (strstr($champ, '.') === false) {
|
| - |
|
251 |
$champ = "$prefixe.$champ";
|
| - |
|
252 |
}
|
| 222 |
$champsProteges[] = "IFNULL($champ, '')";
|
253 |
$champsProteges[] = "IFNULL($champ, '')";
|
| 223 |
}
|
254 |
}
|
| 224 |
return implode(',', $champsProteges);
|
255 |
return implode(',', $champsProteges);
|
| 225 |
}
|
256 |
}
|
| Line 226... |
Line 257... |
| 226 |
|
257 |
|
| 227 |
private function ajouterContrainteDate() {
|
258 |
private function ajouterContrainteDate() {
|
| 228 |
if (isset($this->parametres['masque.date'])) {
|
259 |
if (isset($this->parametres['masque.date'])) {
|
| 229 |
$date = $this->parametres['masque.date'];
|
260 |
$date = $this->parametres['masque.date'];
|
| 230 |
if (is_integer($date) && $date < 2030 && $date > 1600) {
|
261 |
if (preg_match('/^\d{4}$/', $date) && $date < 2030 && $date > 1600) {
|
| 231 |
$sqlTpl = "YEAR(vdi.date_observation) = %d";
|
262 |
$sqlTpl = "YEAR(do.date_observation) = %d";
|
| 232 |
$dateWhere = sprintf($sqlTpl, $date);
|
263 |
$dateWhere = sprintf($sqlTpl, $date);
|
| 233 |
$this->addWhere('masque.date', $dateWhere);
|
264 |
$this->addWhere('masque.date', $dateWhere);
|
| 234 |
} else {
|
265 |
} else {
|
| 235 |
$sqlTpl = "DATE_FORMAT(vdi.date_observation, '%%Y-%%m-%%d') = %s";
|
266 |
$sqlTpl = "do.date_observation = %s";
|
| 236 |
$dateP = $this->bdd->proteger(strftime('%Y-%m-%d', $date));
|
267 |
$dateP = $this->bdd->proteger($date);
|
| 237 |
$dateWhere = sprintf($sqlTpl, $dateP);
|
268 |
$dateWhere = sprintf($sqlTpl, $dateP);
|
| 238 |
$this->addWhere('masque.date', $dateWhere);
|
269 |
$this->addWhere('masque.date', $dateWhere);
|
| - |
|
270 |
}
|
| - |
|
271 |
|
| - |
|
272 |
if ($this->etreAppliImg()) {
|
| - |
|
273 |
$this->addJoin('LEFT JOIN del_observation AS do ON (di.ce_observation = do.id_observation) ');
|
| 239 |
}
|
274 |
}
|
| 240 |
}
|
275 |
}
|
| Line 241... |
Line 276... |
| 241 |
}
|
276 |
}
|
| 242 |
|
277 |
|
| 243 |
private function ajouterContrainteDepartement() {
|
278 |
private function ajouterContrainteDepartement() {
|
| 244 |
if (isset($this->parametres['masque.departement'])) {
|
279 |
if (isset($this->parametres['masque.departement'])) {
|
| 245 |
$dept = $this->parametres['masque.departement'];
|
280 |
$dept = $this->parametres['masque.departement'];
|
| - |
|
281 |
$deptMotif = $this->bdd->proteger("INSEE-C:$dept");
|
| - |
|
282 |
$this->addWhere('masque.departement', "do.ce_zone_geo LIKE $deptMotif");
|
| - |
|
283 |
|
| - |
|
284 |
if ($this->etreAppliImg()) {
|
| 246 |
$deptMotif = $this->bdd->proteger("INSEE-C:$dept");
|
285 |
$this->addJoin('LEFT JOIN del_observation AS do ON (di.ce_observation = do.id_observation) ');
|
| 247 |
$this->addWhere('masque.departement', "vdi.ce_zone_geo LIKE $deptMotif");
|
286 |
}
|
| Line 248... |
Line 287... |
| 248 |
}
|
287 |
}
|
| 249 |
}
|
288 |
}
|
| 250 |
|
289 |
|
| 251 |
private function ajouterContrainteIdZoneGeo() {
|
290 |
private function ajouterContrainteIdZoneGeo() {
|
| - |
|
291 |
if (isset($this->parametres['masque.id_zone_geo'])) {
|
| - |
|
292 |
$idZgMotif = $this->bdd->proteger($this->parametres['masque.id_zone_geo']);
|
| - |
|
293 |
$this->addWhere('masque.id_zone_geo', "do.ce_zone_geo = $idZgMotif");
|
| - |
|
294 |
|
| 252 |
if (isset($this->parametres['masque.id_zone_geo'])) {
|
295 |
if ($this->etreAppliImg()) {
|
| 253 |
$idZgMotif = $this->bdd->proteger($this->parametres['masque.id_zone_geo']);
|
296 |
$this->addJoin('LEFT JOIN del_observation AS do ON (di.ce_observation = do.id_observation) ');
|
| Line 254... |
Line 297... |
| 254 |
$this->addWhere('masque.id_zone_geo', "vdi.ce_zone_geo = $idZgMotif");
|
297 |
}
|
| 255 |
}
|
298 |
}
|
| 256 |
}
|
299 |
}
|
| 257 |
|
300 |
|
| 258 |
private function ajouterContrainteGenre() {
|
301 |
private function ajouterContrainteGenre() {
|
| - |
|
302 |
if (isset($this->parametres['masque.genre'])) {
|
| - |
|
303 |
$genre = $this->parametres['masque.genre'];
|
| - |
|
304 |
$genreMotif = $this->bdd->proteger("%$genre% %");
|
| - |
|
305 |
$this->addWhere('masque.genre', "do.nom_sel LIKE $genreMotif");
|
| 259 |
if (isset($this->parametres['masque.genre'])) {
|
306 |
|
| 260 |
$genre = $this->parametres['masque.genre'];
|
307 |
if ($this->etreAppliImg()) {
|
| Line 261... |
Line 308... |
| 261 |
$genreMotif = $this->bdd->proteger("%$genre% %");
|
308 |
$this->addJoin('LEFT JOIN del_observation AS do ON (di.ce_observation = do.id_observation) ');
|
| 262 |
$this->addWhere('masque.genre', "vdi.nom_sel LIKE $genreMotif");
|
309 |
}
|
| 263 |
}
|
310 |
}
|
| 264 |
}
|
311 |
}
|
| - |
|
312 |
|
| - |
|
313 |
private function ajouterContrainteFamille() {
|
| - |
|
314 |
if (isset($this->parametres['masque.famille'])) {
|
| - |
|
315 |
$familleMotif = $this->bdd->proteger($this->parametres['masque.famille']);
|
| 265 |
|
316 |
$this->addWhere('masque.famille', "do.famille = $familleMotif");
|
| 266 |
private function ajouterContrainteFamille() {
|
317 |
|
| Line 267... |
Line 318... |
| 267 |
if (isset($this->parametres['masque.famille'])) {
|
318 |
if ($this->etreAppliImg()) {
|
| 268 |
$familleMotif = $this->bdd->proteger($this->parametres['masque.famille']);
|
319 |
$this->addJoin('LEFT JOIN del_observation AS do ON (di.ce_observation = do.id_observation) ');
|
| 269 |
$this->addWhere('masque.famille', "vdi.famille = $familleMotif");
|
320 |
}
|
| 270 |
}
|
321 |
}
|
| 271 |
}
|
322 |
}
|
| - |
|
323 |
|
| - |
|
324 |
private function ajouterContrainteNs() {
|
| - |
|
325 |
if (isset($this->parametres['masque.ns'])) {
|
| - |
|
326 |
$ns = $this->parametres['masque.ns'];
|
| 272 |
|
327 |
$nsMotif = $this->bdd->proteger("$ns%");
|
| 273 |
private function ajouterContrainteNs() {
|
328 |
$this->addWhere('masque.ns', "do.nom_sel LIKE $nsMotif");
|
| Line 274... |
Line 329... |
| 274 |
if (isset($this->parametres['masque.ns'])) {
|
329 |
|
| 275 |
$ns = $this->parametres['masque.ns'];
|
330 |
if ($this->etreAppliImg()) {
|
| 276 |
$nsMotif = $this->bdd->proteger("$ns%");
|
331 |
$this->addJoin('LEFT JOIN del_observation AS do ON (di.ce_observation = do.id_observation) ');
|
| 277 |
$this->addWhere('masque.ns', "vdi.nom_sel LIKE $nsMotif");
|
332 |
}
|
| 278 |
}
|
333 |
}
|
| - |
|
334 |
}
|
| - |
|
335 |
|
| - |
|
336 |
private function ajouterContrainteNn() {
|
| - |
|
337 |
if (isset($this->parametres['masque.nn'])) {
|
| 279 |
}
|
338 |
$sqlTpl = '(do.nom_sel_nn = %1$d OR do.nom_ret_nn = %1$d)';
|
| 280 |
|
339 |
$nnWhere = sprintf($sqlTpl, $this->parametres['masque.nn']);
|
| Line 281... |
Line 340... |
| 281 |
private function ajouterContrainteNn() {
|
340 |
$this->addWhere('masque.nn', $nnWhere);
|
| 282 |
if (isset($this->parametres['masque.nn'])) {
|
341 |
|
| 283 |
$sqlTpl = '(vdi.nom_sel_nn = %1$d OR vdi.nom_ret_nn = %1$d)';
|
342 |
if ($this->etreAppliImg()) {
|
| 284 |
$nnWhere = sprintf($sqlTpl, $this->parametres['masque.nn']);
|
343 |
$this->addJoin('LEFT JOIN del_observation AS do ON (di.ce_observation = do.id_observation) ');
|
| 285 |
$this->addWhere('masque.nn', $nnWhere);
|
344 |
}
|
| - |
|
345 |
}
|
| - |
|
346 |
}
|
| - |
|
347 |
|
| - |
|
348 |
private function ajouterContrainteReferentiel() {
|
| 286 |
}
|
349 |
if (isset($this->parametres['masque.referentiel'])) {
|
| 287 |
}
|
350 |
$ref = $this->parametres['masque.referentiel'];
|
| Line 288... |
Line 351... |
| 288 |
|
351 |
$refMotif = $this->bdd->proteger("$ref%");
|
| 289 |
private function ajouterContrainteReferentiel() {
|
352 |
$this->addWhere('masque.referentiel', "do.nom_referentiel LIKE $refMotif");
|
| 290 |
if (isset($this->parametres['masque.referentiel'])) {
|
353 |
|
| 291 |
$ref = $this->parametres['masque.referentiel'];
|
354 |
if ($this->etreAppliImg()) {
|
| 292 |
$refMotif = $this->bdd->proteger("$ref%");
|
355 |
$this->addJoin('LEFT JOIN del_observation AS do ON (di.ce_observation = do.id_observation) ');
|
| - |
|
356 |
}
|
| - |
|
357 |
}
|
| - |
|
358 |
}
|
| - |
|
359 |
|
| 293 |
$this->addWhere('masque.referentiel', "vdi.nom_referentiel LIKE $refMotif");
|
360 |
private function ajouterContrainteCommune() {
|
| 294 |
}
|
361 |
if (isset($this->parametres['masque.commune'])) {
|
| Line 295... |
Line 362... |
| 295 |
}
|
362 |
$commune = $this->parametres['masque.commune'];
|
| 296 |
|
363 |
$communeMotif = $this->bdd->proteger("$commune%");
|
| 297 |
private function ajouterContrainteCommune() {
|
364 |
$this->addWhere('masque.commune', "do.zone_geo LIKE $communeMotif");
|
| 298 |
if (isset($this->parametres['masque.commune'])) {
|
365 |
|
| 299 |
$commune = $this->parametres['masque.commune'];
|
366 |
if ($this->etreAppliImg()) {
|
| 300 |
$communeMotif = $this->bdd->proteger("$commune%");
|
367 |
$this->addJoin('LEFT JOIN del_observation AS do ON (di.ce_observation = do.id_observation) ');
|
| Line 301... |
Line 368... |
| 301 |
$this->addWhere('masque.commune', "vdi.zone_geo LIKE $communeMotif");
|
368 |
}
|
| 302 |
}
|
369 |
}
|
| 303 |
}
|
370 |
}
|
| 304 |
|
371 |
|
| - |
|
372 |
public function ajouterConstrainteAppliObs() {
|
| 305 |
public function ajouterConstrainteAppliObs() {
|
373 |
$this->ajouterContrainteTagCel();
|
| 306 |
$this->ajouterContrainteTagCel();
|
374 |
$this->ajouterContrainteType();
|
| 307 |
$this->ajouterContrainteType();
|
375 |
// TODO : ATTENTION -> vue que l'on utilise une vue basée sur les images, nous devons grouper par obs
|
| 308 |
// TODO : ATTENTION -> vue que l'on utilise une vue basée sur les images, nous devons grouper par obs
|
376 |
$this->addGroupBy('do.id_observation');
|
| 309 |
$this->addGroupBy('vdi.id_observation');
|
377 |
}
|
| 310 |
}
|
378 |
|
| 311 |
|
379 |
/**
|
| 312 |
/**
|
380 |
* @param $req: la représentation de la requête MySQL complète, à amender.
|
| 313 |
* @param $req: la représentation de la requête MySQL complète, à amender.
|
381 |
*/
|
| 314 |
*/
|
382 |
private function ajouterContrainteType() {
|
| 315 |
private function ajouterContrainteType() {
|
383 |
if (isset($this->parametres['masque.type'])) {
|
| 316 |
if (array_key_exists('adeterminer', $this->parametres['masque.type'])) {
|
384 |
if (array_key_exists('adeterminer', $this->parametres['masque.type'])) {
|
| 317 |
// Récupèration de toutes les observations qui on le tag "aDeterminer" *ou* qui n'ont pas de nom d'espèce
|
385 |
// Récupèration de toutes les observations qui on le tag "aDeterminer" *ou* qui n'ont pas de nom d'espèce
|
| 318 |
// *ou* qui ont la "certitude" à ("aDeterminer" *ou* "douteux")
|
386 |
// *ou* qui ont la "certitude" à ("aDeterminer" *ou* "douteux")
|
| 319 |
$this->addWhere('masque.type', '('.
|
387 |
$this->addWhere('masque.type', '('.
|
| 320 |
'vdi.certitude = "aDeterminer" '.
|
388 |
'do.certitude = "aDeterminer" '.
|
| 321 |
'OR vdi.certitude = "douteux" '.
|
389 |
'OR do.certitude = "douteux" '.
|
| 322 |
'OR vdi.mots_cles_texte LIKE "%aDeterminer%" '.
|
390 |
'OR do.mots_cles_texte LIKE "%aDeterminer%" '.
|
| 323 |
'OR vdi.nom_sel_nn IS NULL '.
|
391 |
'OR do.nom_sel_nn IS NULL '.
|
| 324 |
'OR vdi.nom_sel_nn = 0 '.// il ne DEVRAIT pas y avoir d'entrées à 0, mais il y en a quand-même !!
|
392 |
'OR do.nom_sel_nn = 0 '.// il ne DEVRAIT pas y avoir d'entrées à 0, mais il y en a quand-même !!
|
| 325 |
')');
|
393 |
')');
|
| - |
|
394 |
}
|
| - |
|
395 |
if (array_key_exists('validees', $this->parametres['masque.type'])) {
|
| - |
|
396 |
// Récupèration de toutes les observations ayant un commentaire doté de proposition_retenue = 1
|
| - |
|
397 |
$this->addJoin('INNER JOIN del_commentaire AS dc '.
|
| - |
|
398 |
'ON (do.id_observation = dc.ce_observation AND dc.proposition_retenue = 1) ');
|
| 326 |
}
|
399 |
}
|
| 327 |
if (array_key_exists('validees', $this->parametres['masque.type'])) {
|
400 |
|
| Line 328... |
Line 401... |
| 328 |
// Récupèration de toutes les observations ayant un commentaire doté de proposition_retenue = 1
|
401 |
if (array_key_exists('endiscussion', $this->parametres['masque.type'])) {
|
| 329 |
$this->addJoin('INNER JOIN del_commentaire AS dc '.
|
402 |
$nbreCommentaire =(int) ($this->conteneur->getParametre('observations.nb_commentaires_discussion'));
|
| Line 364... |
Line 437... |
| 364 |
|
437 |
|
| 365 |
private function ajouterContrainteMilieu() {
|
438 |
private function ajouterContrainteMilieu() {
|
| 366 |
if (isset($this->parametres['masque.milieu'])) {
|
439 |
if (isset($this->parametres['masque.milieu'])) {
|
| 367 |
$milieu = $this->parametres['masque.milieu'];
|
440 |
$milieu = $this->parametres['masque.milieu'];
|
| 368 |
$milieuMotif = $this->bdd->proteger("%$milieu%");
|
441 |
$milieuMotif = $this->bdd->proteger("%$milieu%");
|
| - |
|
442 |
$this->addWhere('masque.milieu', "do.milieu LIKE $milieuMotif");
|
| - |
|
443 |
|
| - |
|
444 |
if ($this->etreAppliImg()) {
|
| - |
|
445 |
$this->addJoin('LEFT JOIN del_observation AS do ON (di.ce_observation = do.id_observation) ');
|
| 369 |
$this->addWhere('masque.milieu', "vdi.milieu LIKE $milieuMotif");
|
446 |
}
|
| 370 |
}
|
447 |
}
|
| Line 371... |
Line 448... |
| 371 |
}
|
448 |
}
|
| 372 |
|
449 |
|
| Line 390... |
Line 467... |
| 390 |
if (isset($this->parametres['tri'])) {
|
467 |
if (isset($this->parametres['tri'])) {
|
| 391 |
$tri = $this->parametres['tri'];
|
468 |
$tri = $this->parametres['tri'];
|
| Line 392... |
Line 469... |
| 392 |
|
469 |
|
| 393 |
if (isset($this->parametres['protocole']) && ($tri == 'moyenne-arithmetique' || $tri == 'points')) {
|
470 |
if (isset($this->parametres['protocole']) && ($tri == 'moyenne-arithmetique' || $tri == 'points')) {
|
| 394 |
// $this->parametres['protocole'] *est* défini (cf Outils::filtrerUrlsParams...())
|
471 |
// $this->parametres['protocole'] *est* défini (cf Outils::filtrerUrlsParams...())
|
| 395 |
$sqlTpl = 'LEFT JOIN del_image_stat dis ON vdi.id_image = dis.ce_image AND dis.ce_protocole = %d';
|
472 |
$sqlTpl = 'LEFT JOIN del_image_stat AS dis ON di.id_image = dis.ce_image AND dis.ce_protocole = %d';
|
| 396 |
$triSql = sprintf($sqlTpl, $this->parametres['protocole']);
|
473 |
$triSql = sprintf($sqlTpl, $this->parametres['protocole']);
|
| 397 |
$this->addJoinDis($triSql);
|
474 |
$this->addJoinDis($triSql);
|
| Line 398... |
Line 475... |
| 398 |
}
|
475 |
}
|
| 399 |
|
476 |
|
| 400 |
if (isset($this->parametres['ordre']) && $tri == 'tags') {
|
477 |
if (isset($this->parametres['ordre']) && $tri == 'tags') {
|
| 401 |
$typeJointure = ($this->parametres['ordre'] == 'desc') ? 'INNER' : 'LEFT';
|
478 |
$typeJointure = ($this->parametres['ordre'] == 'desc') ? 'INNER' : 'LEFT';
|
| 402 |
$this->addJoin("$typeJointure JOIN del_image_stat dis ON vdi.id_image = dis.ce_image");
|
479 |
$this->addJoin("$typeJointure JOIN del_image_stat AS dis ON di.id_image = dis.ce_image");
|
| 403 |
// nécessaire (dup ce_image dans del_image_stat)
|
480 |
// nécessaire (dup ce_image dans del_image_stat)
|
| 404 |
$this->addGroupBy('vdi.id_observation');
|
481 |
$this->addGroupBy('di.ce_observation');
|
| 405 |
}
|
482 |
}
|
| Line 406... |
Line 483... |
| 406 |
}
|
483 |
}
|
| Line 416... |
Line 493... |
| 416 |
if (isset($this->parametres['masque.tag_cel']['AND'])) {
|
493 |
if (isset($this->parametres['masque.tag_cel']['AND'])) {
|
| 417 |
$tags = $this->parametres['masque.tag_cel']['AND'];
|
494 |
$tags = $this->parametres['masque.tag_cel']['AND'];
|
| 418 |
$clausesWhere = array();
|
495 |
$clausesWhere = array();
|
| 419 |
foreach ($tags as $tag) {
|
496 |
foreach ($tags as $tag) {
|
| 420 |
$tagMotif = $this->bdd->proteger("%$tag%");
|
497 |
$tagMotif = $this->bdd->proteger("%$tag%");
|
| 421 |
$sqlTpl = "CONCAT(IFNULL(vdi.mots_cles_texte,''),IFNULL(vdi.i_mots_cles_texte,'')) LIKE %s";
|
498 |
$sqlTpl = "CONCAT(IFNULL(do.mots_cles_texte,''),IFNULL(di.mots_cles_texte,'')) LIKE %s";
|
| 422 |
$clausesWhere[] = sprintf($sqlTpl, $tagMotif);
|
499 |
$clausesWhere[] = sprintf($sqlTpl, $tagMotif);
|
| 423 |
}
|
500 |
}
|
| 424 |
$whereTags = implode(' AND ', $clausesWhere);
|
501 |
$whereTags = implode(' AND ', $clausesWhere);
|
| 425 |
$this->addWhere('masque.tag_cel', "($whereTags)");
|
502 |
$this->addWhere('masque.tag_cel', "($whereTags)");
|
| 426 |
} else if (isset($this->parametres['masque.tag_cel']['OR'])) {
|
503 |
} else if (isset($this->parametres['masque.tag_cel']['OR'])) {
|
| 427 |
$tags = $this->parametres['masque.tag_cel']['OR'];
|
504 |
$tags = $this->parametres['masque.tag_cel']['OR'];
|
| 428 |
$sqlTpl = "CONCAT(IFNULL(vdi.mots_cles_texte,''),IFNULL(vdi.i_mots_cles_texte,'')) REGEXP %s";
|
505 |
$sqlTpl = "CONCAT(IFNULL(do.mots_cles_texte,''),IFNULL(di.mots_cles_texte,'')) REGEXP %s";
|
| 429 |
$tagMotif = $this->bdd->proteger(implode('|', $tags));
|
506 |
$tagMotif = $this->bdd->proteger(implode('|', $tags));
|
| 430 |
$tagSql = sprintf($sqlTpl, $tagMotif);
|
507 |
$tagSql = sprintf($sqlTpl, $tagMotif);
|
| 431 |
$this->addWhere('masque.tag_cel', $tagSql);
|
508 |
$this->addWhere('masque.tag_cel', $tagSql);
|
| 432 |
}
|
509 |
}
|
| - |
|
510 |
if ($this->etreAppliImg()) {
|
| - |
|
511 |
$this->addJoin('LEFT JOIN del_observation AS do ON (di.ce_observation = do.id_observation) ');
|
| - |
|
512 |
}
|
| - |
|
513 |
if ($this->etreAppliObs()) {
|
| - |
|
514 |
$this->addJoin('LEFT JOIN del_image AS di ON (do.id_observation = di.ce_observation) ');
|
| - |
|
515 |
}
|
| 433 |
}
|
516 |
}
|
| 434 |
}
|
517 |
}
|
| Line 435... |
Line 518... |
| 435 |
|
518 |
|
| 436 |
/**
|
519 |
/**
|
| Line 460... |
Line 543... |
| 460 |
'FROM del_image_tag '.
|
543 |
'FROM del_image_tag '.
|
| 461 |
'WHERE actif = 1 '.
|
544 |
'WHERE actif = 1 '.
|
| 462 |
'GROUP BY ce_image '.
|
545 |
'GROUP BY ce_image '.
|
| 463 |
"HAVING GROUP_CONCAT(tag_normalise) REGEXP $tagsMotif ".
|
546 |
"HAVING GROUP_CONCAT(tag_normalise) REGEXP $tagsMotif ".
|
| 464 |
' -- '.__FILE__.' : '.__LINE__;
|
547 |
' -- '.__FILE__.' : '.__LINE__;
|
| - |
|
548 |
|
| 465 |
$sql = $this->recupererSqlContrainteTag($requete);
|
549 |
$sql = $this->recupererSqlContrainteTag($requete);
|
| 466 |
$this->addWhere('masque.tag_del', $sql);
|
550 |
$this->addWhere('masque.tag_del', $sql);
|
| 467 |
}
|
551 |
}
|
| 468 |
}
|
552 |
}
|
| 469 |
}
|
553 |
}
|
| Line 478... |
Line 562... |
| 478 |
if (!empty($ids)) {
|
562 |
if (!empty($ids)) {
|
| 479 |
$clauseIn = implode(',', $ids);
|
563 |
$clauseIn = implode(',', $ids);
|
| 480 |
} else {
|
564 |
} else {
|
| 481 |
$clauseIn = 'SELECT ce_image FROM del_image_tag WHERE false';
|
565 |
$clauseIn = 'SELECT ce_image FROM del_image_tag WHERE false';
|
| 482 |
}
|
566 |
}
|
| 483 |
return "vdi.id_image IN ($clauseIn)";
|
567 |
return "di.id_image IN ($clauseIn)";
|
| 484 |
}
|
568 |
}
|
| Line 485... |
Line 569... |
| 485 |
|
569 |
|
| 486 |
/**
|
570 |
/**
|
| 487 |
* Partie spécifique à PictoFlora:
|
571 |
* Partie spécifique à PictoFlora:
|
| Line 500... |
Line 584... |
| 500 |
break;
|
584 |
break;
|
| 501 |
case 'tags' :
|
585 |
case 'tags' :
|
| 502 |
$this->addOrderBy("dis.nb_tags $ordre, id_image DESC");
|
586 |
$this->addOrderBy("dis.nb_tags $ordre, id_image DESC");
|
| 503 |
break;
|
587 |
break;
|
| 504 |
case 'date_observation' :
|
588 |
case 'date_observation' :
|
| 505 |
$this->addOrderBy("date_observation $ordre, id_observation $ordre");
|
589 |
$this->addOrderBy("date_observation $ordre, ce_observation $ordre");
|
| 506 |
break;
|
590 |
break;
|
| 507 |
case 'date_transmission' :
|
591 |
case 'date_transmission' :
|
| 508 |
default:
|
592 |
default:
|
| 509 |
$this->addOrderBy("date_transmission $ordre, id_observation $ordre");
|
593 |
$this->addOrderBy("di.date_transmission $ordre, ce_observation $ordre");
|
| 510 |
}
|
594 |
}
|
| 511 |
}
|
595 |
}
|
| Line 512... |
Line 596... |
| 512 |
|
596 |
|
| 513 |
public function definirOrdreSqlAppliObs() {
|
597 |
public function definirOrdreSqlAppliObs() {
|
| Line 517... |
Line 601... |
| 517 |
switch ($this->parametres['tri']) {
|
601 |
switch ($this->parametres['tri']) {
|
| 518 |
case 'date_observation' :
|
602 |
case 'date_observation' :
|
| 519 |
$this->addOrderBy("date_observation $ordre, id_observation $ordre");
|
603 |
$this->addOrderBy("date_observation $ordre, id_observation $ordre");
|
| 520 |
break;
|
604 |
break;
|
| 521 |
default:
|
605 |
default:
|
| 522 |
$this->addOrderBy("date_transmission $ordre, id_observation $ordre");
|
606 |
$this->addOrderBy("do.date_transmission $ordre, id_observation $ordre");
|
| 523 |
}
|
607 |
}
|
| 524 |
}
|
608 |
}
|
| Line 525... |
Line 609... |
| 525 |
|
609 |
|
| 526 |
public function getAliasDesChamps($champsEtAlias, $select = null, $prefix = null) {
|
610 |
public function getAliasDesChamps($champsEtAlias, $select = null, $prefix = null) {
|