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