Created
April 13, 2010 12:36
-
-
Save shadowhand/364560 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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