Subversion Repositories Applications.gtt

Rev

Rev 2 | 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                                                                                            |

include_once 'gtt_taches.class.php';
/**
  * class Projet
  * 
  */

class Projet
{

  /**Aggregations: */

  var $liste_taches = array();
  /**Attributes: */
    var $_id_projet=null;
   
    var $_nom_projet=null;
   
    var $_description_projet=null;
    
    var $_date_debut_projet = null;
    
    var $_duree_prevue_projet=null;
    
    var $_avancement_projet=null;
    
    var $_categorie=null;
      
    
  /**
  *constructeur 
  */
  function Projet($id)
  {
    $this->_id_projet= $id;
  }
  
   /**
  *construit un projet a partir d'un tableau associatif
  *le tableau ne contient toutefois pas la liste de taches
  */
  function construireProjet($tableau)
  {
      
      $this->_nom_projet=$tableau[GEST_CHAMPS_NOM_PROJET];
      $this->_description_projet=$tableau[GEST_CHAMPS_DESCRIPTION_PROJET];
      $this->_date_debut_projet=$tableau[GEST_CHAMPS_DATE_DEBUT_PROJET];
      $this->_duree_prevue_projet= $tableau[GEST_CHAMPS_DUREE_PREVUE_PROJET];
      $this->_avancement_projet=$tableau[GEST_CHAMPS_AVANCEMENT_PROJET];
      $this->_categorie=$tableau[GEST_CHAMPS_ID_CATEGORIE];
  }
 
 /**
   *recupere l'identifiant de la base de donnees
   */
   
   function nextId()
   {
    $requete = 'SELECT MAX('.GEST_CHAMPS_ID_PROJET.') AS maxi FROM '.GEST_PROJET;
    $resultat = $GLOBALS['db']->query($requete);
    if (DB::isError($resultat) || $resultat->numRows() > 1) {
        return false;
    }
    
    $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT);
    return $ligne->maxi + 1;  
   }
   
 
  /**
    * enregistre un nouveau projet
    *renvoie 0 si aucun enregistrement effectue,
    *1 si enregistrement ok
    *-1 si erreur
    *on suppose qu'on aura pas d'erreur car
    *on controle les projets a enregistrer : pas de duplicata
    */
  function enregistrerNewProjet()
  {
    $table=GEST_PROJET;
    $p=&Projet::nextId();
    $this->_id_projet=$p;
    
    $champs=array(
        GEST_CHAMPS_ID_PROJET =>$this->_id_projet,
            GEST_CHAMPS_NOM_PROJET => "$this->_nom_projet",
            GEST_CHAMPS_DESCRIPTION_PROJET =>"$this->_description_projet",
            GEST_CHAMPS_DATE_DEBUT_PROJET =>$this->_date_debut_projet,
            GEST_CHAMPS_DUREE_PREVUE_PROJET =>$this->_duree_prevue_projet,
            GEST_CHAMPS_AVANCEMENT_PROJET =>$this->_avancement_projet,
            GEST_CHAMPS_ID_CATEGORIE => $this->_categorie);
            
    $resultat = $GLOBALS['db']->autoExecute($table, $champs,DB_AUTOQUERY_INSERT);           
  
    if (DB::isError($resultat)) {
    die($resultat->getMessage());
    }
        
    $j =$GLOBALS['db']->affectedRows($resultat);
    return $j;    
  }
  /*
  *recupere une liste de taches
  */
  function recupererListeTaches()
  {
          
  }
  
  /*
  * modifie la liste de taches
  *@param $t : tableau de taches
  */
  function setListeTaches($t)
  {
    $this->_liste_taches= $t;
  }
  
  /**
    *recupere un projet pour instancier l'objet
    *renvoie -1 si erreur
    *renvoie utilisateur sinon
    */
  function recupererProjet($id)
  {
    $requete="SELECT ".GEST_CHAMPS_NOM_PROJET.", ".GEST_CHAMPS_DESCRIPTION_PROJET.", ".GEST_CHAMPS_DATE_DEBUT_PROJET.", "
             .GEST_CHAMPS_DUREE_PREVUE_PROJET.", ".GEST_CHAMPS_AVANCEMENT_PROJET." , ".GEST_CHAMPS_ID_CATEGORIE.
             " FROM ".GEST_PROJET.
             " WHERE ".GEST_CHAMPS_ID_PROJET." = $id";
  
    $resultat = $GLOBALS['db']->query($requete);
    
    (DB::isError($resultat)) ?
               die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;
        
    $tab = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
    $j=$resultat->numRows();
    if ($j==1)
   { 
     $project = new Projet($id);
     $project->construireProjet($tab);
     return $project;
    //recuperation de la liste de taches
    
    
   }else {
           return -1;
   }
        
  }
  /**
  *fonction verifiant si le projet contient des taches
  *renvoie 1 si le projet contient des taches
  *et 0 sinon
  */
  
  function contientTache($id)
  {
    $requete="SELECT ".GEST_CHAMPS_ID_TACHE.
             " FROM ".GEST_TACHES.
             " WHERE ".GEST_CHAMPS_ID_PROJET." = $id ";
             
     $ligne= $GLOBALS['db']->query($requete);
   
   (DB::isError($ligne)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, $ligne->getMessage(), $requete)) : '' ;
 
   $j= $ligne->numRows();
    if ($j==0){
        return -1;
    }else {
        return 1;
    }
  }

  /**
   *supprime un projet de la base de donnees
   *ne prend pas en compte les taches
    */
  function supprimerProjet($id)
  {
    $requete="DELETE FROM ".GEST_PROJET.
             " WHERE ".GEST_CHAMPS_ID_PROJET." =$id";
             
    $ligne=$GLOBALS['db']->query($requete);
    (DB::isError($ligne)) ?
               die (BOG_afficherErreurSql(__FILE__, __LINE__, $ligne->getMessage(), $requete)) : '' ;
    
    $j=$GLOBALS['db']->affectedRows();
    return $j;
  }

  /**
  *fonction recuperant la date de debut d'un projet
  */
  function getDateDeb()
  {
      return $this->_date_debut_projet;
  }
  /**
  *fonction recuperant la duree prevue
  */
  function getDureePrevue()
  {
      return $this->_duree_prevue_projet;
  }
  /**
   *etablit le pourcentage d'avancement du projet
    */
  function setAvancement($pourcentage)
  {
    $this->_avancement_projet=$pourcentage;
  }
  
  /*
  *modofie la duree prevue
  */
  
  function setDureePrevue($d)
  {
          $this->_duree_prevue_projet = $d;
  }
  /*
  *modifie la description
  */
  
  function setDescription($desc)
  {
          $this->_description_projet = $desc;
  }
  
  function mettreAJourProjet()
  {
         $table=GEST_PROJET;
         
        $requete="UPDATE $table SET "
                     .GEST_CHAMPS_NOM_PROJET." = \"$this->_nom_projet\","
                     .GEST_CHAMPS_DESCRIPTION_PROJET." =\"$this->_description_projet\","
                     .GEST_CHAMPS_DATE_DEBUT_PROJET." =\"$this->_date_debut_projet\","
                     .GEST_CHAMPS_DUREE_PREVUE_PROJET." =$this->_duree_prevue_projet,"
                     .GEST_CHAMPS_AVANCEMENT_PROJET." =$this->_avancement_projet,"
                     .GEST_CHAMPS_ID_CATEGORIE." = $this->_categorie"
                                 ." WHERE ".GEST_CHAMPS_ID_PROJET." =$this->_id_projet";
                
                $resultat= $GLOBALS['db']->query($requete);
                (DB::isError($resultat)) ?
                           die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;
                    
                
                $j= $GLOBALS['db']->affectedRows();
                echo "$j";
                
                switch ($j)
                {
                        case 0: return 0;
                        case 1: return 1;
                        default: return -1;
                }
                
  }
        /** Méthode recuperant la liste de projets */
        function recupererTableauProjet()
        {
                $requete = 'SELECT '.GEST_CHAMPS_ID_PROJET." , ".GEST_CHAMPS_NOM_PROJET.",C.".GEST_CHAMPS_ID_CATEGORIE.",C.".GEST_CHAMPS_LIBELLE_CATEGORIE.
                                        " FROM ".GEST_PROJET." P  ,".GEST_CATEGORIE." C ".
                                        " WHERE P.".GEST_CHAMPS_ID_CATEGORIE." = C.".GEST_CHAMPS_ID_CATEGORIE.
                                        " ORDER BY C.".GEST_CHAMPS_ID_CATEGORIE;
                $tab = array();
                $resultat = $GLOBALS['db']->query($requete);
                (DB::isError($resultat)) ? die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;

                $j = $resultat->numRows();
                if ($j != 0) {
                        while($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
                                $case = array(  GEST_CHAMPS_ID_PROJET => $ligne[GEST_CHAMPS_ID_PROJET],
                                                                GEST_CHAMPS_NOM_PROJET => $ligne[GEST_CHAMPS_NOM_PROJET],
                                                                GEST_CHAMPS_LIBELLE_CATEGORIE => $ligne[GEST_CHAMPS_LIBELLE_CATEGORIE]);
                                array_push($tab, $case);
                        }
                }
                return $tab;
        }

 /**
*fonction recuperant la tache par defaut d'un projet
*tache par defaut : tache s'appelant general
*@id : identifiant du projet
*@param : $nom : nom de la atche par default
*@return identifiant de la tache
*/

