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();
|
|
|
63 |
} else {
|
|
|
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 '.
|
|
|
232 |
'FROM cel_images AS ci '.
|
538 |
aurelien |
233 |
' LEFT JOIN cel_obs AS co '.
|
1120 |
aurelien |
234 |
'ON (ci.ce_observation = co.id_observation) '.
|
949 |
raphael |
235 |
'WHERE co.transmission = 1 '.
|
|
|
236 |
" AND co.nom_ret_nn IN ($numNom)";
|
767 |
raphael |
237 |
" AND co.nom_referentiel = ".$this->Bdd->proteger($refTax) . ' -- ' . __FILE__ . ':' . __LINE__;
|
116 |
jpm |
238 |
|
|
|
239 |
$resultat = $this->Bdd->recupererTous($requete);
|
|
|
240 |
|
|
|
241 |
if (!is_array($resultat) || count($resultat) <= 0) {
|
126 |
jpm |
242 |
$message = "Aucune image ne correspond au numéro numenclatural $refTax:$numNom";
|
116 |
jpm |
243 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
244 |
throw new Exception($message, $code);
|
106 |
aurelien |
245 |
}
|
116 |
jpm |
246 |
|
|
|
247 |
$id_image_hasard = $resultat[array_rand($resultat)]['id_image'];
|
106 |
aurelien |
248 |
return $id_image_hasard;
|
|
|
249 |
}
|
377 |
jpm |
250 |
|
330 |
delphine |
251 |
private function obtenirIdPremiereImage() {
|
638 |
aurelien |
252 |
$refTax = $this->parametres['referentiel'];
|
330 |
delphine |
253 |
$numNom = $this->Bdd->proteger($this->ref_tax_demande[$refTax][0]);
|
538 |
aurelien |
254 |
$requete = 'SELECT ci.id_image AS id_image '.
|
330 |
delphine |
255 |
'FROM cel_images AS ci'.
|
538 |
aurelien |
256 |
' LEFT JOIN cel_obs AS co '.
|
1120 |
aurelien |
257 |
' ON (ci.ce_observation = co.id_observation) '.
|
330 |
delphine |
258 |
'WHERE co.transmission = 1 '.
|
538 |
aurelien |
259 |
" AND co.nom_ret_nn IN ($numNom) ".
|
1120 |
aurelien |
260 |
' AND ci.date_prise_de_vue != "0000-00-00" '.
|
|
|
261 |
' AND co.nom_referentiel LIKE '.$this->Bdd->proteger($refTax.'%').' '.
|
|
|
262 |
' ORDER BY ci.date_prise_de_vue ASC '.
|
767 |
raphael |
263 |
'LIMIT 1' . ' -- ' . __FILE__ . ':' . __LINE__;
|
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'.
|
538 |
aurelien |
285 |
' LEFT JOIN cel_obs AS co '.
|
1120 |
aurelien |
286 |
' ON (ci.ce_observation = co.id_observation) '.
|
726 |
raphael |
287 |
'WHERE ci.id_image = '.$this->ressources[0].
|
767 |
raphael |
288 |
' AND co.id_observation IS NOT NULL' . ' -- ' . __FILE__ . ':' . __LINE__;
|
377 |
jpm |
289 |
|
375 |
delphine |
290 |
$this->infosImages = $this->Bdd->recupererTous($requete);
|
|
|
291 |
}
|
116 |
jpm |
292 |
|
375 |
delphine |
293 |
private function chargerListeImages() {
|
638 |
aurelien |
294 |
$refTax = $this->parametres['referentiel'];
|
375 |
delphine |
295 |
$numNomListe = implode(',', $this->ref_tax_demande[$refTax]);
|
|
|
296 |
$depart = $this->parametres['navigation.depart'];
|
|
|
297 |
$limite = $this->parametres['navigation.limite'];
|
377 |
jpm |
298 |
|
375 |
delphine |
299 |
//TODO: modifier la requete lors du passage à la nouvelle base de données pour faire quelque chose
|
386 |
jpm |
300 |
// du numéro nomenclatural + modifier les champs appelés pour le nouveau format
|
375 |
delphine |
301 |
$requete = 'SELECT SQL_CALC_FOUND_ROWS '.
|
538 |
aurelien |
302 |
' co.id_observation AS id_obs, co.courriel_utilisateur AS utilisateur_courriel, co.zone_geo, co.ce_zone_geo, '.
|
|
|
303 |
' co.nom_sel, co.nom_sel_nn, '.
|
638 |
aurelien |
304 |
' ci.id_image AS id_img, co.date_observation AS date '.
|
386 |
jpm |
305 |
(isset($this->parametres['retour.champs']) ? ', '.$this->parametres['retour.champs'] : '').
|
|
|
306 |
'FROM cel_images AS ci'.
|
538 |
aurelien |
307 |
' LEFT JOIN cel_obs AS co '.
|
1120 |
aurelien |
308 |
' ON (ci.ce_observation = co.id_observation) '.
|
386 |
jpm |
309 |
$this->formerRequeteConditions($numNomListe).' '.
|
|
|
310 |
'GROUP BY id_img '.
|
|
|
311 |
$this->formerRequeteTri().
|
767 |
raphael |
312 |
"LIMIT $depart,$limite " . ' -- ' . __FILE__ . ':' . __LINE__;
|
377 |
jpm |
313 |
|
375 |
delphine |
314 |
$this->infosImages = $this->Bdd->recupererTous($requete);
|
|
|
315 |
}
|
386 |
jpm |
316 |
|
375 |
delphine |
317 |
private function formerRequeteConditions($numNomListe) {
|
638 |
aurelien |
318 |
$refTax = $this->parametres['referentiel'];
|
538 |
aurelien |
319 |
$where[] = " co.transmission = 1 AND co.nom_ret_nn IN ($numNomListe) ";
|
638 |
aurelien |
320 |
$where[] = " co.nom_referentiel LIKE ".$this->Bdd->proteger($refTax."%").' ';
|
|
|
321 |
|
375 |
delphine |
322 |
return ' WHERE '.implode(' AND ', $where);
|
|
|
323 |
}
|
377 |
jpm |
324 |
|
375 |
delphine |
325 |
private function formerRequeteTri() {
|
386 |
jpm |
326 |
$order = '';
|
375 |
delphine |
327 |
if (isset($this->parametres['retour.tri']) && $this->parametres['retour.tri'] == 'date') {
|
638 |
aurelien |
328 |
$order = ' ORDER BY co.date_observation ASC ';
|
375 |
delphine |
329 |
}
|
|
|
330 |
return $order;
|
|
|
331 |
}
|
377 |
jpm |
332 |
|
375 |
delphine |
333 |
private function chargerNbreImagesTotal() {
|
|
|
334 |
$requete = 'SELECT FOUND_ROWS() AS nbre ';
|
|
|
335 |
$resultats = $this->Bdd->recuperer($requete);
|
|
|
336 |
$this->nbreImages = (int) $resultats['nbre'];
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
//+---------------------------------------CHEMIN ET CONVERSION--------------------------------------------------------+
|
116 |
jpm |
340 |
private function recupererImageBinaire($id_image) {
|
|
|
341 |
$image = '';
|
|
|
342 |
$chemin = $this->obtenirCheminImage($id_image);
|
118 |
jpm |
343 |
$image = file_get_contents($chemin);
|
|
|
344 |
if ($image === false) {
|
116 |
jpm |
345 |
$message = "L'image demandée est introuvable sur le serveur : $chemin";
|
|
|
346 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
347 |
throw new Exception($message, $code);
|
106 |
aurelien |
348 |
}
|
116 |
jpm |
349 |
return $image;
|
106 |
aurelien |
350 |
}
|
116 |
jpm |
351 |
|
127 |
jpm |
352 |
private function obtenirCheminImage($idImage) {
|
116 |
jpm |
353 |
$nom = $this->convertirIdImageVersNomFichier($idImage);
|
|
|
354 |
$dossier = $this->convertirIdImageVersChemin($idImage);
|
106 |
aurelien |
355 |
return $dossier.'/'.$nom;
|
|
|
356 |
}
|
116 |
jpm |
357 |
|
127 |
jpm |
358 |
private function convertirIdImageVersNomFichier($idImage) {
|
116 |
jpm |
359 |
$codeImage = $this->construireCodeImage($idImage);
|
|
|
360 |
$nom_fichier = $codeImage.'.jpg';
|
106 |
aurelien |
361 |
return $nom_fichier;
|
|
|
362 |
}
|
116 |
jpm |
363 |
|
|
|
364 |
private function convertirIdImageVersChemin($idImage) {
|
|
|
365 |
$codeImage = $this->construireCodeImage($idImage);
|
|
|
366 |
list($dossierNiveau1, $dossierNiveau2, $idFichier, $format) = explode('_', $codeImage);
|
140 |
jpm |
367 |
$chemin_sur_serveur = $this->cheminImagesBase.'/'.$dossierNiveau1.'/'.$dossierNiveau2.'/'.$format;
|
116 |
jpm |
368 |
return $chemin_sur_serveur;
|
106 |
aurelien |
369 |
}
|
116 |
jpm |
370 |
|
|
|
371 |
private function construireCodeImage($idImage) {
|
|
|
372 |
$codeImage = sprintf('%09s', $idImage);
|
|
|
373 |
$codeImage = wordwrap($codeImage, 3, '_', true);
|
|
|
374 |
$format = $this->parametres['retour.format'];
|
|
|
375 |
$codeImage .= '_'.$format;
|
|
|
376 |
return $codeImage;
|
106 |
aurelien |
377 |
}
|
377 |
jpm |
378 |
|
375 |
delphine |
379 |
//+------------------------------------FORMATAGE LISTE----------------------------------------------------------------+
|
138 |
jpm |
380 |
private function formaterListeImages() {
|
|
|
381 |
$entete = $this->construireEntete();
|
|
|
382 |
$resultats = $this->construireResultats();
|
|
|
383 |
|
|
|
384 |
$resultat = array('entete' => $entete, 'resultats' => $resultats);
|
|
|
385 |
return $resultat;
|
|
|
386 |
}
|
|
|
387 |
|
|
|
388 |
private function construireEntete() {
|
|
|
389 |
$entete = array('masque' => '', 'depart' => 0, 'limite' => 100, 'total' => 0);
|
|
|
390 |
|
|
|
391 |
$entete['masque'] = $this->recupererMasque();
|
|
|
392 |
$entete['depart'] = (int) $this->parametres['navigation.depart'];
|
|
|
393 |
$entete['limite'] = (int) $this->parametres['navigation.limite'];
|
|
|
394 |
$entete['total'] = $this->nbreImages;
|
|
|
395 |
if ($hrefPrecedent = $this->recupererHrefPrecedent()) {
|
|
|
396 |
$entete['href.precedent'] = $hrefPrecedent;
|
|
|
397 |
}
|
|
|
398 |
if ($hrefSuivant = $this->recupererHrefSuivant()) {
|
|
|
399 |
$entete['href.suivant'] = $hrefSuivant;
|
|
|
400 |
}
|
|
|
401 |
return $entete;
|
|
|
402 |
}
|
|
|
403 |
|
|
|
404 |
private function recupererMasque() {
|
|
|
405 |
$masqueEntete = '';
|
|
|
406 |
if ($masqueNn = $this->parametres['masque.nn']) {
|
|
|
407 |
$masqueEntete = "nn=$masqueNn";
|
|
|
408 |
}
|
|
|
409 |
return $masqueEntete;
|
|
|
410 |
}
|
|
|
411 |
|
|
|
412 |
private function recupererHrefPrecedent() {
|
|
|
413 |
$departActuel = $this->parametres['navigation.depart'];
|
|
|
414 |
$limite = $this->parametres['navigation.limite'];
|
|
|
415 |
$departPrecedent = $departActuel - $limite;
|
|
|
416 |
$url = null;
|
|
|
417 |
if ($departPrecedent >= 0) {
|
|
|
418 |
$url = $this->obtenirUrlNavigation($departPrecedent, $limite);
|
|
|
419 |
}
|
|
|
420 |
return $url;
|
|
|
421 |
}
|
|
|
422 |
|
|
|
423 |
private function recupererHrefSuivant() {
|
|
|
424 |
$departActuel = $this->parametres['navigation.depart'];
|
|
|
425 |
$limite = $this->parametres['navigation.limite'];
|
|
|
426 |
$departSuivant = $departActuel + $limite;
|
|
|
427 |
$url = null;
|
|
|
428 |
if ($departSuivant < $this->nbreImages) {
|
|
|
429 |
$url = $this->obtenirUrlNavigation($departSuivant, $limite);
|
|
|
430 |
}
|
|
|
431 |
return $url;
|
|
|
432 |
}
|
|
|
433 |
|
|
|
434 |
private function obtenirUrlNavigation($depart, $limite) {
|
|
|
435 |
$parametres = array(
|
|
|
436 |
'navigation.depart' => $depart,
|
|
|
437 |
'navigation.limite' => $limite);
|
|
|
438 |
if (isset($this->parametres['masque.nn'])) {
|
|
|
439 |
$parametres['masque.nn'] = $this->parametres['masque.nn'];
|
|
|
440 |
}
|
140 |
jpm |
441 |
$this->UrlNavigation->setRequete($parametres);
|
|
|
442 |
$url = $this->UrlNavigation->getURL();
|
138 |
jpm |
443 |
return $url;
|
|
|
444 |
}
|
|
|
445 |
|
|
|
446 |
private function construireResultats() {
|
|
|
447 |
$resultats = array();
|
386 |
jpm |
448 |
$this->extraireIdentitesAuteurs();
|
138 |
jpm |
449 |
foreach ($this->infosImages as $img) {
|
375 |
delphine |
450 |
$info = $this->formaterInfosImage($img);
|
142 |
jpm |
451 |
$id = $img['id_img'];
|
378 |
delphine |
452 |
$info['href'] = $this->config['urlService'].'/'.$id;
|
138 |
jpm |
453 |
if (!isset($resultats[$id])) {
|
|
|
454 |
$resultats[$id] = $info;
|
|
|
455 |
} else {
|
|
|
456 |
throw new Exception("Double : $id");
|
|
|
457 |
}
|
|
|
458 |
}
|
|
|
459 |
return $resultats;
|
|
|
460 |
}
|
|
|
461 |
|
375 |
delphine |
462 |
private function formaterInfosImage($img) {
|
|
|
463 |
$info = array();
|
|
|
464 |
$info['date'] = $img['date'];
|
|
|
465 |
$info['mime'] = self::MIME_JPEG;
|
386 |
jpm |
466 |
$info['auteur.libelle'] = $this->Utilisateurs->getIntitule($img['utilisateur_courriel']);
|
|
|
467 |
$info['auteur.id'] = $this->Utilisateurs->getId($img['utilisateur_courriel']);
|
375 |
delphine |
468 |
$info['binaire.href'] = $this->formaterUrlImage($img);
|
393 |
jpm |
469 |
$info['observation.id'] = $img['id_obs'];
|
378 |
delphine |
470 |
if (isset($img['nom_sel'])) {
|
|
|
471 |
$info['determination.libelle'] = $this->formaterDetermination($img);
|
|
|
472 |
$info['determination.nom_sci'] = $img['nom_sel'];
|
|
|
473 |
$info['determination.nom_sci.code'] = $this->formaterNomSciCode($img);
|
|
|
474 |
}
|
375 |
delphine |
475 |
$info = array_merge($info, $this->formaterStation($img));
|
|
|
476 |
return $info;
|
|
|
477 |
}
|
377 |
jpm |
478 |
|
386 |
jpm |
479 |
private function extraireIdentitesAuteurs() {
|
138 |
jpm |
480 |
$courriels = array();
|
|
|
481 |
foreach ($this->infosImages as $img) {
|
|
|
482 |
$courriels[] = $img['utilisateur_courriel'];
|
|
|
483 |
}
|
846 |
raphael |
484 |
// pour Acer monspessulanum L. Sapindaceae, cela divise par 9 le nombre
|
|
|
485 |
// de courriels (213 => 23)
|
|
|
486 |
$courriels = array_values(array_unique($courriels, SORT_STRING));
|
386 |
jpm |
487 |
$this->Utilisateurs->setCourriels($courriels);
|
846 |
raphael |
488 |
// XXX: webservices: /service:annuaire:utilisateur/identite-par-courriel/ [/bibliotheque/Utilisateurs.php]
|
386 |
jpm |
489 |
$this->Utilisateurs->chargerIdentites();
|
138 |
jpm |
490 |
}
|
|
|
491 |
|
|
|
492 |
private function formaterUrlImage($infos) {
|
143 |
jpm |
493 |
$format = $this->parametres['retour.format'];
|
138 |
jpm |
494 |
$id = sprintf('%09s', $infos['id_img']).$format;
|
1044 |
aurelien |
495 |
$url = sprintf($this->tpl_url_img, $id);
|
138 |
jpm |
496 |
return $url;
|
|
|
497 |
}
|
|
|
498 |
|
|
|
499 |
private function formaterDetermination($infos) {
|
386 |
jpm |
500 |
$auteur = $this->Utilisateurs->getIntitule($infos['utilisateur_courriel']);
|
|
|
501 |
return $infos['nom_sel']."[Dét. : $auteur]";
|
138 |
jpm |
502 |
}
|
|
|
503 |
|
|
|
504 |
private function formaterNomSciCode($infos) {
|
638 |
aurelien |
505 |
return $this->parametres['referentiel'].'.'.$infos['nom_sel_nn'];
|
138 |
jpm |
506 |
}
|
|
|
507 |
|
|
|
508 |
private function formaterStation($infos) {
|
|
|
509 |
$station = array();
|
538 |
aurelien |
510 |
if (isset($infos['zone_geo']) && $commune = $this->formaterCommune($infos)) {
|
375 |
delphine |
511 |
$station['station.commune'] = $commune;
|
138 |
jpm |
512 |
}
|
378 |
delphine |
513 |
if (isset($infos['lieudit']) && $this->avoirContenu($infos['lieudit'])) {
|
375 |
delphine |
514 |
$station['station.lieudit'] = $infos['lieudit'];
|
138 |
jpm |
515 |
}
|
378 |
delphine |
516 |
if (isset($infos['station']) && $this->avoirContenu($infos['station'])) {
|
375 |
delphine |
517 |
$station['station.station'] = $infos['station'];
|
138 |
jpm |
518 |
}
|
|
|
519 |
|
378 |
delphine |
520 |
if (isset($infos['milieu']) && $this->avoirContenu($infos['milieu'])) {
|
375 |
delphine |
521 |
$station['station.milieu'] = $infos['milieu'];
|
138 |
jpm |
522 |
}
|
666 |
aurelien |
523 |
if (count($station) >= 1) {
|
378 |
delphine |
524 |
$station['station.libelle'] = implode(' > ', $station);
|
|
|
525 |
}
|
375 |
delphine |
526 |
return $station;
|
138 |
jpm |
527 |
}
|
|
|
528 |
|
|
|
529 |
private function formaterCommune($infos) {
|
|
|
530 |
$commune = array();
|
538 |
aurelien |
531 |
if ($this->avoirContenu($infos['zone_geo'])) {
|
|
|
532 |
$commune[] = $infos['zone_geo'];
|
138 |
jpm |
533 |
}
|
638 |
aurelien |
534 |
if (isset($infos['ce_zone_geo']) && $this->avoirContenu($infos['ce_zone_geo']) && $infos['ce_zone_geo'] != 'INSEE-C:') {
|
538 |
aurelien |
535 |
$commune[] = '('.substr(str_replace('INSEE-C:','',$infos['ce_zone_geo']), 0, 2).')';
|
138 |
jpm |
536 |
}
|
|
|
537 |
return implode(' ', $commune);
|
|
|
538 |
}
|
|
|
539 |
|
|
|
540 |
private function avoirContenu($info) {
|
638 |
aurelien |
541 |
return !($info == null || $info == '' || $info == '000null');
|
138 |
jpm |
542 |
}
|
106 |
aurelien |
543 |
}
|
|
|
544 |
?>
|