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 Prevision
  */

class Prevision
{
  /**Attributes: */
    var $_date_prevue;
    var $_duree_prevue;
    var $_utilisateur;
    var $_tache;

  /**
  *fonction creant une prevision
  *@param u : identifiant d'un utilisateur
  *@param t : identifiant de la tache
  */
  function Prevision($u,$t)
  {
      $this->_utilisateur=$u;
      $this->_tache=$t;
  }
  
  /**
  *fonction creant une nouvelle prevision
  */
  function construirePrevision($tableau)
  {
      $this->_utilisateur=$tableau[GEST_CHAMPS_ID_UTILISATEUR];
      $this->_tache=$tableau[GEST_CHAMPS_ID_TACHE];
      $this->_date_prevue=$tableau[GEST_CHAMPS_DATE_PREVISION];
      $this->_duree_prevue=$tableau[GEST_CHAMPS_DUREE_PREVISION];
  }
  /**
   *fonction enregistrant une nouvelle prevision 
    */
  function enregistrerNewPrevision()
  {
    $table=GEST_PREVISION;
    $champs=array(
        GEST_CHAMPS_ID_UTILISATEUR =>$this->_utilisateur,
        GEST_CHAMPS_ID_TACHE =>$this->_tache,
        GEST_CHAMPS_DATE_PREVISION =>$this->_date_prevue,
        GEST_CHAMPS_DUREE_PREVISION =>$this->_duree_prevue);
        
    $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;
    }
  }

  /**
  *fonction qui met a jour une prevision dans la base de donnees
  *renvoie 1 si mise a jour effectuee
  *renvoie -1 sinon
  */
  function mettreAJourPrevision()
  {
   $requete="UPDATE ".GEST_PREVISION.
            " SET ".GEST_CHAMPS_DUREE_PREVISION." = $this->_duree_prevue".
            " WHERE ".GEST_CHAMPS_ID_UTILISATEUR." = $this->_utilisateur".
            " AND ".GEST_CHAMPS_ID_TACHE." = $this->_tache".
            " AND ".GEST_CHAMPS_DATE_PREVISION." =\" $this->_date_prevue\"";

           
   $resultat =$GLOBALS['db']->query($requete) ;

   (DB::isError($resultat)) ?
        die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;

   $nb_ligne_modifie = $GLOBALS['db']->affectedRows();

   if ($nb_ligne_modifie==1)
      {
         return 1;
       }
       else return -1;


  }


  /**
  *fonction renvoyant la somme des previsions faites pour une journee
  *par un utilisateur
  *@param $id : identifiant de l'utilisateur
  *@param $date : date pour laquelle on veut la somme
  @return somme des heures prevues pour ce jour par cet utilisateur
    */
  function sommeHeurePrevision($id, $date)
  {
      $requete= "SELECT SUM(".GEST_CHAMPS_DUREE_PREVISION." ) ".
                " FROM ".GEST_PREVISION.
                " WHERE ".GEST_CHAMPS_ID_UTILISATEUR." = $id ".
                " AND ".GEST_CHAMPS_DATE_PREVISION." =\" $date\" ";
        $resultat = $GLOBALS['db']->query($requete);
        
        (DB::isError($resultat)) ? 
          die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;
        
        $ligne=$resultat->fetchRow(DB_FETCHMODE_ORDERED);
        return $ligne[0];
        
  }
  /**
  *fonction verifiant si une prevision a deja etet faite pour cette tache
  *si une duree a ete rentree pour une date, utilisateur et tache donnees
  *@return la duree prevue si elle xiste deja
  *@return 0 si aucune prevision 
  *@return -1 si erreur
  */
  function existePrevision()
  {
      $requete= "SELECT  * ".
                " FROM ".GEST_PREVISION.
                " WHERE ".GEST_CHAMPS_ID_TACHE." = $this->_tache ".
                " AND ".GEST_CHAMPS_ID_UTILISATEUR." =$this->_utilisateur  ".
                " AND ".GEST_CHAMPS_DATE_PREVISION."=  \"$this->_date_prevue \"";


      $resultat = $GLOBALS['db']->query($requete);

      $ligne=$resultat->fetchRow(DB_FETCHMODE_ASSOC);
     
     (DB::isError($resultat)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;
        
     $j=$resultat->numRows();
     if ($j==1)
    {
        return $ligne[GEST_CHAMPS_DUREE_PREVISION];

    }elseif($j==0){
        return 0;

    }else{
        return -1;
    }
        
  }

  /**
    * fonction renvoyant la duree d'une tache prevue
    */
  function getDureePrevision()
  {
    return $this->_duree_prevue;
  }
  /**
  *fonction renvoyant la det d'une prevision
  */
  function getDatePrevision()
  {
     return $this->_date_prevue;
  }
  /**
  *fonction renvoyant l'identifiant de l'utilisateur
  */
  function getIdUserPrevision()
  {
      return $this->_utilisateur;
  }

  /**
    *fonction creant la date de prevision
    * @param Date
    */
  function setDate( $date )
  {
    $this->_date_prevue=$date;
  }


  /**
   *fonction creant la duree
   *@param $Duree
    */
  function setDuree( $duree )
  {
    $this->_duree_prevue=$duree;
  }
}
?>