ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
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) {
138 return 0;
139 };
140 switch ($column_name) {
142 $comparator = function (array $f1, array $f2) {
143 return strcmp($f1['name'], $f2['name']);
144 };
145 break;
147 $comparator = function (array $f1, array $f2) {
148 return strcmp($f1['login'], $f2['login']);
149 };
150 break;
152 $comparator = function (array $f1, array $f2) {
153 if ($f1['groups_number'] === $f2['groups_number']) {
154 return 0;
155 }
156 return $f1['groups_number'] > $f2['groups_number'] ? 1 : -1;
157 };
158 break;
160 $comparator = function (array $f1, array $f2) {
161 return strcmp($f1['group_info']['title'], $f2['group_info']['title']);
162 };
163 break;
164 }
165 uasort($rows, $comparator);
166 if ($direction === "DESC") {
167 $rows = array_reverse($rows, true);
168 }
169 $rows = array_slice($rows, $range->getStart(), $range->getLength(), true);
170 foreach ($rows as $row) {
171 $groups_str = '';
172 $enabled_actions = [];
173 foreach ($row['groups'] as $group_info) {
174 $grp_id = $group_info['group_id'];
175 $role = $group_info['role'];
176 $title = $group_info['title'];
177 if (
178 !($role == 'admin' && $groups_rights[$grp_id]['edit_permission']) &&
179 !($role == 'member' && $groups_rights[$grp_id]['manage_members'])
180 ) {
181 continue;
182 }
183 $groups_str .= ($groups_str === '' ? $title : '<br>' . $title);
184 $enabled_actions[] = $this->buildConfirmUnsubscribeActionId($grp_id);
185 }
186 $data_row = $row_builder->buildDataRow(
187 $row['usr_id'] . '',
188 [
193 ]
194 );
195 $disabled_actions = array_diff($this->getAllConfirmUnsubscribeActionIds(), $enabled_actions);
196 foreach ($disabled_actions as $disabled_action) {
197 $data_row = $data_row->withDisabledAction($disabled_action, true);
198 }
199 yield $data_row;
200 }
201 }
202
203 public function getTotalRowCount(
204 mixed $additional_viewcontrol_data,
205 mixed $filter_data,
206 mixed $additional_parameters
207 ): ?int {
208 return count($this->applyFilter($filter_data));
209 }
210
211 public function init(): void
212 {
213 $parent_node = $this->tree->getNodeData($this->ref_id);
214 $groups = $this->tree->getSubTree($parent_node, true, ['grp']);
215 if (
216 !is_array($groups) ||
217 !count($groups)
218 ) {
219 return;
220 }
221 $results_participants = [];
222 $results_groups = [];
223 $results_groups_rights = [];
224 foreach ($groups as $idx => $group_data) {
225 # check for group in group
226 if (
227 $group_data['parent'] != $this->ref_id &&
228 $this->tree->checkForParentType(
229 $group_data['ref_id'],
230 'grp',
231 true
232 )
233 ) {
234 unset($groups[$idx]);
235 continue;
236 }
237 $results_groups[$group_data['ref_id']] = $group_data['title'];
238 $results_groups_rights[$group_data['ref_id']]['manage_members'] = $this->access->checkRbacOrPositionPermissionAccess(
239 'manage_members',
240 'manage_members',
241 $group_data['ref_id']
242 );
243 $results_groups_rights[$group_data['ref_id']]['edit_permission'] = $this->access->checkAccess(
244 'edit_permission',
245 '',
246 $group_data['ref_id']
247 );
248 $gobj = ilGroupParticipants::_getInstanceByObjId($group_data['obj_id']);
249 $members = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
250 'manage_members',
251 'manage_members',
252 $group_data['ref_id'],
253 $gobj->getMembers()
254 );
255 $admins = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
256 'manage_members',
257 'manage_members',
258 $group_data['ref_id'],
259 $gobj->getAdmins()
260 );
261 $results_participants[$group_data['ref_id']]['members'] = $members;
262 $results_participants[$group_data['ref_id']]['admins'] = $admins;
263 }
264 $part = ilCourseParticipants::_getInstanceByObjId($this->obj_id);
265 $members = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
266 'manage_members',
267 'manage_members',
268 $this->ref_id,
269 $part->getMembers()
270 );
271 if ($members === []) {
272 return;
273 }
274 $usr_data = [];
275 foreach ($members as $usr_id) {
276 $name = ilObjUser::_lookupName($usr_id);
277 $membership_count = 0;
278 $new_entry = [
279 'usr_id' => $usr_id,
280 'name' => $name['lastname'] . ', ' . $name['firstname'],
281 'groups' => [],
282 'login' => $name['login']
283 ];
284 foreach (array_keys($results_participants) as $group_id) {
285 $group_info = [
286 'group_id' => $group_id,
287 'title' => $results_groups[$group_id],
288 'role' => ''
289 ];
290 if (in_array($usr_id, $results_participants[$group_id]['members'])) {
291 $group_info['role'] = 'member';
292 }
293 if (in_array($usr_id, $results_participants[$group_id]['admins'])) {
294 $group_info['role'] = 'admin';
295 }
296 if ($group_info['role'] === '') {
297 continue;
298 }
299 $new_entry['groups'][] = $group_info;
300 $membership_count++;
301 }
302 $new_entry['groups_number'] = $membership_count;
303 $usr_data[] = $new_entry;
304 }
305 $this->data['rows'] = $usr_data;
306 $this->data['groups'] = $results_groups;
307 $this->data['groups_rights'] = $results_groups_rights;
308 }
309}
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