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