31,24 → 31,19 |
* |
*/ |
|
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)); |
59,8 → 54,6 |
$this->taxon = $taxon; |
} |
|
|
|
public function renvoyerNomCompletReferentiel() { |
return $this->nomComplet; |
} |
69,15 → 62,16 |
return $this->taxon; |
} |
|
public function chargerTaxon($numTaxon) { |
public function chargerTaxon($typeNumero, $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) { |
$champWhere = $typeNumero == 'nt' ? $this->champs['nt']: 'num_nom'; |
$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']." ". |
$champWhere."={$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) { |
89,10 → 83,21 |
$this->taxon = $taxon; |
} |
|
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 recupererSousTaxons($listeNn = null) { |
public function recupererTaxonsSousEspeces($listeNn = null) { |
$sousTaxons = array(); |
if (!is_null($this->taxon) && $this->taxon['rang'] >= RANG_FAMILLE) { |
if (!is_null($this->taxon) && $this->taxon['rang'] == Config::get('rang.espece')) { |
if (is_null($listeNn)) { |
$listeNn = $this->taxon['nn']; |
} |
109,28 → 114,24 |
} |
// recherche de sous taxons au niveau inferieur (parcours recursif de la methode) |
if (count($resultats) > 0) { |
$sousTaxons = array_merge($sousTaxons, $this->recupererSousTaxons($nouvelleListeNn)); |
$sousTaxons = array_merge($sousTaxons, $this->recupererTaxonsSousEspeces($nouvelleListeNn)); |
} |
} |
|
return $sousTaxons; |
} |
|
|
private function getBdd() { |
if (is_null($this->bdd)) { |
$this->bdd = new Bdd(); |
public function recupererTaxonsFamilles() { |
$sousTaxons = array(); |
if (!is_null($this->taxon) && $this->taxon['rang'] == Config::get('rang.genre')) { |
$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=".$this->taxon['nn']." AND num_nom=".$this->champs['nn']; |
$sousTaxons = $this->getBdd()->recupererTous($requete); |
} |
$nomBdd = Config::get('bdd_eflore'); |
if (is_null($nomBdd)) { |
$nomBdd = Config::get('bdd_nom'); |
return $sousTaxons; |
} |
$this->bdd->requeter("USE ".$nomBdd); |
return $this->bdd; |
} |
|
|
|
public static function recupererListeReferentielsDisponibles() { |
$tableau = array(); |
$tableauPartiel = explode(',', Config::get('referentiels_dispo')); |