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