ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ParticipantTableDeleteResultsAction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\UI\Factory as UIFactory;
29use Psr\Http\Message\ServerRequestInterface;
30
32{
33 public const ACTION_ID = 'delete_results';
34
35 public function __construct(
36 private readonly Language $lng,
37 private readonly \ilGlobalTemplateInterface $tpl,
38 private readonly UIFactory $ui_factory,
39 private readonly \ilDBInterface $db,
40 private readonly \ilTestParticipantAccessFilterFactory $participant_access_filter_factory,
41 private readonly \ilTestAccess $test_access,
42 private readonly \ilObjTest $test_obj
43 ) {
44 }
45
46 public function getActionId(): string
47 {
48 return self::ACTION_ID;
49 }
50
51 public function isAvailable(): bool
52 {
53 return $this->test_access->checkManageParticipantsAccess()
54 && $this->test_obj->evalTotalPersons() > 0;
55 }
56
57 public function getTableAction(
58 URLBuilder $url_builder,
59 URLBuilderToken $row_id_token,
60 URLBuilderToken $action_token,
61 URLBuilderToken $action_type_token
62 ): Action {
63 return $this->ui_factory->table()->action()->standard(
64 $this->lng->txt('delete_user_data'),
65 $url_builder
66 ->withParameter($action_token, self::ACTION_ID)
67 ->withParameter($action_type_token, ParticipantTableActions::SHOW_ACTION),
68 $row_id_token
69 )->withAsync();
70 }
71
72 public function getModal(
73 URLBuilder $url_builder,
74 array $selected_participants,
75 bool $all_participants_selected
76 ): ?Modal {
77 return $this->ui_factory->modal()->interruptive(
78 $this->lng->txt('confirm'),
79 $this->resolveMessage($all_participants_selected),
80 $url_builder->buildURI()->__toString()
81 )->withAffectedItems(
82 array_map(
83 fn(Participant $v) => $this->ui_factory->modal()->interruptiveItem()->standard(
84 (string) $v->getUserId(),
85 $this->test_obj->getAnonymity()
86 ? $this->lng->txt('anonymous')
87 : \ilObjUser::_lookupFullname($v->getUserId())
88 ),
89 $selected_participants
90 )
91 );
92 }
93
94 public function onSubmit(
95 URLBuilder $url_builder,
96 ServerRequestInterface $request,
97 array $selected_participants,
98 bool $all_participants_selected
99 ): ?Modal {
100 if (!$this->test_access->checkManageParticipantsAccess()) {
101 $this->tpl->setOnScreenMessage(
103 $this->lng->txt('no_permission'),
104 true
105 );
106 return null;
107 }
108
109 $access_filter = $this->participant_access_filter_factory
110 ->getManageParticipantsUserFilter($this->test_obj->getRefId());
111 $participant_data = new \ilTestParticipantData($this->db, $this->lng);
112 $participant_data->setParticipantAccessFilter($access_filter);
113 $participant_data->setActiveIdsFilter(
114 array_map(
115 static fn(Participant $v): int => $v->getActiveId(),
116 $selected_participants
117 )
118 );
119 $participant_data->load($this->test_obj->getTestId());
120 $this->test_obj->removeTestResults($participant_data);
121
122 $this->tpl->setOnScreenMessage(
124 $this->lng->txt('tst_selected_user_data_deleted'),
125 true
126 );
127 return null;
128 }
129
130 public function allowActionForRecord(Participant $record): bool
131 {
132 return $record->getActiveId() !== null;
133 }
134
135 private function resolveMessage(bool $all_participants_selected): string
136 {
137 if ($all_participants_selected) {
138 return $this->lng->txt('delete_all_user_data_confirmation');
139 }
140
141 return $this->lng->txt('delete_selected_user_data_confirmation');
142 }
143
144 public function getSelectionErrorMessage(): ?string
145 {
146 return $this->lng->txt('delete_result_no_valid_participants_selected');
147 }
148}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
__construct(private readonly Language $lng, private readonly \ilGlobalTemplateInterface $tpl, private readonly UIFactory $ui_factory, private readonly \ilDBInterface $db, private readonly \ilTestParticipantAccessFilterFactory $participant_access_filter_factory, private readonly \ilTestAccess $test_access, private readonly \ilObjTest $test_obj)
getTableAction(URLBuilder $url_builder, URLBuilderToken $row_id_token, URLBuilderToken $action_token, URLBuilderToken $action_type_token)
getModal(URLBuilder $url_builder, array $selected_participants, bool $all_participants_selected)
onSubmit(URLBuilder $url_builder, ServerRequestInterface $request, array $selected_participants, bool $all_participants_selected)
User class.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes commonalities between the different modals.
Definition: Modal.php:35
Interface ilDBInterface.
modal(string $title="", string $cancel_label="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Participant.php:21
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))