Subversion Repositories eFlore/Applications.cel

Rev

Rev 938 | Rev 954 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 938 Rev 940
Line 70... Line 70...
70
                    $this->construireWhereCommune().
70
                    $this->construireWhereCommune().
71
                    $this->construireWhereUtilisateur().
71
                    $this->construireWhereUtilisateur().
72
					$this->construireWhereNumTaxon().
72
					$this->construireWhereNumTaxon().
73
					$this->construireWhereNomTaxon().
73
					$this->construireWhereNomTaxon().
74
					$this->construireWhereDate().
74
					$this->construireWhereDate().
-
 
75
					$this->construireWhereCommentaire().
75
					$this->construireWhereProjet().
76
					$this->construireWhereProjet().
76
					$this->construireWhereTag();
77
					$this->construireWhereTag();
77
		
-
 
-
 
78
		//die($requete);
78
		$resultats = $this->requeter($requete);
79
		$resultats = $this->requeter($requete);
Line 79... Line 80...
79
		
80
		
80
		// Traitement des résultats
81
		// Traitement des résultats
81
		$obs_nbre = $this->traiterNbreObs($resultats);
82
		$obs_nbre = $this->traiterNbreObs($resultats);
Line 140... Line 141...
140
						$this->construireWhereCoordonnees().
141
						$this->construireWhereCoordonnees().
141
						$this->construireWhereUtilisateur().
142
						$this->construireWhereUtilisateur().
142
						$this->construireWhereNumTaxon().
143
						$this->construireWhereNumTaxon().
143
						$this->construireWhereNomTaxon().
144
						$this->construireWhereNomTaxon().
144
						$this->construireWhereDate().
145
						$this->construireWhereDate().
-
 
146
						$this->construireWhereCommentaire().
145
						$this->construireWhereProjet().
147
						$this->construireWhereProjet().
146
						$this->construireWhereTag().
148
						$this->construireWhereTag().
147
	                    'ORDER BY nom_sel ASC '.
149
	                    'ORDER BY nom_sel ASC '.
148
	                    "LIMIT {$this->start},{$this->limit} ";
150
	                    "LIMIT {$this->start},{$this->limit} ";
149
			//die($requete);
151
			//die($requete);
Line 283... Line 285...
283
                    $this->construireWhereCommune().
285
                    $this->construireWhereCommune().
284
                    $this->construireWhereUtilisateur().
286
                    $this->construireWhereUtilisateur().
285
					$this->construireWhereNumTaxon().
287
					$this->construireWhereNumTaxon().
286
					$this->construireWhereNomTaxon().
288
					$this->construireWhereNomTaxon().
287
					$this->construireWhereDate().
289
					$this->construireWhereDate().
-
 
290
					$this->construireWhereCommentaire().
288
					$this->construireWhereProjet().
291
					$this->construireWhereProjet().
289
					$this->construireWhereTag();
292
					$this->construireWhereTag();
290
					'ORDER BY nom_ret ASC '.
293
					'ORDER BY nom_ret ASC '.
291
                    "LIMIT {$this->start},{$this->limit} ";
294
                    "LIMIT {$this->start},{$this->limit} ";
292
		//$this->debug[] = $requete;
295
		//$this->debug[] = $requete;
Line 320... Line 323...
320
	}
323
	}
Line 321... Line 324...
321
	
324
	
322
	private function construireWhereCoordonnees() {
325
	private function construireWhereCoordonnees() {
323
		$sql = '';
326
		$sql = '';
324
		// Récupération des coordonnées depuis l'id station
327
		// Récupération des coordonnées depuis l'id station
325
		extract($this->decomposerStationId());
328
		extract($this->decomposerParametreStation());
326
		if (isset($type)) {
329
		if (isset($type)) {
327
			if ($type == 'UTM') {
330
			if ($type == 'UTM') {
328
				$secteur = $this->proteger($secteur);
331
				$secteur = $this->proteger($secteur);
329
				$x_utm = $this->proteger($x_utm);
332
				$x_utm = $this->proteger($x_utm);
Line 338... Line 341...
338
			}
341
			}
339
		}		
342
		}		
340
		return $sql;
343
		return $sql;
341
	}
344
	}
Line -... Line 345...
-
 
345
	
-
 
