Skip to content

Instantly share code, notes, and snippets.

@shadowhand
Created April 13, 2010 12:36
Show Gist options
  • Save shadowhand/364560 to your computer and use it in GitHub Desktop.
Save shadowhand/364560 to your computer and use it in GitHub Desktop.
<?php
$depth = 0;
echo '<ol class="tree">';
foreach ($children as $i => $child)
{
// Get the last and next nodes
$last = isset($children[$i-1]) ? $children[$i-1] : $children[0];
$next = isset($children[$i+1]) ? $children[$i+1] : $children[0];
if ($child->lvl > $last->lvl)
{
// Increasing depth, start a new list
echo '<ol class="d', $child->lvl, '">';
}
// Start the line
echo "\n", str_repeat("\t", $child->lvl + 1), "<li>";
// Create a link to the user details
$line = html::anchor('users/view/details/'.$child->id, $child->name ? $child->name : $child->username);
if ($child->lvl < 1)
{
// This user is the start of a network
$line = "<strong>{$line}</strong>";
}
// Display the affiliates name and current credit
echo $line;
if ($next->lvl <= $child->lvl)
{
// Next node has the same depth or less, end this line
echo "</li>";
}
if ($next->lvl < $child->lvl)
{
// Calculate the amount of change
$change = $child->lvl - $next->lvl;
while ($change > 0)
{
// Decreasing depth
$change--;
echo "\n", str_repeat("\t", $child->lvl + $change), "</ol></li>";
}
}
}
echo "\n</ol>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment