public function testMemoryStoreDeleteDataForNodes() { $store = new ezcTreeMemoryDataStore(); $tree = ezcTreeMemory::create($store); $list = new ezcTreeNodeList(); $list->addNode(new ezcTreeNode($tree, 'Mars', '♂')); $list->addNode(new ezcTreeNode($tree, 'Jupiter', '♃')); $ser = serialize($list); $store->deleteDataForNodes($list); self::assertSame($ser, serialize($list)); }
public function testOnDemandData() { $tree = ezcTreeMemory::create(new TestTranslateDataStore()); $list = new ezcTreeNodeList(); $node = new ezcTreeNode($tree, 'vuur'); $list->addNode($node); foreach (new ezcTreeNodeListIterator($tree, $list) as $key => $data) { self::assertSame('vuur', $key); self::assertSame(array('en' => 'fire', 'de' => 'feuer', 'no' => 'fyr'), $data); } }
/** * Returns the node with ID $nodeId and all its children, sorted according to * the {@link http://en.wikipedia.org/wiki/Breadth-first_search Breadth-first sorting} * algorithm. * * @param string $nodeId * @return ezcTreeNodeList */ public function fetchSubtreeBreadthFirst($nodeId) { $className = $this->properties['nodeClassName']; $list = new ezcTreeNodeList(); $list->addNode(new $className($this, $nodeId)); $this->addChildNodesBreadthFirst($list, $nodeId); return $list; }
/** * Returns the node with ID $nodeId and all its children, sorted according to * the {@link http://en.wikipedia.org/wiki/Breadth-first_search Breadth-first sorting} * algorithm. * * @param string $nodeId * @return ezcTreeNodeList */ public function fetchSubtreeBreadthFirst($nodeId) { $list = new ezcTreeNodeList(); $memoryNode = $this->getNodeById($nodeId); $list->addNode($memoryNode->node); $this->addChildNodesBreadthFirst($list, $memoryNode); return $list; }
public function testFetchAllData() { $tree = ezcTreeMemory::create(new TestTranslateDataStore()); $list = new ezcTreeNodeList(); $list->addNode($node = new ezcTreeNode($tree, 'Aries')); $list->addNode($node = new ezcTreeNode($tree, 'Taurus')); $list->addNode($node = new ezcTreeNode($tree, 'Gemini')); $list->addNode($node = new ezcTreeNode($tree, 'Cancer')); foreach ($list->nodes as $node) { self::assertSame(false, $node->dataFetched); } $list->fetchDataForNodes(); foreach ($list->nodes as $node) { self::assertSame(true, $node->dataFetched); } self::assertSame('♋', $list['Cancer']->data); }
/** * Returns the node with ID $nodeId and all its children, sorted according to * the {@link http://en.wikipedia.org/wiki/Depth-first_search Depth-first sorting} * algorithm. * * @param string $nodeId * @return ezcTreeNodeList */ public function fetchSubtreeDepthFirst($nodeId) { $className = $this->properties['nodeClassName']; $list = new ezcTreeNodeList(); $db = $this->dbh; // Fetch parent information list($left, $right, $width) = $this->fetchNodeInformation($nodeId); // Fetch subtree // SELECT id // FROM indexTable // WHERE lft BETWEEN $left AND $right // ORDER BY lft $q = $db->createSelectQuery(); $q->select('id')->from($db->quoteIdentifier($this->indexTableName))->where($q->expr->between('lft', $q->bindValue($left), $q->bindValue($right)))->orderBy('lft'); $s = $q->prepare(); $s->execute(); foreach ($s as $result) { $list->addNode(new $className($this, $result['id'])); } return $list; }