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.
lnauth/classes/lnAuth/Menu.php

80 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2014-09-29 05:15:49 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is used to create our Menu/Navbars
*
* @package lnAuth
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnAuth_Menu extends lnApp_Menu {
private static function collapse(array $array) {
$result = array();
foreach ($array as $mmo) {
if (! is_object($mmo)) {
$result[0] = $mmo;
continue;
}
if (isset($result[$mmo->module->name])) {
if (! is_array($result[$mmo->module->name]))
$result[$mmo->module->name] = array($result[$mmo->module->name]);
array_push($result[$mmo->module->name],$mmo);
continue;
} else {
$result[$mmo->module->name] = $mmo;
}
}
return $result;
}
2014-09-29 07:30:54 +00:00
public static function items($type,array $list=array()) {
2014-09-29 05:15:49 +00:00
$result = array();
if (empty(URL::$method_directory[$type]))
return NULL;
$ao = Auth::instance()->get_user();
if (! $ao->loaded())
return FALSE;
2016-08-25 13:23:25 +00:00
if (is_object($ao))
foreach ($ao->methods() as $mmo)
if ($mmo->menu_display AND $type == $mmo->directory())
if (empty($result[$mmo->id]))
$result[$mmo->id] = $mmo;
2014-09-29 05:15:49 +00:00
return self::collapse($result);
}
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).'</li>');
else
2016-08-25 13:23:25 +00:00
$output .= '<li>'.HTML::anchor($v->url(),$v->menu_display(),array('tabindex'=>-1,'nocg'=>TRUE)).'</li>';
2014-09-29 05:15:49 +00:00
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;
}
}
?>