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                                                                                            |


include_once 'gtt_projet.class.php';

/**
  * class Categorie
  *une categorie regroupe une liste de projets
  */

class Categorie
{

  /**Aggregations: */

    var $_liste_projets = array();//liste de projets de la categorie

  /**Attributes: */
  
    var $_id_categorie=null;
   
    var $_libelle_categorie=null;
    
    /*
    *construit une categorie a partir d'un identifiant
    */
   function Categorie($id)
   {
       $this->_id_categorie=$id;
   }
   
  /**
    *ajouter le libelle
    */
   function setLibelleCategorie($l)
   {
       $this->_libelle_categorie= $l;
   }
   
   /*
   *construit une categorie a partir d'un tableau 
   */
   function construireCategorie($tableau)
   {
       $this->_id_categorie=$tableau[GEST_CHAMPS_ID_CATEGORIE];
       $this->_libelle_categorie=$tableau[GEST_CHAMPS_LIBELLE_CATEGORIE];
   }
   
   /*
   *verifie si la categorie contient des projets ou non
   *renvoie 1 si contient des projets
   *-1 sinon
   */
   function contientProjet($id)
   {
    $requete="SELECT ".GEST_CHAMPS_ID_PROJET.
             " FROM ".GEST_PROJET.
             " WHERE ".GEST_CHAMPS_ID_CATEGORIE." = $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;
    }
   }
   
   /*recuperer un tableau contenant la liste des categories*/
   function recupererTableauCategorie()
   {
       $tableau = array();
       $i=0;
       $requete ="SELECT * FROM ".GEST_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(GEST_CHAMPS_ID_CATEGORIE => $ligne[GEST_CHAMPS_ID_CATEGORIE],
                GEST_CHAMPS_LIBELLE_CATEGORIE =>$ligne[GEST_CHAMPS_LIBELLE_CATEGORIE]);
       
        $tableau[$i]=$case;
        $i=$i+1;
     }
     
     return $tableau;
   }
   
   /**
   *recupere l'identifiant de la prochaine categorie 
   *de la base de donnees
   */
  
   function nextId()
   {
    $requete = 'SELECT MAX('.GEST_CHAMPS_ID_CATEGORIE.') AS maxi FROM '.GEST_CATEGORIE;
    $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 une nouvelle categorie dans la base de donnees
  *ne fait qu'inserer une nouvelle identifiant
  *et libelle de categorie
  *ne traite pas les projets inclus dans une categorie
  *renvoie 1 si enregistrement effectue
  *0 si aucun enregistrement
  *-1 si erreur
  */
  
  
  function enregistrerNewCategorie()
  {
     
    $table =GEST_CATEGORIE;
    //Verification si identifiant deja attribue
   
    $b=&Categorie::nextId();
    $this->_id_categorie=$b;
    
    $champs = array(
              GEST_CHAMPS_ID_CATEGORIE => $this->_id_categorie,
              GEST_CHAMPS_LIBELLE_CATEGORIE => "$this->_libelle_categorie");
              
    $resultat = $GLOBALS['db']->autoExecute($table, $champs, DB_AUTOQUERY_INSERT);      
    if (DB::isError($resultat)) {
    die($resultat->getMessage());
    }
          
   $j=$GLOBALS['db']->affectedRows();
   switch ($j)
   {
       case 1 : return 1;
       case 0 :return 0;
       default :return -1;
   }
  
  }
  


  /**
    *  construit une instance de categorie en recuperant les donnees
    *stockees dans la base de donnees    
    */
  function recupererCategorie($id)
  {
   $requete="SELECT * FROM ".GEST_CATEGORIE.
            " WHERE ".GEST_CHAMPS_ID_CATEGORIE." =$id ";
   
   $ligne =$GLOBALS['db']->query($requete) ;
   $resultat = $ligne->fetchRow(DB_FETCHMODE_ASSOC);

   (DB::isError($resultat)) ?
        die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;
    
    $nb_ligne_selectionne = $ligne->numRows();
      
    if($nb_ligne_selectionne==1) 
    {
    //construction d'une nouvelle categorie
   
     $cat = new Categorie($resultat[GEST_CHAMPS_ID_CATEGORIE]) ;  
     $cat->setLibelleCategorie($resultat[GEST_CHAMPS_LIBELLE_CATEGORIE]);
     
     $cat->_liste_projets=$this->recupererListeProjets($id);
     return $cat;
    }elseif($nb_ligne_selectionne==0){
        return 0;
    }else {
  return -1;
    }
  
  }
    
    
    /*
    *fonction recuperant la liste de projets
    *d'une categorie de la base de donnes
    */
    function recupererListeProjets($id)
    
    {    
 
    $tableau=array();
    $requete="SELECT ".GEST_CHAMPS_ID_PROJET.
             " FROM ".GEST_PROJET.
             " WHERE ".GEST_CHAMPS_ID_CATEGORIE." = $id";
             
    $ligne= $GLOBALS['db']->query($requete);
   
   (DB::isError($resultat)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;
   
   $j = $ligne->numRows();
   if($j!=0){
   //remplit le tableau avec la liste de projets
   while($resultat=$ligne->fetchRow(DB_FETCHMODE_ORDERED))
   {
       array_push($tableau,$resultat[0]);
   }
   }
   return $tableau;
  }


  /**
    * supprime une categorie de la base de donnees   
    *cette methode n'est appelé que quand on est sure qu'il n'y a 
    *aucun projet dans la categorie
    */
  function supprimerCategorie($id)
  {
    $requete="DELETE FROM ".GEST_CATEGORIE.
             " WHERE ".GEST_CHAMPS_ID_CATEGORIE. " = $id";
             
    $resultat = $GLOBALS['db']->query($requete);

    $j= $GLOBALS['db']->affectedRows();
    return $j;
  }

  
 function afficherCategorie()
 {
     echo "<BR> Categorie : ";
     echo "id categorie : \n";
     echo "$this->_id_categorie  <BR>";
     echo "libelle : \n  $this->_libelle_categorie <BR>";
     echo "liste de projets :  ";
     foreach($this->_liste_projets as $h)
     {
         echo "$h \t";
     }
 
 }
}
?>