Subversion Repositories eFlore/Applications.coel-consultation

Rev

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

Rev 25 Rev 30
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * classe Controleur du module Carte.
4
 * classe Controleur du module Carte.
5
 *
5
 *
6
 * @package		Collection
6
 * @package		Collection
7
 * @category	Php5
7
 * @category	Php5
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @copyright	2010 Tela-Botanica
9
 * @copyright	2010 Tela-Botanica
10
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
10
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
11
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
11
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
12
 * @version		SVN: $Id$
12
 * @version		SVN: $Id$
13
 */
13
 */
14
class Carte extends ColControleur {
14
class Carte extends ColControleur {
15
	
15
	
16
	//+----------------------------------------------------------------------------------------------------------------+
16
	//+----------------------------------------------------------------------------------------------------------------+
17
	// Méthodes
17
	// Méthodes
18
	/**
18
	/**
19
	 * Fonction d'affichage par défaut, elle appelle la liste des administrateurs
19
	 * Fonction d'affichage par défaut, elle appelle la liste des administrateurs
20
	 */
20
	 */
21
	public function executerActionParDefaut() {
21
	public function executerActionParDefaut() {
22
		return $this->cartographier();
22
		return $this->cartographier();
23
	}
23
	}
24
	
24
	
25
	/**
25
	/**
26
	 * Cartographier les collections.
26
	 * Cartographier les collections.
27
	 * @return string la vue correspondante
27
	 * @return string la vue correspondante
28
	 */
28
	 */
29
	public function cartographier() {
29
	public function cartographier() {
30
		// Initialisation de variable
30
		// Initialisation de variable
31
		$donnees = array();
31
		$donnees = array();
32
		$structureDao = $this->getModele('StructureDao');
-
 
33
		
-
 
34
		// Construction des données à passer à la cartographie
-
 
35
		$zones = $this->chargerZonesGeo(Config::get('carte_base_nom'));
-
 
36
		$zones_infos = $structureDao->getStructureParZoneGeo('FRD');
-
 
37
		$zones = $this->chargerZonesNbre($zones, $zones_infos);
-
 
38
		$zones = $this->chargerZonesUrls($zones);
-
 
39
		Debug::printr($zones);
-
 
40
		
32
		
41
		// Création de la carte
33
		// Création de la carte
42
		$options = array(
34
		$options = array(
43
			'carte_nom' => 'france',	
35
			'carte_nom' => 'col_str_dep',	
44
			'formule' => Cartographie::FORMULE_PROPORTIONNEL, 
36
			'formule' => Cartographie::FORMULE_PROPORTIONNEL,
-
 
37
			'couleur_claire' => Config::get('carte_couleur_claire'),
-
 
38
			'couleur_foncee' => Config::get('carte_couleur_foncee'), 
45
			'fond_fichier' => Config::get('carte_base_nom'),
39
			'fond_fichier' => Config::get('carte_base_nom'),
46
			'fond_dossier' => Application::getChemin().Config::get('carte_chemin_fonds'),
40
			'fond_dossier' => Application::getChemin().Config::get('carte_fonds_chemin'),
47
			'stock_dossier' => Config::get('carte_chemin_sotckage'),
41
			'stock_dossier' => Config::get('carte_sotckage_chemin'),
-
 
42
			'stock_url' => Config::get('carte_sotckage_url'),
48
			'infos' => $zones);
43
			'debug' => Config::get('carte_mode_debug'));
49
		$cartographie = Composant::fabrique('cartographie', $options);
44
		$cartographie = Composant::fabrique('cartographie', $options);
-
 
45
		// Construction des données nécessaires à la cartographie
-
 
46
		$zones = $cartographie->getCarteZones();
-
 
47
		$this->chargerZonesNbre($zones);
-
 
48
		$this->chargerZonesUrls($zones);
-
 
49
		$cartographie->setCarteZones($zones);
-
 
50
		//Debug::printr($zones);
-
 
51
		
50
		$cartographie->creerCarte();
52
		$cartographie->creerCarte();
51
		$donnees['map'] = $cartographie->getImageMap();
53
		$donnees['map'] = $cartographie->getImageMap();
52
		
54
		
53
		$resultat = $this->getVue('carte', $donnees);
55
		$resultat = $this->getVue('carte', $donnees);
54
		$this->setSortie(self::RENDU_CORPS, $resultat);
56
		$this->setSortie(self::RENDU_CORPS, $resultat);
55
	}
57
	}
56
	
58
	
-
 
59
	private function chargerZonesNbre(&$zones) {
-
 
60
		$structureDao = $this->getModele('StructureDao');
57
	private function chargerZonesNbre($zones, $zones_infos) {
61
		$zones_infos = $structureDao->getStructureParZoneGeo('FRD');
58
		foreach ($zones as $id => &$infos) {
62
		foreach ($zones as $id => &$infos) {
59
			if (isset($zones_infos[$id])) {
63
			if (isset($zones_infos[$id])) {
60
				$nbre = $zones_infos[$id];
64
				$nbre = $zones_infos[$id];
61
				$infos['info_nbre'] = $nbre;
65
				$infos['info_nombre'] = $nbre;
62
			} else {
66
			} else {
63
				$infos['info_nbre'] = 0;
67
				$infos['info_nombre'] = 0;
64
			}
68
			}
65
		}
69
		}
66
		return $zones;
-
 
67
	}
70
	}
68
	
71
	
69
	private function chargerZonesUrls($zones) {
72
	private function chargerZonesUrls(&$zones) {
70
		$this->url->setVariableRequete('module', 'Recherche');
73
		$this->url->setVariableRequete('module', 'Recherche');
71
		$this->url->setVariableRequete('action', 'rechercher');
74
		$this->url->setVariableRequete('action', 'rechercher');
72
		$this->url->setVariableRequete('recherche', 'd:%s');
75
		$this->url->setVariableRequete('recherche', 'str-d:%s');
73
		$url = $this->url->getURL();
76
		$url = $this->url->getURL();
74
		foreach ($zones as $id => &$infos) {
77
		foreach ($zones as $id => &$infos) {
75
			$infos['url'] = sprintf($url, $id);
78
			$infos['url'] = sprintf($url, $id);
76
		}
79
		}
77
		$this->url->unsetVariablesRequete(array('module', 'action', 'recherche'));
80
		$this->url->unsetVariablesRequete(array('module', 'action', 'recherche'));
78
		return $zones;
-
 
79
	}
-
 
80
	
-
 
81
	/**
-
 
82
	 * Charge le fichier csv des zones géographique de la carte
-
 
83
	 */
-
 
84
	private function chargerZonesGeo($nom_carte) {
-
 
85
		$fichier_csv = Application::getChemin().Config::get('carte_chemin_fonds').$nom_carte.'.csv';
-
 
86
		$zones = array();
-
 
87
		if (($handle = fopen($fichier_csv, 'r')) !== false) {
-
 
88
			$ligne = 1;
-
 
89
			$cles = array();
-
 
90
			while (($donnees = fgetcsv($handle, 1000, ',')) !== false) {
-
 
91
				$cle = array_shift($donnees);
-
 
92
				if ($ligne == 1) {
-
 
93
					// Ligne 1 : les noms des champs
-
 
94
					$cles = $donnees;
-
 
95
				} else {
-
 
96
					// Ligne > 1 : traitements des données
-
 
97
					$zones[$cle] = array_combine($cles, $donnees);
-
 
98
				}
-
 
99
				$ligne++;
-
 
100
			}
-
 
101
			fclose($handle);
-
 
102
		}
-
 
103
		return $zones;
-
 
104
	}
81
	}
105
}
82
}
106
?>
83
?>