Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 331 | Rev 377 | Go to most recent revision | Show entire file | Ignore 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
			$resultat->corps = $this->recupererImageBinaire($id_image_a_renvoyer);
64
		} else if ($this->parametres['retour'] == self::MIME_JSON) {
65
		} else if ($this->parametres['retour'] == self::MIME_JSON) {
65
			if (isset($this->ressources[0])) {
66
			$this->chargerListeImages();
66
				$this->chargerInfosImage();
-
 
67
				$this->extraireIntitulesAuteurs();
67
			$this->chargerNbreImagesTotal();
68
				$resultat->corps = $this->formaterInfosImage($this->infosImages[0]);
-
 
69
			} else {
68
			$resultat->corps = $infos = $this->formaterListeImages();
70
				$this->chargerListeImages();
-
 
71
				$this->chargerNbreImagesTotal();
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.";
-
 
105
				} else if ($this->verifierValeurParametreMasqueNn() == false) {
100
			} else if ($this->verifierValeurParametreMasqueNn() == false) {
106
					$erreurs[] = "Le paramètre masque.nn est mal formé.";
101
				$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) {
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 241... Line 249...
241
		}
249
		}
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;
-
 
253
	}
-
 
254
	
-
 
255
	private function chargerInfosImage() {
-
 
256
		$requete = 	'SELECT SQL_CALC_FOUND_ROWS '.
-
 
257
				' ci.ci_id_image AS id_img, co.id AS id_obs, '.
-
 
258
				' identifiant AS utilisateur_courriel, '.
-
 
259
				' nom_sel, num_nom_sel, '.
-
 
260
				' location, id_location, lieudit, station, milieu, '.
-
 
261
			    ' ci.ci_meta_date AS date '.
-
 
262
				'FROM cel_images AS ci'.
-
 
263
				'	LEFT JOIN cel_obs_images AS coi  '.
-
 
264
				'		ON (coi.coi_ce_image = ci.ci_id_image) '.
-
 
265
				'	LEFT JOIN cel_inventory AS co '.
-
 
266
				'		ON (coi.coi_ce_observation = co.ordre AND coi.coi_ce_utilisateur = co.identifiant) '.
-
 
267
				'WHERE ci.ci_id_image = '.$this->ressources[0];
-
 
268
	
-
 
269
		$this->infosImages = $this->Bdd->recupererTous($requete);
Line -... Line 270...
-
 
270
	}
-
 
271
 
-
 
272
	private function chargerListeImages() {
-
 
273
		$refTax = self::CODE_REFTAX_DEFAUT;
-
 
274
		$numNomListe = implode(',', $this->ref_tax_demande[$refTax]);
-
 
275
		$depart = $this->parametres['navigation.depart'];
-
 
276
		$limite = $this->parametres['navigation.limite'];
-
 
277
	
-
 
278
		//TODO: modifier la requete lors du passage à la nouvelle base de données pour faire quelque chose
-
 
279
		// du numéro nomenclatural + modifier les champs appelés pour le nouveau format
-
 
280
		$requete = 	'SELECT SQL_CALC_FOUND_ROWS '.
-
 
281
				' ci.ci_id_image AS id_img, co.id AS id_obs, '.
-
 
282
				' identifiant AS utilisateur_courriel, '.
-
 
283
				' nom_sel, num_nom_sel, '.
-
 
284
				' location, id_location, lieudit, station, milieu, '.
-
 
285
			    ' ci.ci_meta_date AS date '.
-
 
286
				'FROM cel_images AS ci'.
-
 
287
				'	LEFT JOIN cel_obs_images AS coi  '.
-
 
288
				'		ON (coi.coi_ce_image = ci.ci_id_image) '.
-
 
289
				'	LEFT JOIN cel_inventory AS co '.
-
 
290
				'		ON (coi.coi_ce_observation = co.ordre AND coi.coi_ce_utilisateur = co.identifiant) '.
-
 
291
				$this->formerRequeteConditions($numNomListe).
-
 
292
				' GROUP BY id_img '.
-
 
293
				$this->formerRequeteTri().
-
 
294
				"LIMIT $depart,$limite ";
-
 
295
	
-
 
296
		$this->infosImages = $this->Bdd->recupererTous($requete);
-
 
297
	}
