Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 1019 | Rev 1114 | 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
	}
1088 raphael 123
 
124
	// XXX: webservice:
125
	// /service:eflore:0.1/cel/images?masque.nn=XXX&referentiel=bdtfx&retour.format=CS&navigation.limite=801
955 delphine 126
	private function initialiserPhotos($projet) {
127
		$this->images->setProjet($projet);
448 delphine 128
		$nnr = $this->nomCourant->getNnr();
955 delphine 129
		return $this->images->getInfosImagesParIdsNoms(array($nnr));
130
	}
131
 
132
	private function formaterListePhotos($projet, $images) {
133
		foreach ($images as $idImg => $img) {
134
			$infosImg = array();
135
			$infosImg['src'] = $img['binaire.href'];
136
			$infosImg['nomSci'] = $img['determination.nom_sci'];
137
			$infosImg['station'] = $img['station.libelle'];
138
			$infosImg['date'] = $this->formaterDateImg($img['date']);
139
			$infosImg['auteur'] = $img['auteur.libelle'];
140
 
141
			if ($projet == "cel") {
142
				$infosImg['urlDetailImg'] = $this->appUrls->obtenirUrlPopUpIllustrations($idImg);
143
				$infosImg['urlContact'] = $this->appUrls->obtenirUrlPopUpContact($img['auteur.id'], $idImg);
144
			}
145
			$this->donnees[$projet]['images'][$idImg] = $infosImg;
515 jpm 146
		}
955 delphine 147
	}
148
 
149
	private function formaterMetaPhotos($projet) {
150
		$this->meta->setProjet($projet);
339 aurelien 151
		$meta = $this->meta->getMetaDonnees();
152
		$titreMeta = $meta[0]['titre'];
955 delphine 153
		$this->donnees[$projet]['meta']['titre'] = $titreMeta;
154
		$this->donnees[$projet]['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
339 aurelien 155
	}
697 mathilde 156
 
955 delphine 157
 
158
 
697 mathilde 159
	public function getCelExport() {
160
		$cel = array();
161
		$this->images->setProjet('cel');
162
		$nnr = $this->nomCourant->getNnr();
163
		$img = $this->images->getUrlPremiereImageParIdsNoms(array($nnr));
164
		if($img) {
165
			$img = array_values($img);
166
			$cel['images']['src'] = $img[0]['binaire.href'];
167
			$cel['images']['nomSci'] = $img[0]['determination.nom_sci'];
978 aurelien 168
			$cel['images']['station'] = $img[0]['station.libelle'];
697 mathilde 169
			$cel['images']['date'] = $this->formaterDateImg($img[0]['date']);
170
			$cel['images']['auteur'] = $img[0]['auteur.libelle'];
171
			$this->meta->setProjet('cel');
172
			$meta = $this->meta->getMetaDonnees();
173
			$titreMeta = $meta[0]['titre'];
174
			$cel['meta']['titre'] = $titreMeta;
175
			$cel['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('cel');
176
		}
177
		return $cel;
178
	}
179
 
497 jpm 180
	private function formaterDateImg($date) {
181
		$dateFmt = $date;
978 aurelien 182
		if ($date == '' || $date == null || $date == '0000-00-00' || $date == '1970-01-01 01:01:01') {
1019 raphael 183
			return 'inconnue';
497 jpm 184
		}
1019 raphael 185
		$time = strtotime($date);
186
		if(!$time) {
187
			/* TODO: php -r "echo strtotime('1891-00-00 00:00:00');"
188
			   TODO: fixer le template pour affiche "en l'année X", plutôt que "le X"
189
			   si FALSE pour avant 1901: problème php
190
			   On retourne alors simplement l'année.
191
			   si correction, ne pas oublier modules/popup_illustrations/PopupIllustrations.php */
192
			$dateFmt = explode('-', $date);
193
			return $dateFmt[0];
194
		}
195
		return strftime('%e %B %Y', strtotime($date));
497 jpm 196
	}
197
 
955 delphine 198
	private function formaterNomSci($nom) {
199
		$nomFmt = $nom;
200
		if (is_null($nom) || $nom == '') {
201
			$nomFmt = 'inconnu';
202
		}
203
		return $nomFmt;
497 jpm 204
	}
238 delphine 205
}
206
?>