Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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