New file |
0,0 → 1,197 |
<?php |
class Dao extends Bdd { |
|
private $temps_derniere_requete = 0; |
|
public function rechercherCoordonnees($conditions = array()) { |
if(!empty($conditions)) { |
$where = 'WHERE '.implode(' AND ', $conditions); |
} |
|
$requete = "SELECT longitude, latitude ". |
"FROM cel_obs ". |
$where. |
"GROUP BY longitude , latitude "; |
|
$resultat = $this->recupererTous($requete); |
$this->reinitialiserTempsDerniereRequete(); |
return $resultat; |
} |
|
public function rechercherCoordonneesFrancaisesSansCorrespondances() { |
$conditions = array( |
$this->getConditionCoordonneesValides(), |
$this->getConditionInfosGeoIncompletes(), |
$this->getConditionlimiteeALaFrance(), |
$this->getConditionModifObsRecente() |
); |
|
return $this->rechercherCoordonnees($conditions); |
} |
|
public function rechercherCoordonneesFrancaisesSansCorrespondanceDepuisLeDebut() { |
$conditions = array( |
$this->getConditionCoordonneesValides(), |
$this->getConditionInfosGeoIncompletes(), |
$this->getConditionlimiteeALaFrance() |
); |
|
return $this->rechercherCoordonnees($conditions); |
} |
|
public function rechercherPaysSansCorrespondance() { |
$conditions = array( |
$this->getConditionCoordonneesValides(), |
$this->getConditionSansPays(), |
$this->getConditionModifObsRecente() |
); |
|
return $this->rechercherCoordonnees($conditions); |
} |
|
public function rechercherPaysSansCorrespondanceDepuisLeDebut() { |
$conditions = array( |
$this->getConditionCoordonneesValides(), |
$this->getConditionSansPays() |
); |
|
return $this->rechercherCoordonnees($conditions); |
} |
|
public function rechercherToutSansCorrespondance() { |
$conditions = array( |
$this->getConditionCoordonneesValides(), |
'('. |
$this->getConditionInfosGeoIncompletes().' OR '. |
$this->getConditionSansPays(). |
') ', |
$this->getConditionModifObsRecente() |
); |
|
return $this->rechercherCoordonnees($conditions); |
} |
|
public function rechercherSansCorrespondanceDepuisLeDebut() { |
$conditions = array( |
$this->getConditionCoordonneesValides(), |
'('. |
$this->getConditionInfosGeoIncompletes().' OR '. |
$this->getConditionSansPays(). |
') ' |
); |
return $this->rechercherCoordonnees($conditions); |
} |
|
|
private function getConditionModifObsRecente() { |
$condition = 'DATE_ADD(date_modification, INTERVAL 25 HOUR) >= CURDATE() '; |
return $condition; |
} |
|
private function getConditionInfosGeoIncompletes() { |
$condition = '('. |
'ce_zone_geo IS NULL OR ce_zone_geo = "" OR '. |
'zone_geo IS NULL OR zone_geo = "" '. |
') '; |
return $condition; |
} |
|
private function getConditionlimiteeALaFrance() { |
$condition = '('. |
'(latitude <= 51.071667 AND latitude >= 41.316667) AND '. |
'(longitude <= 9.513333 AND longitude >= -5.140278) '. |
') '; |
return $condition; |
} |
|
private function getConditionSansPays() { |
$condition = '(pays IS NULL OR pays = "XX" OR pays = "")'; |
return $condition; |
} |
|
private function getConditionCoordonneesValides() { |
$condition = '(latitude IS NOT NULL AND longitude IS NOT NULL '. |
' AND latitude != 0 AND latitude != "" '. |
' AND longitude != 0 AND longitude != "" '. |
' AND latitude >= -90 AND latitude <= 90 '. |
' AND longitude >= -180 AND longitude <= 180) '; |
return $condition; |
} |
|
public function creerColonneCodeInseeCalcule() { |
$create = 'ALTER TABLE cel_obs '. |
'ADD code_insee_calcule VARCHAR(5) NOT NULL '; |
$this->requeter($create); |
$this->reinitialiserTempsDerniereRequete(); |
} |
|
public function ajouterCodeInseeCalcule($latitude, $longitude, $code_insee) { |
$insert = 'UPDATE cel_obs '. |
"SET ". |
"code_insee_calcule = ".$this->proteger($code_insee)." ". |
"WHERE latitude = ".$this->proteger($latitude)." ". |
" AND longitude = ".$this->proteger($longitude)." "; |
$this->requeter($insert); |
$this->reinitialiserTempsDerniereRequete(); |
} |
|
public function affecterPaysFranceAuxCommunesRenseignees() { |
$update = "UPDATE cel_obs SET pays = 'FR' ". |
"WHERE ". |
"ce_zone_geo LIKE 'INSEE-C:_____' AND ". |
"zone_geo != '' AND ". |
"zone_geo IS NOT NULL AND ". |
"(pays IS NULL OR pays = '') "; |
return $this->executer($update); |
} |
|
public function modifierCodeInseeEtZoneGeo($coordonnees) { |
|
$codeP = $this->proteger($coordonnees['code_insee']); |
$codeInseeP = $this->proteger('INSEE-C:'.$coordonnees['code_insee']); |
$nomP = $this->proteger($coordonnees['nom']); |
|
$update = "UPDATE cel_obs ". |
"SET ". |
"pays = 'FR', ". |
"code_insee_calcule = ".$codeP.", ". |
"ce_zone_geo = ".$codeInseeP.", ". |
"zone_geo = IF(zone_geo = '' OR zone_geo = NULL, ".$nomP.", zone_geo) ". |
"WHERE ". |
" latitude = ".$this->proteger($coordonnees['latitude'])." ". |
" AND longitude = ".$this->proteger($coordonnees['longitude'])." "; |
$this->requeter($update); |
$this->reinitialiserTempsDerniereRequete(); |
} |
|
public function modifierPays($coordonnees) { |
$codePaysP = $this->proteger($coordonnees['code_pays']); |
$nomP = $this->proteger($coordonnees['nom']); |
|
$update = "UPDATE cel_obs ". |
"SET ". |
"pays = ".$codePaysP.", ". |
"zone_geo = IF(zone_geo = '' OR zone_geo = NULL, ".$nomP.", zone_geo) ". |
"WHERE ". |
" latitude = ".$this->proteger($coordonnees['latitude'])." ". |
" AND longitude = ".$this->proteger($coordonnees['longitude'])." "; |
$this->requeter($update); |
$this->reinitialiserTempsDerniereRequete(); |
} |
|
// Il peut se passer assez de temps sans qu'aucune requete ne soit effectuée |
// (cas d'un grand nombre d'enregistrements à la suite pour lesquels on ne trouve |
// aucun département). Pour éviter cela on teste régulièrement la connection |
public function testerActiviteConnection() { |
$temps_courant = microtime(true); |
$temps_depuis_derniere_requete = $temps_courant - $this->temps_derniere_requete; |
if($temps_depuis_derniere_requete >= 18) { |
$this->ping(); |
$this->reinitialiserTempsDerniereRequete(); |
} |
} |
|
private function reinitialiserTempsDerniereRequete() { |
$this->temps_derniere_requete = microtime(true); |
} |
} |