ILIAS  release_8 Revision v8.24
class.ilChatroomKickGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 private function buildMessage(string $messageString, ilChatroomUser $chat_user): stdClass
30 {
31 $data = new stdClass();
32
33 $data->user = $this->gui->getObject()->getPersonalInformation($chat_user);
34 $data->userToKick = $messageString;
35 $data->timestamp = date('c');
36 $data->type = 'kick';
37
38 return $data;
39 }
40
41 public function executeDefault(string $requestedMethod): void
42 {
43 $this->redirectIfNoPermission(['read', 'moderate']);
44
45 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
46 $this->exitIfNoRoomExists($room);
47
48 $userToKick = $this->getRequestValue('user', $this->refinery->kindlyTo()->int());
49 $subRoomId = $this->getRequestValue('sub', $this->refinery->kindlyTo()->int(), 0);
50
51 $connector = $this->gui->getConnector();
52 $response = $connector->sendKick($room->getRoomId(), $subRoomId, $userToKick);
53
54 if (!$subRoomId && $this->isSuccessful($response)) {
55 // 2013-09-11: Should already been done by the chat server
56 $room->disconnectUser($userToKick);
57 }
58
59 $this->sendResponse($response);
60 }
61
62 public function main(): void
63 {
64 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
65 $this->exitIfNoRoomExists($room);
66
67 $userToKick = $this->getRequestValue('user', $this->refinery->kindlyTo()->int());
68 $subRoomId = $this->getRequestValue('sub', $this->refinery->kindlyTo()->int());
69
70 $connector = $this->gui->getConnector();
71 $response = $connector->sendKick($room->getRoomId(), $subRoomId, $userToKick);
72
73 if ($this->isSuccessful($response)) {
74 // 2013-09-11: Should already been done by the chat server
75 $room->disconnectUser($userToKick);
76 }
77
78 $this->sendResponse($response);
79 }
80
84 public function sub(): void
85 {
86 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
87 if ($room) {
88 $subRoomId = $this->getRequestValue('sub', $this->refinery->kindlyTo()->int());
89 if (
90 !ilChatroom::checkUserPermissions(['read', 'moderate'], $this->gui->getRefId()) &&
91 !$room->isOwnerOfPrivateRoom(
92 $this->ilUser->getId(),
93 $subRoomId
94 )
95 ) {
96 $this->ilCtrl->setParameterByClass(ilRepositoryGUI::class, 'ref_id', ROOT_FOLDER_ID);
97 $this->ilCtrl->redirectByClass(ilRepositoryGUI::class);
98 }
99
100 $roomId = $room->getRoomId();
101
102 $userToKick = $this->getRequestValue('user', $this->refinery->kindlyTo()->int());
103 if ($room->userIsInPrivateRoom($subRoomId, $userToKick)) {
104 $connector = $this->gui->getConnector();
105 $response = $connector->sendKick($roomId, $subRoomId, $userToKick);
106 $this->sendResponse($response);
107 }
108 }
109 }
110}
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)
Class ilChatroomKickGUI.
buildMessage(string $messageString, ilChatroomUser $chat_user)
executeDefault(string $requestedMethod)
sub()
Kicks user from subroom into mainroom.
Class ilChatroomUser.
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
static byObjectId(int $object_id)
Class ilCtrl provides processing control methods.
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc
setParameterByClass(string $a_class, string $a_parameter, $a_value)
@inheritDoc
const ROOT_FOLDER_ID
Definition: constants.php:32
$response