* @author Delphine CAUQUIL * @copyright 2011 Tela-Botanica * @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3 * @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2 * @version $Id$ */ class Liste extends aControleur { private $alphabet = null; protected $rang = null; protected $lettre = null; private $rangsCorrespondance = array('F' => 'Famille', 'G' => 'Genre'); public function initialiser() { $this->capturerParametres(); } public function executerActionParDefaut() { $this->executerListe(); } public function executerListe() { $this->initialiserAlphabet(); $this->initialiserLettre(); $couleurs = $this->creerColoration($this->alphabet); $taxons = $this->getListeTaxons(); $donnees = array(); $donnees['i18n'] = I18n::get('Liste'); $donnees['lettre'] = $this->lettre; $donnees['rang'] = $this->rang; $donnees['rangCodes'] = array_keys($this->rangsCorrespondance); $donnees['initiales'] = $this->alphabet; $donnees['lettreCorrespondance'] = $this->chargerCorrespondanceSpeciale(); $donnees['couleurs'] = $couleurs; $donnees['taxons'] = $taxons; $donnees['nbreTaxons'] = $this->getEfloreTaxons()->getEnteteTotal(); $donnees['urlFiltre'] = $this->obtenirUrlBase(); $donnees['referentiel'] = Registre::get('parametres.referentiel'); $donnees['module'] = strtolower(get_class($this)); $donnees['action'] = 'liste'; $this->setSortie(self::RENDU_CORPS, $this->getVue('liste', $donnees)); } private function capturerParametres() { if (isset($_GET['rang'])) { $this->rang = $_GET['rang']; } if (isset($_GET['lettre'])) { $this->lettre = $_GET['lettre']; } } private function initialiserAlphabet() { if (!isset($this->alphabet)) { $this->alphabet = $this->getStatsInitiales(); } ksort($this->alphabet); } private function initialiserLettre() { if (empty($this->lettre)) { if (!is_null($this->alphabet)) { $this->lettre = key($this->alphabet); } else { $m = "Aucune lettre n'a pu être initialiser car l'alphabet vaut null."; trigger_error($m, E_USER_WARNING); } } } private function chargerCorrespondanceSpeciale() { return array('chimere' => '+', 'hybride' => '×'); } private function getStatsInitiales() { $nomRang = $this->getNomCodeRang(); $stats = array(); if ($nomRang) { $methode = 'getStatsInitiales'.$nomRang; $stats = $this->getEfloreTaxons()->$methode(); } return $stats; } private function getListeTaxons() { $taxons = false; if (isset($this->lettre)) { $nomRang = $this->getNomCodeRang(); if ($nomRang) { $methode = "getListe{$nomRang}ParInitiale"; $taxons = $this->getEfloreTaxons()->$methode($this->lettre); } } return $taxons; } private function getNomCodeRang() { $nom = false; if (array_key_exists($this->rang, $this->rangsCorrespondance)) { $nom = $this->rangsCorrespondance[$this->rang]; } else { $m = "Ce code de rang '{$this->rang}' est inconnu. Codes disponibles : ".implode(', ', $this->rangsCorrespondance); trigger_error($m, E_USER_WARNING); } return $nom; } /** * Gestion de la coloration de l'alphabet en fonction du nombre de résultat */ private function creerColoration($alphabet) { $debut = explode(',', Config::get('couleur_alphabet_debut')); // Tableau RGB de départ $fin = explode(',', Config::get('couleur_alphabet_fin')); // Tableau RGB d'arrivée $rvbAbreviations = array('R','V','B'); $nbreLettres = count($alphabet); $valeurMax = max($alphabet); $couleurs = array(); foreach ($alphabet as $lettre => $nbre) { foreach ($rvbAbreviations as $index => $rvb) { //Pour faire le Rouge, Vert, Bleu $couleurs[$nbre][$rvb] = round($debut[$index] - (($debut[$index]-$fin[$index]) / $valeurMax * $nbre) , 0); } } return $couleurs; } } ?>