ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.arGUI.php
Go to the documentation of this file.
1 <?php
2 include_once("./Services/Component/classes/class.ilPluginConfigGUI.php");
3 include_once('./Services/ActiveRecord/class.ActiveRecordList.php');
4 include_once('./Services/ActiveRecord/Views/Index/class.arIndexTableGUI.php');
5 include_once('./Services/UICore/classes/class.ilTemplate.php');
6 
12 class arGUI
13 {
14 
18  protected $ctrl;
22  protected $tpl;
26  protected $access;
30  protected $lng;
34  protected $plugin_object = null;
38  protected $record_type = "";
42  protected $ar;
46  protected $lng_prefix = "";
47 
48 
54  {
55  global $DIC;
56  $tpl = $DIC['tpl'];
57  $ilCtrl = $DIC['ilCtrl'];
58  $ilAccess = $DIC['ilAccess'];
59  $lng = $DIC['lng'];
60 
61  $this->lng = $lng;
62 
63  if ($plugin_object) {
64  $this->setLngPrefix($plugin_object->getPrefix());
65  $plugin_object->loadLanguageModule();
66  }
67 
68  $this->tpl = $tpl;
69  $this->ctrl = $ilCtrl;
70  $this->access = $ilAccess;
71  $this->plugin_object = $plugin_object;
72  $this->record_type = $record_type;
73  $this->ar = new $record_type();
74  }
75 
76 
77  public function executeCommand()
78  {
79  $cmd = $this->ctrl->getCmd();
80  switch ($cmd) {
81  case "edit":
82  case "update":
83  case "view":
84  case "delete":
85  $this->$cmd(arIndexTableGUI::domid_decode($_GET['ar_id']));
86  break;
87  case "multiAction":
88  $action_name = $_POST["index_table_multi_action_2"];
89  $this->multiAction($action_name);
90  break;
91  default:
92  $this->$cmd();
93  break;
94  }
95  }
96 
97 
101  public function index(arIndexTableGUI $table_gui = null)
102  {
103  if (!$table_gui) {
104  $index_table_gui_class = $this->record_type . "IndexTableGUI";
108  $table_gui = new $index_table_gui_class($this, "index", new ActiveRecordList($this->ar));
109  }
110  $this->tpl->setContent($table_gui->getHTML());
111  }
112 
113 
114  public function applyFilter()
115  {
116  $index_table_gui_class = $this->record_type . "IndexTableGUI";
120  $table_gui = new $index_table_gui_class($this, "index", new ActiveRecordList($this->ar));
121  $table_gui->applyFilter();
122  $this->index();
123  }
124 
125 
126  public function resetFilter()
127  {
128  $index_table_gui_class = $this->record_type . "IndexTableGUI";
132  $table_gui = new $index_table_gui_class($this, "index", new ActiveRecordList($this->ar));
133  $table_gui->resetFilter();
134  $this->index();
135  }
136 
137 
141  public function multiAction($action_name = "")
142  {
143  $ids = array();
144  if ($_POST['id']) {
145  foreach ($_POST['id'] as $id) {
146  $ids[] = arIndexTableGUI::domid_decode($id);
147  }
148  }
149 
150  if (empty($ids)) {
151  ilUtil::sendFailure($this->txt("no_checkbox", false), true);
152  $this->ctrl->redirect($this, "index");
153  }
154 
155  switch ($action_name) {
156  case "delete":
157  $this->deleteMultiple($ids);
158  break;
159  default:
160  $this->customMultiAction($action_name, $ids);
161  break;
162  }
163  }
164 
165 
170  public function customMultiAction($action_name = "", $ids = null)
171  {
172  }
173 
174 
178  public function edit($id)
179  {
180  $edit_gui_class = $this->record_type . "EditGUI";
184  $edit_gui = new $edit_gui_class($this, $this->ar->find($id));
185  $this->tpl->setContent($edit_gui->getHTML());
186  }
187 
188 
189  public function add()
190  {
191  $edit_gui_class = $this->record_type . "EditGUI";
195  $edit_gui = new $edit_gui_class($this, $this->ar);
196  $this->tpl->setContent($edit_gui->getHTML());
197  }
198 
199 
200  public function create()
201  {
202  $edit_gui_class = $this->record_type . "EditGUI";
206  $edit_gui = new $edit_gui_class($this, $this->ar);
207  $this->save($edit_gui);
208  }
209 
210 
214  public function update($id)
215  {
216  $edit_gui_class = $this->record_type . "EditGUI";
220  $edit_gui = new $edit_gui_class($this, $this->ar->find($id));
221  $this->save($edit_gui);
222  }
223 
224 
228  public function save(arEditGUI $edit_gui)
229  {
230  if ($edit_gui->saveObject()) {
231  ilUtil::sendSuccess($this->getRecordCreatedMessage());
232  $this->ctrl->redirect($this, "index");
233  } else {
234  $this->tpl->setContent($edit_gui->getHTML());
235  }
236  }
237 
238 
242  public function getRecordCreatedMessage()
243  {
244  return $this->txt(('record_created'), true);
245  }
246 
247 
251  public function view($id)
252  {
253  $display_gui_class = $this->record_type . "DisplayGUI";
257  $display_gui = new $display_gui_class($this, $this->ar->find($id));
258  $this->tpl->setContent($display_gui->getHtml());
259  }
260 
261 
265  public function delete($id)
266  {
267  $this->deleteMultiple(array( $id ));
268  }
269 
270 
274  public function deleteMultiple($ids = null)
275  {
276  $delete_gui_class = $this->record_type . "DeleteGUI";
280  $delete_gui = new $delete_gui_class($this, "delete", new ActiveRecordList($this->ar), "delete", $ids);
281  if (count($ids) == 1) {
283  } else {
285  }
286  $this->tpl->setContent($delete_gui->getHTML());
287  }
288 
289 
294  {
295  return $this->txt(('delete_records_confirmation'), true);
296  }
297 
298 
303  {
304  return $this->txt(('delete_record_confirmation'), true);
305  }
306 
307 
308  public function deleteItems()
309  {
310  $nr_ids = $_POST['nr_ids'];
311  for ($i = 0; $i < $nr_ids; $i++) {
312  $id = $_POST['delete_id_' . $i];
313  $record = $this->ar->find($id);
314  $record->delete();
315  }
316  if ($i == 1) {
317  ilUtil::sendSuccess($this->getDeleteRecordMessage(), true);
318  } else {
319  ilUtil::sendSuccess($this->getDeleteRecordsMessage(), true);
320  }
321 
322  $this->ctrl->redirect($this, "index");
323  }
324 
325 
329  public function getDeleteRecordsMessage()
330  {
331  return $this->txt(('records_deleted'), true);
332  }
333 
334 
338  public function getDeleteRecordMessage()
339  {
340  return $this->txt(('record_deleted'), true);
341  }
342 
343 
347  public function setLngPrefix($lng_prefix)
348  {
349  $this->lng_prefix = $lng_prefix;
350  }
351 
352 
356  public function getLngPrefix()
357  {
358  return $this->lng_prefix;
359  }
360 
361 
368  public function txt($txt, $plugin_txt = true)
369  {
370  if ($this->getLngPrefix() != "" && $plugin_txt) {
371  return $this->lng->txt($this->getLngPrefix() . "_" . $txt, $this->getLngPrefix());
372  } else {
373  return $this->lng->txt($txt);
374  }
375  }
376 }
GUI-Class arIndexTableGUI.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
$plugin_object
Definition: class.arGUI.php:34
save(arEditGUI $edit_gui)
Class ActiveRecordList.
if(!array_key_exists('StateId', $_REQUEST)) $id
getDeleteRecordMessage()
deleteItems()
getDeleteRecordConfirmationMessage()
static domid_decode($id_to_decode)
customMultiAction($action_name="", $ids=null)
$record_type
Definition: class.arGUI.php:38
getRecordCreatedMessage()
global $ilCtrl
Definition: ilias.php:18
getDeleteRecordsConfirmationMessage()
getLngPrefix()
add()
Definition: add.php:2
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
$txt
Definition: error.php:11
GUI-Class arEditGUI.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
getDeleteRecordsMessage()
update($pash, $contents, Config $config)
$lng
ilLanguage
Definition: class.arGUI.php:30
setLngPrefix($lng_prefix)
__construct($record_type, ilPlugin $plugin_object=null)
Definition: class.arGUI.php:53
txt($txt, $plugin_txt=true)
multiAction($action_name="")
$i
Definition: disco.tpl.php:19
executeCommand()
Definition: class.arGUI.php:77
$_POST["username"]