-
Notifications
You must be signed in to change notification settings - Fork 453
/
Entity.php
93 lines (78 loc) · 2.37 KB
/
Entity.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace Concrete\Core\Permission\Access\Entity;
use Concrete\Core\Foundation\ConcreteObject;
use Database;
use Concrete\Core\Permission\Access\Access as PermissionAccess;
use CacheLocal;
use Core;
use RuntimeException;
abstract class Entity extends ConcreteObject
{
public function getAccessEntityTypeID()
{
return $this->petID;
}
public function getAccessEntityTypeObject()
{
return Type::getByID($this->petID);
}
public function getAccessEntityTypeHandle()
{
return $this->petHandle;
}
public function getAccessEntityID()
{
return $this->peID;
}
public function getAccessEntityLabel()
{
return $this->label;
}
abstract public function getAccessEntityUsers(PermissionAccess $pa);
abstract public function getAccessEntityTypeLinkHTML();
/**
* @param mixed $user
*
* @abstract
*/
public static function getAccessEntitiesForUser($user)
{
throw new RuntimeException('This method has not yet been implemented.');
}
public function validate(PermissionAccess $pae)
{
return true;
}
final public static function getByID($peID)
{
$obj = CacheLocal::getEntry('permission_access_entity', $peID);
if ($obj instanceof self) {
return $obj;
}
$db = Database::connection();
$r = $db->GetRow('select petID, peID from PermissionAccessEntities where peID = ?', array($peID));
if (is_array($r)) {
$pt = Type::getByID($r['petID']);
if (!is_object($pt)) {
return false;
}
$class = '\\Core\\Permission\\Access\\Entity\\' . Core::make('helper/text')->camelcase($pt->getAccessEntityTypeHandle()) . 'Entity';
$class = core_class($class, $pt->getPackageHandle());
$obj = Core::make($class);
$r['petHandle'] = $pt->getAccessEntityTypeHandle();
$obj->setPropertiesFromArray($r);
$obj->load();
}
CacheLocal::set('permission_access_entity', $peID, $obj);
return $obj;
}
public static function getForUser($user)
{
$entities = array();
$types = Type::getList();
foreach ($types as $t) {
$entities = array_merge($entities, $t->getAccessEntitiesForUser($user));
}
return $entities;
}
}