Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1568 Rev 1585
Line 88... Line 88...
88
 
88
 
89
		return array('type' => 'png', 'img' => $img);
89
		return array('type' => 'png', 'img' => $img);
Line 90... Line 90...
90
	}
90
	}
91
 
-
 
92
	public function getTout($params) {
91
 
93
 
92
	public function getTout($params) {
94
		$emplacements = null;		
93
		$emplacements = null;
95
		$concatenation_id = "CONCAT(IFNULL(latitude,''),IFNULL(longitude,''), IFNULL(wgs84_latitude,''),IFNULL(wgs84_longitude,'')) ";
94
		$concatenation_id = "CONCAT(IFNULL(latitude,''),IFNULL(longitude,''), IFNULL(wgs84_latitude,''),IFNULL(wgs84_longitude,'')) ";
96
		
-
 
97
		$requete =  'SELECT ce_zone_geo, zone_geo, station, '.
-
 
98
								"mots_cles_texte, ".
-
 
99
								"latitude, ".
-
 
100
								"wgs84_latitude, ".
95
 
101
								"longitude, ".
96
		$requete = 'SELECT ce_zone_geo, zone_geo, station, '.
102
								"wgs84_longitude, ".
97
			'	mots_cles_texte, latitude, wgs84_latitude, longitude, wgs84_longitude, '.
103
								$concatenation_id." as id_coord ".
98
			"	$concatenation_id AS id_coord ".
104
					'FROM cel_obs AS co '.
99
			'FROM cel_obs AS co '.
105
                    '   LEFT JOIN cel_zones_geo AS l '.
100
			'	LEFT JOIN cel_zones_geo AS l '.
106
                    '       ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
101
			'		ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
107
                    "WHERE transmission = '1' ".
102
			"WHERE transmission = '1' ".
108
					" AND (".
103
			" AND (".
109
					$this->construireWhereRectangleStationOR()." OR ".
104
			$this->construireWhereRectangleStationOR()." OR ".
110
					$this->construireWhereRectangleCommuneOR().") ".
105
			$this->construireWhereRectangleCommuneOR().") ".
111
					$this->construireWhereDept().
106
			$this->construireWhereDept().
112
                    $this->construireWhereCommune().
107
			$this->construireWhereCommune().
113
                    $this->construireWhereUtilisateur().
108
			$this->construireWhereUtilisateur().
114
					$this->construireWhereNumTaxonAvecSousTaxons().
109
			$this->construireWhereNumTaxonAvecSousTaxons().
115
					$this->construireWhereNomTaxon().
110
			$this->construireWhereNomTaxon().
116
					$this->construireWhereReferentiel().
111
			$this->construireWhereReferentiel().
117
					$this->construireWhereDate().
112
			$this->construireWhereDate().
118
					$this->construireWhereCommentaire().
113
			$this->construireWhereCommentaire().
119
					$this->construireWherePhotosSeulement().
114
			$this->construireWherePhotosSeulement().
120
					$this->construireWhereProjet().
115
			$this->construireWhereProjet().
121
					$this->construireWhereTag().
116
			$this->construireWhereTag().
122
					$this->construireWhereNombreDeJours().
117
			$this->construireWhereNombreDeJours().
123
					' GROUP BY id_coord';
118
			' GROUP BY id_coord';
124
		
119
 
125
		$resultats_emplacements = $this->executerRequete($requete);
120
		$resultats_emplacements = $this->executerRequete($requete);
126
		$emplacements = $this->traiterEmplacements($resultats_emplacements, $this->compterObservations($params));
121
		$emplacements = $this->traiterEmplacements($resultats_emplacements, $this->compterObservations($params));
127
		return $emplacements;
122
		return $emplacements;
128
	}
123
	}
129
	
124
 
