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