ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDclTableViewGUI.php
Go to the documentation of this file.
1<?php
2
12{
13
17 protected $ctrl;
21 protected $lng;
25 protected $toolbar;
29 protected $tpl;
33 protected $tabs;
37 protected $table;
38
39
46 public function __construct(ilDclTableListGUI $a_parent_obj, $table_id = 0)
47 {
48 global $DIC;
49 $ilCtrl = $DIC['ilCtrl'];
50 $lng = $DIC['lng'];
51 $ilToolbar = $DIC['ilToolbar'];
52 $tpl = $DIC['tpl'];
53 $ilTabs = $DIC['ilTabs'];
54 $locator = $DIC['ilLocator'];
55
56 if ($table_id == 0) {
57 $table_id = $_GET['table_id'];
58 }
59
60 $this->parent_obj = $a_parent_obj;
61 $this->ctrl = $ilCtrl;
62 $this->lng = $lng;
63 $this->tpl = $tpl;
64 $this->tabs = $ilTabs;
65 $this->toolbar = $ilToolbar;
66 $this->table = ilDclCache::getTableCache($table_id);
67
68 $this->ctrl->saveParameterByClass('ilDclTableEditGUI', 'table_id');
69 $locator->addItem($this->table->getTitle(), $this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'edit'));
70 $this->tpl->setLocator();
71
72 if (!$this->checkAccess()) {
73 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
74 $this->ctrl->redirectByClass('ildclrecordlistgui', 'listRecords');
75 }
76 }
77
78
82 public function executeCommand()
83 {
84 $this->ctrl->saveParameter($this, 'table_id');
85 $cmd = $this->ctrl->getCmd("show");
86 $next_class = $this->ctrl->getNextClass($this);
87
88 switch ($next_class) {
89 case 'ildcltablevieweditgui':
90 $edit_gui = new ilDclTableViewEditGUI($this, $this->table, ilDclTableView::findOrGetInstance($_GET['tableview_id']));
91 $this->ctrl->saveParameter($edit_gui, 'tableview_id');
92 $this->ctrl->forwardCommand($edit_gui);
93 break;
94 default:
95 switch ($cmd) {
96 default:
97 $this->$cmd();
98 break;
99 }
100 break;
101 }
102 }
103
104
108 protected function checkAccess()
109 {
110 return ilObjDataCollectionAccess::hasAccessToEditTable($this->parent_obj->getDataCollectionObject()->getRefId(), $this->table->getId());
111 }
112
113
117 public function show()
118 {
119 $add_new = ilLinkButton::getInstance();
120 $add_new->setPrimary(true);
121 $add_new->setCaption("dcl_add_new_view");
122 $add_new->setUrl($this->ctrl->getLinkTargetByClass('ilDclTableViewEditGUI', 'add'));
123 $this->toolbar->addStickyItem($add_new);
124
125 $this->toolbar->addSeparator();
126
127 // Show tables
128 $tables = $this->parent_obj->getDataCollectionObject()->getTables();
129
130 foreach ($tables as $table) {
131 $options[$table->getId()] = $table->getTitle();
132 }
133 $table_selection = new ilSelectInputGUI('', 'table_id');
134 $table_selection->setOptions($options);
135 $table_selection->setValue($this->table->getId());
136
137 $this->toolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclTableViewGUI", "doTableSwitch"));
138 $this->toolbar->addText($this->lng->txt("dcl_select"));
139 $this->toolbar->addInputItem($table_selection);
140 $button = ilSubmitButton::getInstance();
141 $button->setCommand("doTableSwitch");
142 $button->setCaption('change');
143 $this->toolbar->addButtonInstance($button);
144
145 $table_gui = new ilDclTableViewTableGUI($this, 'show', $this->table);
146 $this->tpl->setContent($table_gui->getHTML());
147 }
148
149
153 public function doTableSwitch()
154 {
155 $this->ctrl->setParameterByClass("ilDclTableViewGUI", "table_id", $_POST['table_id']);
156 $this->ctrl->redirectByClass("ilDclTableViewGUI", "show");
157 }
158
159
163 public function confirmDeleteTableviews()
164 {
165 //at least one view must exist
166 $tableviews = isset($_POST['dcl_tableview_ids']) ? $_POST['dcl_tableview_ids'] : array();
167 $this->checkViewsLeft(count($tableviews));
168
169 $this->tabs->clearSubTabs();
170 $conf = new ilConfirmationGUI();
171 $conf->setFormAction($this->ctrl->getFormAction($this));
172 $conf->setHeaderText($this->lng->txt('dcl_tableviews_confirm_delete'));
173
174 foreach ($tableviews as $tableview_id) {
175 $conf->addItem('dcl_tableview_ids[]', $tableview_id, ilDclTableView::find($tableview_id)->getTitle());
176 }
177 $conf->setConfirm($this->lng->txt('delete'), 'deleteTableviews');
178 $conf->setCancel($this->lng->txt('cancel'), 'show');
179 $this->tpl->setContent($conf->getHTML());
180 }
181
182
186 protected function deleteTableviews()
187 {
188 $tableviews = isset($_POST['dcl_tableview_ids']) ? $_POST['dcl_tableview_ids'] : array();
189 foreach ($tableviews as $tableview_id) {
190 ilDclTableView::find($tableview_id)->delete();
191 }
192 $this->table->sortTableViews();
193 ilUtil::sendSuccess($this->lng->txt('dcl_msg_tableviews_deleted'), true);
194 $this->ctrl->redirect($this, 'show');
195 }
196
197
203 public function checkViewsLeft($delete_count)
204 {
205 if ($delete_count >= count($this->table->getTableViews())) {
206 ilUtil::sendFailure($this->lng->txt('dcl_msg_tableviews_delete_all'), true);
207 $this->ctrl->redirect($this, 'show');
208 }
209 }
210
211
215 public function saveTableViewOrder()
216 {
217 $orders = $_POST['order'];
218 asort($orders);
219 $tableviews = array();
220 foreach (array_keys($orders) as $tableview_id) {
221 $tableviews[] = ilDclTableView::find($tableview_id);
222 }
223 $this->table->sortTableViews($tableviews);
224 ilUtil::sendSuccess($this->lng->txt('dcl_msg_tableviews_order_updated'));
225 $this->ctrl->redirect($this);
226 }
227}
$_GET["client_id"]
$_POST["username"]
static findOrGetInstance($primary_key, array $add_constructor_args=array())
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
static getTableCache($table_id=0)
Class ilDclTableListGUI.
Class ilDclTableViewEditGUI.
Class ilDclTableViewGUI.
confirmDeleteTableviews()
Confirm deletion of multiple fields.
checkViewsLeft($delete_count)
redirects if there are no tableviews left after deletion of {$delete_count} tableviews
__construct(ilDclTableListGUI $a_parent_obj, $table_id=0)
Constructor.
saveTableViewOrder()
invoked by ilDclTableViewTableGUI
Class ilDclTableViewTableGUI.
static getInstance()
Factory.
static hasAccessToEditTable($ref_id, $table_id)
This class represents a selection list property in a property form.
static getInstance()
Factory.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $DIC
Definition: goto.php:24