ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilDclTableViewGUI.php
Go to the documentation of this file.
1 <?php
2 require_once('Modules/DataCollection/classes/TableView/class.ilDclTableViewTableGUI.php');
3 require_once('Modules/DataCollection/classes/TableView/class.ilDclTableViewEditGUI.php');
4 require_once('Services/Utilities/classes/class.ilConfirmationGUI.php');
14 {
18  protected $ctrl;
19 
23  protected $lng;
24 
28  protected $toolbar;
29 
33  protected $tpl;
34 
38  protected $tabs;
39 
43  protected $table;
44 
45 
52  public function __construct(ilDclTableListGUI $a_parent_obj, $table_id = 0)
53  {
54  global $DIC;
55  $ilCtrl = $DIC['ilCtrl'];
56  $lng = $DIC['lng'];
57  $ilToolbar = $DIC['ilToolbar'];
58  $tpl = $DIC['tpl'];
59  $ilTabs = $DIC['ilTabs'];
60  $locator = $DIC['ilLocator'];
61 
62  if ($table_id == 0) {
63  $table_id = $_GET['table_id'];
64  }
65 
66  $this->parent_obj = $a_parent_obj;
67  $this->ctrl = $ilCtrl;
68  $this->lng = $lng;
69  $this->tpl = $tpl;
70  $this->tabs = $ilTabs;
71  $this->toolbar = $ilToolbar;
72  $this->table = ilDclCache::getTableCache($table_id);
73 
74  $this->ctrl->saveParameterByClass('ilDclTableEditGUI', 'table_id');
75  $locator->addItem($this->table->getTitle(), $this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'edit'));
76  $this->tpl->setLocator();
77 
78  if ( ! $this->checkAccess()) {
79  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
80  $this->ctrl->redirectByClass('ildclrecordlistgui', 'listRecords');
81  }
82  }
83 
84 
88  public function executeCommand()
89  {
90  $this->ctrl->saveParameter($this, 'table_id');
91  $cmd = $this->ctrl->getCmd("show");
92  $next_class = $this->ctrl->getNextClass($this);
93 
94  switch ($next_class)
95  {
96  case 'ildcltablevieweditgui':
97  require_once('./Modules/DataCollection/classes/TableView/class.ilDclTableViewEditGUI.php');
98  $edit_gui = new ilDclTableViewEditGUI($this, $this->table, ilDclTableView::findOrGetInstance($_GET['tableview_id']));
99  $this->ctrl->saveParameter($edit_gui, 'tableview_id');
100  $this->ctrl->forwardCommand($edit_gui);
101  break;
102  default:
103  switch($cmd)
104  {
105  default:
106  $this->$cmd();
107  break;
108  }
109  break;
110  }
111 
112 
113  }
114 
118  protected function checkAccess()
119  {
120  return ilObjDataCollectionAccess::hasAccessToEditTable($this->parent_obj->getDataCollectionObject()->getRefId(), $this->table->getId());
121  }
122 
126  public function show() {
127  $add_new = ilLinkButton::getInstance();
128  $add_new->setPrimary(true);
129  $add_new->setCaption("dcl_add_new_view");
130  $add_new->setUrl($this->ctrl->getLinkTargetByClass('ilDclTableViewEditGUI', 'add'));
131  $this->toolbar->addStickyItem($add_new);
132 
133  $this->toolbar->addSeparator();
134 
135  // Show tables
136  require_once("./Modules/DataCollection/classes/Table/class.ilDclTable.php");
137  $tables = $this->parent_obj->getDataCollectionObject()->getTables();
138 
139  foreach($tables as $table)
140  {
141  $options[$table->getId()] = $table->getTitle(); //TODO order tables
142  }
143  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
144  $table_selection = new ilSelectInputGUI('', 'table_id');
145  $table_selection->setOptions($options);
146  $table_selection->setValue($this->table->getId());
147 
148  $this->toolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclTableViewGUI", "doTableSwitch"));
149  $this->toolbar->addText($this->lng->txt("dcl_select"));
150  $this->toolbar->addInputItem($table_selection);
151  $button = ilSubmitButton::getInstance();
152  $button->setCommand("doTableSwitch");
153  $button->setCaption('change');
154  $this->toolbar->addButtonInstance($button);
155 
156  $table_gui = new ilDclTableViewTableGUI($this, 'show', $this->table);
157  $this->tpl->setContent($table_gui->getHTML());
158  }
159 
163  public function doTableSwitch()
164  {
165  $this->ctrl->setParameterByClass("ilDclTableViewGUI", "table_id", $_POST['table_id']);
166  $this->ctrl->redirectByClass("ilDclTableViewGUI", "show");
167  }
168 
169 
173  public function confirmDeleteTableviews()
174  {
175  //at least one view must exist
176  $tableviews = isset($_POST['dcl_tableview_ids']) ? $_POST['dcl_tableview_ids'] : array();
177  $this->checkViewsLeft(count($tableviews));
178 
179  $this->tabs->clearSubTabs();
180  $conf = new ilConfirmationGUI();
181  $conf->setFormAction($this->ctrl->getFormAction($this));
182  $conf->setHeaderText($this->lng->txt('dcl_tableviews_confirm_delete'));
183 
184  foreach ($tableviews as $tableview_id) {
185  $conf->addItem('dcl_tableview_ids[]', $tableview_id, ilDclTableView::find($tableview_id)->getTitle());
186  }
187  $conf->setConfirm($this->lng->txt('delete'), 'deleteTableviews');
188  $conf->setCancel($this->lng->txt('cancel'), 'show');
189  $this->tpl->setContent($conf->getHTML());
190  }
191 
195  protected function deleteTableviews()
196  {
197  $tableviews = isset($_POST['dcl_tableview_ids']) ? $_POST['dcl_tableview_ids'] : array();
198  foreach ($tableviews as $tableview_id) {
199  ilDclTableView::find($tableview_id)->delete();
200  }
201  $this->table->sortTableViews();
202  ilUtil::sendSuccess($this->lng->txt('dcl_msg_tableviews_deleted'), true);
203  $this->ctrl->redirect($this, 'show');
204  }
205 
211  public function checkViewsLeft($delete_count)
212  {
213  if ($delete_count >= count($this->table->getTableViews()))
214  {
215  ilUtil::sendFailure($this->lng->txt('dcl_msg_tableviews_delete_all'), true);
216  $this->ctrl->redirect($this, 'show');
217  }
218  }
219 
223  public function saveTableViewOrder()
224  {
225  $orders = $_POST['order'];
226  asort($orders);
227  $tableviews = array();
228  foreach(array_keys($orders) as $tableview_id)
229  {
230  $tableviews[] = ilDclTableView::find($tableview_id);
231  }
232  $this->table->sortTableViews($tableviews);
233  ilUtil::sendSuccess($this->lng->txt('dcl_msg_tableviews_order_updated'));
234  $this->ctrl->redirect($this);
235  }
236 
237 }
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.
$_GET["client_id"]
$cmd
Definition: sahs_server.php:35
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
if(!is_array($argv)) $options
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())
global $DIC
$_POST["username"]
Confirmation screen class.