ILIAS  release_8 Revision v8.24
class.ilChatroomPrivateRoomGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 protected function exitIfEnterRoomIsNotAllowed(ilChatroom $room, int $subRoom, ilChatroomUser $chat_user): void
30 {
31 if (!$room->isAllowedToEnterPrivateRoom($chat_user->getUserId(), $subRoom)) {
32 $this->sendResponse([
33 'success' => false,
34 'reason' => 'not allowed enter to private room'
35 ]);
36 }
37 }
38
39 protected function exitIfNoRoomSubscription(ilChatroom $room, ilChatroomUser $chat_user): void
40 {
41 if (!$room->isSubscribed($chat_user->getUserId())) {
42 $this->sendResponse([
43 'success' => false,
44 'reason' => 'not subscribed'
45 ]);
46 }
47 }
48
49 public function executeDefault(string $requestedMethod): void
50 {
51 }
52
53 public function create(): void
54 {
55 $this->redirectIfNoPermission('read');
56
57 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
58 $this->exitIfNoRoomExists($room);
59
60 $chat_user = new ilChatroomUser($this->ilUser, $room);
61 $this->exitIfNoRoomSubscription($room, $chat_user);
62
63 $title = $room->getUniquePrivateRoomTitle(ilUtil::stripSlashes(
64 $this->getRequestValue('title', $this->refinery->kindlyTo()->string())
65 ));
66 $subRoomId = $room->addPrivateRoom($title, $chat_user, ['public' => false]);
67
68 $connector = $this->gui->getConnector();
69 $response = $connector->sendCreatePrivateRoom($room->getRoomId(), $subRoomId, $chat_user->getUserId(), $title);
70
71 if ($this->isSuccessful($response)) {
72 $response = [
73 'success' => true,
74 'title' => $title,
75 'owner' => $chat_user->getUserId(),
76 'subRoomId' => $subRoomId
77 ];
78 }
79
80 $this->sendResponse($response);
81 }
82
83 public function delete(): void
84 {
85 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
86
87 $this->exitIfNoRoomExists($room);
88
89 $subRoom = $this->getRequestValue('sub', $this->refinery->kindlyTo()->int());
90 $chat_user = new ilChatroomUser($this->ilUser, $room);
91 $this->exitIfNoRoomSubscription($room, $chat_user);
92
93 $room->closePrivateRoom($subRoom);
94
95 $connector = $this->gui->getConnector();
96 $response = $connector->sendDeletePrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
97
98 $this->sendResponse($response);
99 }
100
101 public function leave(): void
102 {
103 $this->redirectIfNoPermission('read');
104
105 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
106
107 $this->exitIfNoRoomExists($room);
108
109 $subRoom = $this->getRequestValue('sub', $this->refinery->kindlyTo()->int());
110 $chat_user = new ilChatroomUser($this->ilUser, $room);
111 $this->exitIfNoRoomSubscription($room, $chat_user);
112
113 $connector = $this->gui->getConnector();
114 $response = $connector->sendLeavePrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
115
116 if ($room->userIsInPrivateRoom($subRoom, $chat_user->getUserId())) {
117 $room->unsubscribeUserFromPrivateRoom($subRoom, $chat_user->getUserId());
118 }
119
120 $this->sendResponse($response);
121 }
122
123 public function enter(): void
124 {
125 $this->redirectIfNoPermission('read');
126
127 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
128 $this->exitIfNoRoomExists($room);
129
130 $subRoom = $this->getRequestValue('sub', $this->refinery->kindlyTo()->int());
131 $chat_user = new ilChatroomUser($this->ilUser, $room);
132 $this->exitIfEnterRoomIsNotAllowed($room, $subRoom, $chat_user);
133
134 $connector = $this->gui->getConnector();
135 $response = $connector->sendEnterPrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
136
137 if ($this->isSuccessful($response)) {
138 $room->subscribeUserToPrivateRoom($subRoom, $chat_user->getUserId());
139 }
140
141 $this->sendResponse($response);
142 }
143
144 public function listUsers(): void
145 {
146 $this->redirectIfNoPermission('read');
147
148 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
149 $this->exitIfNoRoomExists($room);
150
151 $response = $room->listUsersInPrivateRoom(
152 $this->getRequestValue('sub', $this->refinery->kindlyTo()->int())
153 );
154 $this->sendResponse($response);
155 }
156}
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 ilChatroomPrivateRoomGUI.
exitIfNoRoomSubscription(ilChatroom $room, ilChatroomUser $chat_user)
executeDefault(string $requestedMethod)
exitIfEnterRoomIsNotAllowed(ilChatroom $room, int $subRoom, ilChatroomUser $chat_user)
Class ilChatroomUser.
getUserId()
Returns Ilias User ID.
Class ilChatroom.
isAllowedToEnterPrivateRoom(int $chat_userid, int $proom_id)
isSubscribed(int $chat_userid)
static byObjectId(int $object_id)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$response