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/controller/tree.php

93 lines
2.7 KiB
PHP
Raw Normal View History

2010-11-29 22:41:08 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class extends renders OSB menu tree.
*
* @package lnApp
* @subpackage Tree
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Tree extends Controller_lnApp_Tree {
protected $auth_required = TRUE;
/**
* Draw the Tree Menu
*
* The incoming ID is either a Branch B_x or a Node N_x
* Where X is actually the module.
*
2011-09-24 13:13:38 +00:00
* @param array $data Tree data passed in by inherited methods
2010-11-29 22:41:08 +00:00
*/
2011-09-24 13:13:38 +00:00
public function action_json(array $data=array()) {
2010-11-29 22:41:08 +00:00
// Get the user details
2011-09-24 13:13:38 +00:00
$id = (is_null($this->request->param('id')) AND isset($_REQUEST['id'])) ? substr($_REQUEST['id'],2) : $this->request->param('id');
2010-11-29 22:41:08 +00:00
$user = Auth::instance()->get_user();
if ($user) {
if (! $id) {
$modules = array();
foreach ($user->groups() as $go)
2011-09-24 13:13:38 +00:00
foreach ($go->list_parentgrps(TRUE) as $cgo)
foreach ($cgo->module_method->find_all() as $mmo)
if ($mmo->menu_display AND empty($modules[$mmo->module_id]))
$modules[$mmo->module_id] = $mmo->module;
2010-11-29 22:41:08 +00:00
2011-09-24 13:13:38 +00:00
Sort::masort($modules,'name');
2010-11-29 22:41:08 +00:00
2011-09-24 13:13:38 +00:00
foreach ($modules as $id => $mo)
if (! $mo->parent_id)
array_push($data,array('id'=>$id,'name'=>$mo->name,'state'=>'closed'));
2010-11-29 22:41:08 +00:00
} else {
2011-09-24 13:13:38 +00:00
$mo = ORM::factory('module',$id);
$methods = array();
2011-09-24 13:13:38 +00:00
if ($mo->loaded()) {
foreach ($mo->module_method->find_all() as $mmo)
if ($mmo->menu_display)
foreach ($mmo->group->find_all() as $gmo)
if ($user->has_any('group',$gmo->list_childgrps(TRUE)))
$methods[$mmo->id] = $mmo;
2010-11-29 22:41:08 +00:00
2011-09-24 13:13:38 +00:00
Sort::masort($modules,'name');
2010-11-29 22:41:08 +00:00
2011-09-24 13:13:38 +00:00
foreach ($methods as $id => $mmo) {
if (preg_match('/_/',$mmo->name)) {
list($mode,$action) = explode('_',$mmo->name);
$url = URL::site(sprintf('/%s/%s/%s',$mode,$mmo->module->name,$action));
} else {
$url = URL::site(sprintf('/%s/%s',$mmo->module->name,$mmo->name));
}
2011-09-24 13:13:38 +00:00
array_push($data,array(
'id'=>sprintf('%s_%s',$mmo->module_id,$id),
'name'=>$mmo->name,
'state'=>'none',
'attr_id'=>sprintf('%s_%s',$mmo->module->name,$id),
'attr_href'=>(empty($details['page']) ? $url : $details['page'])
));
}
2010-11-29 22:41:08 +00:00
}
}
}
2011-05-14 07:35:33 +00:00
$this->output = array();
2010-11-29 22:41:08 +00:00
foreach ($data as $branch) {
2011-05-14 07:35:33 +00:00
array_push($this->output,array(
2010-11-29 22:41:08 +00:00
'attr'=>array('id'=>sprintf('B_%s',$branch['id'])),
'state'=>$branch['state'],
'data'=>array('title'=>$branch['name']),
'attr'=>array('id'=>sprintf('N_%s',$branch['id']),'href'=>empty($branch['attr_href']) ? URL::site(sprintf('/%s/menu',$branch['name'])) : $branch['attr_href']),
)
);
}
2011-07-13 22:59:32 +00:00
2011-09-24 13:13:38 +00:00
return parent::action_json($data);
2010-11-29 22:41:08 +00:00
}
}
?>