ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseGroupingAssignmentTableGUI.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 include_once('./Services/Table/classes/class.ilTable2GUI.php');
5 
14 {
15  public function __construct($a_parent_obj, $a_parent_cmd, $a_content_obj, $a_group_obj)
16  {
17  global $lng, $ilCtrl;
18 
19  $this->lng = $lng;
20  $this->ctrl = $ilCtrl;
21 
22  parent::__construct($a_parent_obj, $a_parent_cmd);
23 
24  $this->type = ilObject::_lookupType($a_content_obj->getId());
25  $this->lng->loadLanguageModule($this->type);
26 
27  // #9017
28  $this->setLimit(9999);
29 
30  $this->addColumn('','', 1);
31  $this->addColumn($this->lng->txt('title'), 'title');
32  $this->addColumn($this->lng->txt('path'), 'path');
33 
34  $this->setDefaultOrderField('title');
35  $this->setDefaultOrderDirection('asc');
36 
37  $this->setTitle($this->lng->txt('crs_grp_assign_crs').' ('.$a_group_obj->getTitle().')');
38 
39  $this->setRowTemplate("tpl.crs_grp_select_crs.html","Modules/Course");
40  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
41 
42  $this->addMultiCommand('assignCourse', $this->lng->txt('grouping_change_assignment'));
43  $this->addCommandButton('edit', $this->lng->txt('cancel'));
44 
45  $this->getItems($a_content_obj, $a_group_obj);
46  }
47 
48  protected function getItems($a_content_obj, $a_group_obj)
49  {
50  global $ilUser, $tree;
51 
52  $counter = 0;
53  $items = ilUtil::_getObjectsByOperations($this->type,
54  'write', $ilUser->getId(), -1);
55  $items_obj_id = array();
56  $items_ids = array();
57  foreach($items as $ref_id)
58  {
59  $obj_id = ilObject::_lookupObjId($ref_id);
60  $items_ids[$obj_id] = $ref_id;
61  $items_obj_id[] = $obj_id;
62  }
63  $items_obj_id = ilUtil::_sortIds($items_obj_id,'object_data','title','obj_id');
64 
65  $assigned_ids = array();
66  $assigned = $a_group_obj->getAssignedItems();
67  if($assigned)
68  {
69  foreach($assigned as $item)
70  {
71  $assigned_ids[] = $item['target_ref_id'];
72  }
73  }
74 
75  $data = array();
76  foreach($items_obj_id as $obj_id)
77  {
78  $item_id = $items_ids[$obj_id];
79  if($tree->checkForParentType($item_id,'adm'))
80  {
81  continue;
82  }
83 
84  $obj_id = ilObject::_lookupObjId($item_id);
85 
86  $data[] = array('id' => $item_id,
87  'title' => ilObject::_lookupTitle($obj_id),
88  'description' => ilObject::_lookupDescription($obj_id),
89  'path' => $this->__formatPath($tree->getPathFull($item_id)),
90  'assigned' => in_array($item_id, $assigned_ids));
91  }
92 
93  $this->setData($data);
94  }
95 
96  function __formatPath($a_path_arr)
97  {
98  $counter = 0;
99  foreach($a_path_arr as $data)
100  {
101  if(!$counter++)
102  {
103  continue;
104  }
105  if($counter++ > 2)
106  {
107  $path .= " -> ";
108  }
109  $path .= $data['title'];
110  }
111 
112  return $path;
113  }
114 
115  public function fillRow($a_set)
116  {
117  $this->tpl->setVariable("ID", $a_set["id"]);
118  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
119  $this->tpl->setVariable("TXT_PATH", $a_set["path"]);
120 
121  if($a_set["assigned"])
122  {
123  $this->tpl->setVariable("STATUS_CHECKED", " checked=\"checked\"");
124  }
125  }
126 }
127 
128 ?>