Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 331 | Rev 377 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 331 Rev 375
Line 50... Line 50...
50
		$this->parametres = $parametres;
50
		$this->parametres = $parametres;
51
		$this->ressources = $ressources;
51
		$this->ressources = $ressources;
Line 52... Line 52...
52
 
52
 
53
		$this->definirValeurParDefautDesParametres();
53
		$this->definirValeurParDefautDesParametres();
54
		$this->verifierParametres();
-
 
Line 55... Line 54...
55
		$this->analyserMasqueNn();
54
		$this->verifierParametres();
56
 
55
 
57
		$resultat = new ResultatService();
56
		$resultat = new ResultatService();
58
		if ($this->parametres['retour'] == self::MIME_JPEG) {
57
		if ($this->parametres['retour'] == self::MIME_JPEG) {
59
			if ($this->parametres['retour.tri'] == 'date') {
58
			if ($this->parametres['retour.tri'] == 'date') {
60
				$id_image_a_renvoyer = $this->obtenirIdPremiereImage();
59
				$id_image_a_renvoyer = $this->obtenirIdPremiereImage();
61
			} else {
60
			} else {
62
				$id_image_a_renvoyer = $this->obtenirIdImageAuHasard();
61
				$id_image_a_renvoyer = $this->obtenirIdImageAuHasard();
63
			}
62
			}
-
 
63
			$resultat->corps = $this->recupererImageBinaire($id_image_a_renvoyer);
-
 
64
		} else if ($this->parametres['retour'] == self::MIME_JSON) {
-
 
65
			if (isset($this->ressources[0])) {
-
 
66
				$this->chargerInfosImage();
-
 
67
				$this->extraireIntitulesAuteurs();
64
			$resultat->corps = $this->recupererImageBinaire($id_image_a_renvoyer);
68
				$resultat->corps = $this->formaterInfosImage($this->infosImages[0]);
65
		} else if ($this->parametres['retour'] == self::MIME_JSON) {
69
			} else {
66
			$this->chargerListeImages();
70
				$this->chargerListeImages();
67
			$this->chargerNbreImagesTotal();
71
				$this->chargerNbreImagesTotal();
68
			$resultat->corps = $infos = $this->formaterListeImages();
-
 
69
			//$tpsFin = microtime(true);
72
				$resultat->corps = $this->formaterListeImages();
70
			//$resultat->corps['entete']['execution.tps'] = $tpsFin - $tpsDebut;
73
			}
Line 71... Line 74...
71
		}
74
		}
72
		$resultat->mime = $this->parametres['retour'];
75
		$resultat->mime = $this->parametres['retour'];
73
 
-
 
-
 
76
 
74
		return $resultat;
77
		return $resultat;
75
	}
78
	}
76
 
79
//+---------------------------FONCTION D'ANALYSE DES PARAMETRES---------------------------------------------------------+
77
	private function definirValeurParDefautDesParametres() {
80
	private function definirValeurParDefautDesParametres() {
78
		if (isset($this->parametres['retour']) == false) {
81
		if (isset($this->parametres['retour']) == false) {
Line 90... Line 93...
90
	}
93
	}
Line 91... Line 94...
91
 
94
 
92
	private function verifierParametres() {
95
	private function verifierParametres() {
Line -... Line 96...
-
 
96
		$erreurs = array();
93
		$erreurs = array();
97
 
94
 
98
		if (!isset($this->ressources[0])) {
95
		if (isset($this->parametres['masque.nn']) == false) {
99
			if (isset($this->parametres['masque.nn']) == false) {
-
 
100
				$erreurs[] = "Le paramètre masque.nn est obligatoire.";
96
			$erreurs[] = "Le paramètre masque.nn est obligatoire.";
101
			} else {
97
		} else {
102
				$this->analyserMasqueNn();
98
			if ($this->verifierMasqueNnAutorisePourRetourJPEG() == false) {
103
				if ($this->verifierMasqueNnAutorisePourRetourJPEG() == false) {
99
				$erreurs[] = "Le paramètre masque.nn peut contenir une seule valeur numérique pour l'instant pour le format de retour image/jpeg.";
104
					$erreurs[] = "Le paramètre masque.nn peut contenir une seule valeur numérique pour l'instant pour le format de retour image/jpeg.";
100
			} else if ($this->verifierValeurParametreMasqueNn() == false) {
105
				} else if ($this->verifierValeurParametreMasqueNn() == false) {
101
				$erreurs[] = "Le paramètre masque.nn est mal formé.";
106
					$erreurs[] = "Le paramètre masque.nn est mal formé.";
-
 
107
				}
102
			}
108
			}
103
		}
109
		}
104
		if (isset($this->parametres['retour']) == false) {
110
		if (isset($this->parametres['retour']) == false) {
105
			$erreurs[] = "Le paramètre type de retour 'retour' est obligatoire.";
111
			$erreurs[] = "Le paramètre type de retour 'retour' est obligatoire.";
106
		}
112
		}
Line 192... Line 198...
192
				}
198
				}
193
			}
199
			}
