Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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