Subversion Repositories Applications.gtt

Rev

Go to most recent revision | Details | 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
{
29
   var $_utilisateur=null;
30
   var $_projet =null;
31
 
32
   /**
33
   *constructeur
34
   */
35
   function Preference($u,$p)
36
   {
37
       $this->_utilisateur=$u;
38
       $this->_projet=$p;
39
   }
40
 
41
 
42
   /**
43
   *enregistrer une preference dans la base de donnees
44
   *@return 1 si ok
45
   *@return 0 si aucun enregistrement effectue
46
   *@return -1 si erreur
47
   */
48
 
49
   function enregistrerPreference()
50
   {
51
       $table=GEST_PREFERENCES;
52
 
53
       $champs =array(
54
                GEST_CHAMPS_ID_UTILISATEUR =>$this->_utilisateur,
55
		GEST_CHAMPS_ID_PROJET =>$this->_projet);
56
 
57
       $resultat = $GLOBALS['db']->autoExecute($table,$champs,DB_AUTOQUERY_INSERT);
58
 
59
       if (DB::isError($resultat)) {
60
           die($resultat->getMessage());
61
       }
62
 
63
        $j=$GLOBALS['db']->affectedRows();
64
 
65
    if ($j==1)
66
    {
67
	return 1;
68
    }elseif($j==0){
69
	return 0;
70
    }else{
71
	return -1;
72
    }
73
  }
74
 
75
   /**
76
   *recuperer la liste de preferences d'un utilisateur
77
   *@param identifiant utilisateur
78
   */
79
   function  recupererTableauPreferences()
80
  {
81
       $table=array();
82
       $requete="SELECT P.".GEST_CHAMPS_ID_PROJET.", P.".GEST_CHAMPS_NOM_PROJET." ,C.".GEST_CHAMPS_ID_CATEGORIE.",C.".GEST_CHAMPS_LIBELLE_CATEGORIE.
83
                " FROM ".GEST_PREFERENCES." F, ".GEST_PROJET." P,".GEST_CATEGORIE." C".
84
		" WHERE ".GEST_CHAMPS_ID_UTILISATEUR. " = $this->_utilisateur".
85
		" AND  F.".GEST_CHAMPS_ID_PROJET." = P.".GEST_CHAMPS_ID_PROJET.
86
		" AND P.".GEST_CHAMPS_ID_CATEGORIE." = C.".GEST_CHAMPS_ID_CATEGORIE.
87
		" ORDER BY ".GEST_CHAMPS_LIBELLE_CATEGORIE;
88
	$resultat = $GLOBALS['db']->query($requete);
89
 
90
      (DB::isError($resultat)) ? die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;
91
 
92
      while($ligne=$resultat->fetchRow(DB_FETCHMODE_ASSOC))
93
      {
94
	  $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]);
95
	  array_push($table,$case);
96
      }
97
	return $table;
98
  }
99
 
100
      /**
101
      *supprimer liste de preferences
102
      *pour un utilisateur donne
103
      *@param identifiant d'un utilisateur
104
      */
105
 
106
      function supprimerPreferences($id)
107
      {
108
	  $requete="DELETE FROM ".GEST_PREFERENCES.
109
	           " WHERE ".GEST_CHAMPS_ID_UTILISATEUR. " =$id ";
110
 
111
          $resultat = $GLOBALS['db']->query($requete);
112
 
113
	 $j=$GLOBALS['db']->affectedRows();
114
          return $j;
115
      }
116
 
117
     /**
118
     *fonction renvoyant vrai si un projet est dans la liste de preference d'un utilisateur
119
     *$id : identifiant du projet a chercher
120
     @return true : si existe
121
     @return false si n'existe pas
122
     */
123
 
124
     function isInPreferences($id)
125
     {
126
	$tab=$this->recupererTableauPreferences();
127
	$res=false;
128
	for ($r=0; $r<count($tab);$r++)
129
	{
130
	    $t=$tab[$r];
131
	    if ($t['id_proj']==$id)
132
	    {
133
		$res=true;
134
	    }
135
	}
136
	return $res;
137
     }
138
 
139
     /**
140
      *afficher preferences
141
      */
142
 
143
      function afficherPreference()
144
      {
145
	  echo "<br /> preferences <br />";
146
	  $u= array($this->_utilisateur,$this->_projet);
147
 
148
	  foreach ($u as $p)
149
	  {
150
	      echo "$p , ";
151
	  }
152
 
153
	  echo "<br /> ";
154
      }
155
}
156
?>