function getDefaultTache($id, $nom)
{
    $requete="SELECT ".GEST_CHAMPS_ID_TACHE.
             " FROM ".GEST_TACHES.
             " WHERE ".GEST_CHAMPS_ID_PROJET." = $id ".
             " AND ".GEST_CHAMPS_NOM_TACHE."=\" $nom\"";
     $ligne= $GLOBALS['db']->query($requete);
   
   (DB::isError($ligne)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, $ligne->getMessage(), $requete)) : '' ;
 
   $j= $ligne->numRows();
   if ($j==1)
   {
       $resultat=$ligne->fetchRow(DB_FETCHMODE_ORDERED);
       return $resultat[0];
   }else return -1;
             
}     
  
  function afficherProjet()
  {
          echo "<br /> projet: ";
          echo "id projet: \n";
          echo"$this->_id_projet  <br /> ";
          echo "nom projet: \n";
          echo"$this->_nom_projet  <br /> ";
          echo "description projet: \n";
          echo"$this->_description_projet  <br /> ";
          echo "avancement : \n";
          echo"$this->_avancement_projet  <br /> ";
          echo "date debut projet: \n";
          echo"$this->_date_debut_projet  <br /> ";
          echo "duree prevue du projet: \n";
          echo"$this->_duree_prevue_projet  <br /> ";
          echo "categorie : ";
          echo "$this->_categorie <br />";
          echo "liste de taches : ";
          $liste=$this->_liste_taches;
          if (isset($liste))
          {
          foreach ($liste as $t)
          {
                  echo "$t \t , ";
          }
          }
          echo "<br />";
  }

}
?>