PartKeepr\FootprintBundle\Entity\FootprintCategory::setParent PHP Method

setParent() public method

Sets the parent category.
public setParent ( AbstractCategory $parent = null )
$parent PartKeepr\CategoryBundle\Entity\AbstractCategory
    public function setParent(AbstractCategory $parent = null)
    {
        $this->parent = $parent;
    }

Usage Example

 /**
  * Creates a node structure for the given path.
  *
  * @param $path       array The components of the path
  * @param $parentNode FootprintCategory  The parent node
  *
  * @return FootprintCategory
  */
 protected function addFootprintCategoryPath(array $path, FootprintCategory $parentNode)
 {
     if (count($path) == 0) {
         return $parentNode;
     }
     $name = array_shift($path);
     $category = null;
     foreach ($parentNode->getChildren() as $child) {
         if ($child->getName() == $name) {
             $category = $child;
         }
     }
     if ($category === null) {
         $category = new FootprintCategory();
         $category->setParent($parentNode);
         $category->setName($name);
         $parentNode->getChildren()->add($category);
         $this->entityManager->persist($category);
     }
     return $this->addFootprintCategoryPath($path, $category);
 }