Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 1123 | Rev 1135 | 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();
1123 mathias 36
		$this->donnees['nnr'] = $this->nomCourant->getNnr();
955 delphine 37
		$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
1123 mathias 38
		$infosNomRetenu = $this->nomCourant->getNomRetenu()->getInfos();
39
		$this->donnees['nomComplet'] = $infosNomRetenu['nom_complet'];
955 delphine 40
		$this->getPhotos();
41
		$this->getDessin();
1123 mathias 42
		$this->getPhotosOrganes();
43
		$this->getPhotosCaracteresIdentification();
44
		$pso = $this->getPhotosSixOrganes();
45
		$this->setCheminSquelette('modules/fiche/squelettes/'); // @FIXME le chemin devrait déjà être défini correctement !?
46
		$this->donnees['illustrationsOrganes'] = $this->getVue('fiche_illustrations_organes',
47
				array('organes' => $pso, 'nnr' => $this->donnees['nnr'], 'nomComplet' => $this->donnees['nomComplet']));
955 delphine 48
		return $this->donnees;
238 delphine 49
	}
697 mathilde 50
 
51
	public function obtenirDonneesExport() {
955 delphine 52
		$this->donnees['nt'] = $this->nomCourant->getNt();
53
		$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
54
		$this->donnees['cel'] = $this->getCelExport();
1014 raphael 55
		$this->donnees['coste'] = $this->getCoste();
955 delphine 56
		return $this->donnees;
697 mathilde 57
	}
291 jpm 58
 
59
	public function getBloc() {
955 delphine 60
		$this->donnees = $this->getPhoto('cel');
61
		if (empty($this->donnees)) {
62
			$infos_image = $this->getDessin();
631 mathilde 63
			if (empty($infos_image) == false ){
955 delphine 64
				$this->donnees['imageUrl'] =  array_shift($infos_image['images']);
631 mathilde 65
			}
66
		}
955 delphine 67
		if (empty($this->donnees)) {
68
			$this->donnees = $this->getPhoto('photoflora');
631 mathilde 69
		}
955 delphine 70
		return $this->donnees;
631 mathilde 71
	}
72
 
73
 
74
	public function getPhoto($source) {
75
		$donnees = array();
76
		$this->images->setProjet($source);
448 delphine 77
		$nnr = $this->nomCourant->getNnr();
1115 mathias 78
		$infos_image = $this->images->setApi(Eflore::API_EFLORE)->getInfosPremiereImageParIdsNoms(array($nnr));
801 delphine 79
		if ($infos_image != array()) {
80
			$image = array_shift($infos_image);
631 mathilde 81
			$donnees['imageUrl'] =  $image['binaire.href'];
470 aurelien 82
		}
291 jpm 83
		return $donnees;
84
	}
478 jpm 85
 