130
	private function afficherRequeteFormatee($requete) {
125
	private function afficherRequeteFormatee($requete) {
131
		$requete = str_replace(')',')<br />',$requete);
126
		$requete = str_replace(')',')<br />',$requete);
132
		$requete = str_replace('(','	<br />	(',$requete);
127
		$requete = str_replace('(','	<br />	(',$requete);
Line 136... Line 131...
136
 
131
 
Line 137... Line 132...
137
	private $nb_obs = 0;
132
	private $nb_obs = 0;
138
 
133
 
139
	private function compterObservations($params) {
134
	private function compterObservations($params) {
140
		$requete =  'SELECT COUNT(*) as nb '.
135
		$requete =  'SELECT COUNT(*) as nb '.
141
					'FROM cel_obs AS co '.
136
			'FROM cel_obs AS co '.
142
                    '   LEFT JOIN cel_zones_geo AS l '.
137
			'	LEFT JOIN cel_zones_geo AS l '.
143
                    '       ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
138
			'		ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
144
                    "WHERE transmission = '1' ".
139
			"WHERE transmission = '1' ".
145
					" AND (".
140
			" AND (".
146
					$this->construireWhereRectangleStationOR()." OR ".
141
			$this->construireWhereRectangleStationOR()." OR ".
147
					$this->construireWhereRectangleCommuneOR().") ".
142
			$this->construireWhereRectangleCommuneOR().") ".
148
					$this->construireWhereDept().
143
			$this->construireWhereDept().
149
                    $this->construireWhereCommune().
144
			$this->construireWhereCommune().
150
                    $this->construireWhereUtilisateur().
145
			$this->construireWhereUtilisateur().
151
					$this->construireWhereNumTaxonAvecSousTaxons().
146
			$this->construireWhereNumTaxonAvecSousTaxons().
152
					$this->construireWhereNomTaxon().
147
			$this->construireWhereNomTaxon().
153
					$this->construireWhereReferentiel().
148
			$this->construireWhereReferentiel().
154
					$this->construireWhereDate().
149
			$this->construireWhereDate().
155
					$this->construireWhereCommentaire().
150
			$this->construireWhereCommentaire().
156
					$this->construireWherePhotosSeulement().
151
			$this->construireWherePhotosSeulement().
157
					$this->construireWhereProjet().
152
			$this->construireWhereProjet().
Line 158... Line 153...
158
					$this->construireWhereTag().
153
			$this->construireWhereTag().
159
					$this->construireWhereNombreDeJours();
154
			$this->construireWhereNombreDeJours();
160
 
155
 
Line 247... Line 242...
247
		}
242
		}
Line 248... Line 243...
248
 
243
 
249
		if (isset($this->parametres['ne']) && $this->parametres['sw'] && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
244
		if (isset($this->parametres['ne']) && $this->parametres['sw'] && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
250
			$ne = $this->decomposerLatLng($this->parametres['ne']);
245
			$ne = $this->decomposerLatLng($this->parametres['ne']);
251
			$sw = $this->decomposerLatLng($this->parametres['sw']);
246
			$sw = $this->decomposerLatLng($this->parametres['sw']);
252
			$marqueurs['points'] = CartoGroupage::creerGroupesQuadtree(&$points, $ne['lat'], $ne['lng'], $sw['lat'], $sw['lng'], $zoom);
247
			$marqueurs['points'] = CartoGroupage::creerGroupesQuadtree($points, $ne['lat'], $ne['lng'], $sw['lat'], $sw['lng'], $zoom);
253
		} else {
248
		} else {
254
			$marqueurs['points'] = $points;
249
			$marqueurs['points'] = $points;
255
		}
250
		}
256
		//$marqueurs['stats']['latDiff'] = abs($marqueurs['stats']['latMin'] - $marqueurs['stats']['latMax']);
251
		//$marqueurs['stats']['latDiff'] = abs($marqueurs['stats']['latMin'] - $marqueurs['stats']['latMax']);
Line 302... Line 297...
302
		if (stristr($tags, 'sensible') === FALSE) {
297
		if (stristr($tags, 'sensible') === FALSE) {
303
			$sensible = false;
298
			$sensible = false;
304
		}
299
		}
305
		return $sensible;
300
		return $sensible;
306
	}
301
	}
307
	
302
 
308
	private function communeEstDemandee() {
303
	private function communeEstDemandee() {
309
	    $station_infos = $this->decomposerParametreStation();
304
		$station_infos = $this->decomposerParametreStation();
310
	    $commune_demandee = true;
305
		$commune_demandee = true;
311
	    if($station_infos['type'] == self::MARQUEUR_STATION) {
306
		if ($station_infos['type'] == self::MARQUEUR_STATION) {
312
			$commune_demandee = false;
307
			$commune_demandee = false;
313
	    }
308
		}
314
	    return $commune_demandee;
309
		return $commune_demandee;
315
	}
310
	}
Line 316... Line 311...
316
 
311
 
