Enhancements to group handling
This commit is contained in:
@@ -81,9 +81,9 @@ $(function () {
|
||||
* The incoming ID is either a Branch B_x or a Node N_x
|
||||
* Where X is actually the module.
|
||||
*
|
||||
* @param id
|
||||
* @param array $data Tree data passed in by inherited methods
|
||||
*/
|
||||
public function action_json($id=null,array $data=array()) {
|
||||
public function action_json(array $data=array()) {
|
||||
if ($this->_auth_required() AND ! Auth::instance()->logged_in()) {
|
||||
$this->output = array('attr'=>array('id'=>'a_login'),
|
||||
'data'=>array('title'=>_('Please Login').'...','attr'=>array('id'=>'N_login','href'=>URL::site('/login'))));
|
||||
|
@@ -19,52 +19,57 @@ class Controller_Tree extends Controller_lnApp_Tree {
|
||||
* The incoming ID is either a Branch B_x or a Node N_x
|
||||
* Where X is actually the module.
|
||||
*
|
||||
* @param id
|
||||
* @param array $data Tree data passed in by inherited methods
|
||||
*/
|
||||
public function action_json($id=NULL,array $data=array()) {
|
||||
public function action_json(array $data=array()) {
|
||||
// Get the user details
|
||||
$id = (is_null($id) AND isset($_REQUEST['id'])) ? substr($_REQUEST['id'],2) : $id;
|
||||
$id = (is_null($this->request->param('id')) AND isset($_REQUEST['id'])) ? substr($_REQUEST['id'],2) : $this->request->param('id');
|
||||
$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));
|
||||
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;
|
||||
|
||||
ksort($modules);
|
||||
Sort::masort($modules,'name');
|
||||
|
||||
$data = array();
|
||||
foreach ($modules as $module => $details)
|
||||
if (! $details['parent_id'])
|
||||
array_push($data,
|
||||
array('id'=>$details['id'],'name'=>$module,'state'=>'closed')
|
||||
);
|
||||
foreach ($modules as $id => $mo)
|
||||
if (! $mo->parent_id)
|
||||
array_push($data,array('id'=>$id,'name'=>$mo->name,'state'=>'closed'));
|
||||
|
||||
} else {
|
||||
$module = preg_replace('/^N_/','',$id);
|
||||
$mo = ORM::factory('module',$id);
|
||||
|
||||
$methods = array();
|
||||
foreach ($user->groups() as $go)
|
||||
$methods = array_merge($methods,Module_Method::groupmethods($go->id,$module));
|
||||
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;
|
||||
|
||||
ksort($methods);
|
||||
Sort::masort($modules,'name');
|
||||
|
||||
$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));
|
||||
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));
|
||||
}
|
||||
|
||||
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'])
|
||||
));
|
||||
}
|
||||
|
||||
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'])
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,7 +86,7 @@ class Controller_Tree extends Controller_lnApp_Tree {
|
||||
);
|
||||
}
|
||||
|
||||
return parent::action_json($id,$data);
|
||||
return parent::action_json($data);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -1,53 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides access to module configuration.
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Module
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Module_Method {
|
||||
/**
|
||||
* Display the modules available for a group
|
||||
*/
|
||||
public static function groupmodules($gid) {
|
||||
$modules = array();
|
||||
// @todo the database prefix needs to be added to this query
|
||||
$query = DB::query(Database::SELECT,'SELECT A.name AS module,A.id AS MOD_ID,B.name AS parent,B.id AS PARENT_ID FROM ab_module A LEFT JOIN ab_module B ON (A.parent_id=B.id AND A.site_id=B.site_id), ab_module_method C, ab_group_method D WHERE A.id=C.module_id AND A.site_id=C.site_id AND D.method_id=C.id AND D.site_id=C.site_id AND D.group_id=:gid AND A.menu_display=1 AND A.site_id=:siteid GROUP BY module')
|
||||
->param(':siteid',Config::siteid())
|
||||
->param(':gid',$gid);
|
||||
|
||||
foreach ($query->execute() as $record) {
|
||||
$modules[$record['module']]['id'] = $record['MOD_ID'];
|
||||
$modules[$record['module']]['parent_id'] = $record['PARENT_ID'];
|
||||
$modules[$record['module']]['parent'] = $record['parent'];
|
||||
}
|
||||
|
||||
return $modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the methods available for a group
|
||||
*/
|
||||
public static function groupmethods($gid,$mid) {
|
||||
$methods = array();
|
||||
// @todo the database prefix needs to be added to this query
|
||||
$query = DB::query(Database::SELECT,'SELECT C.id,C.name AS METHOD,A.name AS MODULE,C.page FROM ab_module A, ab_module_method C, ab_group_method D WHERE A.id=C.module_id AND A.site_id=C.site_id AND D.method_id=C.id AND D.site_id=C.site_id AND D.group_id=:gid AND C.module_id=:mid AND C.menu_display=1 AND A.site_id=:siteid')
|
||||
->param(':siteid',Config::siteid())
|
||||
->param(':gid',$gid)
|
||||
->param(':mid',$mid);
|
||||
|
||||
foreach ($query->execute() as $record) {
|
||||
$methods[$record['METHOD']]['id'] = $record['id'];
|
||||
$methods[$record['METHOD']]['page'] = $record['page'];
|
||||
$methods[$record['METHOD']]['module'] = $record['MODULE'];
|
||||
}
|
||||
|
||||
return $methods;
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user