Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Role.class.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. class Role
  3. {
  4. protected $permissions;
  5. protected function __construct() {
  6. $this->permissions = array();
  7. }
  8. // return a role object with associated permissions
  9. public static function getRolePerms($role_id, $db)
  10. {
  11. $role = new Role();
  12. $perm_list = $db->select_raw("role_perm as rp JOIN permissions as p ON rp.perm_id = p.perm_id", "WHERE rp.role_id=?", array($role_id), "p.perm_name");
  13. $perms = array();
  14. foreach ($perm_list as $perm)
  15. {
  16. if (!is_array($perm))
  17. {
  18. $perms = array($perm_list);
  19. break;
  20. }
  21. array_push($perms, $perm);
  22. }
  23. foreach ($perms as $perm)
  24. {
  25. $role->permissions[$perm["perm_name"]] = true;
  26. }
  27. return $role;
  28. }
  29. // check if a permission is set
  30. public function hasPerm($permission) {
  31. return isset($this->permissions[$permission]);
  32. }
  33. // Get Role by Name
  34. public function getRole($db, $role_name)
  35. {
  36. $role_list = $db->select('roles', "role_name=?", array($role_name));
  37. $roles = array();
  38. foreach ($role_list as $role)
  39. {
  40. if (!is_array($role))
  41. {
  42. $roles = array($role_list);
  43. break;
  44. }
  45. array_push($roles, $role);
  46. }
  47. return $roles;
  48. }
  49. // Get all Roles
  50. public function getRoles($db)
  51. {
  52. $role_list = $db->select('roles', "1=?", array(1));
  53. $roles = array();
  54. foreach ($role_list as $role)
  55. {
  56. if (!is_array($role))
  57. {
  58. $roles = array($role_list);
  59. break;
  60. }
  61. array_push($roles, $role);
  62. }
  63. return $roles;
  64. }
  65. }
  66. ?>