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

88 lines
2.4 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.
*
* @param id
*/
public function action_json($id=NULL,array $data=array()) {
2010-11-29 22:41:08 +00:00
// Get the user details
$id = (is_null($id) AND isset($_REQUEST['id'])) ? substr($_REQUEST['id'],2) : $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)
$modules = array_merge($modules,Module_Method::groupmodules($go->id));
2010-11-29 22:41:08 +00:00
ksort($modules);
2010-11-29 22:41:08 +00:00
$data = array();
foreach ($modules as $module => $details)
if (! $details['parent_id'])
array_push($data,
array('id'=>$details['id'],'name'=>$module,'state'=>'closed')
);
2010-11-29 22:41:08 +00:00
} else {
$module = preg_replace('/^N_/','',$id);
$methods = array();
foreach ($user->groups() as $go)
$methods = array_merge($methods,Module_Method::groupmethods($go->id,$module));
2010-11-29 22:41:08 +00:00
ksort($methods);
2010-11-29 22:41:08 +00:00
$data = array();
foreach ($methods as $method => $details) {
if (preg_match('/_/',$method)) {
list($mode,$action) = explode('_',$method);
$url = URL::site(sprintf('/%s/%s/%s',$mode,$details['module'],$action));
} else {
$url = URL::site(sprintf('/%s/%s',$details['module'],$method));
}
array_push($data,array(
'id'=>sprintf('%s_%s',$module,$details['id']),
'name'=>$method,
'state'=>'none',
'attr_id'=>sprintf('%s_%s',$module,$details['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
return parent::action_json($id,$data);
2010-11-29 22:41:08 +00:00
}
}
?>