ILIAS  trunk Revision v11.0_alpha-1846-g895b5f47236
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ParticipantTableDeleteParticipantAction.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Test\Participants;
22 
30 
32 {
33  public const ACTION_ID = 'delete_pax';
34 
35  public function __construct(
36  private readonly Language $lng,
37  private readonly \ilGlobalTemplateInterface $tpl,
38  private readonly UIFactory $ui_factory,
39  private readonly ParticipantRepository $participant_repository,
40  private readonly \ilTestAccess $test_access,
41  private readonly \ilObjTest $test_obj
42  ) {
43  }
44 
45  public function getActionId(): string
46  {
47  return self::ACTION_ID;
48  }
49 
50  public function isAvailable(): bool
51  {
52  return $this->test_access->checkManageParticipantsAccess();
53  }
54 
55  public function getTableAction(
56  URLBuilder $url_builder,
57  URLBuilderToken $row_id_token,
58  URLBuilderToken $action_token,
59  URLBuilderToken $action_type_token
60  ): Action {
61  return $this->ui_factory->table()->action()->standard(
62  $this->lng->txt('remove_participants'),
63  $url_builder
64  ->withParameter($action_token, self::ACTION_ID)
65  ->withParameter($action_type_token, ParticipantTableActions::SHOW_ACTION),
66  $row_id_token
67  )->withAsync();
68  }
69 
70  public function getModal(
71  URLBuilder $url_builder,
72  array $selected_participants,
73  bool $all_participants_selected
74  ): ?Modal {
75  return $this->ui_factory->modal()->interruptive(
76  $this->lng->txt('confirm'),
77  $this->lng->txt('remove_selected_participants_confirmation'),
78  $url_builder->buildURI()->__toString()
79  )->withAffectedItems(
80  array_map(
81  fn(Participant $v) => $this->ui_factory->modal()->interruptiveItem()->standard(
82  (string) $v->getUserId(),
83  $this->test_obj->getAnonymity()
84  ? $this->lng->txt('anonymous')
86  ),
87  $selected_participants
88  )
89  )->withActionButtonLabel($this->lng->txt('remove'));
90  }
91 
92  public function onSubmit(
93  URLBuilder $url_builder,
94  ServerRequestInterface $request,
95  array $selected_participants,
96  bool $all_participants_selected
97  ): ?Modal {
98  if (!$this->test_access->checkManageParticipantsAccess()) {
99  $this->tpl->setOnScreenMessage(
101  $this->lng->txt('no_permission'),
102  true
103  );
104  return null;
105  }
106 
107  $this->participant_repository->removeParticipants($selected_participants);
108 
109  $this->tpl->setOnScreenMessage(
111  $this->lng->txt('tst_selected_user_data_deleted'),
112  true
113  );
114  return null;
115  }
116 
117  public function allowActionForRecord(Participant $record): bool
118  {
119  return $record->getActiveId() === null;
120  }
121 
122  public function getSelectionErrorMessage(): ?string
123  {
124  return $this->lng->txt('delete_participants_no_valid_participants_selected');
125  }
126 }
This describes commonalities between the different modals.
Definition: Modal.php:34
getTableAction(URLBuilder $url_builder, URLBuilderToken $row_id_token, URLBuilderToken $action_token, URLBuilderToken $action_type_token)
buildURI()
Get a URI representation of the full URL including query string and fragment/hash.
Definition: URLBuilder.php:212
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Participant.php:21
static _lookupFullname(int $a_user_id)
onSubmit(URLBuilder $url_builder, ServerRequestInterface $request, array $selected_participants, bool $all_participants_selected)
__construct(private readonly Language $lng, private readonly \ilGlobalTemplateInterface $tpl, private readonly UIFactory $ui_factory, private readonly ParticipantRepository $participant_repository, private readonly \ilTestAccess $test_access, private readonly \ilObjTest $test_obj)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getModal(URLBuilder $url_builder, array $selected_participants, bool $all_participants_selected)
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter&#39;s value if the supplied token is valid.
Definition: URLBuilder.php:166
global $lng
Definition: privfeed.php:31
URLBuilder.
Definition: URLBuilder.php:40