ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilDclTableViewGUI.php
Go to the documentation of this file.
1 <?php
2 
12 {
16  protected $ctrl;
17 
21  protected $lng;
22 
26  protected $toolbar;
27 
31  protected $tpl;
32 
36  protected $tabs;
37 
41  protected $table;
42 
43 
50  public function __construct(ilDclTableListGUI $a_parent_obj, $table_id = 0)
51  {
52  global $DIC;
53  $ilCtrl = $DIC['ilCtrl'];
54  $lng = $DIC['lng'];
55  $ilToolbar = $DIC['ilToolbar'];
56  $tpl = $DIC['tpl'];
57  $ilTabs = $DIC['ilTabs'];
58  $locator = $DIC['ilLocator'];
59 
60  if ($table_id == 0) {
61  $table_id = $_GET['table_id'];
62  }
63 
64  $this->parent_obj = $a_parent_obj;
65  $this->ctrl = $ilCtrl;
66  $this->lng = $lng;
67  $this->tpl = $tpl;
68  $this->tabs = $ilTabs;
69  $this->toolbar = $ilToolbar;
70  $this->table = ilDclCache::getTableCache($table_id);
71 
72  $this->ctrl->saveParameterByClass('ilDclTableEditGUI', 'table_id');
73  $locator->addItem($this->table->getTitle(), $this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'edit'));
74  $this->tpl->setLocator();
75 
76  if (!$this->checkAccess()) {
77  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
78  $this->ctrl->redirectByClass('ildclrecordlistgui', 'listRecords');
79  }
80  }
81 
82 
86  public function executeCommand()
87  {
88  $this->ctrl->saveParameter($this, 'table_id');
89  $cmd = $this->ctrl->getCmd("show");
90  $next_class = $this->ctrl->getNextClass($this);
91 
92  switch ($next_class) {
93  case 'ildcltablevieweditgui':
94  $edit_gui = new ilDclTableViewEditGUI($this, $this->table, ilDclTableView::findOrGetInstance($_GET['tableview_id']));
95  $this->ctrl->saveParameter($edit_gui, 'tableview_id');
96  $this->ctrl->forwardCommand($edit_gui);
97  break;
98  default:
99  switch ($cmd) {
100  default:
101  $this->$cmd();
102  break;
103  }
104  break;
105  }
106  }
107 
111  protected function checkAccess()
112  {
113  return ilObjDataCollectionAccess::hasAccessToEditTable($this->parent_obj->getDataCollectionObject()->getRefId(), $this->table->getId());
114  }
115 
119  public function show()
120  {
121  $add_new = ilLinkButton::getInstance();
122  $add_new->setPrimary(true);
123  $add_new->setCaption("dcl_add_new_view");
124  $add_new->setUrl($this->ctrl->getLinkTargetByClass('ilDclTableViewEditGUI', 'add'));
125  $this->toolbar->addStickyItem($add_new);
126 
127  $this->toolbar->addSeparator();
128 
129  // Show tables
130  $tables = $this->parent_obj->getDataCollectionObject()->getTables();
131 
132  foreach ($tables as $table) {
133  $options[$table->getId()] = $table->getTitle(); //TODO order tables
134  }
135  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
136  $table_selection = new ilSelectInputGUI('', 'table_id');
137  $table_selection->setOptions($options);
138  $table_selection->setValue($this->table->getId());
139 
140  $this->toolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclTableViewGUI", "doTableSwitch"));
141  $this->toolbar->addText($this->lng->txt("dcl_select"));
142  $this->toolbar->addInputItem($table_selection);
143  $button = ilSubmitButton::getInstance();
144  $button->setCommand("doTableSwitch");
145  $button->setCaption('change');
146  $this->toolbar->addButtonInstance($button);
147 
148  $table_gui = new ilDclTableViewTableGUI($this, 'show', $this->table);
149  $this->tpl->setContent($table_gui->getHTML());
150  }
151 
155  public function doTableSwitch()
156  {
157  $this->ctrl->setParameterByClass("ilDclTableViewGUI", "table_id", $_POST['table_id']);
158  $this->ctrl->redirectByClass("ilDclTableViewGUI", "show");
159  }
160 
161 
165  public function confirmDeleteTableviews()
166  {
167  //at least one view must exist
168  $tableviews = isset($_POST['dcl_tableview_ids']) ? $_POST['dcl_tableview_ids'] : array();
169  $this->checkViewsLeft(count($tableviews));
170 
171  $this->tabs->clearSubTabs();
172  $conf = new ilConfirmationGUI();
173  $conf->setFormAction($this->ctrl->getFormAction($this));
174  $conf->setHeaderText($this->lng->txt('dcl_tableviews_confirm_delete'));
175 
176  foreach ($tableviews as $tableview_id) {
177  $conf->addItem('dcl_tableview_ids[]', $tableview_id, ilDclTableView::find($tableview_id)->getTitle());
178  }
179  $conf->setConfirm($this->lng->txt('delete'), 'deleteTableviews');
180  $conf->setCancel($this->lng->txt('cancel'), 'show');
181  $this->tpl->setContent($conf->getHTML());
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 
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 
214  public function saveTableViewOrder()
215  {
216  $orders = $_POST['order'];
217  asort($orders);
218  $tableviews = array();
219  foreach (array_keys($orders) as $tableview_id) {
220  $tableviews[] = ilDclTableView::find($tableview_id);
221  }
222  $this->table->sortTableViews($tableviews);
223  ilUtil::sendSuccess($this->lng->txt('dcl_msg_tableviews_order_updated'));
224  $this->ctrl->redirect($this);
225  }
226 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
Class ilDclTableViewEditGUI.
This class represents a selection list property in a property form.
saveTableViewOrder()
invoked by ilDclTableViewTableGUI
Class ilDclTableViewGUI.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
static hasAccessToEditTable($ref_id, $table_id)
Class ilDclTableListGUI.
confirmDeleteTableviews()
Confirm deletion of multiple fields.
static getTableCache($table_id=0)
__construct(ilDclTableListGUI $a_parent_obj, $table_id=0)
Constructor.
Class ilDclTableViewTableGUI.
global $ilCtrl
Definition: ilias.php:18
checkViewsLeft($delete_count)
redirects if there are no tableviews left after deletion of {$delete_count} tableviews ...
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static findOrGetInstance($primary_key, array $add_constructor_args=array())
$_POST["username"]
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
Confirmation screen class.