New file |
0,0 → 1,106 |
<?php |
// declare(encoding='UTF-8'); |
/** |
* classe Controleur du module Carte. |
* |
* @package Collection |
* @category Php5 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @copyright 2010 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL |
* @version SVN: $Id$ |
*/ |
class Carte extends ColControleur { |
|
//+----------------------------------------------------------------------------------------------------------------+ |
// Méthodes |
/** |
* Fonction d'affichage par défaut, elle appelle la liste des administrateurs |
*/ |
public function executerActionParDefaut() { |
return $this->cartographier(); |
} |
|
/** |
* Cartographier les collections. |
* @return string la vue correspondante |
*/ |
public function cartographier() { |
// Initialisation de variable |
$donnees = array(); |
$structureDao = $this->getModele('StructureDao'); |
|
// Construction des données à passer à la cartographie |
$zones = $this->chargerZonesGeo(Config::get('carte_base_nom')); |
$zones_infos = $structureDao->getStructureParZoneGeo('FRD'); |
$zones = $this->chargerZonesNbre($zones, $zones_infos); |
$zones = $this->chargerZonesUrls($zones); |
Debug::printr($zones); |
|
// Création de la carte |
$options = array( |
'carte_nom' => 'france', |
'formule' => Cartographie::FORMULE_PROPORTIONNEL, |
'fond_fichier' => Config::get('carte_base_nom'), |
'fond_dossier' => Application::getChemin().Config::get('carte_chemin_fonds'), |
'stock_dossier' => Config::get('carte_chemin_sotckage'), |
'infos' => $zones); |
$cartographie = Composant::fabrique('cartographie', $options); |
$cartographie->creerCarte(); |
$donnees['map'] = $cartographie->getImageMap(); |
|
$resultat = $this->getVue('carte', $donnees); |
$this->setSortie(self::RENDU_CORPS, $resultat); |
} |
|
private function chargerZonesNbre($zones, $zones_infos) { |
foreach ($zones as $id => &$infos) { |
if (isset($zones_infos[$id])) { |
$nbre = $zones_infos[$id]; |
$infos['info_nbre'] = $nbre; |
} else { |
$infos['info_nbre'] = 0; |
} |
} |
return $zones; |
} |
|
private function chargerZonesUrls($zones) { |
$this->url->setVariableRequete('module', 'Recherche'); |
$this->url->setVariableRequete('action', 'rechercher'); |
$this->url->setVariableRequete('recherche', 'd:%s'); |
$url = $this->url->getURL(); |
foreach ($zones as $id => &$infos) { |
$infos['url'] = sprintf($url, $id); |
} |
$this->url->unsetVariablesRequete(array('module', 'action', 'recherche')); |
return $zones; |
} |
|
/** |
* Charge le fichier csv des zones géographique de la carte |
*/ |
private function chargerZonesGeo($nom_carte) { |
$fichier_csv = Application::getChemin().Config::get('carte_chemin_fonds').$nom_carte.'.csv'; |
$zones = array(); |
if (($handle = fopen($fichier_csv, 'r')) !== false) { |
$ligne = 1; |
$cles = array(); |
while (($donnees = fgetcsv($handle, 1000, ',')) !== false) { |
$cle = array_shift($donnees); |
if ($ligne == 1) { |
// Ligne 1 : les noms des champs |
$cles = $donnees; |
} else { |
// Ligne > 1 : traitements des données |
$zones[$cle] = array_combine($cles, $donnees); |
} |
$ligne++; |
} |
fclose($handle); |
} |
return $zones; |
} |
} |
?> |