Пример #1
0
 public function testTreeOperations()
 {
     $newNode1 = new Tree\Node('abc', 'node1', $this->_tree);
     $this->_tree->addNode($newNode1);
     $newNode2 = new Tree\Node('def', 'node2', $this->_tree);
     $this->_tree->addNode($newNode2, $newNode1);
     $newNode3 = new Tree\Node('ghi', 'node3', $this->_tree);
     $this->_tree->addNode($newNode3, $newNode1);
     $data1 = ['j', 'k', 'l'];
     $this->_tree->appendChild($data1, $newNode3);
     $newNode4 = new Tree\Node('mno', 'node4', $this->_tree);
     $this->_tree->appendChild($newNode4, $newNode3);
     $this->_tree->removeNode($newNode4);
     $this->_tree->removeNode($newNode3);
     $this->_tree->removeNode($newNode2);
     $this->_tree->removeNode($newNode1);
     $this->assertEmpty($this->_tree->getNodes()->getNodes());
 }
Пример #2
0
 /**
  * @param Node $prevNode
  * @return $this
  */
 public function appendChild($prevNode = null)
 {
     $this->_tree->appendChild($this, $prevNode);
     return $this;
 }
Пример #3
0
 /**
  * @param Node $data
  * @param Node $parentNode
  * @param Node $prevNode
  * @return Node
  */
 public function appendChild($data, $parentNode, $prevNode = null)
 {
     $orderSelect = $this->_conn->select();
     $orderSelect->from($this->_table, new \Zend_Db_Expr('MAX(' . $this->_conn->quoteIdentifier($this->_orderField) . ')'))->where($this->_conn->quoteIdentifier($this->_parentField) . '=' . $parentNode->getId());
     $order = $this->_conn->fetchOne($orderSelect);
     $data[$this->_parentField] = $parentNode->getId();
     $data[$this->_levelField] = $parentNode->getData($this->_levelField) + 1;
     $data[$this->_orderField] = $order + 1;
     $this->_conn->insert($this->_table, $data);
     $data[$this->_idField] = $this->_conn->lastInsertId();
     return parent::appendChild($data, $parentNode, $prevNode);
 }