317
	/**
312
	/**
318
	 * Données pour l'affichage des obs d'une station
313
	 * Données pour l'affichage des obs d'une station
319
	 */
314
	 */
320
	public function getObservations($params) {
315
	public function getObservations($params) {
321
		$resultats = array();
316
		$resultats = array();
322
		$total = 0;
317
		$total = 0;
323
		if (isset($this->parametres['station']) && !$this->etreNull($this->parametres['station'])) {
318
		if (isset($this->parametres['station']) && !$this->etreNull($this->parametres['station'])) {
324
			$requete = 	'SELECT SQL_CALC_FOUND_ROWS id_observation, ce_utilisateur, courriel_utilisateur, nom_utilisateur, prenom_utilisateur, '.
319
			$requete = 	'SELECT SQL_CALC_FOUND_ROWS id_observation, ce_utilisateur, courriel_utilisateur, nom_utilisateur, prenom_utilisateur, '.
325
						'	nom_sel, nom_ret, nom_sel_nn, nom_ret_nn, nt, famille, '.
320
				'	nom_sel, nom_ret, nom_sel_nn, nom_ret_nn, nt, famille, '.
326
						'	lieudit, zone_geo, date_observation, milieu, commentaire, '.
321
				'	lieudit, zone_geo, date_observation, milieu, commentaire, '.
327
						'	utm_secteur, utm_x, utm_y, code, date_transmission '.
322
				'	utm_secteur, utm_x, utm_y, code, date_transmission '.
328
						'FROM cel_obs AS co '.
323
				'FROM cel_obs AS co '.
329
						'	LEFT JOIN cel_zones_geo AS l '.
324
				'	LEFT JOIN cel_zones_geo AS l '.
330
						"		ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) ".
325
				"		ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) ".
331
						"WHERE transmission = '1' ".
326
				"WHERE transmission = '1' ".
332
						(($this->communeEstDemandee()) ? $this->construireWhereCommuneSansCoordonneesAvecSensibles() : $this->construireWhereCoordonneesSansSensibles()).
327
				(($this->communeEstDemandee()) ? $this->construireWhereCommuneSansCoordonneesAvecSensibles() : $this->construireWhereCoordonneesSansSensibles()).
333
						$this->construireWhereDept().
328
				$this->construireWhereDept().
334
						$this->construireWhereUtilisateur().
329
				$this->construireWhereUtilisateur().
335
						$this->construireWhereNumTaxonAvecSousTaxons().
330
				$this->construireWhereNumTaxonAvecSousTaxons().
336
						$this->construireWhereNomTaxon().
331
				$this->construireWhereNomTaxon().
337
						$this->construireWhereReferentiel().
332
				$this->construireWhereReferentiel().
338
						$this->construireWhereDate().
333
				$this->construireWhereDate().
339
						$this->construireWhereCommentaire().
334
				$this->construireWhereCommentaire().
340
						$this->construireWherePhotosSeulement().
335
				$this->construireWherePhotosSeulement().
341
						$this->construireWhereProjet().
336
				$this->construireWhereProjet().
342
						$this->construireWhereTag().
337
				$this->construireWhereTag().
343
						$this->construireWhereNombreDeJours().
338
				$this->construireWhereNombreDeJours().
344
	                    'ORDER BY nom_sel ASC '.
339
				'ORDER BY nom_sel ASC '.
345
	                    "LIMIT {$this->start},{$this->limit} ";
340
				"LIMIT {$this->start},{$this->limit} ";
346
			//echo $requete;exit;
341
			//echo $requete;exit;
347
			$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
342
			$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
348
			$requete = 'SELECT FOUND_ROWS()';
343
			$requete = 'SELECT FOUND_ROWS()';
349
			$total = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
344
			$total = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
Line 444... Line 439...
444
				$observations['observations'][$id] = $infos;
439
				$observations['observations'][$id] = $infos;
445
			}
440
			}
446
		}
441
		}
447
		return $observations;
442
		return $observations;
448
	}
443
	}
449
	
444
 
