diff --git a/.gitignore b/.gitignore index 477de25..55daa53 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ *phprbac.sqlite3* *Doxygen* *phpdoc* -index.php \ No newline at end of file +index.php +.idea/ diff --git a/PhpRbac/src/PhpRbac/core/lib/rbac.php b/PhpRbac/src/PhpRbac/core/lib/rbac.php index 9c2dc3e..f61563e 100644 --- a/PhpRbac/src/PhpRbac/core/lib/rbac.php +++ b/PhpRbac/src/PhpRbac/core/lib/rbac.php @@ -1071,7 +1071,27 @@ function allRoles($UserID = null) WHERE TRel.UserID=?", $UserID ); } - /** + /** + * @param null $UserID + * @return array|int|null + * @throws RbacRoleNotFoundException + * @throws RbacUserNotProvidedException + */ + function allPermissions($UserID = null) + { + if ($UserID === null) + throw new \RbacUserNotProvidedException ("\$UserID is a required argument."); + + $Role = Jf::sql ( "SELECT RoleID FROM {$this->tablePrefix()}userroles as ur , {$this->tablePrefix()}roles as r WHERE ur.roleid = r.id and UserID=? limit 1", $UserID ); + if (!$Role) + throw new \RbacRoleNotFoundException("User`s Role not found."); + else + $permissions = Jf::sql ( "SELECT R.* FROM {$this->tablePrefix()}rolepermissions as RP ,{$this->tablePrefix()}permissions as P WHERE roleID=? and RP.PermissionID = P.ID", $Role['RoleID'] ); + return $permissions ? $permissions : array(); + + } + + /** * Return count of roles assigned to a user * * @param integer $UserID