Example #1
0
 private function addMenuNode($parent, NestedSet\NodeWrapper $node, $homepage)
 {
     $menuItem = $node->getNode();
     $name = $menuItem->getName();
     $url = $menuItem->getUrl();
     if ($homepage) {
         $newNode = $parent->setupHomepage($name, $url);
     } else {
         $newNode = $parent->add($name, $url);
     }
     $newNode->setAsCurrent($menuItem->isCurrent());
     $newNode->setOpenInNewWindow($menuItem->isExternal());
     foreach ($node->getChildren() as $child) {
         $this->addMenuNode($newNode, $child, false);
     }
 }
 /**
  * @covers DoctrineExtensions\NestedSet\NodeWrapper::insertAsPrevSiblingOf
  * @covers DoctrineExtensions\NestedSet\NodeWrapper::shiftRLRange
  * @covers DoctrineExtensions\NestedSet\NodeWrapper::insertNode
  */
 public function testInsertAsPrevSiblingOf()
 {
     $newNode = new NodeWrapper(new SingleRootNodeMock(21, '1.1.1(.5)'), $this->nsm);
     $newNode->insertAsPrevSiblingOf($this->wrappers[3]);
     $this->assertEquals(5, $newNode->getLeftValue(), '->insertAsPrevSiblingOf() updates new node\'s left value');
     $this->assertEquals(6, $newNode->getRightValue(), '->insertAsPrevSiblingOf() updates new node\'s right value');
     $this->assertEquals(3, $this->wrappers[2]->getLeftValue(), '->insertAsPrevSiblingOf updates prev node\'s left value');
     $this->assertEquals(4, $this->wrappers[2]->getRightValue(), '->insertAsPrevSiblingOf updates prev node\'s right value');
     $this->assertEquals(7, $this->wrappers[3]->getLeftValue(), '->insertAsPrevSiblingOf updates next node\'s left value');
     $this->assertEquals(8, $this->wrappers[3]->getRightValue(), '->insertAsPrevSiblingOf updates next node\'s right value');
 }
 /**
  * Serializes the given NodeWrapper as array including all children.
  * @param NodeWrapper $node The category nodewrapper to serialize
  * @throws \Exception
  */
 public function serializeTree(NodeWrapper $node = null)
 {
     if ($node == null) {
         throw new \Exception("Node must not be null!");
     }
     $aData = $node->getNode()->serialize();
     $aData["children"] = array();
     if (count($node->getChildren()) == 0) {
         $aData["leaf"] = true;
     } else {
         $aData["expanded"] = true;
     }
     foreach ($node->getChildren() as $child) {
         $aData["children"][] = $this->serializeTree($child);
     }
     return $aData;
 }
 /**
  * Updates the category paths for a given node and all children.
  * 
  * This method is usually called whenever a category is moved.
  * 
  * @param NodeWrapper $startNode The node to start updating at
  */
 public function updateCategoryPaths(NodeWrapper $startNode)
 {
     $pathSeparator = Configuration::getOption("partkeepr.category.path_separator", " ➤ ");
     $startNode->getNode()->setCategoryPath($startNode->getPath($pathSeparator, true));
     foreach ($startNode->getChildren() as $child) {
         $this->updateCategoryPaths($child);
     }
 }
 /**
  * @covers DoctrineExtensions\NestedSet\NodeWrapper::insertAsLastChildOf
  * @expectedException InvalidArgumentException
  */
 public function testInsertAsLastChildOf_CantInsertSelf()
 {
     $newNode = new NodeWrapper(new NodeMock(21, '1.1.3'), $this->nsm);
     $newNode->insertAsLastChildOf($newNode);
 }
Example #6
0
	/**
	 * Deletes the given category ID.
	 * @param $id int The category id to delete
	 * @throws CategoryNotFoundException If the category wasn't found
	 */
	public function deleteCategory ($id) {
		$category = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Category\Category", $id);
		
		
		if ($category) {
			try {
				$category = new NodeWrapper($category, $this->getNodeManager());
				
				if ($category->hasChildren()) {
					$exception = new SerializableException(sprintf(PartKeepr::i18n("Category '%s' contains other categories."), $category->getNode()->getName()));
					$exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the category '%s', but it still contains other categories. Please move the categories or delete them first."), $category->getNode()->getName()));
				
					throw $exception;
				}
				$category->delete();	
			} catch (\PDOException $e) {
				if ($e->getCode() == "23000") {
					$exception = new SerializableException(sprintf(PartKeepr::i18n("Category '%s' contains parts."), $category->getNode()->getName()));
					$exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the category '%s', but it still contains parts. Please move the parts to another category."), $category->getNode()->getName()));
				
					throw $exception;
				}
			}
			
		} else {
			throw new CategoryNotFoundException($id);
		}
	}