450
	private function ajouterAuteursAuxObs($observations) {
445
	private function ajouterAuteursAuxObs($observations) {
451
		$observateurs = $this->recupererUtilisateursIdentite(array_keys($observations['observateurs']));
446
		$observateurs = $this->recupererUtilisateursIdentite(array_keys($observations['observateurs']));
452
		unset($observations['observateurs']);
447
		unset($observations['observateurs']);
453
		foreach ($observations['observations'] as $id => $infos) {
448
		foreach ($observations['observations'] as $id => $infos) {
454
			$courriel = strtolower($infos['observateur']);
449
			$courriel = strtolower($infos['observateur']);
Line 476... Line 471...
476
	 */
471
	 */
477
	public function getTaxons($params) {
472
	public function getTaxons($params) {
478
		$json = null;
473
		$json = null;
Line 479... Line 474...
479
 
474
 
480
		$requete = 	'SELECT SQL_CALC_FOUND_ROWS DISTINCT nom_ret, nom_ret_nn, nt, famille '.
475
		$requete = 	'SELECT SQL_CALC_FOUND_ROWS DISTINCT nom_ret, nom_ret_nn, nt, famille '.
481
					'FROM cel_obs AS co '.
476
			'FROM cel_obs AS co '.
482
					'	LEFT JOIN cel_zones_geo AS l '.
477
			'	LEFT JOIN cel_zones_geo AS l '.
483
					'		ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
478
			'		ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
484
					"WHERE transmission = '1' ".
479
			"WHERE transmission = '1' ".
485
					"	AND nom_ret != '' ".
480
			"	AND nom_ret != '' ".
486
					$this->construireWhereDept().
481
			$this->construireWhereDept().
487
                    $this->construireWhereCommune().
482
			$this->construireWhereCommune().
488
                    $this->construireWhereUtilisateur().
483
			$this->construireWhereUtilisateur().
489
					$this->construireWhereNumTaxon().
484
			$this->construireWhereNumTaxon().
490
					$this->construireWhereNomTaxon().
485
			$this->construireWhereNomTaxon().
491
					$this->construireWhereReferentiel().
486
			$this->construireWhereReferentiel().
492
					$this->construireWhereDate().
487
			$this->construireWhereDate().
493
					$this->construireWhereCommentaire().
488
			$this->construireWhereCommentaire().
494
					$this->construireWherePhotosSeulement().
489
			$this->construireWherePhotosSeulement().
495
					$this->construireWhereProjet().
490
			$this->construireWhereProjet().
496
					$this->construireWhereTag().
491
			$this->construireWhereTag().
497
					$this->construireWhereNombreDeJours().
492
			$this->construireWhereNombreDeJours().
498
					'ORDER BY nom_ret ASC '.
493
			'ORDER BY nom_ret ASC '.
499
                    "LIMIT {$this->start},{$this->limit} ";
494
			"LIMIT {$this->start},{$this->limit} ";
500
		//$this->debug[] = $requete;
495
		//$this->debug[] = $requete;
501
		$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
496
		$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
502
		//echo $requete;exit;
497
		//echo $requete;exit;
503
		$requete = 'SELECT FOUND_ROWS()';
498
		$requete = 'SELECT FOUND_ROWS()';
Line 542... Line 537...
542
				$sql = " AND (latitude LIKE $lat AND longitude LIKE $lng) ";
537
				$sql = " AND (latitude LIKE $lat AND longitude LIKE $lng) ";
543
			}
538
			}
544
		}
539
		}
545
		return $sql;
540
		return $sql;
546
	}
541
	}
547
	
542
 
548
	private function construireWhereCoordonneesSansSensibles() {
543
	private function construireWhereCoordonneesSansSensibles() {
549
		$sql = '(';
544
		$sql = '(';
550
		// Récupération des coordonnées depuis l'id station
545
		// Récupération des coordonnées depuis l'id station
551
		extract($this->decomposerParametreStation());
546
		extract($this->decomposerParametreStation());
552
		if (isset($type)) {
547
		if (isset($type)) {
Line 616... Line 611...
616
					$sql = " AND nom_ret LIKE $nom ";
611
					$sql = " AND nom_ret LIKE $nom ";
617
			}
612
			}
618
		}
613
		}
619
		return $sql;
614
		return $sql;
620
	}
615
	}
621
	
616
 
