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.
khosb/application/classes/Menu.php
2013-05-02 20:50:20 +10:00

72 lines
1.8 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is used to create our Menu/Navbars
*
* @package OSB
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Menu {
public static function items($type) {
$result = array();
if (empty(URL::$method_directory[$type]))
return NULL;
$uo = Auth::instance()->get_user();
foreach ($uo->methods() as $mmo)
if ($mmo->menu_display AND preg_match('/^'.$type.'_/',$mmo->name))
if (empty($result[$mmo->id]))
$result[$mmo->id] = $mmo;
return static::collapse($result);
}
private static function collapse(array $array) {
$result = array();
foreach ($array as $item) {
if (isset($result[$item->module->name])) {
if (! is_array($result[$item->module->name]))
$result[$item->module->name] = array($result[$item->module->name]);
array_push($result[$item->module->name],$item);
continue;
} else {
$result[$item->module->name] = $item;
}
}
return $result;
}
public static function ul(array $result,array $append=NULL,$sub=FALSE) {
$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)),static::ul($v,NULL,TRUE).'</li>');
} else
$output .= '<li>'.HTML::anchor($v->url(),$v->menu_display(),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;
}
}
?>