/** * @Role("Editor") * @Delete * @param NameBindingModel $model * @throws \Exception */ public function remove(NameBindingModel $model) { $response = $this->db->prepare("SELECT id\n FROM categories\n WHERE name LIKE ?", array($model->getName()))->execute()->fetchRowAssoc(); if (!$response) { throw new \Exception("No category '" . $model->getName() . " ' found!", 400); } $id = $response['id']; $response = $this->db->prepare("SELECT p.id\n FROM categories c\n JOIN products_categories pc\n ON c.id = pc.categoryId\n JOIN products p\n ON p.id = pc.productId\n WHERE categoryId = ?", array($id))->execute()->fetchRowAssoc(); if ($response) { throw new \Exception("Category is not empty! Move all products first!", 400); } $this->db->prepare("DELETE FROM\n categories\n WHERE name LIKE ?", array($model->getName()))->execute(); $this->redirect('/categories'); }
/** * @Role("Editor") * @Delete * @param NameBindingModel $model * @throws \Exception */ public function remove(NameBindingModel $model) { $response = $this->db->prepare("\n SELECT id\n FROM categories\n WHERE name LIKE ?", [$model->getName()])->execute()->fetchRowAssoc(); if (!$response) { throw new \Exception("No category '" . $model->getName() . " ' found!", 400); } $id = $response['id']; $response = $this->db->prepare("\n SELECT p.id\n FROM categories c\n JOIN products_categories pc\n ON c.id = pc.categoryId\n JOIN products p\n ON p.id = pc.productId\n WHERE categoryId = ?", [$id])->execute()->fetchRowAssoc(); if ($response) { throw new \Exception("Category isn't empty! First, move all products!", 400); } $this->db->prepare("\n DELETE FROM categories\n WHERE name LIKE ?", [$model->getName()])->execute(); $this->redirect("{$this->path}categories"); }
/** * @Delete * @Route("editor/promotion/remove") * @Role("Editor") * @param NameBindingModel $model */ public function remove(NameBindingModel $model) { $this->db->prepare("\n DELETE FROM promotions\n WHERE name LIKE ?", [$model->getName()])->execute(); $this->redirect("{$this->path}editor"); }
/** * @Delete * @Route("editor/promotion/remove") * @Role("Editor") * @param NameBindingModel $model */ public function remove(NameBindingModel $model) { $this->db->prepare("DELETE\n FROM promotions\n WHERE name LIKE ?", array($model->getName()))->execute(); $this->redirect('/editor'); }
/** * @Post * @Route("products/find") * @param NameBindingModel $model */ public function find(NameBindingModel $model) { $this->db->prepare("\n SELECT id\n FROM products\n WHERE name LIKE ?", [$model->getName()]); $response = $this->db->execute()->fetchRowAssoc(); if ($response) { $productId = Common::normalize($response['id'], 'noescape|int'); $this->redirect("{$this->path}product/{$productId}/show"); } else { $this->redirect("{$this->path}editor"); } }