622
	private function construireWhereReferentiel() {
617
	private function construireWhereReferentiel() {
623
		$sql = '';
618
		$sql = '';
624
		extract($this->parametres);
619
		extract($this->parametres);
625
		if (isset($referentiel) && !$this->etreNull($referentiel)) {
620
		if (isset($referentiel) && !$this->etreNull($referentiel)) {
626
			$referentiel = $this->proteger($referentiel.'%');
621
			$referentiel = $this->proteger($referentiel.'%');
Line 835... Line 830...
835
			$lngMax = $ne['lng'];
830
			$lngMax = $ne['lng'];
Line 836... Line 831...
836
 
831
 
837
			$sql = "( (latitude != 0 AND longitude != 0) ".
832
			$sql = "( (latitude != 0 AND longitude != 0) ".
838
				" AND latitude BETWEEN $latMin AND $latMax ".
833
				" AND latitude BETWEEN $latMin AND $latMax ".
839
				" AND longitude BETWEEN $lngMin AND $lngMax )";
834
				" AND longitude BETWEEN $lngMin AND $lngMax )";
840
			
835
 
841
			/*$sql = " MBRWithin(mon_point, GeomFromText('POLYGON((".$latMin.' '.$lngMin.','.
836
			/*$sql = " MBRWithin(mon_point, GeomFromText('POLYGON((".$latMin.' '.$lngMin.','.
842
			$latMax.' '.$lngMin.','.
837
			$latMax.' '.$lngMin.','.
843
			$latMax.' '.$lngMax.','.
838
			$latMax.' '.$lngMax.','.
844
			$latMax.' '.$lngMin.','.
839
			$latMax.' '.$lngMin.','.
845
			$latMin.' '.$lngMin."))')) ";		*/	
840
			$latMin.' '.$lngMin."))')) ";		*/
846
		}
841
		}
847
		return $sql;
842
		return $sql;
Line 848... Line 843...
848
	}
843
	}
Line 879... Line 874...
879
			$lngMax = $ne['lng'];
874
			$lngMax = $ne['lng'];
Line 880... Line 875...
880
 
875
 
881
			$sql = "( wgs84_longitude != 0 AND wgs84_latitude != 0 ".
876
			$sql = "( wgs84_longitude != 0 AND wgs84_latitude != 0 ".
882
				" AND wgs84_latitude BETWEEN $latMin AND $latMax ".
877
				" AND wgs84_latitude BETWEEN $latMin AND $latMax ".
883
				" AND wgs84_longitude BETWEEN $lngMin AND $lngMax )";
878
				" AND wgs84_longitude BETWEEN $lngMin AND $lngMax )";
884
			
879
 