194
		}
200
		}
195
	}
201
	}
Line -... Line 202...
-
 
202
 
-
 
203
	
196
 
204
//+----------------------------------------  REQUETES  ---------------------------------------------------------------+
197
	private function obtenirIdImageAuHasard() {
205
	private function obtenirIdImageAuHasard() {
198
		$refTax = self::CODE_REFTAX_DEFAUT;
206
		$refTax = self::CODE_REFTAX_DEFAUT;
Line 199... Line 207...
199
		$numNom = $this->Bdd->proteger($this->ref_tax_demande[$refTax][0]);
207
		$numNom = $this->Bdd->proteger($this->ref_tax_demande[$refTax][0]);
Line 242... Line 250...
242
	
250
	
243
		$id_image_hasard = $resultat[0]['id_image'];
251
		$id_image_hasard = $resultat[0]['id_image'];
244
		return $id_image_hasard;
252
		return $id_image_hasard;
Line 245... Line 253...
245
	}
253
	}
246
 
254
	
247
	private function recupererImageBinaire($id_image) {
255
	private function chargerInfosImage() {
248
		$image = '';
256
		$requete = 	'SELECT SQL_CALC_FOUND_ROWS '.
249
		$chemin = $this->obtenirCheminImage($id_image);
257
				' ci.ci_id_image AS id_img, co.id AS id_obs, '.
250
		$image = file_get_contents($chemin);
258
				' identifiant AS utilisateur_courriel, '.
251
		if ($image === false) {
-
 
252
			$message = "L'image demandée est introuvable sur le serveur : $chemin";
259
				' nom_sel, num_nom_sel, '.
253
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
-
 
254
			throw new Exception($message, $code);
260
				' location, id_location, lieudit, station, milieu, '.
255
		}
-
 
256
		return $image;
-
 
257
	}
261
			    ' ci.ci_meta_date AS date '.
258
 
-
 
259
	private function obtenirCheminImage($idImage) {
-
 
260
		$nom = $this->convertirIdImageVersNomFichier($idImage);
-
 
261
		$dossier = $this->convertirIdImageVersChemin($idImage);
-
 
262
		return $dossier.'/'.$nom;
-
 
263
	}
262
				'FROM cel_images AS ci'.
264
 
-
 
265
	private function convertirIdImageVersNomFichier($idImage) {
263
				'	LEFT JOIN cel_obs_images AS coi  '.
266
		$codeImage = $this->construireCodeImage($idImage);
-
 
267
		$nom_fichier = $codeImage.'.jpg';
-
 
268
		return $nom_fichier;
-
 
269
	}
264
				'		ON (coi.coi_ce_image = ci.ci_id_image) '.
270
 
265
				'	LEFT JOIN cel_inventory AS co '.
271
	private function convertirIdImageVersChemin($idImage) {
-
 
272
		$codeImage = $this->construireCodeImage($idImage);
-
 
273
		list($dossierNiveau1, $dossierNiveau2, $idFichier, $format) = explode('_', $codeImage);
-
 
274
		$chemin_sur_serveur = $this->cheminImagesBase.'/'.$dossierNiveau1.'/'.$dossierNiveau2.'/'.$format;
-
 
Line 275... Line -...
275
		return $chemin_sur_serveur;
-
 
276
	}
-
 
277
 
-
 
278
	private function construireCodeImage($idImage) {
266
				'		ON (coi.coi_ce_observation = co.ordre AND coi.coi_ce_utilisateur = co.identifiant) '.
279
		$codeImage = sprintf('%09s', $idImage);
-
 
280
		$codeImage = wordwrap($codeImage, 3, '_', true);
-
 
281
		$format = $this->parametres['retour.format'];
267
				'WHERE ci.ci_id_image = '.$this->ressources[0];
Line 282... Line 268...
282
		$codeImage .= '_'.$format;
268
	
283
		return $codeImage;
269
		$this->infosImages = $this->Bdd->recupererTous($requete);
284
	}
270
	}
Line 302... Line 288...
302
			'		ON (coi.coi_ce_image = ci.ci_id_image) '.
288
				'		ON (coi.coi_ce_image = ci.ci_id_image) '.
