Skip to content

Commit c4aad08

Browse files
committed
porfolio: role/template assignment
1 parent 5e6a969 commit c4aad08

8 files changed

Lines changed: 257 additions & 130 deletions
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 the
10+
* 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\Portfolio\Administration;
22+
23+
use ILIAS\Data\Order;
24+
use ILIAS\Data\Range;
25+
use ILIAS\Repository\RetrievalBase;
26+
use ILIAS\Repository\RetrievalInterface;
27+
28+
class PortfolioRoleAssignmentRetrieval implements RetrievalInterface
29+
{
30+
use RetrievalBase;
31+
32+
public function __construct(
33+
protected PortfolioRoleAssignmentManager $manager
34+
) {
35+
}
36+
37+
public function getData(
38+
array $fields,
39+
?Range $range = null,
40+
?Order $order = null,
41+
array $filter = [],
42+
array $parameters = []
43+
): \Generator {
44+
$data = $this->collectData();
45+
$data = $this->applyOrder($data, $order);
46+
$data = $this->applyRange($data, $range);
47+
48+
foreach ($data as $row) {
49+
yield $row;
50+
}
51+
}
52+
53+
public function count(
54+
array $filter = [],
55+
array $parameters = []
56+
): int {
57+
return count($this->collectData());
58+
}
59+
60+
public function isFieldNumeric(string $field): bool
61+
{
62+
return in_array($field, ["role_id", "template_ref_id"], true);
63+
}
64+
65+
protected function collectData(): array
66+
{
67+
return array_map(
68+
static fn(array $row): array => [
69+
"id" => (string) $row["role_id"] . "_" . (string) $row["template_ref_id"],
70+
"role_title" => (string) $row["role_title"],
71+
"template_title" => (string) $row["template_title"],
72+
"role_id" => (int) $row["role_id"],
73+
"template_ref_id" => (int) $row["template_ref_id"]
74+
],
75+
$this->manager->getAllAssignmentData()
76+
);
77+
}
78+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 the
10+
* 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\Portfolio\Administration;
22+
23+
use ILIAS\Portfolio\InternalDomainService;
24+
use ILIAS\Portfolio\InternalGUIService;
25+
use ILIAS\Repository\RetrievalInterface;
26+
use ILIAS\Repository\Table\CommonTableBuilder;
27+
use ILIAS\Repository\Table\TableAdapterGUI;
28+
29+
class PortfolioRoleAssignmentTableBuilder extends CommonTableBuilder
30+
{
31+
public function __construct(
32+
protected InternalDomainService $domain,
33+
protected InternalGUIService $gui,
34+
protected bool $has_write_permission,
35+
object $parent_gui,
36+
string $parent_cmd
37+
) {
38+
parent::__construct($parent_gui, $parent_cmd, false);
39+
}
40+
41+
protected function getId(): string
42+
{
43+
return "portfolio_role_assignments";
44+
}
45+
46+
protected function getTitle(): string
47+
{
48+
return $this->domain->lng()->txt("prtf_role_assignment");
49+
}
50+
51+
protected function getRetrieval(): RetrievalInterface
52+
{
53+
return $this->domain->portfolioRoleAssignmentRetrieval();
54+
}
55+
56+
protected function transformRow(array $data_row): array
57+
{
58+
return [
59+
"id" => $data_row["id"],
60+
"role_title" => $data_row["role_title"],
61+
"template_title" => $data_row["template_title"]
62+
];
63+
}
64+
65+
protected function build(TableAdapterGUI $table): TableAdapterGUI
66+
{
67+
$lng = $this->domain->lng();
68+
69+
$table = $table
70+
->textColumn("role_title", $lng->txt("prtf_role_title"))
71+
->textColumn("template_title", $lng->txt("prtf_template_title"));
72+
73+
if ($this->has_write_permission) {
74+
$table = $table->singleAction(
75+
"confirmAssignmentDeletion",
76+
$lng->txt("prtf_delete_assignment"),
77+
true
78+
);
79+
}
80+
81+
return $table;
82+
}
83+
}

components/ILIAS/Portfolio/Administration/class.ilPortfolioRoleAssignmentGUI.php

Lines changed: 72 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
*********************************************************************/
1818

1919
use ILIAS\Portfolio\Administration\PortfolioRoleAssignmentManager;
20+
use ILIAS\Portfolio\InternalGUIService;
2021
use ILIAS\Portfolio\StandardGUIRequest;
22+
use ILIAS\Repository\Table\TableAdapterGUI;
2123

2224
/**
2325
* @ilCtrl_Calls ilPortfolioRoleAssignmentGUI: ilPropertyFormGUI
@@ -33,6 +35,7 @@ class ilPortfolioRoleAssignmentGUI
3335
protected ilLanguage $lng;
3436
protected ilGlobalTemplateInterface $main_tpl;
3537
protected PortfolioRoleAssignmentManager $manager;
38+
protected InternalGUIService $portfolio_gui;
3639

3740
public function __construct()
3841
{
@@ -43,6 +46,7 @@ public function __construct()
4346
$this->lng = $DIC->language();
4447
$this->main_tpl = $DIC->ui()->mainTemplate();
4548
$this->manager = new PortfolioRoleAssignmentManager();
49+
$this->portfolio_gui = $DIC->portfolio()->internal()->gui();
4650
$this->port_request = $DIC->portfolio()
4751
->internal()
4852
->gui()
@@ -70,7 +74,7 @@ public function executeCommand(): void
7074
"addAssignment",
7175
"saveAssignment",
7276
"confirmAssignmentDeletion",
73-
"deleteAssignments"
77+
"deleteAssignment"
7478
])) {
7579
$this->$cmd();
7680
}
@@ -87,13 +91,22 @@ protected function listAssignments(): void
8791
);
8892
}
8993

90-
$table = new ilPortfolioRoleAssignmentTableGUI(
91-
$this,
92-
"listAssignments",
93-
$this->manager,
94-
$this->checkWrite()
95-
);
96-
$this->main_tpl->setContent($table->getHTML());
94+
$table = $this->getRoleAssignmentTable();
95+
if ($table->handleCommand()) {
96+
return;
97+
}
98+
$this->main_tpl->setContent($table->render());
99+
}
100+
101+
protected function getRoleAssignmentTable(): TableAdapterGUI
102+
{
103+
return $this->portfolio_gui
104+
->portfolioRoleAssignmentTableBuilder(
105+
$this->checkWrite(),
106+
$this,
107+
"listAssignments"
108+
)
109+
->getTable();
97110
}
98111

99112
protected function addAssignment(): void
@@ -170,47 +183,64 @@ public function saveAssignment(): void
170183
}
171184
}
172185

173-
protected function confirmAssignmentDeletion(): void
186+
public function confirmAssignmentDeletion(string $assignment_id): void
174187
{
175-
$ctrl = $this->ctrl;
176-
$lng = $this->lng;
177-
$main_tpl = $this->main_tpl;
178188
$this->checkWrite(true);
179-
$template_ids = $this->port_request->getRoleTemplateIds();
180-
if (count($template_ids) === 0) {
181-
$this->main_tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
182-
$ctrl->redirect($this, "listAssignments");
183-
} else {
184-
$cgui = new ilConfirmationGUI();
185-
$cgui->setFormAction($ctrl->getFormAction($this));
186-
$cgui->setHeaderText($lng->txt("prtf_delete_assignment_sure"));
187-
$cgui->setCancel($lng->txt("cancel"), "listAssignments");
188-
$cgui->setConfirm($lng->txt("delete"), "deleteAssignments");
189-
foreach ($template_ids as $i) {
190-
$id_arr = explode("_", $i);
191-
$role_title = ilObject::_lookupTitle($id_arr[0]);
192-
$template_title = ilObject::_lookupTitle(
193-
ilObject::_lookupObjId($id_arr[1])
194-
);
195-
$cgui->addItem("role_template_ids[]", $i, $role_title .
196-
" - " . $template_title);
197-
}
198-
199-
$main_tpl->setContent($cgui->getHTML());
189+
$assignment = $this->getAssignment($assignment_id);
190+
if ($assignment === null) {
191+
$this->main_tpl->setOnScreenMessage('info', $this->lng->txt("no_checkbox"), true);
192+
$this->ctrl->redirect($this, "listAssignments");
200193
}
194+
195+
$this->getRoleAssignmentTable()->renderDeletionConfirmation(
196+
$this->lng->txt("prtf_delete_assignment_sure"),
197+
$this->lng->txt("prtf_delete_assignment_sure"),
198+
"deleteAssignment",
199+
[
200+
$assignment_id => $assignment["role_title"] . " - " . $assignment["template_title"]
201+
]
202+
);
201203
}
202204

203-
protected function deleteAssignments(): void
205+
protected function deleteAssignment(): void
204206
{
205207
$this->checkWrite(true);
206-
$ctrl = $this->ctrl;
207-
$lng = $this->lng;
208-
$template_ids = $this->port_request->getRoleTemplateIds();
209-
foreach ($template_ids as $i) {
210-
$id_arr = explode("_", $i);
211-
$this->manager->delete((int) $id_arr[1], (int) $id_arr[0]);
208+
$template_ids = $this->getRoleAssignmentTable()->getItemIds();
209+
$assignment = $this->getAssignment($template_ids[0] ?? "");
210+
if ($assignment === null) {
211+
$this->main_tpl->setOnScreenMessage('info', $this->lng->txt("no_checkbox"), true);
212+
$this->ctrl->redirect($this, "listAssignments");
213+
}
214+
215+
$this->manager->delete(
216+
$assignment["template_ref_id"],
217+
$assignment["role_id"]
218+
);
219+
$this->main_tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
220+
$this->ctrl->redirect($this, "listAssignments");
221+
}
222+
223+
protected function getAssignment(string $assignment_id): ?array
224+
{
225+
$parts = explode("_", $assignment_id);
226+
if (count($parts) !== 2 || !ctype_digit($parts[0]) || !ctype_digit($parts[1])) {
227+
return null;
228+
}
229+
230+
$role_id = (int) $parts[0];
231+
$template_ref_id = (int) $parts[1];
232+
foreach ($this->manager->getAllAssignmentData() as $assignment) {
233+
if ((int) $assignment["role_id"] === $role_id
234+
&& (int) $assignment["template_ref_id"] === $template_ref_id) {
235+
return [
236+
"role_id" => $role_id,
237+
"template_ref_id" => $template_ref_id,
238+
"role_title" => $assignment["role_title"],
239+
"template_title" => $assignment["template_title"]
240+
];
241+
}
212242
}
213-
$this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
214-
$ctrl->redirect($this, "listAssignments");
243+
244+
return null;
215245
}
216246
}

components/ILIAS/Portfolio/Administration/class.ilPortfolioRoleAssignmentTableGUI.php

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)