public function create($name, $description, $image, Category $category) { $errors = array(); $subCategory = new SubCategory($this->db); $valide = $subCategory->setDescription($description); if ($valide === true) { $valide = $subCategory->setName($name); if ($valide === true) { $valide = $subCategory->setImage($image); if ($valide === true) { $valide = $subCategory->setCategory($category); if ($valide === true) { $description = $this->db->quote($subCategory->getDescription()); $name = $this->db->quote($subCategory->getName()); $image = $this->db->quote($subCategory->getImage()); $id_category = $subCategory->getCategory()->getId(); $query = "INSERT INTO subcategory (description, name, image, id_category) VALUES (" . $description . ", " . $name . ", " . $image . ", " . $id_category . ")"; $res = $this->db->query($query); if ($res) { $id = $this->db->lastInsertId(); if ($id) { try { return $this->findById($id); } catch (Exception $e) { $errors[] = $e->getMessage(); } } else { throw new Exception("internal server error"); } } } else { return $valide; } } else { return $valide; } } else { return $valide; } } else { return $valide; } }