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