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.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. $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. foreach ($results as $result)
  14. {
  15. $role->permissions[$result["perm_name"]] = true;
  16. }
  17. return $role;
  18. }
  19. // check if a permission is set
  20. public function hasPerm($permission) {
  21. return isset($this->permissions[$permission]);
  22. }
  23. public function getRoles()
  24. {
  25. $role_list = $db->select('roles', "1=?", array(1));
  26. $roles = array();
  27. foreach ($role_list as $role)
  28. {
  29. if (!is_array($role))
  30. {
  31. $roles = array($role_list);
  32. break;
  33. }
  34. array_push($roles, $role);
  35. }
  36. return $roles;
  37. }
  38. }
  39. ?>