Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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