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

generateCategoryPath() public method

public generateCategoryPath ( $pathSeparator )
    public function generateCategoryPath($pathSeparator)
    {
        if ($this->getParent() !== null) {
            return $this->getParent()->generateCategoryPath($pathSeparator) . $pathSeparator . $this->getName();
        } else {
            return $this->getName();
        }
    }

Usage Example

 /**
  * Recursively updates the category paths.
  *
  * @param FootprintCategory $footprintCategory The footprint category to update
  * @param EntityManager     $entityManager     The entity manager
  */
 public function updateCategoryPaths(FootprintCategory $footprintCategory, OnFlushEventArgs $eventArgs)
 {
     $entityManager = $eventArgs->getEntityManager();
     $pathSeparator = $this->container->getParameter("partkeepr.category.path_separator");
     $footprintCategory->setCategoryPath($footprintCategory->generateCategoryPath($pathSeparator));
     $entityManager->getUnitOfWork()->recomputeSingleEntityChangeSet($entityManager->getClassMetadata(get_class($footprintCategory)), $footprintCategory);
     foreach ($footprintCategory->getChildren() as $child) {
         $this->updateCategoryPaths($child, $eventArgs);
     }
 }