/
PresetLayout.php
114 lines (97 loc) · 2.82 KB
/
PresetLayout.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
<?php
namespace Concrete\Core\Area\Layout;
use Concrete\Core\Area\Layout\Preset\PresetInterface;
use Loader;
use Core;
class PresetLayout extends Layout
{
/**
* @var string
*/
protected $arLayoutType = 'preset';
/**
* @var int
*/
public $arLayoutID;
/**
* @var bool
*/
public $arLayoutIsPreset = true;
/**
* @var string
*/
protected $preset;
protected $presetObject;
protected function loadDetails()
{
$db = Loader::db();
$row = $db->GetRow('select preset from AreaLayoutsUsingPresets where arLayoutID = ?', array($this->arLayoutID));
$this->setPropertiesFromArray($row);
}
public function getPresetObject()
{
if (!isset($this->presetObject)) {
$manager = Core::make('manager/area_layout_preset_provider');
$this->presetObject = $manager->getPresetByIdentifier($this->preset);
}
return $this->presetObject;
}
protected function loadColumnNumber()
{
$preset = $this->getPresetObject();
if (is_object($preset)) {
$this->arLayoutNumColumns = count($preset->getColumns());
}
}
/**
* @return string
*/
public function getAreaLayoutPresetHandle()
{
return $this->preset;
}
/**
* @param \SimpleXMLElement $node
*/
public function exportDetails($node)
{
$node->addAttribute('type', 'preset');
$node->addAttribute('preset-id', $this->preset);
}
/**
* @return PresetLayout
*/
public function duplicate()
{
$db = Loader::db();
$v = array($this->arLayoutIsPreset);
$db->Execute('insert into AreaLayouts (arLayoutIsPreset) values (?)', $v);
$newAreaLayoutID = $db->Insert_ID();
if ($newAreaLayoutID) {
$v = array($newAreaLayoutID, $this->getAreaLayoutPresetHandle());
$db->Execute('insert into AreaLayoutsUsingPresets (arLayoutID, preset) values (?, ?)', $v);
$newAreaLayout = Layout::getByID($newAreaLayoutID);
$columns = $this->getAreaLayoutColumns();
foreach ($columns as $col) {
$col->duplicate($newAreaLayout);
}
return $newAreaLayout;
}
}
/**
* @param PresetInterface $preset
*
* @return PresetLayout
*/
public static function add(PresetInterface $preset)
{
$db = Loader::db();
$db->Execute('insert into AreaLayouts (arLayoutIsPreset) values (?)', array(1));
$arLayoutID = $db->Insert_ID();
if ($arLayoutID) {
$db->Execute('insert into AreaLayoutsUsingPresets (arLayoutID, preset) values (?, ?)', array($arLayoutID, $preset->getIdentifier()));
$ar = static::getByID($arLayoutID);
return $ar;
}
}
}