Not sure if i chose the best way to parameterize the SQL queries, but it seems
to be working for me.
// We retrieve the permissions from:
// 1.) All direct given permissions ($this->permissions)
// 2.) All direct given permissions to a role the user belongs
// 3.) All active memberships
public function getPermissions()
{
if (!Yum::hasModule('role') || !$this->id)
return array();
Yii::import('application.modules.role.models.*');
$roles = $this->roles;
$permissionTable = Yum::module('role')->permissionTable;
$actionTable = Yum::module('role')->actionTable;
if (Yum::hasModule('membership'))
$roles = array_merge($roles, $this->getActiveMemberships());
$permissions = array();
foreach ($roles as $role) {
$sql = "select id, a.title from {$permissionTable} as p left join {$actionTable} as a on a.id = p.action where type = 'role' and principal_id = {$role->id}";
foreach (Yii::app()->db->cache(500)->createCommand($sql)->query()->readAll() as $permission)
$permissions[$permission['id']] = $permission['title'];
}
// Direct user permission assignments
$sql = "select id, a.title from {$permissionTable} as p left join {$actionTable} as a on a.id = p.action where type = 'user' and principal_id = {$this->id}";
foreach (Yii::app()->db->cache(500)->createCommand($sql)->query()->readAll() as $permission)
$permissions[$permission['id']] = $permission['title'];
return $permissions;
}
Original issue reported on code.google.com by marc....@gmail.com on 2 Feb 2012 at 1:13
Original issue reported on code.google.com by
marc....@gmail.com
on 2 Feb 2012 at 1:13