144 |
aurelien |
1 |
<?php
|
161 |
aurelien |
2 |
/**
|
|
|
3 |
* PHP Version 5
|
|
|
4 |
*
|
|
|
5 |
* @category PHP
|
|
|
6 |
* @package annuaire
|
|
|
7 |
* @author aurelien <aurelien@tela-botanica.org>
|
|
|
8 |
* @copyright 2010 Tela-Botanica
|
|
|
9 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
10 |
* @version SVN: <svn_id>
|
|
|
11 |
* @link /doc/annuaire/
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
class GestionAnnuaireControleur extends AppControleur {
|
|
|
15 |
|
|
|
16 |
private $id_liste_champs = 30768;
|
|
|
17 |
|
|
|
18 |
/**--------Fonctions d'ajout et de modification des annuaires --------*/
|
|
|
19 |
|
|
|
20 |
/**
|
164 |
aurelien |
21 |
* Charge la vue contenant les informations d'un annuaire donné en paramètre
|
|
|
22 |
* @param int $id l'identifiant de l'annuaire
|
|
|
23 |
* @return string la vue contenant les informations sur l'annuaire
|
|
|
24 |
*/
|
|
|
25 |
public function chargerAnnuaire($id) {
|
|
|
26 |
$this->chargerModele('AnnuaireModele');
|
|
|
27 |
$this->chargerModele('MetadonneeModele');
|
|
|
28 |
$data['erreurs'] = array();
|
|
|
29 |
$data['champs_mappage'] = $this->obtenirChampsMappageAnnuaire($id);
|
|
|
30 |
$data['annuaire'] = $this->AnnuaireModele->chargerAnnuaire($id, true);
|
|
|
31 |
$data['metadonnees'] = $this->MetadonneeModele->chargerListeMetadonneeAnnuaire($id);
|
|
|
32 |
$annuaire = $this->getVue(Config::get('dossier_squelettes_gestion_annuaires').'annuaire', $data);
|
|
|
33 |
|
|
|
34 |
return $annuaire;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
/**
|
161 |
aurelien |
38 |
* Affiche le formulaire d'ajout d'un annuaire
|
|
|
39 |
* @param Array $valeurs les valeurs à inclure dans le formulaire (dans le cas du retour erreur)
|
|
|
40 |
* @return string la vue contenant le formulaire
|
|
|
41 |
*/
|
|
|
42 |
public function afficherFormulaireAjoutAnnuaire($donnees) {
|
|
|
43 |
|
|
|
44 |
$champs = array(
|
|
|
45 |
"aa_nom" => '',
|
|
|
46 |
"aa_description" => '',
|
|
|
47 |
"aa_bdd" => '',
|
|
|
48 |
"aa_table" => '',
|
|
|
49 |
"aa_code" => '',
|
|
|
50 |
"aa_champ_id" => '',
|
|
|
51 |
"aa_champ_nom" => '',
|
|
|
52 |
"aa_champ_mail" => '',
|
|
|
53 |
"aa_champ_pass" => ''
|
|
|
54 |
);
|
|
|
55 |
$donnees = $donnees;
|
|
|
56 |
|
|
|
57 |
$formulaire_ajout_annuaire = $this->getVue(Config::get('dossier_squelettes_gestion_annuaires').'annuaire_ajout',$donnees);
|
|
|
58 |
|
|
|
59 |
return $formulaire_ajout_annuaire;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
public function ajouterAnnuaire($valeurs) {
|
|
|
63 |
|
|
|
64 |
$champs = array(
|
|
|
65 |
"aa_nom" => '',
|
|
|
66 |
"aa_description" => '',
|
|
|
67 |
"aa_bdd" => '',
|
|
|
68 |
"aa_table" => '',
|
|
|
69 |
"aa_code" => '',
|
|
|
70 |
"aa_champ_id" => '',
|
|
|
71 |
"aa_champ_nom" => '',
|
|
|
72 |
"aa_champ_mail" => '',
|
|
|
73 |
"aa_champ_pass" => ''
|
|
|
74 |
);
|
|
|
75 |
|
|
|
76 |
$donnees = array('erreurs_champs' => array());
|
|
|
77 |
|
|
|
78 |
// vérification de la présence de tous les champs
|
|
|
79 |
foreach($champs as $nom_champ => $valeur) {
|
|
|
80 |
if(!isset($valeurs[$nom_champ]) || $valeurs[$nom_champ] == '') {
|
|
|
81 |
$donnees['erreurs_champs'][$nom_champ] = 'Ce champ est obligatoire';
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
// si il y a une erreur on réaffiche le formulaire
|
|
|
86 |
if(!empty($donnees['erreurs_champs'])) {
|
|
|
87 |
return $this->afficherFormulaireAjoutAnnuaire($donnees);
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
$champs_a_verifier = array($valeurs[aa_champ_id],$valeurs[aa_champ_nom],$valeurs[aa_champ_mail],$valeurs[aa_champ_pass]);
|
|
|
91 |
|
|
|
92 |
$informations_annuaire = array(
|
|
|
93 |
"aa_nom" => $valeurs['aa_nom'],
|
|
|
94 |
"aa_description" => $valeurs['aa_description'],
|
|
|
95 |
"aa_bdd" => $valeurs['aa_bdd'],
|
|
|
96 |
"aa_table" => $valeurs['aa_table'],
|
|
|
97 |
"aa_code" => $valeurs['aa_code'],
|
|
|
98 |
);
|
|
|
99 |
|
|
|
100 |
$informations_champs = array(
|
|
|
101 |
"aa_champ_id" => $valeurs['aa_champ_id'],
|
|
|
102 |
"aa_champ_nom" => $valeurs['aa_champ_nom'],
|
|
|
103 |
"aa_champ_mail" => $valeurs['aa_champ_mail'],
|
|
|
104 |
"aa_champ_pass" => $valeurs['aa_champ_pass']
|
|
|
105 |
);
|
|
|
106 |
|
|
|
107 |
$this->chargerModele('GestionAnnuaireModele');
|
|
|
108 |
$annuaire_existe = $this->GestionAnnuaireModele->verifierPresenceTable($valeurs['aa_bdd'], $valeurs['aa_table']);
|
|
|
109 |
|
|
|
110 |
// si l'annuaire existe déjà
|
|
|
111 |
if($annuaire_existe) {
|
|
|
112 |
$champs_existent = $this->GestionAnnuaireModele->verifierPresenceChamps($valeurs['aa_bdd'], $valeurs['aa_table'], $champs_a_verifier);
|
|
|
113 |
// si l'annuaire existe déjà
|
|
|
114 |
if($champs_existent) {
|
|
|
115 |
// tout existe déjà, rien à créer
|
|
|
116 |
}
|
|
|
117 |
} else {
|
|
|
118 |
|
|
|
119 |
$creation_table = $this->creerTableAnnuaire($informations_annuaire, $informations_champs);
|
|
|
120 |
if(!$creation_table) {
|
|
|
121 |
$donnees['erreurs'] = 'Impossible de créer la table '.$informations_annuaire['aa_table'].' dans la base '.$informations_annuaire['aa_bdd'];
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
// on insere un nouvel enregistrement dans la table des annuaire
|
|
|
126 |
$id_annuaire = $this->GestionAnnuaireModele->AjouterAnnuaire($informations_annuaire);
|
|
|
127 |
|
|
|
128 |
if(!$id_annuaire) {
|
|
|
129 |
$donnees['erreurs_champs'][$nom_champ] = 'Impossible d\'ajouter les infos de la table '.$valeurs['aa_table'].' dans la base de données '.$valeurs['aa_bdd'] ;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
// on cree un set de métadonnées minimal
|
|
|
133 |
$this->creerEtMapperChampsMetadonneeMinimaux($id_annuaire, $informations_champs);
|
|
|
134 |
|
|
|
135 |
return $this->chargerAnnuaire($id_annuaire);
|
|
|
136 |
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
private function creerTableAnnuaire($informations_annuaire, $information_champs) {
|
|
|
140 |
$this->chargerModele('GestionAnnuaireModele');
|
|
|
141 |
|
|
|
142 |
$this->GestionAnnuaireModele->creerTableAnnuaire($informations_annuaire, $information_champs);
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
private function creerEtMapperChampsMetadonneeMinimaux($id_annuaire, $informations_champs) {
|
|
|
146 |
|
|
|
147 |
$metadonnee_controleur = new MetadonneeControleur();
|
|
|
148 |
$this->chargerModele('MappageModele');
|
|
|
149 |
$this->chargerModele('MetadonneeModele');
|
|
|
150 |
|
|
|
151 |
foreach($informations_champs as $type_champ => $nom) {
|
|
|
152 |
|
|
|
153 |
$role = str_replace('aa_','',$type_champ);
|
|
|
154 |
|
|
|
155 |
if($role == 'champ_id') {
|
|
|
156 |
$valeurs_mappage = array(
|
|
|
157 |
'id_annuaire' => $id_annuaire,
|
|
|
158 |
'id_champ_annuaire' => $nom,
|
|
|
159 |
'role' => 'champ_id',
|
|
|
160 |
'id_champ_metadonnee' => ''
|
|
|
161 |
);
|
|
|
162 |
$creation = $this->MappageModele->ajouterNouveauMappage($id_annuaire, $nom, 'champ_id', '0');
|
|
|
163 |
|
|
|
164 |
} else {
|
|
|
165 |
|
|
|
166 |
$valeurs_insertion = $this->renvoyerInformationChampPourType($id_annuaire, $role, $nom);
|
|
|
167 |
|
|
|
168 |
$metadonnee_controleur->ajouterNouvelleMetadonnee($valeurs_insertion);
|
|
|
169 |
|
|
|
170 |
$id_champ_metadonnee = $this->MetadonneeModele->renvoyerIdChampMetadonneeParAbreviation($id_annuaire, $valeurs_insertion['amc_abreviation']);
|
|
|
171 |
|
|
|
172 |
// on affecte à chaque champ son role
|
|
|
173 |
$this->MappageModele->ajouterNouveauMappage($id_annuaire, $nom, $role, $id_champ_metadonnee);
|
|
|
174 |
// et on le rend obligatoire
|
|
|
175 |
$this->MappageModele->ajouterNouveauMappage($id_annuaire, $nom, 'champ_obligatoire', $id_champ_metadonnee);
|
|
|
176 |
|
|
|
177 |
}
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
return true;
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
private function renvoyerInformationChampPourType($id_annuaire, $type, $nom) {
|
|
|
184 |
|
|
|
185 |
$valeurs = array();
|
|
|
186 |
$this->chargerModele('MetadonneeModele');
|
|
|
187 |
|
|
|
188 |
$id_liste_champs = $this->id_liste_champs;
|
|
|
189 |
|
|
|
190 |
switch($type) {
|
|
|
191 |
case 'champ_nom':
|
|
|
192 |
|
|
|
193 |
$affichage = $this->MetadonneeModele->renvoyerCorrespondanceIdParAbreviation('text',$id_liste_champs);
|
|
|
194 |
|
|
|
195 |
$valeurs = array('amc_nom' => $nom,
|
|
|
196 |
'amc_abreviation' => 'nom' ,
|
|
|
197 |
'amc_description' => 'Nom',
|
|
|
198 |
'amc_ce_annuaire' => $id_annuaire,
|
|
|
199 |
'amc_ce_type_affichage' => $affichage,
|
|
|
200 |
'amc_ce_ontologie' => '0'
|
|
|
201 |
);
|
|
|
202 |
break;
|
|
|
203 |
|
|
|
204 |
case 'champ_mail':
|
|
|
205 |
|
|
|
206 |
$affichage = $this->MetadonneeModele->renvoyerCorrespondanceIdParAbreviation('mail',$id_liste_champs);
|
|
|
207 |
$valeurs = array('amc_nom' => $nom,
|
|
|
208 |
'amc_abreviation' => 'mail',
|
|
|
209 |
'amc_description' => 'Adresse electronique',
|
|
|
210 |
'amc_ce_annuaire' => $id_annuaire,
|
|
|
211 |
'amc_ce_type_affichage' => $affichage,
|
|
|
212 |
'amc_ce_ontologie' => '0'
|
|
|
213 |
);
|
|
|
214 |
break;
|
|
|
215 |
|
|
|
216 |
case 'champ_pass':
|
|
|
217 |
|
|
|
218 |
$affichage = $this->MetadonneeModele->renvoyerCorrespondanceIdParAbreviation('password',$id_liste_champs);
|
|
|
219 |
$valeurs = array('amc_nom' => $nom,
|
|
|
220 |
'amc_abreviation' => 'pass',
|
|
|
221 |
'amc_description' => 'Mot de passe',
|
|
|
222 |
'amc_ce_annuaire' => $id_annuaire,
|
|
|
223 |
'amc_ce_type_affichage' => $affichage,
|
|
|
224 |
'amc_ce_ontologie' => '0'
|
|
|
225 |
);
|
|
|
226 |
break;
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
return $valeurs;
|
|
|
230 |
}
|
|
|
231 |
}
|