Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 1273 Rev 1277
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 Fiche extends aControleur {
15
class Fiche extends aControleur {
16
 
16
 
17
	private $onglet = 'synthese';
17
	private $onglet = 'synthese';
18
	private $parametres = array();
18
	private $parametres = array();
19
	private $conteneur = null;
19
	private $conteneur = null;
20
	private $num_nom = 0;
20
	private $num_nom = 0;
21
	private $nom_retenu = '';
21
	private $nom_retenu = '';
22
	private $nom_selectionne = null;
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
23
	private $nom_appele_html = null; // le nom et l'auteur par lesquels on est arrivés sur la fiche, en cas de synonymie
24
	private $url;
24
	private $url;
25
 
25
 
26
 
26
 
27
	public function initialiser() {
27
	public function initialiser() {
28
		$this->capturerParametres();
28
		$this->capturerParametres();
29
		$this->conteneur = new Conteneur($this->parametres);
29
		$this->conteneur = new Conteneur($this->parametres);
30
		$nom_courant = $this->conteneur->getNomCourant();
30
		$nom_courant = $this->conteneur->getNomCourant();
31
		$this->nom_selectionne = $nom_courant->getNomSelectionne();
31
		$this->nom_selectionne = $nom_courant->getNomSelectionne();
32
		$this->url = $this->conteneur->getAppUrls();
32
		$this->url = $this->conteneur->getAppUrls();
33
		$this->nom_retenu = $nom_courant->getNomRetenu();
33
		$this->nom_retenu = $nom_courant->getNomRetenu();
34
		if ($this->nom_retenu->get('id') != $this->nom_selectionne->get('id')) {
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');
35
			$this->nom_appele_html = $this->nom_selectionne->get('nom_sci_html').' '.$this->nom_selectionne->get('auteur');
36
		}
36
		}
37
		spl_autoload_register(array($this, 'chargerClassesOnglets'));
37
		spl_autoload_register(array($this, 'chargerClassesOnglets'));
38
	}
38
	}
39
 
39
 
40
	private function capturerParametres() {
40
	private function capturerParametres() {
41
		if (isset($_GET['num_nom'])) {
41
		if (isset($_GET['num_nom'])) {
42
			$this->parametres['num_nom'] = $_GET['num_nom'];
42
			$this->parametres['num_nom'] = $_GET['num_nom'];
43
		}
43
		}
44
		if (isset($_GET['nom'])) {
44
		if (isset($_GET['nom'])) {
45
			$this->parametres['nom'] = $_GET['nom'];
45
			$this->parametres['nom'] = $_GET['nom'];
46
		}
46
		}
47
		if (isset($_GET['type_nom'])) {
47
		if (isset($_GET['type_nom'])) {
48
			$this->parametres['type_nom'] = $_GET['type_nom'];
48
			$this->parametres['type_nom'] = $_GET['type_nom'];
49
		}
49
		}
50
		if (isset($_GET['referentiel'])) {
50
		if (isset($_GET['referentiel'])) {
51
			$this->parametres['referentiel'] = $_GET['referentiel'];
51
			$this->parametres['referentiel'] = $_GET['referentiel'];
52
			Registre::set('parametres.referentiel', $_GET['referentiel']);
52
			Registre::set('parametres.referentiel', $_GET['referentiel']);
53
		}
53
		}
54
		if (isset($_GET['niveau'])) {
54
		if (isset($_GET['niveau'])) {
55
			Registre::set('parametres.niveau', $_GET['niveau']);
55
			Registre::set('parametres.niveau', $_GET['niveau']);
56
		}
56
		}
57
		if (isset($_GET['onglet'])) {
57
		if (isset($_GET['onglet'])) {
58
			$this->onglet = $_GET['onglet'];
58
			$this->onglet = $_GET['onglet'];
59
		}
59
		}
60
	}
60
	}
61
 
61
 
62
	private function chargerClassesOnglets($classe) {
62
	private function chargerClassesOnglets($classe) {
63
		$base = dirname(__FILE__).DS;
63
		$base = dirname(__FILE__).DS;
64
		$cheminFormateurs = $base.'formateurs'.DS;
64
		$cheminFormateurs = $base.'formateurs'.DS;
65
		$dossiers = array($base, $cheminFormateurs);
65
		$dossiers = array($base, $cheminFormateurs);
66
		foreach ($dossiers as $chemin) {
66
		foreach ($dossiers as $chemin) {
67
			$fichierATester = $chemin.$classe.'.php';
67
			$fichierATester = $chemin.$classe.'.php';
68
			if (file_exists($fichierATester)) {
68
			if (file_exists($fichierATester)) {
69
				include_once $fichierATester;
69
				include_once $fichierATester;
70
				return null;
70
				return null;
71
			}
71
			}
72
		}
72
		}
73
	}
73
	}
74
 
74
 
75
	public function executerActionParDefaut() {
75
	public function executerActionParDefaut() {
76
		$this->executerFiche();
76
		$this->executerFiche();
77
	}
77
	}
78
 
78
 
79
	public function executerFiche(){
79
	public function executerFiche(){
80
 
80
 
81
		$squelette = 'fiche_'.$this->onglet;
81
		$squelette = 'fiche_'.$this->onglet;
82
 
82
 
83
		//Gestion du niveau
83
		//Gestion du niveau
84
		$niveau = isset($_GET['niveau']) ? $_GET['niveau'] : 2;
84
		$niveau = isset($_GET['niveau']) ? $_GET['niveau'] : 2;
85
		if ($this->onglet == 'synthese' && $niveau != null) {
85
		if ($this->onglet == 'synthese' && $niveau != null) {
86
			$squelette .= '_niveau'.$niveau;
86
			$squelette .= '_niveau'.$niveau;
87
		}
87
		}
88
 
88
 
89
		// Récupération parametres et données
89
		// Récupération parametres et données
90
		$donnees = array_merge($this->obtenirDonnees(), $this->parametres);
90
		$donnees = array_merge($this->obtenirDonnees(), $this->parametres);
91
		$donnees['i18n'] = I18n::get('Fiche');
91
		$donnees['i18n'] = I18n::get('Fiche');
92
		$verna = isset($donnees['ethnobotanique']['nomsVerna']) && count($donnees['ethnobotanique']['nomsVerna']) ? $donnees['ethnobotanique']['nomsVerna'][0]['nom_vernaculaire'] : "";
92
		$verna = isset($donnees['ethnobotanique']['nomsVerna']) && count($donnees['ethnobotanique']['nomsVerna']) ? $donnees['ethnobotanique']['nomsVerna'][0]['nom_vernaculaire'] : "";
93
 
93
 
94
		// titre, description et tag de la page
94
		// titre, description et tag de la page
95
		$this->setSortie('titre', $this->nom_retenu->get('nom_sci'));
95
		$this->setSortie('titre', $this->nom_retenu->get('nom_sci'));
96
        // ( <meta name="description" ...> )
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']));
97
		$this->setSortie('description', sprintf("Fiche descriptive de %s %s (%s)", $this->nom_retenu->get('nom_sci'), $verna ? ('/ ' . $verna) : '', $donnees['description']['titre']));
98
 
98
 
99
		$this->setSortie('tags', $this->nom_retenu->get('nom_sci').",".$verna.
99
		$this->setSortie('tags', $this->nom_retenu->get('nom_sci').",".$verna.
100
			",botanique,plante,description,ecologie,reconnaitre,fiche espece");
100
			",botanique,plante,description,ecologie,reconnaitre,fiche espece");
101
 
101
 
102
		// titre de la fiche
102
		// titre de la fiche
103
		$donnees['nom_retenu_html'] = $this->nom_retenu->get('nom_sci_html').' '.$this->nom_retenu->get('auteur');
103
		$nom_html_fmt = $this->nom_retenu->get('nom_sci_html').' '.$this->nom_retenu->get('auteur');
-
 
104
		$donnees['nom_retenu_html'] = $this->formaterLiensNomsHtml($nom_html_fmt);
104
		$donnees['nom_retenu'] = $this->nom_retenu->get('nom_sci');
105
		$donnees['nom_retenu'] = $this->nom_retenu->get('nom_sci');
105
		$donnees['nom_appele_html'] = $this->nom_appele_html;
106
		$donnees['nom_appele_html'] = $this->nom_appele_html;
106
		$donnees['famille'] = $this->nom_retenu->getTaxonSupRang('180');
107
		$famille = $this->nom_retenu->getTaxonSupRang('180');
-
 
108
		$donnees['lien_recherche_famille'] = html_entity_decode($this->url->obtenirUrlRechercheAvancee(array("fam" => $famille)));
-
 
109
		$donnees['famille'] = $famille;
-
 
110
		
107
		$donnees['nom_vernaculaire'] = $verna;
111
		$donnees['nom_vernaculaire'] = $verna;
108
 
112
 
109
		// moteur de recherche
113
		// moteur de recherche
110
		$this->executerAction('Recherche', 'executerAccueil', $this->parametres);
114
		$this->executerAction('Recherche', 'executerAccueil', $this->parametres);
111
 
115
 
112
		// page synthese
116
		// page synthese
113
		$blocs_niveaux = $this->conteneur->getParametreTableau('blocs_fiche_defaut');
117
		$blocs_niveaux = $this->conteneur->getParametreTableau('blocs_fiche_defaut');
114
		$donnees['blocs'] = '"'.str_replace('|', '","', $blocs_niveaux[Registre::get('parametres.niveau')]).'"';
118
		$donnees['blocs'] = '"'.str_replace('|', '","', $blocs_niveaux[Registre::get('parametres.niveau')]).'"';
115
 
119
 
116
		// onglet
120
		// onglet
117
		$donnees['onglet'] = $this->onglet;
121
		$donnees['onglet'] = $this->onglet;
118
		$donnees['niveau'] = $niveau;
122
		$donnees['niveau'] = $niveau;
119
		$donnees['base_url_onglets'] = Config::get('base_url_application_onglets');
123
		$donnees['base_url_onglets'] = Config::get('base_url_application_onglets');
120
		
124
		
121
		$taxons = new Taxons();
125
		$taxons = new Taxons();
122
		$referentiel = $this->conteneur->getParametre('referentiel');
126
		$referentiel = $this->conteneur->getParametre('referentiel');
123
		
127
		
124
		$donnees['permalien_num_nom'] = $taxons->getUrlPermalienNumNom($referentiel, 1, $this->conteneur->getNomCourant()->getNns());
128
		$donnees['permalien_num_nom'] = $taxons->getUrlPermalienNumNom($referentiel, 1, $this->conteneur->getNomCourant()->getNns());
125
		$donnees['entete'] = $this->getVue('fiche_entete', $donnees);
129
		$donnees['entete'] = $this->getVue('fiche_entete', $donnees);
126
		$donnees['contenu_onglet'] = $this->getVue($squelette, $donnees);
130
		$donnees['contenu_onglet'] = $this->getVue($squelette, $donnees);
127
		
131
		
128
		$this->setSortie(self::RENDU_CORPS, $this->getVue('fiche_accueil_niveau'.$niveau, $donnees), true);
132
		$this->setSortie(self::RENDU_CORPS, $this->getVue('fiche_accueil_niveau'.$niveau, $donnees), true);
129
		$this->ajouterPiedDePage();
133
		$this->ajouterPiedDePage();
130
	}
134
	}
-
 
135
	
-
 
136
	private function formaterLiensNomsHtml($nom_sci_html) {
-
 
137
		
-
 
138
		$app_urls = new AppUrls();
-
 
139
		$params = array();
-
 
140
		$classes_recherche = array("fam" => "fam", "gen" => "gen", "sp" => "sp", "infra-sp" => "ssp");
-
 
141
		
-
 
142
		$doc = new DOMDocument();
-
 
143
		$doc->loadHTML($nom_sci_html);
-
 
144
		$spans = $doc->getElementsByTagName('span');
-
 
145
		$abbr = $doc->getElementsByTagName('abbr');
-
 
146
		
-
 
147
		$params_subsp = array();
-
 
148
		
-
 
149
		$i18n =  I18n::get('Fiche');
-
 
150
		
-
 
151
		if ($spans->length > 0) {
-
 
152
			foreach($spans as $span) {
-
 
153
				$classe = $span->getAttribute('class');
-
 
154
				if(in_array($classe, array_keys($classes_recherche))) {
-
 
155
					
-
 
156
					$params[$classes_recherche[$classe]] = $span->nodeValue;	
-
 
157
					if($classe == "sp") {
-
 
158
						$params_subsp = $params;
-
 
159
					}				
-
 
160
					$lien_tpl = html_entity_decode($this->url->obtenirUrlRechercheAvancee($params));
-
 
161
					$texte_lien = $span->nodeValue;	
-
 
162
					
-
 
163
					$span->nodeValue = "";
-
 
164
					$text = $doc->createElement('a', $texte_lien);
-
 
165
					$text->setAttribute('href', $lien_tpl);
-
 
166
					$text->setAttribute('title', $i18n["lien-recherche-hier-".$classe]);
-
 
167
					$text->setAttribute('class', 'lien_recherche_hier');
-
 
168
					$span->appendChild($text);
-
 
169
				}
-
 
170
			}
-
 
171
		}
-
 
172
		
-
 
173
		// TODO: gérer le cas du type d'épithète infra-spécifique (qui est une abbréviation
-
 
174
		// et donc la valeur ne correspond pas à ce qu'attend l'url de recherche)
-
 
175
		
-
 
176
		return $doc->SaveXml();
-
 
177
	}
131
 
178
 
132
	public function ajouterLienModuleExport() {
179
	public function ajouterLienModuleExport() {
133
		$donnees['lien'] = $this->url->obtenirUrlPdfExport($this->parametres['num_nom']);
180
		$donnees['lien'] = $this->url->obtenirUrlPdfExport($this->parametres['num_nom']);
134
		$export = $this->getVue('fiche_pdf_lien', $donnees);
181
		$export = $this->getVue('fiche_pdf_lien', $donnees);
135
		return $export;
182
		return $export;
136
	}
183
	}
137
 
184
 
138
	public function ajouterPiedDePage() {
185
	public function ajouterPiedDePage() {
139
		$description = new Description($this->conteneur);
186
		$description = new Description($this->conteneur);
140
		$taxons = new Taxons();
187
		$taxons = new Taxons();
141
		$referentiel = $this->conteneur->getParametre('referentiel');
188
		$referentiel = $this->conteneur->getParametre('referentiel');
142
		$urlMobile = $this->url->obtenirUrlMobile($this->parametres['num_nom']);
189
		$urlMobile = $this->url->obtenirUrlMobile($this->parametres['num_nom']);
143
		$donnees = array('wikipedia' => $description->getUrlWikipedia(),
190
		$donnees = array('wikipedia' => $description->getUrlWikipedia(),
144
			'export_pdf' => $this->ajouterLienModuleExport(),
191
			'export_pdf' => $this->ajouterLienModuleExport(),
145
			'permalien_num_nom' => $taxons->getUrlPermalienNumNom($referentiel, 1, $this->conteneur->getNomCourant()->getNns()),
192
			'permalien_num_nom' => $taxons->getUrlPermalienNumNom($referentiel, 1, $this->conteneur->getNomCourant()->getNns()),
146
			'permalien_taxon' => $taxons->getUrlPermalienTaxon($referentiel, 1, $this->conteneur->getNomCourant()->getNt()),
193
			'permalien_taxon' => $taxons->getUrlPermalienTaxon($referentiel, 1, $this->conteneur->getNomCourant()->getNt()),
147
			'nn' => $this->conteneur->getNomCourant()->getNns(),
194
			'nn' => $this->conteneur->getNomCourant()->getNns(),
148
			'nt' => $this->conteneur->getNomCourant()->getNt(),
195
			'nt' => $this->conteneur->getNomCourant()->getNt(),
149
			'nnr' => $this->conteneur->getNomCourant()->getNnr(),
196
			'nnr' => $this->conteneur->getNomCourant()->getNnr(),
150
			'inpn' => $this->conteneur->getNomCourant()->getInpn(),
197
			'inpn' => $this->conteneur->getNomCourant()->getInpn(),
151
			'wiki' => $description->getLienWikini(),
198
			'wiki' => $description->getLienWikini(),
152
			'nom_retenu' => $this->nom_retenu->get('nom_sci'),
199
			'nom_retenu' => $this->nom_retenu->get('nom_sci'),
153
			'mobile' => $urlMobile,
200
			'mobile' => $urlMobile,
154
			'qr_code_png' => $this->obtenirUrlQrCode($urlMobile)
201
			'qr_code_png' => $this->obtenirUrlQrCode($urlMobile)
155
		);
202
		);
156
		$this->setSortie(self::RENDU_CORPS, $this->getVue('fiche_pied_page', $donnees), true);
203
		$this->setSortie(self::RENDU_CORPS, $this->getVue('fiche_pied_page', $donnees), true);
157
	}
204
	}
158
 
205
 
159
	private function obtenirUrlQrCode($urlMobile) {
206
	private function obtenirUrlQrCode($urlMobile) {
160
		$qr = $this->conteneur->getQrCode();
207
		$qr = $this->conteneur->getQrCode();
161
		$qr->setUrl(htmlspecialchars_decode($urlMobile));
208
		$qr->setUrl(htmlspecialchars_decode($urlMobile));
162
		$idQrCode = $this->conteneur->getNomCourant()->getNns();
209
		$idQrCode = $this->conteneur->getNomCourant()->getNns();
163
		$urlQrCode = $qr->dessiner($idQrCode);
210
		$urlQrCode = $qr->dessiner($idQrCode);
164
		return $urlQrCode;
211
		return $urlQrCode;
165
	}
212
	}
166
 
213
 
167
	public function executerOnglet(){
214
	public function executerOnglet(){
168
		$this->viderSorties();
215
		$this->viderSorties();
169
		$donnees = $this->obtenirDonnees();
216
		$donnees = $this->obtenirDonnees();
170
		$squelette_onglet = $this->onglet;
217
		$squelette_onglet = $this->onglet;
171
		// onglet
218
		// onglet
172
		$donnees['i18n'] = I18n::get('Fiche');
219
		$donnees['i18n'] = I18n::get('Fiche');
173
		$donnees['onglet'] = $this->onglet;
220
		$donnees['onglet'] = $this->onglet;
174
		$taxons = new Taxons();
221
		$taxons = new Taxons();
175
		$referentiel = $this->conteneur->getParametre('referentiel');
222
		$referentiel = $this->conteneur->getParametre('referentiel');
176
		$donnees['permalien_num_nom'] = $taxons->getUrlPermalienNumNom($referentiel, 1, $this->conteneur->getNomCourant()->getNns());
223
		$donnees['permalien_num_nom'] = $taxons->getUrlPermalienNumNom($referentiel, 1, $this->conteneur->getNomCourant()->getNns());
177
		// cas particulier de l'onglet synthese qui possède 3 niveaux
224
		// cas particulier de l'onglet synthese qui possède 3 niveaux
178
		// et dont le nom n'est donc pas directement celui de son squelette
225
		// et dont le nom n'est donc pas directement celui de son squelette
179
		if($this->onglet == "synthese") {
226
		if($this->onglet == "synthese") {
180
			$niveau = isset($_GET['niveau']) ? $_GET['niveau'] : 2;
227
			$niveau = isset($_GET['niveau']) ? $_GET['niveau'] : 2;
181
			$squelette_onglet .= '_niveau'.$niveau;
228
			$squelette_onglet .= '_niveau'.$niveau;
182
			$entete = $this->getVue('fiche_entete', $donnees);
229
			$entete = $this->getVue('fiche_entete', $donnees);
183
			$vue = $entete.$this->getVue('fiche_'.$squelette_onglet, $donnees);
230
			$vue = $entete.$this->getVue('fiche_'.$squelette_onglet, $donnees);
184
		} else {
231
		} else {
185
			$vue = $this->getVue('fiche_'.$squelette_onglet, $donnees);
232
			$vue = $this->getVue('fiche_'.$squelette_onglet, $donnees);
186
		}
233
		}
187
		
234
		
188
		header('Content-type: text/html');
235
		header('Content-type: text/html');
189
		$this->setSortie(self::RENDU_CORPS, $vue);
236
		$this->setSortie(self::RENDU_CORPS, $vue);
190
	}
237
	}
191
 
238
 
192
	private function obtenirDonnees() {
239
	private function obtenirDonnees() {
193
		$classe = ucfirst($this->onglet);
240
		$classe = ucfirst($this->onglet);
194
		$onglet = new $classe($this->conteneur); // grep-friendly: new Synthese()
241
		$onglet = new $classe($this->conteneur); // grep-friendly: new Synthese()
195
		return $onglet->obtenirDonnees();
242
		return $onglet->obtenirDonnees();
196
	}
243
	}
197
}
244
}
198
?>
245
?>