346
	private function construireWhereCommentaire() {
-
 
347
		$sql = '';
-
 
348
		list($type, $commentaire) = $this->decomposerParametreCommentaire();
-
 
349
		if (!$this->etreNull($commentaire)) {
-
 
350
			$commentaire = $this->proteger('%'.$commentaire.'%');
-
 
351
			switch ($type) {
-
 
352
				case '*' :
-
 
353
					$sql = $this->obtenirConditionPourCommentaires($commentaire);
-
 
354
					$sql = " AND (commentaire LIKE $commentaire OR ($sql)) ";
-
 
355
					break;
-
 
356
				case 'observation' :
-
 
357
					$sql = " AND commentaire LIKE $commentaire ";
-
 
358
					break;
-
 
359
				case 'photo' :
-
 
360
					$sql = ' AND '.$this->obtenirConditionPourCommentaires($commentaire).' ';
-
 
361
					break;
-
 
362
				case 'photo.meta' :
-
 
363
					$sql = ' AND '.$this->obtenirConditionPourCommentaireMeta($commentaire).' ';
-
 
364
					break;
-
 
365
				case 'photo.utilisateur' :
-
 
366
					$sql = ' AND '.$this->obtenirConditionPourCommentaireUtilisateur($commentaire).' ';
-
 
367
					break;
-
 
368
				default:
-
 
369
					$sql = " AND commentaire LIKE $commentaire ";
-
 
370
			}			
-
 
371
		}
-
 
372
		return $sql;
-
 
373
	}
-
 
374
	
342
	
375
	
