31 |
aurelien |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
class OdsIndividu extends JRestService {
|
|
|
4 |
|
33 |
aurelien |
5 |
const PREFIXE = 'get';
|
|
|
6 |
|
31 |
aurelien |
7 |
/**
|
|
|
8 |
* Méthode appelée avec une requête de type GET.
|
|
|
9 |
*
|
|
|
10 |
*/
|
|
|
11 |
function getElement($param = array()) {
|
33 |
aurelien |
12 |
|
|
|
13 |
$type = $param[0];
|
31 |
aurelien |
14 |
|
33 |
aurelien |
15 |
if ($type == '*' || is_numeric($type)) {
|
|
|
16 |
$info = $this->getElementParDefaut($param);
|
|
|
17 |
} else {
|
|
|
18 |
$methode = self::PREFIXE.$type;
|
|
|
19 |
if (method_exists($this, $methode)) {
|
|
|
20 |
array_shift($param);
|
|
|
21 |
$info = $this->$methode($param);
|
|
|
22 |
} else {
|
|
|
23 |
$this->messages[] = "Le type d'information demandé '$type' n'est pas disponible.";
|
|
|
24 |
}
|
|
|
25 |
}
|
31 |
aurelien |
26 |
|
|
|
27 |
// Envoi sur la sortie standard
|
|
|
28 |
$this->envoyer($info);
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Méthode appelée pour ajouter un élément.
|
|
|
33 |
*/
|
|
|
34 |
public function createElement($params) {
|
33 |
aurelien |
35 |
|
|
|
36 |
$elements_requis = array('id_participant','id_espece','id_station','individu_nom');
|
|
|
37 |
|
|
|
38 |
foreach($elements_requis as $requis) {
|
|
|
39 |
if(!isset($params[$requis])) {
|
|
|
40 |
//$erreurs[$requis] = 'erreur ';
|
|
|
41 |
}
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
if(!empty($erreurs)) {
|
|
|
45 |
$this->envoyer($erreurs);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
$requete_creation_individu = 'INSERT INTO ods_individus '.
|
|
|
49 |
'(oi_ce_espece, oi_ce_station, oi_nom) '.
|
|
|
50 |
'VALUES ('.
|
|
|
51 |
$this->proteger($params['id_espece']).','.
|
|
|
52 |
$this->proteger($params['id_station']).','.
|
|
|
53 |
$this->proteger($params['individu_nom']).')';
|
|
|
54 |
$creation_individu = $this->executerRequeteSimple($requete_creation_individu);
|
|
|
55 |
|
46 |
aurelien |
56 |
|
|
|
57 |
if(!$creation_individu) {
|
|
|
58 |
$retour['erreurs'] = 'erreur d\'insertion';
|
|
|
59 |
} else {
|
|
|
60 |
$retour['id_nouvel_individu'] = $this->renvoyerDernierIdInsere();
|
33 |
aurelien |
61 |
}
|
|
|
62 |
|
46 |
aurelien |
63 |
$this->envoyer($retour);
|
31 |
aurelien |
64 |
}
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* Méthode appelée pour mettre à jour un élément
|
|
|
68 |
*/
|
|
|
69 |
public function updateElement($uid, $params) {
|
210 |
aurelien |
70 |
|
|
|
71 |
if(isset($uid[0])) {
|
|
|
72 |
$id_individu = $uid[0];
|
|
|
73 |
} else {
|
|
|
74 |
return;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
$requete_modification_individu = 'UPDATE ods_individus '.
|
|
|
78 |
'SET oi_nom = '.$this->proteger($params['individu_nom']).' '.
|
|
|
79 |
'WHERE oi_id_individu = '.$this->proteger($id_individu);
|
|
|
80 |
|
|
|
81 |
$modification_individu = $this->executerRequeteSimple($requete_modification_individu);
|
31 |
aurelien |
82 |
|
|
|
83 |
$this->envoyer();
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
/**
|
|
|
87 |
* Méthode appelée pour supprimer un élément
|
|
|
88 |
*/
|
|
|
89 |
public function deleteElement($uid) {
|
210 |
aurelien |
90 |
|
|
|
91 |
if(isset($uid[0])) {
|
|
|
92 |
$id_participant = $uid[0];
|
|
|
93 |
} else {
|
|
|
94 |
return;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
if(isset($uid[1])) {
|
|
|
98 |
$id_individu = $uid[1];
|
|
|
99 |
} else {
|
|
|
100 |
return;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
$requete_suppression_individu = 'DELETE FROM ods_individus '.
|
|
|
104 |
'WHERE oi_id_individu = '.$this->proteger($id_individu).' '.
|
|
|
105 |
'AND oi_ce_station IN '.
|
|
|
106 |
'(SELECT os_id_station FROM ods_stations '.
|
|
|
107 |
'WHERE os_ce_participant = '.$this->proteger($id_participant).' '.
|
|
|
108 |
')';
|
|
|
109 |
|
|
|
110 |
$suppression_individu = $this->executerRequeteSimple($requete_suppression_individu);
|
|
|
111 |
|
|
|
112 |
if(!$suppression_individu) {
|
|
|
113 |
// TODO: comment gère t'on les erreurs ?
|
|
|
114 |
}
|
31 |
aurelien |
115 |
|
|
|
116 |
// Envoie sur la sortie standard
|
|
|
117 |
$this->envoyer();
|
|
|
118 |
}
|
|
|
119 |
|
41 |
aurelien |
120 |
private function getElementParDefaut($params) {
|
|
|
121 |
return $this->getInformationsIndividu($params);
|
|
|
122 |
}
|
|
|
123 |
|
33 |
aurelien |
124 |
private function getInformationsIndividu($params) {
|
|
|
125 |
|
|
|
126 |
$id_individu = $params[0];
|
|
|
127 |
|
41 |
aurelien |
128 |
$requete_informations_individu = 'SELECT * FROM ods_individus '.
|
33 |
aurelien |
129 |
'WHERE oi_id_individu = '.$this->proteger($id_individu);
|
|
|
130 |
|
41 |
aurelien |
131 |
$informations_individu = $this->executerRequete($requete_informations_individu);
|
|
|
132 |
|
|
|
133 |
if(!empty($informations_individu)) {
|
|
|
134 |
$informations_individu_formatees = $this->formaterTableauIndividuPourEnvoi($informations_individu[0]);
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
return $informations_individu_formatees;
|
|
|
138 |
|
33 |
aurelien |
139 |
}
|
|
|
140 |
|
|
|
141 |
private function getIndividusPourStation($params) {
|
|
|
142 |
|
|
|
143 |
$id_station = $params[0];
|
31 |
aurelien |
144 |
|
284 |
aurelien |
145 |
$requete_individus_station = 'SELECT oi.* FROM ods_individus oi '.
|
|
|
146 |
'INNER JOIN ods_especes oe '.
|
|
|
147 |
'ON oi.oi_ce_espece = oe.oe_id_espece '.
|
|
|
148 |
'AND oe.oe_espece_active = 1 '.
|
33 |
aurelien |
149 |
'WHERE oi_ce_station = '.$this->proteger($id_station);
|
|
|
150 |
$liste_individus_pour_station = $this->executerRequete($requete_individus_station);
|
|
|
151 |
|
|
|
152 |
foreach($liste_individus_pour_station as &$individu_pour_station) {
|
|
|
153 |
|
|
|
154 |
$individu_pour_station = $this->formaterTableauIndividuPourEnvoi($individu_pour_station);
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
return $liste_individus_pour_station;
|
31 |
aurelien |
158 |
}
|
33 |
aurelien |
159 |
|
|
|
160 |
private function getIndividusPourStationPourEspece($params) {
|
|
|
161 |
|
|
|
162 |
$id_station = $params[0];
|
|
|
163 |
$id_espece = $params[1];
|
|
|
164 |
|
|
|
165 |
$requete_individus_station_espece = 'SELECT * FROM ods_individus '.
|
|
|
166 |
'WHERE oi_ce_station = '.$this->proteger($id_station).' '.
|
|
|
167 |
'AND oi_ce_espece ='.$this->proteger($id_espece);
|
|
|
168 |
|
|
|
169 |
$liste_individus_pour_station_pour_espece = $this->executerRequete($requete_individus_station_espece);
|
|
|
170 |
|
|
|
171 |
foreach($liste_individus_pour_station_pour_espece as &$individu_pour_station_pour_espece) {
|
|
|
172 |
|
|
|
173 |
$individu_pour_station_pour_espece = $this->formaterTableauIndividuPourEnvoi($individu_pour_station_pour_espece);
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
return $liste_individus_pour_station_pour_espece;
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
private function formaterTableauIndividuPourEnvoi($individu) {
|
|
|
180 |
|
|
|
181 |
return array(
|
41 |
aurelien |
182 |
'id_individu' => $individu['oi_id_individu'],
|
33 |
aurelien |
183 |
'id_espece' => $individu['oi_ce_espece'],
|
|
|
184 |
'id_station' => $individu['oi_ce_station'],
|
|
|
185 |
'nom' => $individu['oi_nom']
|
|
|
186 |
);
|
|
|
187 |
|
|
|
188 |
}
|
31 |
aurelien |
189 |
}
|
|
|
190 |
?>
|