-
Notifications
You must be signed in to change notification settings - Fork 454
/
AddBlockBlockTypeKey.php
71 lines (65 loc) · 2.37 KB
/
AddBlockBlockTypeKey.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
<?php
namespace Concrete\Core\Permission\Key;
use Loader;
use Concrete\Core\User\User;
use Concrete\Core\Support\Facade\Application;
use PermissionKey;
use Concrete\Core\Permission\Duration as PermissionDuration;
class AddBlockBlockTypeKey extends BlockTypeKey
{
protected function getAllowedBlockTypeIDs()
{
$app = Application::getFacadeApplication();
$u = $app->make(User::class);
$pae = $this->getPermissionAccessObject();
if (!is_object($pae)) {
return array();
}
$accessEntities = $u->getUserAccessEntityObjects();
$accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
$list = $this->getAccessListItems(PermissionKey::ACCESS_TYPE_ALL, $accessEntities);
$list = PermissionDuration::filterByActive($list);
$db = Loader::db();
$btIDs = array();
if (count($list) > 0) {
$dsh = Loader::helper('concrete/dashboard');
if ($dsh->inDashboard()) {
$allBTIDs = $db->GetCol('select btID from BlockTypes');
} else {
$allBTIDs = $db->GetCol('select btID from BlockTypes where btIsInternal = 0');
}
foreach ($list as $l) {
switch ($l->getBlockTypesAllowedPermission()) {
case 'N':
$btIDs = array();
break;
case 'C':
if ($l->getAccessType() == PermissionKey::ACCESS_TYPE_EXCLUDE) {
$btIDs = array_values(array_diff($btIDs, $l->getBlockTypesAllowedArray()));
} else {
$btIDs = array_unique(array_merge($btIDs, $l->getBlockTypesAllowedArray()));
}
break;
case 'A':
$btIDs = $allBTIDs;
break;
}
}
}
return $btIDs;
}
public function validate($bt = false)
{
$app = Application::getFacadeApplication();
$u = $app->make(User::class);
if ($u->isSuperUser()) {
return true;
}
$types = $this->getAllowedBlockTypeIDs();
if ($bt != false) {
return in_array($bt->getBlockTypeID(), $types);
} else {
return count($types) > 0;
}
}
}