sfPropelActAsNestedSetBehaviorUtils.class.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /*
  3. * This file is part of the sfPropelActAsNestedSetBehavior package.
  4. *
  5. * (c) 2006-2007 Tristan Rivoallan <tristan@rivoallan.net>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * Helper functions for working with nested sets.
  12. */
  13. class sfPropelActAsNestedSetBehaviorUtils
  14. {
  15. /**
  16. * Dumps tree below given node.
  17. *
  18. * @param BaseObject $root_node
  19. * @param string $indent_string
  20. * @param string $display_method
  21. */
  22. public static function dumpTree(BaseObject $root_node, $indent_string = "\t", $display_method = '__toString')
  23. {
  24. $tree_repr = array((string)$root_node);
  25. foreach ($root_node->getDescendants() as $node)
  26. {
  27. if (method_exists($node, $display_method))
  28. {
  29. $node_repr = $node->$display_method();
  30. }
  31. else
  32. {
  33. $node_repr = (string)$node;
  34. }
  35. $tree_repr[] = sprintf("%s%s", str_repeat($indent_string, $node->getLevel()), $node_repr);
  36. }
  37. return implode("\n", $tree_repr);
  38. }
  39. }