1014 raphael 86
	public function getCoste() {
87
		$coste = array();
88
		$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
89
		$this->images->setProjet('coste');
90
		$this->images->setNnTaxon($tax);
1115 mathias 91
		$costeImg = $this->images->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
1014 raphael 92
		foreach ($costeImg as $infos) {
93
			$coste['images'][] = $infos['binaire.href'];
94
		}
95
		$this->meta->setProjet('coste');
96
		$meta = $this->meta->getMetaDonnees();
1130 aurelien 97
		$coste['meta'] = $meta[0];
1014 raphael 98
		$coste['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('coste');
99
		return $coste;
100
	}
101
 
955 delphine 102
	public function getDessin() {
103
		$projet = Config::get($this->referentiel.'.baseDessins');
104
		if ($projet != "") {
105
			$dessin = array();
106
			$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
107
			$this->images->setProjet($projet);
108
			$this->images->setNnTaxon($tax);
1115 mathias 109
			$costeImg = $this->images->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
955 delphine 110
				foreach ($costeImg as $infos) {
111
					$dessin['images'][] = $infos['binaire.href'];
112
				}
113
			$this->meta->setProjet('coste');
114
			$meta = $this->meta->getMetaDonnees();
1130 aurelien 115
			$dessin['meta'] = $meta[0];
955 delphine 116
			$dessin['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
117
			$this->donnees['coste'] = $dessin;
118
		}
119
	}
120
 
121
	public function getPhotos() {
122
		$projets[] = Config::get($this->referentiel.'.baseImages');
123
		$projets[] = Config::get($this->referentiel.'.baseImagesSupp');
124
		foreach ($projets as $projet) {
125
			if ($projet != "") {
1115 mathias 126
				if ($projet == "cel") {
127
					$this->images->setApi(Eflore::API_EFLORE); // prêt à passer à API_DEL
128
				} else {
129
					$this->images->setApi(Eflore::API_EFLORE);
130
				}
955 delphine 131
				$images = $this->initialiserPhotos($projet);
132
				$this->formaterListePhotos($projet, $images);
133
				$this->formaterMetaPhotos($projet);
621 mathilde 134
			}
955 delphine 135
		}
621 mathilde 136
	}
1123 mathias 137
 
138
	public function getPhotosSixOrganes() {
139
		$organes = array(
140
				'fleur' => array(),
141
				'feuille' => array(),
142
				'fruit' => array(),
143
				'ecorce' => array(),
144
				'port' => array(),
145
				'rameau' => array());
146
		$nnr = $this->nomCourant->getNnr();
147
		$infosOrganes = $this->images->getInfosMeilleuresImagesParTag($nnr, array_keys($organes), Eflore::PROTOCOLE_CAPITALISATION, 6, 'CRX2S');
148
		$vide = true;
149
		foreach ($infosOrganes as $tag => $organe) {
150
			$organes[$tag] = $organe;
151
			$nbImages = count($organe);
152
			if ($nbImages != 0) {
153
				$vide = false;
154
				for ($i = 6; $i > $nbImages; $i--) {
155
					$organes[$tag][] = null;
156
				}
157
			}
158
		}
159
		if ($vide) {
160
			$organes = array();
161
		}
162
		return $organes;
163
	}
164
 
165
	public function getPhotosOrganes() {
166
		$organes = array(
167
				'fleur' => array(),
168
				'feuille' => array(),
169
				'fruit' => array(),
170
				'ecorce' => array(),
171
				'port' => array(),
172
				'rameau' => array());
173
		$nnr = $this->nomCourant->getNnr();
174
		$infosOrganes = $this->images->getInfosMeilleuresImagesParTag($nnr, array_keys($organes), Eflore::PROTOCOLE_CAPITALISATION, 1);
175
		$vide = true;
176
		foreach ($infosOrganes as $tag => $organe) {
177
			$nbImages = count($organe);
178
			// une image par organe seulement
179
			$organes[$tag] = array_pop($organe);
180
			if ($nbImages != 0) {
181
				$vide = false;
182
			}
183
		}
184
		if ($vide) {
185
			$organes = array();
186
		}
187
		$this->donnees['organes'] = $organes;
188
	}
189
 
190
	public function getPhotosCaracteresIdentification() {
191
		$caracteres = array();
192
		$nnr = $this->nomCourant->getNnr();
193
		$infosCaracteres = $this->images->getInfosMeilleuresImagesParTag($nnr, array_keys($organes), Eflore::PROTOCOLE_CARACTERES, 3);
194
		if (! empty($infosCaracteres) && ! empty($infosCaracteres[''])) { // le tag est vide, ici
195
			$caracteres = $infosCaracteres[''];
196
		}
197
		$this->donnees['caracteres'] = $caracteres;
198
	}
1088 raphael 199
 
200
	// XXX: webservice:
201
	// /service:eflore:0.1/cel/images?masque.nn=XXX&referentiel=bdtfx&retour.format=CS&navigation.limite=801
955 delphine 202
	private function initialiserPhotos($projet) {
203
		$this->images->setProjet($projet);
448 delphine 204
		$nnr = $this->nomCourant->getNnr();
1123 mathias 205
		$ret = $this->images->getInfosImagesParIdsNoms(array($nnr));
206
		return $ret;
955 delphine 207
	}
208
 
209
	private function formaterListePhotos($projet, $images) {
210
		foreach ($images as $idImg => $img) {
211
			$infosImg = array();
212
			$infosImg['src'] = $img['binaire.href'];
213
			$infosImg['nomSci'] = $img['determination.nom_sci'];
214
			$infosImg['station'] = $img['station.libelle'];
215
			$infosImg['date'] = $this->formaterDateImg($img['date']);
216
			$infosImg['auteur'] = $img['auteur.libelle'];
217
			if ($projet == "cel") {
218
				$infosImg['urlDetailImg'] = $this->appUrls->obtenirUrlPopUpIllustrations($idImg);
219
				$infosImg['urlContact'] = $this->appUrls->obtenirUrlPopUpContact($img['auteur.id'], $idImg);
1114 aurelien 220
				$infosImg['urlProfil'] = $this->appUrls->obtenirUrlProfilAnnuaire($img['auteur.id']);
221
				$infosImg['urlMauvaiseIdentification'] =  $this->appUrls->obtenirUrlMauvaiseIdentification($img['observation.id']);
955 delphine 222
			}
223
			$this->donnees[$projet]['images'][$idImg] = $infosImg;
515 jpm 224
		}
955 delphine 225
	}
226
 
227
	private function formaterMetaPhotos($projet) {
228
		$this->meta->setProjet($projet);
339 aurelien 229
		$meta = $this->meta->getMetaDonnees();
1130 aurelien 230
		$titreMeta = $meta[0];
231
		$this->donnees[$projet]['meta'] = $titreMeta;
955 delphine 232
		$this->donnees[$projet]['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
339 aurelien 233
	}
697 mathilde 234
 
955 delphine 235
 
236
 
697 mathilde 237
	public function getCelExport() {
238
		$cel = array();
239
		$this->images->setProjet('cel');
240
		$nnr = $this->nomCourant->getNnr();
241
		$img = $this->images->getUrlPremiereImageParIdsNoms(array($nnr));
242
		if($img) {
243
			$img = array_values($img);
244
			$cel['images']['src'] = $img[0]['binaire.href'];
245
			$cel['images']['nomSci'] = $img[0]['determination.nom_sci'];
978 aurelien 246
			$cel['images']['station'] = $img[0]['station.libelle'];
697 mathilde 247
			$cel['images']['date'] = $this->formaterDateImg($img[0]['date']);
248
			$cel['images']['auteur'] = $img[0]['auteur.libelle'];
249
			$this->meta->setProjet('cel');
250
			$meta = $this->meta->getMetaDonnees();
1130 aurelien 251
			$cel['meta'] = $meta[0];
697 mathilde 252
			$cel['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('cel');
253
		}
254
		return $cel;
255
	}
256
 
497 jpm 257
	private function formaterDateImg($date) {
258
		$dateFmt = $date;
978 aurelien 259
		if ($date == '' || $date == null || $date == '0000-00-00' || $date == '1970-01-01 01:01:01') {
1019 raphael 260
			return 'inconnue';
497 jpm 261
		}
1019 raphael 262
		$time = strtotime($date);
263
		if(!$time) {
264
			/* TODO: php -r "echo strtotime('1891-00-00 00:00:00');"
265
			   TODO: fixer le template pour affiche "en l'année X", plutôt que "le X"
266
			   si FALSE pour avant 1901: problème php
267
			   On retourne alors simplement l'année.
268
			   si correction, ne pas oublier modules/popup_illustrations/PopupIllustrations.php */
269
			$dateFmt = explode('-', $date);
270
			return $dateFmt[0];
271
		}
272
		return strftime('%e %B %Y', strtotime($date));
497 jpm 273
	}
274
 
955 delphine 275
	private function formaterNomSci($nom) {
276
		$nomFmt = $nom;
277
		if (is_null($nom) || $nom == '') {
278
			$nomFmt = 'inconnu';
279
		}
280
		return $nomFmt;
497 jpm 281
	}
238 delphine 282
}
283
?>