149 |
aurelien |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Modèle d'accès à la base de données des listes
|
|
|
5 |
* d'ontologies
|
|
|
6 |
*
|
|
|
7 |
* PHP Version 5
|
|
|
8 |
*
|
|
|
9 |
* @package Framework
|
|
|
10 |
* @category Class
|
|
|
11 |
* @author aurelien <aurelien@tela-botanica.org>
|
|
|
12 |
* @copyright 2009 Tela-Botanica
|
|
|
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
|
|
|
15 |
* @version SVN: $$Id: ListeAdmin.php 128 2009-09-02 12:20:55Z aurelien $$
|
|
|
16 |
* @link /doc/framework/
|
|
|
17 |
*
|
|
|
18 |
*/
|
|
|
19 |
class GestionAnnuaireModele extends Modele {
|
|
|
20 |
|
|
|
21 |
public function verifierPresenceTable($bdd, $nom_table) {
|
|
|
22 |
|
|
|
23 |
if(!$bdd || !$nom_table) {
|
|
|
24 |
return false;
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
$requete = 'DESCRIBE '.$bdd.'.'.$nom_table;
|
|
|
28 |
$resultat = $this->requeteUn($requete);
|
|
|
29 |
|
|
|
30 |
return $resultat;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
public function verifierPresenceChamps($bdd, $nom_table, $champs_a_verifier) {
|
|
|
34 |
|
|
|
35 |
if(!$bdd || !$nom_table) {
|
|
|
36 |
return false;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
$requete = 'DESCRIBE '.$bdd.'.'.$nom_table;
|
|
|
40 |
|
|
|
41 |
$resultat = $this->requeteTous($requete);
|
|
|
42 |
|
|
|
43 |
if(!$resultat) {
|
|
|
44 |
return false;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
$tableau_champs_table = array();;
|
|
|
48 |
|
|
|
49 |
foreach($resultat as $champ_table) {
|
|
|
50 |
$tableau_champs_table[] = $champ_table['Field'];
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
foreach($champs_a_verifier as $champ) {
|
|
|
54 |
if(!in_array($champ, $tableau_champs_table)) {
|
|
|
55 |
return false;
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
return $resultat;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
public function ajouterAnnuaire($informations) {
|
|
|
63 |
|
|
|
64 |
if(!$informations) {
|
|
|
65 |
return false;
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
$valeurs_prot = array_map(array($this,'proteger'),$informations);
|
|
|
69 |
|
|
|
70 |
$valeurs = implode(',',$valeurs_prot);
|
|
|
71 |
$champs = implode(',',array_keys($informations));
|
|
|
72 |
|
|
|
73 |
$requete_insertion_annuaire = 'INSERT INTO annu_annuaire '.
|
|
|
74 |
'('.$champs.') '.
|
|
|
75 |
'VALUES ('.$valeurs.')';
|
|
|
76 |
|
|
|
77 |
$resultat_insertion_annuaire = $this->requete($requete_insertion_annuaire);
|
|
|
78 |
|
|
|
79 |
$id_annuaire = false;
|
|
|
80 |
|
|
|
81 |
if($resultat_insertion_annuaire) {
|
|
|
82 |
|
|
|
83 |
$requete_selection_annuaire = 'SELECT aa_id_annuaire FROM annu_annuaire '.
|
|
|
84 |
' WHERE aa_code = '.$this->proteger($informations['aa_code']);
|
|
|
85 |
|
|
|
86 |
$resultat_selection_annuaire = $this->requeteUn($requete_selection_annuaire);
|
|
|
87 |
|
|
|
88 |
if($resultat_selection_annuaire) {
|
|
|
89 |
$id_annuaire = $resultat_selection_annuaire['aa_id_annuaire'];
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
return $id_annuaire;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
* Charge la liste complète des champs d'un annuaire
|
|
|
98 |
* @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
|
|
|
100 |
* @return array un tableau contenant des objets d'informations sur les annuaires
|
|
|
101 |
*/
|
|
|
102 |
public function chargerAnnuaire($identifiant, $charger_liste_champs = true) {
|
|
|
103 |
|
|
|
104 |
$requete = 'SELECT * '.
|
|
|
105 |
'FROM annu_annuaire '.
|
|
|
106 |
'WHERE aa_id_annuaire = '.$identifiant.' ';
|
|
|
107 |
$resultat = $this->requeteTous($requete);
|
|
|
108 |
$annuaire = array();
|
|
|
109 |
foreach ($resultat as $ligne) {
|
|
|
110 |
$annuaire['informations'] = $ligne;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
if($charger_liste_champs) {
|
|
|
114 |
$requete = 'DESCRIBE '.$annuaire['informations']['aa_bdd'].'.'.$annuaire['informations']['aa_table'];
|
|
|
115 |
$resultat = $this->requeteTous($requete);
|
|
|
116 |
foreach ($resultat as $colonne) {
|
|
|
117 |
$annuaire['colonnes'][] = $colonne;
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
return $annuaire;
|
|
|
122 |
}
|
|
|
123 |
}
|