PartKeepr\SetupBundle\Services\FootprintSetupService::addFootprintCategoryPath PHP Method

addFootprintCategoryPath() protected method

Creates a node structure for the given path.
protected addFootprintCategoryPath ( array $path, FootprintCategory $parentNode ) : FootprintCategory
$path array array The components of the path
$parentNode PartKeepr\FootprintBundle\Entity\FootprintCategory FootprintCategory The parent node
return PartKeepr\FootprintBundle\Entity\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);
    }