/trunk/services/bibliotheque/Maillage.php |
---|
New file |
0,0 → 1,229 |
<?php |
class Maillage { |
private $bbox; |
private $zoom; |
private $indexLongitude; |
private $indexLatitude; |
private $mailles; |
private $bdd = null; |
public function __construct($bbox, $zoom) { |
$this->bbox = $bbox; |
$this->zoom = $zoom; |
$this->indexLongitude = array(); |
$this->indexLatitude = array(); |
$this->mailles = array(); |
} |
public function __destruct() { |
while (count($this->indexLatitude) > 0) { |
array_pop($this->indexLatitude); |
} |
while (count($this->indexLongitude) > 0) { |
array_pop($this->indexLongitude); |
} |
while (count($this->mailles) > 0) { |
array_pop($this->mailles); |
} |
unset($this); |
} |
public function genererMaillesVides() { |
$this->recupererIndexMaillesDansBbox(); |
foreach ($this->indexLatitude as $indexLat => $intervalleLat) { |
$ligne = array(); |
foreach ($this->indexLongitude as $indexLng => $intervalleLng) { |
$ligne[] = new Maille($intervalleLat[0], $intervalleLng[0], $intervalleLat[1], |
$intervalleLng[1], $indexLat, $indexLng); |
} |
$this->mailles[] = $ligne; |
} |
} |
private function recupererIndexMaillesDansBbox() { |
// recuperer toutes les mailles qui couvrent l'espace a requeter |
$conditionsLongitude = ""; |
if ($this->bbox['ouest'] > $this->bbox['est']) { |
$conditionsLongitude = "NOT(debut>=".$this->bbox['ouest']." AND fin<=".$this->bbox['est'].")"; |
} else { |
$conditionsLongitude = "fin>=".$this->bbox['ouest']." AND debut <=".$this->bbox['est']; |
} |
$requete = |
"SELECT axe, position, debut, fin FROM mailles_index WHERE zoom=".$this->zoom." ". |
"AND (". |
"(axe='lat' AND fin>=".$this->bbox['sud']." AND debut<=".$this->bbox['nord'].") ". |
"OR (axe='lng' AND {$conditionsLongitude})". |
") ORDER BY axe, position"; |
$indexMailles = $this->getBdd()->recupererTous($requete); |
foreach ($indexMailles as $index) { |
if ($index['axe'] == 'lng') { |
$this->indexLongitude[$index['position']] = array($index['debut'], $index['fin']); |
} else { |
$this->indexLatitude[$index['position']] = array($index['debut'], $index['fin']); |
} |
} |
} |
private function getBdd() { |
if (is_null($this->bdd)) { |
$this->bdd = new Bdd(); |
} |
$nomBdd = Config::get('bdd_eflore'); |
if (is_null($nomBdd)) { |
$nomBdd = Config::get('bdd_nom'); |
} |
$this->bdd->requeter("USE ".$nomBdd); |
return $this->bdd; |
} |
public function ajouterPoints(& $points) { |
foreach ($points as $index => $point) { |
list($longitude, $latitude) = $this->obtenirCoordonneesPoint($point); |
list($indexLongitude, $indexLatitude) = $this->rechercherIndexMaille($longitude, $latitude); |
$this->mailles[$indexLatitude][$indexLongitude]->ajouterPoint($point); |
} |
} |
private function obtenirCoordonneesPoint($point) { |
$longitude = 0; |
$latitude = 0; |
if (!isset($point['type_site']) || $point['type_site'] == 'STATION') { |
$longitude = $point['longitude']; |
$latitude = $point['latitude']; |
} else { |
$longitude = $point['lng_commune']; |
$latitude = $point['lat_commune']; |
} |
return array($longitude, $latitude); |
} |
private function rechercherIndexMaille($longitude, $latitude) { |
$indexLatitude = 0; |
$indexLongitude = 0; |
while ($indexLatitude < count($this->indexLatitude) - 1 |
&& $this->mailles[$indexLatitude][0]->getLatitudeNord() < $latitude) { |
$indexLatitude ++; |
} |
while ($indexLongitude < count($this->indexLongitude) - 1 |
&& $this->mailles[$indexLatitude][$indexLongitude]->getLongitudeEst() < $longitude) { |
$indexLongitude ++; |
} |
return array($indexLongitude, $indexLatitude); |
} |
public function formaterSortie() { |
$mailles_resume = array(); |
foreach ($this->mailles as $ligne) { |
foreach ($ligne as $maille) { |
$nombrePoints = $maille->getNombrePoints(); |
if ($nombrePoints == 0) |
continue; |
$mailles_resume[] = array( |
'zoom' => $this->zoom, |
'sud' => $maille->getLatitudeSud(), |
'ouest' => $maille->getLongitudeOuest(), |
'nord' => $maille->getLatitudeNord(), |
'est' => $maille->getLongitudeEst(), |
'points' => $nombrePoints, |
'type_site' => 'MAILLE' |
); |
} |
} |
if (count($mailles_resume) == 0 || count($mailles_resume[0]) == 0) |
return array(); |
return $mailles_resume; |
} |
public function formaterPourInsertionBdd() { |
$mailles_resume = array(); |
foreach ($this->mailles as $ligne) { |
foreach ($ligne as $maille) { |
if ($maille->getNombrePoints() > 0) { |
$mailles_resume[] = array( |
'zoom' => $this->zoom, |
'sud' => $maille->getLatitudeSud(), |
'ouest' => $maille->getLongitudeOuest(), |
'nord' => $maille->getLatitudeNord(), |
'est' => $maille->getLongitudeEst(), |
'indexLat' => $maille->getIndexLatitude(), |
'indexLng' => $maille->getIndexLongitude(), |
'points' => $maille->getNombrePoints() |
); |
} |
} |
} |
if (count($mailles_resume[0]) == 0) |
return array(); |
return $mailles_resume; |
} |
public function zoomer() { |
$this->zoom += 1; |
} |
// redecoupage des mailles en 4 (fonction quadtree) |
// TODO : revoir le fonctionnement de cette methode (pour utilisation par les scripts uniquement) |
public function redecouperMailles() { |
$bdd = new Bdd(); |
while (count($this->indexLatitude) > 0) { |
array_pop($this->indexLatitude); |
} |
while (count($this->indexLongitude) > 0) { |
array_pop($this->indexLongitude); |
} |
$mailles = $this->resumePourInsertionBdd(); |
while (count($this->mailles) > 0) { |
array_pop($this->mailles); |
} |
foreach ($mailles as $maille) { |
$indexLat = 2 * $maille['indexLat']; |
$indexLng = 2 * $maille['indexLng']; |
// rechercher les nouvelles coordonnees des mailles au niveau de zoom inferieur |
$requete = "SELECT axe,position,debut,fin FROM mailles_index WHERE zoom=". $this->zoom ." AND ((axe='lat'" |
. " AND (position={$indexLat} OR position=" . ($indexLat+1) . ")) OR (axe='lng' AND" |
. " (position={$indexLng} OR position=" . ($indexLng+1) . "))) ORDER BY If(axe='lat',0,1)"; |
$resultats = $bdd->recupererTous($requete); |
$this->indexLatitude[$indexLat] = array($resultats[0]['debut'], $resultats[0]['fin']); |
$this->indexLatitude[$indexLat+1] = array($resultats[1]['debut'], $resultats[1]['fin']); |
$this->indexLongitude[$indexLng] = array($resultats[2]['debut'], $resultats[2]['fin']); |
$this->indexLongitude[$indexLng+1] = array($resultats[3]['debut'], $resultats[3]['fin']); |
} |
ksort($this->indexLatitude); |
ksort($this->indexLongitude); |
// creer et ajouter les nouvelles mailles a partir des nouveaux index |
foreach ($this->indexLatitude as $indexLat => $intervalleLat) { |
$ligne = array(); |
foreach ($this->indexLongitude as $indexLng => $intervalleLng) { |
$ligne[] = new Maille($intervalleLat[0], $intervalleLng[0], $intervalleLat[1], |
$intervalleLng[1], $indexLat, $indexLng); |
} |
$this->mailles[] = $ligne; |
} |
} |
public function getNombreMailles() { |
return count($this->mailles); |
} |
} |
?> |
/trunk/services/bibliotheque/VerificateurParametres.php |
---|
New file |
0,0 → 1,305 |
<?php |
/** |
* Classe commune a tous les services de ce projet qui va analyser et rechercher des erreurs |
* sur les valeurs passees en parametres lors d'un appel a ces web services. |
* |
* Les parametres suivants sont traites : |
* - zoom : le niveau de zoom sur la carte (API cartographique client) |
* On va verifier que c'est un nombre entier compris entre une valeur minimale et une valeur maximale |
* |
* - bbox : rectangle dont les bords delimitent en coordonnees l'espace de recherche de donnees spatiales |
* L'ordre des valeurs est le suivant : ouest, sud, est, nord |
* On va verifier que c'est une serie de quatre nombre decimaux delimites par des virgules |
* et compris dans l'espace representant le monde a partir du systeme de projection WGS84 (EPSG:4326) |
* |
* - longitude et latitude : representent les coordonnees d'un point dans l'espace |
* On va verifier que ces coordonnees soient valides dans le systeme de projection utilise |
* |
* - referentiel : referentiel taxonomique a utiliser. On peut passer aussi bien en parametres |
* son nom court que son nom complet (incluant le numero de version) |
* On va verifier la disponibilite du referentiel pour ce service |
* |
* - num_taxon : numero taxonomique d'une espece |
* On va rechercher sa presence dans les referentiels disponibles |
* (les informations principales sur ce taxon seront renvoyees) |
* |
* - dept : une liste de numeros de departements separees entre eux par des virgules |
* On va verifier que chaque numero est un nombre entier et represente un code de departement valide |
* |
* - auteur : l'auteur de l'observation |
* |
* La fonction principale de verification des parametres va parcourir tous les parametres, et verifier |
* pour chacun d'eux la validite de leurs valeurs. Dans le cas ou une valeur anormale est detectee |
* ou qu'elle se trouve en dehors de l'intervalle des resultats acceptes, une liste de messages d'erreur |
* sera generee et mise a jour. |
* |
* Le resultat final de la verfication peut entrainer deux cas d'utilisation possibles. Si des messages |
* d'erreurs ont ete generes durant la verification, ils sont regroupes en un seul message pour lever |
* une exception qui sera interpretee par la classe appelante. Dans le cas ou la verification n'a rien |
* rencontre d'anormal, une fonction renverra la liste des parametres valides utilisables |
* pour des recherches de donnees pour la suite du traitement pour le service. |
* |
* @package framework-0.3 |
* @author Alexandre GALIBERT <alexandre.galibert@tela-botanica.org> |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt> |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt> |
* @version $Id$ |
* @copyright 2013 Tela Botanica (accueil@tela-botanica.org) |
* |
*/ |
class VerificateurParametres { |
private $parametres = array(); |
private $validation = null; |
private $erreurs = array(); |
private $bboxMonde = null; |
public function __construct($parametres) { |
foreach ($parametres as $nomParametre => $valeur) { |
if ($nomParametre != 'source') { |
$this->parametres[$nomParametre] = $valeur; |
} |
} |
$this->bboxMonde = array( |
'ouest' => floatval(Config::get('carte.limite_ouest')), |
'est' => floatval(Config::get('carte.limite_est')), |
'sud' => floatval(Config::get('carte.limite_sud')), |
'nord' => floatval(Config::get('carte.limite_nord')) |
); |
$this->validation = new StdClass(); |
} |
public function verifierParametres() { |
foreach ($this->parametres as $nomParametre => $valeur) { |
switch ($nomParametre) { |
case 'zoom' : $this->traiterParametreZoom($valeur); |
break; |
case 'bbox' : $this->traiterParametreBbox($valeur); |
break; |
case 'longitude' : |
case 'latitude' : $this->traiterParametresCoordonnees($this->parametres['longitude'], |
$this->parametres['latitude']); |
break; |
case 'dept' : $this->traiterParametreDepartement($valeur); |
break; |
case 'auteur' : $this->traiterParametreAuteur($valeur); |
break; |
case 'referentiel' : $this->traiterParametreReferentiel($valeur); |
break; |
case 'num_taxon' : $this->traiterParametreTaxon($valeur); |
break; |
// autres parametres ==> les ignorer |
default : break; |
} |
} |
$this->verifierPresenceParametreSpatial(); |
} |
private function ajouterErreur($messageErreur) { |
$this->erreurs[] = $messageErreur; |
} |
public function renvoyerResultatVerification() { |
return $this->validation; |
} |
public function contienterreurs() { |
return count($this->erreurs); |
} |
public function leverException() { |
$messagesErreur = "Les erreurs suivantes ont été rencontrées : \n". |
implode("\n", $this->erreurs); |
throw new Exception($messagesErreur, RestServeur::HTTP_CODE_MAUVAISE_REQUETE); |
} |
// ------------------------------------------------------------------------- // |
// Fonctions de verification de parametres et detection de valeurs anormales // |
// ------------------------------------------------------------------------- // |
private function traiterParametreZoom($zoom) { |
$zoom = intval($zoom); |
$mondeZoom = array( |
'min' => intval(Config::get('carte.zoom_minimal')), |
'max' => intval(Config::get('carte.zoom_maximal')) |
); |
if ($zoom < $mondeZoom['min'] || $zoom > $mondeZoom['max']) { |
$message = 'Niveau de zoom non reconnu par le service. Il doit être compris entre '. |
$mondeZoom['min'].' et '.$mondeZoom['max']; |
$this->ajouterErreur($message); |
} else { |
$this->validation->zoom = $zoom; |
} |
} |
private function traiterParametreBbox($bbox) { |
// verifier que la chaine de caracteres $bbox est une serie de chaque nombre decimaux |
// separes entre eux par une virgule |
if (preg_match('/^(-?\d{1,3}(.\d+)?,){3}(-?\d{1,3}(.\d+)?)$/', $bbox) == 0) { |
$message = "Format de saisie des coordonnees de la bounding box non valide. Le service ". |
"n'accepte seulement qu'une serie de 4 nombre décimaux séparés par des virgules."; |
$this->ajouterErreur($message); |
} else { |
$coordonnees = explode(',', $bbox); |
// index du tableau des coordonnees : ouest/sud/est/nord |
$nomsIndexBbox = array("ouest", "sud", "est", "nord"); |
$bbox = array(); |
for ($i = 0; $i < count($coordonnees); $i ++) { |
$bbox[$nomsIndexBbox[$i]] = $coordonnees[$i]; |
} |
// verifier que les coordonnees de chaque bord de la bbox sont valides |
if ($this->estUneBboxValide($bbox)) { |
$this->validation->bbox = $bbox; |
} else { |
$message = "Certaines coordonnées de la bounding box sont situés en dehors des limites ". |
"de notre monde"; |
$this->ajouterErreur($message); |
} |
} |
} |
private function estUneBboxValide($bbox) { |
$monde = $this->bboxMonde; |
return (floatval($bbox['ouest']) >= $monde['ouest'] && floatval($bbox['ouest']) <= $monde['est'] |
&& floatval($bbox['est']) >= $monde['ouest'] && floatval($bbox['est']) <= $monde['est'] |
&& floatval($bbox['nord']) >= $monde['sud'] && floatval($bbox['nord']) <= $monde['nord'] |
&& floatval($bbox['sud']) >= $monde['sud'] && floatval($bbox['sud']) <= $monde['nord']); |
} |
private function traiterParametresCoordonnees($longitude, $latitude) { |
if ($this->sontDesCoordonneesValides($longitude, $latitude)) { |
$this->validation->latitude = $latitude; |
$this->validation->longitude = $longitude; |
} else { |
$message = "Les coordonnees du point passées en parametres sont en dehors des limites de ". |
"notre monde"; |
$this->ajouterErreur($message); |
} |
} |
private function sontDesCoordonneesValides($longitude, $latitude) { |
$monde = $this->bboxMonde; |
return (floatval($longitude) >= $monde['ouest'] && floatval($longitude) <= $monde['est'] |
&& floatval($latitude) >= $monde['sud'] && floatval($latitude) <= $monde['nord']); |
} |
private function traiterParametreDepartement($numeroDepartement) { |
if ($numeroDepartement != '*') { |
$departements = explode(',', trim($numeroDepartement)); |
foreach ($departements as $departement) { |
if($this->estUnCodeDepartementValide($departement)) { |
$this->validation->departement[] = $departement; |
} else { |
$message = "Code de département non valide"; |
$this->ajouterErreur($message); |
} |
} |
} |
} |
private function estUnCodeDepartementValide($departement) { |
// expression reguliere pour verifier que c'est un nombre entier a 2 ou 3 chiffres |
$estUnDepartementValide = true; |
if (preg_match('/^\d{2,3}$/', $departement) != 1) { |
$estUnDepartementValide = false; |
} else { |
if ((intval($departement) < 1 || intval($departement) > 95) |
&& (intval($departement) < 971 || intval($departement) > 978)) { |
$estUnDepartementValide = false; |
} |
} |
return $estUnDepartementValide; |
} |
private function traiterParametreAuteur($auteur) { |
if ($auteur != '*') { |
$this->validation->auteur = trim($auteur); |
} |
} |
private function traiterParametreReferentiel($referentiel) { |
if (!isset($this->validation->referentiel) && $referentiel != '*') { |
$referentielAUtiliser = $this->affecterNomCompletReferentiel($referentiel); |
if (is_null($referentielAUtiliser)) { |
$message = "Le référentiel demandé n'est pas reconnu par le service."; |
$this->ajouterErreur($message); |
} else { |
$this->validation->referentiel = $referentielAUtiliser; |
} |
} |
} |
private function affecterNomCompletReferentiel($referentiel) { |
$referentielAUtiliser = null; |
$listeReferentiels = Referentiel::recupererListeReferentielsDisponibles(); |
foreach ($listeReferentiels as $nomReferentiel) { |
$nomCourtReferentiel = current(explode('_', $nomReferentiel)); |
if ($referentiel == $nomCourtReferentiel || $referentiel == $nomReferentiel) { |
$referentielAUtiliser = $nomReferentiel; |
break; |
} |
} |
return $referentielAUtiliser; |
} |
private function traiterParametreTaxon($numeroTaxon) { |
if ($numeroTaxon != '*') { |
$taxon = null; |
if (isset($this->validation->referentiel)) { |
$taxon = $this->renvoyerTaxonDansReferentiel($numeroTaxon, $this->validation->referentiel); |
} else { |
// parcours de tous les referentiels jusqu'a retrouver le taxon dans sa liste |
$taxon = $this->rechercherTaxonDansReferentiels($numeroTaxon); |
} |
if (is_null($taxon)) { |
$message = "Le numéro de taxon n'a pas permis de retrouver le taxon associé."; |
$this->ajouterErreur($message); |
} else { |
$this->validation->taxon = $taxon; |
$this->validation->referentiel = $taxon['referentiel']; |
} |
} |
} |
private function rechercherTaxonDansReferentiels($numeroTaxon) { |
$taxon = null; |
$listeReferentiels = Referentiel::recupererListeReferentielsDisponibles(); |
foreach ($listeReferentiels as $nomReferentiel) { |
$taxon = $this->renvoyerTaxonDansReferentiel($numeroTaxon, $nomReferentiel); |
if (!is_null($taxon)) { |
break; |
} |
} |
return $taxon; |
} |
private function renvoyerTaxonDansReferentiel($numeroTaxon, $nomReferentiel) { |
$referentiel = new Referentiel($nomReferentiel); |
$referentiel->chargerTaxon($numeroTaxon); |
$taxon = $referentiel->renvoyerTaxon(); |
return $taxon; |
} |
private function verifierPresenceParametreSpatial() { |
$presenceParametreSpatial = false; |
if (isset($this->parametres['bbox']) |
|| (isset($this->parametres['longitude']) && isset($this->parametres['latitude']))) { |
$presenceParametreSpatial = true; |
} |
if ($presenceParametreSpatial == false) { |
$message = "Aucune coordonnée n'a été saisie"; |
$this->ajouterErreur($message); |
} |
} |
} |
?> |
/trunk/services/bibliotheque/FormateurJson.php |
---|
New file |
0,0 → 1,141 |
<?php |
class FormateurJson { |
private $sourceDonnees; |
public function __construct($source) { |
$this->sourceDonnees = $source; |
} |
public function formaterStations($stations) { |
$objetJSON = new StdClass(); |
$objetJSON->type = "FeatureCollection"; |
$objetJSON->stats = new StdClass(); |
$objetJSON->stats->communes = 0; |
$objetJSON->stats->stations = 0; |
$objetJSON->features = array(); |
foreach ($stations as $station) { |
$stationJSON = NULL; |
// construction d'un objet feature adapte a la structure des donnees spatiales |
if ($station['type_site'] == 'MAILLE') { |
$stationJSON = $this->formaterMaille($station); |
} else { |
if ($station['type_site'] == 'STATION') { |
$objetJSON->stats->communes ++; |
} else { |
$objetJSON->stats->stations ++; |
} |
$stationJSON = $this->formaterPoint($station); |
} |
if (!is_null($stationJSON)) { |
$objetJSON->features[] = $stationJSON; |
} |
} |
return $objetJSON; |
} |
private function formaterPoint($station) { |
$json = new StdClass(); |
$json->type = "Feature"; |
$json->geometry = new StdClass(); |
$json->properties = new StdClass(); |
$json->geometry->type = "Point"; |
$json->properties->typeSite = $station['type_site']; |
if ($this->sourceDonnees == 'floradata' && $station['type_site'] == 'COMMUNE') { |
$json->geometry->coordinates = array($station['lat_commune'], $station['lng_commune']); |
} else { |
$json->geometry->coordinates = array($station['latitude'], $station['longitude']); |
} |
if ($this->sourceDonnees == 'floradata') { |
$json->properties->nom = $this->construireNomStationFloradata($station); |
} else { |
$station['code_insee'] = ''; |
$codeDepartement = $this->extraireCodeDepartement($station['code_insee']); |
$json->properties->nom = trim($station['nom'])." ({$codeDepartement})"; |
} |
return $json; |
} |
private function construireNomStationFloradata($station) { |
$nom = ($station['type_site'] == 'COMMUNE') ? trim($station['nom_commune']) : trim($station['station']); |
$codeDepartement = $this->extraireCodeDepartement($station['ce_zone_geo']); |
if ($station['type_site'] == 'COMMUNE') { |
$nom = $station['zone_geo'] . " ({$codeDepartement})"; |
} else { |
if (strlen($nom) == 0) { |
$nom = 'station sans nom, '.trim($station['zone_geo']); |
} |
$nom .= " ({$codeDepartement})";; |
} |
return $nom; |
} |
private function extraireCodeDepartement($codeInsee) { |
$codeInsee = substr($codeInsee,-5); |
$codeDepartement = substr($codeInsee, 0 ,2); |
if (intval($codeDepartement) > 95) { |
substr($codeInsee, 0 ,3); |
} |
return $codeDepartement; |
} |
private function formaterMaille($maille) { |
if ($maille['points'] == 0) { |
return null; |
} |
$json = new StdClass(); |
$json->type = "Feature"; |
$json->geometry = new StdClass(); |
$json->geometry->type = "Polygon"; |
$json->geometry->coordinates = array( |
array(floatval($maille['sud']), floatval($maille['ouest'])), |
array(floatval($maille['sud']), floatval($maille['est'])), |
array(floatval($maille['nord']), floatval($maille['est'])), |
array(floatval($maille['nord']), floatval($maille['ouest'])), |
array(floatval($maille['sud']), floatval($maille['ouest'])) |
); |
$json->properties = new StdClass(); |
$json->properties->typeSite = $maille['type_site']; |
$json->properties->nombrePoints = $maille['points']; |
return $json; |
} |
public function formaterObservations($observations, $nomSite) { |
$objetJSON = new StdClass(); |
$objetJSON->site = trim($nomSite); |
$objetJSON->total = count($observations); |
$objetJSON->observations = array(); |
foreach ($observations as $observation) { |
$observationJson = new stdClass(); |
foreach ($observation as $colonne => $valeur) { |
if ($colonne == 'nom_referentiel') { |
$observationJson->urlEflore = $this->genererUrlFicheEflore($observation); |
} else { |
$observationJson->$colonne = is_string($valeur) ? trim($valeur) : $valeur; |
} |
} |
$objetJSON->observations[] = $observationJson; |
} |
return $objetJSON; |
} |
private function genererUrlFicheEflore($observation) { |
$url = null; |
if (strstr('bdtfx', $observation['nom_referentiel']) !== false) { |
$url = 'http://www.tela-botanica.org/bdtfx-nn-'.$observation['nn']; |
} |
return $url; |
} |
} |
?> |
/trunk/services/bibliotheque/Maille.php |
---|
New file |
0,0 → 1,68 |
<?php |
class Maille { |
private $latitudeSud; |
private $longitudeOuest; |
private $latitudeNord; |
private $longitudeEst; |
private $indexLatitude; |
private $indexLongitude; |
private $points = array(); |
private $nombrePoints = 0; |
public function __construct($sud, $ouest, $nord, $est, $indexLat, $indexLng) { |
$this->latitudeSud = $sud; |
$this->longitudeOuest = $ouest; |
$this->latitudeNord = $nord; |
$this->longitudeEst = $est; |
$this->indexLatitude = $indexLat; |
$this->indexLongitude = $indexLng; |
} |
public function ajouterPoint(& $point) { |
$this->points[] = $point; |
$this->nombrePoints ++; |
} |
public function getLatitudeNord() { |
return $this->latitudeNord; |
} |
public function getLongitudeOuest() { |
return $this->longitudeOuest; |
} |
public function getLatitudeSud() { |
return $this->latitudeSud; |
} |
public function getLongitudeEst() { |
return $this->longitudeEst; |
} |
public function getIndexLatitude() { |
return $this->indexLatitude; |
} |
public function getIndexLongitude() { |
return $this->indexLongitude; |
} |
public function getNombrePoints() { |
return $this->nombrePoints; |
} |
public function getPoint($index = 0) { |
return (!isset($this->points[$index])) ? NULL : $this->points[$index]; |
} |
public function totalNonNul() { |
return !is_null($this->nombrePoints); |
} |
} |
?> |
/trunk/services/bibliotheque/Referentiel.php |
---|
New file |
0,0 → 1,165 |
<?php |
/** |
* Classe qui va effectuer toutes les operations liees aux referentiels ou rechercher |
* des informations sur les taxons dans les tables des referentiels dans la base de donnees |
* |
* Operations a utiliser : |
* - recupererListeReferentielsDisponibles (statique) : recherche dans les fichiers de configuration |
* la liste des referentiels disponibles et les renvoie dans un tableau |
* |
* - chargerTaxon : recherche dans la table possedant le meme nom que le nom du referentiel en attribut |
* les informations generales sur un taxon (numero nomenclatural retenu, numero taxonomique, |
* nom scientifique, rang) a partir de son numero taxonomique |
* On stockera dans un attribut un tableau associatif contenant ces informations + le nom du referentiel, |
* ou la valeur nulle si aucun taxon n'a ete trouve |
* |
* - recupererSousTaxons : a partir du numero nomenclatural d'un taxon, la fonction va recuperer |
* tous les taxons de rang inferieur de maniere recursive jusqu'en ne plus en trouver de nouveaux |
* la recherche s'effectuera seulement au niveau des rangs famille, genre, espece et sous-espece |
* pour limiter le nombre d'informations qui sera a la fin renvoye |
* |
* - obtenirNumeroNomenclatural : recherche le numero nomenclatural d'un taxon a partir de son nom scientifique |
* |
* @package framework-0.3 |
* @author Alexandre GALIBERT <alexandre.galibert@tela-botanica.org> |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt> |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt> |
* @version $Id$ |
* @copyright 2013 Tela Botanica (accueil@tela-botanica.org) |
* |
*/ |
define("RANG_FAMILLE", 180); |
class Referentiel { |
private $nomComplet; |
private $nomCourt; |
private $taxon; |
private $bdd = null; |
private $nomsChampsBdtfx = array('nn' => 'num_nom_retenu', 'nt' => 'num_taxonomique', 'ns' => 'nom_sci'); |
private $nomsChampsBdtxa = array('nn' => 'num_nom_retenu', 'nt' => 'num_tax', 'ns' => 'nom_sci'); |
private $champs; |
public function __construct($nomReferentiel, $taxon = null) { |
$this->nomComplet = $nomReferentiel; |
$this->nomCourt = current(explode('_', $nomReferentiel)); |
$proprieteChamps = 'nomsChamps' . ucfirst($this->nomCourt); |
foreach ($this->$proprieteChamps as $nomCourt => $nomChamp) { |
$this->champs[$nomCourt] = $nomChamp; |
} |
$this->taxon = $taxon; |
} |
public function renvoyerNomCompletReferentiel() { |
return $this->nomComplet; |
} |
public function renvoyerTaxon() { |
return $this->taxon; |
} |
public function chargerTaxon($numTaxon) { |
$taxon = null; |
// verifier que le numero de taxon soit bien une chaine de caracteres composee uniquement |
// que de nombres entiers avant de construire la requete SQL a executer |
if (preg_match('/^\d+$/', $numTaxon) == 1) { |
$requete = |
"SELECT ".$this->champs['nn']." AS nn, ".$this->champs['nt']." AS nt, ". |
$this->champs['ns']." AS nom, rang FROM ".$this->nomComplet." WHERE ". |
$this->champs['nt']."={$numTaxon} AND num_nom=".$this->champs['nn']." ". |
"ORDER BY rang, If(num_nom=".$this->champs['nn'].", 0, 1) LIMIT 0, 1"; |
$taxon = $this->getBdd()->recuperer($requete); |
if ($taxon == false) { |
$taxon = null; |
} else { |
$taxon['referentiel'] = $this->nomComplet; |
} |
} |
$this->taxon = $taxon; |
} |
public function recupererSousTaxons($listeNn = null) { |
$sousTaxons = array(); |
if (!is_null($this->taxon) && $this->taxon['rang'] >= RANG_FAMILLE) { |
if (is_null($listeNn)) { |
$listeNn = $this->taxon['nn']; |
} |
$requete = |
"SELECT ".$this->champs['nn']." AS nn, ".$this->champs['nt']." AS nt, ". |
$this->champs['ns']." AS nom, rang FROM ".$this->nomComplet." WHERE ". |
"num_tax_sup IN ({$listeNn}) AND num_nom=".$this->champs['nn']; |
$resultats = $this->getBdd()->recupererTous($requete); |
$nouvelleListeNn = ''; |
foreach ($resultats as $sousTaxon) { |
$sousTaxons[] = $sousTaxon; |
$nouvelleListeNn .= (strlen($nouvelleListeNn) == 0 ? '' : ',') . $sousTaxon['nn']; |
} |
// recherche de sous taxons au niveau inferieur (parcours recursif de la methode) |
if (count($resultats) > 0) { |
$sousTaxons = array_merge($sousTaxons, $this->recupererSousTaxons($nouvelleListeNn)); |
} |
} |
return $sousTaxons; |
} |
private function getBdd() { |
if (is_null($this->bdd)) { |
$this->bdd = new Bdd(); |
} |
$nomBdd = Config::get('bdd_eflore'); |
if (is_null($nomBdd)) { |
$nomBdd = Config::get('bdd_nom'); |
} |
$this->bdd->requeter("USE ".$nomBdd); |
return $this->bdd; |
} |
public static function recupererListeReferentielsDisponibles() { |
$tableau = array(); |
$tableauPartiel = explode(',', Config::get('referentiels_dispo')); |
$tableauPartiel = array_map('trim', $tableauPartiel); |
foreach ($tableauPartiel as $champ) { |
if (strpos($champ, '=') === false) { |
$tableau[] = $champ; |
} else { |
list($cle, $val) = explode('=', $champ); |
$clePropre = trim($cle); |
$valeurPropre = trim($val); |
$tableau[$clePropre] = $valeurPropre; |
} |
} |
return $tableau; |
} |
public function obtenirNumeroNomenclatural($nomScientifique) { |
$aProteger = $this->getBdd()->proteger(trim($nomScientifique) . '%'); |
$requete = "SELECT ".$this->champs['nn']." AS nn FROM ".$this->nomComplet." ". |
"WHERE ".$this->champs['ns']." LIKE ".$aProteger; |
$taxon = $this->getBdd()->recuperer($requete); |
if ($taxon == false) { |
$taxon = null; |
} else { |
$taxon['referentiel'] = $this->nomComplet; |
} |
return $taxon; |
} |
} |
?> |
/trunk/services/bibliotheque/CacheMoissonnage.php |
---|
4,18 → 4,20 |
private $service; |
private $config; |
private $dureecache = 0; |
private $projetNom; |
private $serviceNom; |
private $cache; |
private $cacheActif; |
public function __construct($service, $projetNom, $serviceNom, $cacheActif) { |
public function __construct($service, $serviceNom, $cacheActif) { |
$this->cacheActif = $cacheActif; |
$this->service = $service; |
$this->chargerDureeCache(); |
$this->projetNom = $projetNom; |
$this->serviceNom = $serviceNom; |
$this->cache = new CacheSimple(array("mise_en_cache" => true, "stockage_chemin" => Config::get("chemincache"), "duree_de_vie" => $this->dureecache)); |
$this->cache = new CacheSimple(array( |
"mise_en_cache" => true, |
"stockage_chemin" => Config::get("chemincache"), |
"duree_de_vie" => $this->dureecache |
)); |
} |
public function chargerDureeCache() { |
59,7 → 61,7 |
} |
} |
$chaineMD5 = $this->projetNom.'/'.$this->serviceNom.'/'.md5($chaineRessources.$chaineParametres); |
$chaineMD5 = $this->serviceNom.'/'.md5($chaineRessources.$chaineParametres); |
return $chaineMD5; |
} |
} |