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 |
|
70 |
aurelien |
26 |
if(isset($_GET['id_station'])) {
|
|
|
27 |
$this->id_station_en_cours = $_GET['id_station'];
|
|
|
28 |
}
|
31 |
aurelien |
29 |
$this->setNavigation();
|
|
|
30 |
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
public function executerActionParDefaut() {
|
|
|
34 |
return $this->afficherFormulaireSaisieStation();
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
// +---------------------------------------------------------------------------------------------------------------+
|
|
|
38 |
// METHODES D'AFFICHAGE DE FORMULAIRE
|
112 |
aurelien |
39 |
public function afficherFormulaireSaisieStation($donnees = array()) {
|
31 |
aurelien |
40 |
|
112 |
aurelien |
41 |
if($donnees == array()) {
|
|
|
42 |
|
|
|
43 |
$donnees['station_commune'] = '';
|
|
|
44 |
$donnees['station_milieu'] = '';
|
|
|
45 |
$donnees['station_nom'] = '';
|
|
|
46 |
$donnees['station_lat'] = '';
|
|
|
47 |
$donnees['station_lon'] = '';
|
|
|
48 |
$donnees['station_alt'] = '';
|
|
|
49 |
}
|
83 |
aurelien |
50 |
|
|
|
51 |
$donnees['milieux'] = $this->getListeMilieux();
|
31 |
aurelien |
52 |
$formulaire = $this->getVue('formulaires/station_saisie',$donnees);
|
|
|
53 |
$this->setSortie(self::RENDU_CORPS, $formulaire);
|
|
|
54 |
}
|
|
|
55 |
|
112 |
aurelien |
56 |
public function afficherFormulaireModificationStation($donnees = array()) {
|
31 |
aurelien |
57 |
|
|
|
58 |
$id_station = $this->id_station_en_cours;
|
83 |
aurelien |
59 |
$donnees['milieux'] = $this->getListeMilieux();
|
31 |
aurelien |
60 |
$donnees['infos_station'] = $this->getInformationsStation($id_station);
|
83 |
aurelien |
61 |
|
31 |
aurelien |
62 |
$formulaire = $this->getVue('formulaires/station_modification',$donnees);
|
|
|
63 |
$this->setSortie(self::RENDU_CORPS, $formulaire);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
// +---------------------------------------------------------------------------------------------------------------+
|
|
|
67 |
// METHODES APPELEES LORS DE LA VALIDATION D'UN FORMULAIRE
|
|
|
68 |
public function validerFormulaireSaisieStation() {
|
|
|
69 |
|
112 |
aurelien |
70 |
$valeurs_collectees = $this->collecterValeursFormulaireSaisieStation();
|
|
|
71 |
|
|
|
72 |
$verification_ou_erreurs = $this->verifierValeursStation($valeurs_collectees);
|
|
|
73 |
|
|
|
74 |
if($verification_ou_erreurs !== true) {
|
|
|
75 |
|
|
|
76 |
$donnees = $valeurs_collectees;
|
|
|
77 |
|
|
|
78 |
$donnees['erreurs'] = $verification_ou_erreurs;
|
|
|
79 |
$this->afficherFormulaireSaisieStation($donnees);
|
|
|
80 |
return;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
$valeurs_verifiees = $valeurs_collectees;
|
95 |
aurelien |
84 |
|
31 |
aurelien |
85 |
$station_dao = new StationDao();
|
44 |
aurelien |
86 |
$retour_ajout_station = $station_dao->ajouterStation($valeurs_verifiees);
|
|
|
87 |
|
|
|
88 |
if($id_nouvelle_station = $this->renvoyerIdSiAjoutStationEffectue($retour_ajout_station)) {
|
|
|
89 |
$this->id_station_en_cours = $id_nouvelle_station;
|
|
|
90 |
$this->afficherInformationsStation();
|
|
|
91 |
$this->setNavigation();
|
|
|
92 |
}
|
31 |
aurelien |
93 |
}
|
|
|
94 |
|
44 |
aurelien |
95 |
private function renvoyerIdSiAjoutStationEffectue($donnees_retour_dao) {
|
|
|
96 |
|
|
|
97 |
if(isset($donnees_retour_dao['id_nouvelle_station'])) {
|
|
|
98 |
return $donnees_retour_dao['id_nouvelle_station'];
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
return false;
|
|
|
102 |
}
|
|
|
103 |
|
31 |
aurelien |
104 |
private function collecterValeursFormulaireSaisieStation() {
|
|
|
105 |
|
112 |
aurelien |
106 |
$valeurs_collectees['station_commune'] = $_POST['station_commune'];
|
|
|
107 |
$valeurs_collectees['station_milieu'] = $_POST['station_milieu'];
|
|
|
108 |
$valeurs_collectees['station_nom'] = $_POST['station_nom'];
|
|
|
109 |
$valeurs_collectees['station_lat'] = $_POST['station_lat'];
|
|
|
110 |
$valeurs_collectees['station_lon'] = $_POST['station_lon'];
|
|
|
111 |
$valeurs_collectees['station_alt'] = $_POST['station_alt'];
|
31 |
aurelien |
112 |
|
112 |
aurelien |
113 |
return $valeurs_collectees;
|
31 |
aurelien |
114 |
|
|
|
115 |
}
|
|
|
116 |
|
95 |
aurelien |
117 |
private function collecterValeursFormulaireModificationStation() {
|
|
|
118 |
|
112 |
aurelien |
119 |
$valeurs_collectees['station_commune'] = $_POST['station_commune'];
|
|
|
120 |
$valeurs_collectees['station_milieu'] = $_POST['station_milieu'];
|
|
|
121 |
$valeurs_collectees['station_nom'] = $_POST['station_nom'];
|
|
|
122 |
$valeurs_collectees['station_lat'] = $_POST['station_lat'];
|
|
|
123 |
$valeurs_collectees['station_lon'] = $_POST['station_lon'];
|
|
|
124 |
$valeurs_collectees['station_alt'] = $_POST['station_alt'];
|
|
|
125 |
$valeurs_collectees['station_id'] = $_POST['station_id'];
|
95 |
aurelien |
126 |
|
112 |
aurelien |
127 |
return $valeurs_collectees;
|
95 |
aurelien |
128 |
|
|
|
129 |
}
|
|
|
130 |
|
112 |
aurelien |
131 |
private function verifierValeursStation($valeurs_a_verifier) {
|
|
|
132 |
|
|
|
133 |
$erreurs = array();
|
|
|
134 |
|
|
|
135 |
foreach($valeurs_a_verifier as $champ => $valeur) {
|
|
|
136 |
if(trim($valeur) == '') {
|
|
|
137 |
$erreurs[$champ] .= ' Ce champ ne peut pas être vide';
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
if(!empty($erreurs)) {
|
|
|
142 |
return $erreurs;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
return true;
|
|
|
146 |
}
|
|
|
147 |
|
31 |
aurelien |
148 |
public function validerFormulaireModificationStation() {
|
|
|
149 |
|
95 |
aurelien |
150 |
$valeurs_verifiees = $this->collecterValeursFormulaireModificationStation();
|
31 |
aurelien |
151 |
|
|
|
152 |
$station_dao = new StationDao();
|
95 |
aurelien |
153 |
$retour_modification = $station_dao->modifierStation($valeurs_verifiees['station_id'],$valeurs_verifiees);
|
31 |
aurelien |
154 |
|
95 |
aurelien |
155 |
if($retour_modification) {
|
|
|
156 |
$this->afficherInformationsStation();
|
|
|
157 |
$this->setNavigation();
|
|
|
158 |
}
|
|
|
159 |
|
31 |
aurelien |
160 |
}
|
|
|
161 |
|
|
|
162 |
// +---------------------------------------------------------------------------------------------------------------+
|
|
|
163 |
// METHODES D'AFFICHAGES D'INFORMATION
|
|
|
164 |
public function afficherlisteStation($param = null) {
|
|
|
165 |
|
|
|
166 |
$id_utilisateur = AppControleur::getIdUtilisateur();
|
|
|
167 |
|
|
|
168 |
$donnees['stations'] = $this->getListeStations($id_utilisateur);
|
|
|
169 |
$this->setSortie(self::RENDU_CORPS, $this->getVue('listes/station_liste', $donnees));
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
public function afficherInformationsStation() {
|
|
|
173 |
|
|
|
174 |
$id_station = $this->id_station_en_cours;
|
|
|
175 |
|
|
|
176 |
$donnees['id_station'] = $id_station;
|
|
|
177 |
$donnees['infos_station'] = $this->getInformationsStation($id_station);
|
83 |
aurelien |
178 |
$donnees['milieux'] = $this->getListeMilieux();
|
63 |
aurelien |
179 |
|
31 |
aurelien |
180 |
$this->setSortie(self::RENDU_CORPS, $this->getVue('fiches/station_fiche', $donnees));
|
|
|
181 |
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
// +---------------------------------------------------------------------------------------------------------------+
|
|
|
185 |
// METHODES POUR FABRIQUER LE MENU
|
70 |
aurelien |
186 |
public function construireMenuNavigation($id_espece_en_cours = null) {
|
31 |
aurelien |
187 |
|
|
|
188 |
$id_station_en_cours = $this->id_station_en_cours;
|
|
|
189 |
|
63 |
aurelien |
190 |
if(isset($_GET['id_espece'])) {
|
|
|
191 |
$id_espece_en_cours = $_GET['id_espece'];
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
|
31 |
aurelien |
195 |
$stations = $this->getListeStations();
|
|
|
196 |
|
63 |
aurelien |
197 |
foreach($stations as &$station) {
|
|
|
198 |
|
70 |
aurelien |
199 |
$station['url'] = Liens::getUrlConsultationFicheStation($station['id']);
|
31 |
aurelien |
200 |
}
|
|
|
201 |
|
83 |
aurelien |
202 |
if($id_station_en_cours != null && $id_station_en_cours != 'saisie') {
|
31 |
aurelien |
203 |
$especes_station_en_cours = $this->getEspecesStation($id_station_en_cours);
|
|
|
204 |
|
|
|
205 |
foreach($especes_station_en_cours as &$espece) {
|
70 |
aurelien |
206 |
$espece['url'] = Liens::getUrlConsultationEspeceStation($id_station_en_cours, $espece['id_espece']);
|
31 |
aurelien |
207 |
}
|
|
|
208 |
$stations[$id_station_en_cours]['especes'] = $especes_station_en_cours;
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
$donnees['stations'] = $stations;
|
|
|
212 |
$donnees['id_station_en_cours'] = $id_station_en_cours;
|
70 |
aurelien |
213 |
|
|
|
214 |
$donnees['id_espece_en_cours'] = $id_espece_en_cours;
|
31 |
aurelien |
215 |
|
|
|
216 |
$menu_navigation = $this->getVue('navigation/menu', $donnees);
|
|
|
217 |
|
|
|
218 |
return $menu_navigation;
|
|
|
219 |
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
public function setNavigation() {
|
|
|
223 |
$this->setSortie(self::RENDU_NAVIGATION, $this->construireMenuNavigation());
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
// +---------------------------------------------------------------------------------------------------------------+
|
|
|
227 |
// METHODE D'APPELS AUX DAOS
|
|
|
228 |
protected function getListeStations() {
|
|
|
229 |
|
|
|
230 |
$station_dao = new StationDao();
|
|
|
231 |
return $station_dao->getListeStations();
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
private function getInformationsStation($id_station) {
|
|
|
235 |
|
|
|
236 |
$station_dao = new StationDao();
|
|
|
237 |
$infos_station = $station_dao->getInformationsStation($id_station);
|
|
|
238 |
|
|
|
239 |
$infos_station['individus'] = $this->getIndividusStation($id_station);
|
|
|
240 |
|
|
|
241 |
return $infos_station;
|
|
|
242 |
}
|
|
|
243 |
|
|
|
244 |
private function getEspecesStation($id_station) {
|
|
|
245 |
|
|
|
246 |
$espece_dao = new EspeceDao();
|
|
|
247 |
$liste_especes = $espece_dao->getListeEspecesPourStation($id_station);
|
|
|
248 |
|
|
|
249 |
return $liste_especes;
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
public function getIndividusStation($id_station) {
|
|
|
253 |
|
|
|
254 |
$individu_dao = new IndividuDao();
|
|
|
255 |
$liste_individus = $individu_dao->getListeIndividusPourStation($id_station);
|
|
|
256 |
|
|
|
257 |
return $liste_individus;
|
|
|
258 |
}
|
43 |
aurelien |
259 |
|
|
|
260 |
public function getIndividusStationPourEspece($id_station,$id_espece) {
|
|
|
261 |
|
|
|
262 |
$individu_dao = new IndividuDao();
|
|
|
263 |
$liste_individus = $individu_dao->getListeIndividusPourStationPourEspece($id_station, $id_espece);
|
|
|
264 |
|
|
|
265 |
return $liste_individus;
|
|
|
266 |
}
|
83 |
aurelien |
267 |
|
|
|
268 |
public function getListeMilieux() {
|
|
|
269 |
|
|
|
270 |
$triple_dao = new TripleDao();
|
|
|
271 |
$liste_milieux = $triple_dao->getListeMilieux();
|
|
|
272 |
|
|
|
273 |
return $liste_milieux;
|
|
|
274 |
}
|
70 |
aurelien |
275 |
}
|
|
|
276 |
?>
|