ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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(); //TODO order tables
132 }
133 include_once './Services/Form/classes/class.ilSelectInputGUI.php';
134 $table_selection = new ilSelectInputGUI('', 'table_id');
135 $table_selection->setOptions($options);
136 $table_selection->setValue($this->table->getId());
137
138 $this->toolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclTableViewGUI", "doTableSwitch"));
139 $this->toolbar->addText($this->lng->txt("dcl_select"));
140 $this->toolbar->addInputItem($table_selection);
141 $button = ilSubmitButton::getInstance();
142 $button->setCommand("doTableSwitch");
143 $button->setCaption('change');
144 $this->toolbar->addButtonInstance($button);
145
146 $table_gui = new ilDclTableViewTableGUI($this, 'show', $this->table);
147 $this->tpl->setContent($table_gui->getHTML());
148 }
149
150
154 public function doTableSwitch()
155 {
156 $this->ctrl->setParameterByClass("ilDclTableViewGUI", "table_id", $_POST['table_id']);
157 $this->ctrl->redirectByClass("ilDclTableViewGUI", "show");
158 }
159
160
164 public function confirmDeleteTableviews()
165 {
166 //at least one view must exist
167 $tableviews = isset($_POST['dcl_tableview_ids']) ? $_POST['dcl_tableview_ids'] : array();
168 $this->checkViewsLeft(count($tableviews));
169
170 $this->tabs->clearSubTabs();
171 $conf = new ilConfirmationGUI();
172 $conf->setFormAction($this->ctrl->getFormAction($this));
173 $conf->setHeaderText($this->lng->txt('dcl_tableviews_confirm_delete'));
174
175 foreach ($tableviews as $tableview_id) {
176 $conf->addItem('dcl_tableview_ids[]', $tableview_id, ilDclTableView::find($tableview_id)->getTitle());
177 }
178 $conf->setConfirm($this->lng->txt('delete'), 'deleteTableviews');
179 $conf->setCancel($this->lng->txt('cancel'), 'show');
180 $this->tpl->setContent($conf->getHTML());
181 }
182
183
187 protected function deleteTableviews()
188 {
189 $tableviews = isset($_POST['dcl_tableview_ids']) ? $_POST['dcl_tableview_ids'] : array();
190 foreach ($tableviews as $tableview_id) {
191 ilDclTableView::find($tableview_id)->delete();
192 }
193 $this->table->sortTableViews();
194 ilUtil::sendSuccess($this->lng->txt('dcl_msg_tableviews_deleted'), true);
195 $this->ctrl->redirect($this, 'show');
196 }
197
198
204 public function checkViewsLeft($delete_count)
205 {
206 if ($delete_count >= count($this->table->getTableViews())) {
207 ilUtil::sendFailure($this->lng->txt('dcl_msg_tableviews_delete_all'), true);
208 $this->ctrl->redirect($this, 'show');
209 }
210 }
211
212
216 public function saveTableViewOrder()
217 {
218 $orders = $_POST['order'];
219 asort($orders);
220 $tableviews = array();
221 foreach (array_keys($orders) as $tableview_id) {
222 $tableviews[] = ilDclTableView::find($tableview_id);
223 }
224 $this->table->sortTableViews($tableviews);
225 ilUtil::sendSuccess($this->lng->txt('dcl_msg_tableviews_order_updated'));
226 $this->ctrl->redirect($this);
227 }
228}
$_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 $ilCtrl
Definition: ilias.php:18
global $DIC
Definition: saml.php:7