Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 801 | Rev 978 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
238 delphine 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
 * Classe mère du module Liste.
5
 *
6
 * @category	PHP 5.2
7
 * @package		eflore-consultation
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @author		Delphine CAUQUIL <delphine@tela-botanica.org>
10
 * @copyright	2011 Tela-Botanica
11
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
12
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
13
 * @version		$Id$
14
 */
15
class Illustrations extends aControleur {
291 jpm 16
 
17
	private $conteneur = null;
294 delphine 18
	private $nomCourant = null;
291 jpm 19
	private $images = null;
478 jpm 20
	private $appUrls = null;
21
	private $meta = null;
955 delphine 22
	private $referentiel = 'bdtfx';
23
	private $donnees = array();
291 jpm 24
 
25
	public function __construct(Conteneur $conteneur) {
26
		$this->conteneur = $conteneur;
294 delphine 27
		$this->nomCourant = $this->conteneur->getNomCourant();
955 delphine 28
		$this->referentiel = $this->conteneur->getParametre('referentiel');
291 jpm 29
		$this->images = $this->conteneur->getApiImages();
30
		$this->appUrls = $this->conteneur->getAppUrls();
320 aurelien 31
		$this->meta = $this->conteneur->getApiMetaDonnees();
238 delphine 32
	}
291 jpm 33
 
34
	public function obtenirDonnees() {
955 delphine 35
		$this->donnees['nt'] = $this->nomCourant->getNt();
36
		$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
37
		$this->getPhotos();
38
		$this->getDessin();
39
		return $this->donnees;
238 delphine 40
	}
697 mathilde 41
 
42
	public function obtenirDonneesExport() {
955 delphine 43
		$this->donnees['nt'] = $this->nomCourant->getNt();
44
		$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
45
		$this->donnees['cel'] = $this->getCelExport();
46
		return $this->donnees;
697 mathilde 47
	}
291 jpm 48
 
49
	public function getBloc() {
955 delphine 50
		$this->donnees = $this->getPhoto('cel');
51
		if (empty($this->donnees)) {
52
			$infos_image = $this->getDessin();
631 mathilde 53
			if (empty($infos_image) == false ){
955 delphine 54
				$this->donnees['imageUrl'] =  array_shift($infos_image['images']);
631 mathilde 55
			}
56
		}
955 delphine 57
		if (empty($this->donnees)) {
58
			$this->donnees = $this->getPhoto('photoflora');
631 mathilde 59
		}
955 delphine 60
		return $this->donnees;
631 mathilde 61
	}
62
 
63
 
64
	public function getPhoto($source) {
65
		$donnees = array();
66
		$this->images->setProjet($source);
448 delphine 67
		$nnr = $this->nomCourant->getNnr();
68
		$infos_image = $this->images->getUrlPremiereImageParIdsNoms(array($nnr));
801 delphine 69
		if ($infos_image != array()) {
70
			$image = array_shift($infos_image);
631 mathilde 71
			$donnees['imageUrl'] =  $image['binaire.href'];
470 aurelien 72
		}
291 jpm 73
		return $donnees;
74
	}
478 jpm 75
 
955 delphine 76
	public function getDessin() {
77
		$projet = Config::get($this->referentiel.'.baseDessins');
78
		if ($projet != "") {
79
			$dessin = array();
80
			$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
81
			$this->images->setProjet($projet);
82
			$this->images->setNnTaxon($tax);
83
			$costeImg = $this->images->getInfosImagesTaxons();
84
				foreach ($costeImg as $infos) {
85
					$dessin['images'][] = $infos['binaire.href'];
86
				}
87
			$this->meta->setProjet('coste');
88
			$meta = $this->meta->getMetaDonnees();
89
			$dessin['meta']['titre']= $meta[0]['titre'];
90
			$dessin['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
91
			$this->donnees['coste'] = $dessin;
92
		}
93
	}
94
 
95
	public function getPhotos() {
96
		$projets[] = Config::get($this->referentiel.'.baseImages');
97
		$projets[] = Config::get($this->referentiel.'.baseImagesSupp');
98
		foreach ($projets as $projet) {
99
			if ($projet != "") {
100
				$images = $this->initialiserPhotos($projet);
101
				$this->formaterListePhotos($projet, $images);
102
				$this->formaterMetaPhotos($projet);
621 mathilde 103
			}
955 delphine 104
		}
621 mathilde 105
	}
106
 
955 delphine 107
	private function initialiserPhotos($projet) {
108
		$this->images->setProjet($projet);
448 delphine 109
		$nnr = $this->nomCourant->getNnr();
955 delphine 110
		return $this->images->getInfosImagesParIdsNoms(array($nnr));
111
	}
112
 
113
	private function formaterListePhotos($projet, $images) {
114
		foreach ($images as $idImg => $img) {
115
			$infosImg = array();
116
			$infosImg['src'] = $img['binaire.href'];
117
			$infosImg['nomSci'] = $img['determination.nom_sci'];
118
			$infosImg['station'] = $img['station.libelle'];
119
			$infosImg['date'] = $this->formaterDateImg($img['date']);
120
			$infosImg['auteur'] = $img['auteur.libelle'];
121
 
122
			if ($projet == "cel") {
123
				$infosImg['urlDetailImg'] = $this->appUrls->obtenirUrlPopUpIllustrations($idImg);
124
				$infosImg['urlContact'] = $this->appUrls->obtenirUrlPopUpContact($img['auteur.id'], $idImg);
125
			}
126
			$this->donnees[$projet]['images'][$idImg] = $infosImg;
515 jpm 127
		}
955 delphine 128
	}
129
 
130
	private function formaterMetaPhotos($projet) {
131
		$this->meta->setProjet($projet);
339 aurelien 132
		$meta = $this->meta->getMetaDonnees();
133
		$titreMeta = $meta[0]['titre'];
955 delphine 134
		$this->donnees[$projet]['meta']['titre'] = $titreMeta;
135
		$this->donnees[$projet]['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
339 aurelien 136
	}
697 mathilde 137
 
955 delphine 138
 
139
 
697 mathilde 140
	public function getCelExport() {
141
		$cel = array();
142
		$this->images->setProjet('cel');
143
		$nnr = $this->nomCourant->getNnr();
144
		$img = $this->images->getUrlPremiereImageParIdsNoms(array($nnr));
145
		if($img) {
146
			$img = array_values($img);
147
			$cel['images']['src'] = $img[0]['binaire.href'];
148
			$cel['images']['nomSci'] = $img[0]['determination.nom_sci'];
149
			$cel['images']['commune'] = $img[0]['station.commune'];
150
			$cel['images']['date'] = $this->formaterDateImg($img[0]['date']);
151
			$cel['images']['auteur'] = $img[0]['auteur.libelle'];
152
			$this->meta->setProjet('cel');
153
			$meta = $this->meta->getMetaDonnees();
154
			$titreMeta = $meta[0]['titre'];
155
			$cel['meta']['titre'] = $titreMeta;
156
			$cel['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('cel');
157
		}
158
		return $cel;
159
	}
160
 
497 jpm 161
	private function formaterDateImg($date) {
162
		$dateFmt = $date;
515 jpm 163
		if ($date == '0000-00-00' || $date == '1970-01-01 01:01:01') {
497 jpm 164
			$dateFmt = 'inconnue';
165
		} else {
515 jpm 166
			$dateFmt = strftime('%e %B %Y', strtotime($date));
497 jpm 167
		}
168
		return $dateFmt;
169
	}
170
 
955 delphine 171
	private function formaterNomSci($nom) {
172
		$nomFmt = $nom;
173
		if (is_null($nom) || $nom == '') {
174
			$nomFmt = 'inconnu';
175
		}
176
		return $nomFmt;
497 jpm 177
	}
238 delphine 178
}
179
?>