Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 1452 | Rev 1480 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
71 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 Fiche extends aControleur {
291 jpm 16
 
230 delphine 17
	private $onglet = 'synthese';
291 jpm 18
	private $parametres = array();
19
	private $conteneur = null;
238 delphine 20
	private $num_nom = 0;
376 delphine 21
	private $nom_retenu = '';
1164 mathias 22
	private $nom_selectionne = null;
23
	private $nom_appele_html = null; // le nom et l'auteur par lesquels on est arrivés sur la fiche, en cas de synonymie
651 mathilde 24
	private $url;
291 jpm 25
 
26
 
216 delphine 27
	public function initialiser() {
28
		$this->capturerParametres();
500 jpm 29
		$this->conteneur = new Conteneur($this->parametres);
1164 mathias 30
		$nom_courant = $this->conteneur->getNomCourant();
31
		$this->nom_selectionne = $nom_courant->getNomSelectionne();
651 mathilde 32
		$this->url = $this->conteneur->getAppUrls();
1164 mathias 33
		$this->nom_retenu = $nom_courant->getNomRetenu();
34
		if ($this->nom_retenu->get('id') != $this->nom_selectionne->get('id')) {
35
			$this->nom_appele_html = $this->nom_selectionne->get('nom_sci_html').' '.$this->nom_selectionne->get('auteur');
36
		}
238 delphine 37
		spl_autoload_register(array($this, 'chargerClassesOnglets'));
216 delphine 38
	}
291 jpm 39
 
40
	private function capturerParametres() {
41
		if (isset($_GET['num_nom'])) {
42
			$this->parametres['num_nom'] = $_GET['num_nom'];
43
		}
44
		if (isset($_GET['nom'])) {
45
			$this->parametres['nom'] = $_GET['nom'];
46
		}
47
		if (isset($_GET['type_nom'])) {
48
			$this->parametres['type_nom'] = $_GET['type_nom'];
49
		}
395 aurelien 50
		if (isset($_GET['referentiel'])) {
51
			$this->parametres['referentiel'] = $_GET['referentiel'];
939 aurelien 52
			Registre::set('parametres.referentiel', $_GET['referentiel']);
395 aurelien 53
		}
291 jpm 54
		if (isset($_GET['niveau'])) {
55
			Registre::set('parametres.niveau', $_GET['niveau']);
56
		}
57
		if (isset($_GET['onglet'])) {
58
			$this->onglet = $_GET['onglet'];
59
		}
60
	}
61
 
238 delphine 62
	private function chargerClassesOnglets($classe) {
63
		$base = dirname(__FILE__).DS;
64
		$cheminFormateurs = $base.'formateurs'.DS;
65
		$dossiers = array($base, $cheminFormateurs);
66
		foreach ($dossiers as $chemin) {
67
			$fichierATester = $chemin.$classe.'.php';
68
			if (file_exists($fichierATester)) {
69
				include_once $fichierATester;
70
				return null;
71
			}
72
		}
73
	}
291 jpm 74
 
71 delphine 75
	public function executerActionParDefaut() {
76
		$this->executerFiche();
77
	}
291 jpm 78
 
141 delphine 79
	public function executerFiche(){
1105 jpm 80
 
525 gduche 81
		$squelette = 'fiche_'.$this->onglet;
1105 jpm 82
 
525 gduche 83
		//Gestion du niveau
545 gduche 84
		$niveau = isset($_GET['niveau']) ? $_GET['niveau'] : 2;
525 gduche 85
		if ($this->onglet == 'synthese' && $niveau != null) {
86
			$squelette .= '_niveau'.$niveau;
87
		}
1105 jpm 88
 
979 delphine 89
		// Récupération parametres et données
1144 raphael 90
		$donnees = array_merge($this->obtenirDonnees(), $this->parametres);
979 delphine 91
		$donnees['i18n'] = I18n::get('Fiche');
1144 raphael 92
		$verna = isset($donnees['ethnobotanique']['nomsVerna']) && count($donnees['ethnobotanique']['nomsVerna']) ? $donnees['ethnobotanique']['nomsVerna'][0]['nom_vernaculaire'] : "";
1105 jpm 93
 
979 delphine 94
		// titre, description et tag de la page
95
		$this->setSortie('titre', $this->nom_retenu->get('nom_sci'));
1144 raphael 96
        // ( <meta name="description" ...> )
97
		$this->setSortie('description', sprintf("Fiche descriptive de %s %s (%s)", $this->nom_retenu->get('nom_sci'), $verna ? ('/ ' . $verna) : '', $donnees['description']['titre']));
98
 
979 delphine 99
		$this->setSortie('tags', $this->nom_retenu->get('nom_sci').",".$verna.
100
			",botanique,plante,description,ecologie,reconnaitre,fiche espece");
1105 jpm 101
 
1282 aurelien 102
		$nom_sci_html = $this->nom_retenu->get('nom_sci_html');
1477 mathias 103
		// la recherche avancée à partir du clic sur le nom ne fonctionne pas sur les hybrides
104
		$nom_sci_html = strpos($nom_sci_html, 'class="hyb"') === false ?
1282 aurelien 105
							$this->formaterLiensNomsHtml($nom_sci_html) : $nom_sci_html;
106
 
979 delphine 107
		// titre de la fiche
1282 aurelien 108
		$donnees['nom_retenu_html'] = $nom_sci_html.' '.$this->nom_retenu->get('auteur');
1280 aurelien 109
 
982 delphine 110
		$donnees['nom_retenu'] = $this->nom_retenu->get('nom_sci');
1375 mathias 111
		$donnees['num_tax'] = $this->nom_selectionne->get('num_taxonomique');
1164 mathias 112
		$donnees['nom_appele_html'] = $this->nom_appele_html;
1277 aurelien 113
		$famille = $this->nom_retenu->getTaxonSupRang('180');
114
		$donnees['lien_recherche_famille'] = html_entity_decode($this->url->obtenirUrlRechercheAvancee(array("fam" => $famille)));
115
		$donnees['famille'] = $famille;
116
 
979 delphine 117
		$donnees['nom_vernaculaire'] = $verna;
1105 jpm 118
 
979 delphine 119
		// moteur de recherche
291 jpm 120
		$this->executerAction('Recherche', 'executerAccueil', $this->parametres);
1105 jpm 121
 
979 delphine 122
		// page synthese
291 jpm 123
		$blocs_niveaux = $this->conteneur->getParametreTableau('blocs_fiche_defaut');
219 delphine 124
		$donnees['blocs'] = '"'.str_replace('|', '","', $blocs_niveaux[Registre::get('parametres.niveau')]).'"';
291 jpm 125
 
979 delphine 126
		// onglet
238 delphine 127
		$donnees['onglet'] = $this->onglet;
1477 mathias 128
		$donnees['niveau'] = $niveau;
1273 aurelien 129
		$donnees['base_url_onglets'] = Config::get('base_url_application_onglets');
130
 
1243 aurelien 131
		$taxons = new Taxons();
132
		$referentiel = $this->conteneur->getParametre('referentiel');
1452 mathias 133
 
134
		$donnees['prod'] = Config::get('info.prod');
135
 
1243 aurelien 136
		$donnees['permalien_num_nom'] = $taxons->getUrlPermalienNumNom($referentiel, 1, $this->conteneur->getNomCourant()->getNns());
137
		$donnees['entete'] = $this->getVue('fiche_entete', $donnees);
525 gduche 138
		$donnees['contenu_onglet'] = $this->getVue($squelette, $donnees);
1452 mathias 139
 
545 gduche 140
		$this->setSortie(self::RENDU_CORPS, $this->getVue('fiche_accueil_niveau'.$niveau, $donnees), true);
709 aurelien 141
		$this->ajouterPiedDePage();
71 delphine 142
	}
1277 aurelien 143
 
1381 aurelien 144
	public function executerTemplateAjax() {
1477 mathias 145
		$classe = ucfirst($this->onglet);
1381 aurelien 146
		$onglet = new $classe($this->conteneur);
147
		$action = 'obtenir'.ucfirst($_GET['sous_action']);
148
		$html_ajax = $onglet->$action();
149
		header('Content-type : text/html');
1477 mathias 150
		echo $html_ajax;
1381 aurelien 151
		exit;
152
	}
153
 
1280 aurelien 154
	private function formaterLiensNomsHtml($nom_sci_html) {
1277 aurelien 155
		$app_urls = new AppUrls();
156
		$params = array();
157
		$classes_recherche = array("fam" => "fam", "gen" => "gen", "sp" => "sp", "infra-sp" => "ssp");
158
 
1477 mathias 159
		$doc = new DOMDocument();
160
		$doc->loadHTML($nom_sci_html);
1277 aurelien 161
		$spans = $doc->getElementsByTagName('span');
1280 aurelien 162
		$abbrs = $doc->getElementsByTagName('abbr');
1277 aurelien 163
 
164
		$params_subsp = array();
165
 
166
		$i18n =  I18n::get('Fiche');
1280 aurelien 167
 
1477 mathias 168
		//TODO: c'est un peu moche, la fonction est surement factorisable
169
		if ($spans->length > 0) {
1277 aurelien 170
			foreach($spans as $span) {
171
				$classe = $span->getAttribute('class');
172
				if(in_array($classe, array_keys($classes_recherche))) {
173
 
174
					$params[$classes_recherche[$classe]] = $span->nodeValue;
1477 mathias 175
					if($classe == "sp") {
176
						$params_subsp = $params;
1277 aurelien 177
					}
178
					$lien_tpl = html_entity_decode($this->url->obtenirUrlRechercheAvancee($params));
179
					$texte_lien = $span->nodeValue;
180
 
181
					$span->nodeValue = "";
182
					$text = $doc->createElement('a', $texte_lien);
183
					$text->setAttribute('href', $lien_tpl);
184
					$text->setAttribute('title', $i18n["lien-recherche-hier-".$classe]);
1477 mathias 185
					$text->setAttribute('class', 'lien_recherche_hier');
1277 aurelien 186
					$span->appendChild($text);
187
				}
1477 mathias 188
			}
1277 aurelien 189
		}
1280 aurelien 190
 
191
		if ($abbrs->length > 0) {
192
			foreach($abbrs as $abbr) {
193
				$classe = $abbr->getAttribute('class');
194
				$params_subsp["type"] = $abbr->nodeValue;
1477 mathias 195
				$lien_tpl = html_entity_decode($this->url->obtenirUrlRechercheAvancee($params_subsp));
196
				$texte_lien = $abbr->nodeValue;
197
 
198
				$abbr->nodeValue = "";
199
				$text = $doc->createElement('a', $texte_lien);
200
				$text->setAttribute('href', $lien_tpl);
201
				$text->setAttribute('title', $i18n["lien-recherche-hier-ssp"]);
202
				$text->setAttribute('class', 'lien_recherche_hier');
1280 aurelien 203
				$abbr->appendChild($text);
204
			}
205
		}
1277 aurelien 206
 
207
		return $doc->SaveXml();
208
	}
1280 aurelien 209
 
210
	private function formaterLienRechercheSurPartieNomSci(&$noeud, &$params) {
211
 
212
	}
291 jpm 213
 
651 mathilde 214
	public function ajouterLienModuleExport() {
677 mathilde 215
		$donnees['lien'] = $this->url->obtenirUrlPdfExport($this->parametres['num_nom']);
709 aurelien 216
		$export = $this->getVue('fiche_pdf_lien', $donnees);
217
		return $export;
651 mathilde 218
	}
1105 jpm 219
 
709 aurelien 220
	public function ajouterPiedDePage() {
221
		$description = new Description($this->conteneur);
1145 raphael 222
		$taxons = new Taxons();
709 aurelien 223
		$referentiel = $this->conteneur->getParametre('referentiel');
1105 jpm 224
		$urlMobile = $this->url->obtenirUrlMobile($this->parametres['num_nom']);
983 aurelien 225
		$donnees = array('wikipedia' => $description->getUrlWikipedia(),
990 isa 226
			'export_pdf' => $this->ajouterLienModuleExport(),
227
			'permalien_num_nom' => $taxons->getUrlPermalienNumNom($referentiel, 1, $this->conteneur->getNomCourant()->getNns()),
228
			'permalien_taxon' => $taxons->getUrlPermalienTaxon($referentiel, 1, $this->conteneur->getNomCourant()->getNt()),
229
			'nn' => $this->conteneur->getNomCourant()->getNns(),
230
			'nt' => $this->conteneur->getNomCourant()->getNt(),
1224 delphine 231
			'nnr' => $this->conteneur->getNomCourant()->getNnr(),
232
			'inpn' => $this->conteneur->getNomCourant()->getInpn(),
990 isa 233
			'wiki' => $description->getLienWikini(),
234
			'nom_retenu' => $this->nom_retenu->get('nom_sci'),
235
			'mobile' => $urlMobile,
1477 mathias 236
			'baseUrlIco' => Registre::get('eFlore.urlBaseDossier')->getUrl() . '/',
990 isa 237
			'qr_code_png' => $this->obtenirUrlQrCode($urlMobile)
238
		);
709 aurelien 239
		$this->setSortie(self::RENDU_CORPS, $this->getVue('fiche_pied_page', $donnees), true);
240
	}
1105 jpm 241
 
990 isa 242
	private function obtenirUrlQrCode($urlMobile) {
243
		$qr = $this->conteneur->getQrCode();
244
		$qr->setUrl(htmlspecialchars_decode($urlMobile));
1299 mathias 245
		$idQrCode = $this->conteneur->getParametre('referentiel') . '-' .$this->conteneur->getNomCourant()->getNns();
990 isa 246
		$urlQrCode = $qr->dessiner($idQrCode);
247
		return $urlQrCode;
248
	}
1105 jpm 249
 
230 delphine 250
	public function executerOnglet(){
913 aurelien 251
		$this->viderSorties();
238 delphine 252
		$donnees = $this->obtenirDonnees();
1243 aurelien 253
		$squelette_onglet = $this->onglet;
254
		// onglet
1255 aurelien 255
		$donnees['i18n'] = I18n::get('Fiche');
1243 aurelien 256
		$donnees['onglet'] = $this->onglet;
257
		$taxons = new Taxons();
258
		$referentiel = $this->conteneur->getParametre('referentiel');
259
		$donnees['permalien_num_nom'] = $taxons->getUrlPermalienNumNom($referentiel, 1, $this->conteneur->getNomCourant()->getNns());
1452 mathias 260
		$donnees['prod'] = Config::get('info.prod');
261
 
1243 aurelien 262
		// cas particulier de l'onglet synthese qui possède 3 niveaux
263
		// et dont le nom n'est donc pas directement celui de son squelette
264
		if($this->onglet == "synthese") {
265
			$niveau = isset($_GET['niveau']) ? $_GET['niveau'] : 2;
266
			$squelette_onglet .= '_niveau'.$niveau;
267
			$entete = $this->getVue('fiche_entete', $donnees);
268
			$vue = $entete.$this->getVue('fiche_'.$squelette_onglet, $donnees);
269
		} else {
270
			$vue = $this->getVue('fiche_'.$squelette_onglet, $donnees);
271
		}
272
 
291 jpm 273
		header('Content-type: text/html');
1243 aurelien 274
		$this->setSortie(self::RENDU_CORPS, $vue);
230 delphine 275
	}
291 jpm 276
 
277
	private function obtenirDonnees() {
278
		$classe = ucfirst($this->onglet);
1058 raphael 279
		$onglet = new $classe($this->conteneur); // grep-friendly: new Synthese()
1144 raphael 280
		return $onglet->obtenirDonnees();
238 delphine 281
	}
71 delphine 282
}
283
?>