Subversion Repositories Applications.annuaire

Rev

Rev 149 | Rev 167 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 162
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Modèle d'accès à la base de données des listes
4
 * Modèle d'accès à la base de données des listes
5
 * d'ontologies
5
 * d'ontologies
6
 *
6
 *
7
 * PHP Version 5
7
 * PHP Version 5
8
 *
8
 *
9
 * @package   Framework
9
 * @package   Framework
10
 * @category  Class
10
 * @category  Class
11
 * @author	aurelien <aurelien@tela-botanica.org>
11
 * @author	aurelien <aurelien@tela-botanica.org>
12
 * @copyright 2009 Tela-Botanica
12
 * @copyright 2009 Tela-Botanica
13
 * @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
13
 * @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
14
 * @license   http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
14
 * @license   http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
15
 * @version   SVN: $$Id: ListeAdmin.php 128 2009-09-02 12:20:55Z aurelien $$
15
 * @version   SVN: $$Id: ListeAdmin.php 128 2009-09-02 12:20:55Z aurelien $$
16
 * @link	  /doc/framework/
16
 * @link	  /doc/framework/
17
 *
17
 *
18
 */
18
 */
19
class GestionAnnuaireModele extends Modele {
19
class GestionAnnuaireModele extends Modele {
20
	
20
	
21
	public function verifierPresenceTable($bdd, $nom_table) {
21
	public function verifierPresenceTable($bdd, $nom_table) {
22
		
22
		
23
		if(!$bdd || !$nom_table) {
23
		if(!$bdd || !$nom_table) {
24
			return false;
24
			return false;
25
		}
25
		}
26
 
26
		
27
		$requete = 'DESCRIBE '.$bdd.'.'.$nom_table;
27
		$requete = 'DESCRIBE '.$bdd.'.'.$nom_table;
-
 
28
		
28
		$resultat = $this->requeteUn($requete);
29
		$resultat = $this->requeteUn($requete);
29
		
30
		
30
		return $resultat;
31
		return $resultat;
31
	}
32
	}
32
	
33
	
33
	public function verifierPresenceChamps($bdd, $nom_table, $champs_a_verifier) {
34
	public function verifierPresenceChamps($bdd, $nom_table, $champs_a_verifier) {
-
 
35
		
-
 
36
		$tableau_champs_table = $this->obtenirListeNomsChampsAnnuaireParBddNomTable($bdd, $nom_table);
-
 
37
 
-
 
38
		foreach($champs_a_verifier as $champ) {
-
 
39
			if(!in_array($champ, $tableau_champs_table)) {
-
 
40
				return false;
-
 
41
			}
-
 
42
		}
-
 
43
		
-
 
44
		return $resultat;
-
 
45
	}
-
 
46
	
-
 
47
	public function obtenirListeNomsChampsAnnuaireParBddNomTable($bdd, $nom_table) {
34
		
48
		
35
		if(!$bdd || !$nom_table) {
49
		if(!$bdd || !$nom_table) {
36
			return false;
50
			return false;
37
		}
51
		}
38
 
52
 
39
		$requete = 'DESCRIBE '.$bdd.'.'.$nom_table;
53
		$requete = 'DESCRIBE '.$bdd.'.'.$nom_table;
40
		
54
		
41
		$resultat = $this->requeteTous($requete);
55
		$resultat = $this->requeteTous($requete);
42
		
56
		
43
		if(!$resultat) {
57
		if(!$resultat) {
44
			return false;
58
			return false;
45
		}
59
		}
46
		
60
		
47
		$tableau_champs_table = array();;
61
		$tableau_champs_table = array();;
48
		
62
		
49
		foreach($resultat as $champ_table) {
63
		foreach($resultat as $champ_table) {
50
			$tableau_champs_table[] = $champ_table['Field'];
64
			$tableau_champs_table[] = $champ_table['Field'];
51
		}
65
		}
52
		
66
		
-
 
67
		return $tableau_champs_table;
-
 
68
	}
-
 
69
	
-
 
70
	public function obtenirListeNomsChampsAnnuaireParIdAnnuaire($id_annuaire) {
-
 
71
		
-
 
72
		
-
 
73
		$requete_selection_bdd_table =  'SELECT aa_bdd, aa_table FROM annu_annuaire '.
-
 
74
					' WHERE aa_id_annuaire = '.$this->proteger($id_annuaire);
-
 
75
		
-
 
76
		$resultat_selection_bdd_table = $this->requeteUn($requete_selection_bdd_table);
53
		foreach($champs_a_verifier as $champ) {
77
			
54
			if(!in_array($champ, $tableau_champs_table)) {
78
		if(!$resultat_selection_bdd_table) {
55
				return false;
-
 
56
			}
79
			return array();
57
		}
80
		}
58
		
81
		
59
		return $resultat;
82
		return $this->obtenirListeNomsChampsAnnuaireParBddNomTable($resultat_selection_bdd_table['aa_bdd'], $resultat_selection_bdd_table['aa_table']);
60
	}
83
	}
61
	
84
	
62
	public function ajouterAnnuaire($informations) {
85
	public function ajouterAnnuaire($informations) {
63
		
86
		
64
		if(!$informations) {
87
		if(!$informations) {
65
			return false;
88
			return false;
66
		}
89
		}
67
								
90
								
68
		$valeurs_prot = array_map(array($this,'proteger'),$informations);
91
		$valeurs_prot = array_map(array($this,'proteger'),$informations);
69
		
92
		
70
		$valeurs = implode(',',$valeurs_prot);
93
		$valeurs = implode(',',$valeurs_prot);
71
		$champs = implode(',',array_keys($informations));
94
		$champs = implode(',',array_keys($informations));
72
 
95
 
73
		$requete_insertion_annuaire =  'INSERT INTO annu_annuaire '.
96
		$requete_insertion_annuaire =  'INSERT INTO annu_annuaire '.
74
					'('.$champs.') '.
97
					'('.$champs.') '.
75
					'VALUES ('.$valeurs.')';
98
					'VALUES ('.$valeurs.')';
76
		
99
		
77
		$resultat_insertion_annuaire = $this->requete($requete_insertion_annuaire);
100
		$resultat_insertion_annuaire = $this->requete($requete_insertion_annuaire);
78
		
101
		
79
		$id_annuaire = false;
102
		$id_annuaire = false;
80
		
103
		
81
		if($resultat_insertion_annuaire) {
104
		if($resultat_insertion_annuaire) {
82
			
105
			
83
			$requete_selection_annuaire =  'SELECT aa_id_annuaire FROM annu_annuaire '.
106
			$requete_selection_annuaire =  'SELECT aa_id_annuaire FROM annu_annuaire '.
84
					' WHERE aa_code = '.$this->proteger($informations['aa_code']);
107
					' WHERE aa_code = '.$this->proteger($informations['aa_code']);
85
			
108
			
86
			$resultat_selection_annuaire = $this->requeteUn($requete_selection_annuaire);
109
			$resultat_selection_annuaire = $this->requeteUn($requete_selection_annuaire);
87
			
110
			
88
			if($resultat_selection_annuaire) {
111
			if($resultat_selection_annuaire) {
89
				$id_annuaire = $resultat_selection_annuaire['aa_id_annuaire'];
112
				$id_annuaire = $resultat_selection_annuaire['aa_id_annuaire'];
90
			}
113
			}
91
		}
114
		}
92
		
115
		
93
		return $id_annuaire;
116
		return $id_annuaire;
94
	}
117
	}
-
 
118
	
-
 
119
	public function creerTableAnnuaire($informations_table, $informations_champs) {
-
 
120
		
-
 
121
		$nom_bdd = $this->proteger($informations_table['nom_bdd']);
-
 
122
		$nom_table = $this->proteger($informations_table['nom_table']);
-
 
123
		
-
 
124
		$champ_id = $this->proteger($informations_champs['champ_id']);
-
 
125
		$champ_nom = $this->proteger($informations_champs['champ_id']);
-
 
126
		$champ_mail = $this->proteger($informations_champs['champ_id']);
-
 
127
		$champ_mot_de_passe = $this->proteger($informations_champs['champ_id']);
-
 
128
		
-
 
129
		$requete_creation_table = 'CREATE TABLE '.$bdd.'.'.$nom_table.' '.
-
 
130
									'('.$champ_id.' INT NOT NULL AUTO_INCREMENT PRIMARY KEY,'. 
-
 
131
									$champ_nom.' TEXT NOT NULL,'. 
-
 
132
									$champ_mail.' TEXT NOT NULL)'. 
-
 
133
									$champ_mot_de_passe.' TEXT NOT NULL)';
-
 
134
									//'ENGINE = MyISAM' ;
-
 
135
									
-
 
136
		echo $requete_creation_table;
-
 
137
		exit;
-
 
138
		
-
 
139
		return $this->requete($requete_creation_table);
-
 
140
		
-
 
141
	}
95
	
142
	
96
	/**
143
	/**
97
	 * Charge la liste complète des champs d'un annuaire
144
	 * Charge la liste complète des champs d'un annuaire
98
	 * @param int $identifiant l'identifiant de l'annuaire demandé
145
	 * @param int $identifiant l'identifiant de l'annuaire demandé
99
	 * @param boolean $charger_liste_champs indique si l'on doit ou non charger la liste des noms des champs
146
	 * @param boolean $charger_liste_champs indique si l'on doit ou non charger la liste des noms des champs
100
	 * @return array un tableau contenant des objets d'informations sur les annuaires
147
	 * @return array un tableau contenant des objets d'informations sur les annuaires
101
	 */
148
	 */
102
   	public function chargerAnnuaire($identifiant, $charger_liste_champs = true) {
149
   	public function chargerAnnuaire($identifiant, $charger_liste_champs = true) {
103
 
150
 
104
		$requete = 	'SELECT * '.
151
		$requete = 	'SELECT * '.
105
					'FROM  annu_annuaire '.
152
					'FROM  annu_annuaire '.
106
					'WHERE aa_id_annuaire = '.$identifiant.' ';
153
					'WHERE aa_id_annuaire = '.$identifiant.' ';
107
		$resultat = $this->requeteTous($requete);
154
		$resultat = $this->requeteTous($requete);
108
		$annuaire = array();
155
		$annuaire = array();
109
		foreach ($resultat as $ligne) {
156
		foreach ($resultat as $ligne) {
110
			$annuaire['informations'] = $ligne;
157
			$annuaire['informations'] = $ligne;
111
		}
158
		}
112
 
159
 
113
		if($charger_liste_champs) {
160
		if($charger_liste_champs) {
114
			$requete = 'DESCRIBE '.$annuaire['informations']['aa_bdd'].'.'.$annuaire['informations']['aa_table'];
161
			$requete = 'DESCRIBE '.$annuaire['informations']['aa_bdd'].'.'.$annuaire['informations']['aa_table'];
115
			$resultat = $this->requeteTous($requete);
162
			$resultat = $this->requeteTous($requete);
116
			foreach ($resultat as $colonne) {
163
			foreach ($resultat as $colonne) {
117
				$annuaire['colonnes'][] = $colonne;
164
				$annuaire['colonnes'][] = $colonne;
118
			}
165
			}
119
		}
166
		}
120
 
167
 
121
		return $annuaire;
168
		return $annuaire;
122
	}
169
	}
123
}
170
}