示例#1
0
 /**
  * @return \TreeNode 
  */
 public function build()
 {
     $node = new TreeNode($this->data, $this->id);
     $node->setChildren($this->children);
     $node->setObject($this->object);
     return $node;
 }
 /**
  * @return TreeNode
  */
 public function wrapInAThreeLevelArtifactTree(array $cards)
 {
     $forest = new TreeNode();
     $forest->setChildren($cards);
     $root = new TreeNode();
     $root->addChild($forest);
     return $root;
 }
示例#3
0
 /**
  * @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();
 }
示例#4
0
 /**
  * @see TreeNodeCallback
  * 
  * @param TreeNode $node
  * @return \Tracker_TreeNode_CardPresenterNode
  */
 public function apply(TreeNode $node)
 {
     if (!$node instanceof ArtifactNode) {
         return clone $node;
     }
     $presenter = new Cardwall_CardPresenter($node->getArtifact(), $this->card_fields);
     $new_node = new Tracker_TreeNode_CardPresenterNode($node, $presenter);
     return $new_node;
 }
示例#5
0
 public function __construct(Tracker_Hierarchy_HierarchicalTracker $tracker, array $possible_children, TreeNode $hierarchy)
 {
     $this->tracker = $tracker;
     $this->tracker_name = $tracker->getUnhierarchizedTracker()->getName();
     $this->possible_children = array_values($possible_children);
     $this->hierarchy = $hierarchy;
     $visitor = new TreeNode_InjectPaddingInTreeNodeVisitor();
     $this->hierarchy->accept($visitor);
 }
 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)));
 }
 private function getParentNode(Tracker_Artifact $parent, array &$cache_alreaydy_built_parents)
 {
     if (!isset($cache_alreaydy_built_parents[$parent->getId()])) {
         $parent_node = new TreeNode();
         $parent_node->setId($parent->getId());
         $parent_node->setObject($parent);
         $cache_alreaydy_built_parents[$parent->getId()] = $parent_node;
     }
     return $cache_alreaydy_built_parents[$parent->getId()];
 }
 /**
  * Makes a CardPresenterNode out of $node if $node contains an artifact
  *
  * TODO something is wrong since we return different types here
  * When on the left side of the planning, the top node is just
  * a node holding the other nodes, and we cant use an array of nodes because
  * there are card-actions available for it...
  *
  * @param TreeNode $node
  *
  * @return \Tracker_TreeNode_CardPresenterNode or \TreeNode
  */
 public function apply(TreeNode $node)
 {
     $artifact = $node->getObject();
     if ($artifact) {
         $planning_item = new Planning_Item($artifact, $this->planning, $artifact->getParent($this->user));
         $presenter = new Planning_ItemPresenter($planning_item, $this->card_fields, $this->classname);
         $presenter_node = new Tracker_TreeNode_CardPresenterNode($node, $presenter);
         return $presenter_node;
     }
     return $node;
 }
 function ItInjectsPadding()
 {
     $root = new TreeNode();
     $node1 = new TreeNode();
     $node2 = new TreeNode();
     $root->addChild($node1);
     $node1->addChild($node2);
     $visitor = new TreeNode_InjectPaddingInTreeNodeVisitor();
     $root->accept($visitor);
     $data = $node2->getData();
     $this->assertPattern('%div class="tree-blank" >[^<]*</div><div class="tree-last"%', $data['tree-padding']);
 }
