Line 44... |
Line 44... |
44 |
* Process $_POST et $_GET
|
44 |
* Process $_POST et $_GET
|
45 |
* TODO: changer JRest pour pouvoir disposer d'un nom de méthode plus représentatif que "updateXXX"
|
45 |
* TODO: changer JRest pour pouvoir disposer d'un nom de méthode plus représentatif que "updateXXX"
|
46 |
* en POST
|
46 |
* en POST
|
47 |
*/
|
47 |
*/
|
48 |
function updateElement($uid, $pairs) {
|
48 |
function updateElement($uid, $pairs) {
|
49 |
$params = Array('uid' => $uid);
|
49 |
$params = Array('uid' => $uid[0]);
|
50 |
// TODO: pas de range mais un utilisateur: possible
|
50 |
// TODO: pas de range mais un utilisateur: possible
|
51 |
if(!isset($_POST['range'])) {
|
51 |
if(!isset($_POST['range'])) {
|
52 |
header('HTTP/1.0 204 No Content');
|
52 |
header('HTTP/1.0 204 No Content');
|
53 |
exit;
|
53 |
exit;
|
54 |
}
|
54 |
}
|
- |
|
55 |
// trim() car: `POST http://url<<<"range=*"`
|
55 |
elseif($_POST['range'] == '*') {
|
56 |
elseif(trim($_POST['range']) == '*') {
|
56 |
$records = Array('*');
|
57 |
$records = Array('*');
|
57 |
}
|
58 |
}
|
58 |
else {
|
59 |
else {
|
59 |
$records = self::rangeToList($_POST['range']);
|
60 |
$records = self::rangeToList(trim($_POST['range']));
|
60 |
}
|
61 |
}
|
61 |
$this->export($records, NULL, $params);
|
62 |
$this->export($records, NULL, $params);
|
62 |
exit;
|
63 |
exit;
|
63 |
}
|
64 |
}
|
Line 72... |
Line 73... |
72 |
$columnSlugs = array_keys($colonnes);
|
73 |
$columnSlugs = array_keys($colonnes);
|
73 |
$chercheur_observations = new RechercheObservation($this->config);
|
74 |
$chercheur_observations = new RechercheObservation($this->config);
|
Line 74... |
Line 75... |
74 |
|
75 |
|
Line 75... |
Line -... |
75 |
$objPHPExcel = new PHPExcel();
|
- |
|
76 |
|
76 |
$objPHPExcel = new PHPExcel();
|
77 |
|
77 |
|
78 |
// TODO: $params['part'] pour le multi-part
|
78 |
// TODO: $params['part'] pour le multi-part
|
79 |
$params['widget'] = isset($params['widget']) ? $params['widget'] : 'CEL';
|
79 |
$params['widget'] = isset($params['widget']) ? $params['widget'] : 'CEL';
|
80 |
// TODO: controleUtilisateur()
|
80 |
// TODO: controleUtilisateur()
|
81 |
if( /* REMOVE*/ true || ! $params['uid'] || ! $this->controleUtilisateur($params['uid'])) {
|
81 |
if(! $params['uid']) { // || ! $this->controleUtilisateur($params['uid'])) {
|
Line 82... |
Line 82... |
82 |
$params['uid'] = NULL;
|
82 |
$params['uid'] = NULL;
|
83 |
}
|
83 |
}
|
84 |
|
84 |
|
85 |
$criteres = Array();
|
85 |
$criteres = Array();
|
86 |
if(count($records) == 1 && $records[0] == '*') {
|
86 |
if(! $records || count($records) == 1 && $records[0] == '*') {
|
87 |
unset($criteres['raw']);
|
87 |
unset($criteres['raw']);
|
88 |
}
|
88 |
}
|
89 |
else {
|
89 |
else {
|
Line 90... |
Line 90... |
90 |
$criteres = Array('raw' =>
|
90 |
$criteres = Array('raw' =>
|
91 |
sprintf('id_observation IN (%s)', implode(',', $records)));
|
91 |
sprintf('id_observation IN (%s)', implode(',', $records)));
|
92 |
}
|
92 |
}
|
93 |
|
- |
|
94 |
$criteres['debut'] = isset($_GET['debut']) ? intval($_GET['debut']) : 0;
|
93 |
|
95 |
$criteres['limite'] = isset($_GET['limite']) ? intval($_GET['limite']) : 0;
|
94 |
$criteres['debut'] = isset($_GET['debut']) ? intval($_GET['debut']) : 0;
|
96 |
$observations = $chercheur_observations->rechercherObservations($params['uid'],
|
95 |
$criteres['limite'] = isset($_GET['limite']) ? intval($_GET['limite']) : 0;
|
- |
|
96 |
$observations = $chercheur_observations
|
97 |
$criteres,
|
97 |
->rechercherObservations($params['uid'], $criteres, $criteres['debut'], $criteres['limite'])
|
98 |
$criteres['debut'],
|
98 |
->get();
|
99 |
$criteres['limite']);
|
99 |
|
100 |
|
100 |
// debug //echo ($chercheur_observations->requete_selection_observations);
|
101 |
// XXX: malheureusement l'instance de JRest n'est pas accessible ici
|
101 |
// XXX: malheureusement l'instance de JRest n'est pas accessible ici
|
Line 134... |
Line 134... |
134 |
|
134 |
|
135 |
$row = 2;
|
135 |
$row = 2;
|
136 |
foreach ($observations as $obs) {
|
136 |
foreach ($observations as $obs) {
|
137 |
$colid = 0;
|
137 |
$colid = 0;
|
- |
|
138 |
foreach($colonnes as $slug => $colonne) {
|
138 |
foreach($colonnes as $slug => $colonne) {
|
139 |
// valeur direct depuis cel_obs ?
|
Line 139... |
Line 140... |
139 |
$valeur = $obs[$slug];
|
140 |
if(isset($obs[$slug])) $valeur = $obs[$slug];
|
140 |
|
141 |
|
141 |
// pré-processeur des champs
|
142 |
// pré-processeur de la champs
|
142 |
if(function_exists($colonne['function']))
|
143 |
if(function_exists($colonne['fonction'])) {
|
143 |
$valeur = $colonne['function']($valeur);
|
144 |
$valeur = $colonne['fonction']($valeur);
|
144 |
elseif(method_exists(__CLASS__, $colonne['function']))
|
145 |
} elseif(method_exists(__CLASS__, $colonne['fonction'])) {
|
145 |
$valeur = call_user_func(array(__CLASS__, $colonne['function']), $valeur);
|
146 |
$valeur = call_user_func(array(__CLASS__, $colonne['fonction']), $valeur);
|
- |
|
147 |
} elseif($colonne['fonction']) {
|
- |
|
148 |
die("méthode {$colonne['fonction']} introuvable");
|
- |
|
149 |
}
|
- |
|
150 |
// fonction pour obtenir des champs (étendus)
|
- |
|
151 |
elseif(function_exists($colonne['fonction_data'])) {
|
- |
|
152 |
$valeur = $colonne['fonction_data']($obs);
|
- |
|
153 |
}
|
146 |
elseif($colonne['function']) {
|
154 |
elseif(method_exists(__CLASS__, $colonne['fonction_data'])) {
|
Line -... |
Line 155... |
- |
|
155 |
$valeur = call_user_func(array(__CLASS__, $colonne['fonction_data']), $obs);
|
147 |
die("méthode {$colonne['function']} introuvable");
|
156 |
}
|
148 |
}
|
157 |
|
149 |
|
158 |
|
150 |
// // cette section devrait être vide:
|
159 |
// // cette section devrait être vide:
|
Line 173... |
Line 182... |
173 |
* @return un tableau trié, eg: 1,2,3,4,5,8,32,58,...,101
|
182 |
* @return un tableau trié, eg: 1,2,3,4,5,8,32,58,...,101
|
174 |
*/
|
183 |
*/
|
175 |
static function rangeToList($in = '') {
|
184 |
static function rangeToList($in = '') {
|
176 |
$inSets = explode(',', $in);
|
185 |
$inSets = explode(',', $in);
|
177 |
$outSets = array();
|
186 |
$outSets = array();
|
- |
|
187 |
|
178 |
foreach($inSets as $inSet) {
|
188 |
foreach($inSets as $inSet) {
|
179 |
list($start,$end) = explode('-', $inSet . '-' . $inSet);
|
189 |
list($start,$end) = explode('-', $inSet . '-' . $inSet);
|
180 |
$outSets = array_merge($outSets,range($start,$end));
|
190 |
$outSets = array_merge($outSets,range($start,$end));
|
181 |
}
|
191 |
}
|
182 |
$outSets = array_unique($outSets);
|
192 |
$outSets = array_unique($outSets);
|
Line 202... |
Line 212... |
202 |
$colonnes = Array();
|
212 |
$colonnes = Array();
|
Line 203... |
Line 213... |
203 |
|
213 |
|
204 |
if(isset($fieldSets['standard'])) {
|
214 |
if(isset($fieldSets['standard'])) {
|
205 |
$colonnes += Array(
|
215 |
$colonnes += Array(
|
206 |
'nom_sel' => self::GenColInfo('nom_sel', 'Espèce'),
|
216 |
'nom_sel' => self::GenColInfo('nom_sel', 'Espèce'),
|
207 |
'nom_sel_nn' => self::GenColInfo('nom_sel_nn', 'Numero nomenclatural'),
|
217 |
'nom_sel_nn' => self::GenColInfo('nom_sel_nn', 'Numéro nomenclatural'),
|
208 |
'nom_ret' => self::GenColInfo('nom_ret', 'Nom retenu'),
|
218 |
'nom_ret' => self::GenColInfo('nom_ret', 'Nom retenu'),
|
209 |
'nom_ret_nn' => self::GenColInfo('nom_ret_nn', 'Numero nomenclatural nom retenu'),
|
219 |
'nom_ret_nn' => self::GenColInfo('nom_ret_nn', 'Numéro nomenclatural nom retenu'),
|
210 |
'nt' => self::GenColInfo('nt', 'Numero taxonomique'),
|
220 |
'nt' => self::GenColInfo('nt', 'Numéro taxonomique'),
|
211 |
'famille' => self::GenColInfo('famille', 'Famille'),
|
221 |
'famille' => self::GenColInfo('famille', 'Famille'),
|
212 |
'nom_referentiel' => self::GenColInfo('nom_referentiel', 'Referentiel taxonomique'),
|
222 |
'nom_referentiel' => self::GenColInfo('nom_referentiel', 'Referentiel taxonomique'),
|
213 |
'zone_geo' => self::GenColInfo('zone_geo', 'Commune'),
|
223 |
'zone_geo' => self::GenColInfo('zone_geo', 'Commune'),
|
214 |
'ce_zone_geo' => self::GenColInfo('ce_zone_geo', 'Identifiant Commune', 0, 'convertirCodeZoneGeoVersDepartement'),
|
224 |
'ce_zone_geo' => self::GenColInfo('ce_zone_geo', 'Identifiant Commune', 0, 'convertirCodeZoneGeoVersDepartement'),
|
Line 217... |
Line 227... |
217 |
'station' => self::GenColInfo('station', 'Station'),
|
227 |
'station' => self::GenColInfo('station', 'Station'),
|
218 |
'milieu' => self::GenColInfo('milieu', 'Milieu'),
|
228 |
'milieu' => self::GenColInfo('milieu', 'Milieu'),
|
219 |
'commentaire' => self::GenColInfo('commentaire', 'Notes'),
|
229 |
'commentaire' => self::GenColInfo('commentaire', 'Notes'),
|
220 |
'latitude' => self::GenColInfo('latitude', 'Latitude', 1),
|
230 |
'latitude' => self::GenColInfo('latitude', 'Latitude', 1),
|
221 |
'longitude' => self::GenColInfo('longitude', 'Longitude', 1),
|
231 |
'longitude' => self::GenColInfo('longitude', 'Longitude', 1),
|
222 |
'geodatum' => self::GenColInfo('geodatum', 'Referentiel Geographique', 1),
|
232 |
'geodatum' => self::GenColInfo('geodatum', 'Référentiel Géographique', 1),
|
Line 223... |
Line 233... |
223 |
|
233 |
|
224 |
'ordre' => self::GenColInfo('ordre', 'Ordre', 1),
|
234 |
'ordre' => self::GenColInfo('ordre', 'Ordre', 1),
|
Line 225... |
Line 235... |
225 |
'id_observation' => self::GenColInfo('id_observation', 'Identifiant', 1),
|
235 |
'id_observation' => self::GenColInfo('id_observation', 'Identifiant', 1),
|
Line 230... |
Line 240... |
230 |
'date_modification' => self::GenColInfo('date_modification', 'Date Modification', 1),
|
240 |
'date_modification' => self::GenColInfo('date_modification', 'Date Modification', 1),
|
231 |
'date_transmission' => self::GenColInfo('date_transmission', 'Date Transmission', 1),
|
241 |
'date_transmission' => self::GenColInfo('date_transmission', 'Date Transmission', 1),
|
232 |
'abondance' => self::GenColInfo('abondance', 'Abondance', 1),
|
242 |
'abondance' => self::GenColInfo('abondance', 'Abondance', 1),
|
233 |
'certitude' => self::GenColInfo('certitude', 'Certitude', 1),
|
243 |
'certitude' => self::GenColInfo('certitude', 'Certitude', 1),
|
234 |
'phenologie' => self::GenColInfo('phenologie', 'Phénologie', 1),
|
244 |
'phenologie' => self::GenColInfo('phenologie', 'Phénologie', 1),
|
235 |
|
245 |
|
- |
|
246 |
//'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun')
|
- |
|
247 |
//'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v2')
|
- |
|
248 |
//'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v3')
|
236 |
);
|
249 |
);
|
237 |
}
|
250 |
}
|
Line 238... |
Line 251... |
238 |
|
251 |
|
239 |
return $colonnes;
|
252 |
return $colonnes;
|
Line 240... |
Line 253... |
240 |
}
|
253 |
}
|
241 |
|
254 |
|
242 |
/*
|
255 |
/*
|
243 |
* Wrapper générant un tableau associatif:
|
256 |
* Wrapper générant un tableau associatif:
|
244 |
* @param $is_extra: défini si la colonne est extra (auquelle une bordure bleue entoure son nom dans la première ligne
|
257 |
* @param $is_extra: défini si la colonne est extra (auquelle une bordure bleue entoure son nom dans la première ligne
|
- |
|
258 |
* @param $fonction (optionnel): un nom d'un fonction de préprocessing
|
- |
|
259 |
* $fonction doit prendre comme seul argument la valeur d'origine et retourner la valeur transformée
|
- |
|
260 |
* @param $fonction_data (optionnel): une *méthode* d'obtention de donnée
|
- |
|
261 |
* $fonction_data doit prendre comme premier argument les champs de l'enregistrement existant
|
245 |
* @param $function: un nom optionnel d'un fonction de préprocessing
|
262 |
* $fonction_data doit retourner une valeur
|
246 |
* $function doit prendre comme argument la valeur et retourner la valeur transformée
|
263 |
|
247 |
*/
|
264 |
*/
|
248 |
static function GenColInfo($slug, $nom, $is_extra = 0, $function = NULL) {
|
265 |
static function GenColInfo($slug, $nom, $is_extra = 0, $fonction = NULL, $fonction_data = NULL) {
|
249 |
return Array('slug' => $slug,
|
266 |
return Array('slug' => $slug,
|
250 |
'nom' => $nom,
|
267 |
'nom' => $nom,
|
- |
|
268 |
'extra' => $is_extra ? 1 : 0,
|
251 |
'extra' => $is_extra ? 1 : 0,
|
269 |
'fonction' => $fonction,
|
252 |
'function' => $function
|
270 |
'fonction_data' => $fonction_data
|
Line 253... |
Line 271... |
253 |
);
|
271 |
);
|
254 |
}
|
272 |
}
|
255 |
|
273 |
|
256 |
protected function formaterDate($date_heure_mysql, $format = NULL) {
|
274 |
protected function formaterDate($date_heure_mysql, $format = NULL) {
|
257 |
if (!$date_heure_mysql || $date_heure_mysql == "0000-00-00 00:00:00") return "00/00/0000";
|
275 |
if (!$date_heure_mysql || $date_heure_mysql == "0000-00-00 00:00:00") return "00/00/0000";
|
258 |
$timestamp = DateTime::createFromFormat("Y-m-d H:i:s", $date_heure_mysql);
|
276 |
$timestamp = DateTime::createFromFormat("Y-m-d H:i:s", $date_heure_mysql)->getTimestamp();
|
259 |
if(!$timestamp) return "00/00/0000";
|
277 |
if(!$timestamp) return "00/00/0000";
|
260 |
// TODO: les widget ne font malheureusement pas usage de l'heure dans le CEL
|
278 |
// TODO: les widget ne font malheureusement pas usage de l'heure dans le CEL
|
261 |
$date_formatee = strftime('%A %d %B %Y', $timestamp->getTimestamp());
|
279 |
$date_formatee = strftime('%A %d %B %Y', $timestamp);
|
262 |
if(!$date_formatee) return "00/00/0000";
|
280 |
if(!$date_formatee) return "00/00/0000";
|
263 |
return $date_formatee;
|
281 |
return $date_formatee;
|