Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Role.class.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 = $db->select('roles', "role_name=? LIMIT 1", array($role_name));
  37. return $role;
  38. }
  39. // Get all Roles
  40. public function getRoles($db)
  41. {
  42. $role_list = $db->select('roles', "1=?", array(1));
  43. $roles = array();
  44. foreach ($role_list as $role)
  45. {
  46. if (!is_array($role))
  47. {
  48. $roles = array($role_list);
  49. break;
  50. }
  51. array_push($roles, $role);
  52. }
  53. return $roles;
  54. }
  55. }
  56. ?>