ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public function __construct($a_parent_obj, $a_parent_cmd, $ref_id)
25  {
26  global $DIC;
27 
28  $ilCtrl = $DIC['ilCtrl'];
29  $ilObjDataCache = $DIC['ilObjDataCache'];
30  $lng = $DIC['lng'];
31 
32  $lng->loadLanguageModule('grp');
33 
34  $this->ref_id = $ref_id;
35  $this->obj_id = $ilObjDataCache->lookupObjId($this->ref_id);
36 
37  $this->setId('tblcrsprtgrp_' . $ref_id);
38 
39  parent::__construct($a_parent_obj, $a_parent_cmd);
40  // $this->setTitle($lng->txt("tr_summary"));
41  $this->setLimit(9999);
42  // $this->setShowTemplates(true);
43 
44  $this->setTitle($this->lng->txt('crs_grp_assignments'));
45 
46  $this->addColumn('', '', 0);
47  $this->addColumn($this->lng->txt("name"), "name", '35%');
48  $this->addColumn($this->lng->txt("login"), "login", '35%');
49  $this->addColumn($this->lng->txt("crs_groups_nr"), "groups_number");
50  $this->addColumn($this->lng->txt("groups"));
51 
52  // $this->setExternalSorting(true);
53  $this->setEnableHeader(true);
54  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
55  $this->setRowTemplate("tpl.crs_members_grp_row.html", "Modules/Course");
56  $this->setSelectAllCheckbox("usrs");
57 
58  $this->initGroups();
59 
60  if ($this->groups) {
61  $selectable_groups = [];
62  foreach ($this->groups as $ref_id => $something) {
63  if ($this->groups_rights[$ref_id]['manage_members']) {
64  $selectable_groups[$ref_id] = $this->groups[$ref_id];
65  }
66  }
67  if (count($selectable_groups)) {
69  "grp_id",
70  $selectable_groups,
71  "add",
72  $this->lng->txt("crs_add_to_group")
73  );
74  }
75  $this->initFilter();
76  }
77 
78 
79 
80  $this->getItems();
81  }
82 
86  public function initGroups()
87  {
88  global $DIC;
89 
90  $tree = $DIC['tree'];
91  $ilAccess = $DIC['ilAccess'];
92 
93  $parent_node = $tree->getNodeData($this->ref_id);
94  $groups = $tree->getSubTree($parent_node, true, "grp");
95  if (is_array($groups) && sizeof($groups)) {
96  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
97  $this->participants = $this->groups = $this->groups_rights = array();
98  foreach ($groups as $idx => $group_data) {
99  // check for group in group
100  if ($group_data["parent"] != $this->ref_id && $tree->checkForParentType($group_data["ref_id"], "grp", true)) {
101  unset($groups[$idx]);
102  } else {
103  $this->groups[$group_data["ref_id"]] = $group_data["title"];
104  $this->groups_rights[$group_data["ref_id"]]["manage_members"] = (bool)
105  $GLOBALS['DIC']->access()->checkRbacOrPositionPermissionAccess(
106  'manage_members',
107  'manage_members',
108  $group_data['ref_id']
109  )
110  ;
111 
112  $this->groups_rights[$group_data["ref_id"]]["edit_permission"] = (bool)
113  $GLOBALS['DIC']->access()->checkAccess(
114  "edit_permission",
115  "",
116  $group_data["ref_id"]
117  );
118 
119  $gobj = ilGroupParticipants::_getInstanceByObjId($group_data["obj_id"]);
120 
121  $members = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
122  'manage_members',
123  'manage_members',
124  $group_data['ref_id'],
125  $gobj->getMembers()
126  );
127  $admins = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
128  'manage_members',
129  'manage_members',
130  $group_data['ref_id'],
131  $gobj->getAdmins()
132  );
133 
134  $this->participants[$group_data["ref_id"]]["members"] = $members;
135  $this->participants[$group_data["ref_id"]]["admins"] = $admins;
136  }
137  }
138  }
139  }
140 
144  public function initFilter()
145  {
146  global $DIC;
147 
148  $lng = $DIC['lng'];
149 
150  $item = $this->addFilterItemByMetaType("name", ilTable2GUI::FILTER_TEXT);
151  $this->filter["name"] = $item->getValue();
152 
153  if ($this->groups) {
154  $item = $this->addFilterItemByMetaType("group", ilTable2GUI::FILTER_SELECT);
155  $item->setOptions(array("" => $lng->txt("all")) + $this->groups);
156  $this->filter["group"] = $item->getValue();
157  }
158  }
159 
163  public function getItems()
164  {
165  if ($this->groups) {
166  include_once('./Modules/Course/classes/class.ilCourseParticipants.php');
167  $part = ilCourseParticipants::_getInstanceByObjId($this->obj_id);
168  $members = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
169  'manage_members',
170  'manage_members',
171  $this->ref_id,
172  $part->getMembers()
173  );
174 
175  if (count($members)) {
176  include_once './Services/User/classes/class.ilUserUtil.php';
177  $usr_data = array();
178  foreach ($members as $usr_id) {
179  $name = ilObjUser::_lookupName($usr_id);
180  // #9984
181  $user_groups = array("members" => array(),"admins" => array());
182  $user_groups_number = 0;
183  foreach (array_keys($this->participants) as $group_id) {
184  if (in_array($usr_id, $this->participants[$group_id]["members"])) {
185  $user_groups["members"][$group_id] = $this->groups[$group_id];
186  $user_groups_number++;
187  } elseif (in_array($usr_id, $this->participants[$group_id]["admins"])) {
188  $user_groups["admins"][$group_id] = $this->groups[$group_id];
189  $user_groups_number++;
190  }
191  }
192 
193  if ((!$this->filter["name"] || stristr(implode("", $name), $this->filter["name"])) &&
194  (!$this->filter["group"] || array_key_exists($this->filter["group"], $user_groups["members"]) ||
195  array_key_exists($this->filter["group"], $user_groups["admins"]))) {
196  $usr_data[] = array("usr_id" => $usr_id,
197  "name" => $name["lastname"] . ", " . $name["firstname"],
198  "groups" => $user_groups,
199  "groups_number" => $user_groups_number,
200  "login" => $name["login"]
201  );
202  }
203  }
204 
205  // ???
206  $usr_data = array_slice($usr_data, (int) $this->getOffset(), (int) $this->getLimit());
207 
208  $this->setMaxCount(sizeof($members));
209  $this->setData($usr_data);
210  }
211 
212  return $titles;
213  }
214  }
215 
219  protected function fillRow($a_set)
220  {
221  global $DIC;
222 
223  $lng = $DIC['lng'];
224  $ilCtrl = $DIC['ilCtrl'];
225 
226  $this->tpl->setVariable("VAL_ID", $a_set["usr_id"]);
227 
228  $this->tpl->setVariable("TXT_USER", $a_set["name"]);
229  $this->tpl->setVariable("TXT_LOGIN", $a_set["login"]);
230  $this->tpl->setVariable("VAL_GROUP_NUMBER", $a_set["groups_number"]);
231 
232  if (sizeof($a_set["groups"])) {
233  foreach ($a_set["groups"] as $type => $groups) {
234  foreach ($groups as $grp_id => $title) {
235  if (
236  ($type == "admins" && $this->groups_rights[$grp_id]["edit_permission"]) ||
237  ($type == "members" && $this->groups_rights[$grp_id]["manage_members"])
238  ) {
239  $this->tpl->setCurrentBlock("groups_remove");
240 
241  $this->tpl->setVariable("TXT_GROUP_REMOVE", $lng->txt("grp_unsubscribe"));
242 
243  $ilCtrl->setParameter($this->parent_obj, "usr_id", $a_set["usr_id"]);
244  $ilCtrl->setParameter($this->parent_obj, "grp_id", $grp_id);
245  $this->tpl->setVariable("URL_REMOVE", $ilCtrl->getLinkTarget($this->parent_obj, "confirmremove"));
246  $ilCtrl->setParameter($this->parent_obj, "grp_id", "");
247  $ilCtrl->setParameter($this->parent_obj, "usr_id", "");
248 
249  $this->tpl->parseCurrentBlock();
250  }
251 
252  $this->tpl->setCurrentBlock("groups");
253  $this->tpl->setVariable("TXT_GROUP_TITLE", $title);
254  $this->tpl->parseCurrentBlock();
255  }
256  }
257  }
258  }
259 }
static _lookupName($a_user_id)
lookup user name
__construct($a_parent_obj, $a_parent_cmd, $ref_id)
Constructor.
$type
global $DIC
Definition: saml.php:7
initGroups()
find groups in course, exclude groups in groups
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
addFilterItemByMetaType($id, $type=self::FILTER_TEXT, $a_optional=false, $caption=null)
Add filter by standard type.
setId($a_val)
Set id.
global $ilCtrl
Definition: ilias.php:18
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
Class ilTable2GUI.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
getOffset()
Get offset.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
addMultiItemSelectionButton($a_sel_var, $a_options, $a_cmd, $a_text, $a_default_selection='')
Add Selection List + Command button for selected items.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
getItems()
Build item rows for given object and filter(s)
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setEnableHeader($a_enableheader)
Set Enable Header.
getLimit()
Get limit.
setMaxCount($a_max_count)
set max.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
setLimit($a_limit=0, $a_default_limit=0)