885
			/*$sql = " MBRWithin(point_commune, GeomFromText('POLYGON((".$latMin.' '.$lngMin.','.
880
			/*$sql = " MBRWithin(point_commune, GeomFromText('POLYGON((".$latMin.' '.$lngMin.','.
886
			$latMax.' '.$lngMin.','.
881
			$latMax.' '.$lngMin.','.
887
			$latMax.' '.$lngMax.','.
882
			$latMax.' '.$lngMax.','.
888
			$latMax.' '.$lngMin.','.
883
			$latMax.' '.$lngMin.','.
Line 929... Line 924...
929
			           			(latitude = '000null' OR latitude = '' OR latitude = 0 OR latitude IS NULL) ".
924
			           			(latitude = '000null' OR latitude = '' OR latitude = 0 OR latitude IS NULL) ".
930
								" AND (longitude = '000null' OR longitude = '' OR longitude = 0 OR longitude IS NULL)".
925
								" AND (longitude = '000null' OR longitude = '' OR longitude = 0 OR longitude IS NULL)".
931
							')'.
926
							')'.
932
							' OR mots_cles_texte LIKE "%sensible%"'.
927
							' OR mots_cles_texte LIKE "%sensible%"'.
933
						') ';
928
						') ';
934
			
929
 
935
		}
930
		}
936
		return $sql;
931
		return $sql;
937
	}
932
	}
938
	
933
 
939
	
934
 
940
	private function construireWherePhotosSeulement() {
935
	private function construireWherePhotosSeulement() {
941
		$sql = '';
936
		$sql = '';
942
		if (isset($this->parametres['photos']) && $this->parametres['photos'] == 1) {
937
		if (isset($this->parametres['photos']) && $this->parametres['photos'] == 1) {
943
			$sql = 'AND co.id_observation IN (SELECT DISTINCT id_observation FROM cel_obs_images) ';
938
			$sql = 'AND co.id_observation IN (SELECT DISTINCT id_observation FROM cel_obs_images) ';
944
		}
939
		}
Line 954... Line 949...
954
			$utilisateur = $this->proteger($utilisateur);
949
			$utilisateur = $this->proteger($utilisateur);
955
			$sql = " AND co.courriel_utilisateur = $utilisateur ";
950
			$sql = " AND co.courriel_utilisateur = $utilisateur ";
956
		}
951
		}
957
		return $sql;
952
		return $sql;
958
	}
953
	}
959
	
954
 
960
	
955
 
961
	private function construireWhereNumTaxon() {
956
	private function construireWhereNumTaxon() {
962
		$sql = '';
957
		$sql = '';
963
		// Récupération des coordonnées depuis l'id station
958
		// Récupération des coordonnées depuis l'id station
964
		extract($this->parametres);
959
		extract($this->parametres);
965
		if (isset($this->parametres['num_taxon']) && !$this->etreNull($num_taxon)) {
960
		if (isset($this->parametres['num_taxon']) && !$this->etreNull($num_taxon)) {
966
		$num_taxon = $this->proteger($num_taxon);
961
		$num_taxon = $this->proteger($num_taxon);
967
		$sql = " AND nt = $num_taxon ";
962
		$sql = " AND nt = $num_taxon ";
968
		}
963
		}
969
		return $sql;
964
		return $sql;
970
	}
965
	}
971
	
966
 
972
	private function construireWhereNumTaxonAvecSousTaxons() {
967
	private function construireWhereNumTaxonAvecSousTaxons() {
973
		$sql = '';
968
		$sql = '';
974
		// Récupération des coordonnées depuis l'id station
969
		// Récupération des coordonnées depuis l'id station
975
		extract($this->parametres);
970
		extract($this->parametres);
976
		if (isset($this->parametres['num_taxon']) && !$this->etreNull($num_taxon)) {
971
		if (isset($this->parametres['num_taxon']) && !$this->etreNull($num_taxon)) {
Line 987... Line 982...
987
				$sql = " AND nt = $num_taxon ";
982
				$sql = " AND nt = $num_taxon ";
988
			}
983
			}
989
		}
984
		}
990
		return $sql;
985
		return $sql;
991
	}
986
	}
992
	
987
 
993
	private function obtenirSousTaxons($nt) {
988
	private function obtenirSousTaxons($nt) {
994
		$referentiel = 'bdtfx';
989
		$referentiel = 'bdtfx';
995
		if($this->parametres['referentiel'] && $this->parametres['referentiel'] != "" && $this->parametres['referentiel'] != '*') {
990
		if($this->parametres['referentiel'] && $this->parametres['referentiel'] != "" && $this->parametres['referentiel'] != '*') {
996
			$referentiel = $this->parametres['referentiel'];
991
			$referentiel = $this->parametres['referentiel'];
997
		}
992
		}
Line 1011... Line 1006...
1011
		if (!$this->etreNull($projet_sql)) {
1006
		if (!$this->etreNull($projet_sql)) {
1012
			$sql = " AND ($projet_sql) ";
1007
			$sql = " AND ($projet_sql) ";
1013
		}
1008
		}
1014
		return $sql;
1009
		return $sql;
1015
	}
1010
	}
1016
	
1011
 
1017
	/**
1012
	/**
1018
	 * Traitement de $projet pour construction du filtre dans la requête
1013
	 * Traitement de $projet pour construction du filtre dans la requête
1019
	 */
1014
	 */
1020
	private function getSqlWhereProjet($projet) {
1015
	private function getSqlWhereProjet($projet) {
1021
		$sql = null;
1016
		$sql = null;
1022
		if (isset($projet) && !$this->etreNull($projet)) {
1017
		if (isset($projet) && !$this->etreNull($projet)) {
1023
			$sql = 'co.mots_cles_texte LIKE '.$this->proteger('%'.$projet.'%');
1018
			$sql = 'co.mots_cles_texte LIKE '.$this->proteger('%'.$projet.'%');
1024
		}
1019
		}
1025
		return $sql;
1020
		return $sql;
1026
	}
1021
	}
1027
	
1022
 
1028
	private function construireWhereTag() {
1023
	private function construireWhereTag() {
1029
		$sql = '';
1024
		$sql = '';
1030
		extract($this->parametres);
1025
		extract($this->parametres);
1031
		$tag_sql = isset($tag) ? $this->getSqlWhereObsAvecImagesTaguees($tag) : null;
1026
		$tag_sql = isset($tag) ? $this->getSqlWhereObsAvecImagesTaguees($tag) : null;
1032
		if (!$this->etreNull($tag_sql)) {
1027
		if (!$this->etreNull($tag_sql)) {
1033
			$sql = " AND ($tag_sql) ";
1028
			$sql = " AND ($tag_sql) ";
1034
		}
1029
		}
1035
		return $sql;
1030
		return $sql;
1036
	}
1031
	}
