Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 44 | Rev 70 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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