//main.php { Main//Main }
<?php
class Main extends Controller_Hybrid
{
static $_log;
static $_resource = array();
static $_user;
function before ()
{
parent::before();
(string)self::$_resource['controller'] = Request::main()->route->controller;
(string)self::$_resource['method'] = Request::main()->action;
self::$_user = \Auth::get_user_id();
self::has_access();
}
public static function has_access ()
{
if ( !DbAcl::has_access( self::$_resource['controller'], self::$_resource['method'], self::get_role_name() ) )
{
echo "Plop :D";
}
}
// This should be added in the DbAcl package
public static function get_role_name($id = null)
{
$user = \Auth::get_user_id();
($id) ? $id = $id : $id = $user[1];
$user_role = \DB::select()
->from( \Config::get('dbacl.table.users_groups', 'dbacl_user_group') )
->where( 'user_id', $id )
->execute(\Config::get('dbacl.connection', null))->current();
if (\DB::count_last_query() > 0)
{
$group_permission = \DB::select('role_id')
->from( \Config::get('dbacl.table.groups_permissions', 'dbacl_group_permission') )
->where('group_id', $user_role['group_id'])
->execute(\Config::get('dbacl.connection', null))->current();
}
if (\DB::count_last_query() > 0)
{
$role = \DB::select('name')
->from( \Config::get('dbacl.table.roles', 'dbacl_role') )
->where('id', $group_permission['role_id'])
->execute(\Config::get('dbacl.connection', null))->current();
}
if (\DB::count_last_query() > 0)
{
$result = $role['name'];
}
else
{
$result = false;
}
return $result;
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!