
Untitled
By: a guest on
May 17th, 2012 | syntax:
None | size: 1.42 KB | hits: 14 | expires: Never
<?php
class Example_ACL
{
public static function getActionValue($actionString)
{
switch ($actionString)
{
case 'none':
return 0;
break;
case 'view':
return 1;
break;
case 'create':
return 2;
break;
case 'edit':
return 3;
break;
case 'status':
return 4;
break;
case 'delete':
return 5;
break;
default:
throw new Exception("Unknown Action", 500);
}
}
public static function isAllowed(Example_Account_Record $user, $object, $action)
{
if (!in_array('Example_Permissionable', class_implements($object))) {
throw new Exception('That class is not permissionable', 500);
}
$action = self::getActionValue($action);
$method = "getNonOwnerPermission";
if ($user->id == $object->owner_id) {
$method= "getOwnerPermission";
}
$permission = 0;
foreach($user->getGroups() as $group) {
if ($groupPermission = $group->$method($object->getPermissionableClass(), $object->getScope($user)) >= $action) {
return true;
}
}
return false;
}
}