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 |
}
|
|
|
164 |
|
|
|
165 |
// +---------------------------------------------------------------------------------------------------------------+
|
|
|
166 |
// METHODES D'AFFICHAGES D'INFORMATION
|
|
|
167 |
public function afficherlisteStation($param = null) {
|
|
|
168 |
|
|
|
169 |
$id_utilisateur = AppControleur::getIdUtilisateur();
|
|
|
170 |
|
|
|
171 |
$donnees['stations'] = $this->getListeStations($id_utilisateur);
|
|
|
172 |
$this->setSortie(self::RENDU_CORPS, $this->getVue('listes/station_liste', $donnees));
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
public function afficherInformationsStation() {
|
|
|
176 |
|
|
|
177 |
$id_station = $this->id_station_en_cours;
|
|
|
178 |
|
|
|
179 |
$donnees['id_station'] = $id_station;
|
|
|
180 |
$donnees['infos_station'] = $this->getInformationsStation($id_station);
|
83 |
aurelien |
181 |
$donnees['milieux'] = $this->getListeMilieux();
|
63 |
aurelien |
182 |
|
31 |
aurelien |
183 |
$this->setSortie(self::RENDU_CORPS, $this->getVue('fiches/station_fiche', $donnees));
|
|
|
184 |
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
// +---------------------------------------------------------------------------------------------------------------+
|
|
|
188 |
// METHODES POUR FABRIQUER LE MENU
|
70 |
aurelien |
189 |
public function construireMenuNavigation($id_espece_en_cours = null) {
|
31 |
aurelien |
190 |
|
|
|
191 |
$id_station_en_cours = $this->id_station_en_cours;
|
|
|
192 |
|
63 |
aurelien |
193 |
if(isset($_GET['id_espece'])) {
|
|
|
194 |
$id_espece_en_cours = $_GET['id_espece'];
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
|
31 |
aurelien |
198 |
$stations = $this->getListeStations();
|
|
|
199 |
|
63 |
aurelien |
200 |
foreach($stations as &$station) {
|
|
|
201 |
|
70 |
aurelien |
202 |
$station['url'] = Liens::getUrlConsultationFicheStation($station['id']);
|
31 |
aurelien |
203 |
}
|
|
|
204 |
|
83 |
aurelien |
205 |
if($id_station_en_cours != null && $id_station_en_cours != 'saisie') {
|
31 |
aurelien |
206 |
$especes_station_en_cours = $this->getEspecesStation($id_station_en_cours);
|
|
|
207 |
|
|
|
208 |
foreach($especes_station_en_cours as &$espece) {
|
70 |
aurelien |
209 |
$espece['url'] = Liens::getUrlConsultationEspeceStation($id_station_en_cours, $espece['id_espece']);
|
31 |
aurelien |
210 |
}
|
|
|
211 |
$stations[$id_station_en_cours]['especes'] = $especes_station_en_cours;
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
$donnees['stations'] = $stations;
|
|
|
215 |
$donnees['id_station_en_cours'] = $id_station_en_cours;
|
70 |
aurelien |
216 |
|
|
|
217 |
$donnees['id_espece_en_cours'] = $id_espece_en_cours;
|
31 |
aurelien |
218 |
|
|
|
219 |
$menu_navigation = $this->getVue('navigation/menu', $donnees);
|
|
|
220 |
|
|
|
221 |
return $menu_navigation;
|
|
|
222 |
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
public function setNavigation() {
|
|
|
226 |
$this->setSortie(self::RENDU_NAVIGATION, $this->construireMenuNavigation());
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
// +---------------------------------------------------------------------------------------------------------------+
|
|
|
230 |
// METHODE D'APPELS AUX DAOS
|
|
|
231 |
protected function getListeStations() {
|
|
|
232 |
|
|
|
233 |
$station_dao = new StationDao();
|
|
|
234 |
return $station_dao->getListeStations();
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
private function getInformationsStation($id_station) {
|
|
|
238 |
|
|
|
239 |
$station_dao = new StationDao();
|
|
|
240 |
$infos_station = $station_dao->getInformationsStation($id_station);
|
|
|
241 |
|
|
|
242 |
$infos_station['individus'] = $this->getIndividusStation($id_station);
|
|
|
243 |
|
|
|
244 |
return $infos_station;
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
private function getEspecesStation($id_station) {
|
|
|
248 |
|
|
|
249 |
$espece_dao = new EspeceDao();
|
|
|
250 |
$liste_especes = $espece_dao->getListeEspecesPourStation($id_station);
|
|
|
251 |
|
|
|
252 |
return $liste_especes;
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
public function getIndividusStation($id_station) {
|
|
|
256 |
|
|
|
257 |
$individu_dao = new IndividuDao();
|
|
|
258 |
$liste_individus = $individu_dao->getListeIndividusPourStation($id_station);
|
|
|
259 |
|
|
|
260 |
return $liste_individus;
|
|
|
261 |
}
|
43 |
aurelien |
262 |
|
|
|
263 |
public function getIndividusStationPourEspece($id_station,$id_espece) {
|
|
|
264 |
|
|
|
265 |
$individu_dao = new IndividuDao();
|
|
|
266 |
$liste_individus = $individu_dao->getListeIndividusPourStationPourEspece($id_station, $id_espece);
|
|
|
267 |
|
|
|
268 |
return $liste_individus;
|
|
|
269 |
}
|
83 |
aurelien |
270 |
|
|
|
271 |
public function getListeMilieux() {
|
|
|
272 |
|
|
|
273 |
$triple_dao = new TripleDao();
|
|
|
274 |
$liste_milieux = $triple_dao->getListeMilieux();
|
|
|
275 |
|
|
|
276 |
return $liste_milieux;
|
|
|
277 |
}
|
70 |
aurelien |
278 |
}
|
|
|
279 |
?>
|