17,11 → 17,17 |
|
protected $parametres = array(); |
protected $ressources = array(); |
|
private $bdd; |
private $retour_format = 'complet'; |
private $retours_formats_autorises = array('complet','zone_geo'); |
protected $table_version = null; |
|
|
public function __construct($config = null) { |
$this->config = $config; |
$this->bdd = $this->getBdd(); |
$this->table_version = Config::get('table_version'); |
} |
|
public function consulter($ressources, $parametres) { |
29,6 → 35,7 |
$this->parametres = $parametres; |
$this->ressources = $ressources; |
|
$this->affecterParametresParDefaut(); |
$this->verifierParametres(); |
|
$resultat = new ResultatService(); |
38,6 → 45,10 |
} |
//+---------------------------FONCTION D'ANALYSE DES PARAMETRES---------------------------------------------------------+ |
|
private function affecterParametresParDefaut() { |
$this->retour_format = isset($this->parametres['retour.format']) ? $this->parametres['retour.format'] : $this->retour_format; |
} |
|
private function verifierParametres() { |
$erreurs = array(); |
|
49,6 → 60,10 |
$erreurs[] = 'la valeur pour masque.nn doit ĂȘtre un entier'; |
} |
|
if(!in_array($this->retour_format, $this->retours_formats_autorises)) { |
$erreurs[] = 'la valeur '.$this->retour_format.' est inconnue'; |
} |
|
if (count($erreurs) > 0) { |
$message = implode('<br />', $erreurs); |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE; |
60,22 → 75,60 |
|
private function obtenirLois(Array $id_lois) { |
$id_lois = array_map(array($this->bdd, 'proteger'), $id_lois); |
$requete = "SELECT * FROM sptb_lois_v2012 ". |
$requete = "SELECT * FROM sptb_lois_v".$this->table_version.' '. |
"WHERE id IN (".implode(',',$id_lois).") "; |
return $this->bdd->recupererTous($requete); |
} |
|
private function obtenirLoisZoneGeo(Array $id_lois) { |
$id_lois = array_map(array($this->bdd, 'proteger'), $id_lois); |
$requete = "SELECT DISTINCT zone_application, code_zone_application FROM sptb_lois_v".$this->table_version.' '. |
"WHERE id IN (".implode(',',$id_lois).") "; |
return $this->bdd->recupererTous($requete); |
} |
|
private function obtenirStatuts() { |
$requete = "SELECT * FROM sptb_especes_v2012 ". |
$requete = "SELECT * FROM sptb_especes_v".$this->table_version.' '. |
"WHERE ". |
"num_nom = ".$this->bdd->proteger($this->parametres['masque.nn']).""; |
|
$statuts = $this->bdd->recuperer($requete); |
$statuts = $this->formaterStatutsTaxon($statuts); |
$statuts = $this->formaterRetour($statuts); |
return $statuts; |
} |
|
//+---------------------------FONCTIONS DE FORMATAGE---------------------------------------------------------+ |
|
private function formaterRetour($statuts_taxon) { |
switch($this->retour_format) { |
case 'zone_geo': |
$retour = $this->formaterStatutsTaxonZoneGeo($statuts_taxon); |
break; |
|
case 'complet': |
$retour = $this->formaterStatutsTaxon($statuts_taxon); |
break; |
|
default: |
$retour = $this->formaterStatutsTaxon(); |
break; |
} |
return $retour; |
} |
|
private function formaterStatutsTaxonZoneGeo($statuts_taxon) { |
$lois_statuts = array(); |
foreach ($statuts_taxon as $champ => $statut) { |
if($statut == "1") { |
$lois_statuts[] = $champ; |
} |
} |
|
$zones_geo_lois = (!empty($lois_statuts)) ? $this->obtenirLoisZoneGeo($lois_statuts) : array(); |
|
return $zones_geo_lois; |
} |
|
private function formaterStatutsTaxon($statuts_taxon) { |
$statuts_formates = array(); |
unset($statuts_taxon['num_nom']); |
84,11 → 137,11 |
foreach ($statuts_taxon as $champ => $statut) { |
if($statut == "1") { |
$lois_statuts[] = $champ; |
} |
} |
} |
|
|
$statuts_formates = (!empty($lois_statuts)) ? $this->obtenirLois($lois_statuts) : array(); |
|
|
return $statuts_formates; |
} |
} |