Source for file HierarchyPrinter.class.php

Documentation is available at HierarchyPrinter.class.php

  1. <?php
  2. /**
  3. * @package polyphony.HierarchyPrinter
  4. *
  5. * @copyright Copyright &copy; 2005, Middlebury College
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  7. *
  8. * @version $Id: HierarchyPrinter.class.php,v 1.14 2007/09/19 14:04:46 adamfranco Exp $
  9. */
  10.  
  11. /**
  12. * This class will print an expandible, view of a hierarchy
  13. *
  14. * @package polyphony.HierarchyPrinter
  15. *
  16. * @copyright Copyright &copy; 2005, Middlebury College
  17. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  18. *
  19. * @version $Id: HierarchyPrinter.class.php,v 1.14 2007/09/19 14:04:46 adamfranco Exp $
  20. */
  21.  
  22. class HierarchyPrinter {
  23. /**
  24. * Print a node and the expanded children
  25. *
  26. * @param object $node
  27. * @param string $printFunction Function that prints the current node's info.
  28. * @param string $hasChildrenFunction Function that returns true if the node
  29. * has children.
  30. * @param string $getChildrenFunction Function that returns an array of the
  31. * children of this node.
  32. * @return void
  33. * @access public
  34. * @since 11/8/04
  35. */
  36. function printNode ($node, $harmoni,
  37. $startingPathInfoKey,
  38. $printFunction,
  39. $hasChildrenFunction,
  40. $getChildrenFunction,
  41. $color = NULL )
  42. {
  43. print "\n<div";
  44. if ($color !== NULL) {
  45. print " style='";
  46. // print " border: 1px solid #000;";
  47. print " padding-top: 5px; padding-left: 5px; padding-bottom: 10px;";
  48. print " background-color: ".$color->getHTMLcolor().";'";
  49. }
  50. print ">";
  51. // Get a string of our nodeIds
  52. $nodeId =$node->getId();
  53. // Break the path info into parts for the enviroment and parts that
  54. // designate which nodes to expand.
  55. $expandedNodes = explode("!", $harmoni->request->get('expanded_nodes'));
  56. print "\n\n<table>\n\t<tr><td valign='top'>";
  57. // Print The node
  58. eval('$hasChildren = '.$hasChildrenFunction.'($node);');
  59. if ($hasChildren) {
  60. ?>
  61.  
  62. <div style='
  63. border: 1px solid #000;
  64. width: 15px;
  65. height: 15px;
  66. text-align: center;
  67. text-decoration: none;
  68. font-weight: bold;
  69. '>
  70. <?php
  71. /**
  72. * @package polyphony.library.
  73. */
  74. // The child nodes are already expanded for this node.
  75. // Show option to collapse the list.
  76. if (in_array($nodeId->getIdString(), $expandedNodes)) {
  77. $newExpandedNodes = array_diff($expandedNodes,
  78. array($nodeId->getIdString()));
  79. $symbol = '-';
  80. $expanded = TRUE;
  81. // The node is not already expanded. Show option to expand.
  82. } else {
  83. $newExpandedNodes = array_merge($expandedNodes,
  84. array($nodeId->getIdString()));
  85. $symbol = '+';
  86. $expanded = FALSE;
  87. }
  88. $url =$harmoni->request->mkURLWithPassthrough();
  89. $url->setValue('expanded_nodes', implode('!', $newExpandedNodes));
  90. print "<a style='text-decoration: none;' href='".$url->write()."'>".$symbol."</a>";
  91. print "\n\t\t</div>";
  92. // Make a vertical line to connect to the line in front of the children
  93. if ($expanded) {
  94. print <<<END
  95. <div style='
  96. height: 100%;
  97. border-left: 1px #000 solid;
  98. margin-left: 10px;
  99. margin-right: 0px;
  100. margin-top:0px;
  101. '>&nbsp;</div>
  102. END;
  103. }
  104. // The node has no children. Do not show options to expand/collapse.
  105. } else {
  106. print "\n\t\t<div style='width: 15px;'>&nbsp;</div>";
  107. }
  108. print "\n\t</td><td valign='top'>\n\t\t";
  109. eval($printFunction.'( $node );');
  110. print "\n\t</td></tr>\n</table>";
  111. // Recursively print the children.
  112. if (in_array($nodeId->getIdString(), $expandedNodes)) {
  113. print <<<END
  114.  
  115. <div style='
  116. margin-left: 13px;
  117. margin-right: 0px;
  118. margin-top:0px;
  119. padding-left: 10px;
  120. border-left: 1px solid #000;
  121. END;
  122. print "'>";
  123. if ($color !== NULL) {
  124. $childColor =$color->replicate();
  125. $childColor->darken(20);
  126. } else {
  127. $childColor = NULL;
  128. }
  129. eval('$children = '.$getChildrenFunction.'($node);');
  130. foreach (array_keys($children) as $key) {
  131. HierarchyPrinter::printNode( $children[$key], $harmoni, $startingPathInfoKey, $printFunction, $hasChildrenFunction, $getChildrenFunction, $childColor );
  132. }
  133. print "\n</div>";
  134. }
  135. print "\n</div>";
  136. }
  137. }
  138.  
  139. ?>

Documentation generated on Wed, 19 Sep 2007 10:24:32 -0400 by phpDocumentor 1.3.0RC3