ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilChatroomBanGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 private readonly ilCtrlInterface $controller;
30 private readonly ilLanguage $language;
31 private readonly ilObjUser $user;
32
33 public function __construct(
36 ?ilLanguage $language = null,
37 ?ilObjUser $user = null
38 ) {
39 if ($controller === null) {
40 global $DIC;
41 $controller = $DIC->ctrl();
42 }
43 $this->controller = $controller;
44
45 if ($language === null) {
46 global $DIC;
47 $language = $DIC->language();
48 }
49 $this->language = $language;
50
51 if ($user === null) {
52 global $DIC;
53 $user = $DIC->user();
54 }
55 $this->user = $user;
56
58 }
59
60 public function handleTableActions(): void
61 {
62 $action = $this->http->wrapper()->query()->retrieve(
63 'chat_ban_table_action',
64 $this->refinery->byTrying([
65 $this->refinery->kindlyTo()->string(),
66 $this->refinery->always('')
67 ])
68 );
69 match ($action) {
70 'delete' => $this->delete(),
71 default => $this->ilCtrl->redirect($this, 'show'),
72 };
73 }
74
75 private function delete(): void
76 {
77 $this->redirectIfNoPermission(['read', 'moderate']);
78
79 $userTrafo = $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string());
80
81 $users = $this->getRequestValue('chat_ban_table_user_ids', $userTrafo, []);
82 if ($users === []) {
83 $this->mainTpl->setOnScreenMessage('info', $this->ilLng->txt('no_checkbox'), true);
84 $this->ilCtrl->redirect($this->gui, 'ban-show');
85 }
86
87 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
88 $this->exitIfNoRoomExists($room);
89
90 if ((string) current($users) === 'ALL_OBJECTS') {
91 $users = array_map(static fn(array $row): int => (int) $row['user_id'], $room->getBannedUsers());
92 } else {
93 $users = array_map(intval(...), $users);
94 }
95
96 $room->unbanUser($users);
97
98 $this->mainTpl->setOnScreenMessage(
99 $this->mainTpl::MESSAGE_TYPE_SUCCESS,
100 $this->ilLng->txt('saved_successfully'),
101 true
102 );
103 $this->ilCtrl->redirect($this->gui, 'ban-show');
104 }
105
106 public function executeDefault(string $requestedMethod): void
107 {
108 $this->show();
109 }
110
114 public function show(): void
115 {
116 $this->redirectIfNoPermission(['read', 'moderate']);
117
118 $this->gui->switchToVisibleMode();
119
120 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
121 $this->exitIfNoRoomExists($room);
122
123 $data = $room->getBannedUsers();
124 $actorId = array_filter(array_map(static fn(array $row): int => (int) $row['actor_id'], $data));
125
126 $sortable_names = ilUserUtil::getNamePresentation($actorId);
127 $names = ilUserUtil::getNamePresentation($actorId, false, false, '', false, false, false);
128
129 array_walk($data, function (&$row) use ($names, $sortable_names): void {
130 if ($row['actor_id'] > 0 && isset($names[$row['actor_id']])) {
131 $row['actor_display'] = $names[$row['actor_id']];
132 $row['actor'] = $sortable_names[$row['actor_id']];
133 } else {
134 $row['actor_display'] = $this->language->txt('unknown');
135 $row['actor'] = $this->language->txt('unknown');
136 }
137 });
138
139 $tbl = new \ILIAS\Chatroom\Bans\BannedUsersTable(
140 $this->user,
141 $room->getRoomId(),
142 $data,
143 $this->ilCtrl,
144 $this->ilLng,
145 $this->http,
146 $this->uiFactory
147 );
148
149 $this->mainTpl->setContent($this->uiRenderer->render($tbl->getComponent()));
150 }
151
152 public function active(): void
153 {
154 $this->redirectIfNoPermission(['read', 'moderate']);
155
156 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
157 $this->exitIfNoRoomExists($room);
158
159 $userToBan = $this->getRequestValue('user', $this->refinery->kindlyTo()->int());
160
161 $connector = $this->gui->getConnector();
162 $response = $connector->sendBan($room->getRoomId(), $userToBan);
163
164 if ($this->isSuccessful($response)) {
165 $room->banUser($userToBan, $this->user->getId());
166 $room->disconnectUser($userToBan);
167 }
168
169 $this->sendResponse($response, 'application/json');
170 }
171}
Class ilChatroomBanGUI.
__construct(?ilChatroomObjectGUI $gui, ?ilCtrlInterface $controller=null, ?ilLanguage $language=null, ?ilObjUser $user=null)
readonly ilLanguage $language
readonly ilCtrlInterface $controller
show()
Displays banned users task.
readonly ilObjUser $user
executeDefault(string $requestedMethod)
Class ilChatroomGUIHandler.
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
exitIfNoRoomExists(?ilChatroom $room)
Checks if a ilChatroom exists.
sendResponse(string $content, string $type)
Sends a response and exits the php process.
isSuccessful($response)
Checks for success param in an json decoded response.
getRequestValue(string $key, Transformation $trafo, $default=null)
static byObjectId(int $object_id)
Class ilCtrl provides processing control methods.
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
language handling
User class.
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path=null)
Default behaviour is:
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$response
Definition: xapitoken.php:93