Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 712 Rev 719
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Widget fournissant des interfaces de saisies simplifiée pour différent projets.
4
 * Widget fournissant des interfaces de saisies simplifiée pour différent projets.
5
 * Encodage en entrée : utf8
5
 * Encodage en entrée : utf8
6
 * Encodage en sortie : utf8
6
 * Encodage en sortie : utf8
7
 *
7
 *
8
 * Cas d'utilisation et documentation :
8
 * Cas d'utilisation et documentation :
9
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetSaisie
9
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetSaisie
10
 *
10
 *
11
 * Paramètres :
11
 * Paramètres :
12
 * ===> projet = chaine  [par défaut : Biodiversite34]
12
 * ===> projet = chaine  [par défaut : Biodiversite34]
13
 * Indique quel projet nous voulons charger
13
 * Indique quel projet nous voulons charger
14
 *
14
 *
15
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
15
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
16
 * @license		GPL v3 <http://www.gnu.org/licenses/gpl.txt>
16
 * @license		GPL v3 <http://www.gnu.org/licenses/gpl.txt>
17
 * @license		CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
17
 * @license		CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
18
 * @version		$Id$
18
 * @version		$Id$
19
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
19
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
20
 */
20
 */
21
class Saisie extends WidgetCommun {
21
class Saisie extends WidgetCommun {
22
	
22
	
23
	const DS = DIRECTORY_SEPARATOR;
23
	const DS = DIRECTORY_SEPARATOR;
24
	const PROJET_DEFAUT = 'biodiversite34';
24
	const PROJET_DEFAUT = 'biodiversite34';
-
 
25
	private $projet = null;
-
 
26
	private $configProjet = null;
25
	
27
	 
26
	/**
28
	/**
27
	 * Méthode appelée par défaut pour charger ce widget.
29
	 * Méthode appelée par défaut pour charger ce widget.
28
	 */
30
	 */
29
	public function executer() {
31
	public function executer() {
30
		$retour = null;
32
		$retour = null;
31
		extract($this->parametres);
33
		extract($this->parametres);
32
 
34
 
33
		if (!isset($projet)) {
35
		if (!isset($projet)) {
34
			$projet = self::PROJET_DEFAUT;
36
			$this->projet = self::PROJET_DEFAUT;
-
 
37
		} else {
-
 
38
			$this->projet = $projet;
35
		}
39
		}
-
 
40
		$this->chargerConfigProjet();
-
 
41
		
36
		
42
		$service = (isset($service)) ? $service : $this->projet;
37
		$methode = $this->traiterNomMethodeExecuter($projet);
43
		$methode = $this->traiterNomMethodeExecuter($service);
38
		if (method_exists($this, $methode)) {
44
		if (method_exists($this, $methode)) {
39
			$retour = $this->$methode();
45
			$retour = $this->$methode();
40
		} else {
46
		} else {
41
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
47
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
42
		}
48
		}
43
 
49
 
44
		if (is_null($retour)) {
50
		if (is_null($retour)) {
45
			$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
51
			$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
46
		} else {
52
		} else {
-
 
53
			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
47
			$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$projet.self::DS.$retour['squelette'].'.tpl.html';
54
			$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$ext;
48
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
55
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
49
		}
56
		}
50
		$this->envoyer($contenu);
57
		$this->envoyer($contenu);
51
	}
58
	}
-
 
59
	
-
 
60
	private function chargerConfigProjet() {
-
 
61
		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
-
 
62
		if (file_exists($fichier_config)) {
-
 
63
			if (!$this->configProjet	= parse_ini_file($fichier_config)) {
-
 
64
				$this->messages[] = "Le fichier ini '$fichier_config' du projet n'a pu être chargé.";
-
 
65
			} 
-
 
66
		} else {
-
 
67
			$this->messages[] = "Le fichier ini '$fichier_config' du projet n'existe pas.";
-
 
68
		}
-
 
69
	}
52
	
70
	
53
	public function executerBiodiversite34() {
71
	public function executerBiodiversite34() {
54
		$widget['squelette'] = 'biodiversite34';
72
		$widget['squelette'] = $this->projet;
55
		$widget['donnees'] = array();
73
		$widget['donnees'] = array();
56
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
74
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
57
		$widget['donnees']['taxons'] = $this->recupererListeTaxonBiodiversite34();
75
		$widget['donnees']['taxons'] = $this->recupererListeTaxonBiodiversite34();
-
 
76
		$widget['donnees']['milieux'] = $this->parserMilieuxBiodiversite34();
58
		return  $widget;
77
		return  $widget;
59
	}
78
	}
-
 
79
	public function executerTaxons() {
-
 
80
		$widget['squelette'] = $this->projet.'_taxons';
-
 
81
		$widget['squelette_ext'] = '.tpl.js';
-
 
82
		$widget['donnees'] = array();
-
 
83
		$methode = 'recupererListeTaxon'.str_replace(' ', '', ucwords(str_replace('-', ' ', strtolower($this->projet))));
-
 
84
		$taxons = $this->$methode();
-
 
85
		$taxons_tries = array();
-
 
86
		foreach ($taxons as $taxon) {
-
 
87
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
-
 
88
		}
-
 
89
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
-
 
90
		return  $widget;
-
 
91
	}
-
 
92
	
-
 
93
	private function parserMilieuxBiodiversite34() {
-
 
94
		$infosMilieux = array();
-
 
95
		$milieux = explode('|', $this->configProjet['milieux']);
-
 
96
		foreach ($milieux as $milieu) {
-
 
97
			$details = explode(';', $milieu);
-
 
98
			if (isset($details[1])) {
-
 
99
				$infosMilieux[$details[0]] = $details[1];
-
 
100
			} else {
-
 
101
				$infosMilieux[$details[0]] = '';
-
 
102
			}
-
 
103
		}
-
 
104
		return $infosMilieux;
-
 
105
	}
60
	
106
	
61
	private function recupererListeTaxonBiodiversite34() {
107
	private function recupererListeTaxonBiodiversite34() {
62
		$taxons = null;
108
		$taxons = null;
63
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.'biodiversite34_taxons.tsv';
109
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.'biodiversite34_taxons.tsv';
64
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
110
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
65
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
111
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
66
		} else {
112
		} else {
67
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
113
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
68
		}
114
		}
69
		return $taxons;
115
		return $taxons;
70
	}
116
	}
71
	
117
	
72
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
118
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
73
		$header = NULL;
119
		$header = NULL;
74
	    $data = array();
120
	    $data = array();
75
	    if (($handle = fopen($fichier, 'r')) !== FALSE) {
121
	    if (($handle = fopen($fichier, 'r')) !== FALSE) {
76
	        while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
122
	        while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
77
	            if (!$header) {
123
	            if (!$header) {
78
	                $header = $row;
124
	                $header = $row;
79
	            } else {  
125
	            } else {  
80
	                $data[] = array_combine($header, $row);
126
	                $data[] = array_combine($header, $row);
81
	            }
127
	            }
82
	        }
128
	        }
83
	        fclose($handle);
129
	        fclose($handle);
84
	    }
130
	    }
85
	    return $data; 
131
	    return $data; 
86
	}
132
	}
87
}
133
}