ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.arGUI.php
Go to the documentation of this file.
1<?php
2include_once("./Services/Component/classes/class.ilPluginConfigGUI.php");
3include_once('./Services/ActiveRecord/class.ActiveRecordList.php');
4include_once('./Services/ActiveRecord/Views/Index/class.arIndexTableGUI.php');
5include_once('./Services/UICore/classes/class.ilTemplate.php');
6
12class arGUI {
13
17 protected $ctrl;
21 protected $tpl;
25 protected $access;
29 protected $lng;
33 protected $plugin_object = NULL;
37 protected $record_type = "";
41 protected $ar;
45 protected $lng_prefix = "";
46
47
53 global $tpl, $ilCtrl, $ilAccess, $lng;
54
55 $this->lng = $lng;
56
57 if ($plugin_object) {
58 $this->setLngPrefix($plugin_object->getPrefix());
59 $plugin_object->loadLanguageModule();
60 }
61
62 $this->tpl = $tpl;
63 $this->ctrl = $ilCtrl;
64 $this->access = $ilAccess;
65 $this->plugin_object = $plugin_object;
66 $this->record_type = $record_type;
67 $this->ar = new $record_type();
68 }
69
70
71 function executeCommand() {
72 $cmd = $this->ctrl->getCmd();
73 switch ($cmd) {
74 case "edit":
75 case "update":
76 case "view":
77 case "delete":
79 break;
80 case "multiAction":
81 $action_name = $_POST["index_table_multi_action_2"];
82 $this->multiAction($action_name);
83 break;
84 default:
85 $this->$cmd();
86 break;
87 }
88 }
89
90
94 function index(arIndexTableGUI $table_gui = NULL) {
95 if (!$table_gui) {
96 $index_table_gui_class = $this->record_type . "IndexTableGUI";
100 $table_gui = new $index_table_gui_class($this, "index", new ActiveRecordList($this->ar));
101 }
102 $this->tpl->setContent($table_gui->getHTML());
103 }
104
105
106 function applyFilter() {
107 $index_table_gui_class = $this->record_type . "IndexTableGUI";
111 $table_gui = new $index_table_gui_class($this, "index", new ActiveRecordList($this->ar));
112 $table_gui->applyFilter();
113 $this->index();
114 }
115
116
117 function resetFilter() {
118 $index_table_gui_class = $this->record_type . "IndexTableGUI";
122 $table_gui = new $index_table_gui_class($this, "index", new ActiveRecordList($this->ar));
123 $table_gui->resetFilter();
124 $this->index();
125 }
126
127
131 function multiAction($action_name = "") {
132 $ids = array();
133 if ($_POST['id']) {
134 foreach ($_POST['id'] as $id) {
135 $ids[] = arIndexTableGUI::domid_decode($id);
136 }
137 }
138
139 if (empty($ids)) {
140 ilUtil::sendFailure($this->txt("no_checkbox", false), true);
141 $this->ctrl->redirect($this, "index");
142 }
143
144 switch ($action_name) {
145 case "delete":
146 $this->deleteMultiple($ids);
147 break;
148 default:
149 $this->customMultiAction($action_name, $ids);
150 break;
151 }
152 }
153
154
159 function customMultiAction($action_name = "", $ids = NULL) {
160 }
161
162
166 function edit($id) {
167 $edit_gui_class = $this->record_type . "EditGUI";
171 $edit_gui = new $edit_gui_class($this, $this->ar->find($id));
172 $this->tpl->setContent($edit_gui->getHTML());
173 }
174
175
176 function add() {
177 $edit_gui_class = $this->record_type . "EditGUI";
181 $edit_gui = new $edit_gui_class($this, $this->ar);
182 $this->tpl->setContent($edit_gui->getHTML());
183 }
184
185
186 public function create() {
187 $edit_gui_class = $this->record_type . "EditGUI";
191 $edit_gui = new $edit_gui_class($this, $this->ar);
192 $this->save($edit_gui);
193 }
194
195
199 public function update($id) {
200 $edit_gui_class = $this->record_type . "EditGUI";
204 $edit_gui = new $edit_gui_class($this, $this->ar->find($id));
205 $this->save($edit_gui);
206 }
207
208
212 public function save(arEditGUI $edit_gui) {
213 if ($edit_gui->saveObject()) {
215 $this->ctrl->redirect($this, "index");
216 } else {
217 $this->tpl->setContent($edit_gui->getHTML());
218 }
219 }
220
221
225 public function getRecordCreatedMessage() {
226 return $this->txt(('record_created'), true);
227 }
228
229
233 function view($id) {
234 $display_gui_class = $this->record_type . "DisplayGUI";
238 $display_gui = new $display_gui_class($this, $this->ar->find($id));
239 $this->tpl->setContent($display_gui->getHtml());
240 }
241
242
246 function delete($id) {
247 $this->deleteMultiple(array( $id ));
248 }
249
250
254 function deleteMultiple($ids = NULL) {
255 $delete_gui_class = $this->record_type . "DeleteGUI";
259 $delete_gui = new $delete_gui_class($this, "delete", new ActiveRecordList($this->ar), "delete", $ids);
260 if (count($ids) == 1) {
262 } else {
264 }
265 $this->tpl->setContent($delete_gui->getHTML());
266 }
267
268
273 return $this->txt(('delete_records_confirmation'), true);
274 }
275
276
281 return $this->txt(('delete_record_confirmation'), true);
282 }
283
284
285 function deleteItems() {
286 $nr_ids = $_POST['nr_ids'];
287 for ($i = 0; $i < $nr_ids; $i ++) {
288 $id = $_POST['delete_id_' . $i];
289 $record = $this->ar->find($id);
290 $record->delete();
291 }
292 if ($i == 1) {
294 } else {
296 }
297
298 $this->ctrl->redirect($this, "index");
299 }
300
301
305 public function getDeleteRecordsMessage() {
306 return $this->txt(('records_deleted'), true);
307 }
308
309
313 public function getDeleteRecordMessage() {
314 return $this->txt(('record_deleted'), true);
315 }
316
317
321 public function setLngPrefix($lng_prefix) {
322 $this->lng_prefix = $lng_prefix;
323 }
324
325
329 public function getLngPrefix() {
330 return $this->lng_prefix;
331 }
332
333
340 public function txt($txt, $plugin_txt = true) {
341 if ($this->getLngPrefix() != "" && $plugin_txt) {
342 return $this->lng->txt($this->getLngPrefix() . "_" . $txt, $this->getLngPrefix());
343 } else {
344 return $this->lng->txt($txt);
345 }
346 }
347}
$_GET["client_id"]
Class ActiveRecordList.
GUI-Class arEditGUI.
deleteItems()
__construct($record_type, ilPlugin $plugin_object=NULL)
Definition: class.arGUI.php:52
$plugin_object
Definition: class.arGUI.php:33
$lng
@ar ilLanguage
Definition: class.arGUI.php:29
getDeleteRecordsMessage()
getDeleteRecordMessage()
$record_type
Definition: class.arGUI.php:37
customMultiAction($action_name="", $ids=NULL)
txt($txt, $plugin_txt=true)
setLngPrefix($lng_prefix)
executeCommand()
Definition: class.arGUI.php:71
multiAction($action_name="")
getDeleteRecordConfirmationMessage()
getDeleteRecordsConfirmationMessage()
getLngPrefix()
getRecordCreatedMessage()
save(arEditGUI $edit_gui)
GUI-Class arIndexTableGUI.
static domid_decode($id_to_decode)
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$_POST['username']
Definition: cron.php:12
$txt
Definition: error.php:12
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35