1037
	
1032
 
1038
	private function construireWhereNombreDeJours() {
1033
	private function construireWhereNombreDeJours() {
1039
		$sql = null;
1034
		$sql = null;
1040
		extract($this->parametres);
1035
		extract($this->parametres);
1041
		if (isset($nbjours) && !$this->etreNull($nbjours)) {
1036
		if (isset($nbjours) && !$this->etreNull($nbjours)) {
1042
			$sql = ' AND DATEDIFF(CURDATE(),co.date_creation) <= '.$this->proteger($nbjours).' ';
1037
			$sql = ' AND DATEDIFF(CURDATE(),co.date_creation) <= '.$this->proteger($nbjours).' ';
1043
		}
1038
		}
1044
		return $sql;
1039
		return $sql;
1045
	}
1040
	}
1046
	
1041
 
1047
	/**
1042
	/**
1048
	 * Traitement de $tag pour construction du filtre dans la requête
1043
	 * Traitement de $tag pour construction du filtre dans la requête
1049
	 */
1044
	 */
1050
	private function getSqlWhereObsAvecImagesTaguees($tag) {
1045
	private function getSqlWhereObsAvecImagesTaguees($tag) {
1051
		$sql = null;
1046
		$sql = null;
Line 1070... Line 1065...
1070
						(!$this->etreNull($tag_sql) ? "AND ($tag_sql) " : '').
1065
						(!$this->etreNull($tag_sql) ? "AND ($tag_sql) " : '').
1071
						'ORDER BY utilisateur ASC, ci.ordre ASC';
1066
						'ORDER BY utilisateur ASC, ci.ordre ASC';
1072
			//$this->debug[] = $requete;
1067
			//$this->debug[] = $requete;
1073
			//die($requete);
1068
			//die($requete);
1074
			$elements_tag = $this->executerRequete($requete);
1069
			$elements_tag = $this->executerRequete($requete);
1075
			
1070
 
1076
			$requete_tag = array();
1071
			$requete_tag = array();
1077
			if ($elements_tag != false && count($elements_tag) > 0) {
1072
			if ($elements_tag != false && count($elements_tag) > 0) {
1078
				
1073
 
1079
				$filtres = array();
1074
				$filtres = array();
1080
				foreach ($elements_tag as $occurence) {
1075
				foreach ($elements_tag as $occurence) {
1081
					$utilisateur = $occurence['utilisateur'];
1076
					$utilisateur = $occurence['utilisateur'];
1082
					$id_obs = $occurence['id_obs'];
1077
					$id_obs = $occurence['id_obs'];
1083
					if (!array_key_exists($utilisateur, $filtres)) {
1078
					if (!array_key_exists($utilisateur, $filtres)) {
Line 1085... Line 1080...
1085
					}
1080
					}
1086
					if (!array_key_exists($id_obs, $filtres[$utilisateur])) {
1081
					if (!array_key_exists($id_obs, $filtres[$utilisateur])) {
1087
						$filtres[$utilisateur][$id_obs] = $id_obs;
1082
						$filtres[$utilisateur][$id_obs] = $id_obs;
1088
					}
1083
					}
1089
				}
1084
				}
1090
				
1085
 
1091
				// Pré-construction du where de la requête
1086
				// Pré-construction du where de la requête
1092
				$tpl_where = "(id_observation IN (%s))";
1087
				$tpl_where = "(id_observation IN (%s))";
1093
				foreach ($filtres as $utilisateur => $id_obs) {
1088
				foreach ($filtres as $utilisateur => $id_obs) {
1094
					$requete_tag[] = sprintf($tpl_where, implode(',', $id_obs));
1089
					$requete_tag[] = sprintf($tpl_where, implode(',', $id_obs));
1095
				}
1090
				}
1096
				
1091
 
1097
			} else {
1092
			} else {
1098
				$this->messages[] = "Aucune observation ne possède d'images avec ce mot-clé.";
1093
				$this->messages[] = "Aucune observation ne possède d'images avec ce mot-clé.";
1099
			}
1094
			}
1100
			if (count($requete_tag) > 0) {
1095
			if (count($requete_tag) > 0) {
1101
				$sql = implode(" \nOR ", $requete_tag);
1096
				$sql = implode(" \nOR ", $requete_tag);
1102
			}
1097
			}
1103
		}
1098
		}
