Skip to content

Commit efb1390

Browse files
committed
exercise: team table
1 parent ab4e0e9 commit efb1390

7 files changed

Lines changed: 254 additions & 151 deletions

File tree

components/ILIAS/Exercise/Service/classes/class.InternalDomainService.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use ILIAS\Exercise\Submission\PublicSubmissionsRetrieval;
3131
use ILIAS\Exercise\Submission\TextSubmissionsRetrieval;
3232
use ILIAS\Exercise\Team\TeamLogRetrieval;
33+
use ILIAS\Exercise\Team\TeamMembersRetrieval;
3334
use ILIAS\Exercise\PeerReview\PeerReviewOverviewRetrieval;
3435
use ILIAS\Exercise\TutorFeedbackFile\MultiFeedbackConfirmationRetrieval;
3536
use ILIAS\Exercise\PeerReview\DomainService;
@@ -102,6 +103,19 @@ public function teamLogRetrieval(\ilExAssignmentTeam $team): TeamLogRetrieval
102103
return new TeamLogRetrieval($this, $team);
103104
}
104105

106+
public function teamMembersRetrieval(
107+
\ilExAssignmentTeam $team,
108+
int $parent_ref_id,
109+
bool $edit_permission
110+
): TeamMembersRetrieval {
111+
return new TeamMembersRetrieval(
112+
$this,
113+
$team,
114+
$parent_ref_id,
115+
$edit_permission
116+
);
117+
}
118+
105119
public function peerReviewOverviewRetrieval(
106120
\ilExAssignment $assignment
107121
): PeerReviewOverviewRetrieval {

components/ILIAS/Exercise/Service/classes/class.InternalGUIService.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,24 @@ public function teamLogTableBuilder(
197197
);
198198
}
199199

200+
public function teamMembersTableBuilder(
201+
\ilExAssignmentTeam $team,
202+
int $parent_ref_id,
203+
bool $read_only,
204+
object $parent_gui,
205+
string $parent_cmd
206+
): \ILIAS\Exercise\Team\TeamMembersTableBuilder {
207+
return new \ILIAS\Exercise\Team\TeamMembersTableBuilder(
208+
$this->domain_service,
209+
$this,
210+
$team,
211+
$parent_ref_id,
212+
$read_only,
213+
$parent_gui,
214+
$parent_cmd
215+
);
216+
}
217+
200218
public function peerReviewOverviewTableBuilder(
201219
\ilExAssignment $assignment,
202220
object $parent_gui,

components/ILIAS/Exercise/Submission/class.ilExSubmissionTeamGUI.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,19 @@ public function submissionScreenTeamObject(): void
346346
$this->tpl->setOnScreenMessage('info', $this->lng->txt("exc_no_team_yet_info_tutor"));
347347
}
348348

349-
$tbl = new ilExAssignmentTeamTableGUI(
350-
$this,
351-
"submissionScreenTeam",
352-
ilExAssignmentTeamTableGUI::MODE_EDIT,
353-
$this->exercise->getRefId(),
349+
$table = $this->gui->teamMembersTableBuilder(
354350
$this->team,
355-
$read_only
356-
);
351+
$this->exercise->getRefId(),
352+
$read_only,
353+
$this,
354+
"submissionScreenTeam"
355+
)->getTable();
357356

358-
$this->tpl->setContent($tbl->getHTML());
357+
if ($table->handleCommand()) {
358+
return;
359+
}
360+
361+
$this->tpl->setContent($table->render());
359362
}
360363

361364
/**
@@ -409,27 +412,34 @@ public function addTeamMemberActionObject(
409412
*/
410413
public function confirmDeleteTeamObject(): void
411414
{
412-
$this->confirmRemoveTeamMemberObject(true);
415+
$this->confirmRemoveTeamMemberObject(0, true);
416+
}
417+
418+
public function confirmRemoveTeamMember(int $user_id): void
419+
{
420+
$this->confirmRemoveTeamMemberObject($user_id);
413421
}
414422