303
			'	LEFT JOIN cel_inventory AS co '.
289
				'	LEFT JOIN cel_inventory AS co '.
304
			'		ON (coi.coi_ce_observation = co.ordre AND coi.coi_ce_utilisateur = co.identifiant) '.
290
				'		ON (coi.coi_ce_observation = co.ordre AND coi.coi_ce_utilisateur = co.identifiant) '.
305
			$this->formerRequeteConditions($numNomListe).
291
				$this->formerRequeteConditions($numNomListe).
306
			' GROUP BY id_img '.
292
				' GROUP BY id_img '.
307
			$this->formerRequeteOrdre().
293
				$this->formerRequeteTri().
308
			"LIMIT $depart,$limite ";
294
				"LIMIT $depart,$limite ";
Line 309... Line 295...
309
 
295
	
310
		$this->infosImages = $this->Bdd->recupererTous($requete);
296
		$this->infosImages = $this->Bdd->recupererTous($requete);
Line 316... Line 302...
316
			$where[] = ' ci.ci_meta_date != "0000-00-00"';
302
			$where[] = ' ci.ci_meta_date != "0000-00-00"';
317
		}
303
		}
318
		return ' WHERE '.implode(' AND ', $where);
304
		return ' WHERE '.implode(' AND ', $where);
319
	}
305
	}
Line 320... Line 306...
320
	
306
	
321
	private function formerRequeteOrdre() {
307
	private function formerRequeteTri() {
322
		$order = "";
308
		$order = "";
323
		if (isset($this->parametres['retour.tri']) && $this->parametres['retour.tri'] == 'date') {
309
		if (isset($this->parametres['retour.tri']) && $this->parametres['retour.tri'] == 'date') {
324
			$order = ' ORDER BY ci.ci_meta_date ASC ';
310
			$order = ' ORDER BY ci.ci_meta_date ASC ';
325
		}
311
		}
Line 331... Line 317...
331
		$requete = 'SELECT FOUND_ROWS() AS nbre ';
317
		$requete = 'SELECT FOUND_ROWS() AS nbre ';
332
		$resultats = $this->Bdd->recuperer($requete);
318
		$resultats = $this->Bdd->recuperer($requete);
333
		$this->nbreImages = (int) $resultats['nbre'];
319
		$this->nbreImages = (int) $resultats['nbre'];
334
	}
320
	}
Line -... Line 321...
-
 
321
	
-
 
322
 
-
 
323
//+---------------------------------------CHEMIN ET CONVERSION--------------------------------------------------------+
-
 
324
	private function recupererImageBinaire($id_image) {
-
 
325
		$image = '';
-
 
326
		$chemin = $this->obtenirCheminImage($id_image);
-
 
327
		$image = file_get_contents($chemin);
-
 
328
		if ($image === false) {
-
 
329
			$message = "L'image demandée est introuvable sur le serveur : $chemin";
-
 
330
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
-
 
331
			throw new Exception($message, $code);
-
 
332
		}
-
 
333
		return $image;
-
 
334
	}
-
 
335
 
-
 
336
	private function obtenirCheminImage($idImage) {
-
 
337
		$nom = $this->convertirIdImageVersNomFichier($idImage);
-
 
338
		$dossier = $this->convertirIdImageVersChemin($idImage);
-
 
339
		return $dossier.'/'.$nom;
-
 
340
	}
-
 
341
 
-
 
342
	private function convertirIdImageVersNomFichier($idImage) {
-
 
343
		$codeImage = $this->construireCodeImage($idImage);
-
 
344
		$nom_fichier = $codeImage.'.jpg';
-
 
345
		return $nom_fichier;
-
 
346
	}
-
 
347
 
-
 
348
	private function convertirIdImageVersChemin($idImage) {
-
 
349
		$codeImage = $this->construireCodeImage($idImage);
-
 
350
		list($dossierNiveau1, $dossierNiveau2, $idFichier, $format) = explode('_', $codeImage);
-
 
351
		$chemin_sur_serveur = $this->cheminImagesBase.'/'.$dossierNiveau1.'/'.$dossierNiveau2.'/'.$format;
-
 
352
		return $chemin_sur_serveur;
-
 
353
	}
-
 
354
 
-
 
355
	private function construireCodeImage($idImage) {
-
 
356
		$codeImage = sprintf('%09s', $idImage);
-
 
357
		$codeImage = wordwrap($codeImage, 3, '_', true);
-
 
358
		$format = $this->parametres['retour.format'];
-
 
359
		$codeImage .= '_'.$format;
-
 
360
		return $codeImage;
-
 
361
	}
