ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjCourseGroupingGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
32 require_once "./classes/class.ilObjectGUI.php";
33 
35 {
37  var $tpl;
38  var $ctrl;
39  var $lng;
44  function ilObjCourseGroupingGUI(&$content_obj,$a_obj_id = 0)
45  {
46  global $tpl,$ilCtrl,$lng,$ilObjDataCache;
47 
48  $this->tpl =& $tpl;
49  $this->ctrl =& $ilCtrl;
50  $this->lng =& $lng;
51 
52  $this->type = "crsg";
53  $this->content_obj =& $content_obj;
54  $this->content_type = $ilObjDataCache->lookupType($this->content_obj->getId());
55 
56  $this->id = $a_obj_id;
57  $this->ctrl->saveParameter($this,'obj_id');
58 
59  $this->__initGroupingObject();
60 
61  }
62 
63  function getContentType()
64  {
65  return $this->content_type;
66  }
67 
68  function listGroupings()
69  {
70  global $ilErr,$ilAccess,$ilObjDataCache;
71 
72  if(!$ilAccess->checkAccess('write','',$this->content_obj->getRefId()))
73  {
74  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
75  }
76 
77  $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.groupings.html",'Modules/Course');
78 
79  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
80  $this->tpl->setVariable("HEADER_DESC",$this->lng->txt('description'));
81  $this->tpl->setVariable("HEADER_UNAMBIGUOUSNESS",$this->lng->txt('unambiguousness'));
82  $this->tpl->setVariable("ASSIGNED_ITEMS",$this->lng->txt('groupings_assigned_obj_'.$this->getContentType()));
83 
84  $items = ilObjCourseGrouping::_getVisibleGroupings($this->content_obj->getId());
85 
86  // Fill table
87  $counter = 0;
88  $has_access = false;
89  foreach($items as $grouping_id)
90  {
91  $tmp_obj =& new ilObjCourseGrouping($grouping_id);
92 
93  // Description
94  if(strlen($tmp_obj->getDescription()))
95  {
96  $this->tpl->setCurrentBlock("description");
97  $this->tpl->setVariable("DESCRIPTION_GRP",$tmp_obj->getDescription());
98  $this->tpl->parseCurrentBlock();
99  }
100 
101  // Assigned items
102  $assigned_items = $tmp_obj->getAssignedItems();
103  if($num_items = count($assigned_items))
104  {
105  $this->tpl->setVariable("ASSIGNED_COURSES",$this->lng->txt('crs_grp_assigned_courses_info'));
106  }
107  else
108  {
109  $this->tpl->setVariable("ASSIGNED_COURSES",$this->lng->txt('crs_grp_no_courses_assigned'));
110  }
111 
112  foreach($assigned_items as $condition)
113  {
114  $this->tpl->setCurrentBlock("item");
115  $this->tpl->setVariable("ITEM_TITLE",$ilObjDataCache->lookupTitle($condition['target_obj_id']));
116  $this->tpl->parseCurrentBlock();
117  }
118 
119 
120  $this->tpl->setCurrentBlock("grouping_row");
121  $this->tpl->setVariable("GRP_TITLE",$tmp_obj->getTitle());
122 
123  if(ilObjCourseGrouping::_checkAccess($grouping_id))
124  {
125  $has_access = true;
126  $this->tpl->setVariable("CHECK_GRP",ilUtil::formCheckbox(0,'grouping[]',$grouping_id));
127  }
128  $this->tpl->setVariable("AMB_GRP",$this->lng->txt($tmp_obj->getUniqueField()));
129  $this->tpl->setVariable("ROW_CLASS",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
130 
131  $this->ctrl->setParameterByClass('ilobjcoursegroupinggui','obj_id',$grouping_id);
132  $this->tpl->setVariable("EDIT_LINK",$this->ctrl->getLinkTargetByClass('ilobjcoursegroupinggui','edit'));
133 
134  $this->tpl->parseCurrentBlock();
135  }
136 
137  if(count($items) and $has_access)
138  {
139  $this->tpl->setCurrentBlock("has_items");
140  $this->tpl->setVariable("ARR_DOWNRIGHT",ilUtil::getImagePath('arrow_downright.gif'));
141  $this->tpl->setVariable("EDIT",$this->lng->txt('edit'));
142  $this->tpl->setVariable("DELETE",$this->lng->txt('delete'));
143  $this->tpl->setVariable("ACTIONS",$this->lng->txt('actions'));
144  $this->tpl->parseCurrentBlock();
145  }
146  elseif(!count($items))
147  {
148  // no items
149  $this->tpl->setCurrentBlock("no_items");
150  $this->tpl->setVariable("TXT_NO_ITEMS",$this->lng->txt('no_datasets'));
151  $this->tpl->parseCurrentBlock();
152  }
153 
154  $this->tpl->setVariable("ADD",$this->lng->txt('crs_add_grouping'));
155 
156  }
157 
158 
159  function askDeleteGrouping()
160  {
161  global $ilErr,$ilAccess,$ilObjDataCache;
162 
163  if(!$ilAccess->checkAccess('write','',$this->content_obj->getRefId()))
164  {
165  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
166  }
167 
168  if(!count($_POST['grouping']))
169  {
170  ilUtil::sendFailure($this->lng->txt('crs_grouping_select_one'));
171  $this->listGroupings();
172 
173  return false;
174  }
175 
176  ilUtil::sendQuestion($this->lng->txt('crs_grouping_delete_sure'));
177  $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.crs_ask_delete_goupings.html",'Modules/Course');
178 
179  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
180  $this->tpl->setVariable("HEADER_DESC",$this->lng->txt('description'));
181  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt('cancel'));
182  $this->tpl->setVariable("BTN_DELETE",$this->lng->txt('delete'));
183 
184 
185  $counter = 0;
186  foreach($_POST['grouping'] as $grouping_id)
187  {
188  $tmp_obj =& new ilObjCourseGrouping($grouping_id);
189 
190  if(strlen($tmp_obj->getDescription()))
191  {
192  $this->tpl->setCurrentBlock("description");
193  $this->tpl->setVariable("DESCRIPTION_GRP",$tmp_obj->getDescription());
194  $this->tpl->parseCurrentBlock();
195  }
196  $this->tpl->setCurrentBlock("grouping_row");
197  $this->tpl->setVariable("GRP_TITLE",$tmp_obj->getTitle());
198  $this->tpl->setVariable("ROW_CLASS",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
199  $this->tpl->parseCurrentBlock();
200  }
201  $_SESSION['crs_grouping_del'] = $_POST['grouping'];
202  }
203 
204  function deleteGrouping()
205  {
206  global $ilErr,$ilAccess,$ilObjDataCache;
207 
208  if(!$ilAccess->checkAccess('write','',$this->content_obj->getRefId()))
209  {
210  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
211  }
212 
213  if(!count($_SESSION['crs_grouping_del']))
214  {
215  ilUtil::sendFailure('No grouping selected');
216  $this->listGroupings();
217 
218  return false;
219  }
220  foreach($_SESSION['crs_grouping_del'] as $grouping_id)
221  {
222  $tmp_obj =& new ilObjCourseGrouping((int) $grouping_id);
223  $tmp_obj->delete();
224  }
225  ilUtil::sendSuccess($this->lng->txt('crs_grouping_deleted'));
226  $this->listGroupings();
227 
228  unset($_SESSION['crs_grouping_del']);
229  return true;
230  }
231 
232  function create()
233  {
234  $options = array('login' => 'login',
235  'email' => 'email',
236  'matriculation' => 'matriculation');
237 
238 
239  $title = ilUtil::prepareFormOutput($_POST["title"],true);
240  $desc = ilUtil::stripSlashes($_POST["description"]);
241  $unique = $_POST['unique'] ? $_POST['unique'] : 'login';
242 
243  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.crs_grp_add.html",'Modules/Course');
244 
245  $this->tpl->setVariable("TITLE",$title);
246  $this->tpl->setVariable("DESC",$desc);
247  $this->tpl->setVariable("UNAM_SELECT",ilUtil::formSelect($unique,'unique',$options));
248 
249  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
250  $this->tpl->setVariable("TXT_HEADER",$this->lng->txt('crs_add_grouping'));
251  $this->tpl->setVariable("TXT_TITLE",$this->lng->txt('title'));
252  $this->tpl->setVariable("TXT_DESC",$this->lng->txt('description'));
253  $this->tpl->setVariable("TXT_UNAM",$this->lng->txt('unambiguousness'));
254  $this->tpl->setVariable("TXT_REQUIRED_FLD",$this->lng->txt('required_field'));
255  $this->tpl->setVariable("CMD_SUBMIT",'add');
256  $this->tpl->setVariable("TXT_SUBMIT",$this->lng->txt('btn_add'));
257  $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt('cancel'));
258  }
259 
260  function cancel()
261  {
262  // unset session variables
263  unset($_SESSION['crs_grouping_del']);
264 
265  $this->listGroupings();
266  return true;
267  }
268 
269  function add()
270  {
271  if(!$_POST['title'])
272  {
273  ilUtil::sendFailure($this->lng->txt('crs_grp_enter_title'));
274  $this->create();
275 
276  return false;
277  }
278 
279  $this->grp_obj->setTitle(ilUtil::stripSlashes($_POST['title']));
280  $this->grp_obj->setDescription(ilUtil::stripSlashes($_POST['description']));
281  $this->grp_obj->setUniqueField($_POST['unique']);
282  if($this->grp_obj->create($this->content_obj->getRefId(),$this->content_obj->getId()))
283  {
284  ilUtil::sendSuccess($this->lng->txt('crs_grp_added_grouping'));
285  }
286  else
287  {
288  ilUtil::sendFailure($this->lng->txt('crs_grp_err_adding_grouping'));
289  }
290 
291  $this->listGroupings();
292  return false;
293  }
294 
295  function edit($a_grouping_id = 0)
296  {
297  global $ilErr,$ilAccess,$ilObjDataCache;
298 
299  if(!$ilAccess->checkAccess('write','',$this->content_obj->getRefId()))
300  {
301  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
302  }
303  if($a_grouping_id)
304  {
305  $grouping_id = $a_grouping_id;
306  }
307  elseif(count($_POST['grouping']) != 1)
308  {
309  ilUtil::sendFailure($this->lng->txt('grouping_select_exactly_one'));
310  $this->listGroupings();
311  return false;
312  }
313  else
314  {
315  $grouping_id = (int) $_POST['grouping'][0];
316  }
317 
318  $options = array('login' => 'login',
319  'email' => 'email',
320  'matriculation' => 'matriculation');
321 
322  $tmp_grouping = new ilObjCourseGrouping($grouping_id);
323 
324  $title = isset($_POST['title']) ? ilUtil::stripSlashes($_POST['title']) : $tmp_grouping->getTitle();
325  $description = isset($_POST["description"]) ? ilUtil::stripSlashes($_POST['description']) : $tmp_grouping->getDescription();
326  $unique = $_POST['unique'] ? $_POST['unique'] : $tmp_grouping->getUniqueField();
327 
328  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.crs_grp_edit.html",'Modules/Course');
329 
330  $this->ctrl->setParameter($this,'obj_id',$grouping_id);
331  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
332  $this->tpl->setVariable("EDIT_GROUPING",$this->lng->txt('edit_grouping'));
333  $this->tpl->setVariable("BTN_UPDATE",$this->lng->txt('save'));
334  $this->tpl->setVariable("BTN_ADD",$this->lng->txt('grouping_change_assignment'));
335  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt('cancel'));
336  $this->tpl->setVariable("TXT_TITLE",$this->lng->txt('title'));
337  $this->tpl->setVariable("TXT_DESCRIPTION",$this->lng->txt('description'));
338 
339  $this->tpl->setVariable("TXT_UNAM",$this->lng->txt('unambiguousness'));
340  $this->tpl->setVariable("UNAM_SELECT",ilUtil::formSelect($unique,'unique',$options));
341 
342  $this->tpl->setVariable("TITLE",$title);
343  $this->tpl->setVariable("DESCRIPTION",$description);
344 
345 
346  $items = $tmp_grouping->getAssignedItems();
347  foreach($items as $cond_data)
348  {
349  $this->tpl->setCurrentBlock("list_courses");
350  $this->tpl->setVariable("LIST_CRS_TITLE",$ilObjDataCache->lookupTitle($cond_data['target_obj_id']));
351  $this->tpl->parseCurrentBlock();
352  }
353  if(count($items))
354  {
355  $this->tpl->setCurrentBlock("assigned");
356  $this->tpl->setVariable("ASS_COURSES",$this->lng->txt('crs_grp_table_assigned_courses'));
357  $this->tpl->parseCurrentBlock();
358  }
359  else
360  {
361  $this->tpl->setCurrentBlock("no_assigned");
362  $this->tpl->setVariable("MESSAGE_NO_COURSES",$this->lng->txt('crs_grp_no_courses_assigned'));
363  $this->tpl->parseCurrentBlock();
364  }
365  }
366 
367 
368  function update()
369  {
370  global $ilErr,$ilAccess,$ilObjDataCache;
371 
372  if(!$ilAccess->checkAccess('write','',$this->content_obj->getRefId()))
373  {
374  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
375  }
376 
377  if(!$_GET['obj_id'])
378  {
379  ilUtil::sendFailure($this->lng->txt('crs_grp_no_grouping_id_given'));
380  $this->listGroupings();
381  return false;
382  }
383  if(!$_POST['title'])
384  {
385  ilUtil::sendFailure($this->lng->txt('crs_grp_enter_title'));
386  $this->edit((int) $_GET['obj_id']);
387  return false;
388  }
389 
390  $tmp_grouping = new ilObjCourseGrouping($_GET['obj_id']);
391  $tmp_grouping->setTitle(ilUtil::stripSlashes($_POST['title']));
392  $tmp_grouping->setDescription(ilUtil::stripSlashes($_POST['description']));
393  $tmp_grouping->setUniqueField($_POST['unique']);
394  $tmp_grouping->update();
395 
396  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
397  $this->listGroupings();
398 
399  return true;
400  }
401 
402  function selectCourse()
403  {
404  global $ilErr,$ilAccess,$ilObjDataCache,$tree,$ilUser;
405 
406  if(!$ilAccess->checkAccess('write','',$this->content_obj->getRefId()))
407  {
408  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
409  }
410 
411  if(!$_GET['obj_id'])
412  {
413  ilUtil::sendFailure($this->lng->txt('crs_grp_no_grouping_id_given'));
414  $this->listGroupings();
415  return false;
416  }
417 
418  $tmp_grouping = new ilObjCourseGrouping((int) $_GET['obj_id']);
419 
420  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.crs_grp_select_crs.html",'Modules/Course');
421 
422  $this->ctrl->setParameter($this,'obj_id',(int) $_GET['obj_id']);
423  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
424  $this->tpl->setVariable("TBL_TITLE",$this->lng->txt('crs_grp_assign_crs').' ('.$this->grp_obj->getTitle().')');
425  $this->tpl->setVariable("BTN_ASSIGN",$this->lng->txt('grouping_change_assignment'));
426  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt('cancel'));
427  $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath('arrow_downright.gif'));
428  $this->tpl->setVariable("HEADER_DESC",$this->lng->txt('description'));
429 
430  $counter = 0;
432  'write',
433  $ilUser->getId(),-1);
434 
435  $items_obj_id = array();
436  $items_ids = array();
437  foreach($items as $ref_id)
438  {
439  $obj_id = $ilObjDataCache->lookupObjId($ref_id);
440  $items_ids[$obj_id] = $ref_id;
441  $items_obj_id[] = $obj_id;
442  }
443  $items_obj_id = ilUtil::_sortIds($items_obj_id,'object_data','title','obj_id');
444  foreach($items_obj_id as $obj_id)
445  {
446  $item_id = $items_ids[$obj_id];
447  if($tree->checkForParentType($item_id,'adm'))
448  {
449  continue;
450  }
451  $obj_id = $ilObjDataCache->lookupObjId($item_id);
452  $title = $ilObjDataCache->lookupTitle($obj_id);
453  $description = $ilObjDataCache->lookupDescription($obj_id);
454 
455  $assigned = $tmp_grouping->isAssigned($obj_id) ? 1 : 0;
456 
457  if(strlen($description))
458  {
459  $this->tpl->setCurrentBlock("description");
460  $this->tpl->setVariable("DESCRIPTION_CRS",$description);
461  $this->tpl->parseCurrentBlock();
462  }
463 
464  $this->tpl->setCurrentBlock("crs_row");
465  $this->tpl->setVariable("ROW_CLASS",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
466  $this->tpl->setVariable("CHECK_CRS",ilUtil::formCheckbox($assigned,'crs_ids[]',$item_id));
467  $this->tpl->setVariable("CRS_TITLE",$title);
468 
469  $path = $this->__formatPath($tree->getPathFull($item_id));
470  $this->tpl->setVariable("CRS_PATH",$this->lng->txt('path').": ".$path);
471  $this->tpl->parseCurrentBlock();
472  }
473 
474  return true;
475  }
476 
477  function assignCourse()
478  {
479  global $ilErr,$ilAccess,$ilObjDataCache,$tree,$ilUser;
480 
481  if(!$ilAccess->checkAccess('write','',$this->content_obj->getRefId()))
482  {
483  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
484  }
485 
486  if(!$_GET['obj_id'])
487  {
488  ilUtil::sendFailure($this->lng->txt('crs_grp_no_grouping_id_given'));
489  $this->listGroupings();
490  return false;
491  }
492 
493  $container_ids = is_array($_POST['crs_ids']) ? $_POST['crs_ids'] : array();
494 
495  $tmp_grouping = new ilObjCourseGrouping((int) $_GET['obj_id']);
496 
497  // delete all existing conditions
498  include_once './classes/class.ilConditionHandler.php';
499 
500  $condh = new ilConditionHandler();
501  $condh->deleteByObjId((int) $_GET['obj_id']);
502 
503  $added = 0;
504  foreach($container_ids as $course_ref_id)
505  {
506  $tmp_crs =& ilObjectFactory::getInstanceByRefId($course_ref_id);
507  $tmp_condh =& new ilConditionHandler();
508  $tmp_condh->enableAutomaticValidation(false);
509 
510  $tmp_condh->setTargetRefId($course_ref_id);
511  $tmp_condh->setTargetObjId($tmp_crs->getId());
512  $tmp_condh->setTargetType($this->getContentType());
513  $tmp_condh->setTriggerRefId(0);
514  $tmp_condh->setTriggerObjId($this->id);
515  $tmp_condh->setTriggerType('crsg');
516  $tmp_condh->setOperator('not_member');
517  $tmp_condh->setValue($this->grp_obj->getUniqueField());
518 
519  if(!$tmp_condh->checkExists())
520  {
521  $tmp_condh->storeCondition();
522  ++$added;
523  }
524  }
525  $this->edit((int) $_GET['obj_id']);
526  }
527 
528 
529  function &executeCommand()
530  {
531  global $ilTabs;
532 
533  $ilTabs->setTabActive('crs_groupings');
534 
535  $cmd = $this->ctrl->getCmd();
536  if (!$cmd = $this->ctrl->getCmd())
537  {
538  $cmd = "edit";
539  }
540  $this->$cmd();
541  }
542 
543  // PRIVATE
545  {
546  include_once './Modules/Course/classes/class.ilObjCourseGrouping.php';
547 
548  $this->grp_obj =& new ilObjCourseGrouping($this->id);
549  }
550 
551  function __formatPath($a_path_arr)
552  {
553  $counter = 0;
554  foreach($a_path_arr as $data)
555  {
556  if(!$counter++)
557  {
558  continue;
559  }
560  if($counter++ > 2)
561  {
562  $path .= " -> ";
563  }
564  $path .= $data['title'];
565  }
566 
567  return $path;
568  }
569 
570 } // END class.ilObjCourseGrouping
571 ?>