-
 
298
	
-
 
299
	private function formerRequeteConditions($numNomListe) {
-
 
300
		$where[] = " co.transmission = 1 AND co.num_nom_ret IN ($numNomListe) ";
-
 
301
		if (isset($this->parametres['retour.tri']) && $this->parametres['retour.tri'] == 'date') {
-
 
302
			$where[] = ' ci.ci_meta_date != "0000-00-00"';
-
 
303
		}
-
 
304
		return ' WHERE '.implode(' AND ', $where);
-
 
305
	}
-
 
306
	
-
 
307
	private function formerRequeteTri() {
-
 
308
		$order = "";
-
 
309
		if (isset($this->parametres['retour.tri']) && $this->parametres['retour.tri'] == 'date') {
-
 
310
			$order = ' ORDER BY ci.ci_meta_date ASC ';
-
 
311
		}
-
 
312
		return $order;
-
 
313
	}
-
 
314
	
-
 
315
	
-
 
316
	private function chargerNbreImagesTotal() {
-
 
317
		$requete = 'SELECT FOUND_ROWS() AS nbre ';
-
 
318
		$resultats = $this->Bdd->recuperer($requete);
-
 
319
		$this->nbreImages = (int) $resultats['nbre'];
-
 
320
	}
-
 
321
	
245
	}
322
 
246
 
323
//+---------------------------------------CHEMIN ET CONVERSION--------------------------------------------------------+
247
	private function recupererImageBinaire($id_image) {
324
	private function recupererImageBinaire($id_image) {
248
		$image = '';
325
		$image = '';
249
		$chemin = $this->obtenirCheminImage($id_image);
326
		$chemin = $this->obtenirCheminImage($id_image);
Line 280... Line 357...
280
		$codeImage = wordwrap($codeImage, 3, '_', true);
357
		$codeImage = wordwrap($codeImage, 3, '_', true);
281
		$format = $this->parametres['retour.format'];
358
		$format = $this->parametres['retour.format'];
282
		$codeImage .= '_'.$format;
359
		$codeImage .= '_'.$format;
283
		return $codeImage;
360
		return $codeImage;
284
	}
361
	}
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
			$this->formerRequeteConditions($numNomListe).
-
 
306
			' GROUP BY id_img '.
-
 
307
			$this->formerRequeteOrdre().
-
 
308
			"LIMIT $depart,$limite ";
-
 
309
 
-
 
310
		$this->infosImages = $this->Bdd->recupererTous($requete);
-
 
311
	}
-
 
312
	
-
 
313
	private function formerRequeteConditions($numNomListe) {
-
 
314
		$where[] = " co.transmission = 1 AND co.num_nom_ret IN ($numNomListe) ";
-
 
315
		if (isset($this->parametres['retour.tri']) && $this->parametres['retour.tri'] == 'date') {
-
 
316
			$where[] = ' ci.ci_meta_date != "0000-00-00"';
-
 
317
		}
-
 
318
		return ' WHERE '.implode(' AND ', $where);
-
 
319
	}
-
 
Line 320... Line -...
320
	
-
 
321
	private function formerRequeteOrdre() {
-
 
322
		$order = "";
-
 
323
		if (isset($this->parametres['retour.tri']) && $this->parametres['retour.tri'] == 'date') {
-
 
324
			$order = ' ORDER BY ci.ci_meta_date ASC ';
-
 
325
		}
-
 
326
		return $order;
-
 
Line 327... Line -...
327
	}
-
 
328
	
-
 
329
 
-
 
330
	private function chargerNbreImagesTotal() {
362
	
331
		$requete = 'SELECT FOUND_ROWS() AS nbre ';
-
 
332
		$resultats = $this->Bdd->recuperer($requete);
-
 
333
		$this->nbreImages = (int) $resultats['nbre'];
-
 
334
	}
363
	
335
 
364
//+------------------------------------FORMATAGE LISTE----------------------------------------------------------------+
336
	private function formaterListeImages() {
365
	private function formaterListeImages() {
Line 337... Line 366...
337
		$entete = $this->construireEntete();
366
		$entete = $this->construireEntete();
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