Exemplo n.º 1
0
 public function update(Brand $brand, $errors = array())
 {
     $id = $brand->getId();
     $name = $this->db->quote($brand->getName());
     $description = $this->db->quote($brand->getDescription());
     $query = "UPDATE brand SET name = " . $name . ", description = " . $description . "WHERE id = " . $id;
     $data = $this->db->exec($query);
     if ($data) {
         $id = $this->db->lastInsertId();
         if ($id) {
             try {
                 $brand = $this->findByid($id);
                 return $brand;
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
                 return $errors;
             }
         } else {
             throw new Exception('Last insert error');
         }
     } else {
         throw new Exception('Update error');
     }
 }
Exemplo n.º 2
0
 /**
  * @param $name
  * @param $description
  * @param array $errors
  * @return object
  * @throws Exception
  */
 public function create($name, $description, $errors = array())
 {
     $category = new Brand($this->db);
     try {
         $category->setName($name);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     try {
         $category->setDescription($description);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     if (count($errors) == 0) {
         $name = $this->db->quote($category->getName());
         $description = $this->db->quote($category->getDescription());
         $query = "INSERT INTO category (name, description) VALUES(" . $name . ", " . $description . ")";
         $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('Insert error');
         }
     } else {
         return $errors;
     }
 }