Subversion Repositories eFlore/Applications.del

Rev

Rev 1174 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
803 gduche 1
<?php
2
/**
3
* Description :
4
* Classe principale de chargement des services d'eFlore.
5
*
6
* Encodage en entrée : utf8
7
* Encodage en sortie : utf8
8
* @package eflore-projets
9
* @author Jennifer DHÉ <jennifer.dhe@tela-botanica.org>
10
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
11
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
13
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
14
* @version 0.1
15
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
16
*/
17
class Utilisateurs extends RestService {
18
 
19
 
20
	private $parametres = array();
21
	private $ressources = array();
22
	private $methode = null;
23
	private $projetNom = array();
24
	private $serviceNom = array();
25
	private $cheminCourant = null;
26
 
27
	private $conteneur;
28
 
29
	/** Indique si oui (true) ou non (false), on veut utiliser les paramètres bruts. */
30
	protected $utilisationParametresBruts = true;
31
 
32
	public function __construct() {
33
		$this->cheminCourant = dirname(__FILE__).DS;
34
	}
35
 
36
	public function consulter($ressources, $parametres) {
37
		$this->methode = 'consulter';
38
		$resultat = '';
39
		$reponseHttp = new ReponseHttp();
40
		try {
41
			$this->initialiserRessourcesEtParametres($ressources, $parametres);
42
			$this->conteneur = new Conteneur($this->parametres);
43
			$resultat = $this->traiterRessources();
44
			$reponseHttp->setResultatService($resultat);
45
		} catch (Exception $e) {
46
			$reponseHttp->ajouterErreur($e);
47
		}
48
		$reponseHttp->emettreLesEntetes();
49
		$corps = $reponseHttp->getCorps();
50
		return $corps;
51
	}
52
 
1174 aurelien 53
	public function modifier($ressources, $parametres) {
54
		$this->methode = 'modifier';
55
		$resultat = '';
56
		$reponseHttp = new ReponseHttp();
57
		try {
58
			$this->initialiserRessourcesEtParametres($ressources, $parametres);
59
			$this->conteneur = new Conteneur($this->parametres);
60
			$resultat = $this->traiterRessources();
61
			$reponseHttp->setResultatService($resultat);
62
		} catch (Exception $e) {
63
			$reponseHttp->ajouterErreur($e);
64
		}
65
		$reponseHttp->emettreLesEntetes();
66
		$corps = $reponseHttp->getCorps();
67
		return $corps;
68
	}
69
 
803 gduche 70
	private function initialiserRessourcesEtParametres($ressources, $parametres) {
71
		$this->ressources = $ressources;
72
		$this->parametres = $parametres;
73
	}
74
 
75
	private function traiterRessources() {
76
		$retour = '';
77
		$this->initialiserProjet();
78
		$retour = $this->initialiserService();
79
		return $retour;
80
	}
81
 
82
 
83
	/*------------------------------------------------------------------------------------------------------------------
84
										CONFIGURATION DU PROJET
85
	------------------------------------------------------------------------------------------------------------------*/
86
	private function initialiserProjet() {
87
		$this->projetNom = 'utilisateurs';
88
		$this->chargerConfigProjet();
89
	}
90
 
91
	private function chargerConfigProjet() {
92
		$projet = $this->projetNom;
93
		$chemin = Config::get('chemin_configurations')."config_$projet.ini";
94
		Config::charger($chemin);
95
	}
96
 
97
	/*------------------------------------------------------------------------------------------------------------------
98
								CONFIGURATION DU SERVICE
99
	------------------------------------------------------------------------------------------------------------------*/
100
	private function initialiserService() {
101
 
102
		$this->chargerNomService();
103
 
104
		$classe = $this->obtenirNomClasseService($this->serviceNom);
105
		$chemins = array();
106
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
107
		$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
108
		$retour = '';
109
		$service = null;
110
		foreach ($chemins as $chemin) {
111
			if (file_exists($chemin)) {
112
				$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
113
 
114
				require_once $chemin;
115
				$service = new $classe($this->conteneur);
116
				if ($this->methode == 'consulter') {
117
					$retour = $service->consulter($this->ressources, $this->parametres);
118
				} elseif ($this->methode == 'ajouter') {
119
					$retour = $service->ajouter($this->ressources, $this->parametres);
1174 aurelien 120
				} elseif ($this->methode == 'modifier') {
121
					$retour = $service->modifier($this->ressources, $this->parametres);
803 gduche 122
				}
123
			}
124
		}
125
 
126
		if (is_null($service)) {
127
			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
128
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
129
			throw new Exception($message, $code);
130
		}
131
		return $retour;
132
	}
133
 
134
	private function chargerNomService() {
135
		//S'il n'y a pas de ressources => envoyer sur identification anonyme
136
		if (!isset($this->ressources) || empty($this->ressources)) {
137
			$this->serviceNom = 'identification-anonyme';
138
		} else {
139
			//S'il y a 1 ressource et que celle ci est 'deconnecter', envoyer vers deconnecter
140
			if (sizeof($this->ressources) == 1 && ($this->ressources[0] == 'deconnecter')) {
141
				$this->serviceNom = 'deconnecter';
1174 aurelien 142
			} else if(sizeof($this->ressources) == 2 && $this->ressources[1] == 'preferences') {
143
				$this->serviceNom = 'preferences';
803 gduche 144
			} else if (sizeof($this->ressources) == 2) {
145
				$this->serviceNom = 'connecter';
146
			} else {
147
				$this->serviceNom = 'identification-anonyme';
148
			}
149
		}
150
	}
151
 
152
	private function obtenirNomClasseService($mot) {
153
		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
154
		return $classeNom;
155
	}
156
 
157
 
158
}
159
?>