This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
lnapp/classes/lnApp/Menu.php
2014-10-22 11:36:01 +11:00

73 lines
2.0 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is used to create our Menu/Navbars
*
* @package lnApp
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnApp_Menu {
public static function items($type,array $list=array()) {
$result = array();
if (empty(URL::$method_directory[$type]))
return NULL;
if (! $list)
$list = Kohana::list_files('classes/Controller/'.ucfirst($type));
// This will be used a lot!
$ext_length = strlen(EXT);
foreach ($list as $name => $path)
if (is_array($path)) {
$result += self::items($type,$path);
} elseif (substr($name, -$ext_length) === EXT) {
// Remove "classes/" and the extension
$class = substr($name, 8, -$ext_length);
// Convert slashes to underscores
$class = str_replace(DIRECTORY_SEPARATOR, '_', $class);
if (method_exists($class,'menu')) {
$cat = strtolower(str_replace('Controller_'.ucfirst($type).'_','',$class));
foreach ($class::menu() as $k=>$v)
$result[$cat][$k] = $v;
}
}
return $result;
}
public static function mainnav() {
return Kohana::$config->load('mainnav');
}
public static function ul($type,array $result,array $append=NULL,$sub=FALSE,$method=NULL) {
$output = $sub ? '<ul class="dropdown-menu">' : '<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">';
foreach ($result as $k => $v)
if (is_array($v))
$output .= sprintf('<li class="dropdown-submenu">%s%s',HTML::anchor('#',$k,array('nocg'=>TRUE)),self::ul($type,$v,NULL,TRUE,$k).'</li>');
else
$output .= '<li>'.HTML::anchor(URL::$method_directory[$type].'/'.$method.'/'.$k,$v,array('tabindex'=>-1,'nocg'=>TRUE)).'</li>';
if ($append) {
$output .= '<li class="divider"></li>';
foreach ($append as $k => $v)
$output .= sprintf('<li>%s</li>',HTML::anchor($k,$v,array('nocg'=>TRUE)));
}
$output .= '</ul>';
return $output;
}
}
?>