public function removeCategory(Category $category) { $oldSiblings = $category->getParent() ? $category->getParent()->getChildren() : $category->getGuide()->getCategoriesWithoutParent(); foreach ($oldSiblings as $child) { if ($child->getPosition() >= $category->getPosition()) { $child->setPosition($child->getPosition() - 1); } $this->em->persist($child); } $this->em->remove($category); $this->em->flush(); }
public function getModel(Category $category) { return (new CategoryModel())->setId($category->getId())->setPosition($category->getPosition())->setTitle($category->getTitle())->setImage($category->getImage())->setContent($category->getContent()); }
/** * @FosRest\Delete("/{category}", requirements={"category" = "\d+"}) * * @ParamConverter("category", class="MainBundle:Category") * * @FosRest\View() * @param Category $category */ public function removeAction(Category $category) { $this->checkPermissionsForSection($category->getGuide()->getSection()); return $this->get('main.category.service')->removeCategory($category); }