1104
		return $sql;
1099
		return $sql;
1105
	}
1100
	}
1106
	
1101
 
1107
	/**
1102
	/**
1108
	 * Traitement de $tag pour construction du filtre dans la requête
1103
	 * Traitement de $tag pour construction du filtre dans la requête
1109
	 */
1104
	 */
1110
	private function getSqlWhereMotsCles($tag) {
1105
	private function getSqlWhereMotsCles($tag) {
1111
		$sql = null;
1106
		$sql = null;
Line 1113... Line 1108...
1113
		$requete_projet = $this->getSqlWhereMotsClesImages($mots_cles);
1108
		$requete_projet = $this->getSqlWhereMotsClesImages($mots_cles);
1114
		$sql = $requete_projet;
1109
		$sql = $requete_projet;
1115
		//$this->debug[] = $sql;
1110
		//$this->debug[] = $sql;
1116
		return $sql;
1111
		return $sql;
1117
	}
1112
	}
1118
	
1113
 
1119
	/**
1114
	/**
1120
	 * Traitement de $tag pour construction du filtre dans la requête
1115
	 * Traitement de $tag pour construction du filtre dans la requête
1121
	 */
1116
	 */
1122
	private function getSqlWhereMotsClesImages($mots_cles_encodes) {
1117
	private function getSqlWhereMotsClesImages($mots_cles_encodes) {
1123
		$where_mots_cles_images = array();
1118
		$where_mots_cles_images = array();
Line 1125... Line 1120...
1125
			$where_mots_cles_images[] = "ci.mots_cles_texte LIKE $mot_cle_encode";
1120
			$where_mots_cles_images[] = "ci.mots_cles_texte LIKE $mot_cle_encode";
1126
		}
1121
		}
1127
		$where_mots_cles_images = implode(' '.$mots_cles_encodes['type'].' ', $where_mots_cles_images);
1122
		$where_mots_cles_images = implode(' '.$mots_cles_encodes['type'].' ', $where_mots_cles_images);
1128
		return $where_mots_cles_images;
1123
		return $where_mots_cles_images;
1129
	}
1124
	}
1130
	
1125
 
1131
	private function decomposerParametreTag($tags) {
1126
	private function decomposerParametreTag($tags) {
1132
		
1127
 
1133
		$mots_cles = array('type' => null, 'motsCles' => null, 'motsClesEncodesProteges' => null);
1128
		$mots_cles = array('type' => null, 'motsCles' => null, 'motsClesEncodesProteges' => null);
1134
		if (preg_match('/.+OU.+/', $tags)) {
1129
		if (preg_match('/.+OU.+/', $tags)) {
1135
			$mots_cles['type'] = 'OR';
1130
			$mots_cles['type'] = 'OR';
1136
			$mots_cles['motsCles'] = explode('OU', $tags);
1131
			$mots_cles['motsCles'] = explode('OU', $tags);
1137
		} else if (preg_match('/.+ET.+/', $tags)) {
1132
		} else if (preg_match('/.+ET.+/', $tags)) {
1138
			$mots_cles['type'] = 'AND';
1133
			$mots_cles['type'] = 'AND';
1139
			$mots_cles['motsCles'] = explode('ET', $tags);
1134
			$mots_cles['motsCles'] = explode('ET', $tags);
1140
		} else {
1135
		} else {
1141
			$mots_cles['motsCles'][] = $tags;
1136
			$mots_cles['motsCles'][] = $tags;
1142
		}
1137
		}
1143
		
1138
 
1144
		foreach ($mots_cles['motsCles'] as $mot) {
1139
		foreach ($mots_cles['motsCles'] as $mot) {
1145
			$mots_cles['motsClesEncodesProteges'][] = $this->bdd->quote('%'.$mot.'%');
1140
			$mots_cles['motsClesEncodesProteges'][] = $this->bdd->quote('%'.$mot.'%');
1146
		}
1141
		}
1147
		$this->debug[] = $mots_cles;
1142
		$this->debug[] = $mots_cles;
1148
		return $mots_cles;
1143
		return $mots_cles;