Exemplo n.º 1
0
 public function itAddsTheGivenChildren()
 {
     $root = new TreeNode();
     $children = array(new TreeNode(), new TreeNode());
     $root->setChildren($children);
     $this->assertEqual($children, $root->getChildren());
 }
 public function visit(TreeNode $node)
 {
     $top_parents = array();
     $cache_alreaydy_built_parents = array();
     foreach ($node->getChildren() as $child) {
         $top = $this->buildParentHierarchy($child, $cache_alreaydy_built_parents);
         $top_parents[$top->getId()] = $top;
     }
     $node->setChildren($top_parents);
 }
Exemplo n.º 3
0
 private function getArtifactsFromSecondLevelAndDown(TreeNode $root_node)
 {
     $leafs = array();
     foreach ($root_node->getChildren() as $child) {
         $leafs = array_merge($leafs, $child->flattenChildren());
     }
     $artifacts = array();
     foreach ($leafs as $node) {
         $this->appendIfArtifactNode($artifacts, $node);
     }
     return $artifacts;
 }
Exemplo n.º 4
0
 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;
 }
Exemplo n.º 5
0
 /**
  *	  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 visit(TreeNode $tree_node)
 {
     $new_children = array();
     foreach ($tree_node->getChildren() as $child_node) {
         $child_artifact = $child_node->getObject();
         if ($this->hierarchy->exists($child_artifact->getTrackerId())) {
             if ($this->isBacklogPlannableArtifact($child_artifact)) {
                 $new_children[] = $child_node;
             } else {
                 $new_subchildren = $child_node->accept($this)->getChildren();
                 $new_children = array_merge($new_children, $new_subchildren);
             }
         }
     }
     $new_tree_node = new TreeNode();
     $new_tree_node->setChildren($new_children);
     return $new_tree_node;
 }
Exemplo n.º 7
0
 private function setState(TreeNode $node, $prefix)
 {
     $children = $node->getChildren();
     $nb_children = count($children);
     $i = 0;
     $children_prefix = $this->getDefaultChildrenPrefix($prefix);
     $child_state = $this->getDefaultState($prefix);
     foreach ($children as $child) {
         $child_id = $child->getId();
         if ($this->isLastChildren($i, $nb_children)) {
             $children_prefix = $this->getChildrenPrefixForLastChild($prefix);
             $child_state = $this->getStateWhenChildIsTheLastOne($prefix);
         }
         $this->setChildState($child, $child_state);
         $child->accept($this, $children_prefix);
         $i++;
     }
 }
Exemplo n.º 8
0
 private function getSwimlines(Cardwall_OnTop_Config_ColumnCollection $columns, TreeNode $forests_of_cardincell_presenters, $config, $field_provider)
 {
     $swimline_factory = new Cardwall_SwimlineFactory($config, $field_provider);
     return $swimline_factory->getSwimlines($columns, $forests_of_cardincell_presenters->getChildren());
 }
Exemplo n.º 9
0
 /**
  * Removes the sub-milestone artifacts from an artifacts tree.
  *
  * @param User             $user               The user accessing the data
  * @param Tracker_Artifact $milestone_artifact The parent artifact of sub-milestones artifacts
  * @param TreeNode         $artifacts_tree     The artifacts tree to clean up
  */
 private function removeSubMilestones(User $user, Tracker_Artifact $milestone_artifact, TreeNode $artifacts_tree)
 {
     $hierarchy_children_ids = $this->getSubMilestonesArtifactIds($user, $milestone_artifact);
     foreach ($artifacts_tree->getChildren() as $node) {
         if (in_array($node->getId(), $hierarchy_children_ids)) {
             $artifacts_tree->removeChild(null, $node);
         }
     }
 }
Exemplo n.º 10
0
 private function getSwimline(Cardwall_OnTop_Config_ColumnCollection $columns, TreeNode $child)
 {
     $potential_presenters = $this->extractPresentersFrom($child->getChildren());
     $cells = $this->getCells($columns, $potential_presenters);
     return new Cardwall_Swimline($child, $cells);
 }
Exemplo n.º 11
0
 private function addChildrenNodes(TreeNode $root_node, &$artifacts, $user)
 {
     foreach ($root_node->getChildren() as $node) {
         $artifact = $node->getObject();
         $artifacts[] = $artifact;
         $artifacts = array_merge($artifacts, $artifact->getUniqueLinkedArtifacts($user));
         $this->addChildrenNodes($node, $artifacts, $user);
     }
 }
Exemplo n.º 12
0
 /**
  * Helper function to generate the code using a given 
  * root node.
  *
  * @param TreeNode $root - the root node
  * @return string - the generated code
  * @author Karthik Viswanathan
  */
 private function generateCode($root)
 {
     $node = $root->getValue();
     if ($node instanceof Tag) {
         $str = $node->getTagHTML();
         // open tag
         foreach ($root->getChildren() as $child) {
             $str .= $this->generateCode($child, $str);
             // everything inside tag
         }
         if (!$node->isSelfClosed()) {
             $str .= '</' . $node->getName() . '>';
         }
         // end tag
     } else {
         $str = $node;
     }
     // node is just text
     return $str;
 }
Exemplo n.º 13
0
 public function __construct(TreeNode $node)
 {
     parent::__construct($node->getData(), $node->getId());
     $this->setChildren($node->getChildren());
     $this->setObject($node->getObject());
 }
Exemplo n.º 14
0
 function visit(TreeNode $node)
 {
     $data = $node->getData();
     echo '<div style="clear:both;">';
     echo $data['tree-padding'] . $data['title'];
     echo '</div>';
     foreach ($node->getChildren() as $child) {
         $child->accept($this);
     }
 }
Exemplo n.º 15
0
 public function visit(TreeNode $node)
 {
     $html = '';
     $row = $node->getData();
     $artifact = $this->artifact_factory->getArtifactById($row['id']);
     if ($artifact) {
         $html .= '<tr id="tree-node-' . $row['id'] . '" class="' . html_get_alt_row_color($this->current_index++) . '" >';
         $html .= '<td class="first-column">';
         $html .= $row['tree-padding'];
         $html .= sprintf($row['content-template'], $artifact->fetchDirectLinkToArtifact());
         $html .= '</td>';
         $html .= $this->fetchColumnsValues($artifact, $row);
         $html .= '</tr>';
         foreach ($node->getChildren() as $child) {
             $html .= $child->accept($this);
         }
     }
     return $html;
 }