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

72 lines
1.8 KiB
PHP
Raw Normal View History

<?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 {
2013-05-02 09:52:19 +00:00
private static function collapse(array $array) {
$result = array();
foreach ($array as $mmo) {
if (isset($result[$mmo->module->name])) {
if (! is_array($result[$mmo->module->name]))
$result[$mmo->module->name] = array($result[$mmo->module->name]);
2013-05-02 09:52:19 +00:00
array_push($result[$mmo->module->name],$mmo);
2013-05-02 09:52:19 +00:00
continue;
} else {
$result[$mmo->module->name] = $mmo;
2013-05-02 09:52:19 +00:00
}
}
return $result;
}
2013-05-02 09:52:19 +00:00
2013-05-10 10:48:10 +00:00
public static function items($type) {
$result = array();
if (empty(URL::$method_directory[$type]))
return NULL;
$ao = Auth::instance()->get_user();
2013-05-10 10:48:10 +00:00
foreach ($ao->methods() as $mmo)
if ($mmo->menu_display AND $type == $mmo->directory())
2013-05-10 10:48:10 +00:00
if (empty($result[$mmo->id]))
$result[$mmo->id] = $mmo;
return self::collapse($result);
2013-05-10 10:48:10 +00:00
}
2013-05-02 09:52:19 +00:00
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)
2014-01-23 13:20:48 +00:00
if (is_array($v))
$output .= sprintf('<li class="dropdown-submenu">%s%s',HTML::anchor('#',$k,array('nocg'=>TRUE)),self::ul($v,NULL,TRUE).'</li>');
2014-01-23 13:20:48 +00:00
else
2013-05-02 09:52:19 +00:00
$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;
}
}
?>