ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilCourseParticipantsGroupsTableGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=0);
24{
25 protected int $ref_id;
26 protected int $obj_id;
27 protected array $filter = [];
28 protected array $groups = [];
29 protected array $groups_rights = [];
30 protected array $participants = [];
31
33 protected ilTree $tree;
34
38 public function __construct(object $a_parent_obj, string $a_parent_cmd, int $ref_id)
39 {
40 global $DIC;
41
42 $this->access = $DIC->access();
43 $this->tree = $DIC->repositoryTree();
44
45 $this->ref_id = $ref_id;
46 $this->obj_id = ilObject::_lookupObjId($ref_id);
47
48 $this->setId('tblcrsprtgrp_' . $ref_id);
49 parent::__construct($a_parent_obj, $a_parent_cmd);
50 $this->lng->loadLanguageModule('grp');
51 $this->setLimit(9999);
52
53 $this->setTitle($this->lng->txt('crs_grp_assignments'));
54
55 $this->addColumn('', '', '0');
56 $this->addColumn($this->lng->txt("name"), "name", '35%');
57 $this->addColumn($this->lng->txt("login"), "login", '35%');
58 $this->addColumn($this->lng->txt("crs_groups_nr"), "groups_number");
59 $this->addColumn($this->lng->txt("groups"));
60
61 $this->setEnableHeader(true);
62 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
63 $this->setRowTemplate("tpl.crs_members_grp_row.html", "Modules/Course");
64 $this->setSelectAllCheckbox("usrs");
65
66 $this->initGroups();
67
68 if ($this->groups) {
69 $selectable_groups = [];
70 foreach ($this->groups as $ref_id => $something) {
71 if ($this->groups_rights[$ref_id]['manage_members']) {
72 $selectable_groups[$ref_id] = $this->groups[$ref_id];
73 }
74 }
75 if ($selectable_groups !== []) {
77 "grp_id",
78 $selectable_groups,
79 "add",
80 $this->lng->txt("crs_add_to_group")
81 );
82 }
83 $this->initFilter();
84 }
85 $this->getItems();
86 }
87
91 public function initGroups(): void
92 {
93 $parent_node = $this->tree->getNodeData($this->ref_id);
94 $groups = $this->tree->getSubTree($parent_node, true, ['grp']);
95 if (is_array($groups) && count($groups)) {
96 $this->participants = $this->groups = $this->groups_rights = array();
97 foreach ($groups as $idx => $group_data) {
98 // check for group in group
99 if ($group_data["parent"] != $this->ref_id && $this->tree->checkForParentType(
100 $group_data["ref_id"],
101 "grp",
102 true
103 )) {
104 unset($groups[$idx]);
105 } else {
106 $this->groups[$group_data["ref_id"]] = $group_data["title"];
107 $this->groups_rights[$group_data["ref_id"]]["manage_members"] = $this->access->checkRbacOrPositionPermissionAccess(
108 'manage_members',
109 'manage_members',
110 $group_data['ref_id']
111 );
112
113 $this->groups_rights[$group_data["ref_id"]]["edit_permission"] = $this->access->checkAccess(
114 "edit_permission",
115 "",
116 $group_data["ref_id"]
117 );
118
119 $gobj = ilGroupParticipants::_getInstanceByObjId($group_data["obj_id"]);
120
121 $members = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
122 'manage_members',
123 'manage_members',
124 $group_data['ref_id'],
125 $gobj->getMembers()
126 );
127 $admins = $this->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(): void
145 {
147 $this->filter["name"] = $item->getValue();
148
149 if ($this->groups) {
151 $item->setOptions(array("" => $this->lng->txt("all")) + $this->groups);
152 $this->filter["group"] = $item->getValue();
153 }
154 }
155
156 public function getItems(): void
157 {
158 if ($this->groups) {
159 $part = ilCourseParticipants::_getInstanceByObjId($this->obj_id);
160 $members = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
161 'manage_members',
162 'manage_members',
163 $this->ref_id,
164 $part->getMembers()
165 );
166
167 if ($members !== []) {
168 $usr_data = array();
169 foreach ($members as $usr_id) {
170 $name = ilObjUser::_lookupName($usr_id);
171 $user_groups = array("members" => array(), "admins" => array());
172 $user_groups_number = 0;
173 foreach (array_keys($this->participants) as $group_id) {
174 if (in_array($usr_id, $this->participants[$group_id]["members"])) {
175 $user_groups["members"][$group_id] = $this->groups[$group_id];
176 $user_groups_number++;
177 } elseif (in_array($usr_id, $this->participants[$group_id]["admins"])) {
178 $user_groups["admins"][$group_id] = $this->groups[$group_id];
179 $user_groups_number++;
180 }
181 }
182
183 if ((!$this->filter["name"] || stristr(implode("", $name), $this->filter["name"])) &&
184 (!$this->filter["group"] || array_key_exists($this->filter["group"], $user_groups["members"]) ||
185 array_key_exists($this->filter["group"], $user_groups["admins"]))) {
186 $usr_data[] = array("usr_id" => $usr_id,
187 "name" => $name["lastname"] . ", " . $name["firstname"],
188 "groups" => $user_groups,
189 "groups_number" => $user_groups_number,
190 "login" => $name["login"]
191 );
192 }
193 }
194
195 $usr_data = array_slice($usr_data, $this->getOffset(), $this->getLimit());
196 $this->setMaxCount(count($members));
197 $this->setData($usr_data);
198 }
199 }
200 }
201
202 protected function fillRow(array $a_set): void
203 {
204 $this->tpl->setVariable("VAL_ID", $a_set["usr_id"]);
205
206 $this->tpl->setVariable("TXT_USER", $a_set["name"]);
207 $this->tpl->setVariable("TXT_LOGIN", $a_set["login"]);
208 $this->tpl->setVariable("VAL_GROUP_NUMBER", $a_set["groups_number"]);
209
210 if (count($a_set["groups"]) !== 0) {
211 foreach ($a_set["groups"] as $type => $groups) {
212 foreach ($groups as $grp_id => $title) {
213 if (
214 ($type == "admins" && $this->groups_rights[$grp_id]["edit_permission"]) ||
215 ($type == "members" && $this->groups_rights[$grp_id]["manage_members"])
216 ) {
217 $this->tpl->setCurrentBlock("groups_remove");
218
219 $this->tpl->setVariable("TXT_GROUP_REMOVE", $this->lng->txt("grp_unsubscribe"));
220
221 $this->ctrl->setParameter($this->parent_obj, "usr_id", $a_set["usr_id"]);
222 $this->ctrl->setParameter($this->parent_obj, "grp_id", $grp_id);
223 $this->tpl->setVariable(
224 "URL_REMOVE",
225 $this->ctrl->getLinkTarget($this->parent_obj, "confirmremove")
226 );
227 $this->ctrl->setParameter($this->parent_obj, "grp_id", "");
228 $this->ctrl->setParameter($this->parent_obj, "usr_id", "");
229
230 $this->tpl->parseCurrentBlock();
231 }
232
233 $this->tpl->setCurrentBlock("groups");
234 $this->tpl->setVariable("TXT_GROUP_TITLE", $title);
235 $this->tpl->parseCurrentBlock();
236 }
237 }
238 }
239 }
240}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initGroups()
find groups in course, exclude groups in groups
__construct(object $a_parent_obj, string $a_parent_cmd, int $ref_id)
Constructor.
fillRow(array $a_set)
Standard Version of Fill Row.
static _getInstanceByObjId(int $a_obj_id)
static _getInstanceByObjId(int $a_obj_id)
Get singleton instance.
static _lookupName(int $a_user_id)
lookup user name
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setEnableHeader(bool $a_enableheader)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
addMultiItemSelectionButton(string $a_sel_var, array $a_options, string $a_cmd, string $a_text, string $a_default_selection='')
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setData(array $a_data)
Set table data.
setMaxCount(int $a_max_count)
set max.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($format !==null) $name
Definition: metadata.php:247
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type