ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilCourseParticipantsGroupsTableDataRetrieval.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\UI\Component\Table\DataRetrieval as ilTableDataRetrievalInterface;
22use ILIAS\DI\UIServices as ilUIServices;
23
24class ilCourseParticipantsGroupsTableDataRetrieval implements ilTableDataRetrievalInterface
25{
26 protected const string TABLE_ACTION_CONFIRM_UNSUBSCRIBE_SUFFIX = '_confirm_unsubscribe';
27 protected const string TABLE_ACTION_UNSUBSCRIBE_SUFFIX = '_unsubscribe';
28
29 protected array $data;
30 protected int $obj_id;
31
32 public function __construct(
33 protected ilCourseParticipantsGroupsGUI $parent_obj,
34 protected ilTree $tree,
35 protected ilAccess $access,
36 protected ilUIServices $ui_services,
37 protected int $ref_id
38 ) {
39 $this->data = [];
40 $this->obj_id = ilObject::_lookupObjId($ref_id);
41 }
42
43 protected function applyFilter(
44 ?array $filter_data
45 ): array {
46 if (is_null($filter_data)) {
47 return $this->data['rows'] ?? [];
48 }
55 $group_ids = is_null($select->getValue()) ? [] : [(int) $select->getValue()];
56 $group_ids = array_diff($group_ids, [0]);
57 $name = $text->getValue() ?? '';
58 $rows = [];
59 foreach ($this->data['rows'] ?? [] as $row) {
60 $row_group_ids = [];
61 foreach ($row['groups'] as $group) {
62 $row_group_ids[] = $group['group_id'];
63 }
64 if (
65 !$select->isDisabled() &&
66 count($group_ids) > 0 &&
67 count(array_diff($group_ids, $row_group_ids)) === count($group_ids)
68 ) {
69 continue;
70 }
71 if (
72 !$text->isDisabled() &&
73 $name !== '' &&
74 !str_contains($row['name'], $name)
75 ) {
76 continue;
77 }
78 $rows[] = $row;
79 }
80 return $rows;
81 }
82
84 int $group_ref_id
85 ): string {
86 return $group_ref_id . self::TABLE_ACTION_CONFIRM_UNSUBSCRIBE_SUFFIX;
87 }
88
89 public function buildUnsubscribeActionId(
90 int $group_ref_id
91 ): string {
92 return $group_ref_id . self::TABLE_ACTION_UNSUBSCRIBE_SUFFIX;
93 }
94
95 public function getAllConfirmUnsubscribeActionIds(): array
96 {
97 $ids = [];
98 foreach ($this->getSelectableGroups() as $ref_id => $group) {
99 $ids[] = $this->buildConfirmUnsubscribeActionId($ref_id);
100 }
101 return $ids;
102 }
103
104 public function getAllUserIds(): array
105 {
106 # TODO: Filter
107 $ids = [];
108 foreach ($this->data['rows'] ?? [] as $row) {
109 $ids[] = (int) $row['usr_id'];
110 }
111 return $ids;
112 }
113
114 public function getSelectableGroups(): array
115 {
116 $selectable_group_ids = [];
117 foreach ($this->data['groups'] ?? [] as $ref_id => $something) {
118 if ($this->data['groups_rights'][$ref_id]['manage_members']) {
119 $selectable_group_ids[$ref_id] = $this->data['groups'][$ref_id];
120 }
121 }
122 return $selectable_group_ids;
123 }
124
125 public function getRows(
126 \ILIAS\UI\Component\Table\DataRowBuilder $row_builder,
127 array $visible_column_ids,
128 \ILIAS\Data\Range $range,
129 \ILIAS\Data\Order $order,
130 mixed $additional_viewcontrol_data,
131 mixed $filter_data,
132 mixed $additional_parameters
133 ): Generator {
134 [$column_name, $direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
135 $rows = $this->applyFilter($filter_data);
136 $groups_rights = $this->data['groups_rights'] ?? [];
137 $comparator = function (array $f1, array $f2) { return 0; };
138 switch ($column_name) {
140 $comparator = function (array $f1, array $f2) {
141 return strcmp($f1['name'], $f2['name']);
142 };
143 break;
145 $comparator = function (array $f1, array $f2) {
146 return strcmp($f1['login'], $f2['login']);
147 };
148 break;
150 $comparator = function (array $f1, array $f2) {
151 if ($f1['groups_number'] === $f2['groups_number']) {
152 return 0;
153 }
154 return $f1['groups_number'] > $f2['groups_number'] ? 1 : -1;
155 };
156 break;
158 $comparator = function (array $f1, array $f2) {
159 return strcmp($f1['group_info']['title'], $f2['group_info']['title']);
160 };
161 break;
162 }
163 uasort($rows, $comparator);
164 if ($direction === "DESC") {
165 $rows = array_reverse($rows, true);
166 }
167 $rows = array_slice($rows, $range->getStart(), $range->getLength(), true);
168 foreach ($rows as $row) {
169 $groups_str = '';
170 $enabled_actions = [];
171 foreach ($row['groups'] as $group_info) {
172 $grp_id = $group_info['group_id'];
173 $role = $group_info['role'];
174 $title = $group_info['title'];
175 if (
176 !($role == 'admin' && $groups_rights[$grp_id]['edit_permission']) &&
177 !($role == 'member' && $groups_rights[$grp_id]['manage_members'])
178 ) {
179 continue;
180 }
181 $groups_str .= ($groups_str === '' ? $title : '<br>' . $title);
182 $enabled_actions[] = $this->buildConfirmUnsubscribeActionId($grp_id);
183 }
184 $data_row = $row_builder->buildDataRow(
185 $row['usr_id'] . '',
186 [
191 ]
192 );
193 $disabled_actions = array_diff($this->getAllConfirmUnsubscribeActionIds(), $enabled_actions);
194 foreach ($disabled_actions as $disabled_action) {
195 $data_row = $data_row->withDisabledAction($disabled_action, true);
196 }
197 yield $data_row;
198 }
199 }
200
201 public function getTotalRowCount(
202 mixed $additional_viewcontrol_data,
203 mixed $filter_data,
204 mixed $additional_parameters
205 ): ?int {
206 return count($this->applyFilter($filter_data));
207 }
208
209 public function init(): void
210 {
211 $parent_node = $this->tree->getNodeData($this->ref_id);
212 $groups = $this->tree->getSubTree($parent_node, true, ['grp']);
213 if (
214 !is_array($groups) ||
215 !count($groups)
216 ) {
217 return;
218 }
219 $results_participants = [];
220 $results_groups = [];
221 $results_groups_rights = [];
222 foreach ($groups as $idx => $group_data) {
223 # check for group in group
224 if (
225 $group_data['parent'] != $this->ref_id &&
226 $this->tree->checkForParentType(
227 $group_data['ref_id'],
228 'grp',
229 true
230 )
231 ) {
232 unset($groups[$idx]);
233 continue;
234 }
235 $results_groups[$group_data['ref_id']] = $group_data['title'];
236 $results_groups_rights[$group_data['ref_id']]['manage_members'] = $this->access->checkRbacOrPositionPermissionAccess(
237 'manage_members',
238 'manage_members',
239 $group_data['ref_id']
240 );
241 $results_groups_rights[$group_data['ref_id']]['edit_permission'] = $this->access->checkAccess(
242 'edit_permission',
243 '',
244 $group_data['ref_id']
245 );
246 $gobj = ilGroupParticipants::_getInstanceByObjId($group_data['obj_id']);
247 $members = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
248 'manage_members',
249 'manage_members',
250 $group_data['ref_id'],
251 $gobj->getMembers()
252 );
253 $admins = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
254 'manage_members',
255 'manage_members',
256 $group_data['ref_id'],
257 $gobj->getAdmins()
258 );
259 $results_participants[$group_data['ref_id']]['members'] = $members;
260 $results_participants[$group_data['ref_id']]['admins'] = $admins;
261 }
262 $part = ilCourseParticipants::_getInstanceByObjId($this->obj_id);
263 $members = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
264 'manage_members',
265 'manage_members',
266 $this->ref_id,
267 $part->getMembers()
268 );
269 if ($members === []) {
270 return;
271 }
272 $usr_data = [];
273 foreach ($members as $usr_id) {
274 $name = ilObjUser::_lookupName($usr_id);
275 $membership_count = 0;
276 $new_entry = [
277 'usr_id' => $usr_id,
278 'name' => $name['lastname'] . ', ' . $name['firstname'],
279 'groups' => [],
280 'login' => $name['login']
281 ];
282 foreach (array_keys($results_participants) as $group_id) {
283 $group_info = [
284 'group_id' => $group_id,
285 'title' => $results_groups[$group_id],
286 'role' => ''
287 ];
288 if (in_array($usr_id, $results_participants[$group_id]['members'])) {
289 $group_info['role'] = 'member';
290 }
291 if (in_array($usr_id, $results_participants[$group_id]['admins'])) {
292 $group_info['role'] = 'admin';
293 }
294 if ($group_info['role'] === '') {
295 continue;
296 }
297 $new_entry['groups'][] = $group_info;
298 $membership_count++;
299 }
300 $new_entry['groups_number'] = $membership_count;
301 $usr_data[] = $new_entry;
302 }
303 $this->data['rows'] = $usr_data;
304 $this->data['groups'] = $results_groups;
305 $this->data['groups_rights'] = $results_groups_rights;
306 }
307}
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Class ilAccessHandler Checks access for ILIAS objects.
Class ilCourseParticipantsGroupsGUI.
getTotalRowCount(mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
__construct(protected ilCourseParticipantsGroupsGUI $parent_obj, protected ilTree $tree, protected ilAccess $access, protected ilUIServices $ui_services, protected int $ref_id)
getRows(\ILIAS\UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, \ILIAS\Data\Range $range, \ILIAS\Data\Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
static _getInstanceByObjId(int $a_obj_id)
static _getInstanceByObjId(int $a_obj_id)
Get singleton instance.
static _lookupName(int $a_user_id)
static _lookupObjId(int $ref_id)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:66
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
if(!file_exists('../ilias.ini.php'))
$text
Definition: xapiexit.php:21