2 |
jpm |
1 |
<?php
|
|
|
2 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
3 |
// | PHP version 4.1 |
|
|
|
4 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
5 |
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) |
|
|
|
6 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
7 |
// | This library is free software; you can redistribute it and/or |
|
|
|
8 |
// | modify it under the terms of the GNU Lesser General Public |
|
|
|
9 |
// | License as published by the Free Software Foundation; either |
|
|
|
10 |
// | version 2.1 of the License, or (at your option) any later version. |
|
|
|
11 |
// | |
|
|
|
12 |
// | This library is distributed in the hope that it will be useful, |
|
|
|
13 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
14 |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
|
15 |
// | Lesser General Public License for more details. |
|
|
|
16 |
// | |
|
|
|
17 |
// | You should have received a copy of the GNU Lesser General Public |
|
|
|
18 |
// | License along with this library; if not, write to the Free Software |
|
|
|
19 |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
|
20 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
21 |
|
|
|
22 |
// |@author ABDOOL RAHEEM shaheen shaheenar50@hotmail.com |
|
|
|
23 |
// |@version 3 |
|
|
|
24 |
|
|
|
25 |
|
8 |
jpm |
26 |
class Preference {
|
5 |
jpm |
27 |
private $table = 'gestion_preferences';
|
|
|
28 |
private $id_utilisateur = null;
|
|
|
29 |
private $id_projet = null;
|
|
|
30 |
|
|
|
31 |
/*** Constructeur */
|
|
|
32 |
function Preference($u, $p)
|
|
|
33 |
{
|
8 |
jpm |
34 |
$this->id_utilisateur = $u;
|
|
|
35 |
$this->id_projet = $p;
|
5 |
jpm |
36 |
}
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Ajouter une préférence dans la base de données.
|
|
|
40 |
*@return true si ok, false si aucun enregistrement effectué
|
|
|
41 |
*/
|
|
|
42 |
function ajouter()
|
|
|
43 |
{
|
|
|
44 |
$requete = 'INSERT INTO gestion_preferences (gp_id_utilisateur, gp_id_projet) '.
|
|
|
45 |
'VALUES ('.$this->id_utilisateur.', '.$this->id_projet.')';
|
|
|
46 |
$resultat = $GLOBALS['db']->query($requete);
|
2 |
jpm |
47 |
|
8 |
jpm |
48 |
(DB::isError($resultat)) ? die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;
|
|
|
49 |
|
5 |
jpm |
50 |
$nbre_enregistrement_ajoute = $GLOBALS['db']->affectedRows();
|
|
|
51 |
|
|
|
52 |
if ($nbre_enregistrement_ajoute == 1) {
|
|
|
53 |
return true;
|
|
|
54 |
} elseif ($nbre_enregistrement_ajoute == 0) {
|
|
|
55 |
return false;
|
|
|
56 |
}
|
|
|
57 |
}
|
8 |
jpm |
58 |
|
5 |
jpm |
59 |
/**
|
8 |
jpm |
60 |
*supprimer liste de preferences
|
|
|
61 |
*pour un utilisateur donne
|
|
|
62 |
*@param identifiant d'un utilisateur
|
|
|
63 |
*/
|
|
|
64 |
function supprimer($id)
|
|
|
65 |
{
|
|
|
66 |
$requete = 'DELETE FROM '.GEST_PREFERENCES.' '.
|
|
|
67 |
'WHERE '.GEST_CHAMPS_ID_UTILISATEUR.' = '.$id;
|
|
|
68 |
$resultat = $GLOBALS['db']->query($requete);
|
|
|
69 |
return $GLOBALS['db']->affectedRows();
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
/**
|
5 |
jpm |
73 |
* Récupérer la liste de préférences d'un utilisateur.
|
|
|
74 |
*@param identifiant utilisateur.
|
|
|
75 |
*/
|
|
|
76 |
function recupererTableauPreferences()
|
|
|
77 |
{
|
|
|
78 |
$table = array();
|
7 |
jpm |
79 |
$requete = 'SELECT P.gp_id_projet, P.gp_nom_projet , C.gc_id_categorie, C.gc_libelle_categorie '.
|
|
|
80 |
'FROM gestion_preferences F, gestion_projet P, gestion_categorie C '.
|
8 |
jpm |
81 |
'WHERE gp_id_utilisateur = '.$this->id_utilisateur.' '.
|
7 |
jpm |
82 |
'AND F.gp_id_projet = P.gp_id_projet '.
|
|
|
83 |
'AND P.gc_id_categorie = C.gc_id_categorie '.
|
|
|
84 |
'ORDER BY gc_libelle_categorie ';
|
5 |
jpm |
85 |
$resultat = $GLOBALS['db']->query($requete);
|
|
|
86 |
|
|
|
87 |
(DB::isError($resultat)) ? die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;
|
|
|
88 |
|
8 |
jpm |
89 |
while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
|
5 |
jpm |
90 |
$case = array('id_proj' => $ligne[GEST_CHAMPS_ID_PROJET], 'nom_proj' => $ligne[GEST_CHAMPS_NOM_PROJET],'id_cat' => $ligne[GEST_CHAMPS_ID_CATEGORIE], 'libelle_cat' => $ligne[GEST_CHAMPS_LIBELLE_CATEGORIE]);
|
|
|
91 |
array_push($table, $case);
|
|
|
92 |
}
|
|
|
93 |
return $table;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
* Méthode renvoyant vrai si un projet est dans la liste de préférence d'un utilisateur.
|
|
|
98 |
*$id : identifiant du projet a chercher
|
|
|
99 |
*@return true : si existe
|
|
|
100 |
*@return false si n'existe pas
|
|
|
101 |
*/
|
|
|
102 |
function isInPreferences($id)
|
|
|
103 |
{
|
|
|
104 |
$tab = $this->recupererTableauPreferences();
|
8 |
jpm |
105 |
for ($i = 0; $i < count($tab); $i++) {
|
|
|
106 |
$t = $tab[$i];
|
5 |
jpm |
107 |
if ($t['id_proj'] == $id) {
|
8 |
jpm |
108 |
return true;
|
5 |
jpm |
109 |
}
|
|
|
110 |
}
|
8 |
jpm |
111 |
return false;
|
5 |
jpm |
112 |
}
|
|
|
113 |
|
|
|
114 |
/**
|
|
|
115 |
* Afficher préférences
|
|
|
116 |
*/
|
|
|
117 |
function afficherPreference()
|
|
|
118 |
{
|
8 |
jpm |
119 |
echo '<pre>'.print_r($this, true).'</pre>';
|
5 |
jpm |
120 |
}
|
2 |
jpm |
121 |
}
|
|
|
122 |
?>
|