ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseParticipantsGroupsTableGUI.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 
15 {
16  protected $filter; // array
17  protected $groups; // array
18  protected $groups_rights; // array
19  protected $participants; // array
20 
24  function __construct($a_parent_obj, $a_parent_cmd, $ref_id)
25  {
26  global $ilCtrl, $ilObjDataCache,$lng;
27 
28  $lng->loadLanguageModule('grp');
29 
30  $this->ref_id = $ref_id;
31  $this->obj_id = $ilObjDataCache->lookupObjId($this->ref_id);
32 
33  $this->setId("tblcrsprtgrp");
34 
35  parent::__construct($a_parent_obj, $a_parent_cmd);
36  // $this->setTitle($lng->txt("tr_summary"));
37  $this->setLimit(9999);
38  // $this->setShowTemplates(true);
39 
40  $this->setTitle($this->lng->txt('crs_grp_assignments'));
41 
42  $this->addColumn('','',0);
43  $this->addColumn($this->lng->txt("name"), "name",'70%');
44  $this->addColumn($this->lng->txt("crs_groups_nr"), "groups_number");
45  $this->addColumn($this->lng->txt("groups"));
46 
47  // $this->setExternalSorting(true);
48  $this->setEnableHeader(true);
49  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
50  $this->setRowTemplate("tpl.crs_members_grp_row.html", "Modules/Course");
51  $this->setSelectAllCheckbox("usrs");
52 
53  $this->initGroups();
54 
55  if($this->groups)
56  {
57  $this->addMultiItemSelectionButton("grp_id", $this->groups, "add", $this->lng->txt("crs_add_to_group"));
58  $this->initFilter();
59  }
60 
61  $this->getItems();
62  }
63 
67  function initGroups()
68  {
69  global $tree, $ilAccess;
70 
71  $parent_node = $tree->getNodeData($this->ref_id);
72  $groups = $tree->getSubTree($parent_node, true, "grp");
73  if(is_array($groups) && sizeof($groups))
74  {
75  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
76  $this->participants = $this->groups = $this->groups_rights = array();
77  foreach($groups as $idx => $group_data)
78  {
79  // check for group in group
80  if($group_data["parent"] != $this->ref_id && $tree->checkForParentType($group_data["ref_id"], "grp",true))
81  {
82  unset($groups[$idx]);
83  }
84  else
85  {
86  $this->groups[$group_data["ref_id"]] = $group_data["title"];
87  $this->groups_rights[$group_data["ref_id"]]["write"] = (bool)$ilAccess->checkAccess("write", "", $group_data["ref_id"]);
88  $this->groups_rights[$group_data["ref_id"]]["edit_permission"] = (bool)$ilAccess->checkAccess("edit_permission", "", $group_data["ref_id"]);
89  $gobj = ilGroupParticipants::_getInstanceByObjId($group_data["obj_id"]);
90  $this->participants[$group_data["ref_id"]]["members"] = $gobj->getMembers();
91  $this->participants[$group_data["ref_id"]]["admins"] = $gobj->getAdmins();
92  }
93  }
94  }
95  }
96 
100  function initFilter()
101  {
102  global $lng;
103 
104  $item = $this->addFilterItemByMetaType("name", ilTable2GUI::FILTER_TEXT);
105  $this->filter["name"] = $item->getValue();
106 
107  if($this->groups)
108  {
109  $item = $this->addFilterItemByMetaType("group", ilTable2GUI::FILTER_SELECT);
110  $item->setOptions(array("" => $lng->txt("all"))+$this->groups);
111  $this->filter["group"] = $item->getValue();
112  }
113  }
114 
118  function getItems()
119  {
120  if($this->groups)
121  {
122  include_once('./Modules/Course/classes/class.ilCourseParticipants.php');
123  $part = ilCourseParticipants::_getInstanceByObjId($this->obj_id);
124  $members = $part->getMembers();
125  if(count($members))
126  {
127  include_once './Services/User/classes/class.ilUserUtil.php';
128  $usr_data = array();
129  foreach(ilUserUtil::getNamePresentation($members, false, false, "", true) as $usr_id => $name)
130  {
131  // #9984
132  $user_groups = array("members"=>array(),"admins"=>array());
133  $user_groups_number = 0;
134  foreach(array_keys($this->participants) as $group_id)
135  {
136  if(in_array($usr_id, $this->participants[$group_id]["members"]))
137  {
138  $user_groups["members"][$group_id] = $this->groups[$group_id];
139  $user_groups_number++;
140  }
141  else if(in_array($usr_id, $this->participants[$group_id]["admins"]))
142  {
143  $user_groups["admins"][$group_id] = $this->groups[$group_id];
144  $user_groups_number++;
145  }
146  }
147 
148  if((!$this->filter["name"] || stristr($name, $this->filter["name"])) &&
149  (!$this->filter["group"] || array_key_exists($this->filter["group"], $user_groups["members"]) ||
150  array_key_exists($this->filter["group"], $user_groups["admins"])))
151  {
152  $usr_data[] = array("usr_id" => $usr_id,
153  "name" => $name,
154  "groups" => $user_groups,
155  "groups_number" => $user_groups_number
156  );
157  }
158  }
159 
160  // ???
161  $usr_data = array_slice($usr_data, (int)$this->getOffset(), (int)$this->getLimit());
162 
163  $this->setMaxCount(sizeof($members));
164  $this->setData($usr_data);
165  }
166 
167  return $titles;
168  }
169  }
170 
174  protected function fillRow($a_set)
175  {
176  global $lng, $ilCtrl;
177 
178  $this->tpl->setVariable("VAL_ID", $a_set["usr_id"]);
179 
180  $this->tpl->setVariable("TXT_USER", $a_set["name"]);
181  $this->tpl->setVariable("VAL_GROUP_NUMBER", $a_set["groups_number"]);
182 
183  if(sizeof($a_set["groups"]))
184  {
185 
186  foreach($a_set["groups"] as $type => $groups)
187  {
188  foreach($groups as $grp_id => $title)
189  {
190  if(($type == "admins" && $this->groups_rights[$grp_id]["edit_permission"]) ||
191  ($type == "members" && $this->groups_rights[$grp_id]["write"]))
192  {
193  $this->tpl->setCurrentBlock("groups_remove");
194 
195  $this->tpl->setVariable("TXT_GROUP_REMOVE", $lng->txt("grp_unsubscribe"));
196 
197  $ilCtrl->setParameter($this->parent_obj, "usr_id", $a_set["usr_id"]);
198  $ilCtrl->setParameter($this->parent_obj, "grp_id", $grp_id);
199  $this->tpl->setVariable("URL_REMOVE", $ilCtrl->getLinkTarget($this->parent_obj, "confirmremove"));
200  $ilCtrl->setParameter($this->parent_obj, "grp_id", "");
201  $ilCtrl->setParameter($this->parent_obj, "usr_id", "");
202 
203  $this->tpl->parseCurrentBlock();
204  }
205 
206  $this->tpl->setCurrentBlock("groups");
207  $this->tpl->setVariable("TXT_GROUP_TITLE", $title);
208  $this->tpl->parseCurrentBlock();
209  }
210  }
211  }
212  }
213 }
214 ?>