示例#10
0
 public function __construct(Tracker_Hierarchy_HierarchicalTracker $tracker, array $possible_children, TreeNode $hierarchy, array $trackers_not_in_hierarchy)
 {
     $this->tracker = $tracker;
     $this->tracker_name = $tracker->getUnhierarchizedTracker()->getName();
     $this->possible_children = array_values($possible_children);
     $this->hierarchy = $hierarchy;
     $this->trackers_not_in_hierarchy = $trackers_not_in_hierarchy;
     $this->has_trackers_not_in_hierarchy = count($trackers_not_in_hierarchy) > 0;
     $this->cannot_be_used_in_hierarchy = in_array($tracker->getUnhierarchizedTracker(), $this->trackers_not_in_hierarchy);
     $visitor = new TreeNode_InjectPaddingInTreeNodeVisitor();
     $this->hierarchy->accept($visitor);
     usort($this->trackers_not_in_hierarchy, array($this, 'sortTrackerAlphabetically'));
 }
 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>&nbsp;</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;
 }
 private function getHierarchyAsTreeNode($hierarchy)
 {
     $node = new TreeNode();
     if (isset($hierarchy['children'])) {
         $node->setData(array('name' => $hierarchy['name'], 'id' => $hierarchy['id']));
         $node->setId($hierarchy['id']);
         $hierarchy = $hierarchy['children'];
     } else {
         $node->setId('root');
     }
     foreach ($hierarchy as $item) {
         $node->addChild($this->getHierarchyAsTreeNode($item));
     }
     return $node;
 }
示例#14
0
 /**
  * Tree Builder
  *
  * Re-sorts the data from from_list() and turns it into two datastructures:
  *
  * An array of tree root nodes, with children in the __children__ key
  * of their respective parents. Thus forming a tree as a nested array.
  *
  * A lookup table of id => row, where each item is actually a reference
  * into the tree. This way we can do quick by-index lookups.
  *
  * @param data - array of array('unique_id' => x, 'parent_id' => y, ...data)
  * @param unique id key
  * @param parent id key
  *
  * @return TreeNode	The root node of a tree.
  */
 protected function buildTree($data, $conf)
 {
     $nodes = array();
     $child_key = $conf['id'];
     $parent_key = $conf['parent'];
     $name = $conf['name_key'];
     $class = $conf['class_name'];
     // First we create a lookup table of id => object
     // This lets us build the tree on references which
     // will in turn allow for quick subtree lookup.
     foreach ($data as $row) {
         $id = $row[$child_key];
         $nodes[$id] = new $class($row[$name], $row);
     }
     $tree = new TreeNode('__root__');
     // And now build the actual tree by assigning children
     foreach ($data as $row) {
         $parent = $row[$parent_key];
         $node = $nodes[$row[$child_key]];
         if (isset($nodes[$parent])) {
             $nodes[$parent]->add($node);
         } else {
             $tree->add($node);
         }
     }
     return $tree;
 }
 /**
  *	  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));
 }
 /**
  * Makes a CardPresenterNode out of $node if $node contains an artifact
  *
  * TODO something is wrong since we return different types here
  * When on the left side of the planning, the top node is just
  * a node holding the other nodes, and we cant use an array of nodes because
  * there are card-actions available for it...
  *
  * @param TreeNode $node
  *
  * @return \Tracker_TreeNode_CardPresenterNode or \TreeNode
  */
 public function apply(TreeNode $node)
 {
     $artifact = $node->getObject();
     if ($artifact) {
         $parent = null;
         try {
             $parent = $artifact->getParent($this->user);
         } catch (Tracker_Hierarchy_MoreThanOneParentException $e) {
             $GLOBALS['Response']->addFeedback('error', $e->getMessage(), CODENDI_PURIFIER_LIGHT);
         }
         $planning_item = new Planning_Item($artifact, $this->planning, $parent);
         $presenter = new Planning_ItemPresenter($planning_item, $this->card_fields, $this->classname);
         $presenter_node = new Tracker_TreeNode_CardPresenterNode($node, $presenter);
         return $presenter_node;
     }
     return $node;
 }
 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;
 }
 protected function setArtifactLinks(TreeNode $node, $artifactLinks)
 {
     if (is_array($artifactLinks)) {
         $artifactLinks = implode(', ', $artifactLinks);
     }
     $nodeData = $node->getData();
     $nodeData['artifactlinks'] = $artifactLinks;
     $node->setData($nodeData);
     return $node;
 }
