Skip to content

Commit

Permalink
adding a toHTML() method to the navigation classes. Output should not…
Browse files Browse the repository at this point in the history
… be used without filtering
  • Loading branch information
SignpostMarv committed Apr 29, 2012
1 parent 51f3a46 commit 0345fa2
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions libAurora/Template/navigation.php
Expand Up @@ -49,7 +49,7 @@ public function query($parent, array $display){
}
$results = array_merge($results, $v->query($parent, $display));
}

return $results;
}

Expand All @@ -65,6 +65,17 @@ public function sort(){
$v->sort();
}
}


public function toHTML(array $display=null){
$doc = '<ul>';

foreach($this as $v){
$doc .= $v->toHTML($display);
}

return $doc . '</ul>';
}
}


Expand All @@ -89,7 +100,7 @@ protected function __construct($id, $rank, $url, $target, $display){
throw new InvalidArgumentException('Rank must be specified as float.');
}else if(is_integer($display) === false){
throw new InvalidArgumentException('Display must be specified as integer.');
}else if(is_string($url) === false){
}else if($url !== null && is_string($url) === false){
throw new InvalidArgumentException('URL must be specified as string.');
}else if(is_string($target) === false){
throw new InvalidArgumentException('Target must be specified as string.');
Expand Down Expand Up @@ -141,6 +152,28 @@ public function target(){
public function display(){
return $this->display;
}


public function toHTML(array $display=null){
$display = $display === null ? array(2) : $display;
if(in_array($this->display(), $display) === false){
return '';
}
$doc = '<li>';
if($this->url() !== null){
$doc .= '<a href="' . $this->url() . '"' . (trim($this->target()) === '' ? '' : ' target="' . $this->target() . '"') . '>' . $this->id(). '</a>';
}else{
$doc .= $this->id();
}
if($this->count() > 0){
$doc .= ' <ul>';
foreach($this as $v){
$doc .= $v->toHTML();
}
$doc .= '</ul>';
}
return $doc .= '</li>';
}
}
}
?>
?>

0 comments on commit 0345fa2

Please sign in to comment.