forked from koala-framework/koala-framework
/
Controller.php
187 lines (171 loc) · 8.71 KB
/
Controller.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
class Kwc_Directories_Item_Directory_Controller extends Kwf_Controller_Action_Auto_Kwc_Grid
{
protected $_buttons = array(
'save',
'delete',
'reload',
'add'
);
protected $_filters = array('text'=>true);
protected $_paging = 25;
public function preDispatch()
{
parent::preDispatch();
if (is_instance_of(Kwc_Abstract::getSetting($this->_getParam('class'), 'extConfig'), 'Kwc_Directories_Item_Directory_ExtConfigEditButtons')
|| is_instance_of(Kwc_Abstract::getSetting($this->_getParam('class'), 'extConfigControllerIndex'), 'Kwc_Directories_Item_Directory_ExtConfigEditButtons')) {
$url = Kwc_Admin::getInstance($this->_getParam('class'))->getControllerUrl('Form');
$editDialog = array(
'autoForm' => 'Kwc.Directories.Item.Directory.EditFormPanel',
'controllerUrl' => $url
);
if (!empty($this->_editDialog['width'])) $editDialog['width'] = $this->_editDialog['width'];
if (!empty($this->_editDialog['height'])) $editDialog['height'] = $this->_editDialog['height'];
$this->_editDialog = $editDialog;
}
if ($this->_columns[0] instanceof Kwf_Grid_Column_Button) {
throw new Kwf_Exception("Override Controller and add at least one column (button must not be first)");
}
if ($this->_columns[0] instanceof Kwf_Grid_Column && $this->_columns[0]->getName() == 'component_class') {
throw new Kwf_Exception("Override Controller and add at least one column (component_class must not be first)");
}
}
protected function _initColumns()
{
$extConfigType = false;
if (is_instance_of(Kwc_Abstract::getSetting($this->_getParam('class'), 'extConfig'), 'Kwc_Directories_Item_Directory_ExtConfigEditButtons')) {
$extConfigType = 'extConfig';
} else if (is_instance_of(Kwc_Abstract::getSetting($this->_getParam('class'), 'extConfigControllerIndex'), 'Kwc_Directories_Item_Directory_ExtConfigEditButtons')) {
$extConfigType = 'extConfigControllerIndex';
}
if ($extConfigType) {
//shows editDialog
if ($this->_editDialog) {
$this->_columns->add(new Kwf_Grid_Column_Button('properties', ' ', 20))
->setButtonIcon('/assets/silkicons/newspaper.png')
->setTooltip(trlKwf('Properties'));
}
$extConfig = Kwf_Component_Abstract_ExtConfig_Abstract::getInstance($this->_getParam('class'), $extConfigType)
->getConfig(Kwf_Component_Abstract_ExtConfig_Abstract::TYPE_DEFAULT);
$extConfig = $extConfig['items'];
if ($extConfig['countDetailClasses'] > 1 && !$this->_getModel()->hasColumn('component')) {
throw new Kwf_Exception('If you have more than one detail-component your table has to have a column named "component"');
}
if ($extConfig['countDetailClasses'] == 1 && $this->_getModel()->hasColumn('component')) {
throw new Kwf_Exception('If you have just one detail-component your table is not allowed to have a column named "component"');
}
$i=0;
foreach ($extConfig['contentEditComponents'] as $ec) {
$name = Kwf_Trl::getInstance()->trlStaticExecute(Kwc_Abstract::getSetting($ec['componentClass'], 'componentName'));
$icon = Kwc_Abstract::getSetting($ec['componentClass'], 'componentIcon');
$icon = new Kwf_Asset($icon);
$this->_columns->add(new Kwc_Directories_Item_Directory_ControllerEditButton('edit_'.$i, ' ', 20))
->setColumnType('editContent')
->setEditComponentClass($ec['componentClass'])
->setEditComponent($ec['component'])
->setEditType($ec['type'])
->setEditIdTemplate($ec['idTemplate'])
->setEditComponentIdSuffix($ec['componentIdSuffix'])
->setButtonIcon($icon->toString(array('arrow')))
->setTooltip(trlKwf('Edit {0}', $name));
$i++;
}
}
if ($this->_model->hasColumn('component')) {
$this->_columns->add(new Kwf_Grid_Column('component'));
}
$this->_columns->add(new Kwf_Grid_Column('component_class'))
->setData(new Kwf_Data_Kwc_ComponentClass($this->_getParam('class'), 'detail'));
$this->_columns->add(new Kwf_Grid_Column('edit_components'))
->setData(new Kwf_Data_Kwc_EditComponents($this->_getParam('class'), 'detail'));
}
protected function _beforeSave(Kwf_Model_Row_Interface $row)
{
parent::_beforeSave($row);
if ($row->getModel()->hasColumn('visible') && !$row->visible) {
$this->_checkRowIndependence($row, trlKwf('hide'));
}
}
protected function _beforeDelete(Kwf_Model_Row_Interface $row)
{
parent::_beforeDelete($row);
$this->_checkRowIndependence($row, trlKwf('delete'));
}
private function _checkRowIndependence(Kwf_Model_Row_Interface $row, $msgMethod)
{
$c = Kwf_Component_Data_Root::getInstance()
->getComponentByDbId($this->_getParam('componentId'));
// wenn zB Newsletter statisch in root erstellt wurde, gibts kein visible
if (!$c) {
//wenn seite offline ist ignorieren
// ist nicht natürlich nicht korrekt, wir *müssten* die überprüfung
// nachholen, sobald die seite online gestellt wird
return;
}
$components = array();
foreach (Kwc_Admin::getDependsOnRowInstances() as $a) {
if ($a instanceof Kwf_Component_Abstract_Admin_Interface_DependsOnRow) {
$components = array_merge($components, $a->getComponentsDependingOnRow($row));
}
}
$g = Kwc_Abstract::getSetting($this->_getParam('class'), 'generators');
if (isset($g['detail']['dbIdShortcut'])) {
//wenn auf sich selbst verlinkt ignorieren
foreach ($components as $k=>&$c) {
$c = $c->getPage();
$news = Kwf_Component_Data_Root::getInstance()
->getComponentsByDbId($g['detail']['dbIdShortcut'].$row->id);
foreach ($news as $n) {
if ($c->componentId == $n->getPage()->componentId) {
unset($components[$k]);
}
}
}
}
if ($components) {
$msg = trlKwf("You can not {0} this entry as it is used on the following pages:", $msgMethod);
$msg .= Kwf_Util_Component::getHtmlLocations($components);
throw new Kwf_ClientException($msg);
}
}
public function jsonDuplicateAction()
{
if (!isset($this->_permissions['duplicate']) || !$this->_permissions['duplicate']) {
throw new Kwf_Exception("Duplicate is not allowed.");
}
$ids = $this->getRequest()->getParam($this->_primaryKey);
$ids = explode(';', $ids);
$progressBar = null;
$this->view->data = array('duplicatedIds' => array());
ignore_user_abort(true);
if (Zend_Registry::get('db')) Zend_Registry::get('db')->beginTransaction();
$dir = Kwf_Component_Data_Root::getInstance()->getComponentByDbId(
$this->_getParam('componentId'),
array('ignoreVisible'=>true, 'limit'=>1)
);
foreach ($ids as $id) {
$child = $dir->getChildComponent(array('id'=>'-'.$id, 'ignoreVisible'=>true));
$newChild = Kwf_Util_Component::duplicate($child, $dir, $progressBar);
$newChild->row->save();
$this->view->data['duplicatedIds'][] = $newChild->id;
}
if (Zend_Registry::get('db')) Zend_Registry::get('db')->commit();
}
public function jsonMultiUploadAction()
{
$componentId = $this->_getParam('componentId');
$component = Kwf_Component_Data_Root::getInstance()
->getComponentByDbId($componentId, array('ignoreVisible' => true, 'limit' => 1));
if (Kwc_Abstract::getSetting($component->componentClass, 'multiFileUpload')) {
$uploadIds = $this->_getParam('uploadIds');
$uploadIds = explode(',', $uploadIds);
foreach ($uploadIds as $uploadId) {
$this->_createNewDetailComponentFromUpload($uploadId, $component);
}
}
}
protected function _createNewDetailComponentFromUpload($uploadId, $component)
{
throw new Kwf_Exception_NotYetImplemented('You have to override _createNewDetailComponentFormUpload function to create child components on multiFileUpload');
}
}