示例#19
0
 /**
  *
  * @param PFUser     $user                  the user who build the tree
  * @param TreeNode $root                  the artifacts tree
  * @param array    $artifacts             list of artifacts
  * @param array    $artifacts_info        list of the artifacts informations : id, last_changeset_id, title, tracker_id, artifactlinks
  * @param array    $excluded_artifact_ids list of excluded artifact ids
  * @param array    $artifacts_done        list of artifacts already processed
  */
 private function buildArtifactsTree(PFUser $user, TreeNode $root, array $artifacts, array $artifacts_info, array $excluded_artifact_ids, array &$artifacts_done)
 {
     foreach ($artifacts as $artifact) {
         $artifact_id = $artifact->getId();
         if (!isset($excluded_artifact_ids[$artifact_id]) && !isset($artifacts_done[$artifact_id])) {
             $node = new TreeNode($this->getArtifactInfo($artifact, $artifacts_info));
             $node->setObject($artifact);
             $artifacts_done[$artifact_id] = true;
             $this->buildArtifactsTree($user, $node, $artifact->getHierarchyLinkedArtifacts($user), $artifacts_info, $excluded_artifact_ids, $artifacts_done);
             $root->addChild($node);
         }
     }
 }
 public function itWrapsAnArtifactInATreeNode()
 {
     $tracker = aMockTracker()->withId(23452345)->build();
     $children_trackers = array(mock('Tracker'), mock('Tracker'));
     $artifact = mock('Tracker_Artifact');
     stub($artifact)->getId()->returns(123);
     stub($artifact)->getTitle()->returns('Foo');
     stub($artifact)->getUri()->returns('/bar');
     stub($artifact)->getXRef()->returns('art #123');
     stub($artifact)->getTracker()->returns($tracker);
     stub($artifact)->getAllowedChildrenTypes()->returns($children_trackers);
     $planning = mock('Planning');
     $node = new TreeNode(array('id' => 123));
     $node->setObject($artifact);
     $card_mapper = new TreeNodeMapper(new Planning_ItemCardPresenterCallback($planning, mock('Tracker_CardFields'), mock('User'), 'baz'));
     $visited_node = $card_mapper->map($node);
     $presenter = $visited_node->getCardPresenter();
     $this->assertEqual(123, $presenter->getId());
     $this->assertEqual('Foo', $presenter->getTitle());
     $this->assertEqual('/bar', $presenter->getUrl());
     $this->assertEqual('art #123', $presenter->getXRef());
     $this->assertEqual('baz', $presenter->getCssClasses());
     $this->assertEqual($children_trackers, $presenter->allowedChildrenTypes());
 }
示例#21
0
            $node->setOpened(true);
        }
        $node->SetClosedImageSource(PEERICONS . $navtable[$i][0]['image']);
        //This node has no childs, which means it´s always closed.
        $node->SetOpenedImageSource(PEERICONS . $navtable[$i][0]['image']);
        //This node has no childs, which means it´s always closed.
        $_SESSION[$menu_name]->AddNode($node);
        //Add "Root Folder" node to treeview.
        $_SESSION[$menu_name]->SetWidthBetweenNodeLayers(6);
        $parent = $genid;
        $genid++;
        $submenu_count = 0;
        for ($j = 0; $j < count($navtable[$i]); $j++) {
            $submenu_name = $navtable[$i][$j]['linktext'];
            unset($_SESSION[$submenu_name]->Nodes);
            $subnode = new TreeNode($genid, $submenu_name);
            //Create a new node object with id "1" and set name to "Root Folder".
            $subnode->SetParentId($parent);
            //Set "sites" node as parent.
            $subnode->SetExternUrl(PEERSITE . $navtable[$i][$j]['target']);
            $subnode->SetClosedImageSource(PEERICONS . $navtable[$i][$j]['image']);
            //This node has no childs, which means it´s always closed.
            $subnode->SetOpenedImageSource(PEERICONS . $navtable[$i][$j]['image']);
            //This node has no childs, which means it´s always closed.
            $_SESSION[$menu_name]->AddNode($subnode);
            //Add "Root Folder" node to treeview.
            $genid++;
        }
    }
    $_SESSION["NodesHasBeenAddedUrl"] = true;
}
 function project_tabs($toptab, $group_id)
 {
     $pm = ProjectManager::instance();
     $project = $pm->getProject($group_id);
     if ($project->isError()) {
         //wasn't found or some other problem
         return;
     }
     $menuTree = new TreeNode();
     $output = '';
     $tabs = $this->_getProjectTabs($toptab, $project);
     $nb = count($tabs);
     $selected = false;
     for ($i = 0; $i < $nb; $i++) {
         if ($tabs[$i]['enabled'] === true) {
             $selected = true;
         }
         $menuTree->addChild(new TreeNode(array('link' => $tabs[$i]['link'], 'title' => $tabs[$i]['label'], 'selected' => $tabs[$i]['enabled'])));
     }
     //$output .= $this->tabGenerator($TABS_DIRS,$TABS_TITLES,true,$selected, 2);
     //echo $output;
     return $menuTree;
 }
