Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 45 | Rev 64 | 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;
20
 
45 jpm 21
	public function initialiser() {
22
		$this->capturerParametres();
23
	}
24
 
25
	public function executerActionParDefaut() {
59 jpm 26
		$this->executerListe();
45 jpm 27
	}
28
 
59 jpm 29
	public function executerListe() {
30
		$this->chargerAlphabet();
31
		$this->lettre = key($this->alphabet);
32
		$this->executerFiltre();
33
	}
34
 
35
	public function executerFiltre() {
36
		$this->chargerAlphabet();
37
		$couleurs = $this->creerColoration($this->alphabet);
38
		$taxons = $this->getListeTaxons();
39
 
45 jpm 40
		$donnees = array();
41
		$donnees['i18n'] = I18n::get('Liste');
59 jpm 42
		$donnees['lettre'] = $this->lettre;
43
		$donnees['rang'] = $this->rang;
44
		$donnees['initiales'] = $this->alphabet;
45
		$donnees['couleurs'] = $couleurs;
46
		$donnees['taxons'] = $taxons;
47
		$donnees['nbreTaxons'] = $this->getEfloreTaxons()->getEnteteTotal();
48
		$donnees['urlFiltre'] = $this->obtenirUrlBase();
49
		$donnees['referentiel'] = Registre::get('parametres.referentiel');
50
		$donnees['module'] = strtolower(get_class($this));
51
		$donnees['action'] = 'filtre';
45 jpm 52
		$this->setSortie(self::RENDU_CORPS, $this->getVue('liste', $donnees));
53
	}
54
 
55
 
56
	private function capturerParametres() {
57
		if (isset($_GET['rang'])) {
59 jpm 58
			$this->rang = $_GET['rang'];
45 jpm 59
		}
59 jpm 60
		if (isset($_GET['lettre'])) {
61
			$this->lettre = $_GET['lettre'];
62
		}
45 jpm 63
	}
59 jpm 64
 
65
	private function chargerAlphabet() {
66
		if (!isset($this->alphabet)) {
67
			$this->alphabet = $this->getStatsInitiales();
68
		}
69
		ksort($this->alphabet);
70
	}
71
 
72
	private function getStatsInitiales() {
73
		$nomRang = $this->getNomCodeRang();
74
		$stats = array();
75
		if ($nomRang) {
76
			$methode = 'getStatsInitiales'.$nomRang;
77
			$stats = $this->getEfloreTaxons()->$methode();
78
		}
79
		return $stats;
80
	}
81
 
82
	private function getListeTaxons() {
83
		$taxons = array();
84
		if (isset($this->lettre)) {
85
			$nomRang = $this->getNomCodeRang();
86
			if ($nomRang) {
87
				$methode = "getListe{$nomRang}ParInitiale";
88
				$taxons = $this->getEfloreTaxons()->$methode($this->lettre);
89
			}
90
		}
91
		return $taxons;
92
	}
93
 
94
	private function getNomCodeRang() {
95
		$nom = false;
96
		switch ($this->rang) {
97
			case 'F' :
98
				$nom = 'Famille';
99
				break;
100
			case 'G' :
101
				$nom = 'Genre';
102
				break;
103
			default :
104
				$m = "Ce code de rang '{$this->rang}' est inconnu. Codes disponibles : F (Famille), G (Genre).";
105
				trigger_error($m, E_USER_WARNING);
106
		}
107
		return $nom;
108
	}
109
 
110
	/**
111
	 *  Gestion de la coloration de l'alphabet en fonction du nombre de résultat
112
	 */
113
	private function creerColoration($alphabet) {
114
		$debut = explode(',', Config::get('couleur_alphabet_debut')); // Tableau RGB de départ
115
		$fin = explode(',', Config::get('couleur_alphabet_fin')); // Tableau RGB d'arrivée
116
		$rvbAbreviations = array('R','V','B');
117
		$nbreLettres = count($alphabet);
118
		$valeurMax = max($alphabet);
119
		$couleurs = array();
120
		foreach ($alphabet as $lettre => $nbre) {
121
			foreach ($rvbAbreviations as $index => $rvb) { //Pour faire le Rouge, Vert, Bleu
122
				$couleurs[$nbre][$rvb] = round($debut[$index] - (($debut[$index]-$fin[$index]) / $valeurMax * $nbre) , 0);
123
			}
124
		}
125
		return $couleurs;
126
	}
127
 
45 jpm 128
}
129
?>