-
 
362
	
-
 
363
	
335
 
364
//+------------------------------------FORMATAGE LISTE----------------------------------------------------------------+
336
	private function formaterListeImages() {
365
	private function formaterListeImages() {
337
		$entete = $this->construireEntete();
366
		$entete = $this->construireEntete();
Line 338... Line 367...
338
		$resultats = $this->construireResultats();
367
		$resultats = $this->construireResultats();
Line 401... Line 430...
401
 
430
 
402
	private function construireResultats() {
431
	private function construireResultats() {
403
		$resultats = array();
432
		$resultats = array();
404
		$this->extraireIntitulesAuteurs();
433
		$this->extraireIntitulesAuteurs();
405
		foreach ($this->infosImages as $img) {
-
 
406
			$info = array();
-
 
407
			$info['date'] = $img['date'];
-
 
408
			$info['mime'] = self::MIME_JPEG;
-
 
409
			$info['auteur'] = $this->formaterAuteur($img);
434
		foreach ($this->infosImages as $img) {
410
			$info['binaire.href'] = $this->formaterUrlImage($img);
-
 
411
			$info['determination'] = $this->formaterDetermination($img);
-
 
412
			$info['determination.nom_sci'] = $img['nom_sel'];
-
 
413
			$info['determination.nom_sci.code'] = $this->formaterNomSciCode($img);
-
 
414
			$info['station'] = $this->formaterStation($img);
-
 
415
 
435
			$info = $this->formaterInfosImage($img);
416
			$id = $img['id_img'];
436
			$id = $img['id_img'];
417
			if (!isset($resultats[$id])) {
437
			if (!isset($resultats[$id])) {
418
				$resultats[$id] = $info;
438
				$resultats[$id] = $info;
419
			} else {
439
			} else {
420
				throw new Exception("Double : $id");
440
				throw new Exception("Double : $id");
421
			}
441
			}
422
		}
442
		}
423
		return $resultats;
443
		return $resultats;
Line -... Line 444...
-
 
444
	}
-
 
445
 
-
 
446
	private function formaterInfosImage($img) {
-
 
447
		$info = array();
-
 
448
		$info['date'] = $img['date'];
-
 
449
		$info['mime'] = self::MIME_JPEG;
-
 
450
		$info['auteur'] = $this->formaterAuteur($img);
-
 
451
		$info['binaire.href'] = $this->formaterUrlImage($img);
-
 
452
		$info['determination.libelle'] = $this->formaterDetermination($img);
-
 
453
		$info['determination.nom_sci'] = $img['nom_sel'];
-
 
454
		$info['determination.nom_sci.code'] = $this->formaterNomSciCode($img);
-
 
455
		$info = array_merge($info, $this->formaterStation($img));
-
 
456
		return $info;
424
	}
457
	}
425
 
458
	
426
	private function extraireIntitulesAuteurs() {
459
	private function extraireIntitulesAuteurs() {
427
		$courriels = array();
460
		$courriels = array();
428
		foreach ($this->infosImages as $img) {
461
		foreach ($this->infosImages as $img) {
Line 448... Line 481...
448
	}
481
	}
Line 449... Line 482...
449
 
482
 
450
	private function formaterStation($infos) {
483
	private function formaterStation($infos) {
451
		$station = array();
484
		$station = array();
452
		if ($commune = $this->formaterCommune($infos)) {
485
		if ($commune = $this->formaterCommune($infos)) {
453
			$station[] = $commune;
486
			$station['station.commune'] = $commune;
454
		}
487
		}
455
		if ($this->avoirContenu($infos['lieudit'])) {
488
		if ($this->avoirContenu($infos['lieudit'])) {
456
			$station[] = $infos['lieudit'];
489
			$station['station.lieudit'] = $infos['lieudit'];
457
		}
490
		}
458
		if ($this->avoirContenu($infos['station'])) {
491
		if ($this->avoirContenu($infos['station'])) {
459
			$station[] = $infos['station'];
492
			$station['station.station'] = $infos['station'];
Line 460... Line 493...
460
		}
493
		}
461
 
494
 
462
		if ($this->avoirContenu($infos['milieu'])) {
495
		if ($this->avoirContenu($infos['milieu'])) {
463
			$station[] = $infos['milieu'];
496
			$station['station.milieu'] = $infos['milieu'];
-
 
497
		}
464
		}
498
		$station['station.libelle'] = implode(' > ', $station);
Line 465... Line 499...
465
		return implode(' > ', $station);
499
		return $station;
466
	}
500
	}
467
 
501