ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjCourseGroupingGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once "./Services/Object/classes/class.ilObjectGUI.php";
5
14{
16 public $tpl;
17 public $ctrl;
18 public $lng;
19
24 public function __construct($content_obj, $a_obj_id = 0)
25 {
26 global $DIC;
27
28 $tpl = $DIC['tpl'];
29 $ilCtrl = $DIC['ilCtrl'];
30 $lng = $DIC['lng'];
31 $ilObjDataCache = $DIC['ilObjDataCache'];
32
33 $this->tpl = $tpl;
34 $this->ctrl = $ilCtrl;
35 $this->lng = $lng;
36
37 $this->type = "crsg";
38 $this->content_obj = $content_obj;
39 $this->content_type = $ilObjDataCache->lookupType($this->content_obj->getId());
40
41 $this->id = $a_obj_id;
42 $this->ctrl->saveParameter($this, 'obj_id');
43
44 $this->__initGroupingObject();
45 }
46
47 public function executeCommand()
48 {
49 global $DIC;
50
51 $ilTabs = $DIC['ilTabs'];
52
53 $ilTabs->setTabActive('crs_groupings');
54
55 $cmd = $this->ctrl->getCmd();
56 if (!$cmd = $this->ctrl->getCmd()) {
57 $cmd = "edit";
58 }
59 $this->$cmd();
60 }
61
62 // PRIVATE
63 public function __initGroupingObject()
64 {
65 include_once './Modules/Course/classes/class.ilObjCourseGrouping.php';
66
67 $this->grp_obj = new ilObjCourseGrouping($this->id);
68 }
69
70 public function getContentType()
71 {
72 return $this->content_type;
73 }
74
75 public function listGroupings()
76 {
77 global $DIC;
78
79 $ilErr = $DIC['ilErr'];
80 $ilAccess = $DIC['ilAccess'];
81 $ilToolbar = $DIC['ilToolbar'];
82 $tpl = $DIC['tpl'];
83
84 if (!$ilAccess->checkAccess('write', '', $this->content_obj->getRefId())) {
85 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
86 }
87
88 $ilToolbar->addButton(
89 $this->lng->txt('crs_add_grouping'),
90 $this->ctrl->getLinkTarget($this, 'create')
91 );
92
93 include_once 'Modules/Course/classes/class.ilCourseGroupingTableGUI.php';
94 $table = new ilCourseGroupingTableGUI($this, 'listGroupings', $this->content_obj);
95
96 $tpl->setContent($table->getHTML());
97 }
98
99 public function askDeleteGrouping()
100 {
101 global $DIC;
102
103 $ilErr = $DIC['ilErr'];
104 $ilAccess = $DIC['ilAccess'];
105 $tpl = $DIC['tpl'];
106
107 if (!$ilAccess->checkAccess('write', '', $this->content_obj->getRefId())) {
108 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
109 }
110
111 if (empty($_POST['grouping'])) {
112 ilUtil::sendFailure($this->lng->txt('crs_grouping_select_one'));
113 $this->listGroupings();
114
115 return false;
116 }
117
118 // display confirmation message
119 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
120 $cgui = new ilConfirmationGUI();
121 $cgui->setFormAction($this->ctrl->getFormAction($this));
122 $cgui->setHeaderText($this->lng->txt("crs_grouping_delete_sure"));
123 $cgui->setCancel($this->lng->txt("cancel"), "listGroupings");
124 $cgui->setConfirm($this->lng->txt("delete"), "deleteGrouping");
125
126 // list objects that should be deleted
127 foreach ($_POST['grouping'] as $grouping_id) {
128 $tmp_obj = new ilObjCourseGrouping($grouping_id);
129 $cgui->addItem("grouping[]", $grouping_id, $tmp_obj->getTitle());
130 }
131
132 $tpl->setContent($cgui->getHTML());
133 }
134
135 public function deleteGrouping()
136 {
137 global $DIC;
138
139 $ilErr = $DIC['ilErr'];
140 $ilAccess = $DIC['ilAccess'];
141
142 if (!$ilAccess->checkAccess('write', '', $this->content_obj->getRefId())) {
143 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
144 }
145
146 foreach ($_POST['grouping'] as $grouping_id) {
147 $tmp_obj = new ilObjCourseGrouping((int) $grouping_id);
148 $tmp_obj->delete();
149 }
150
151 ilUtil::sendSuccess($this->lng->txt('crs_grouping_deleted'), true);
152 $this->ctrl->redirect($this, 'listGroupings');
153 }
154
155 public function create($a_form = null)
156 {
157 global $DIC;
158
159 $ilErr = $DIC['ilErr'];
160 $ilAccess = $DIC['ilAccess'];
161 $tpl = $DIC['tpl'];
162
163 if (!$ilAccess->checkAccess('write', '', $this->content_obj->getRefId())) {
164 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
165 }
166
167 if (!$a_form) {
168 $a_form = $this->initForm(true);
169 }
170
171 $tpl->setContent($a_form->getHTML());
172 }
173
174 public function initForm($a_create)
175 {
176 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
177 $form = new ilPropertyFormGUI();
178 $form->setFormAction($this->ctrl->getFormAction($this));
179
180 $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
181 $title->setRequired(true);
182 $form->addItem($title);
183
184 $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
185 $form->addItem($desc);
186
187 $options = array('login' => 'login',
188 'email' => 'email',
189 'matriculation' => 'matriculation');
190
191 foreach ($options as $value => $caption) {
192 $options[$value] = $this->lng->txt($caption);
193 }
194 $uniq = new ilSelectInputGUI($this->lng->txt('unambiguousness'), 'unique');
195 $uniq->setRequired(true);
196 $uniq->setOptions($options);
197 $form->addItem($uniq);
198
199 if ($a_create) {
200 $form->setTitle($this->lng->txt('crs_add_grouping'));
201 $form->addCommandButton('add', $this->lng->txt('btn_add'));
202 } else {
203 $grouping = new ilObjCourseGrouping($_REQUEST['obj_id']);
204 $title->setValue($grouping->getTitle());
205 $desc->setValue($grouping->getDescription());
206 $uniq->setValue($grouping->getUniqueField());
207
208 $ass = new ilCustomInputGUI($this->lng->txt('groupings_assigned_obj_' . $this->getContentType()));
209 $form->addItem($ass);
210
211 // assignments
212 $items = array();
213 foreach ($grouping->getAssignedItems() as $cond_data) {
214 $items[] = ilObject::_lookupTitle($cond_data['target_obj_id']);
215 }
216 if (count($items)) {
217 $ass->setHtml(implode("<br />", $items));
218 } else {
219 $ass->setHtml($this->lng->txt('crs_grp_no_courses_assigned'));
220 }
221
222 $form->setTitle($this->lng->txt('edit_grouping'));
223 $form->addCommandButton('update', $this->lng->txt('save'));
224 $form->addCommandButton('selectCourse', $this->lng->txt('grouping_change_assignment'));
225 }
226
227 $form->addCommandButton('listGroupings', $this->lng->txt('cancel'));
228
229 return $form;
230 }
231
232 public function add()
233 {
234 $form = $this->initForm(true);
235 if ($form->checkInput()) {
236 $this->grp_obj->setTitle($form->getInput('title'));
237 $this->grp_obj->setDescription($form->getInput('description'));
238 $this->grp_obj->setUniqueField($form->getInput('unique'));
239
240 if ($this->grp_obj->create($this->content_obj->getRefId(), $this->content_obj->getId())) {
241 ilUtil::sendSuccess($this->lng->txt('crs_grp_added_grouping'), true);
242 } else {
243 ilUtil::sendFailure($this->lng->txt('crs_grp_err_adding_grouping'), true);
244 }
245
246 $this->ctrl->redirect($this, 'listGroupings');
247 }
248
249 $form->setValuesByPost();
250 $this->create($form);
251 }
252
253 public function edit($a_form = null)
254 {
255 global $DIC;
256
257 $ilErr = $DIC['ilErr'];
258 $ilAccess = $DIC['ilAccess'];
259 $tpl = $DIC['tpl'];
260
261 if (!$ilAccess->checkAccess('write', '', $this->content_obj->getRefId())) {
262 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
263 }
264
265 if (!$a_form) {
266 $a_form = $this->initForm(false);
267 }
268
269 $tpl->setContent($a_form->getHTML());
270 }
271
272 public function update()
273 {
274 global $DIC;
275
276 $ilErr = $DIC['ilErr'];
277 $ilAccess = $DIC['ilAccess'];
278 $ilObjDataCache = $DIC['ilObjDataCache'];
279
280 if (!$ilAccess->checkAccess('write', '', $this->content_obj->getRefId())) {
281 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
282 }
283
284 $form = $this->initForm(false);
285 if ($form->checkInput()) {
286 $tmp_grouping = new ilObjCourseGrouping($_REQUEST['obj_id']);
287 $tmp_grouping->setTitle($form->getInput('title'));
288 $tmp_grouping->setDescription($form->getInput('description'));
289 $tmp_grouping->setUniqueField($form->getInput('unique'));
290 $tmp_grouping->update();
291
292 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
293 $this->ctrl->redirect($this, 'listGroupings');
294 }
295
296 $form->setValuesByPost();
297 $this->edit($form);
298 }
299
300 public function selectCourse()
301 {
302 global $DIC;
303
304 $ilErr = $DIC['ilErr'];
305 $ilAccess = $DIC['ilAccess'];
306 $tpl = $DIC['tpl'];
307 $ilTabs = $DIC['ilTabs'];
308
309 if (!$ilAccess->checkAccess('write', '', $this->content_obj->getRefId())) {
310 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
311 }
312
313 if (!$_GET['obj_id']) {
314 ilUtil::sendFailure($this->lng->txt('crs_grp_no_grouping_id_given'));
315 $this->listGroupings();
316 return false;
317 }
318
319 $ilTabs->clearTargets();
320 $ilTabs->setBackTarget(
321 $this->lng->txt('back'),
322 $this->ctrl->getLinkTarget($this, 'edit')
323 );
324
325 $tmp_grouping = new ilObjCourseGrouping((int) $_GET['obj_id']);
326
327 include_once 'Modules/Course/classes/class.ilCourseGroupingAssignmentTableGUI.php';
328 $table = new ilCourseGroupingAssignmentTableGUI($this, 'selectCourse', $this->content_obj, $tmp_grouping);
329
330 $tpl->setContent($table->getHTML());
331
332 return true;
333 }
334
335 public function assignCourse()
336 {
337 global $DIC;
338
339 $ilErr = $DIC['ilErr'];
340 $ilAccess = $DIC['ilAccess'];
341 $ilObjDataCache = $DIC['ilObjDataCache'];
342 $tree = $DIC['tree'];
343 $ilUser = $DIC['ilUser'];
344
345 if (!$ilAccess->checkAccess('write', '', $this->content_obj->getRefId())) {
346 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
347 }
348
349 if (!$_GET['obj_id']) {
350 $this->listGroupings();
351 return false;
352 }
353
354 // delete all existing conditions
355 include_once './Services/Conditions/classes/class.ilConditionHandler.php';
356 $condh = new ilConditionHandler();
357 $condh->deleteByObjId((int) $_GET['obj_id']);
358
359 $added = 0;
360 $container_ids = is_array($_POST['crs_ids']) ? $_POST['crs_ids'] : array();
361 foreach ($container_ids as $course_ref_id) {
362 $tmp_crs = ilObjectFactory::getInstanceByRefId($course_ref_id);
363 $tmp_condh = new ilConditionHandler();
364 $tmp_condh->enableAutomaticValidation(false);
365
366 $tmp_condh->setTargetRefId($course_ref_id);
367 $tmp_condh->setTargetObjId($tmp_crs->getId());
368 $tmp_condh->setTargetType($this->getContentType());
369 $tmp_condh->setTriggerRefId(0);
370 $tmp_condh->setTriggerObjId($this->id);
371 $tmp_condh->setTriggerType('crsg');
372 $tmp_condh->setOperator('not_member');
373 $tmp_condh->setValue($this->grp_obj->getUniqueField());
374
375 if (!$tmp_condh->checkExists()) {
376 $tmp_condh->storeCondition();
377 ++$added;
378 }
379 }
380
381 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
382 $this->ctrl->redirect($this, 'edit');
383 }
384} // END class.ilObjCourseGrouping
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
INTERNAL CLASS: Please do not use in consumer code.
Confirmation screen class.
This class represents a custom property in a property form.
Class ilObjCourseGroupingGUI.
__construct($content_obj, $a_obj_id=0)
Constructor @access public.
Class ilObj<module_name>
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupTitle($a_id)
lookup object title
This class represents a property form user interface.
This class represents a selection list property in a property form.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $ilCtrl
Definition: ilias.php:18
if(empty($password)) $table
Definition: pwgen.php:24
$ilErr
Definition: raiseError.php:18
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18