/
AreaResponse.php
93 lines (79 loc) · 2.39 KB
/
AreaResponse.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\Response;
use Concrete\Core\Block\Block;
use Concrete\Core\Support\Facade\Application;
use Concrete\Core\User\User;
class AreaResponse extends Response
{
// legacy support
public function canRead()
{
return $this->validate('view_area');
}
public function canWrite()
{
return $this->validate('edit_area_contents');
}
public function canAdmin()
{
return $this->validate('edit_area_permissions');
}
public function canAddBlocks()
{
return $this->validate('add_block_to_area');
}
public function canAddStacks()
{
return $this->validate('add_stack_to_area');
}
public function canAddStack()
{
return $this->validate('add_stack_to_area');
}
public function canAddLayout()
{
return $this->validate('add_layout_to_area');
}
/**
* Check if a new block can be added to the area, or if an existing block can be moved to it.
*
* @param \Concrete\Core\Entity\Block\BlockType\BlockType|\Concrete\Core\Block\Block $blockTypeOrBlock specify a block type when adding a new block, a block instance when adding an existing block
*
* @return bool
*/
public function canAddBlock($blockTypeOrBlock)
{
if ($blockTypeOrBlock instanceof Block) {
$blockType = $blockTypeOrBlock->getBlockTypeObject();
} else {
$blockType = $blockTypeOrBlock;
}
switch ($blockType->getBlockTypeHandle()) {
case BLOCK_HANDLE_LAYOUT_PROXY:
return $this->canAddLayout();
case BLOCK_HANDLE_PAGE_TYPE_OUTPUT_PROXY:
return $this->canAddBlocks();
}
$pk = $this->category->getPermissionKeyByHandle('add_block_to_area');
$pk->setPermissionObject($this->object);
return $pk->validate($blockTypeOrBlock);
}
// convenience function
public function canViewAreaControls()
{
$app = Application::getFacadeApplication();
$u = $app->make(User::class);
if ($u->isSuperUser()) {
return true;
}
if (
$this->canEditAreaContents() ||
$this->canEditAreaPermissions() ||
$this->canAddBlockToArea() ||
$this->canAddStackToArea() ||
$this->canAddLayoutToArea()) {
return true;
}
return false;
}
}