Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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