Guest User

Untitled

a guest
May 17th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <?php
  2. class Example_ACL
  3. {
  4. public static function getActionValue($actionString)
  5. {
  6. switch ($actionString)
  7. {
  8. case 'none':
  9. return 0;
  10. break;
  11. case 'view':
  12. return 1;
  13. break;
  14. case 'create':
  15. return 2;
  16. break;
  17. case 'edit':
  18. return 3;
  19. break;
  20. case 'status':
  21. return 4;
  22. break;
  23. case 'delete':
  24. return 5;
  25. break;
  26. default:
  27. throw new Exception("Unknown Action", 500);
  28. }
  29. }
  30. public static function isAllowed(Example_Account_Record $user, $object, $action)
  31. {
  32. if (!in_array('Example_Permissionable', class_implements($object))) {
  33. throw new Exception('That class is not permissionable', 500);
  34. }
  35.  
  36. $action = self::getActionValue($action);
  37.  
  38. $method = "getNonOwnerPermission";
  39. if ($user->id == $object->owner_id) {
  40. $method= "getOwnerPermission";
  41. }
  42.  
  43. $permission = 0;
  44.  
  45. foreach($user->getGroups() as $group) {
  46. if ($groupPermission = $group->$method($object->getPermissionableClass(), $object->getScope($user)) >= $action) {
  47. return true;
  48. }
  49. }
  50.  
  51. return false;
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment