Наследование: extends PartKeepr\CategoryBundle\Entity\AbstractCategory, implements PartKeepr\CategoryBundle\Entity\CategoryPathInterface
Пример #1
0
 /**
  * Returns the category path.
  *
  * @Groups({"default"})
  *
  * @return string
  */
 public function getCategoryPath()
 {
     if ($this->category !== null) {
         return $this->category->getCategoryPath();
     } else {
         return '';
     }
 }
Пример #2
0
 /**
  * Recursively updates the category paths.
  *
  * @param StorageLocationCategory $storageLocationCategory The storage location category to update
  * @param EntityManager           $entityManager           The entity manager
  */
 public function updateCategoryPaths(StorageLocationCategory $storageLocationCategory, OnFlushEventArgs $eventArgs)
 {
     $entityManager = $eventArgs->getEntityManager();
     $pathSeparator = $this->container->getParameter('partkeepr.category.path_separator');
     $storageLocationCategory->setCategoryPath($storageLocationCategory->generateCategoryPath($pathSeparator));
     $entityManager->getUnitOfWork()->recomputeSingleEntityChangeSet($entityManager->getClassMetadata(get_class($storageLocationCategory)), $storageLocationCategory);
     foreach ($storageLocationCategory->getChildren() as $child) {
         $this->updateCategoryPaths($child, $eventArgs);
     }
 }
Пример #3
0
 /**
  * @param Schema $schema
  */
 public function up(Schema $schema)
 {
     $this->performDatabaseUpgrade();
     $repository = $this->getEM()->getRepository('PartKeeprStorageLocationBundle:StorageLocationCategory');
     $rootNodes = $repository->getRootNodes();
     if (count($rootNodes) === 0) {
         // Ensure that the root category exists
         $rootNode = new StorageLocationCategory();
         $rootNode->setName('Root Node');
         $this->getEM()->persist($rootNode);
         $this->getEM()->flush();
     } else {
         $rootNode = array_values($rootNodes)[0];
     }
     $storageLocationRepository = $this->getEM()->getRepository('PartKeeprStorageLocationBundle:StorageLocation');
     $allStorageLocations = $storageLocationRepository->findAll();
     foreach ($allStorageLocations as $storageLocation) {
         $storageLocation->setCategory($rootNode);
     }
     $this->getEM()->flush();
 }