Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 1115 | Rev 1130 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1115 Rev 1123
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Classe mère du module Liste.
4
 * Classe mère du module Liste.
5
 *
5
 *
6
 * @category	PHP 5.2
6
 * @category	PHP 5.2
7
 * @package		eflore-consultation
7
 * @package		eflore-consultation
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @author		Delphine CAUQUIL <delphine@tela-botanica.org>
9
 * @author		Delphine CAUQUIL <delphine@tela-botanica.org>
10
 * @copyright	2011 Tela-Botanica
10
 * @copyright	2011 Tela-Botanica
11
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
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
12
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
13
 * @version		$Id$
13
 * @version		$Id$
14
 */
14
 */
15
class Illustrations extends aControleur {
15
class Illustrations extends aControleur {
16
 
16
 
17
	private $conteneur = null;
17
	private $conteneur = null;
18
	private $nomCourant = null;
18
	private $nomCourant = null;
19
	private $images = null;
19
	private $images = null;
20
	private $appUrls = null;
20
	private $appUrls = null;
21
	private $meta = null;
21
	private $meta = null;
22
	private $referentiel = 'bdtfx';
22
	private $referentiel = 'bdtfx';
23
	private $donnees = array();
23
	private $donnees = array();
24
 
24
 
25
	public function __construct(Conteneur $conteneur) {
25
	public function __construct(Conteneur $conteneur) {
26
		$this->conteneur = $conteneur;
26
		$this->conteneur = $conteneur;
27
		$this->nomCourant = $this->conteneur->getNomCourant();
27
		$this->nomCourant = $this->conteneur->getNomCourant();
28
		$this->referentiel = $this->conteneur->getParametre('referentiel');
28
		$this->referentiel = $this->conteneur->getParametre('referentiel');
29
		$this->images = $this->conteneur->getApiImages();
29
		$this->images = $this->conteneur->getApiImages();
30
		$this->appUrls = $this->conteneur->getAppUrls();
30
		$this->appUrls = $this->conteneur->getAppUrls();
31
		$this->meta = $this->conteneur->getApiMetaDonnees();
31
		$this->meta = $this->conteneur->getApiMetaDonnees();
32
	}
32
	}
33
 
33
 
34
	public function obtenirDonnees() {
34
	public function obtenirDonnees() {
35
		$this->donnees['nt'] = $this->nomCourant->getNt();
35
		$this->donnees['nt'] = $this->nomCourant->getNt();
-
 
36
		$this->donnees['nnr'] = $this->nomCourant->getNnr();
36
		$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
37
		$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
-
 
38
		$infosNomRetenu = $this->nomCourant->getNomRetenu()->getInfos();
-
 
39
		$this->donnees['nomComplet'] = $infosNomRetenu['nom_complet'];
37
		$this->getPhotos();
40
		$this->getPhotos();
38
		$this->getDessin();
41
		$this->getDessin();
-
 
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']));
39
		return $this->donnees;
48
		return $this->donnees;
40
	}
49
	}
41
	
50
	
42
	public function obtenirDonneesExport() {
51
	public function obtenirDonneesExport() {
43
		$this->donnees['nt'] = $this->nomCourant->getNt();
52
		$this->donnees['nt'] = $this->nomCourant->getNt();
44
		$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
53
		$this->donnees['nomSciRetenu'] = $this->nomCourant->getNomRetenu()->get('nom_sci_html');
45
		$this->donnees['cel'] = $this->getCelExport();
54
		$this->donnees['cel'] = $this->getCelExport();
46
		$this->donnees['coste'] = $this->getCoste();
55
		$this->donnees['coste'] = $this->getCoste();
47
		return $this->donnees;
56
		return $this->donnees;
48
	}
57
	}
49
 
58
 
50
	public function getBloc() {
59
	public function getBloc() {
51
		$this->donnees = $this->getPhoto('cel');
60
		$this->donnees = $this->getPhoto('cel');
52
		if (empty($this->donnees)) {
61
		if (empty($this->donnees)) {
53
			$infos_image = $this->getDessin();
62
			$infos_image = $this->getDessin();
54
			if (empty($infos_image) == false ){
63
			if (empty($infos_image) == false ){
55
				$this->donnees['imageUrl'] =  array_shift($infos_image['images']);
64
				$this->donnees['imageUrl'] =  array_shift($infos_image['images']);
56
			}
65
			}
57
		}
66
		}
58
		if (empty($this->donnees)) {
67
		if (empty($this->donnees)) {
59
			$this->donnees = $this->getPhoto('photoflora');
68
			$this->donnees = $this->getPhoto('photoflora');
60
		}
69
		}
61
		return $this->donnees;
70
		return $this->donnees;
62
	}
71
	}
63
	
72
	
64
	
73
	
65
	public function getPhoto($source) {
74
	public function getPhoto($source) {
66
		$donnees = array();
75
		$donnees = array();
67
		$this->images->setProjet($source);
76
		$this->images->setProjet($source);
68
		$nnr = $this->nomCourant->getNnr();
77
		$nnr = $this->nomCourant->getNnr();
69
		$infos_image = $this->images->setApi(Eflore::API_EFLORE)->getInfosPremiereImageParIdsNoms(array($nnr));
78
		$infos_image = $this->images->setApi(Eflore::API_EFLORE)->getInfosPremiereImageParIdsNoms(array($nnr));
70
		if ($infos_image != array()) {
79
		if ($infos_image != array()) {
71
			$image = array_shift($infos_image);
80
			$image = array_shift($infos_image);
72
			$donnees['imageUrl'] =  $image['binaire.href'];
81
			$donnees['imageUrl'] =  $image['binaire.href'];
73
		}
82
		}
74
		return $donnees;
83
		return $donnees;
75
	}
84
	}
76
 
85
 
77
	public function getCoste() {
86
	public function getCoste() {
78
		$coste = array();
87
		$coste = array();
79
		$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
88
		$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
80
		$this->images->setProjet('coste');
89
		$this->images->setProjet('coste');
81
		$this->images->setNnTaxon($tax);
90
		$this->images->setNnTaxon($tax);
82
		$costeImg = $this->images->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
91
		$costeImg = $this->images->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
83
		foreach ($costeImg as $infos) {
92
		foreach ($costeImg as $infos) {
84
			$coste['images'][] = $infos['binaire.href'];
93
			$coste['images'][] = $infos['binaire.href'];
85
		}
94
		}
86
		$this->meta->setProjet('coste');
95
		$this->meta->setProjet('coste');
87
		$meta = $this->meta->getMetaDonnees();
96
		$meta = $this->meta->getMetaDonnees();
88
		$coste['meta']['titre']= $meta[0]['titre'];
97
		$coste['meta']['titre']= $meta[0]['titre'];
89
		$coste['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('coste');
98
		$coste['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('coste');
90
		return $coste;
99
		return $coste;
91
	}
100
	}
92
 
101
 
93
	public function getDessin() {
102
	public function getDessin() {
94
		$projet = Config::get($this->referentiel.'.baseDessins');
103
		$projet = Config::get($this->referentiel.'.baseDessins');
95
		if ($projet != "") {
104
		if ($projet != "") {
96
			$dessin = array();
105
			$dessin = array();
97
			$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
106
			$tax = $this->nomCourant->getNomRetenu()->get('num_taxonomique');
98
			$this->images->setProjet($projet);
107
			$this->images->setProjet($projet);
99
			$this->images->setNnTaxon($tax);
108
			$this->images->setNnTaxon($tax);
100
			$costeImg = $this->images->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
109
			$costeImg = $this->images->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
101
				foreach ($costeImg as $infos) {
110
				foreach ($costeImg as $infos) {
102
					$dessin['images'][] = $infos['binaire.href'];
111
					$dessin['images'][] = $infos['binaire.href'];
103
				}
112
				}
104
			$this->meta->setProjet('coste');
113
			$this->meta->setProjet('coste');
105
			$meta = $this->meta->getMetaDonnees();
114
			$meta = $this->meta->getMetaDonnees();
106
			$dessin['meta']['titre']= $meta[0]['titre'];
115
			$dessin['meta']['titre']= $meta[0]['titre'];
107
			$dessin['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
116
			$dessin['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
108
			$this->donnees['coste'] = $dessin;
117
			$this->donnees['coste'] = $dessin;
109
		}
118
		}
110
	}
119
	}
111
	
120
	
112
	public function getPhotos() {
121
	public function getPhotos() {
113
		$projets[] = Config::get($this->referentiel.'.baseImages');
122
		$projets[] = Config::get($this->referentiel.'.baseImages');
114
		$projets[] = Config::get($this->referentiel.'.baseImagesSupp');
123
		$projets[] = Config::get($this->referentiel.'.baseImagesSupp');
115
		foreach ($projets as $projet) {
124
		foreach ($projets as $projet) {
116
			if ($projet != "") {
125
			if ($projet != "") {
117
				if ($projet == "cel") {
126
				if ($projet == "cel") {
118
					$this->images->setApi(Eflore::API_EFLORE); // prêt à passer à API_DEL
127
					$this->images->setApi(Eflore::API_EFLORE); // prêt à passer à API_DEL
119
				} else {
128
				} else {
120
					$this->images->setApi(Eflore::API_EFLORE);
129
					$this->images->setApi(Eflore::API_EFLORE);
121
				}
130
				}
122
				$images = $this->initialiserPhotos($projet);
131
				$images = $this->initialiserPhotos($projet);
123
				$this->formaterListePhotos($projet, $images);
132
				$this->formaterListePhotos($projet, $images);
124
				$this->formaterMetaPhotos($projet);
133
				$this->formaterMetaPhotos($projet);
125
			}
134
			}
126
		}
135
		}
127
	}
136
	}
-
 
137
	
-
 
138
	public function getPhotosSixOrganes() {
-
 
139
		$organes = array(
-
 
140
				'fleur' => array(),
-
 
141
				'feuille' => array(),
-
 
142
				'fruit' => array(),
-
 
143
				'ecorce' => array(),
-
 
144
				'port' => array(),
-
 
145
				'rameau' => array());
-
 
146
		$nnr = $this->nomCourant->getNnr();
-
 
147
		$infosOrganes = $this->images->getInfosMeilleuresImagesParTag($nnr, array_keys($organes), Eflore::PROTOCOLE_CAPITALISATION, 6, 'CRX2S');
-
 
148
		$vide = true;
-
 
149
		foreach ($infosOrganes as $tag => $organe) {
-
 
150
			$organes[$tag] = $organe;
-
 
151
			$nbImages = count($organe);
-
 
152
			if ($nbImages != 0) {
-
 
153
				$vide = false;
-
 
154
				for ($i = 6; $i > $nbImages; $i--) {
-
 
155
					$organes[$tag][] = null;
-
 
156
				}
-
 
157
			}
-
 
158
		}
-
 
159
		if ($vide) {
-
 
160
			$organes = array();
-
 
161
		}
-
 
162
		return $organes;
-
 
163
	}
-
 
164
	
-
 
165
	public function getPhotosOrganes() {
-
 
166
		$organes = array(
-
 
167
				'fleur' => array(),
-
 
168
				'feuille' => array(),
-
 
169
				'fruit' => array(),
-
 
170
				'ecorce' => array(),
-
 
171
				'port' => array(),
-
 
172
				'rameau' => array());
-
 
173
		$nnr = $this->nomCourant->getNnr();
-
 
174
		$infosOrganes = $this->images->getInfosMeilleuresImagesParTag($nnr, array_keys($organes), Eflore::PROTOCOLE_CAPITALISATION, 1);
-
 
175
		$vide = true;
-
 
176
		foreach ($infosOrganes as $tag => $organe) {
-
 
177
			$nbImages = count($organe);
-
 
178
			// une image par organe seulement
-
 
179
			$organes[$tag] = array_pop($organe);
-
 
180
			if ($nbImages != 0) {
-
 
181
				$vide = false;
-
 
182
			}
-
 
183
		}
-
 
184
		if ($vide) {
-
 
185
			$organes = array();
-
 
186
		}
-
 
187
		$this->donnees['organes'] = $organes;
-
 
188
	}
-
 
189
	
-
 
190
	public function getPhotosCaracteresIdentification() {
-
 
191
		$caracteres = array();
-
 
192
		$nnr = $this->nomCourant->getNnr();
-
 
193
		$infosCaracteres = $this->images->getInfosMeilleuresImagesParTag($nnr, array_keys($organes), Eflore::PROTOCOLE_CARACTERES, 3);
-
 
194
		if (! empty($infosCaracteres) && ! empty($infosCaracteres[''])) { // le tag est vide, ici
-
 
195
			$caracteres = $infosCaracteres[''];
-
 
196
		}
-
 
197
		$this->donnees['caracteres'] = $caracteres;
-
 
198
	}
128
 
199
 
129
	// XXX: webservice:
200
	// XXX: webservice:
130
	// /service:eflore:0.1/cel/images?masque.nn=XXX&referentiel=bdtfx&retour.format=CS&navigation.limite=801
201
	// /service:eflore:0.1/cel/images?masque.nn=XXX&referentiel=bdtfx&retour.format=CS&navigation.limite=801
131
	private function initialiserPhotos($projet) {
202
	private function initialiserPhotos($projet) {
132
		$this->images->setProjet($projet);
203
		$this->images->setProjet($projet);
133
		$nnr = $this->nomCourant->getNnr();
204
		$nnr = $this->nomCourant->getNnr();
134
		return $this->images->getInfosImagesParIdsNoms(array($nnr));
205
		$ret = $this->images->getInfosImagesParIdsNoms(array($nnr));
-
 
206
		return $ret;
135
	}
207
	}
136
	
208
	
137
	private function formaterListePhotos($projet, $images) {
209
	private function formaterListePhotos($projet, $images) {
138
		foreach ($images as $idImg => $img) {
210
		foreach ($images as $idImg => $img) {
139
			$infosImg = array();
211
			$infosImg = array();
140
			$infosImg['src'] = $img['binaire.href'];
212
			$infosImg['src'] = $img['binaire.href'];
141
			$infosImg['nomSci'] = $img['determination.nom_sci'];
213
			$infosImg['nomSci'] = $img['determination.nom_sci'];
142
			$infosImg['station'] = $img['station.libelle'];
214
			$infosImg['station'] = $img['station.libelle'];
143
			$infosImg['date'] = $this->formaterDateImg($img['date']);
215
			$infosImg['date'] = $this->formaterDateImg($img['date']);
144
			$infosImg['auteur'] = $img['auteur.libelle'];
216
			$infosImg['auteur'] = $img['auteur.libelle'];
145
			if ($projet == "cel") {
217
			if ($projet == "cel") {
146
				$infosImg['urlDetailImg'] = $this->appUrls->obtenirUrlPopUpIllustrations($idImg);
218
				$infosImg['urlDetailImg'] = $this->appUrls->obtenirUrlPopUpIllustrations($idImg);
147
				$infosImg['urlContact'] = $this->appUrls->obtenirUrlPopUpContact($img['auteur.id'], $idImg);
219
				$infosImg['urlContact'] = $this->appUrls->obtenirUrlPopUpContact($img['auteur.id'], $idImg);
148
				$infosImg['urlProfil'] = $this->appUrls->obtenirUrlProfilAnnuaire($img['auteur.id']);
220
				$infosImg['urlProfil'] = $this->appUrls->obtenirUrlProfilAnnuaire($img['auteur.id']);
149
				$infosImg['urlMauvaiseIdentification'] =  $this->appUrls->obtenirUrlMauvaiseIdentification($img['observation.id']);
221
				$infosImg['urlMauvaiseIdentification'] =  $this->appUrls->obtenirUrlMauvaiseIdentification($img['observation.id']);
150
			}
222
			}
151
			$this->donnees[$projet]['images'][$idImg] = $infosImg;
223
			$this->donnees[$projet]['images'][$idImg] = $infosImg;
152
		}
224
		}
153
	}
225
	}
154
	
226
	
155
	private function formaterMetaPhotos($projet) {
227
	private function formaterMetaPhotos($projet) {
156
		$this->meta->setProjet($projet);
228
		$this->meta->setProjet($projet);
157
		$meta = $this->meta->getMetaDonnees();
229
		$meta = $this->meta->getMetaDonnees();
158
		$titreMeta = $meta[0]['titre'];
230
		$titreMeta = $meta[0]['titre'];
159
		$this->donnees[$projet]['meta']['titre'] = $titreMeta;
231
		$this->donnees[$projet]['meta']['titre'] = $titreMeta;
160
		$this->donnees[$projet]['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
232
		$this->donnees[$projet]['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees($projet);
161
	}
233
	}
162
	
234
	
163
	
235
	
164
	
236
	
165
	public function getCelExport() {
237
	public function getCelExport() {
166
		$cel = array();
238
		$cel = array();
167
		$this->images->setProjet('cel');
239
		$this->images->setProjet('cel');
168
		$nnr = $this->nomCourant->getNnr();
240
		$nnr = $this->nomCourant->getNnr();
169
		$img = $this->images->getUrlPremiereImageParIdsNoms(array($nnr));
241
		$img = $this->images->getUrlPremiereImageParIdsNoms(array($nnr));
170
		if($img) {
242
		if($img) {
171
			$img = array_values($img);
243
			$img = array_values($img);
172
			$cel['images']['src'] = $img[0]['binaire.href'];
244
			$cel['images']['src'] = $img[0]['binaire.href'];
173
			$cel['images']['nomSci'] = $img[0]['determination.nom_sci'];
245
			$cel['images']['nomSci'] = $img[0]['determination.nom_sci'];
174
			$cel['images']['station'] = $img[0]['station.libelle'];
246
			$cel['images']['station'] = $img[0]['station.libelle'];
175
			$cel['images']['date'] = $this->formaterDateImg($img[0]['date']);
247
			$cel['images']['date'] = $this->formaterDateImg($img[0]['date']);
176
			$cel['images']['auteur'] = $img[0]['auteur.libelle'];
248
			$cel['images']['auteur'] = $img[0]['auteur.libelle'];
177
			$this->meta->setProjet('cel');
249
			$this->meta->setProjet('cel');
178
			$meta = $this->meta->getMetaDonnees();
250
			$meta = $this->meta->getMetaDonnees();
179
			$titreMeta = $meta[0]['titre'];
251
			$titreMeta = $meta[0]['titre'];
180
			$cel['meta']['titre'] = $titreMeta;
252
			$cel['meta']['titre'] = $titreMeta;
181
			$cel['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('cel');
253
			$cel['meta']['url'] = $this->appUrls->obtenirUrlMetaDonnees('cel');
182
		}
254
		}
183
		return $cel;
255
		return $cel;
184
	}
256
	}
185
 
257
 
186
	private function formaterDateImg($date) {
258
	private function formaterDateImg($date) {
187
		$dateFmt = $date;
259
		$dateFmt = $date;
188
		if ($date == '' || $date == null || $date == '0000-00-00' || $date == '1970-01-01 01:01:01') {
260
		if ($date == '' || $date == null || $date == '0000-00-00' || $date == '1970-01-01 01:01:01') {
189
			return 'inconnue';
261
			return 'inconnue';
190
		}
262
		}
191
		$time = strtotime($date);
263
		$time = strtotime($date);
192
		if(!$time) {
264
		if(!$time) {
193
			/* TODO: php -r "echo strtotime('1891-00-00 00:00:00');"
265
			/* TODO: php -r "echo strtotime('1891-00-00 00:00:00');"
194
			   TODO: fixer le template pour affiche "en l'année X", plutôt que "le X"
266
			   TODO: fixer le template pour affiche "en l'année X", plutôt que "le X"
195
			   si FALSE pour avant 1901: problème php
267
			   si FALSE pour avant 1901: problème php
196
			   On retourne alors simplement l'année.
268
			   On retourne alors simplement l'année.
197
			   si correction, ne pas oublier modules/popup_illustrations/PopupIllustrations.php */
269
			   si correction, ne pas oublier modules/popup_illustrations/PopupIllustrations.php */
198
			$dateFmt = explode('-', $date);
270
			$dateFmt = explode('-', $date);
199
			return $dateFmt[0];
271
			return $dateFmt[0];
200
		}
272
		}
201
		return strftime('%e %B %Y', strtotime($date));
273
		return strftime('%e %B %Y', strtotime($date));
202
	}
274
	}
203
 
275
 
204
	private function formaterNomSci($nom) {
276
	private function formaterNomSci($nom) {
205
		$nomFmt = $nom;
277
		$nomFmt = $nom;
206
		if (is_null($nom) || $nom == '') {
278
		if (is_null($nom) || $nom == '') {
207
			$nomFmt = 'inconnu';
279
			$nomFmt = 'inconnu';
208
		}
280
		}
209
		return $nomFmt;
281
		return $nomFmt;
210
	}
282
	}
211
}
283
}
212
?>
284
?>