private function addDeleteContainer() { $deleteContainer = $this->addContainer('delete'); foreach ($this->categoryService->getAll() as $category) { if (!$category->hasProducts()) { $deleteContainer->addSubmit($category->getId(), 'x'); } } }
private function manageCategories(ArrayHash $values, ManageCategoriesForm $form) { /** @var Container $deleteContainer */ $deleteContainer = $form->getComponent('delete'); foreach ($this->categoryService->getAll() as $category) { /** @var SubmitButton $deleteSubmit */ $deleteSubmit = $deleteContainer->getComponent($category->getId(), false); if ($deleteSubmit !== null && $deleteSubmit->isSubmittedBy()) { $this->flashMessage(sprintf('Category %s has been deleted.', $category->getName())); $this->categoryService->remove($category); $this->redirect('this'); } } }
private function addParentCategoryControl() { $parentCategoryItems = [self::ROOT_CATEGORY_KEY => '']; foreach ($this->categoryService->getAll() as $category) { if ($this->editedCategory !== null) { if ($category->isSelfOrSubcategoryOf($this->editedCategory)) { continue; } } $parentCategoryItems[$category->getId()] = ''; } $parentCategoryControl = $this->addRadioList('parentCategory', 'Parent category', $parentCategoryItems); $parentCategoryControl->setRequired(); $parentCategoryControl->setDefaultValue($this->editedCategory !== null && $this->editedCategory->hasParent() ? $this->editedCategory->getParent()->getId() : self::ROOT_CATEGORY_KEY); }
private function addCategoriesControl() { $categoryIds = iterator_to_array($this->categoryService->getAll()); $categoryIds = array_map(function (Category $category) { return $category->getId(); }, $categoryIds); $control = $this->addCheckboxList('categories', 'Categories', array_flip($categoryIds)); if ($this->editedProduct !== null) { $checkedIds = iterator_to_array($this->editedProduct->getCategories()); $checkedIds = array_map(function (Category $category) { return $category->getId(); }, $checkedIds); $control->setDefaultValue($checkedIds); } }