Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 72 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
45 jpm 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
 * Classe mère du module Liste.
5
 *
6
 * @category	PHP 5.2
7
 * @package		eflore-consultation
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @author		Delphine CAUQUIL <delphine@tela-botanica.org>
10
 * @copyright	2011 Tela-Botanica
11
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
12
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
13
 * @version		$Id$
14
 */
15
class Liste extends aControleur {
16
 
59 jpm 17
	private $alphabet = null;
18
	protected $rang = null;
19
	protected $lettre = null;
64 jpm 20
	private $rangsCorrespondance = array('F' => 'Famille', 'G' => 'Genre');
59 jpm 21
 
45 jpm 22
	public function initialiser() {
23
		$this->capturerParametres();
24
	}
25
 
26
	public function executerActionParDefaut() {
59 jpm 27
		$this->executerListe();
45 jpm 28
	}
29
 
59 jpm 30
	public function executerListe() {
64 jpm 31
		$this->initialiserAlphabet();
32
		$this->initialiserLettre();
59 jpm 33
		$couleurs = $this->creerColoration($this->alphabet);
34
		$taxons = $this->getListeTaxons();
72 jpm 35
 
45 jpm 36
		$donnees = array();
37
		$donnees['i18n'] = I18n::get('Liste');
59 jpm 38
		$donnees['lettre'] = $this->lettre;
39
		$donnees['rang'] = $this->rang;
64 jpm 40
		$donnees['rangCodes'] = array_keys($this->rangsCorrespondance);
59 jpm 41
		$donnees['initiales'] = $this->alphabet;
64 jpm 42
		$donnees['lettreCorrespondance'] = $this->chargerCorrespondanceSpeciale();
59 jpm 43
		$donnees['couleurs'] = $couleurs;
44
		$donnees['taxons'] = $taxons;
45
		$donnees['nbreTaxons'] = $this->getEfloreTaxons()->getEnteteTotal();
46
		$donnees['urlFiltre'] = $this->obtenirUrlBase();
47
		$donnees['referentiel'] = Registre::get('parametres.referentiel');
48
		$donnees['module'] = strtolower(get_class($this));
64 jpm 49
		$donnees['action'] = 'liste';
45 jpm 50
		$this->setSortie(self::RENDU_CORPS, $this->getVue('liste', $donnees));
51
	}
52
 
53
 
54
	private function capturerParametres() {
55
		if (isset($_GET['rang'])) {
59 jpm 56
			$this->rang = $_GET['rang'];
45 jpm 57
		}
59 jpm 58
		if (isset($_GET['lettre'])) {
59
			$this->lettre = $_GET['lettre'];
60
		}
45 jpm 61
	}
59 jpm 62
 
64 jpm 63
	private function initialiserAlphabet() {
59 jpm 64
		if (!isset($this->alphabet)) {
65
			$this->alphabet = $this->getStatsInitiales();
66
		}
67
		ksort($this->alphabet);
68
	}
64 jpm 69
 
70
	private function initialiserLettre() {
71
		if (empty($this->lettre)) {
72
			if (!is_null($this->alphabet)) {
73
				$this->lettre = key($this->alphabet);
74
			} else {
75
				$m = "Aucune lettre n'a pu être initialiser car l'alphabet vaut null.";
76
				trigger_error($m, E_USER_WARNING);
77
			}
78
		}
79
	}
59 jpm 80
 
64 jpm 81
	private function chargerCorrespondanceSpeciale() {
82
		return array('chimere' => '+', 'hybride' => '×');
83
	}
84
 
59 jpm 85
	private function getStatsInitiales() {
86
		$nomRang = $this->getNomCodeRang();
87
		$stats = array();
88
		if ($nomRang) {
89
			$methode = 'getStatsInitiales'.$nomRang;
90
			$stats = $this->getEfloreTaxons()->$methode();
91
		}
92
		return $stats;
93
	}
94
 
95
	private function getListeTaxons() {
64 jpm 96
		$taxons = false;
59 jpm 97
		if (isset($this->lettre)) {
98
			$nomRang = $this->getNomCodeRang();
99
			if ($nomRang) {
100
				$methode = "getListe{$nomRang}ParInitiale";
101
				$taxons = $this->getEfloreTaxons()->$methode($this->lettre);
102
			}
103
		}
104
		return $taxons;
105
	}
106
 
107
	private function getNomCodeRang() {
108
		$nom = false;
64 jpm 109
		if (array_key_exists($this->rang, $this->rangsCorrespondance)) {
110
			$nom = $this->rangsCorrespondance[$this->rang];
111
		} else {
112
			$m = "Ce code de rang '{$this->rang}' est inconnu. Codes disponibles : ".implode(', ', $this->rangsCorrespondance);
113
			trigger_error($m, E_USER_WARNING);
59 jpm 114
		}
115
		return $nom;
116
	}
117
 
118
	/**
119
	 *  Gestion de la coloration de l'alphabet en fonction du nombre de résultat
120
	 */
121
	private function creerColoration($alphabet) {
122
		$debut = explode(',', Config::get('couleur_alphabet_debut')); // Tableau RGB de départ
123
		$fin = explode(',', Config::get('couleur_alphabet_fin')); // Tableau RGB d'arrivée
124
		$rvbAbreviations = array('R','V','B');
125
		$nbreLettres = count($alphabet);
126
		$valeurMax = max($alphabet);
127
		$couleurs = array();
128
		foreach ($alphabet as $lettre => $nbre) {
129
			foreach ($rvbAbreviations as $index => $rvb) { //Pour faire le Rouge, Vert, Bleu
130
				$couleurs[$nbre][$rvb] = round($debut[$index] - (($debut[$index]-$fin[$index]) / $valeurMax * $nbre) , 0);
131
			}
132
		}
133
		return $couleurs;
134
	}
135
 
45 jpm 136
}
137
?>