-
Notifications
You must be signed in to change notification settings - Fork 451
/
presets.php
91 lines (79 loc) · 2.99 KB
/
presets.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
<?php
namespace Concrete\Controller\Dialog\Area\Layout;
use Concrete\Controller\Backend\UserInterface as BackendInterfaceController;
use Concrete\Core\Page\EditResponse;
use PermissionKey;
use Exception;
use Request;
use Concrete\Core\Area\Layout\Preset\Preset;
use Concrete\Core\Area\Layout\Preset\UserPreset;
use Concrete\Core\Area\Layout\Layout as AreaLayout;
class Presets extends BackendInterfaceController
{
protected $viewPath = '/dialogs/area/layout/presets';
protected function canAccess()
{
$pk = PermissionKey::getByHandle('manage_layout_presets');
return $pk->validate();
}
public function view($arLayoutID)
{
$arLayout = AreaLayout::getByID($arLayoutID);
if (!is_object($arLayout)) {
throw new Exception(t('Invalid layout object.'));
}
$presetlist = UserPreset::getList();
$presets = array();
$presets['-1'] = t('** New');
foreach ($presetlist as $preset) {
$presets[$preset->getAreaLayoutPresetID()] = h($preset->getAreaLayoutPresetName());
}
$this->set('arLayout', $arLayout);
$this->set('presets', $presets);
}
public function getPresetData($cID, $arLayoutPresetID)
{
$c = \Page::getByID($cID, 'ACTIVE');
$r = Request::getInstance();
$r->setCurrentPage($c);
$existingPreset = Preset::getByID($arLayoutPresetID);
if (is_object($existingPreset)) {
$r = new \stdClass();
$formatter = $existingPreset->getFormatter();
$container = $formatter->getPresetContainerHtmlObject();
foreach ($existingPreset->getColumns() as $column) {
$html = $column->getColumnHtmlObjectEditMode();
$container->appendChild($html);
}
$r->id = $arLayoutPresetID;
$r->html = (string) $container;
\Core::make('helper/ajax')->sendResult($r);
}
}
public function submit($arLayoutID)
{
if ($this->validateAction()) {
$existingPreset = null;
$arLayout = AreaLayout::getByID($arLayoutID);
if (!is_object($arLayout)) {
throw new Exception(t('Invalid layout object.'));
}
if ($_POST['arLayoutPresetID'] == '-1') {
UserPreset::add($arLayout, $_POST['arLayoutPresetName']);
} else {
$existingPreset = UserPreset::getByID($_POST['arLayoutPresetID']);
if (is_object($existingPreset)) {
$existingPreset->updateName($_POST['arLayoutPresetName']);
$existingPreset->updateAreaLayoutObject($arLayout);
}
}
$pr = new EditResponse();
if ($existingPreset) {
$pr->setMessage(t('Area layout preset updated successfully.'));
} else {
$pr->setMessage(t('Area layout preset saved successfully.'));
}
$pr->outputJSON();
}
}
}