Inheritance: extends PartKeepr\CategoryBundle\Entity\AbstractCategory, implements PartKeepr\CategoryBundle\Entity\CategoryPathInterface
Exemplo n.º 1
0
 /**
  * Returns the category path.
  *
  * @Groups({"default"})
  *
  * @return string
  */
 public function getCategoryPath()
 {
     if ($this->category !== null) {
         return $this->category->getCategoryPath();
     } else {
         return '';
     }
 }
Exemplo n.º 2
0
 /**
  * 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);
     }
 }
Exemplo n.º 3
0
 /**
  * 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);
 }