コード例 #1
0
 function it_dispatches_an_event_when_removing_a_tree($eventDispatcher, $objectManager, CategoryInterface $tree)
 {
     $tree->isRoot()->willReturn(true);
     $tree->getProducts()->willReturn([]);
     $eventDispatcher->dispatch(CategoryEvents::PRE_REMOVE_TREE, Argument::type('Symfony\\Component\\EventDispatcher\\GenericEvent'))->shouldBeCalled();
     $objectManager->remove($tree)->shouldBeCalled();
     $this->remove($tree, ['flush' => false]);
 }
コード例 #2
0
 function it_dispatches_an_event_when_removing_a_tree($eventDispatcher, $objectManager, CategoryInterface $tree)
 {
     $tree->getId()->willReturn(12);
     $tree->isRoot()->willReturn(true);
     $tree->getProducts()->willReturn([]);
     $eventDispatcher->dispatch(CategoryEvents::PRE_REMOVE_TREE, Argument::type('Akeneo\\Component\\StorageUtils\\Event\\RemoveEvent'))->shouldBeCalled();
     $objectManager->remove($tree)->shouldBeCalled();
     $eventDispatcher->dispatch(CategoryEvents::POST_REMOVE_TREE, Argument::type('Akeneo\\Component\\StorageUtils\\Event\\RemoveEvent'))->shouldBeCalled();
     $this->remove($tree, ['flush' => true]);
 }
コード例 #3
0
 /**
  * Define the state of a category
  *
  * @param CategoryInterface $category
  * @param bool              $hasChild
  * @param array             $selectedIds
  *
  * @return string
  */
 protected function defineCategoryState(CategoryInterface $category, $hasChild = false, array $selectedIds = [])
 {
     $state = $category->hasChildren() ? 'closed' : 'leaf';
     if ($hasChild === true) {
         $state = 'open';
     }
     if (in_array($category->getId(), $selectedIds)) {
         $state .= ' toselect jstree-checked';
     }
     if ($category->isRoot()) {
         $state .= ' jstree-root';
     }
     return $state;
 }
コード例 #4
0
 /**
  * Remove a category
  *
  * @param CategoryInterface $category
  */
 public function remove(CategoryInterface $category)
 {
     $eventName = $category->isRoot() ? CategoryEvents::PRE_REMOVE_TREE : CategoryEvents::PRE_REMOVE_CATEGORY;
     $this->eventDispatcher->dispatch($eventName, new GenericEvent($category));
     foreach ($category->getProducts() as $product) {
         $product->removeCategory($category);
     }
     $this->getObjectManager()->remove($category);
 }