2013-04-26 01:42:09 +00:00
|
|
|
<?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();
|
|
|
|
|
2013-06-04 11:50:41 +00:00
|
|
|
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
|
|
|
|
2013-06-04 11:50:41 +00:00
|
|
|
array_push($result[$mmo->module->name],$mmo);
|
2013-05-02 09:52:19 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
} else {
|
2013-06-04 11:50:41 +00:00
|
|
|
$result[$mmo->module->name] = $mmo;
|
2013-05-02 09:52:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-26 01:42:09 +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;
|
|
|
|
|
2013-06-04 11:50:41 +00:00
|
|
|
$ao = Auth::instance()->get_user();
|
2013-05-10 10:48:10 +00:00
|
|
|
|
2013-06-04 11:50:41 +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;
|
|
|
|
|
2013-12-19 23:00:32 +00:00
|
|
|
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))
|
2013-12-19 23:00:32 +00:00
|
|
|
$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;
|
|
|
|
}
|
2013-04-26 01:42:09 +00:00
|
|
|
}
|
|
|
|
?>
|