/
SubArea.php
144 lines (125 loc) · 3.72 KB
/
SubArea.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
namespace Concrete\Core\Area;
use Loader;
class SubArea extends Area
{
const AREA_SUB_DELIMITER = ' : ';
/**
* @var \Block
*/
protected $parentBlock;
/**
* @param \Block $block
*/
public function setSubAreaBlockObject($block)
{
$this->parentBlock = $block;
}
/**
* @param \Page $c
* @param string $arHandle
*
* @return Area
*/
public function create($c, $arHandle)
{
$db = Loader::db();
$db->Replace('Areas', array('cID' => $c->getCollectionID(), 'arHandle' => $arHandle, 'arParentID' => $this->arParentID), array('arHandle', 'cID'), true);
$this->refreshCache($c);
$area = self::get($c, $arHandle);
$area->rescanAreaPermissionsChain();
return $area;
}
/**
* @return bool|Area|mixed|null
*/
public function getSubAreaParentPermissionsObject()
{
$cache = \Core::make('cache/request');
$item = $cache->getItem(sprintf('subarea/parent/permissions/%s', $this->getAreaID()));
if (!$item->isMiss()) {
return $item->get();
}
$db = Loader::db();
$arParentID = $this->arParentID;
if ($arParentID == 0) {
return false;
}
while ($arParentID > 0) {
$row = $db->GetRow('select arID, arHandle, arParentID, arOverrideCollectionPermissions from Areas where arID = ?', array($arParentID));
$arParentID = $row['arParentID'];
if ($row['arOverrideCollectionPermissions']) {
break;
}
}
$a = Area::get($this->c, $row['arHandle']);
$cache->save($item->set($a));
return $a;
}
/**
* @return \Block
*/
public function getSubAreaBlockObject()
{
return $this->parentBlock;
}
/**
* @param string $arHandle
* @param string $arParentHandle
* @param int $arParentID
*/
public function __construct($arHandle, $arParentHandle, $arParentID)
{
$this->arParentID = $arParentID;
$arHandle = $arParentHandle . self::AREA_SUB_DELIMITER . $arHandle;
parent::__construct($arHandle);
}
/**
* @return int
*/
public function getAreaParentID()
{
return $this->arParentID;
}
public function getAreaCustomTemplates($include_parent_templates = true)
{
$these_templates = parent::getAreaCustomTemplates();
if ($include_parent_templates && $this->parentBlock && $this->parentBlock->a) {
// include parent templates if instructed to do so
$parent_templates = $this->parentBlock->a->getAreaCustomTemplates();
// make sure that parent templates can be overwritten by
// custom templates set on the subarea itself
return array_merge($parent_templates, $these_templates);
}
return $these_templates;
}
/**
* @param \SimpleXMLElement $p
* @param \Page $page
*/
public function export($p, $page)
{
$c = $this->getAreaCollectionObject();
$style = $c->getAreaCustomStyle($this);
if (is_object($style)) {
$set = $style->getStyleSet();
$set->export($p);
}
$blocks = $page->getBlocks($this->getAreaHandle());
foreach ($blocks as $bl) {
$bl->export($p);
}
}
public function delete()
{
$db = Loader::db();
$blocks = $this->getAreaBlocksArray();
foreach ($blocks as $b) {
$bp = new \Permissions($b);
if ($bp->canDeleteBlock()) {
$b->deleteBlock();
}
}
$db->Execute('delete from Areas where arID = ?', array($this->arID));
}
}