Subversion Repositories Applications.gtt

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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();
69
		$requete =	"SELECT P.".GEST_CHAMPS_ID_PROJET.", P.".GEST_CHAMPS_NOM_PROJET." ,C.".GEST_CHAMPS_ID_CATEGORIE.",C.".GEST_CHAMPS_LIBELLE_CATEGORIE.
70
					" FROM ".GEST_PREFERENCES." F, ".GEST_PROJET." P,".GEST_CATEGORIE." C".
71
					" WHERE ".GEST_CHAMPS_ID_UTILISATEUR. " = $this->_utilisateur".
72
					" AND  F.".GEST_CHAMPS_ID_PROJET." = P.".GEST_CHAMPS_ID_PROJET.
73
					" AND P.".GEST_CHAMPS_ID_CATEGORIE." = C.".GEST_CHAMPS_ID_CATEGORIE.
74
					" ORDER BY ".GEST_CHAMPS_LIBELLE_CATEGORIE;
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
 
86
      /**
87
      *supprimer liste de preferences
88
      *pour un utilisateur donne
89
      *@param identifiant d'un utilisateur
90
      */
91
 
5 jpm 92
	function supprimerPreferences($id)
2 jpm 93
	{
5 jpm 94
		$requete =	'DELETE FROM '.GEST_PREFERENCES.' '.
95
					'WHERE '.GEST_CHAMPS_ID_UTILISATEUR.' = '.$id;
96
		$resultat = $GLOBALS['db']->query($requete);
97
		return $GLOBALS['db']->affectedRows();
98
	}
99
 
100
	/**
101
	* Méthode renvoyant vrai si un projet est dans la liste de préférence d'un utilisateur.
102
	*$id : identifiant du projet a chercher
103
	*@return true : si existe
104
	*@return false si n'existe pas
105
	*/
106
	function isInPreferences($id)
107
	{
108
		$tab = $this->recupererTableauPreferences();
109
		$res = false;
110
		for ($r = 0; $r < count($tab); $r++) {
111
			$t = $tab[$r];
112
			if ($t['id_proj'] == $id) {
113
				$res = true;
114
			}
115
		}
116
		return $res;
117
	}
118
 
119
	/**
120
	* Afficher préférences
121
	*/
122
	function afficherPreference()
123
	{
124
		echo "<br /> preferences <br />";
125
		$u= array($this->_utilisateur,$this->_projet);
126
 
127
		foreach ($u as $p) {
128
			echo "$p , ";
129
		}
130
		echo "<br /> ";
131
	}
2 jpm 132
}
133
?>