Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 59 | Go to most recent revision | 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();
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
 
75
			} else {
76
				$m = "Aucune lettre n'a pu être initialiser car l'alphabet vaut null.";
77
				trigger_error($m, E_USER_WARNING);
78
			}
79
		}
80
	}
59 jpm 81
 
64 jpm 82
	private function chargerCorrespondanceSpeciale() {
83
		return array('chimere' => '+', 'hybride' => '×');
84
	}
85
 
59 jpm 86
	private function getStatsInitiales() {
87
		$nomRang = $this->getNomCodeRang();
88
		$stats = array();
89
		if ($nomRang) {
90
			$methode = 'getStatsInitiales'.$nomRang;
91
			$stats = $this->getEfloreTaxons()->$methode();
92
		}
93
		return $stats;
94
	}
95
 
96
	private function getListeTaxons() {
64 jpm 97
		$taxons = false;
59 jpm 98
		if (isset($this->lettre)) {
99
			$nomRang = $this->getNomCodeRang();
100
			if ($nomRang) {
101
				$methode = "getListe{$nomRang}ParInitiale";
102
				$taxons = $this->getEfloreTaxons()->$methode($this->lettre);
103
			}
104
		}
105
		return $taxons;
106
	}
107
 
108
	private function getNomCodeRang() {
109
		$nom = false;
64 jpm 110
		if (array_key_exists($this->rang, $this->rangsCorrespondance)) {
111
			$nom = $this->rangsCorrespondance[$this->rang];
112
		} else {
113
			$m = "Ce code de rang '{$this->rang}' est inconnu. Codes disponibles : ".implode(', ', $this->rangsCorrespondance);
114
			trigger_error($m, E_USER_WARNING);
59 jpm 115
		}
116
		return $nom;
117
	}
118
 
119
	/**
120
	 *  Gestion de la coloration de l'alphabet en fonction du nombre de résultat
121
	 */
122
	private function creerColoration($alphabet) {
123
		$debut = explode(',', Config::get('couleur_alphabet_debut')); // Tableau RGB de départ
124
		$fin = explode(',', Config::get('couleur_alphabet_fin')); // Tableau RGB d'arrivée
125
		$rvbAbreviations = array('R','V','B');
126
		$nbreLettres = count($alphabet);
127
		$valeurMax = max($alphabet);
128
		$couleurs = array();
129
		foreach ($alphabet as $lettre => $nbre) {
130
			foreach ($rvbAbreviations as $index => $rvb) { //Pour faire le Rouge, Vert, Bleu
131
				$couleurs[$nbre][$rvb] = round($debut[$index] - (($debut[$index]-$fin[$index]) / $valeurMax * $nbre) , 0);
132
			}
133
		}
134
		return $couleurs;
135
	}
136
 
45 jpm 137
}
138
?>