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