343
	private function construireWhereNomTaxon() {
376
	private function construireWhereNomTaxon() {
344
		$sql = '';
-
 
345
		// Récupération des coordonnées depuis l'id station
377
		$sql = '';
346
		extract($this->parametres);
378
		list($type, $nom) = $this->decomposerParametreTaxon();
347
		if (!$this->etreNull($taxon)) {
-
 
348
			if (strpos($taxon, ':')) {
-
 
349
				list($type, $nom) = explode(':', $taxon);
-
 
350
			} else {
-
 
351
				$type = 'nr';
-
 
352
				$nom = $taxon;
-
 
353
			}
-
 
354
			
379
		if (!$this->etreNull($nom)) {
355
			$nom = $this->proteger($nom.'%');
380
			$nom = $this->proteger($nom.'%');
356
			switch ($type) {
381
			switch ($type) {
357
				case '*' :
382
				case '*' :
358
					$sql = " AND (nom_ret LIKE $nom OR nom_sel LIKE $nom OR famille LIKE $nom) ";
383
					$sql = " AND (nom_ret LIKE $nom OR nom_sel LIKE $nom OR famille LIKE $nom) ";
359
					break;
384
					break;
360
				case 'nr' :
385
				case 'retenu' :
361
					$sql = " AND nom_ret LIKE $nom ";
386
					$sql = " AND nom_ret LIKE $nom ";
362
					break;
387
					break;
363
				case 'ns' :
388
				case 'selectionne' :
364
					$sql = " AND nom_sel LIKE $nom ";
389
					$sql = " AND nom_sel LIKE $nom ";
365
					break;
390
					break;
366
				case 'f' :
391
				case 'famille' :
367
					$sql = " AND famille LIKE $nom ";
392
					$sql = " AND famille LIKE $nom ";
368
					break;
393
					break;
369
				default:
394
				default:
370
					$sql = " AND nom_ret LIKE $nom ";
395
					$sql = " AND nom_ret LIKE $nom ";
Line 374... Line 399...
374
	}
399
	}
Line 375... Line 400...
375
	
400
	
376
	private function construireWhereDate() {
401
	private function construireWhereDate() {
377
		$sql = '';
402
		$sql = '';
378
		// Récupération des coordonnées depuis l'id station
403
		// Récupération des coordonnées depuis l'id station
-
 
404
		list($type, $date) = $this->decomposerParametreDate();
379
		extract($this->parametres);
405
		
380
		if (!$this->etreNull($date)) {
-
 
381
			if (strpos($date, ':')) {
-
 
382
				list($type, $date) = explode(':', $date);
-
 
383
			} else {
-
 
384
				$type = 'observation';
-
 
385
			}
-
 
386
			
406
		if (!$this->etreNull($date)) {
387
			$date = $this->proteger($date.'%');
407
			$date = $this->proteger($date.'%');
388
			switch ($type) {
408
			switch ($type) {
389
				case '*' :
409
				case '*' :
390
					$sql = " AND (
410
					$sql = " AND (
Line 403... Line 423...
403
					$sql = " AND date_modification LIKE $date ";
423
					$sql = " AND date_modification LIKE $date ";
404
					break;
424
					break;
405
				case 'transmission' :
425
				case 'transmission' :
406
					$sql = " AND date_transmission LIKE $date ";
426
					$sql = " AND date_transmission LIKE $date ";
407
					break;
427
					break;
408
				case 'liaison' :
-
 
409
					$sql = '';
-
 
410
					break;
-
 
411
				case 'photo' :
428
				case 'photo' :
-
 
429
					$sql = $this->obtenirConditionPourDatePhoto($date);
-
 
430
					break;
-
 
431
				case 'ajout' :
-
 
432
					$sql = $this->obtenirConditionPourDateAjout($date);
412
					$sql = '';
433
					break;
-
 
434
				case 'liaison' :
-
 
435
					$sql = $this->obtenirConditionPourDateLiaison($date);
413
					break;
436
					break;
414
				default:
437
				default:
415
					$sql = " AND date_observation LIKE $date ";
438
					$sql = " AND date_observation LIKE $date ";
416
			}
439
			}
417
		}
440
		}
418
		return $sql;
441
		return $sql;
419
	}
442
	}
Line -... Line 443...
-
 
443
	
-
 
444
	private function obtenirConditionPourDatePhoto($date) {
-
 
445
		$observations = $this->obtenirObsLieesImg('date.photo', $date);
-
 
446
		if (is_null($observations)) {
-
 
447
			$this->debug[] = "Aucune observation n'est liée à une photo prise à la date : $date";
-
 
448
		}
-
 
449
		$sql = $this->assemblerObsEnConditionSql($observations);
-
 
450
		return $sql;
-
 
451
	}
-
 
452
	
-
 
453
	private function obtenirConditionPourDateLiaison($date) {
-
 
454
		$observations = $this->obtenirObsLieesImg('date.liaison', $date);
-
 
455
		if (is_null($observations)) {
-
 
456
			$this->debug[] = "Aucune observation n'a été liée à une image à à la date : $date";
-
 
457
		}
-
 
458
		$sql = $this->assemblerObsEnConditionSql($observations);
-
 
459
		return $sql;
-
 
460
	}
-
 
461
 
-
 
462
	private function obtenirConditionPourDateAjout($date) {
-
 
463
		$observations = $this->obtenirObsLieesImg('date.ajout', $date);
-
 
464
		if (is_null($observations)) {
-
 
465
			$this->debug[] = "Aucune observation n'est liée à une image ajoutée à la date : $date";
-
 
466
		}
-
 
467
		$sql = $this->assemblerObsEnConditionSql($observations);
-
 
468
		return $sql;
-
 
469
	}
-
 
470
	
-
 
471
	private function obtenirConditionPourCommentaireMeta($commentaire) {
-
 
472
		$observations = $this->obtenirObsLieesImg('commentaire.meta', $commentaire);
-
 
473
		if (is_null($observations)) {
-
 
474
			$this->debug[] = "Aucune observation n'est liée à une image dont le commentaire des méta-données correspond à : $commmentaire";
-
 
475
		}
-
 
476
		$operateur = '';
-
 
477
		$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
-
 
478
		return $sql;
-
 
479
	}
-
 
480
	
-
 
481
	private function obtenirConditionPourCommentaireUtilisateur($commentaire) {
-
 
482
		$observations = $this->obtenirObsLieesImg('commentaire.utilisateur', $commentaire);
-
 
483
		if (is_null($observations)) {
-
 
484
			$this->debug[] = "Aucune observation n'est liée à une image dont le commentaire des utilisateur correspond à : $commmentaire";
-
 
485
		}
-
 
486
		$operateur = '';
-
 
487
		$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
-
 
488
		return $sql;
-
 
489
	}
-
 
490
	
-
 
491
	private function obtenirConditionPourCommentaires($commentaire) {
-
 
492
		$observations = $this->obtenirObsLieesImg('commentaire.*', $commentaire);
-
 
493
		if (is_null($observations)) {
-
 
494
			$this->debug[] = "Aucune observation n'est liée à une image dont un des commentaires correspond à : $commmentaire";
-
 
495
		}
-
 
496
		$operateur = '';
-
 
497
		$sql = $this->assemblerObsEnConditionSql($observations, $operateur);
-
 
498
		return $sql;
-
 
499
	}
-
 
500
	
-
 
501
	/**
-
 
502
	 * Récupération des identifiant d'utilisateur et des ordres des observations correspondant à une date.
-
 
503
	 * Retour sous forme de tableau : array[identifiant] = array(ordre, ordre...);
-
 
504
	 */
-
 
505
	private function obtenirObsLieesImg($type, $param) {
-
 
506
		// Construction de la requête
-
 
507
		$requete = 	'SELECT DISTINCT coi_ce_observation AS ordre,  coi_ce_utilisateur AS utilisateur '.
-
 
508
			'FROM  cel_images '.
-
 
509
			'	LEFT JOIN cel_obs_images '.
-
 
510
			'		ON (ci_id_image = coi_ce_image) '.
-
 
511
			'	LEFT JOIN cel_inventory AS i '.
-
 
512
			'		ON (coi_ce_utilisateur = i.identifiant AND coi_ce_observation = i.ordre) '.
-
 
513
			'	LEFT JOIN locations AS l '.
-
 
514
			'		ON (l.name = i.location AND l.code = i.id_location) '.
-
 
515
			"WHERE  transmission = '1' ".
-
 
516
			($type == 'date.photo' ? " AND (ci_meta_date_time LIKE ".str_replace('-', ':', $param)." OR ci_meta_date LIKE $param) " : '').
-
 
517
			($type == 'date.ajout' ? " AND ci_meta_date_ajout LIKE $param " : '').
-
 
518
			($type == 'date.liaison' ? " AND coi_date_liaison LIKE $param " : '').
-
 
519
			($type == 'commentaire.meta' ? " AND ci_meta_comment LIKE $param " : '').
-
 
520
			($type == 'commentaire.utilisateur' ? "	AND ci_meta_user_comment LIKE $param " : '').
-
 
521
			($type == 'commentaire.*' ? " AND (ci_meta_comment LIKE $param OR ci_meta_user_comment LIKE $param) " : '').
-
 
522
			$this->construireWhereCoordonnees().			
-
 
523
			$this->construireWhereDept().
-
 
524
			$this->construireWhereCommune().
-
 
525
			$this->construireWhereUtilisateur().
-
 
526
			$this->construireWhereNumTaxon().
-
 
527
			$this->construireWhereNomTaxon().
-
 
528
			$this->construireWhereProjet().
-
 
529
			$this->construireWhereTag().
-
 
530
			'ORDER BY utilisateur ASC, ordre ASC';
-
 
531
		//$this->debug[] = $requete;
-
 
532
		//die($requete);
-
 
533
		$resultats = $this->executerRequete($requete);
-
 
534
		
-
 
535
		$observations = null;
-
 
536
		if ($resultats != false) {
-
 
537
			$observations = array();
-
 
538
			foreach ($resultats as $occurence) {
-
 
539
				$utilisateur = $occurence['utilisateur'];
-
 
540
				$ordre = $occurence['ordre'];
-
 
541
				if (!array_key_exists($utilisateur, $observations)) {
-
 
542
					$observations[$utilisateur] = array();
-
 
543
				}
-
 
544
				if (!array_key_exists($ordre, $observations[$utilisateur])) {
-
 
545
					$observations[$utilisateur][$ordre] = $ordre;
-
 
546
				}
-
 
547
			}
-
 
548
		}
-
 
549
		return $observations;
-
 
550
	}
-
 
551
	
-
 
552
	private function assemblerObsEnConditionSql($observations, $operateur = 'AND') {
-
 
553
		$sql = '';
-
 
554
		if ($observations != null) {
-
 
555
			// Pré-construction du where de la requête
-
 
556
			$tpl_where = "(identifiant = '%s' AND ordre IN (%s))";
-
 
557
			foreach ($observations as $utilisateur => $ordres) {
-
 
558
				$morceaux_requete[] = sprintf($tpl_where, $utilisateur, implode(',', $ordres));
-
 
559
			}
-
 
560
			if (count($morceaux_requete) > 0) {
-
 
561
				$sql = implode(" \nOR ", $morceaux_requete);
-
 
562
			}
-
 
563
		} else {
-
 
564
			// Nous voulons que la requête ne retourne rien
-
 
565
			$sql = "identifiant = '' AND ordre = ''";
-
 
566
		}
-
 
567
		$sql = " $operateur ($sql) ";
-
 
568
		return $sql;
-
 
569
	}
420
	
570
	
421
	private function construireWhereDept() {
571
	private function construireWhereDept() {
422
		$sql = '';
572
		$sql = '';
423
		// Récupération des coordonnées depuis l'id station
573
		// Récupération des coordonnées depuis l'id station
424
		extract($this->parametres);
574
		extract($this->parametres);
Line 579... Line 729...
579
	/**
729
	/**
580
	 * Traitement de $tag pour construction du filtre dans la requête
730
	 * Traitement de $tag pour construction du filtre dans la requête
581
	 */
731
	 */
582
	private function getSqlWhereMotsCles($tag) {
732
	private function getSqlWhereMotsCles($tag) {
583
		$sql = null;
733
		$sql = null;
584
		$mots_cles = $this->decomposerTag($tag);
734
		$mots_cles = $this->decomposerParametreTag($tag);
Line 585... Line 735...
585
		
735
		
586
		// Construction de la requête
736
		// Construction de la requête
587
		$requete = 	'SELECT cmc_id_proprietaire AS utilisateur, cmc_id_mot_cle_general AS mot_cle_general, '.
737
		$requete = 	'SELECT cmc_id_proprietaire AS utilisateur, cmc_id_mot_cle_general AS mot_cle_general, '.
588
					'	cmc_id_mot_cle_utilisateur AS mot_cle_utilisateur '.
738
					'	cmc_id_mot_cle_utilisateur AS mot_cle_utilisateur '.
Line 640... Line 790...
640
		}
790
		}
641
		$where_mots_cles_images = implode(' OR ', $where_mots_cles_images);
791
		$where_mots_cles_images = implode(' OR ', $where_mots_cles_images);
642
		return $where_mots_cles_images;
792
		return $where_mots_cles_images;
643
	}
793
	}
Line 644... Line 794...
644
	
794
	
645
	private function decomposerTag($tags) {
795
	private function decomposerParametreTag($tags) {
646
		$mots_cles = array('type' => null, 'motsCles' => null, 'motsClesEncodesProteges' => null);
796
		$mots_cles = array('type' => null, 'motsCles' => null, 'motsClesEncodesProteges' => null);
647
		if (preg_match('/.+OU.+/', $tags)) {
797
		if (preg_match('/.+OU.+/', $tags)) {
648
			$mots_cles['type'] = 'OR';
798
			$mots_cles['type'] = 'OR';
649
			$mots_cles['motsCles'] = explode('OU', $tags);
799
			$mots_cles['motsCles'] = explode('OU', $tags);
Line 659... Line 809...
659
		}
809
		}
660
		$this->debug[] = $mots_cles;
810
		$this->debug[] = $mots_cles;
661
		return $mots_cles;
811
		return $mots_cles;
662
	}
812
	}
Line 663... Line 813...
663
	
813
	
664
	private function decomposerStationId() {
814
	private function decomposerParametreStation() {
665
		$station_infos = array();
815
		$station_infos = array();
666
		if (isset($this->parametres['station'])) {
816
		if (isset($this->parametres['station'])) {
667
			$station = $this->parametres['station'];
817
			$station = $this->parametres['station'];
668
			$this->debug[] = $station;
818
			$this->debug[] = $station;
Line 677... Line 827...
677
			}
827
			}
678
			$station_infos['type'] = $type;
828
			$station_infos['type'] = $type;
679
		}
829
		}
680
		return $station_infos;
830
		return $station_infos;
681
	}
831
	}
-
 
832
	
-
 
833
	private function decomposerParametreDate() {
-
 
834
		$date_infos = array();
-
 
835
		if (isset($this->parametres['date'])) {
-
 
836
			$date = $this->parametres['date'];
-
 
837
			if (strpos($date, ':')) {
-
 
838
				list($type, $date) = explode(':', $date);
-
 
839
			} else {
-
 
840
				$type = 'observation';
-
 
841
			}
-
 
842
			
-
 
843
			$date = str_replace('/', '-', $date);
-
 
844
			if (preg_match('/(^[0-9]{2})-([0-9]{2})-([0-9]{4}$)/', $date, $matches)) {
-
 
845
				$date = $matches[3].'-'.$matches[2].'-'.$matches[1];
-
 
846
			}
-
 
847
			
-
 
848
			$date_infos = array($type, $date);
-
 
849
		}
-
 
850
		return $date_infos;
-
 
851
	}
-
 
852
	
-
 
853
	private function decomposerParametreTaxon() {
-
 
854
		$nom_infos = array();
-
 
855
		if (isset($this->parametres['taxon'])) {
-
 
856
			$taxon = $this->parametres['taxon'];
-
 
857
			if (strpos($taxon, ':')) {
-
 
858
				$nom_infos = explode(':', $taxon);
-
 
859
			} else {
-
 
860
				$nom_infos = array('retenu', $taxon);
-
 
861
			}
-
 
862
		}
-
 
863
		return $nom_infos;
-
 
864
	}
-
 
865
	
-
 
866
	private function decomposerParametreCommentaire() {
-
 
867
		$commentaire_infos = array();
-
 
868
		if (isset($this->parametres['commentaire'])) {
-
 
869
			$commentaire = $this->parametres['commentaire'];
-
 
870
			if (strpos($commentaire, ':')) {
-
 
871
				$commentaire_infos = explode(':', $commentaire);
-
 
872
			} else {
-
 
873
				$commentaire_infos = array('observation', $commentaire);
-
 
874
			}
-
 
875
		}
-
 
876
		return $commentaire_infos;
-
 
877
	}
682
}
878
}
683
879