1 |
<?php |
2 |
|
3 |
require_once("YakkaSerializableObject.php"); |
4 |
|
5 |
class YakkaPermitableObject extends YakkaSerializableObject { |
6 |
var $permissionStorage; |
7 |
|
8 |
function YakkaPermitableObject($id) { |
9 |
$$singleton = YAKKA_GLOBAL_SINGLETON; |
10 |
global $singleton; |
11 |
$this->permissionStorage = &$singleton->permissionStorage; |
12 |
|
13 |
$this->YakkaSerializableObject($id); |
14 |
} |
15 |
|
16 |
function allows($user, $privilege) { |
17 |
if ($this->hasUserGrants($user, $privilege)) |
18 |
return true; |
19 |
else |
20 |
return ($this->hasRoleGrants($user, $privilege) && !$this->hasRevokes($user, $privilege)); |
21 |
} |
22 |
|
23 |
function hasRoleGrants($user, $privilege) { |
24 |
if ($roles = $user->getRoles()) { |
25 |
while (list(,$role) = each($roles)) { |
26 |
if ($this->permissionStorage->hasGrantPrivilege($privilege, "?", $this->getType(), $role->getId(), $role->getType()) || $this->permissionStorage->hasGrantPrivilege($privilege, $this->getId(), $this->getType(), $role->getId(), $role->getType())) |
27 |
return true; |
28 |
} |
29 |
} |
30 |
|
31 |
return false; |
32 |
} |
33 |
|
34 |
function hasUserGrants($user, $privilege) { |
35 |
return ($this->permissionStorage->hasGrantPrivilege($privilege, "?", $this->getType(), $user->getId(), $user->getType())) || $this->permissionStorage->hasGrantPrivilege($privilege, $this->getId(), $this->getType(), $user->getId(), $user->getType()); |
36 |
} |
37 |
|
38 |
function hasRevokes($user, $privilege) { |
39 |
if ($roles = $user->getRoles()) { |
40 |
while (list(,$role) = each($roles)) { |
41 |
if ($this->permissionStorage->hasRevokePrivilege($privilege, $this->getId(), $this->getType(), $role->getId(), $role->getType())) |
42 |
return true; |
43 |
} |
44 |
} |
45 |
|
46 |
return $this->permissionStorage->hasRevokePrivilege($privilege, $this->getId(), $this->getType(), $user->getId(), $user->getType()); |
47 |
} |
48 |
|
49 |
function grant($user, $privilege) { |
50 |
return $this->permissionStorage->setGrantPrivilege($privilege, $this->getId(), $this->getType(), $user->getId(), $user->getType()); |
51 |
} |
52 |
|
53 |
function copyGrantsOf($source) { |
54 |
$this->permissionStorage->copyGrantPrivileges($source, $this->getType(), $this->getId(), $this->getType()); |
55 |
} |
56 |
|
57 |
function copyRevokesOf($source) { |
58 |
//$this->permissionStorage->copyRevokePrivileges($source, $this->getType(), $this->getId(), $this->getType()); |
59 |
} |
60 |
} |
61 |
|
62 |
?> |