示例#23
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);
 }
 /**
  * Avalia a expressão e retorna o seu valor (resolve a expessão)
  * @param TreeNode|TreeLeaf $treeNode Arvore que será analizada
  * @return float|int|null Resultado da expressão
  */
 public function evaluate($treeNode = null)
 {
     $result = null;
     if ($treeNode == null) {
         $result = $this->treeNode == null ? 0 : $this->evaluate($this->treeNode);
     } else {
         if ($treeNode instanceof TreeLeaf) {
             /**
              * SE é uma folha, então so tem o valor numérico
              */
             $result = $treeNode->getValue();
         } else {
             /**
              * Aqui é nó binário, então existe o lado esquerdo, direito e o operador
              */
             $operator = $treeNode->getOperator();
             /**
              * Chama recursivamente cada lado do nó (que podem ser outros nós)
              */
             $valueLeft = $this->evaluate($treeNode->getLeft());
             $valueRight = $this->evaluate($treeNode->getRight());
             /**
              * Executa as operações
              */
             switch ($operator) {
                 case '+':
                     $result = $valueLeft + $valueRight;
                     break;
                 case '-':
                     $result = $valueLeft - $valueRight;
                     break;
                 case '*':
                     $result = $valueLeft * $valueRight;
                     break;
                 case '/':
                     $result = $valueLeft / $valueRight;
                     break;
                 case '^':
                     $result = $valueLeft ^ $valueRight;
                     break;
             }
         }
     }
     return $result;
 }
示例#25
0
 /**
  * Adds $parent_node children according to $artifact ones.
  *
  * @param type $user
  * @param type $artifact
  * @param type $parent_node
  * @param type $parents     The list of parents to prevent infinite recursion
  *
  * @return boolean
  */
 private function addChildrenPlannedArtifacts(User $user, Tracker_Artifact $artifact, TreeNode $parent_node, array $parents)
 {
     $linked_artifacts = $artifact->getUniqueLinkedArtifacts($user);
     if (!$linked_artifacts) {
         return false;
     }
     if (in_array($artifact->getId(), $parents)) {
         return false;
     }
     $parents[] = $artifact->getId();
     foreach ($linked_artifacts as $linked_artifact) {
         $node = $this->makeNodeWithChildren($user, $linked_artifact, $parents);
         $parent_node->addChild($node);
     }
 }
示例#26
0
 public function __construct(Tracker_Artifact $artifact, array $data = null)
 {
     parent::__construct($data, $artifact->getId());
     $this->setObject($artifact);
 }
示例#27
0
 public function __construct($caption, $loading = false)
 {
     parent::__construct($caption, null, $loading);
 }
示例#28
0
 /**
  * Remove node.
  *
  * @param TreeNode $node Node.
  * @return TreeNode
  */
 public function remove(TreeNode $node)
 {
     $result = $node;
     unset($this->nodeList[$node->getID()]);
     return $result;
 }
示例#29
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());
 }
示例#30
0
 private function GivenANodeInAparent(TreeNode $parent)
 {
     $node = new TreeNode();
     $parent->addChild($node);
     return $node;
 }