ILIAS  release_8 Revision v8.24
class.ilChatroomBanGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
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 delete(): void
61 {
62 $userTrafo = $this->refinery->kindlyTo()->listOf(
63 $this->refinery->kindlyTo()->int()
64 );
65
66 $users = $this->getRequestValue('banned_user_id', $userTrafo, []);
67 if ($users === []) {
68 $this->mainTpl->setOnScreenMessage('info', $this->ilLng->txt('no_checkbox'), true);
69 $this->ilCtrl->redirect($this->gui, 'ban-show');
70 }
71
72 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
73 $this->exitIfNoRoomExists($room);
74
75 $room->unbanUser($users);
76
77 $this->ilCtrl->redirect($this->gui, 'ban-show');
78 }
79
80 public function executeDefault(string $requestedMethod): void
81 {
82 $this->show();
83 }
84
88 public function show(): void
89 {
90 $this->redirectIfNoPermission('read');
91
92 $this->gui->switchToVisibleMode();
93
94 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
95 $this->exitIfNoRoomExists($room);
96
97 $table = new ilBannedUsersTableGUI($this->gui, 'ban-show');
98 $table->setFormAction($this->controller->getFormAction($this->gui, 'ban-show'));
99
100 $data = $room->getBannedUsers();
101 $actorId = array_filter(array_map(static function (array $row): int {
102 return (int) $row['actor_id'];
103 }, $data));
104
105 $sortable_names = ilUserUtil::getNamePresentation($actorId);
106 $names = ilUserUtil::getNamePresentation($actorId, false, false, '', false, false, false);
107
108 array_walk($data, function (&$row) use ($names, $sortable_names): void {
109 if ($row['actor_id'] > 0 && isset($names[$row['actor_id']])) {
110 $row['actor_display'] = $names[$row['actor_id']];
111 $row['actor'] = $sortable_names[$row['actor_id']];
112 } else {
113 $row['actor_display'] = $this->language->txt('unknown');
114 $row['actor'] = $this->language->txt('unknown');
115 }
116 });
117
118 $table->setData($data);
119
120 $this->mainTpl->setVariable('ADM_CONTENT', $table->getHTML());
121 }
122
123 public function active(): void
124 {
125 $this->redirectIfNoPermission(['read', 'moderate']);
126
127 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
128 $this->exitIfNoRoomExists($room);
129
130 $userToBan = $this->getRequestValue('user', $this->refinery->kindlyTo()->int());
131 $subRoomId = $this->getRequestValue('sub', $this->refinery->kindlyTo()->int());
132
133 $connector = $this->gui->getConnector();
134 $response = $connector->sendBan($room->getRoomId(), $subRoomId, $userToBan);
135
136 if ($this->isSuccessful($response)) {
137 $room->banUser($userToBan, $this->user->getId());
138 $room->disconnectUser($userToBan);
139 }
140
141 $this->sendResponse($response);
142 }
143}
Class ilBannedUsersTableGUI.
Class ilChatroomBanGUI.
show()
Displays banned users task.
__construct(ilChatroomObjectGUI $gui, ilCtrlInterface $controller=null, ilLanguage $language=null, ilObjUser $user=null)
executeDefault(string $requestedMethod)
ilCtrlInterface $controller
Class ilChatroomGUIHandler.
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
exitIfNoRoomExists(?ilChatroom $room)
Checks if a ilChatroom exists.
sendResponse($response, bool $isJson=false)
Sends a json encoded 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="ilpublicuserprofilegui")
Default behaviour is:
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$response