Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 43 | Rev 63 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 aurelien 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
 * Classe de test des Controleurs.
5
 *
6
 * @package     Collection
7
 * @category    Php 5.2
8
 * @author      Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @copyright   2010 Tela-Botanica
10
 * @license     http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
11
 * @license     http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
12
 * @version     SVN: $Id: Fiche.php 152 2010-09-06 16:19:12Z jpm $
13
 */
14
class Station extends aControleur {
15
 
16
	private $id_station_en_cours = null;
17
 
18
    public function __construct()  {
19
 
20
		parent::__construct();
21
        $this->initialiser();
22
    }
23
 
24
    public function initialiser() {
25
 
26
    	$this->id_station_en_cours = $_GET['id_station'];
27
    	$this->setNavigation();
28
 
29
    }
30
 
31
    public function executerActionParDefaut() {
32
    	return $this->afficherFormulaireSaisieStation();
33
    }
34
 
35
   	// +---------------------------------------------------------------------------------------------------------------+
36
    // METHODES D'AFFICHAGE DE FORMULAIRE
37
    public function afficherFormulaireSaisieStation() {
38
 
39
    	$donnees = array();
40
    	$formulaire = $this->getVue('formulaires/station_saisie',$donnees);
41
    	$this->setSortie(self::RENDU_CORPS, $formulaire);
42
    }
43
 
44
	public function afficherFormulaireModificationStation() {
45
 
46
    	$donnees = array();
47
 
48
    	$id_station = $this->id_station_en_cours;
49
    	$donnees['infos_station'] = $this->getInformationsStation($id_station);
50
    	$formulaire = $this->getVue('formulaires/station_modification',$donnees);
51
    	$this->setSortie(self::RENDU_CORPS, $formulaire);
52
    }
53
 
54
    // +---------------------------------------------------------------------------------------------------------------+
55
    // METHODES APPELEES LORS DE LA VALIDATION D'UN FORMULAIRE
56
    public function validerFormulaireSaisieStation() {
57
 
58
    	$valeurs_verifiees = $this->collecterValeursFormulaireSaisieStation();
59
 
60
    	$station_dao = new StationDao();
44 aurelien 61
    	$retour_ajout_station = $station_dao->ajouterStation($valeurs_verifiees);
62
 
63
    	if($id_nouvelle_station = $this->renvoyerIdSiAjoutStationEffectue($retour_ajout_station)) {
64
    		$this->id_station_en_cours = $id_nouvelle_station;
65
    		$this->afficherInformationsStation();
66
    		$this->setNavigation();
67
    	}
31 aurelien 68
    }
69
 
44 aurelien 70
    private function renvoyerIdSiAjoutStationEffectue($donnees_retour_dao) {
71
 
72
    	if(isset($donnees_retour_dao['id_nouvelle_station'])) {
73
    		return $donnees_retour_dao['id_nouvelle_station'];
74
    	}
75
 
76
    	return false;
77
    }
78
 
31 aurelien 79
    private function collecterValeursFormulaireSaisieStation() {
80
 
81
    	$valeurs_verifiees['station_commune'] = $_POST['station_commune'];
82
	    $valeurs_verifiees['station_milieu'] =  $_POST['station_milieu'];
83
	    $valeurs_verifiees['station_nom'] = $_POST['station_nom'];
84
	    $valeurs_verifiees['station_lat'] =  $_POST['station_lat'];
85
	    $valeurs_verifiees['station_lon'] = $_POST['station_lon'];
86
 
87
	    //TODO: verifier valeurs plus complètement
88
 
89
	    return $valeurs_verifiees;
90
 
91
    }
92
 
93
    public function validerFormulaireModificationStation() {
94
 
95
    	$valeurs_formulaires = $_POST['form_modif_station'];
96
 
97
    	$valeurs_verifiees = array();
98
 
99
    	$station_dao = new StationDao();
100
    	$station_dao->modifierStation($valeurs_verifiees);
101
 
102
    }
103
 
104
	// +---------------------------------------------------------------------------------------------------------------+
105
    // METHODES D'AFFICHAGES D'INFORMATION
106
    public function afficherlisteStation($param = null) {
107
 
108
    	$id_utilisateur = AppControleur::getIdUtilisateur();
109
 
110
    	$donnees['stations'] = $this->getListeStations($id_utilisateur);
111
        $this->setSortie(self::RENDU_CORPS, $this->getVue('listes/station_liste', $donnees));
112
    }
113
 
114
    public function afficherInformationsStation() {
115
 
116
    	$id_station = $this->id_station_en_cours;
117
 
118
    	$donnees['id_station'] = $id_station;
119
    	$donnees['infos_station'] = $this->getInformationsStation($id_station);
120
    	$this->setSortie(self::RENDU_CORPS, $this->getVue('fiches/station_fiche', $donnees));
121
 
122
    }
123
 
124
    // +---------------------------------------------------------------------------------------------------------------+
125
    // METHODES POUR FABRIQUER LE MENU
126
    public function construireMenuNavigation($espece_en_cours = null) {
127
 
128
    	$id_station_en_cours = $this->id_station_en_cours;
44 aurelien 129
    	$id_espece_en_cours = $_GET['id_espece'];
31 aurelien 130
 
131
    	$stations = $this->getListeStations();
132
 
133
    	foreach($stations as &$station) {
134
    		$station['url'] = aControleur::getUrlConsultationFicheStation($station['id']);
135
    	}
136
 
137
    	if($id_station_en_cours != null) {
138
    		$especes_station_en_cours = $this->getEspecesStation($id_station_en_cours);
139
 
140
    	    foreach($especes_station_en_cours as &$espece) {
35 aurelien 141
    			$espece['url'] = aControleur::getUrlConsultationEspeceStation($id_station_en_cours, $espece['id_espece']);
31 aurelien 142
    	    }
143
    		$stations[$id_station_en_cours]['especes'] = $especes_station_en_cours;
144
    	}
145
 
146
    	$donnees['stations'] = $stations;
147
    	$donnees['id_station_en_cours'] = $id_station_en_cours;
148
 
149
    	if($id_espece_en_cours != null) {
44 aurelien 150
    		$donnees['id_espece_en_cours'] = $id_espece_en_cours;
31 aurelien 151
    	}
152
 
153
    	$menu_navigation = $this->getVue('navigation/menu', $donnees);
154
 
155
        return $menu_navigation;
156
 
157
    }
158
 
159
    public function setNavigation() {
160
    	$this->setSortie(self::RENDU_NAVIGATION, $this->construireMenuNavigation());
161
    }
162
 
163
    // +---------------------------------------------------------------------------------------------------------------+
164
    // METHODE D'APPELS AUX DAOS
165
    protected function getListeStations() {
166
 
167
    	$station_dao = new StationDao();
168
    	return $station_dao->getListeStations();
169
    }
170
 
171
    private function getInformationsStation($id_station) {
172
 
173
    	$station_dao = new StationDao();
174
    	$infos_station = $station_dao->getInformationsStation($id_station);
175
 
176
    	$infos_station['individus'] = $this->getIndividusStation($id_station);
177
 
178
    	return $infos_station;
179
    }
180
 
181
    private function getEspecesStation($id_station) {
182
 
183
    	$espece_dao = new EspeceDao();
184
    	$liste_especes = $espece_dao->getListeEspecesPourStation($id_station);
185
 
186
    	return $liste_especes;
187
    }
188
 
189
    public function getIndividusStation($id_station) {
190
 
191
    	$individu_dao = new IndividuDao();
192
    	$liste_individus = $individu_dao->getListeIndividusPourStation($id_station);
193
 
194
    	return $liste_individus;
195
    }
43 aurelien 196
 
197
	public function getIndividusStationPourEspece($id_station,$id_espece) {
198
 
199
    	$individu_dao = new IndividuDao();
200
    	$liste_individus = $individu_dao->getListeIndividusPourStationPourEspece($id_station, $id_espece);
201
 
202
    	return $liste_individus;
203
    }
31 aurelien 204
}