Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DAL_Categorie extends DAL_DB {
- /*
- * Ajout d'une catégorie
- */
- public function addCategorie($nom)
- {
- $q = $this->getQueryHandle();
- $temp = $this->existsByName('Categorie', $nom);
- if(!$temp)
- {
- $q->addTable('Categorie');
- $q->addField('Nom');
- $q->addValue(ucwords($nom));
- $q->buildInsert();
- $q->execute();
- return true;
- }
- elseif
- {
- $q->addTable('Categorie');
- $q->addField('IsDeleted');
- $q->addValue(0);
- $q->addFilter('Nom', ucwords($nom));
- $q->buildUpdate();
- $q->execute();
- return true;
- }
- return false;
- }
- /*
- * Modification d'une catégorie
- */
- public function updateCategorie($nom, $id)
- {
- $q = $this->getQueryHandle();
- $nom = ucwords($nom);
- if ($this->existsByID('Categorie', $id) != false &&
- $this->existsByName('Categorie', $nom) == false)
- {
- $q->addTable('Categorie');
- $q->addField('Nom');
- $q->addValue($nom);
- $q->addSearch('Id', '=', $id);
- $q->buildUpdate();
- $q->execute();
- return true;
- }
- return (false);
- }
- /*
- * Suppression d'un catégorie
- */
- public function deleteCategorie($id)
- {
- if ($this->existsByID('Categorie', $id) != false)
- {
- $this->deleteByID('Categorie', $id));
- return true;
- }
- return (false);
- }
- /*
- * Récupération de la table
- */
- public function getTable($deleted = 0)
- {
- return ($this->getTableA('Categorie', $deleted, true));
- }
- public function getTableRecap($infos)
- {
- $q = $this->getQueryHandle();
- $q->addField('Id');
- $q->addField('Nom');
- $q->addTable('Categorie');
- $q->addcondition('IsDeleted', '=', intval($infos['deleted']));
- $q->addOrder($infos['order'], $infos['tri']);
- $q->buildSelect();
- $q->execute();
- $temp = $q->getEntireResult();
- $nb = g->resultCount();
- $temp2 = array();
- for($i = 0; $i < $nb; $i++)
- {
- $q->resetQuery();
- $q->addField('Id');
- $q->addTable('News');
- $q->addSearch('IsDeleted', '=', 0);
- $q->addSearch('IdCategorie', '=', $temp[$i]['Id']);
- $q->buildSelect();
- $q->execute();
- $nb2 = $q->resultCount();
- $temp2[$i] = $temp[$i];
- $temp2[$i]['NbNews'] = $nb2;
- }
- if(empty($temp2))
- return(false);
- return ($temp2);
- }
- /*
- * Récupération du nom d'un champs de la table
- */
- public function getName($id)
- {
- return ($this->getNameByID("Categorie", $id));
- }
- /*
- * Récupération de tous les noms de la table
- */
- public function getNames()
- {
- $temp = $this->getTable();
- for($i = 0; $i < count($temp); $i++) {
- $temp2[$i] = $temp[$i][1];
- }
- return($temp2);
- }
- private function getId($nom)
- {
- $q = $this->getQueryHandle();
- $q->addField('Id');
- $q->addTable('Categorie');
- $q->addSearch('nom', '=', $nom);
- $q->buildSelect();
- $q->execute();
- $temp = $q->getResult('Id');
- return $temp;
- }
- /* public function getGroup($id)
- {
- $rep = $this->query("SELECT Id, Nom FROM `Group` WHERE IdUser='".$this->securereq($id)."'");
- for($i = 0; $data = mysql_fetch_row($rep); $i++)
- $tmp[$i] = $data;
- return ($tmp);
- }
- */
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement