Subversion Repositories Applications.gtt

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

<?php

// +------------------------------------------------------------------------------------------------------+
// | PHP version 4.1                                                                                      |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
// +------------------------------------------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or                                        |
// | modify it under the terms of the GNU Lesser General Public                                           |
// | License as published by the Free Software Foundation; either                                         |
// | version 2.1 of the License, or (at your option) any later version.                                   |
// |                                                                                                      |
// | This library is distributed in the hope that it will be useful,                                      |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
// | Lesser General Public License for more details.                                                      |
// |                                                                                                      |
// | You should have received a copy of the GNU Lesser General Public                                     |
// | License along with this library; if not, write to the Free Software                                  |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
// +------------------------------------------------------------------------------------------------------+

// |@author ABDOOL RAHEEM shaheen shaheenar50@hotmail.com                                                 |
// |@version 3                                                                                            |


class Preference
{
   var $_utilisateur=null;
   var $_projet =null;
   
   /**
   *constructeur
   */
   function Preference($u,$p)
   {
       $this->_utilisateur=$u;
       $this->_projet=$p;
   }
   
   
   /**
   *enregistrer une preference dans la base de donnees
   *@return 1 si ok
   *@return 0 si aucun enregistrement effectue
   *@return -1 si erreur
   */
   
   function enregistrerPreference()
   {
       $table=GEST_PREFERENCES;
       
       $champs =array(
                GEST_CHAMPS_ID_UTILISATEUR =>$this->_utilisateur,
                GEST_CHAMPS_ID_PROJET =>$this->_projet);
                
       $resultat = $GLOBALS['db']->autoExecute($table,$champs,DB_AUTOQUERY_INSERT);
    
       if (DB::isError($resultat)) {
           die($resultat->getMessage());
       }
       
        $j=$GLOBALS['db']->affectedRows();
   
    if ($j==1)
    {
        return 1;
    }elseif($j==0){
        return 0;
    }else{
        return -1;
    }
  }
   
   /**
   *recuperer la liste de preferences d'un utilisateur
   *@param identifiant utilisateur
   */
   function  recupererTableauPreferences()
  {
       $table=array();
       $requete="SELECT P.".GEST_CHAMPS_ID_PROJET.", P.".GEST_CHAMPS_NOM_PROJET." ,C.".GEST_CHAMPS_ID_CATEGORIE.",C.".GEST_CHAMPS_LIBELLE_CATEGORIE.
                " FROM ".GEST_PREFERENCES." F, ".GEST_PROJET." P,".GEST_CATEGORIE." C".
                " WHERE ".GEST_CHAMPS_ID_UTILISATEUR. " = $this->_utilisateur".
                " AND  F.".GEST_CHAMPS_ID_PROJET." = P.".GEST_CHAMPS_ID_PROJET.
                " AND P.".GEST_CHAMPS_ID_CATEGORIE." = C.".GEST_CHAMPS_ID_CATEGORIE.
                " ORDER BY ".GEST_CHAMPS_LIBELLE_CATEGORIE;
        $resultat = $GLOBALS['db']->query($requete);
     
      (DB::isError($resultat)) ? die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;
      
      while($ligne=$resultat->fetchRow(DB_FETCHMODE_ASSOC))
      {
          $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]);
          array_push($table,$case);
      }
        return $table;
  }
      
      /**
      *supprimer liste de preferences
      *pour un utilisateur donne
      *@param identifiant d'un utilisateur
      */
      
      function supprimerPreferences($id)
      {
          $requete="DELETE FROM ".GEST_PREFERENCES.
                   " WHERE ".GEST_CHAMPS_ID_UTILISATEUR. " =$id ";
                   
          $resultat = $GLOBALS['db']->query($requete);
          
         $j=$GLOBALS['db']->affectedRows();
          return $j;
      }
     
     /**
     *fonction renvoyant vrai si un projet est dans la liste de preference d'un utilisateur
     *$id : identifiant du projet a chercher
     @return true : si existe
     @return false si n'existe pas
     */
     
     function isInPreferences($id)
     {
        $tab=$this->recupererTableauPreferences(); 
        $res=false;
        for ($r=0; $r<count($tab);$r++)
        {
            $t=$tab[$r];
            if ($t['id_proj']==$id)
            {
                $res=true;
            }
        }  
        return $res;        
     }
     
     /**
      *afficher preferences
      */
      
      function afficherPreference()
      {
          echo "<br /> preferences <br />";
          $u= array($this->_utilisateur,$this->_projet);
          
          foreach ($u as $p)
          {
              echo "$p , ";
          }
          
          echo "<br /> ";
      }
}
?>