ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilChatroomPrivateRoomGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
5require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
6
14{
18 public function executeDefault($requestedMethod)
19 {
20 }
21
22 public function create()
23 {
24 $this->redirectIfNoPermission('read');
25
26 $room = ilChatroom::byObjectId($this->gui->object->getId());
27 $chat_user = new ilChatroomUser($this->ilUser, $room);
28
29 $this->exitIfNoRoomExists($room);
30 $this->exitIfNoRoomSubscription($room, $chat_user);
31
32 $title = $room->getUniquePrivateRoomTitle(ilUtil::stripSlashes((string) $_REQUEST['title']));
33 $subRoomId = $room->addPrivateRoom($title, $chat_user, array('public' => false));
34
35 $connector = $this->gui->getConnector();
36 $response = $connector->sendCreatePrivateRoom($room->getRoomId(), $subRoomId, $chat_user->getUserId(), $title);
37
38 if ($this->isSuccessful($response)) {
39 $response = array(
40 'success' => true,
41 'title' => $title,
42 'owner' => $chat_user->getUserId(),
43 'subRoomId' => $subRoomId
44 );
45 }
46
47 $this->sendResponse($response);
48 }
49
54 protected function exitIfNoRoomSubscription($room, $chat_user)
55 {
56 if (!$room->isSubscribed($chat_user->getUserId())) {
57 $this->sendResponse(array(
58 'success' => false,
59 'reason' => 'not subscribed'
60 ));
61 }
62 }
63
64 public function delete()
65 {
66 $room = ilChatroom::byObjectId($this->gui->object->getId());
67 $subRoom = $_REQUEST['sub'];
68 $chat_user = new ilChatroomUser($this->ilUser, $room);
69
70 $this->exitIfNoRoomExists($room);
71 $this->exitIfNoRoomSubscription($room, $chat_user);
72
73 $room->closePrivateRoom($subRoom);
74
75 $connector = $this->gui->getConnector();
76 $response = $connector->sendDeletePrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
77
78 $this->sendResponse($response);
79 }
80
81 public function leave()
82 {
83 $room = ilChatroom::byObjectId($this->gui->object->getId());
84 $chat_user = new ilChatroomUser($this->ilUser, $room);
85 $subRoom = $_REQUEST['sub'];
86
87 $this->exitIfNoRoomExists($room);
88 $this->exitIfNoRoomSubscription($room, $chat_user);
89
90 $connector = $this->gui->getConnector();
91 $response = $connector->sendLeavePrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
92
93 if ($room->userIsInPrivateRoom($subRoom, $chat_user->getUserId())) {
94 $room->unsubscribeUserFromPrivateRoom($subRoom, $chat_user->getUserId());
95 }
96
97 $this->sendResponse($response);
98 }
99
100 public function enter()
101 {
102 $this->redirectIfNoPermission('read');
103
104 $room = ilChatroom::byObjectId($this->gui->object->getId());
105 $subRoom = $_REQUEST['sub'];
106 $chat_user = new ilChatroomUser($this->ilUser, $room);
107
108 $this->exitIfNoRoomExists($room);
109 $this->exitIfEnterRoomIsNotAllowed($room, $subRoom, $chat_user);
110
111 $connector = $this->gui->getConnector();
112 $response = $connector->sendEnterPrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
113
114 if ($this->isSuccessful($response)) {
115 $room->subscribeUserToPrivateRoom($subRoom, $chat_user->getUserId());
116 }
117
118 $this->sendResponse($response);
119 }
120
126 protected function exitIfEnterRoomIsNotAllowed($room, $subRoom, $chat_user)
127 {
128 if (!$room->isAllowedToEnterPrivateRoom($chat_user->getUserId(), $subRoom)) {
129 $this->sendResponse(array(
130 'success' => false,
131 'reason' => 'not allowed enter to private room'
132 ));
133 }
134 }
135
136 public function listUsers()
137 {
138 $room = ilChatroom::byObjectId($this->gui->object->getId());
139
140 $response = $room->listUsersInPrivateRoom($_REQUEST['sub']);
141 $this->sendResponse($response);
142 }
143}
An exception for terminatinating execution or to throw for unit testing.
Class ilChatroomGUIHandler.
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
sendResponse($response)
Sends a json encoded response and exits the php process.
exitIfNoRoomExists($room)
Checks if a ilChatroom exists.
isSuccessful($response)
Checks for success param in an json decoded response.
Class ilChatroomPrivateRoomGUI.
exitIfEnterRoomIsNotAllowed($room, $subRoom, $chat_user)
executeDefault($requestedMethod)
@inheritDoc
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$response