Subversion Repositories eFlore/Applications.moissonnage

Compare Revisions

Ignore whitespace Rev 33 → Rev 34

/trunk/services/modules/0.1/sources/Formateur.php
3,81 → 3,73
abstract class Formateur {
protected $criteresRecherche;
protected $bdd;
protected $bdd = null;
protected $nomSource = '';
public function __construct($criteresRecherche) {
public function __construct($criteresRecherche, $source) {
$this->criteresRecherche = $criteresRecherche;
$this->nomSource = Config::get('nom_source');
$this->nomSource = $source;
}
public function recupererStations() {
$stations = null;
if ($this->estTraitementRecuperationAutorise()) {
$stations = $this->traiterRecupererStations();
protected function getBdd() {
if (is_null($this->bdd)) {
$this->bdd = new Bdd();
$nomBdd = $this->nomSource == 'floradata' ? Config::get('bdd_nom_floradata') : Config::get('bdd_nom_eflore');
$this->bdd->requeter("USE {$nomBdd}");
}
return $stations;
return $this->bdd;
}
public function recupererObservations() {
$stations = null;
if ($this->estTraitementRecuperationAutorise()) {
$stations = $this->traiterRecupererObservations();
public function recupererStations() {
$stations = array();
if ($this->nomSource == 'floradata' || $this->calculerNombreCriteresNonSpatiaux() > 0) {
$requeteSql = $this->construireRequeteStations();
$stations = $this->getBdd()->recupererTous($requeteSql);
if ($this->determinerFormatRetour(count($stations)) == 'maille') {
$maillage = new Maillage($this->criteresRecherche->bbox,
$this->criteresRecherche->zoom, $this->nomSource);
$maillage->genererMaillesVides();
$maillage->ajouterStations($stations);
$stations = $maillage->formaterSortie();
}
} else {
$nombreStations = $this->obtenirNombreStationsDansBbox();
if ($this->determinerFormatRetour($nombreStations) == 'maille') {
$stations = $this->recupererMaillesDansBbox();
} else {
$requeteSql = $this->construireRequeteStations();
$stations = $this->getBdd()->recupererTous($requeteSql);
}
}
return $stations;
}
protected function estTraitementRecuperationAutorise() {
return (!(
isset($this->criteresRecherche->nbJours) ||
(isset($this->criteresRecherche->referentiel) &&
$this->criteresRecherche->referentiel != Config::get('referentiel_source'))
));
public function recupererWfs() {
$requeteSql = $this->construireRequeteWfs();
return $this->getBdd()->recupererTous($requeteSql);
}
protected function traiterRecupererStations() {
$stations = array();
$nombreStations = $this->obtenirNombreStationsDansBbox();
$seuilMaillage = Config::get('seuil_maillage');
$nombreParametresNonSpatiaux = $this->calculerNombreCriteresNonSpatiaux();
if ($nombreStations >= $seuilMaillage && $nombreParametresNonSpatiaux == 0) {
// pas besoin de rechercher les stations correspondant a ces criteres
// recuperer les mailles se trouvant dans l'espace de recherche demande
$stations = $this->recupererMaillesDansBbox();
protected function determinerFormatRetour($nombreStations) {
$formatRetour = 'point';
$zoomMaxMaillage = Config::get('zoom_maximal_maillage');
if (isset($this->criteresRecherche->format) && $this->criteresRecherche->format == 'maille'
&& $this->criteresRecherche->zoom <= $zoomMaxMaillage) {
$formatRetour = 'maille';
} else {
$requeteSql = $this->construireRequeteStations();
$stations = $this->getBdd()->recupererTous($requeteSql);
$zoom = $this->criteresRecherche->zoom;
$zoomMaxMaillage = Config::get('zoom_maximal_maillage');
if ($zoom <= $zoomMaxMaillage && count($stations) >= $seuilMaillage) {
$maillage = new Maillage($this->criteresRecherche->bbox, $zoom, $this->nomSource);
$maillage->genererMaillesVides();
$maillage->ajouterPoints($stations);
$stations = $maillage->formaterSortie();
$seuilMaillage = Config::get('seuil_maillage');
if ($this->criteresRecherche->zoom <= $zoomMaxMaillage && $nombreStations > $seuilMaillage) {
$formatRetour = 'maille';
}
}
$formateurJSON = new FormateurJson($this->nomSource);
$donneesFormatees = $formateurJSON->formaterStations($stations);
return $donneesFormatees;
return $formatRetour;
}
protected function traiterRecupererObservations() {
$requeteSql = $this->construireRequeteObservations();
$observations = $this->getBdd()->recupererTous($requeteSql);
$this->recupererNumeroNomenclaturauxTaxons($observations);
$nomStation = $this->obtenirNomsStationsSurPoint();
$formateurJSON = new FormateurJson($this->nomSource);
$donneesFormatees = $formateurJSON->formaterObservations($observations, $nomStation);
return $donneesFormatees;
}
protected function calculerNombreCriteresNonSpatiaux() {
$nombreParametresNonSpatiaux = 0;
$criteresAIgnorer = array('zoom', 'bbox', 'longitude', 'latitude', 'referentiel');
$criteresAIgnorer = array('zoom', 'bbox', 'stations', 'referentiel', 'format');
foreach ($this->criteresRecherche as $nomCritere => $valeur) {
if (!in_array($nomCritere, $criteresAIgnorer)) {
echo $nomCritere.chr(13);
$nombreParametresNonSpatiaux ++;
}
}
84,66 → 76,56
return $nombreParametresNonSpatiaux;
}
protected function getBdd() {
if (!isset($this->bdd)) {
$this->bdd = new Bdd();
abstract protected function construireRequeteStations();
protected function obtenirNombreStationsDansBbox() {}
protected function recupererMaillesDansBbox() {}
public function recupererObservations() {
$requeteSql = $this->construireRequeteObservations();
$observations = $this->getBdd()->recupererTous($requeteSql);
if ($this->nomSource != 'floradata') {
$this->recupererNumeroNomenclaturauxTaxons($observations);
}
$this->bdd->requeter("USE ".Config::get('bdd_nom'));
return $this->bdd;
}
protected function getNomRang($taxon) {
$nomsRangs = array('famille', 'genre', 'espece', 'sous_espece');
for ($index = 0; $index < count($nomsRangs)
&& Config::get("rang.".$nomsRangs[$index]) != $taxon['rang']; $index ++);
$position = $index == count($nomsRangs) ? count($nomsRangs)-1 : $index;
return $nomsRangs[$position];
}
 
protected function recupererNumeroNomenclaturauxTaxons(& $observations) {
$nomStation = $this->obtenirNomsStationsSurPoint();
if (strlen($nomStation) == 0) {
$nomStation = 'station sans nom';
}
for ($index = 0; $index < count($observations); $index ++) {
$taxons = isset($this->criteresRecherche->taxon) ? $this->criteresRecherche->taxon : null;
if (!is_null($taxons)) {
foreach ($taxons as $taxon) {
if ($observations[$index]['nomSci'] == 0) {
continue;
}
if (isset($this->criteresRecherche->taxon)) {
$taxon = $this->rechercherTaxonDansReferentiel($observations[$index]['nomSci'],
$this->criteresRecherche->referentiel);
} else {
$taxon = $this->obtenirNumeroTaxon($observations[$index]['nomSci']);
}
if (!is_null($taxon)) {
$observations[$index]['nn'] = $taxon['nn'];
$observations[$index]['num_referentiel'] = $taxon['referentiel'];
} else {
$observations[$index]['nn'] = '';
}
}
}
$observations[$index]['nom_station'] = $nomStation;
}
return $observations;
}
protected function rechercherTaxonDansReferentiel($nomScientifique, $nomReferentiel) {
$referentiel = new Referentiel($nomReferentiel);
$taxon = $referentiel->obtenirNumeroNomenclatural($nomScientifique);
return $taxon;
}
abstract protected function construireRequeteObservations();
protected function obtenirNumeroTaxon($nomScientifique) {
$taxonTrouve = null;
$listeReferentiels = Referentiel::recupererListeReferentielsDisponibles();
foreach ($listeReferentiels as $nomReferentiel) {
$taxon = $this->rechercherTaxonDansReferentiel($nomScientifique, $nomReferentiel);
protected function recupererNumeroNomenclaturauxTaxons(& $observations) {
for ($index = 0; $index < count($observations); $index ++) {
if (strlen (trim($observations[$index]['nomSci'])) == 0) {
continue;
}
$numeroNomenclatural = isset($observations[$index]['nn']) ? $observations[$index]['nn'] : null;
$referentiels = Referentiel::recupererListeReferentielsDisponibles();
$taxon = null;
$indexRef = 0;
while ($indexRef < count($referentiels) && is_null($taxon)) {
$referentiel = new Referentiel($referentiels[$indexRef]);
$taxon = $referentiel->obtenirNumeroNomenclatural($observations[$index]['nomSci'],
$numeroNomenclatural);
$indexRef ++;
}
if (!is_null($taxon)) {
$taxonTrouve = $taxon;
break;
$observations[$index]['nn'] = $taxon['nn'];
$observations[$index]['nom_referentiel'] = $taxon['referentiel'];
} else {
$observations[$index]['nn'] = '';
}
}
return $taxonTrouve;
}
abstract protected function obtenirNomsStationsSurPoint();
}
 
?>