803 |
gduche |
1 |
<?php
|
1820 |
jpm |
2 |
// declare(encoding='UTF-8');
|
803 |
gduche |
3 |
/**
|
1795 |
jpm |
4 |
* Classe principale de chargement des sous-services liés aux utilisateurs.
|
|
|
5 |
*
|
|
|
6 |
* @category DEL
|
|
|
7 |
* @package Services
|
|
|
8 |
* @subpackage Utilisateurs
|
|
|
9 |
* @version 0.1
|
|
|
10 |
* @author Mathias CHOUET <mathias@tela-botanica.org>
|
|
|
11 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
12 |
* @author Aurelien PERONNET <aurelien@tela-botanica.org>
|
|
|
13 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
14 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
15 |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org>
|
|
|
16 |
*/
|
803 |
gduche |
17 |
class Utilisateurs extends RestService {
|
|
|
18 |
|
1666 |
jpm |
19 |
|
803 |
gduche |
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;
|
1666 |
jpm |
28 |
|
803 |
gduche |
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 |
}
|
1666 |
jpm |
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 |
}
|
1666 |
jpm |
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 |
|
1666 |
jpm |
82 |
|
803 |
gduche |
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() {
|
1666 |
jpm |
101 |
|
803 |
gduche |
102 |
$this->chargerNomService();
|
1666 |
jpm |
103 |
|
803 |
gduche |
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');
|
1666 |
jpm |
113 |
|
803 |
gduche |
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') {
|
1666 |
jpm |
119 |
$retour = $service->ajouter($this->ressources, $this->parametres);
|
1174 |
aurelien |
120 |
} elseif ($this->methode == 'modifier') {
|
1666 |
jpm |
121 |
$retour = $service->modifier($this->ressources, $this->parametres);
|
803 |
gduche |
122 |
}
|
|
|
123 |
}
|
|
|
124 |
}
|
1666 |
jpm |
125 |
|
803 |
gduche |
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 |
}
|
1666 |
jpm |
133 |
|
803 |
gduche |
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 |
?>
|