Blame | Last modification | View Log | RSS feed
<?php
define("RANG_FAMILLE", 180);
class Referentiel {
private $nomComplet;
private $nomCourt;
private $taxon = null;
private $bdd = null;
public function __construct($nomReferentiel) {
$this->nomComplet = $nomReferentiel;
$this->nomCourt = current(explode('_', $nomReferentiel));
}
public function getReferentiel() {
return $this->nomComplet;
}
public function getTaxon() {
return $this->taxon;
}
public function setTaxon($taxon) {
$this->taxon = $taxon;
}
public function recupererTaxon($numTaxon) {
if (is_null($numTaxon) || $numTaxon == 0) {
return null;
}
$methodeChamps = 'nomsChamps' . ucfirst($this->nomCourt);
extract($this->$methodeChamps());
// requete SQL a executer
$requete = "SELECT {$nn} AS nn, {$nt} AS nt, {$ns} AS nom, rang FROM {$this->nomComplet}"
. " WHERE {$nt}={$numTaxon} AND num_nom={$nn} ORDER BY rang, If(num_nom={$nn},0,1) LIMIT 0,1";
$taxon = $this->getBdd()->recuperer($requete);
return ($taxon == false ? null : $taxon);
}
public function recupererSousTaxons($listeNn = null) {
if ($this->taxon['rang'] < RANG_FAMILLE) {
// recherche de sous taxons seulement si le rang du taxon precedemment recupere
// est du niveau de la famille ou inferieur (genre, espece)
return array();
}
$methodeChamps = 'nomsChamps' . ucfirst($this->nomCourt);
extract($this->$methodeChamps());
if (is_null($listeNn)) {
$listeNn = $this->taxon['nn'];
}
$requete = "SELECT {$nn} AS nn, {$nt} As nt, {$ns} AS nom FROM {$this->nomComplet} WHERE"
. " num_tax_sup IN ({$listeNn}) AND num_nom={$nn}";
$sousTaxons = $this->getBdd()->recupererTous($requete);
$listeComplete = array();
$nouvelleListeNn = '';
foreach ($sousTaxons as $sousTaxon) {
$listeComplete[] = $sousTaxon;
$nouvelleListeNn .= (strlen($nouvelleListeNn) == 0 ? '' : ',') . $sousTaxon['nn'];
}
// recherche de sous taxons au niveau inferieur (parcours recursif de la methode)
if (count($listeComplete) > 0) {
$listeComplete = array_merge($listeComplete, $this->recupererSousTaxons($nouvelleListeNn));
}
return $listeComplete;
}
private function getBdd() {
if (is_null($this->bdd)) {
$this->bdd = new Bdd();
}
$this->bdd->requeter("USE tb_eflore");
return $this->bdd;
}
private function nomsChampsBdtfx() {
return array('nn' => 'num_nom_retenu', 'nt' => 'num_taxonomique', 'ns' => 'nom_sci');
}
private function nomsChampsBdtxa() {
return array('nn' => 'num_nom_retenu', 'nt' => 'num_tax', 'ns' => 'nom_sci');
}
public static function listeReferentielsDisponibles() {
$tableau = array();
$tableauPartiel = explode(',', Config::get('referentielsDispo'));
$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;
}
}
/*$nombreCriteres = 0;
foreach ($masques as $masque => $valeur) {
if ($masque == 'masque.nt') {
$requete .= ($nombreCriteres == 0 ? '' : " AND ") . "";
$nombreCriteres ++;
} elseif ($masque == 'masque.nn') {
$requete .= ($nombreCriteres == 0 ? '' : " AND ") . "num_nom = (SELECT num_nom_retenu"
. " FROM {$this->nomComplet} WHERE num_nom={$valeur})";
$nombreCriteres ++;
} elseif ($masque == 'masque.ns') {
$requete .= ($nombreCriteres == 0 ? '' : " AND ") . "({$ns} LIKE '{$valeur}%'"
. " OR num_nom=(SELECT {$nn} FROM {$this->nomComplet} WHERE {$ns} LIKE '{$valeur}%'"
. " ORDER BY rang LIMIT 0, 1))";
$nombreCriteres ++;
}
}
$requete .= " ";*/
?>