/** * Deletes the footprint with the given id. * * @param int $id The footprint id to delete * @throws \de\RaumZeitLabor\PartKeepr\Util\SerializableException */ public function deleteFootprint ($id) { $footprint = Footprint::loadById($id); try { PartKeepr::getEM()->remove($footprint); PartKeepr::getEM()->flush(); } catch (\PDOException $e) { if ($e->getCode() == "23000") { $exception = new SerializableException(sprintf(PartKeepr::i18n("Footprint %s is in use by some parts!"), $footprint->getName())); $exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the footprint %s, but there are parts which use this footprint."), $footprint->getName())); throw $exception; } } }
/** * Deletes the given category ID. * @param $id int The category id to delete * @throws CategoryNotFoundException If the category wasn't found */ public function deleteCategory ($id) { $category = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Category\Category", $id); if ($category) { try { $category = new NodeWrapper($category, $this->getNodeManager()); if ($category->hasChildren()) { $exception = new SerializableException(sprintf(PartKeepr::i18n("Category '%s' contains other categories."), $category->getNode()->getName())); $exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the category '%s', but it still contains other categories. Please move the categories or delete them first."), $category->getNode()->getName())); throw $exception; } $category->delete(); } catch (\PDOException $e) { if ($e->getCode() == "23000") { $exception = new SerializableException(sprintf(PartKeepr::i18n("Category '%s' contains parts."), $category->getNode()->getName())); $exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the category '%s', but it still contains parts. Please move the parts to another category."), $category->getNode()->getName())); throw $exception; } } } else { throw new CategoryNotFoundException($id); } }