protected function modify(Category $category)
 {
     $q = $this->dao->prepare('UPDATE ' . $this->table() . ' SET NAME = :name, DESCRIPTION = :description, PARENT_CATEGORY_ID = :parentCategoryId, IS_ROOT = :isRoot WHERE ID = :id');
     $q->bindValue(':name', $category->getName());
     $q->bindValue(':description', $category->getDescription());
     $q->bindValue(':parentCategoryId', $category->getParentCategoryId());
     $q->bindValue(':isRoot', $category->getIsRoot());
     $q->bindValue(':id', $category->id(), PDO::PARAM_INT);
     $q->execute();
 }
 public function edit(User $currentUser, Category $category)
 {
     $id = intval($category->getId());
     $name = $this->database->quote($category->getName());
     $description = $this->database->quote($category->getDescription());
     $query = "UPDATE category SET name = '" . $name . "', description = '" . $description . "' WHERE id = " . $id;
     $result = $this->database->exec($query);
     if ($result) {
         return true;
     } else {
         throw new Exception("Catastrophe base de données.");
     }
 }
 public function create($name, $description, $img)
 {
     $category = new Category($this->db);
     $errors = array();
     try {
         $category->setName($name);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     try {
         $category->setDescription($description);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     try {
         $category->setImg($img);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     if (count($errors) == 0) {
         $name = $this->db->quote($category->getName());
         $description = $this->db->quote($category->getDescription());
         $img = $this->db->quote($category->getImg());
         $query = "INSERT INTO category (name, description, img) VALUES(" . $name . "," . $description . "," . $img . ")";
         $res = $this->db->exec($query);
         if ($res) {
             $id = $this->db->lastInsertId();
             if ($id) {
                 return $this->findById($id);
             } else {
                 $errors[] = "Category not found";
                 return $errors;
             }
         } else {
             $errors[] = "Internal server error";
             return $errors;
         }
     } else {
         return $errors;
     }
 }
Example #4
0
 public function update(Category $category)
 {
     $id = intval($category->getId());
     $name = $this->db->quote($category->getName());
     $description = $this->db->quote($category->getDescription());
     $query = "UPDATE category SET name='" . $name . "', description='" . $description . "', WHERE id='" . $id . "'";
     $res = $this->db->exec($query);
     if ($result) {
         return $this->readById($id);
     } else {
         return "Error";
     }
 }
 public function update(Category $category, $errors = array())
 {
     $id = $category->getId();
     $name = $this->db->quote($category->getName());
     $description = $this->db->quote($category->getDescription());
     $query = "UPDATE category SET name = " . $name . ", description = " . $description . "WHERE id = " . $id;
     $data = $this->db->exec($query);
     if ($data) {
         $id = $this->db->lastInsertId();
         if ($id) {
             try {
                 $category = $this->findByid($id);
                 return $category;
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
                 return $errors;
             }
         } else {
             throw new Exception('Last insert error');
         }
     } else {
         throw new Exception('Update error');
     }
 }