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