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