Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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