Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 1014 | Rev 1088 | 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();
1014 raphael 46
		$this->donnees['coste'] = $this->getCoste();
955 delphine 47
		return $this->donnees;
697 mathilde 48
	}
291 jpm 49
 
50
	public function getBloc() {
955 delphine 51
		$this->donnees = $this->getPhoto('cel');
52
		if (empty($this->donnees)) {
53
			$infos_image = $this->getDessin();
631 mathilde 54
			if (empty($infos_image) == false ){
955 delphine 55
				$this->donnees['imageUrl'] =  array_shift($infos_image['images']);
631 mathilde 56
			}
57
		}
955 delphine 58
		if (empty($this->donnees)) {
59
			$this->donnees = $this->getPhoto('photoflora');
631 mathilde 60
		}
955 delphine 61
		return $this->donnees;
631 mathilde 62
	}
63
 
64
 
65
	public function getPhoto($source) {
66
		$donnees = array();
67
		$this->images->setProjet($source);
448 delphine 68
		$nnr = $this->nomCourant->getNnr();
69
		$infos_image = $this->images->getUrlPremiereImageParIdsNoms(array($nnr));
801 delphine 70
		if ($infos_image != array()) {
71
			$image = array_shift($infos_image);
631 mathilde 72
			$donnees['imageUrl'] =  $image['binaire.href'];
470 aurelien 73
		}
291 jpm 74
		return $donnees;
75
	}
478 jpm 76
 
1014 raphael 77
	public function getCoste() {
78
		$coste = array();
79
		$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
80
		$this->images->setProjet('coste');
81
		$this->images->setNnTaxon($tax);
82
		$costeImg = $this->images->getInfosImagesTaxons();
83
		foreach ($costeImg as $infos) {
84
			$coste['images'][] = $infos['binaire.href'];
85
		}
86
		$this->meta->setProjet('coste');
87
		$meta = $this->meta->getMetaDonnees();
88
		$coste['meta']['titre']= $meta[0]['titre'];
89
		$coste['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('coste');
90
		return $coste;
91
	}
92
 
955 delphine 93
	public function getDessin() {
94
		$projet = Config::get($this->referentiel.'.baseDessins');
95
		if ($projet != "") {
96
			$dessin = array();
97
			$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
98
			$this->images->setProjet($projet);
99
			$this->images->setNnTaxon($tax);
100
			$costeImg = $this->images->getInfosImagesTaxons();
101
				foreach ($costeImg as $infos) {
102
					$dessin['images'][] = $infos['binaire.href'];
103
				}
104
			$this->meta->setProjet('coste');
105
			$meta = $this->meta->getMetaDonnees();
106
			$dessin['meta']['titre']= $meta[0]['titre'];
107
			$dessin['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
108
			$this->donnees['coste'] = $dessin;
109
		}
110
	}
111
 
112
	public function getPhotos() {
113
		$projets[] = Config::get($this->referentiel.'.baseImages');
114
		$projets[] = Config::get($this->referentiel.'.baseImagesSupp');
115
		foreach ($projets as $projet) {
116
			if ($projet != "") {
117
				$images = $this->initialiserPhotos($projet);
118
				$this->formaterListePhotos($projet, $images);
119
				$this->formaterMetaPhotos($projet);
621 mathilde 120
			}
955 delphine 121
		}
621 mathilde 122
	}
123
 
955 delphine 124
	private function initialiserPhotos($projet) {
125
		$this->images->setProjet($projet);
448 delphine 126
		$nnr = $this->nomCourant->getNnr();
955 delphine 127
		return $this->images->getInfosImagesParIdsNoms(array($nnr));
128
	}
129
 
130
	private function formaterListePhotos($projet, $images) {
131
		foreach ($images as $idImg => $img) {
132
			$infosImg = array();
133
			$infosImg['src'] = $img['binaire.href'];
134
			$infosImg['nomSci'] = $img['determination.nom_sci'];
135
			$infosImg['station'] = $img['station.libelle'];
136
			$infosImg['date'] = $this->formaterDateImg($img['date']);
137
			$infosImg['auteur'] = $img['auteur.libelle'];
138
 
139
			if ($projet == "cel") {
140
				$infosImg['urlDetailImg'] = $this->appUrls->obtenirUrlPopUpIllustrations($idImg);
141
				$infosImg['urlContact'] = $this->appUrls->obtenirUrlPopUpContact($img['auteur.id'], $idImg);
142
			}
143
			$this->donnees[$projet]['images'][$idImg] = $infosImg;
515 jpm 144
		}
955 delphine 145
	}
146
 
147
	private function formaterMetaPhotos($projet) {
148
		$this->meta->setProjet($projet);
339 aurelien 149
		$meta = $this->meta->getMetaDonnees();
150
		$titreMeta = $meta[0]['titre'];
955 delphine 151
		$this->donnees[$projet]['meta']['titre'] = $titreMeta;
152
		$this->donnees[$projet]['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
339 aurelien 153
	}
697 mathilde 154
 
955 delphine 155
 
156
 
697 mathilde 157
	public function getCelExport() {
158
		$cel = array();
159
		$this->images->setProjet('cel');
160
		$nnr = $this->nomCourant->getNnr();
161
		$img = $this->images->getUrlPremiereImageParIdsNoms(array($nnr));
162
		if($img) {
163
			$img = array_values($img);
164
			$cel['images']['src'] = $img[0]['binaire.href'];
165
			$cel['images']['nomSci'] = $img[0]['determination.nom_sci'];
978 aurelien 166
			$cel['images']['station'] = $img[0]['station.libelle'];
697 mathilde 167
			$cel['images']['date'] = $this->formaterDateImg($img[0]['date']);
168
			$cel['images']['auteur'] = $img[0]['auteur.libelle'];
169
			$this->meta->setProjet('cel');
170
			$meta = $this->meta->getMetaDonnees();
171
			$titreMeta = $meta[0]['titre'];
172
			$cel['meta']['titre'] = $titreMeta;
173
			$cel['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('cel');
174
		}
175
		return $cel;
176
	}
177
 
497 jpm 178
	private function formaterDateImg($date) {
179
		$dateFmt = $date;
978 aurelien 180
		if ($date == '' || $date == null || $date == '0000-00-00' || $date == '1970-01-01 01:01:01') {
1019 raphael 181
			return 'inconnue';
497 jpm 182
		}
1019 raphael 183
		$time = strtotime($date);
184
		if(!$time) {
185
			/* TODO: php -r "echo strtotime('1891-00-00 00:00:00');"
186
			   TODO: fixer le template pour affiche "en l'année X", plutôt que "le X"
187
			   si FALSE pour avant 1901: problème php
188
			   On retourne alors simplement l'année.
189
			   si correction, ne pas oublier modules/popup_illustrations/PopupIllustrations.php */
190
			$dateFmt = explode('-', $date);
191
			return $dateFmt[0];
192
		}
193
		return strftime('%e %B %Y', strtotime($date));
497 jpm 194
	}
195
 
955 delphine 196
	private function formaterNomSci($nom) {
197
		$nomFmt = $nom;
198
		if (is_null($nom) || $nom == '') {
199
			$nomFmt = 'inconnu';
200
		}
201
		return $nomFmt;
497 jpm 202
	}
238 delphine 203
}
204
?>