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 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. public function getRole($db, $role_name)
  34. {
  35. $role_list = $db->select('roles', "role_name=?", array($role_name));
  36. $roles = array();
  37. foreach ($role_list as $role)
  38. {
  39. if (!is_array($role))
  40. {
  41. $roles = array($role_list);
  42. break;
  43. }
  44. array_push($roles, $role);
  45. }
  46. return $roles;
  47. }
  48. public function getRoles($db)
  49. {
  50. $role_list = $db->select('roles', "1=?", array(1));
  51. $roles = array();
  52. foreach ($role_list as $role)
  53. {
  54. if (!is_array($role))
  55. {
  56. $roles = array($role_list);
  57. break;
  58. }
  59. array_push($roles, $role);
  60. }
  61. return $roles;
  62. }
  63. public function getRole($db, $role_name)
  64. {
  65. $role_list = $db->select('roles', "role_name=?", array($role_name));
  66. $roles = array();
  67. foreach ($role_list as $role)
  68. {
  69. if (!is_array($role))
  70. {
  71. $roles = array($role_list);
  72. break;
  73. }
  74. array_push($roles, $role);
  75. }
  76. return $roles;
  77. }
  78. }
  79. ?>