106 |
aurelien |
1 |
<?php
|
118 |
jpm |
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Classe implémentant l'API d'eFlore Images pour le projet CEL.
|
|
|
5 |
*
|
|
|
6 |
* @see http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=EfloreApi01Images
|
|
|
7 |
*
|
|
|
8 |
* @package eFlore/services
|
|
|
9 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
10 |
* @author Aurélien PERONNET <aurelien@tela-botanica.org>
|
|
|
11 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
12 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
13 |
* @version 1.0
|
|
|
14 |
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
|
|
|
15 |
*/
|
|
|
16 |
// TODO : Config et Outils sont des classes statiques qui doivent poser des pb pour les tests...
|
539 |
aurelien |
17 |
class Images extends Commun {
|
116 |
jpm |
18 |
|
539 |
aurelien |
19 |
protected $parametres = array();
|
|
|
20 |
protected $ressources = array();
|
106 |
aurelien |
21 |
private $Bdd;
|
116 |
jpm |
22 |
|
138 |
jpm |
23 |
const CODE_REFTAX_DEFAUT = 'bdtfx';
|
|
|
24 |
const TPL_URL_IMG = 'http://www.tela-botanica.org/appli:cel-img:%s.jpg';
|
|
|
25 |
const TAILLE_IMG_DEFAUT = 'M';
|
|
|
26 |
const MIME_JPEG = 'image/jpeg';
|
|
|
27 |
const MIME_JSON = 'application/json';
|
140 |
jpm |
28 |
|
|
|
29 |
private $config = array();
|
|
|
30 |
private $cheminImagesBase = '';
|
138 |
jpm |
31 |
private $formats_supportes = array(self::MIME_JPEG, self::MIME_JSON);
|
330 |
delphine |
32 |
private $tris_supportes = array('date');
|
538 |
aurelien |
33 |
private $retour_champs = array('determination.nom_sci' => 'nom_sel', 'determination.nom_sci.code' => 'nom_sel_nn',
|
378 |
delphine |
34 |
'station.lieudit' => 'lieudit', 'station', 'milieu');
|
638 |
aurelien |
35 |
private $code_ref_tax_demande = null;
|
116 |
jpm |
36 |
private $ref_tax_demande = array();
|
138 |
jpm |
37 |
private $infosImages = array();
|
|
|
38 |
private $nbreImages = 0;
|
|
|
39 |
private $Utilisateurs = null;
|
140 |
jpm |
40 |
private $UrlNavigation = null;
|
116 |
jpm |
41 |
|
140 |
jpm |
42 |
public function __construct(Bdd $bdd = null, Array $config = null, Utilisateurs $utilisateurs = null, Url $url = null) {
|
|
|
43 |
$this->config = is_null($config) ? Config::get('Images') : $config;
|
138 |
jpm |
44 |
$this->Bdd = is_null($bdd) ? new Bdd() : $bdd;
|
|
|
45 |
$this->Utilisateurs = is_null($utilisateurs) ? new Utilisateurs() : $utilisateurs;
|
140 |
jpm |
46 |
$this->UrlNavigation = is_null($url) ? new Url($this->config['urlService']) : $url;
|
|
|
47 |
$this->cheminImagesBase = $this->config['chemin'];
|
116 |
jpm |
48 |
}
|
|
|
49 |
|
106 |
aurelien |
50 |
public function consulter($ressources, $parametres) {
|
140 |
jpm |
51 |
//$tpsDebut = microtime(true);
|
116 |
jpm |
52 |
$this->parametres = $parametres;
|
|
|
53 |
$this->ressources = $ressources;
|
|
|
54 |
|
|
|
55 |
$this->definirValeurParDefautDesParametres();
|
|
|
56 |
$this->verifierParametres();
|
|
|
57 |
|
|
|
58 |
$resultat = new ResultatService();
|
138 |
jpm |
59 |
if ($this->parametres['retour'] == self::MIME_JPEG) {
|
378 |
delphine |
60 |
if ($this->parametres['retour.tri'] == 'date') { // recherche la plus vieille image du CEL
|
330 |
delphine |
61 |
$id_image_a_renvoyer = $this->obtenirIdPremiereImage();
|
|
|
62 |
} else {
|
|
|
63 |
$id_image_a_renvoyer = $this->obtenirIdImageAuHasard();
|
|
|
64 |
}
|
138 |
jpm |
65 |
$resultat->corps = $this->recupererImageBinaire($id_image_a_renvoyer);
|
|
|
66 |
} else if ($this->parametres['retour'] == self::MIME_JSON) {
|
375 |
delphine |
67 |
if (isset($this->ressources[0])) {
|
|
|
68 |
$this->chargerInfosImage();
|
386 |
jpm |
69 |
$this->extraireIdentitesAuteurs();
|
375 |
delphine |
70 |
$resultat->corps = $this->formaterInfosImage($this->infosImages[0]);
|
|
|
71 |
} else {
|
|
|
72 |
$this->chargerListeImages();
|
|
|
73 |
$this->chargerNbreImagesTotal();
|
|
|
74 |
$resultat->corps = $this->formaterListeImages();
|
|
|
75 |
}
|
138 |
jpm |
76 |
}
|
|
|
77 |
$resultat->mime = $this->parametres['retour'];
|
|
|
78 |
|
116 |
jpm |
79 |
return $resultat;
|
106 |
aurelien |
80 |
}
|
375 |
delphine |
81 |
//+---------------------------FONCTION D'ANALYSE DES PARAMETRES---------------------------------------------------------+
|
116 |
jpm |
82 |
private function definirValeurParDefautDesParametres() {
|
|
|
83 |
if (isset($this->parametres['retour']) == false) {
|
138 |
jpm |
84 |
$this->parametres['retour'] = self::MIME_JSON;
|
106 |
aurelien |
85 |
}
|
116 |
jpm |
86 |
if (isset($this->parametres['retour.format']) == false) {
|
|
|
87 |
$this->parametres['retour.format'] = 'M';
|
106 |
aurelien |
88 |
}
|
138 |
jpm |
89 |
if (isset($this->parametres['navigation.depart']) == false) {
|
|
|
90 |
$this->parametres['navigation.depart'] = 0;
|
|
|
91 |
}
|
|
|
92 |
if (isset($this->parametres['navigation.limite']) == false) {
|
|
|
93 |
$this->parametres['navigation.limite'] = 100;
|
|
|
94 |
}
|
638 |
aurelien |
95 |
if (isset($this->parametres['referentiel']) == false) {
|
|
|
96 |
$this->parametres['referentiel'] = self::CODE_REFTAX_DEFAUT;
|
|
|
97 |
}
|
106 |
aurelien |
98 |
}
|
116 |
jpm |
99 |
|
|
|
100 |
private function verifierParametres() {
|
|
|
101 |
$erreurs = array();
|
|
|
102 |
|
375 |
delphine |
103 |
if (!isset($this->ressources[0])) {
|
|
|
104 |
if (isset($this->parametres['masque.nn']) == false) {
|
|
|
105 |
$erreurs[] = "Le paramètre masque.nn est obligatoire.";
|
|
|
106 |
} else {
|
|
|
107 |
$this->analyserMasqueNn();
|
|
|
108 |
if ($this->verifierMasqueNnAutorisePourRetourJPEG() == false) {
|
|
|
109 |
$erreurs[] = "Le paramètre masque.nn peut contenir une seule valeur numérique pour l'instant pour le format de retour image/jpeg.";
|
|
|
110 |
} else if ($this->verifierValeurParametreMasqueNn() == false) {
|
|
|
111 |
$erreurs[] = "Le paramètre masque.nn est mal formé.";
|
|
|
112 |
}
|
106 |
aurelien |
113 |
}
|
|
|
114 |
}
|
116 |
jpm |
115 |
if (isset($this->parametres['retour']) == false) {
|
|
|
116 |
$erreurs[] = "Le paramètre type de retour 'retour' est obligatoire.";
|
106 |
aurelien |
117 |
}
|
116 |
jpm |
118 |
if ($this->verifierValeurParametreRetour() == false) {
|
|
|
119 |
$erreurs[] = "Le type de retour '{$this->parametres['retour']}' n'est pas supporté";
|
106 |
aurelien |
120 |
}
|
116 |
jpm |
121 |
if (isset($this->parametres['retour.format']) == false) {
|
|
|
122 |
$erreurs[] = "Le paramètre de format de retour 'retour.format' est obligatoire.";
|
106 |
aurelien |
123 |
}
|
116 |
jpm |
124 |
if ($this->verifierValeurParametreFormat() == false) {
|
|
|
125 |
$erreurs[] = "Le type de format '{$this->parametres['retour.format']}' n'est pas supporté";
|
|
|
126 |
}
|
330 |
delphine |
127 |
if (isset($this->parametres['retour.tri'])){
|
|
|
128 |
if ($this->verifierValeurParametreTri() == false) {
|
|
|
129 |
$erreurs[] = "Le type de tri '{$this->parametres['retour.tri']}' n'est pas supporté";
|
|
|
130 |
}
|
|
|
131 |
}
|
386 |
jpm |
132 |
|
378 |
delphine |
133 |
if (isset($this->parametres['retour.champs'])){
|
|
|
134 |
if ($this->verifierValeurParametreRetourChamps() == false) {
|
|
|
135 |
$erreurs[] = "Le champs '{$this->parametres['retour.champs']}' n'existe pas";
|
|
|
136 |
}
|
|
|
137 |
}
|
386 |
jpm |
138 |
|
138 |
jpm |
139 |
if ($this->verifierValeurParametreNavigationDepart() == false) {
|
|
|
140 |
$erreurs[] = "Le paramètre 'navigation.depart' doit possèder un valeur numérique.";
|
|
|
141 |
}
|
|
|
142 |
if ($this->verifierValeurParametreNavigationLimite() == false) {
|
|
|
143 |
$erreurs[] = "Le paramètre 'navigation.limite' doit possèder un valeur numérique supérieure à 0.";
|
|
|
144 |
}
|
116 |
jpm |
145 |
|
|
|
146 |
if (count($erreurs) > 0) {
|
|
|
147 |
$message = implode('<br />', $erreurs);
|
|
|
148 |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
|
|
|
149 |
throw new Exception($message, $code);
|
|
|
150 |
}
|
106 |
aurelien |
151 |
}
|
116 |
jpm |
152 |
|
162 |
jpm |
153 |
private function verifierMasqueNnAutorisePourRetourJPEG() {
|
138 |
jpm |
154 |
$ok = true;
|
|
|
155 |
$masque = $this->parametres['masque.nn'];
|
|
|
156 |
$retour = $this->parametres['retour'];
|
162 |
jpm |
157 |
|
138 |
jpm |
158 |
if ($retour == self::MIME_JPEG) {
|
|
|
159 |
$ok = is_numeric($masque) ? true : false;
|
|
|
160 |
}
|
|
|
161 |
return $ok;
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
private function verifierValeurParametreMasqueNn() {
|
|
|
165 |
$nn = $this->parametres['masque.nn'];
|
|
|
166 |
$projetPattern = '(?:(?:[A-Z0-9]+:)?(?:[0-9]+,)*[0-9]+)';
|
162 |
jpm |
167 |
$patternComplet = "/^$projetPattern(?:;$projetPattern)*$/i";
|
138 |
jpm |
168 |
$ok = preg_match($patternComplet, $nn) ? true : false;
|
|
|
169 |
return $ok;
|
|
|
170 |
}
|
|
|
171 |
|
116 |
jpm |
172 |
private function verifierValeurParametreRetour() {
|
|
|
173 |
return in_array($this->parametres['retour'], $this->formats_supportes);
|
106 |
aurelien |
174 |
}
|
116 |
jpm |
175 |
|
|
|
176 |
private function verifierValeurParametreFormat() {
|
118 |
jpm |
177 |
$formats = Outils::recupererTableauConfig('Images.formats');
|
116 |
jpm |
178 |
$ok = array_key_exists($this->parametres['retour.format'], $formats);
|
|
|
179 |
return $ok;
|
106 |
aurelien |
180 |
}
|
377 |
jpm |
181 |
|
330 |
delphine |
182 |
private function verifierValeurParametreTri() {
|
|
|
183 |
return in_array($this->parametres['retour.tri'], $this->tris_supportes);
|
|
|
184 |
}
|
386 |
jpm |
185 |
|
378 |
delphine |
186 |
private function verifierValeurParametreRetourChamps() {
|
|
|
187 |
$ok = false;
|
|
|
188 |
$liste_champs = preg_split(',', $this->parametres['retour.champs']);
|
|
|
189 |
foreach ($liste_champs as $champs) {
|
|
|
190 |
$ok[$champs] = array_key_exists($champs, $this->retour_champs);
|
|
|
191 |
}
|
|
|
192 |
return $ok;
|
|
|
193 |
}
|
116 |
jpm |
194 |
|
138 |
jpm |
195 |
private function verifierValeurParametreNavigationDepart() {
|
|
|
196 |
$depart = $this->parametres['navigation.depart'];
|
|
|
197 |
$ok = is_numeric($depart) ? true : false;
|
116 |
jpm |
198 |
return $ok;
|
106 |
aurelien |
199 |
}
|
116 |
jpm |
200 |
|
138 |
jpm |
201 |
private function verifierValeurParametreNavigationLimite() {
|
|
|
202 |
$limite = $this->parametres['navigation.limite'];
|
|
|
203 |
$ok = (is_numeric($limite) && $limite != 0) ? true : false;
|
116 |
jpm |
204 |
return $ok;
|
106 |
aurelien |
205 |
}
|
116 |
jpm |
206 |
|
|
|
207 |
private function analyserMasqueNn() {
|
|
|
208 |
$nn = $this->parametres['masque.nn'];
|
142 |
jpm |
209 |
if (preg_match('/^[0-9]+$/', $nn)) {
|
638 |
aurelien |
210 |
$this->ref_tax_demande[$this->parametres['referentiel']][] = $nn;
|
106 |
aurelien |
211 |
} else {
|
116 |
jpm |
212 |
// ceci contient potentiellement des formes ref_tax1:nn1,nn2;ref_tax2:nn3,nn4
|
|
|
213 |
$projetsListeEtNumNoms = explode(';', $nn);
|
|
|
214 |
if (count($projetsListeEtNumNoms) > 0) {
|
|
|
215 |
foreach ($projetsListeEtNumNoms as $projetEtNumNoms) {
|
638 |
aurelien |
216 |
$projetEtNumNoms = (strpos($projetEtNumNoms, ':')) ? $projetEtNumNoms : $this->parametres['referentiel'].':'.$projetEtNumNoms;
|
116 |
jpm |
217 |
list($projet, $numNoms) = explode(':', $projetEtNumNoms);
|
|
|
218 |
$this->ref_tax_demande[$projet] = explode(',', $numNoms);
|
106 |
aurelien |
219 |
}
|
|
|
220 |
}
|
|
|
221 |
}
|
|
|
222 |
}
|
116 |
jpm |
223 |
|
377 |
jpm |
224 |
|
375 |
delphine |
225 |
//+---------------------------------------- REQUETES ---------------------------------------------------------------+
|
138 |
jpm |
226 |
private function obtenirIdImageAuHasard() {
|
638 |
aurelien |
227 |
$refTax = $this->parametres['referentiel'];
|
142 |
jpm |
228 |
$numNom = $this->Bdd->proteger($this->ref_tax_demande[$refTax][0]);
|
116 |
jpm |
229 |
|
538 |
aurelien |
230 |
$requete = 'SELECT coi.id_image AS id_image '.
|
116 |
jpm |
231 |
'FROM cel_obs_images AS coi '.
|
538 |
aurelien |
232 |
' LEFT JOIN cel_obs AS co '.
|
|
|
233 |
'ON (coi.id_observation = co.id_observation) '.
|
116 |
jpm |
234 |
'WHERE ci.transmission = 1 '.
|
538 |
aurelien |
235 |
" AND ci.nom_ret_nn IN ($numNom)";
|
638 |
aurelien |
236 |
" AND co.nom_referentiel = ".$this->Bdd->proteger($refTax);
|
116 |
jpm |
237 |
|
|
|
238 |
$resultat = $this->Bdd->recupererTous($requete);
|
|
|
239 |
|
|
|
240 |
if (!is_array($resultat) || count($resultat) <= 0) {
|
126 |
jpm |
241 |
$message = "Aucune image ne correspond au numéro numenclatural $refTax:$numNom";
|
116 |
jpm |
242 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
243 |
throw new Exception($message, $code);
|
106 |
aurelien |
244 |
}
|
116 |
jpm |
245 |
|
|
|
246 |
$id_image_hasard = $resultat[array_rand($resultat)]['id_image'];
|
106 |
aurelien |
247 |
return $id_image_hasard;
|
|
|
248 |
}
|
377 |
jpm |
249 |
|
330 |
delphine |
250 |
private function obtenirIdPremiereImage() {
|
638 |
aurelien |
251 |
$refTax = $this->parametres['referentiel'];
|
330 |
delphine |
252 |
$numNom = $this->Bdd->proteger($this->ref_tax_demande[$refTax][0]);
|
538 |
aurelien |
253 |
$requete = 'SELECT ci.id_image AS id_image '.
|
330 |
delphine |
254 |
'FROM cel_images AS ci'.
|
|
|
255 |
' LEFT JOIN cel_obs_images AS coi '.
|
538 |
aurelien |
256 |
' ON (coi.id_image = ci.id_image) '.
|
|
|
257 |
' LEFT JOIN cel_obs AS co '.
|
|
|
258 |
' ON (coi.id_observation = co.id_observation) '.
|
330 |
delphine |
259 |
'WHERE co.transmission = 1 '.
|
538 |
aurelien |
260 |
" AND co.nom_ret_nn IN ($numNom) ".
|
626 |
aurelien |
261 |
' AND ci.date_prise_de_vue != "0000-00-00" ORDER BY ci.date_prise_de_vue ASC '.
|
638 |
aurelien |
262 |
' AND co.nom_referentiel LIKE '.$this->proteger($refTax.'%').' '.
|
626 |
aurelien |
263 |
'LIMIT 1';
|
377 |
jpm |
264 |
|
330 |
delphine |
265 |
$resultat = $this->Bdd->recupererTous($requete);
|
377 |
jpm |
266 |
|
330 |
delphine |
267 |
if (!is_array($resultat) || count($resultat) <= 0) {
|
|
|
268 |
$message = "Aucune image ne correspond au numéro numenclatural $refTax:$numNom";
|
|
|
269 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
270 |
throw new Exception($message, $code);
|
|
|
271 |
}
|
377 |
jpm |
272 |
|
330 |
delphine |
273 |
$id_image_hasard = $resultat[0]['id_image'];
|
|
|
274 |
return $id_image_hasard;
|
|
|
275 |
}
|
377 |
jpm |
276 |
|
375 |
delphine |
277 |
private function chargerInfosImage() {
|
|
|
278 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS '.
|
638 |
aurelien |
279 |
' ci.id_image AS id_img, co.date_observation AS date, '.
|
538 |
aurelien |
280 |
' co.id_observation AS id_obs, '.
|
539 |
aurelien |
281 |
' ci.courriel_utilisateur AS utilisateur_courriel, '.
|
538 |
aurelien |
282 |
' nom_sel, nom_sel_nn, '.
|
|
|
283 |
' zone_geo, ce_zone_geo, lieudit, station, milieu '.
|
375 |
delphine |
284 |
'FROM cel_images AS ci'.
|
|
|
285 |
' LEFT JOIN cel_obs_images AS coi '.
|
539 |
aurelien |
286 |
' ON (coi.id_image = ci.id_image) '.
|
538 |
aurelien |
287 |
' LEFT JOIN cel_obs AS co '.
|
|
|
288 |
' ON (coi.id_observation = co.id_observation) '.
|
|
|
289 |
'WHERE ci.id_image = '.$this->ressources[0];
|
377 |
jpm |
290 |
|
375 |
delphine |
291 |
$this->infosImages = $this->Bdd->recupererTous($requete);
|
|
|
292 |
}
|
116 |
jpm |
293 |
|
375 |
delphine |
294 |
private function chargerListeImages() {
|
638 |
aurelien |
295 |
$refTax = $this->parametres['referentiel'];
|
375 |
delphine |
296 |
$numNomListe = implode(',', $this->ref_tax_demande[$refTax]);
|
|
|
297 |
$depart = $this->parametres['navigation.depart'];
|
|
|
298 |
$limite = $this->parametres['navigation.limite'];
|
377 |
jpm |
299 |
|
375 |
delphine |
300 |
//TODO: modifier la requete lors du passage à la nouvelle base de données pour faire quelque chose
|
386 |
jpm |
301 |
// du numéro nomenclatural + modifier les champs appelés pour le nouveau format
|
375 |
delphine |
302 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS '.
|
538 |
aurelien |
303 |
' co.id_observation AS id_obs, co.courriel_utilisateur AS utilisateur_courriel, co.zone_geo, co.ce_zone_geo, '.
|
|
|
304 |
' co.nom_sel, co.nom_sel_nn, '.
|
638 |
aurelien |
305 |
' ci.id_image AS id_img, co.date_observation AS date '.
|
386 |
jpm |
306 |
(isset($this->parametres['retour.champs']) ? ', '.$this->parametres['retour.champs'] : '').
|
|
|
307 |
'FROM cel_images AS ci'.
|
|
|
308 |
' LEFT JOIN cel_obs_images AS coi '.
|
538 |
aurelien |
309 |
' ON (coi.id_image = ci.id_image) '.
|
|
|
310 |
' LEFT JOIN cel_obs AS co '.
|
|
|
311 |
' ON (coi.id_observation = co.id_observation) '.
|
386 |
jpm |
312 |
$this->formerRequeteConditions($numNomListe).' '.
|
|
|
313 |
'GROUP BY id_img '.
|
|
|
314 |
$this->formerRequeteTri().
|
|
|
315 |
"LIMIT $depart,$limite ";
|
377 |
jpm |
316 |
|
375 |
delphine |
317 |
$this->infosImages = $this->Bdd->recupererTous($requete);
|
|
|
318 |
}
|
386 |
jpm |
319 |
|
375 |
delphine |
320 |
private function formerRequeteConditions($numNomListe) {
|
638 |
aurelien |
321 |
$refTax = $this->parametres['referentiel'];
|
538 |
aurelien |
322 |
$where[] = " co.transmission = 1 AND co.nom_ret_nn IN ($numNomListe) ";
|
638 |
aurelien |
323 |
$where[] = " co.nom_referentiel LIKE ".$this->Bdd->proteger($refTax."%").' ';
|
|
|
324 |
|
375 |
delphine |
325 |
return ' WHERE '.implode(' AND ', $where);
|
|
|
326 |
}
|
377 |
jpm |
327 |
|
375 |
delphine |
328 |
private function formerRequeteTri() {
|
386 |
jpm |
329 |
$order = '';
|
375 |
delphine |
330 |
if (isset($this->parametres['retour.tri']) && $this->parametres['retour.tri'] == 'date') {
|
638 |
aurelien |
331 |
$order = ' ORDER BY co.date_observation ASC ';
|
375 |
delphine |
332 |
}
|
|
|
333 |
return $order;
|
|
|
334 |
}
|
377 |
jpm |
335 |
|
375 |
delphine |
336 |
private function chargerNbreImagesTotal() {
|
|
|
337 |
$requete = 'SELECT FOUND_ROWS() AS nbre ';
|
|
|
338 |
$resultats = $this->Bdd->recuperer($requete);
|
|
|
339 |
$this->nbreImages = (int) $resultats['nbre'];
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
//+---------------------------------------CHEMIN ET CONVERSION--------------------------------------------------------+
|
116 |
jpm |
343 |
private function recupererImageBinaire($id_image) {
|
|
|
344 |
$image = '';
|
|
|
345 |
$chemin = $this->obtenirCheminImage($id_image);
|
118 |
jpm |
346 |
$image = file_get_contents($chemin);
|
|
|
347 |
if ($image === false) {
|
116 |
jpm |
348 |
$message = "L'image demandée est introuvable sur le serveur : $chemin";
|
|
|
349 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
350 |
throw new Exception($message, $code);
|
106 |
aurelien |
351 |
}
|
116 |
jpm |
352 |
return $image;
|
106 |
aurelien |
353 |
}
|
116 |
jpm |
354 |
|
127 |
jpm |
355 |
private function obtenirCheminImage($idImage) {
|
116 |
jpm |
356 |
$nom = $this->convertirIdImageVersNomFichier($idImage);
|
|
|
357 |
$dossier = $this->convertirIdImageVersChemin($idImage);
|
106 |
aurelien |
358 |
return $dossier.'/'.$nom;
|
|
|
359 |
}
|
116 |
jpm |
360 |
|
127 |
jpm |
361 |
private function convertirIdImageVersNomFichier($idImage) {
|
116 |
jpm |
362 |
$codeImage = $this->construireCodeImage($idImage);
|
|
|
363 |
$nom_fichier = $codeImage.'.jpg';
|
106 |
aurelien |
364 |
return $nom_fichier;
|
|
|
365 |
}
|
116 |
jpm |
366 |
|
|
|
367 |
private function convertirIdImageVersChemin($idImage) {
|
|
|
368 |
$codeImage = $this->construireCodeImage($idImage);
|
|
|
369 |
list($dossierNiveau1, $dossierNiveau2, $idFichier, $format) = explode('_', $codeImage);
|
140 |
jpm |
370 |
$chemin_sur_serveur = $this->cheminImagesBase.'/'.$dossierNiveau1.'/'.$dossierNiveau2.'/'.$format;
|
116 |
jpm |
371 |
return $chemin_sur_serveur;
|
106 |
aurelien |
372 |
}
|
116 |
jpm |
373 |
|
|
|
374 |
private function construireCodeImage($idImage) {
|
|
|
375 |
$codeImage = sprintf('%09s', $idImage);
|
|
|
376 |
$codeImage = wordwrap($codeImage, 3, '_', true);
|
|
|
377 |
$format = $this->parametres['retour.format'];
|
|
|
378 |
$codeImage .= '_'.$format;
|
|
|
379 |
return $codeImage;
|
106 |
aurelien |
380 |
}
|
377 |
jpm |
381 |
|
375 |
delphine |
382 |
//+------------------------------------FORMATAGE LISTE----------------------------------------------------------------+
|
138 |
jpm |
383 |
private function formaterListeImages() {
|
|
|
384 |
$entete = $this->construireEntete();
|
|
|
385 |
$resultats = $this->construireResultats();
|
|
|
386 |
|
|
|
387 |
$resultat = array('entete' => $entete, 'resultats' => $resultats);
|
|
|
388 |
return $resultat;
|
|
|
389 |
}
|
|
|
390 |
|
|
|
391 |
private function construireEntete() {
|
|
|
392 |
$entete = array('masque' => '', 'depart' => 0, 'limite' => 100, 'total' => 0);
|
|
|
393 |
|
|
|
394 |
$entete['masque'] = $this->recupererMasque();
|
|
|
395 |
$entete['depart'] = (int) $this->parametres['navigation.depart'];
|
|
|
396 |
$entete['limite'] = (int) $this->parametres['navigation.limite'];
|
|
|
397 |
$entete['total'] = $this->nbreImages;
|
|
|
398 |
if ($hrefPrecedent = $this->recupererHrefPrecedent()) {
|
|
|
399 |
$entete['href.precedent'] = $hrefPrecedent;
|
|
|
400 |
}
|
|
|
401 |
if ($hrefSuivant = $this->recupererHrefSuivant()) {
|
|
|
402 |
$entete['href.suivant'] = $hrefSuivant;
|
|
|
403 |
}
|
|
|
404 |
return $entete;
|
|
|
405 |
}
|
|
|
406 |
|
|
|
407 |
private function recupererMasque() {
|
|
|
408 |
$masqueEntete = '';
|
|
|
409 |
if ($masqueNn = $this->parametres['masque.nn']) {
|
|
|
410 |
$masqueEntete = "nn=$masqueNn";
|
|
|
411 |
}
|
|
|
412 |
return $masqueEntete;
|
|
|
413 |
}
|
|
|
414 |
|
|
|
415 |
private function recupererHrefPrecedent() {
|
|
|
416 |
$departActuel = $this->parametres['navigation.depart'];
|
|
|
417 |
$limite = $this->parametres['navigation.limite'];
|
|
|
418 |
$departPrecedent = $departActuel - $limite;
|
|
|
419 |
$url = null;
|
|
|
420 |
if ($departPrecedent >= 0) {
|
|
|
421 |
$url = $this->obtenirUrlNavigation($departPrecedent, $limite);
|
|
|
422 |
}
|
|
|
423 |
return $url;
|
|
|
424 |
}
|
|
|
425 |
|
|
|
426 |
private function recupererHrefSuivant() {
|
|
|
427 |
$departActuel = $this->parametres['navigation.depart'];
|
|
|
428 |
$limite = $this->parametres['navigation.limite'];
|
|
|
429 |
$departSuivant = $departActuel + $limite;
|
|
|
430 |
$url = null;
|
|
|
431 |
if ($departSuivant < $this->nbreImages) {
|
|
|
432 |
$url = $this->obtenirUrlNavigation($departSuivant, $limite);
|
|
|
433 |
}
|
|
|
434 |
return $url;
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
private function obtenirUrlNavigation($depart, $limite) {
|
|
|
438 |
$parametres = array(
|
|
|
439 |
'navigation.depart' => $depart,
|
|
|
440 |
'navigation.limite' => $limite);
|
|
|
441 |
if (isset($this->parametres['masque.nn'])) {
|
|
|
442 |
$parametres['masque.nn'] = $this->parametres['masque.nn'];
|
|
|
443 |
}
|
140 |
jpm |
444 |
$this->UrlNavigation->setRequete($parametres);
|
|
|
445 |
$url = $this->UrlNavigation->getURL();
|
138 |
jpm |
446 |
return $url;
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
private function construireResultats() {
|
|
|
450 |
$resultats = array();
|
386 |
jpm |
451 |
$this->extraireIdentitesAuteurs();
|
138 |
jpm |
452 |
foreach ($this->infosImages as $img) {
|
375 |
delphine |
453 |
$info = $this->formaterInfosImage($img);
|
142 |
jpm |
454 |
$id = $img['id_img'];
|
378 |
delphine |
455 |
$info['href'] = $this->config['urlService'].'/'.$id;
|
138 |
jpm |
456 |
if (!isset($resultats[$id])) {
|
|
|
457 |
$resultats[$id] = $info;
|
|
|
458 |
} else {
|
|
|
459 |
throw new Exception("Double : $id");
|
|
|
460 |
}
|
|
|
461 |
}
|
|
|
462 |
return $resultats;
|
|
|
463 |
}
|
|
|
464 |
|
375 |
delphine |
465 |
private function formaterInfosImage($img) {
|
|
|
466 |
$info = array();
|
|
|
467 |
$info['date'] = $img['date'];
|
|
|
468 |
$info['mime'] = self::MIME_JPEG;
|
386 |
jpm |
469 |
$info['auteur.libelle'] = $this->Utilisateurs->getIntitule($img['utilisateur_courriel']);
|
|
|
470 |
$info['auteur.id'] = $this->Utilisateurs->getId($img['utilisateur_courriel']);
|
375 |
delphine |
471 |
$info['binaire.href'] = $this->formaterUrlImage($img);
|
393 |
jpm |
472 |
$info['observation.id'] = $img['id_obs'];
|
378 |
delphine |
473 |
if (isset($img['nom_sel'])) {
|
|
|
474 |
$info['determination.libelle'] = $this->formaterDetermination($img);
|
|
|
475 |
$info['determination.nom_sci'] = $img['nom_sel'];
|
|
|
476 |
$info['determination.nom_sci.code'] = $this->formaterNomSciCode($img);
|
|
|
477 |
}
|
375 |
delphine |
478 |
$info = array_merge($info, $this->formaterStation($img));
|
|
|
479 |
return $info;
|
|
|
480 |
}
|
377 |
jpm |
481 |
|
386 |
jpm |
482 |
private function extraireIdentitesAuteurs() {
|
138 |
jpm |
483 |
$courriels = array();
|
|
|
484 |
foreach ($this->infosImages as $img) {
|
|
|
485 |
$courriels[] = $img['utilisateur_courriel'];
|
|
|
486 |
}
|
386 |
jpm |
487 |
$this->Utilisateurs->setCourriels($courriels);
|
|
|
488 |
$this->Utilisateurs->chargerIdentites();
|
138 |
jpm |
489 |
}
|
|
|
490 |
|
|
|
491 |
private function formaterUrlImage($infos) {
|
143 |
jpm |
492 |
$format = $this->parametres['retour.format'];
|
138 |
jpm |
493 |
$id = sprintf('%09s', $infos['id_img']).$format;
|
|
|
494 |
$url = sprintf(self::TPL_URL_IMG, $id);
|
|
|
495 |
return $url;
|
|
|
496 |
}
|
|
|
497 |
|
|
|
498 |
private function formaterDetermination($infos) {
|
386 |
jpm |
499 |
$auteur = $this->Utilisateurs->getIntitule($infos['utilisateur_courriel']);
|
|
|
500 |
return $infos['nom_sel']."[Dét. : $auteur]";
|
138 |
jpm |
501 |
}
|
|
|
502 |
|
|
|
503 |
private function formaterNomSciCode($infos) {
|
638 |
aurelien |
504 |
return $this->parametres['referentiel'].'.'.$infos['nom_sel_nn'];
|
138 |
jpm |
505 |
}
|
|
|
506 |
|
|
|
507 |
private function formaterStation($infos) {
|
|
|
508 |
$station = array();
|
538 |
aurelien |
509 |
if (isset($infos['zone_geo']) && $commune = $this->formaterCommune($infos)) {
|
375 |
delphine |
510 |
$station['station.commune'] = $commune;
|
138 |
jpm |
511 |
}
|
378 |
delphine |
512 |
if (isset($infos['lieudit']) && $this->avoirContenu($infos['lieudit'])) {
|
375 |
delphine |
513 |
$station['station.lieudit'] = $infos['lieudit'];
|
138 |
jpm |
514 |
}
|
378 |
delphine |
515 |
if (isset($infos['station']) && $this->avoirContenu($infos['station'])) {
|
375 |
delphine |
516 |
$station['station.station'] = $infos['station'];
|
138 |
jpm |
517 |
}
|
|
|
518 |
|
378 |
delphine |
519 |
if (isset($infos['milieu']) && $this->avoirContenu($infos['milieu'])) {
|
375 |
delphine |
520 |
$station['station.milieu'] = $infos['milieu'];
|
138 |
jpm |
521 |
}
|
378 |
delphine |
522 |
if (count($station) > 1) {
|
|
|
523 |
$station['station.libelle'] = implode(' > ', $station);
|
|
|
524 |
}
|
375 |
delphine |
525 |
return $station;
|
138 |
jpm |
526 |
}
|
|
|
527 |
|
|
|
528 |
private function formaterCommune($infos) {
|
|
|
529 |
$commune = array();
|
538 |
aurelien |
530 |
if ($this->avoirContenu($infos['zone_geo'])) {
|
|
|
531 |
$commune[] = $infos['zone_geo'];
|
138 |
jpm |
532 |
}
|
638 |
aurelien |
533 |
if (isset($infos['ce_zone_geo']) && $this->avoirContenu($infos['ce_zone_geo']) && $infos['ce_zone_geo'] != 'INSEE-C:') {
|
538 |
aurelien |
534 |
$commune[] = '('.substr(str_replace('INSEE-C:','',$infos['ce_zone_geo']), 0, 2).')';
|
138 |
jpm |
535 |
}
|
|
|
536 |
return implode(' ', $commune);
|
|
|
537 |
}
|
|
|
538 |
|
|
|
539 |
private function avoirContenu($info) {
|
638 |
aurelien |
540 |
return !($info == null || $info == '' || $info == '000null');
|
138 |
jpm |
541 |
}
|
106 |
aurelien |
542 |
}
|
|
|
543 |
?>
|