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