FEATURE: allow 3 levels of navigation for the module. _getModulePages() should in theory support any depth of pages

This commit is contained in:
Will Rossiter 2010-10-22 03:46:44 +00:00
parent 1a5c88b469
commit ef7c095533
2 changed files with 50 additions and 18 deletions

View File

@ -382,24 +382,9 @@ class DocumentationViewer extends Controller {
if($page->Title != "Index") $linkParts[] = $page->Filename;
$page->Link = $this->Link($linkParts);
$page->LinkingMode = 'link';
$page->Children = false;
if(isset($this->Remaining[0])) {
if(strtolower($this->Remaining[0]) == $page->Filename) {
$page->LinkingMode = 'current';
if(is_dir($page->Path)) {
$children = DocumentationParser::get_pages_from_folder($page->Path);
foreach($children as $child) {
$child->Link = $this->Link(array($this->Remaining[0], $child->Filename));
}
$page->Children = $children;
}
}
}
$page->Children = $this->_getModulePagesNested($page);
}
}
@ -409,6 +394,45 @@ class DocumentationViewer extends Controller {
return false;
}
/**
* Get the module pages under a given page. Recursive call for {@link getModulePages()}
*
* @param ArrayData CurrentPage
* @param int Depth of page in the tree
*
* @return DataObjectSet|false
*/
private function _getModulePagesNested(&$page, $level = 0) {
// only support 2 more levels
if(isset($this->Remaining[$level])) {
if(strtolower($this->Remaining[$level]) == $page->Filename) {
// its either in this section or is the actual link
$page->LinkingMode = (isset($this->Remaining[$level + 1])) ? 'section' : 'current';
if(is_dir($page->Path)) {
$children = DocumentationParser::get_pages_from_folder($page->Path);
$segments = array();
for($x = 0; $x <= $level; $x++) {
$segments[] = $this->Remaining[$x];
}
foreach($children as $child) {
$child->Link = $this->Link(array_merge($segments, array($child->Filename)));
$child->LinkingMode = 'link';
$child->Children = $this->_getModulePagesNested($child, $level + 1);
}
return $children;
}
}
}
return false;
}
/**
* Return the content for the page. If its an actual documentation page then
* display the content from the page, otherwise display the contents from

View File

@ -8,7 +8,15 @@
<% if Children %>
<ul>
<% control Children %>
<li><a href="$Link" class="$LinkingMode">$Title</a></li>
<li><a href="$Link" class="$LinkingMode">$Title</a>
<% if Children %>
<ul>
<% control Children %>
<li><a href="$Link" class="$LinkingMode">$Title</a></li>
<% end_control %>
</ul>
<% end_if %>
</li>
<% end_control %>
</ul>
<% end_if %>