Subversion Repositories Sites.obs-saisons.fr

Rev

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

Rev 31 Rev 33
1
<?php
1
<?php
2
 
2
 
3
class OdsStation extends GestionTriple {
3
class OdsStation extends GestionTriple {
4
 
4
 
5
	/**
5
	/**
6
     * Méthode appelée avec une requête de type GET.
6
     * Méthode appelée avec une requête de type GET.
7
     *
7
     *
8
     */
8
     */
9
    function getElement($param = array()) {
9
    function getElement($param = array()) {
10
    	
10
    	
11
    	if(isset($param[0])) {
11
    	if(isset($param[0])) {
12
    		$id_participant = $param[0];
12
    		$id_participant = $param[0];
13
    	} else {
13
    	} else {
14
    		return;
14
    		return;
15
    	}
15
    	}
16
       
16
       
17
		if($param[1] == "*") {
17
		if($param[1] == "*") {
18
        
18
        
19
			$info = $this->obtenirListeStationPourParticipant($id_participant);
19
			$info = $this->obtenirListeStationPourParticipant($id_participant);
20
			
20
			
21
		} else if(is_numeric($param[1])) {
21
		} else if(is_numeric($param[1])) {
22
			
22
			
23
			$id_station = $param[1];
23
			$id_station = $param[1];
24
			
24
			
25
			$info = $this->obtenirInformationsStation($id_station);
25
			$info = $this->obtenirInformationsStation($id_station);
26
		}
26
		}
27
       
27
       
28
        // Envoi sur la sortie standard
28
        // Envoi sur la sortie standard
29
        $this->envoyer($info);
29
        $this->envoyer($info);
30
    
30
    
31
    }
31
    }
32
   
32
   
33
    /**
33
    /**
34
     * Méthode appelée pour ajouter un élément.
34
     * Méthode appelée pour ajouter un élément.
35
     */
35
     */
36
    public function createElement($params) {
36
    public function createElement($params) {
37
    	
37
    	
38
    	$elements_requis = array('id_participant','station_nom', 'station_commune', 'station_lat', 'station_lon','station_milieu');
38
    	$elements_requis = array('id_participant','station_nom', 'station_commune', 'station_lat', 'station_lon','station_milieu');
39
    	$erreurs = array();
39
    	$erreurs = array();
40
        
40
        
41
    	foreach($elements_requis as $requis) {
41
    	foreach($elements_requis as $requis) {
42
    		if(!isset($params[$requis])) {
42
    		if(!isset($params[$requis])) {
43
    			//$erreurs[$requis] = 'erreur ';
43
    			//$erreurs[$requis] = 'erreur ';
44
    		}
44
    		}
45
    	}
45
    	}
46
    	
46
    	
47
    	if(!empty($erreurs)) {
47
    	if(!empty($erreurs)) {
48
    		$this->envoyer($erreurs);
48
    		$this->envoyer($erreurs);
49
    	}
49
    	}
50
    	
50
    	
51
    	$station['alt'] = '0';
51
    	$station['alt'] = '0';
52
    	
52
    	
53
    	$id_participant = $params['id_participant'];
53
    	$id_participant = $params['id_participant'];
54
    	
54
    	
55
    	$requete_creation_station = 'INSERT INTO ods_stations '.
55
    	$requete_creation_station = 'INSERT INTO ods_stations '.
56
					'(os_ce_participant, os_nom, os_ce_commune, os_latitude, os_longitude, os_altitude, os_ce_environnement, os_commentaire) '.
56
					'(os_ce_participant, os_nom, os_ce_commune, os_latitude, os_longitude, os_altitude, os_ce_environnement, os_commentaire) '.
57
					'VALUES ('.
57
					'VALUES ('.
58
							$this->bdd->quote($id_participant).','.
58
							$this->proteger($id_participant).','.
59
							$this->bdd->quote($params['station_nom']).','.
59
							$this->proteger($params['station_nom']).','.
60
							$this->bdd->quote($params['station_commune']).','.
60
							$this->proteger($params['station_commune']).','.
61
							$this->bdd->quote($params['station_lat']).','.
61
							$this->proteger($params['station_lat']).','.
62
							$this->bdd->quote($params['station_lon']).','.
62
							$this->proteger($params['station_lon']).','.
63
							$this->bdd->quote($params['station_alt']).','.
63
							$this->proteger($params['station_alt']).','.
64
							$this->bdd->quote($params['station_milieu']).','.
64
							$this->proteger($params['station_milieu']).','.
65
							$this->bdd->quote($params['station_description']).')';		
65
							$this->proteger($params['station_description']).')';		
66
							
66
							
67
		$creation_station = $this->executerRequeteSimple($requete_creation_station);
67
		$creation_station = $this->executerRequeteSimple($requete_creation_station);
68
		
68
		
69
		if(!$creation_station) {
69
		if(!$creation_station) {
70
    		// TODO: comment gère t'on les erreurs ?
70
    		// TODO: comment gère t'on les erreurs ?
71
    	}
71
    	}
72
    	
72
    	
73
    	$this->envoyer();
73
    	$this->envoyer();
74
    	
74
    	
75
    }
75
    }
76
   
76
   
77
    /**
77
    /**
78
     * Méthode appelée pour mettre à jour un élément
78
     * Méthode appelée pour mettre à jour un élément
79
     */
79
     */
80
    public function updateElement($uid, $params)    {
80
    public function updateElement($uid, $params)    {
81
    	
81
    	
82
	    if(!isset($uid[0])) {
82
	    if(!isset($uid[0])) {
83
    		$id_participant = $uid[0];
83
    		$id_participant = $uid[0];
84
    	} else {
84
    	} else {
85
    		return;
85
    		return;
86
    	}
86
    	}
87
    	
87
    	
88
    	if(!isset($uid[1])) {
88
    	if(!isset($uid[1])) {
89
    		$id_station = $uid[1];
89
    		$id_station = $uid[1];
90
    	} else {
90
    	} else {
91
    		return;
91
    		return;
92
    	}
92
    	}
93
    	
93
    	
94
        $requete_modification_station = 'UPDATE ods_stations '.
94
        $requete_modification_station = 'UPDATE ods_stations '.
95
			'SET '.
95
			'SET '.
96
			'os_nom ='.$this->bdd->quote($params['station_nom']).','.
96
			'os_nom ='.$this->proteger($params['station_nom']).','.
97
        	'os_latitude ='.$this->bdd->quote($params['station_commune']).','.
97
        	'os_latitude ='.$this->proteger($params['station_commune']).','.
98
			'os_latitude ='.$this->bdd->quote($params['station_lat']).','.
98
			'os_latitude ='.$this->proteger($params['station_lat']).','.
99
			'os_longitude ='.$this->bdd->quote($params['station_lon']).','.
99
			'os_longitude ='.$this->proteger($params['station_lon']).','.
100
			'os_altitude ='.$this->bdd->quote($params['station_alt']).','.
100
			'os_altitude ='.$this->proteger($params['station_alt']).','.
101
			'os_ce_environnement ='.$this->bdd->quote($params['station_milieu']).','.
101
			'os_ce_environnement ='.$this->proteger($params['station_milieu']).','.
102
			'os_commentaire ='.$this->bdd->quote($params['station_description']).' '.
102
			'os_commentaire ='.$this->proteger($params['station_description']).' '.
103
			'WHERE os_ce_particant = '.$this->bdd->quote($id_participant).' '.
103
			'WHERE os_ce_particant = '.$this->proteger($id_participant).' '.
104
        	'AND os_id_station = '.$this->bdd->quote($id_station);
104
        	'AND os_id_station = '.$this->proteger($id_station);
105
							
105
							
106
		$modification_station = $this->executerRequeteSimple($requete_creation_station);
106
		$modification_station = $this->executerRequeteSimple($requete_creation_station);
107
		
107
		
108
		if(!$modification_station) {
108
		if(!$modification_station) {
109
    		// TODO: comment gère t'on les erreurs ?
109
    		// TODO: comment gère t'on les erreurs ?
110
    	}
110
    	}
111
    	
111
    	
112
    	$this->envoyer();
112
    	$this->envoyer();
113
    }
113
    }
114
   
114
   
115
    /**
115
    /**
116
     * Méthode appelée pour supprimer un élément
116
     * Méthode appelée pour supprimer un élément
117
     */
117
     */
118
    public function deleteElement($uid) {
118
    public function deleteElement($uid) {
119
    	
119
    	
120
    	// Pour le moment, pas de suppression des stations
120
    	// Pour le moment, pas de suppression des stations
121
    	return ;
121
    	return ;
122
		
122
		
123
    	if(!isset($uid[0])) {
123
    	if(!isset($uid[0])) {
124
    		$id_participant = $uid[0];
124
    		$id_participant = $uid[0];
125
    	} else {
125
    	} else {
126
    		return;
126
    		return;
127
    	}
127
    	}
128
    	
128
    	
129
    	if(!isset($uid[1])) {
129
    	if(!isset($uid[1])) {
130
    		$id_station = $uid[1];
130
    		$id_station = $uid[1];
131
    	} else {
131
    	} else {
132
    		return;
132
    		return;
133
    	}
133
    	}
134
    	
134
    	
135
    	$requete_suppression_station = 'DELETE FROM ods_stations '.
135
    	$requete_suppression_station = 'DELETE FROM ods_stations '.
136
    	'WHERE os_ce_particant = '.$this->bdd->quote($id_participant).' '.
136
    	'WHERE os_ce_particant = '.$this->proteger($id_participant).' '.
137
        	'AND os_id_station = '.$this->bdd->quote($id_station);
137
        	'AND os_id_station = '.$this->proteger($id_station);
138
    	
138
    	
139
    	// TODO : supprimer également tout ce qui est associé à la station (observations, etc...)
139
    	// TODO : supprimer également tout ce qui est associé à la station (observations, etc...)
140
    	$suppression_station = $this->executerRequeteSimple($requete_suppression_station);
140
    	$suppression_station = $this->executerRequeteSimple($requete_suppression_station);
141
    	
141
    	
142
    	if(!$suppression_station) {
142
    	if(!$suppression_station) {
143
    		// TODO: comment gère t'on les erreurs ?
143
    		// TODO: comment gère t'on les erreurs ?
144
    	}
144
    	}
145
    	
145
    	
146
    	$this->envoyer();
146
    	$this->envoyer();
147
    	
147
    	
148
    }
148
    }
149
    
149
    
150
    
150
    
151
    // +---------------------------------------------------------------------------------------------------------------+
151
    // +---------------------------------------------------------------------------------------------------------------+
152
    // METHODES D'ACCES A LA BASE DE DONNEES
152
    // METHODES D'ACCES A LA BASE DE DONNEES
153
	private function obtenirListeStationPourParticipant($id_participant) {
153
	private function obtenirListeStationPourParticipant($id_participant) {
154
	    	
154
	    	
155
    	$requete_liste_station = 'SELECT * FROM ods_stations WHERE os_ce_participant = '.$this->bdd->quote($id_participant);
155
    	$requete_liste_station = 'SELECT * FROM ods_stations WHERE os_ce_participant = '.$this->proteger($id_participant);
156
 
156
 
157
    	$liste_station = $this->executerRequete($requete_liste_station);
157
    	$liste_station = $this->executerRequete($requete_liste_station);
158
    	
158
    	
159
    	$liste_station_formatees = array();
159
    	$liste_station_formatees = array();
160
    	 	
160
    	 	
161
    	foreach($liste_station as $indice => $station) {
161
    	foreach($liste_station as $indice => $station) {
162
	    		
162
	    		
163
    		$station_champs_formates = $this->formaterChampsStationPourEnvoi($station);
163
    		$station_champs_formates = $this->formaterChampsStationPourEnvoi($station);
164
		    $liste_station_formatees[$station['os_id_station']] = $station_champs_formates;
164
		    $liste_station_formatees[$station['os_id_station']] = $station_champs_formates;
165
    	}
165
    	}
166
    	
166
    	
167
    	return $liste_station_formatees;
167
    	return $liste_station_formatees;
168
	}
168
	}
169
    
169
    
170
    private function obtenirInformationsStation($id_station) {
170
    private function obtenirInformationsStation($id_station) {
171
    	
171
    	
172
    	$requete_infos_station = 'SELECT * FROM ods_stations WHERE os_id_station = '.$this->bdd->quote($id_station);
172
    	$requete_infos_station = 'SELECT * FROM ods_stations WHERE os_id_station = '.$this->proteger($id_station);
173
 
173
 
174
    	$infos_station = $this->executerRequete($requete_infos_station);
174
    	$infos_station = $this->executerRequete($requete_infos_station);
175
    	
175
    	
176
    	$infos_station_formatees = array();
176
    	$infos_station_formatees = array();
177
    	
177
    	
178
    	if(!empty($infos_station)) {
178
    	if(!empty($infos_station)) {
179
    		$infos_station = $infos_station[0];
179
    		$infos_station = $infos_station[0];
180
    		$infos_station_formatees = $this->formaterChampsStationPourEnvoi($infos_station);
180
    		$infos_station_formatees = $this->formaterChampsStationPourEnvoi($infos_station);
181
    	}
181
    	}
182
    	
182
    	
183
    	return $infos_station_formatees;
183
    	return $infos_station_formatees;
184
    }
184
    }
185
    
185
    
186
    private function formaterChampsStationPourEnvoi($station) {
186
    private function formaterChampsStationPourEnvoi($station) {
187
    	
187
    	
188
    	$station_champs_formates = array(
188
    	$station_champs_formates = array(
189
		    	'id' => $station['os_id_station'],
189
		    	'id' => $station['os_id_station'],
190
		    	'nom' => $station['os_nom'],
190
		    	'nom' => $station['os_nom'],
191
				'id_commune' => $station['os_ce_commune'],
191
				'id_commune' => $station['os_ce_commune'],
192
    			'commune' => 'Montpellier',//$this->obtenirInformationsCommuneParCodeInsee($station['os_ce_commune']),
192
    			'commune' => 'Montpellier',//$this->obtenirInformationsCommuneParCodeInsee($station['os_ce_commune']),
193
				'milieu' => 'Urbain',//$this->obtenirInformationsMilieuParAbreviation($station['os_milieu']),
193
				'milieu' => 'Urbain',//$this->obtenirInformationsMilieuParAbreviation($station['os_milieu']),
194
				'latitude' => $station['os_latitude'],
194
				'latitude' => $station['os_latitude'],
195
				'longitude' => $station['os_longitude'],
195
				'longitude' => $station['os_longitude'],
196
    			'altitude' => $station['os_altitude'],
196
    			'altitude' => $station['os_altitude'],
197
				'description' => $station['os_commentaire']
197
				'description' => $station['os_commentaire']
198
		    );
198
		    );
199
		    
199
		    
200
		return $station_champs_formates;
200
		return $station_champs_formates;
201
    }
201
    }
202
    
202
    
203
    private function obtenirInformationsCommuneParId($id_commune) {
203
    private function obtenirInformationsCommuneParId($id_commune) {
204
    	
204
    	
205
    	$requete_infos_commune = 'SELECT * FROM ods_communes WHERE oc_id_commune = '.$this->bdd->quote($id_commune);
205
    	$requete_infos_commune = 'SELECT * FROM ods_communes WHERE oc_id_commune = '.$this->proteger($id_commune);
206
    	$infos_commune = $this->executerRequete($requete_infos_commune);
206
    	$infos_commune = $this->executerRequete($requete_infos_commune);
207
    	
207
    	
208
    	return $infos_commune;
208
    	return $infos_commune;
209
    }
209
    }
210
    
210
    
211
	private function obtenirInformationsCommuneParCodeInsee($code_insee_commune) {
211
	private function obtenirInformationsCommuneParCodeInsee($code_insee_commune) {
212
    	
212
    	
213
    	$requete_infos_commune = 'SELECT * FROM ods_communes WHERE oc_code_insee = '.$this->bdd->quote($code_insee_commune);
213
    	$requete_infos_commune = 'SELECT * FROM ods_communes WHERE oc_code_insee = '.$this->proteger($code_insee_commune);
214
    	$infos_commune = $this->executerRequete($requete_infos_commune);
214
    	$infos_commune = $this->executerRequete($requete_infos_commune);
215
    	
215
    	
216
    	return $infos_commune;
216
    	return $infos_commune;
217
    }
217
    }
218
    
218
    
219
    private function obtenirInformationsMilieuParAbreviation($abreviation_milieu) {
219
    private function obtenirInformationsMilieuParAbreviation($abreviation_milieu) {
220
    	
220
    	
221
    	$informations_milieu = $this->obtenirValeurTripleParAbreviation($abreviation_milieu);
221
    	$informations_milieu = $this->obtenirValeurTripleParAbreviation($abreviation_milieu);
222
    	return $informations_milieu;
222
    	return $informations_milieu;
223
    	
223
    	
224
    }
224
    }
225
}
225
}
226
?>
226
?>