Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2454 Rev 2455
Line 1... Line 1...
1
<?php
1
<?php
2
class CelRadiusPoints extends Cel {
2
class CelRadiusPoints extends Cel {
Line -... Line 3...
-
 
3
	
-
 
4
	private $champs = array("id_observation", "nom_sel", "latitude", "longitude", "COUNT(id_observation) as nb_obs");
-
 
5
	private $champs_min = array("latitude", "longitude");
-
 
6
	
-
 
7
	private $champs_mode = null;
3
	
8
	
4
	/**
9
	/**
5
	 * Méthode appelée avec une requête de type GET.
10
	 * Méthode appelée avec une requête de type GET.
6
	 */
11
	 */
-
 
12
	public function getRessource() {
7
	public function getRessource() {
13
		$this->champs_mode = $this->champs_min;
8
		return $this->getElement(array());
14
		return $this->getElement(array());
Line 9... Line 15...
9
	}
15
	}
10
	
16
	
Line 27... Line 33...
27
		$this->envoyerJson($retour);
33
		$this->envoyerJson($retour);
28
	}
34
	}
Line 29... Line 35...
29
 
35
 
30
	public function obtenirPointsPourCentreEtRadius($lat_centre, $lon_centre, $radius) {
36
	public function obtenirPointsPourCentreEtRadius($lat_centre, $lon_centre, $radius) {
31
		$requete = "SELECT ".
37
		$requete = "SELECT ".
32
			"id_observation, nom_sel, latitude, longitude, COUNT(id_observation) as nb_obs ".
38
			implode(", ", $this->champs_mode)." ".
33
			"FROM cel_obs ".
39
			"FROM cel_obs ".
34
			"WHERE latitude != 0 AND longitude != 0 ".
40
			"WHERE latitude != 0 AND longitude != 0 ".
35
			"AND ".$this->renvoyerDistanceSql($lat_centre, $lon_centre)." < ".$radius." ".
41
			"AND ".$this->renvoyerDistanceSql($lat_centre, $lon_centre)." < ".$radius." ".
Line 52... Line 58...
52
				") ";
58
				") ";
53
		return $sous_requete;
59
		return $sous_requete;
54
	}
60
	}
Line 55... Line 61...
55
	
61
	
-
 
62
	public function obtenirPointPlusProche($lat_centre, $lon_centre) {
56
	public function obtenirPointPlusProche($lat_centre, $lon_centre) {
63
		// TODO: faire moins moche et plus efficace
57
		$requete = "SELECT ".
64
		$requete = "SELECT ".
58
				"id_observation, nom_sel, ".$this->renvoyerDistanceSql($lat_centre, $lon_centre)." AS distance, ".
-
 
59
				"latitude, longitude, COUNT(id_observation) as nb_obs ".
65
				implode(", ", $this->champs_mode).", ".$this->renvoyerDistanceSql($lat_centre, $lon_centre)." AS distance ".
60
				"FROM cel_obs ".
66
				"FROM cel_obs ".
61
				"WHERE latitude != 0 AND longitude != 0 ".
67
				"WHERE latitude != 0 AND longitude != 0 ".
62
				"GROUP BY latitude, longitude ".
68
				"GROUP BY latitude, longitude ".
63
				"HAVING distance = MIN(distance) ".
69
				"ORDER BY distance ".
64
				"ORDER BY distance ";
70
				"LIMIT 1";
65
		
71
 
66
		$point = Cel::db()->requeterLigne($requete);
72
		$point = Cel::db()->requeterLigne($requete);
67
		return $point;
73
		return $point;