/** * @param string $title * @param array $cells */ public function __construct(TreeNode $node, array $cells) { if ($node instanceof Cardwall_CardInCellPresenterNode) { $this->card_presenter = $node->getCardInCellPresenter()->getCardPresenter(); } $this->cells = $cells; $this->swimline_id = $node->getId(); }
public function itHasACardInCellPresenterWithSwimLineValueCollection() { $parent_node = new TreeNode(); $parent_node->addChild($this->card_presenter_node); $mapping_collection = stub('Cardwall_MappingCollection')->getSwimLineValues($this->field_id)->returns(array(123, 456)); $cardincell_presenter_callback = new Cardwall_CardInCellPresenterCallback($this->field_retriever, $mapping_collection); $cardincell_presenter_node = $cardincell_presenter_callback->apply($this->card_presenter_node); $this->assertEqual($cardincell_presenter_node->getCardInCellPresenter(), new Cardwall_CardInCellPresenter($this->card_presenter, $this->field_id, $parent_node->getId(), array(123, 456))); }
public function visit(TreeNode $node) { $output = (string) $node->getId(); $children = $node->getChildren(); if ($children) { $children_output = array(); foreach ($children as $child) { $children_output[] = $child->accept($this); } $output .= ' (' . implode(', ', $children_output) . ')'; } return $output; }
private function convertStateToDivs(TreeNode $node, $state) { $html = ''; $template = '<div class="%s" %s> </div>'; foreach ($state as $state_id) { $id = ''; $class = self::$state_classes[$state_id]; if ($this->collapsable && $node->hasChildren() && ($state_id == self::STATE_LAST || $state_id == self::STATE_NODE)) { $class .= ' tree-collapsable'; $id = 'id="tree-node-' . $node->getId() . '"'; } $html .= sprintf($template, $class, $id); } return $html; }
/** * Test the constructor */ function test_everything() { // create a few root nodes $node1 = new TreeNode('1'); $this->assertIdentical($node1->getId(), '1'); $this->assertFalse($node1->hasParents()); $this->assertEqual($node1->getChildren(), array()); $this->assertFalse($node1->hasChildren()); $this->assertIdentical($node1->getChildrenCount(), 0); // create some children $node1_1 = new TreeNode('2'); $node1_2 = new TreeNode('3'); $node1->addChild($node1_1); $node1->addChild($node1_2); $node1_1_1 = new TreeNode('4'); $node1_1->addChild($node1_1_1); $parents = $node1_1->getParents(); $this->assertReference($node1, $parents['1']); $parents = $node1_2->getParents(); $this->assertReference($node1, $parents['1']); $parents = $node1_1_1->getParents(); $this->assertReference($node1_1, $parents['2']); $this->assertIdentical($node1_1->getId(), '2'); $this->assertIdentical($node1_2->getId(), '3'); $this->assertIdentical($node1_1_1->getId(), '4'); $this->assertTrue($node1->hasChildren()); $this->assertTrue($node1_1->hasChildren()); $this->assertFalse($node1_2->hasChildren()); $this->assertIdentical($node1->getChildrenCount(), 2); $children = $node1->getChildren(); $this->assertReference($children['2'], $node1_1); $this->assertReference($children['3'], $node1_2); $children = $node1_1->getChildren(); $this->assertReference($children['4'], $node1_1_1); // create a new root $node = new TreeNode('100'); $node->addChild($node1); $children = $node->getChildren(); $this->assertReference($children['1'], $node1); $parents = $node1->getParents(); $this->assertReference($node, $parents['100']); // try detaching a node now $node1->detachChild($node1_1); $this->assertFalse($node1_1->hasParents()); $this->assertFalse($node1->isChild($node1_1)); $this->assertTrue($node1->isChild($node1_2)); }
public function __construct(TreeNode $node) { parent::__construct($node->getData(), $node->getId()); $this->setChildren($node->getChildren()); $this->setObject($node->getObject()); }
protected function setChildState(TreeNode $child, $state) { $this->states[$child->getId()] = $state; }