Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 64 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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