415423
/**
416424
* @throws ilExcUnknownAssignmentTypeException
417425
*/
418426
public function confirmRemoveTeamMemberObject(
427+
int $a_user_id = 0,
419428
bool $a_full_delete = false
420429
): void {
421430
$ilUser = $this->user;
422431
$tpl = $this->tpl;
423432

424-
if (!$this->submission->isTutor()) {
425-
$ids = $a_full_delete ? $this->team->getMembers() : $this->requested_team_ids;
433+
$ids = $a_full_delete
434+
? $this->team->getMembers()
435+
: ($a_user_id > 0 ? [$a_user_id] : $this->requested_team_ids);
426436

437+
if (!$this->submission->isTutor()) {
427438
if ([] === $ids) {
428439
$this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"), true);
429440
$this->ctrl->redirect($this, "submissionScreenTeam");
430441
}
431442
} else {
432-
$ids = $this->requested_team_ids;
433443
if ([] === $ids) {
434444
$this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"), true);
435445
$this->returnToParentObject();
@@ -440,7 +450,7 @@ public function confirmRemoveTeamMemberObject(
440450
if (count($members) <= count($ids)) {
441451
if (count($members) == 1 && $members[0] == $ilUser->getId()) {
442452
// direct team deletion - no confirmation
443-
$this->removeTeamMemberObject($a_full_delete);
453+
$this->removeTeamMemberObject($a_user_id, $a_full_delete);
444454
return;
445455
} else {
446456
$this->tpl->setOnScreenMessage('failure', $this->lng->txt("exc_team_at_least_one"), true);
@@ -480,6 +490,7 @@ public function confirmRemoveTeamMemberObject(
480490
* @throws ilExcUnknownAssignmentTypeException
481491
*/
482492
public function removeTeamMemberObject(
493+
int $a_user_id = 0,
483494
bool $a_full_delete = false
484495
): void {
485496
$ilUser = $this->user;
@@ -491,6 +502,8 @@ public function removeTeamMemberObject(
491502
$ids = [];
492503
if ($a_full_delete) {
493504
$ids = $this->team->getMembers();
505+
} elseif ($a_user_id > 0) {
506+
$ids = [$a_user_id];
494507
} else {
495508
$ids = $this->requested_team_ids;
496509
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with
10+
* the source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
declare(strict_types=1);
20+
21+
namespace ILIAS\Exercise\Team;
22+
23+
use ILIAS\Data\Order;
24+
use ILIAS\Data\Range;
25+
use ILIAS\Exercise\InternalDomainService;
26+
use ILIAS\Repository\RetrievalBase;
27+
use ILIAS\Repository\RetrievalInterface;
28+
29+
class TeamMembersRetrieval implements RetrievalInterface
30+
{
31+
use RetrievalBase;
32+
33+
public function __construct(
34+
protected InternalDomainService $domain,
35+
protected \ilExAssignmentTeam $team,
36+
protected int $parent_ref_id,
37+
protected bool $edit_permission
38+
) {
39+
}
40+
41+
public function getData(
42+
array $fields,
43+
?Range $range = null,
44+
?Order $order = null,
45+
array $filter = [],
46+
array $parameters = []
47+
): \Generator {
48+
$data = $this->collectData();
49+
$order ??= new Order('name', Order::ASC);
50+
$data = $this->applyOrder($data, $order);
51+
$data = $this->applyRange($data, $range);
52+
53+
foreach ($data as $row) {
54+
yield $row;
55+
}
56+
}
57+
58+
public function count(
59+
array $filter = [],
60+
array $parameters = []
61+
): int {
62+
return count($this->collectData());
63+
}
64+
65+
public function isFieldNumeric(string $field): bool
66+
{
67+
return $field === 'id';
68+
}
69+
70+
protected function collectData(): array
71+
{
72+
$access = $this->domain->access();
73+
$data = [];
74+
75+
foreach ($this->team->getMembers() as $id) {
76+
$access_warning = '';
77+
if (!$access->checkAccessOfUser($id, 'read', '', $this->parent_ref_id) &&
78+
is_array($info = $access->getInfo())) {
79+
$access_warning = $info[0]['text'] ?? '';
80+
}
81+
82+
$data[] = [
83+
'id' => $id,
84+
'name' => \ilUserUtil::getNamePresentation(
85+
$id,
86+
false,
87+
false,
88+
'',
89+
$this->edit_permission
90+
),
91+
'access_warning' => $access_warning
92+
];
93+
}
94+
95+
return $data;
96+
}
97+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with
10+
* the source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
declare(strict_types=1);
20+
21+
namespace ILIAS\Exercise\Team;
22+
23+
use ILIAS\Exercise\InternalDomainService;
24+
use ILIAS\Exercise\InternalGUIService;
25+
use ILIAS\Repository\RetrievalInterface;
26+
use ILIAS\Repository\Table\CommonTableBuilder;
27+
use ILIAS\Repository\Table\TableAdapterGUI;
28+
29+
class TeamMembersTableBuilder extends CommonTableBuilder
30+
{
31+
public function __construct(
32+
protected InternalDomainService $domain,
33+
protected InternalGUIService $gui,
34+
protected \ilExAssignmentTeam $team,
35+
protected int $parent_ref_id,
36+
protected bool $read_only,
37+
object $parent_gui,
38+
string $parent_cmd
39+
) {
40+
parent::__construct($parent_gui, $parent_cmd);
41+
}
42+
43+
protected function getId(): string
44+
{
45+
return 'exercise_team_members';
46+
}
47+
48+
protected function getTitle(): string
49+
{
50+
return $this->domain->lng()->txt('exc_team_members');
51+
}
52+
53+
protected function getRetrieval(): RetrievalInterface
54+
{
55+
$edit_permission = $this->domain->access()->checkAccessOfUser(
56+
$this->domain->user()->getId(),
57+
'edit',
58+
'',
59+
$this->parent_ref_id
60+
);
61+
62+
return $this->domain->teamMembersRetrieval(
63+
$this->team,
64+
$this->parent_ref_id,
65+
$edit_permission
66+
);
67+
}
68+
69+
protected function transformRow(array $data_row): array
70+
{
71+
$name = $data_row['name'];
72+
if ($data_row['access_warning'] !== '') {
73+
$name .= '<br>' . htmlspecialchars($data_row['access_warning']);
74+
}
75+
76+
return [
77+
'id' => $data_row['id'],
78+
'name' => $name
79+
];
80+
}
81+
82+
protected function build(TableAdapterGUI $table): TableAdapterGUI
83+
{
84+
$table = $table->textColumn(
85+
'name',
86+
$this->domain->lng()->txt('name'),
87+
true
88+
);
89+
90+
if (!$this->read_only) {
91+
$table = $table->singleAction(
92+
'confirmRemoveTeamMember',
93+
$this->domain->lng()->txt('remove')
94+
);
95+
}
96+
97+
return $table;
98+
}
99+
}

0 commit comments

Comments
 (0)