Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 719 Rev 917
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;
25
	private $projet = null;
26
	private $configProjet = null;
26
	private $configProjet = null;
27
	 
27
	 
28
	/**
28
	/**
29
	 * Méthode appelée par défaut pour charger ce widget.
29
	 * Méthode appelée par défaut pour charger ce widget.
30
	 */
30
	 */
31
	public function executer() {
31
	public function executer() {
32
		$retour = null;
32
		$retour = null;
33
		extract($this->parametres);
33
		extract($this->parametres);
34
 
34
 
35
		if (!isset($projet)) {
35
		if (!isset($projet)) {
36
			$this->projet = self::PROJET_DEFAUT;
36
			$this->projet = self::PROJET_DEFAUT;
37
		} else {
37
		} else {
38
			$this->projet = $projet;
38
			$this->projet = $projet;
39
		}
39
		}
40
		$this->chargerConfigProjet();
40
		$this->chargerConfigProjet();
41
		
41
		
42
		$service = (isset($service)) ? $service : $this->projet;
42
		$service = (isset($service)) ? $service : $this->projet;
43
		$methode = $this->traiterNomMethodeExecuter($service);
43
		$methode = $this->traiterNomMethodeExecuter($service);
44
		if (method_exists($this, $methode)) {
44
		if (method_exists($this, $methode)) {
45
			$retour = $this->$methode();
45
			$retour = $this->$methode();
46
		} else {
46
		} else {
47
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
47
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
48
		}
48
		}
49
 
49
 
50
		if (is_null($retour)) {
50
		if (is_null($retour)) {
51
			$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
51
			$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
52
		} else {
52
		} else {
53
			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
53
			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
54
			$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$ext;
54
			$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$ext;
55
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
55
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
56
		}
56
		}
57
		$this->envoyer($contenu);
57
		$this->envoyer($contenu);
58
	}
58
	}
59
	
59
	
60
	private function chargerConfigProjet() {
60
	private function chargerConfigProjet() {
61
		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
61
		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
62
		if (file_exists($fichier_config)) {
62
		if (file_exists($fichier_config)) {
63
			if (!$this->configProjet	= parse_ini_file($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é.";
64
				$this->messages[] = "Le fichier ini '$fichier_config' du projet n'a pu être chargé.";
65
			} 
65
			} 
66
		} else {
66
		} else {
67
			$this->messages[] = "Le fichier ini '$fichier_config' du projet n'existe pas.";
67
			$this->messages[] = "Le fichier ini '$fichier_config' du projet n'existe pas.";
68
		}
68
		}
69
	}
69
	}
70
	
70
	
71
	public function executerBiodiversite34() {
71
	public function executerBiodiversite34() {
72
		$widget['squelette'] = $this->projet;
72
		$widget['squelette'] = $this->projet;
73
		$widget['donnees'] = array();
73
		$widget['donnees'] = array();
74
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
74
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
75
		$widget['donnees']['taxons'] = $this->recupererListeTaxonBiodiversite34();
75
		$widget['donnees']['taxons'] = $this->recupererListeTaxonBiodiversite34();
76
		$widget['donnees']['milieux'] = $this->parserMilieuxBiodiversite34();
76
		$widget['donnees']['milieux'] = $this->parserMilieuxBiodiversite34();
77
		return  $widget;
77
		return  $widget;
78
	}
78
	}
79
	public function executerTaxons() {
79
	public function executerTaxons() {
80
		$widget['squelette'] = $this->projet.'_taxons';
80
		$widget['squelette'] = $this->projet.'_taxons';
81
		$widget['squelette_ext'] = '.tpl.js';
81
		$widget['squelette_ext'] = '.tpl.js';
82
		$widget['donnees'] = array();
82
		$widget['donnees'] = array();
83
		$methode = 'recupererListeTaxon'.str_replace(' ', '', ucwords(str_replace('-', ' ', strtolower($this->projet))));
83
		$methode = 'recupererListeTaxon'.str_replace(' ', '', ucwords(str_replace('-', ' ', strtolower($this->projet))));
84
		$taxons = $this->$methode();
84
		$taxons = $this->$methode();
85
		$taxons_tries = array();
85
		$taxons_tries = array();
86
		foreach ($taxons as $taxon) {
86
		foreach ($taxons as $taxon) {
87
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
87
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
88
		}
88
		}
89
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
89
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
90
		return  $widget;
90
		return  $widget;
91
	}
91
	}
92
	
92
	
93
	private function parserMilieuxBiodiversite34() {
93
	private function parserMilieuxBiodiversite34() {
94
		$infosMilieux = array();
94
		$infosMilieux = array();
95
		$milieux = explode('|', $this->configProjet['milieux']);
95
		$milieux = explode('|', $this->configProjet['milieux']);
96
		foreach ($milieux as $milieu) {
96
		foreach ($milieux as $milieu) {
97
			$details = explode(';', $milieu);
97
			$details = explode(';', $milieu);
98
			if (isset($details[1])) {
98
			if (isset($details[1])) {
99
				$infosMilieux[$details[0]] = $details[1];
99
				$infosMilieux[$details[0]] = $details[1];
100
			} else {
100
			} else {
101
				$infosMilieux[$details[0]] = '';
101
				$infosMilieux[$details[0]] = '';
102
			}
102
			}
103
		}
103
		}
-
 
104
		ksort($infosMilieux);
104
		return $infosMilieux;
105
		return $infosMilieux;
105
	}
106
	}
106
	
107
	
107
	private function recupererListeTaxonBiodiversite34() {
108
	private function recupererListeTaxonBiodiversite34() {
108
		$taxons = null;
109
		$taxons = null;
109
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.'biodiversite34_taxons.tsv';
110
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.'biodiversite34_taxons.tsv';
110
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
111
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
111
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
112
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
112
		} else {
113
		} else {
113
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
114
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
114
		}
115
		}
-
 
116
		
-
 
117
		$taxons_tries = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
-
 
118
		
115
		return $taxons;
119
		return $taxons_tries;
116
	}
120
	}
117
	
121
	
118
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
122
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
119
		$header = NULL;
123
		$header = NULL;
120
	    $data = array();
124
	    $data = array();
121
	    if (($handle = fopen($fichier, 'r')) !== FALSE) {
125
	    if (($handle = fopen($fichier, 'r')) !== FALSE) {
122
	        while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
126
	        while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
123
	            if (!$header) {
127
	            if (!$header) {
124
	                $header = $row;
128
	                $header = $row;
125
	            } else {  
129
	            } else {  
126
	                $data[] = array_combine($header, $row);
130
	                $data[] = array_combine($header, $row);
127
	            }
131
	            }
128
	        }
132
	        }
129
	        fclose($handle);
133
	        fclose($handle);
130
	    }
134
	    }
131
	    return $data; 
135
	    return $data; 
132
	}
136
	}
133
}
137
}