New file |
0,0 → 1,92 |
<?php |
|
class ControlleurFrontal { |
|
public function getRegistre() |
{ |
return Registre::getRegistre(); |
} |
|
public function parserAction($url) |
{ |
if (preg_match('/^(.+?)(?:_(.+)|)$/', $url, $match)) { |
$retour['classe_action'] = 'GttCtrlAction'.ucfirst($match[1]); |
} |
|
$retour['tab_actions'] = array(''); |
if (isset($match[2])) { |
preg_match_all('/(.+)(?:_|$)/', $match[2], $match_actions); |
$retour['tab_actions'] = $match_actions[1]; |
} |
return $retour; |
} |
|
public function executer($url_action) |
{ |
$tab_info_url = $this->parserAction($url_action); |
//echo '<pre>'.print_r($tab_info_url, true).'</pre>'; |
$classe_action = $tab_info_url['classe_action']; |
$fichier_action = GTT_CHEMIN_ACTION.$classe_action.'.class.php'; |
if (file_exists($fichier_action)) { |
require_once $fichier_action; |
$Action = new $classe_action($this->getRegistre()); |
foreach ($tab_info_url['tab_actions'] as $action) { |
// Vérification des données POST ou GET avant l'appel de l'action |
if (isset($_POST) || isset($_GET)) { |
$Action->verifier(); |
$methode_verif = 'verifier'.ucfirst($action); |
if (method_exists($Action, $methode_verif)) { |
// Méthode "vérifier" spécifique à une action |
$Action->$methode_verif(); |
} |
} |
// Execution de l'action |
$Action->setSuivant(ucfirst($action)); |
} |
$Action->demarrer(); |
$aso_principal['principal'] = $this->rendre(); |
//echo '<pre>'.print_r($aso_principal, true).'</pre>'; |
$Resultats = $this->getRegistre(); |
$aso_principal['principal']['titre'] = $Resultats->getTitre(); |
$Resultats->setEspaces(array()); |
$Resultats->setSquelettes(array()); |
$Resultats->setDonnees(array()); |
$Resultats->ajouterEspace('Principal', 'principal'); |
$Resultats->ajouterSquelette('principal', 'principal.tpl.html'); |
$Resultats->ajouterDonnee('principal', $aso_principal['principal']); |
return $this->rendre(); |
} else { |
$m = "Le fichier $fichier_action contenant l'action est introuvable!"; |
trigger_error($m, E_USER_ERROR); |
} |
} |
|
public function rendre() |
{ |
$contenu_principal = null; |
$aso_contenu = array('zone_contenu' => '', 'zone_identification' => ''); |
foreach ($this->getRegistre()->getEspaces() as $espace_de_nom) { |
ob_start(); |
extract($GLOBALS['_GTT_']['i18n']['general'], EXTR_PREFIX_ALL, 'i18n_general'); |
extract($this->getRegistre()->getDonnees($espace_de_nom)); |
include_once GTT_CHEMIN_PRESENTATION.$this->getRegistre()->getSquelettes($espace_de_nom); |
// Répartition dans des zones |
switch($espace_de_nom) { |
case 'principal' : |
$contenu_principal .= ob_get_contents(); |
break; |
case 'identification' : |
$aso_contenu['zone_identification'] .= ob_get_contents(); |
break; |
default: |
$aso_contenu['zone_contenu'] .= ob_get_contents(); |
} |
ob_end_clean(); |
} |
if (!is_null($contenu_principal)) { |
return $contenu_principal; |
} |
return $aso_contenu; |
} |
} |
?> |