Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.08 KB | None | 0 0
  1. <?php
  2. class DAL_Categorie extends DAL_DB {
  3.    
  4.     /*
  5.      *  Ajout d'une catégorie
  6.      */    
  7.     public function addCategorie($nom)
  8.     {
  9.         $q = $this->getQueryHandle();
  10.         $temp = $this->existsByName('Categorie', $nom);
  11.         if(!$temp)
  12.         {
  13.             $q->addTable('Categorie');
  14.             $q->addField('Nom');
  15.             $q->addValue(ucwords($nom));
  16.             $q->buildInsert();
  17.             $q->execute();
  18.             return true;
  19.         }
  20.         elseif
  21.         {
  22.             $q->addTable('Categorie');
  23.             $q->addField('IsDeleted');
  24.             $q->addValue(0);
  25.             $q->addFilter('Nom', ucwords($nom));
  26.             $q->buildUpdate();
  27.             $q->execute();
  28.             return true;
  29.         }
  30.         return false;
  31.     }
  32.    
  33.     /*
  34.      *  Modification d'une catégorie
  35.      */
  36.     public function updateCategorie($nom, $id)
  37.     {
  38.         $q = $this->getQueryHandle();
  39.         $nom = ucwords($nom);
  40.         if ($this->existsByID('Categorie', $id) != false &&
  41.             $this->existsByName('Categorie', $nom) == false)
  42.         {
  43.             $q->addTable('Categorie');
  44.             $q->addField('Nom');
  45.             $q->addValue($nom);
  46.             $q->addSearch('Id', '=', $id);
  47.             $q->buildUpdate();
  48.             $q->execute();
  49.             return true;
  50.         }
  51.         return (false);
  52.     }
  53.  
  54.     /*
  55.      *  Suppression d'un catégorie
  56.      */
  57.     public function deleteCategorie($id)
  58.     {
  59.         if ($this->existsByID('Categorie', $id) != false)
  60.         {
  61.             $this->deleteByID('Categorie', $id));
  62.             return true;
  63.         }
  64.         return (false);
  65.     }
  66.  
  67.     /*
  68.      *  Récupération de la table
  69.      */
  70.     public function getTable($deleted = 0)
  71.     {
  72.         return ($this->getTableA('Categorie', $deleted, true));
  73.     }
  74.  
  75.     public function getTableRecap($infos)
  76.     {
  77.         $q = $this->getQueryHandle();
  78.         $q->addField('Id');
  79.         $q->addField('Nom');
  80.         $q->addTable('Categorie');
  81.         $q->addcondition('IsDeleted', '=', intval($infos['deleted']));
  82.         $q->addOrder($infos['order'], $infos['tri']);
  83.         $q->buildSelect();
  84.         $q->execute();
  85.         $temp = $q->getEntireResult();
  86.         $nb = g->resultCount();
  87.         $temp2 = array();
  88.         for($i = 0; $i < $nb; $i++)
  89.         {
  90.             $q->resetQuery();
  91.             $q->addField('Id');
  92.             $q->addTable('News');
  93.             $q->addSearch('IsDeleted', '=', 0);
  94.             $q->addSearch('IdCategorie', '=', $temp[$i]['Id']);
  95.             $q->buildSelect();
  96.             $q->execute();
  97.             $nb2 = $q->resultCount();
  98.             $temp2[$i] = $temp[$i];
  99.             $temp2[$i]['NbNews'] = $nb2;
  100.         }
  101.         if(empty($temp2))
  102.             return(false);
  103.         return ($temp2);
  104.     }
  105.     /*
  106.      *  Récupération du nom d'un champs de la table
  107.      */
  108.     public function getName($id)
  109.     {
  110.         return ($this->getNameByID("Categorie", $id));
  111.     }
  112.  
  113.     /*
  114.      *  Récupération de tous les noms de la table
  115.      */
  116.     public function getNames()
  117.     {
  118.         $temp = $this->getTable();
  119.         for($i = 0; $i < count($temp); $i++) {
  120.             $temp2[$i] = $temp[$i][1];
  121.         }
  122.         return($temp2);
  123.     }
  124.    
  125.     private function getId($nom)
  126.     {
  127.         $q = $this->getQueryHandle();
  128.         $q->addField('Id');
  129.         $q->addTable('Categorie');
  130.         $q->addSearch('nom', '=', $nom);
  131.         $q->buildSelect();
  132.         $q->execute();
  133.         $temp = $q->getResult('Id');
  134.         return $temp;  
  135.     }
  136.    
  137. /*  public function getGroup($id)
  138.     {
  139.         $rep = $this->query("SELECT Id, Nom FROM `Group` WHERE IdUser='".$this->securereq($id)."'");
  140.         for($i = 0; $data = mysql_fetch_row($rep); $i++)
  141.             $tmp[$i] = $data;
  142.         return ($tmp);
  143.    
  144.     }
  145. */
  146. }  
  147. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement