Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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