Subversion Repositories Applications.gtt

Rev

Rev 10 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10 Rev 11
Line 1... Line 1...
1
<?php
1
<?php
Line 2... Line 2...
2
 
2
 
Line 3... Line 3...
3
class Controlleur {
3
class ControlleurFrontal {
-
 
4
	
-
 
5
	public function getRegistre()
-
 
6
	{
-
 
7
		return Registre::getRegistre();
-
 
8
	}
4
	
9
	
5
	public function executer($action)
10
	public function parserAction($url)
6
    {
11
    {
7
    	if (preg_match('/^(.+?)(?:_(.+)|)$/', $action, $match)) {
12
    	if (preg_match('/^(.+?)(?:_(.+)|)$/', $url, $match)) {
Line 8... Line 13...
8
	    	$classe_action = 'GttAction'.ucfirst($match[1]);
13
	    	$retour['classe_action'] = 'GttCtrlAction'.ucfirst($match[1]);
9
    	}
14
    	}
10
    	
15
    	
11
    	$tab_actions = array();
16
    	$retour['tab_actions'] = array('');
12
    	if (isset($match[2])) {
17
    	if (isset($match[2])) {
-
 
18
    		preg_match_all('/(.+)(?:_|$)/', $match[2], $match_actions);
-
 
19
    		$retour['tab_actions'] = $match_actions[1];
-
 
20
    	}
-
 
21
		return $retour;
-
 
22
    }
-
 
23
 
-
 
24
	public function executer($url_action)
-
 
25
    {
13
    		preg_match_all('/(.+)(?:_|$)/', $match[2], $match_actions);
26
    	$tab_info_url = $this->parserAction($url_action);
14
    		$tab_actions = $match_actions[1];
27
    	//echo '<pre>'.print_r($tab_info_url, true).'</pre>';
15
    	}
28
    	$classe_action = $tab_info_url['classe_action'];
16
		$fichier_action = GTT_CHEMIN_ACTION.$classe_action.'.class.php';
29
    	$fichier_action = GTT_CHEMIN_ACTION.$classe_action.'.class.php';
17
    	if (file_exists($fichier_action)) {
-
 
18
			require_once $fichier_action;
30
    	if (file_exists($fichier_action)) {
19
			$Action = new $classe_action;
31
			require_once $fichier_action;
20
			
32
			$Action = new $classe_action($this->getRegistre());
-
 
33
			foreach ($tab_info_url['tab_actions'] as $action) {
21
			foreach ($tab_actions as $action) {
34
				// Vérification des données POST ou GET avant l'appel de l'action
22
				// Vérification des données POST ou GET avant l'appel de l'action
35
				if (isset($_POST) || isset($_GET)) {
23
				if (isset($_POST) || isset($_GET)) {
36
					$Action->verifier();
24
					$methode_verif = 'verifier'.ucfirst($action);
37
					$methode_verif = 'verifier'.ucfirst($action);
25
					if (method_exists($Action, $methode_verif)) {
38
					if (method_exists($Action, $methode_verif)) {
26
						// Méthode "vérifier" spécifique à une action
39
						// Méthode "vérifier" spécifique à une action
27
						$Action->$methode_verif($Action->getResultat());
40
						$Action->$methode_verif();
28
					}
41
					}
29
				}
42
				}
30
				// Execution de l'action
43
				// Execution de l'action
31
				$Action->setSuivant(ucfirst($action));
44
				$Action->setSuivant(ucfirst($action));
-
 
45
			}
32
			}
46
			$Action->demarrer();
33
			$Action->demarrer();
47
			$aso_principal['principal'] = $this->rendre();
34
			$aso_principal['principal']['contenu_principal'] = $this->rendre($Action->getResultat());
48
			//echo '<pre>'.print_r($aso_principal, true).'</pre>';
35
			$Resultats = $Action->getResultat();
49
			$Resultats = $this->getRegistre();
36
			$aso_principal['principal']['titre'] = $Resultats->getTitre();
50
			$aso_principal['principal']['titre'] = $Resultats->getTitre();
37
			$Resultats->setEspaces(array());
51
			$Resultats->setEspaces(array());
38
			$Resultats->setSquelettes(array());
52
			$Resultats->setSquelettes(array());
39
			$Resultats->setDonnees(array());
53
			$Resultats->setDonnees(array());
40
			$Resultats->ajouterEspace('Principal', 'principal');
54
			$Resultats->ajouterEspace('Principal', 'principal');
-
 
55
    		$Resultats->ajouterSquelette('principal', 'principal.tpl.html');
-
 
56
    		$Resultats->ajouterDonnee('principal', $aso_principal['principal']);
-
 
57
    		return $this->rendre();
41
    		$Resultats->ajouterSquelette('principal', 'principal.tpl.html');
58
    	} else {
42
    		$Resultats->ajouterDonnee('principal', $aso_principal['principal']);
59
    		$m = "Le fichier $fichier_action contenant l'action est introuvable!";
Line 43... Line 60...
43
    		return $this->rendre($Resultats);
60
    		trigger_error($m, E_USER_ERROR);
44
    	}
61
    	}
45
    }
62
    }
-
 
63
    
46
    
64
    public function rendre()
47
    public function rendre(Resultat $Resultats)
65
    {
48
    {
66
    	$contenu_principal = null;
49
    	$contenu = '';
67
    	$aso_contenu = array('zone_contenu' => '', 'zone_identification' => '');
50
    	foreach ($Resultats->getEspaces() as $espace_de_nom) {
68
    	foreach ($this->getRegistre()->getEspaces() as $espace_de_nom) {
-
 
69
    		ob_start();
-
 
70
    		extract($GLOBALS['_GTT_']['i18n']['general'], EXTR_PREFIX_ALL, 'i18n_general');
-
 
71
    		extract($this->getRegistre()->getDonnees($espace_de_nom));
51
    		ob_start();
72
			include_once GTT_CHEMIN_PRESENTATION.$this->getRegistre()->getSquelettes($espace_de_nom);
-
 
73
			// Répartition dans des zones 
-
 
74
			switch($espace_de_nom) {
-
 
75
    			case 'principal' :
-
 
76
    				$contenu_principal .= ob_get_contents();
-
 
77
    				break;
-
 
78
    			case 'identification' :
-
 
79
    				$aso_contenu['zone_identification'] .= ob_get_contents();
52
    		extract($GLOBALS['_GTT_']['i18n']['general'], EXTR_PREFIX_ALL, 'i18n_general');
80
    				break;
-
 
81
    			default:
-
 
82
    				$aso_contenu['zone_contenu'] .= ob_get_contents();
-
 
83
    		}
53
    		extract($Resultats->getDonnees($espace_de_nom));
84
    		ob_end_clean();
54
			include_once GTT_CHEMIN_PRESENTATION.$Resultats->getSquelettes($espace_de_nom);
85
    	}
55
			$contenu .= ob_get_contents();
86
    	if (!is_null($contenu_principal)) {
56
			ob_end_clean();
87
    		return $contenu_principal;
57
    	}
88
    	}
58
    	return $contenu;
89
    	return $aso_contenu;