public function create () { $this->requireParameter("name"); $this->requireParameter("parent"); $category = new Category; $category->setName($this->getParameter("name")); $category->setDescription($this->getParameter("description", "")); $category->setParent($this->getParameter("parent")); $category = CategoryManager::getInstance()->addCategory($category); return array("data" => $this->serializeCategory($category)); }
public function movePart () { $this->requireParameter("targetCategory"); if ($this->getParameter("parts", false) !== false) { /* We are moving multiple parts */ foreach ($this->getParameter("parts") as $part) { $part = Part::loadById($part); $category = Category::loadById($this->getParameter("targetCategory")); $part->setCategory($category); } } else { $part = Part::loadById($this->getParameter("part")); $category = Category::loadById($this->getParameter("targetCategory")); $part->setCategory($category); } PartKeepr::getEM()->flush(); }
function addCategoryRecursive ($aCategories, $currentId, $parent) { global $newCategories; foreach ($aCategories as $aCategory) { if ($aCategory["parentnode"] == $currentId) { echo "Adding ".sprintf("%40s", $aCategory["name"])."\r"; $oCategory = new Category(); $oCategory->setName(convertText($aCategory["name"])); $oCategory->setDescription(""); $oCategory->setParent($parent->getId()); $category = CategoryManager::getInstance()->addCategory($oCategory); addCategoryRecursive($aCategories, $aCategory["id"], $category); $newCategories[$aCategory["id"]] = $oCategory; } } }
/** * Adds a given category. * @param Category $category The category to add to the tree * @return Category the added category */ public function addCategory (Category $category) { $parent = $category->getParent(); if ($parent == 0) { $parent = $this->getRootNode(); } else { $parent = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Category\Category", $parent); $parent = new NodeWrapper($parent, $this->getNodeManager()); } return $parent->addChild($category); }