ILIAS  release_8 Revision v8.24
class.ilStudyProgrammeMembersTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Data;
22
24{
26 protected int $prg_obj_id;
27 protected bool $prg_has_lp_children;
30 protected bool $may_edit_anything;
32 protected ilObjUser $user;
36
37 public function __construct(
38 int $prg_obj_id,
39 int $prg_ref_id,
44 ILIAS\UI\Renderer $ui_renderer,
48 string $parent_cmd = '',
49 string $template_context = ''
50 ) {
51 $this->setId("sp_member_list_" . $prg_obj_id);
52 $this->prg_obj_id = $prg_obj_id;
53 $this->prg_user_table = $prg_user_table;
54 $this->custom_filter = $custom_filter;
55 parent::__construct($parent_obj, $parent_cmd, $template_context);
56
57 $this->data_factory = $data_factory;
58 $this->ui_factory = $ui_factory;
59 $this->ui_renderer = $ui_renderer;
60 $this->permissions = $permissions;
62 $this->user = $user;
63
64 $this->prg = ilObjStudyProgramme::getInstanceByRefId($prg_ref_id);
65 $this->prg_has_lp_children = $parent_obj->getStudyProgramme()->hasLPChildren();
66
67 $this->setEnableTitle(true);
68 $this->setTopCommands(false);
69 $this->setEnableHeader(true);
70 $this->setExternalSorting(true);
71 $this->setExternalSegmentation(true);
72 $this->setRowTemplate("tpl.members_table_row.html", "Modules/StudyProgramme");
73 $this->setShowRowsSelector(true);
74 $this->setFormAction($this->ctrl->getFormAction($parent_obj, "view"));
75 $this->addColumn("", "", "1", true);
76 $this->setEnableAllCommand(true);
77 $this->addMultiCommands();
78 $this->setDefaultOrderField('prgrs_id');
79 $this->setDefaultOrderDirection('ASC');
80
81 if ($this->may_edit_anything) {
82 $this->setSelectAllCheckbox($parent_obj::F_SELECTED_PROGRESS_IDS . '[]');
83 }
84
85 $selected = $this->getSelectedColumns();
86 foreach ($this->prg_user_table->getColumns($prg_obj_id) as $column) {
87 [$col, $lng_var, $optional, $lp, $no_lp] = $column;
88
89 $show_by_lp = ($this->prg_has_lp_children && $lp) || (!$this->prg_has_lp_children && $no_lp);
90 $show_optional = !$optional || ($optional && array_key_exists($col, $selected));
91
92 if ($show_by_lp && $show_optional) {
93 $this->addColumn($lng_var, $col);
94 }
95 }
96
97 $this->addColumn($this->lng->txt('action'), '');
98
99 $this->initFilter();
101 $this->determineLimit();
102
103 $valid_user_ids = $this->getValidUserIds();
104 $filter_values = $this->getFilterValues();
105
106 $order = $this->getOrdering();
107
108 $members_list = $this->prg_user_table->fetchData(
110 $valid_user_ids,
111 $order,
112 $this->custom_filter->withValues($filter_values),
113 $this->getLimit() ? (int) $this->getLimit() : null,
114 $this->getOffset()
115 );
116
117 $count = $this->prg_user_table->countFetchData(
119 $valid_user_ids,
120 $this->custom_filter->withValues($filter_values)
121 );
122 $this->setMaxCount($count);
123
124
125 $progress_ids = array_map(
126 function ($row) {
127 return (string) $row->getId();
128 },
129 $members_list
130 );
131 $this->addHiddenInput(
132 $parent_obj::F_ALL_PROGRESS_IDS,
133 implode(',', $progress_ids)
134 );
135
136 $this->setData($members_list);
137 }
138
139 protected function getOrdering(): Data\Order
140 {
141 $field = $this->getOrderField();
142 if (!$field) {
143 $field = $this->getDefaultOrderField();
144 }
145 $direction = $this->getOrderDirection();
146 if (!$direction) {
147 $direction = $this->getDefaultOrderDirection();
148 }
149
150 return $this->data_factory->order($field, strtoupper($direction));
151 }
152
153
154 protected function fillRow($row): void
155 {
156 if (!$row instanceof ilStudyProgrammeUserTableRow) {
157 throw new \Exception("use ilStudyProgrammeUserTableRow for data output", 1);
158 }
159
160 if ($this->may_edit_anything) {
161 $this->tpl->setCurrentBlock("checkb");
162 $this->tpl->setVariable("ID", (string) $row->getId());
163 $this->tpl->parseCurrentBlock();
164 }
165
166 if (!$row->isUserActiveRaw()) {
167 $this->tpl->setCurrentBlock('access_warning');
168 $this->tpl->setVariable('PARENT_ACCESS', $this->lng->txt('usr_account_inactive'));
169 $this->tpl->parseCurrentBlock();
170 }
171
172 $this->tpl->setVariable("FIRSTNAME", $row->getFirstname());
173 $this->tpl->setVariable("LASTNAME", $row->getLastname());
174 $this->tpl->setVariable("LOGIN", $row->getLogin());
175 $this->tpl->setVariable("STATUS", $row->getStatus());
176 $this->tpl->setVariable("ASSIGN_DATE", $row->getAssignmentDate());
177 $this->tpl->setVariable("POINTS_REQUIRED", $row->getPointsRequired());
178
179 if (!$this->prg_has_lp_children) {
180 $this->tpl->setCurrentBlock("points_current");
181 $this->tpl->setVariable("POINTS_CURRENT", $row->getPointsCurrent());
182 $this->tpl->parseCurrentBlock();
183 }
184
185 foreach ($this->getSelectedColumns() as $column) {
186 switch ($column) {
187 case "prg_orgus":
188 $this->tpl->setVariable("ORGUS", $row->getOrgUs());
189 break;
190 case "prg_completion_date":
191 $this->tpl->setVariable("COMPLETION_DATE", $row->getCompletionDate());
192 break;
193 case "prg_completion_by":
194
195 $completion_by = $row->getCompletionBy();
196 if ($completion_by_obj_ids = $row->getCompletionByObjIds()) {
197 $out = [];
198 foreach ($completion_by_obj_ids as $completion_by_obj_id) {
199 $type = ilObject::_lookupType($completion_by_obj_id);
200 if ($type === 'crs') {
201 $out[] = $this->getCompletionLink($completion_by_obj_id, $completion_by);
202 } else {
203 $target_obj_id = $completion_by_obj_id;
204 $out[] = $this->getCompletionLink(
205 $target_obj_id,
206 ilStudyProgrammeUserTable::lookupTitle($completion_by_obj_id)
207 );
208 }
209 }
210 $completion_by = implode(', ', $out);
211 }
212 $this->tpl->setVariable("COMPLETION_BY", $completion_by);
213 break;
214 case "prg_custom_plan":
215 $this->tpl->setVariable("CUSTOM_PLAN", $row->getCustomPlan());
216 break;
217 case "prg_belongs_to":
218 $this->tpl->setVariable("BELONGS_TO", $row->getBelongsTo());
219 break;
220 case "prg_expiry_date":
221 $this->tpl->setVariable("EXPIRY_DATE", $row->getExpiryDate());
222 break;
223 case "prg_assigned_by":
224 $this->tpl->setVariable("ASSIGNED_BY", $row->getAssignmentBy());
225 break;
226 case "prg_deadline":
227 $this->tpl->setVariable("DEADLINE", $row->getDeadline());
228 break;
229 case "prg_validity":
230 $this->tpl->setVariable("VALIDITY", $row->getValidity());
231 break;
232 case 'org_units':
233 $this->tpl->setCurrentBlock('udf');
234 $this->tpl->setVariable("UDF", $row->getOrgUs());
235 $this->tpl->parseCurrentBlock();
236 break;
237 case 'gender':
238 $this->tpl->setCurrentBlock('udf');
239 $this->tpl->setVariable("UDF", $row->getGender());
240 $this->tpl->parseCurrentBlock();
241 break;
242
243 case strpos($column, 'udf_') === 0:
244 $id = str_replace('udf_', 'f_', $column);
245 $this->tpl->setCurrentBlock('udf');
246 $this->tpl->setVariable("UDF", $row->getUDF($id));
247 $this->tpl->parseCurrentBlock();
248 break;
249 default:
250 $this->tpl->setCurrentBlock('udf');
251 $this->tpl->setVariable("UDF", $row->getUDF($column));
252 $this->tpl->parseCurrentBlock();
253 }
254 }
255 $actions = $this->getPossibleActions(
256 $row->isRootProgress(),
257 $row->getStatusRaw()
258 );
259
260 $this->tpl->setVariable(
261 "ACTIONS",
262 $this->buildActionDropDown(
263 $actions,
264 (string) $row->getId(),
265 $row->getAssignmentId()
266 )
267 );
268 }
269
270 protected function buildActionDropDown(
271 array $actions,
272 string $prgrs_id,
273 int $ass_id
274 ): string {
276
277 $view_individual_plan = $this->permissions->may(ilOrgUnitOperation::OP_VIEW_INDIVIDUAL_PLAN);
278 $edit_individual_plan = $this->permissions->may(ilOrgUnitOperation::OP_EDIT_INDIVIDUAL_PLAN);
279 $addremove_users = $this->permissions->may(ilOrgUnitOperation::OP_MANAGE_MEMBERS);
280
281 foreach ($actions as $action) {
282 switch ($action) {
291 if (!$edit_individual_plan) {
292 continue 2;
293 }
294 break;
296 if (!$view_individual_plan) {
297 continue 2;
298 }
299 break;
300
302 if (!$addremove_users) {
303 continue 2;
304 }
305 break;
306 }
307
308 $target = $this->getLinkTargetForAction($action, $prgrs_id, $ass_id);
309 $l->addItem($this->lng->txt("prg_$action"), $action, $target);
310 }
311
312 return $l->getHTML();
313 }
314
315
316 protected function getLinkTargetForAction(string $action, string $prgrs_id, int $ass_id): string
317 {
318 return $this->getParentObject()->getLinkTargetForAction($action, $prgrs_id, $ass_id);
319 }
320
321 public function getSelectableColumns(): array
322 {
323 $cols = [];
324 foreach ($this->prg_user_table->getColumns($this->prg_obj_id) as $column) {
325 [$col, $lng_var, $optional, $lp, $no_lp] = $column;
326 if ($optional) {
327 $cols[$col] = ["txt" => $lng_var];
328 }
329 }
330
331 return $cols;
332 }
333
334 protected function addMultiCommands(): void
335 {
336 foreach ($this->getMultiCommands() as $cmd => $caption) {
337 $this->addMultiCommand($cmd, $caption);
338 }
339 }
340
346 protected function getMultiCommands(): array
347 {
348 $permissions_for_edit_individual_plan = [
349 'updateFromCurrentPlanMulti' => $this->lng->txt('prg_multi_update_from_current_plan'),
350 'acknowledgeCoursesMulti' => $this->lng->txt('prg_acknowledge_completed_courses'),
351 'markRelevantMulti' => $this->lng->txt('prg_multi_mark_relevant'),
352 'markNotRelevantMulti' => $this->lng->txt('prg_multi_unmark_relevant'),
353 'changeDeadlineMulti' => $this->lng->txt('prg_multi_change_deadline'),
354 'changeExpireDateMulti' => $this->lng->txt('prg_multi_change_expire_date'),
355 'markAccreditedMulti' => $this->lng->txt('prg_multi_mark_accredited'),
356 'unmarkAccreditedMulti' => $this->lng->txt('prg_multi_unmark_accredited')
357 ];
358
359 $permissions_for_manage = [
360 'removeUserMulti' => $this->lng->txt('prg_multi_remove_user'),
361 'mailUserMulti' => $this->lng->txt('prg_multi_mail_user')
362 ];
363
364 $perms = [];
365
366 if ($this->permissions->may(ilOrgUnitOperation::OP_EDIT_INDIVIDUAL_PLAN)) {
367 $perms = array_merge($perms, $permissions_for_edit_individual_plan);
368 }
369
370 if ($this->permissions->may(ilOrgUnitOperation::OP_MANAGE_MEMBERS)) {
371 $perms = array_merge($perms, $permissions_for_manage);
372 }
373
374 return $perms;
375 }
376
380 public function initFilter(): void
381 {
382 foreach ($this->custom_filter->getItemConfig() as $conf) {
383 [$id, $type, $options, $caption] = $conf;
384 $item = $this->addFilterItemByMetaType($id, $type, false, $caption);
385 if ($options) {
386 $item->setOptions($options);
387 }
388 }
389 }
390
394 protected function getFilterValues(): array
395 {
396 $this->getCurrentState();
397 $f = [];
398 foreach ($this->filters as $item) {
399 $f[$item->getFieldId()] = $this->getFilterValue($item);
400 }
401 return $f;
402 }
403
409 protected function getPossibleActions(
410 bool $is_root,
411 int $status
412 ): array {
413 $actions = [];
414
415 if ($is_root) {
424 }
425
426 if ($status == ilPRGProgress::STATUS_ACCREDITED) {
428 }
429 if ($status == ilPRGProgress::STATUS_IN_PROGRESS) {
431 }
432
433 return $actions;
434 }
435
436 protected function getValidUserIds(): ?array
437 {
438 if ($this->permissions->may($this->permissions::ROLEPERM_MANAGE_MEMBERS)) {
439 return null;
440 }
441
442 $valid_user_ids = $this->permissions->getUserIdsSusceptibleTo(ilOrgUnitOperation::OP_VIEW_MEMBERS);
443 array_unshift($valid_user_ids, $this->user->getId());
444 return $valid_user_ids;
445 }
446
447 protected function getCompletionLink(int $reference_obj_id, string $title): string
448 {
449 $link = $title;
450 $target_obj_id = ilContainerReference::_lookupTargetId($reference_obj_id);
451 $ref_ids = ilObject::_getAllReferences($target_obj_id);
452 foreach ($ref_ids as $ref_id) {
455 $link = $this->ui_renderer->render($this->ui_factory->link()->standard($title, $url));
456 }
457 }
458 return $link;
459 }
460}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$out
Definition: buildRTE.php:24
Builds data types.
Definition: Factory.php:21
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:13
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupTargetId(int $a_obj_id)
@ilCtrl_Calls ilObjStudyProgrammeMembersGUI: ilStudyProgrammeRepositorySearchGUI @ilCtrl_Calls ilObjS...
User class.
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _isInTrash(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPossibleActions(bool $is_root, int $status)
Get a list with possible actions on a progress record.
getLinkTargetForAction(string $action, string $prgrs_id, int $ass_id)
__construct(int $prg_obj_id, int $prg_ref_id, ilObjStudyProgrammeMembersGUI $parent_obj, ilPRGPermissionsHelper $permissions, Data\Factory $data_factory, ILIAS\UI\Factory $ui_factory, ILIAS\UI\Renderer $ui_renderer, ilStudyProgrammeUserTable $prg_user_table, ilPRGAssignmentFilter $custom_filter, ilObjUser $user, string $parent_cmd='', string $template_context='')
getCompletionLink(int $reference_obj_id, string $title)
buildActionDropDown(array $actions, string $prgrs_id, int $ass_id)
ilStudyProgrammeUserTable provides a flattened list of progresses at a programme-node.
ilStudyProgrammeUserTable provides a flattened list of progresses at a programme-node.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setEnableAllCommand(bool $a_value)
determineOffsetAndOrder(bool $a_omit_offset=false)
setExternalSegmentation(bool $a_val)
setEnableTitle(bool $a_enabletitle)
addHiddenInput(string $a_name, string $a_value)
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)
setDefaultOrderField(string $a_defaultorderfield)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setTopCommands(bool $a_val)
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setData(array $a_data)
Set table data.
setMaxCount(int $a_max_count)
set max.
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
$ref_id
Definition: ltiauth.php:67
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$type
$url
$cols
Definition: xhr_table.php:11