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