ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
15
19 protected $ilUser;
20
26 {
27 global $ilUser;
28
29 $this->ilUser = $ilUser;
30
31 parent::__construct($gui);
32 }
33
34 public function executeDefault($method)
35 {
36 }
37
38 public function create()
39 {
40 $this->redirectIfNoPermission('read');
41
42 $room = ilChatroom::byObjectId($this->gui->object->getId());
43 $chat_user = new ilChatroomUser($this->ilUser, $room);
44
45 $this->exitIfNoRoomExists($room);
46 $this->exitIfNoRoomSubscription($room, $chat_user);
47
48 $title = $room->getUniquePrivateRoomTitle(ilUtil::stripSlashes((string) $_REQUEST['title']));
49 $subRoomId = $room->addPrivateRoom($title, $chat_user, array('public' => false));
50
51 $connector = $this->gui->getConnector();
52 $response = $connector->sendCreatePrivateRoom($room->getRoomId(), $subRoomId, $chat_user->getUserId(), $title);
53
54 if ($this->isSuccessful($response)) {
55 $response = array(
56 'success' => true,
57 'title' => $title,
58 'owner' => $chat_user->getUserId(),
59 'subRoomId' => $subRoomId
60 );
61 }
62
63 $this->sendResponse($response);
64 }
65
70 protected function exitIfNoRoomSubscription($room, $chat_user)
71 {
72 if (!$room->isSubscribed($chat_user->getUserId())) {
73 $this->sendResponse(array(
74 'success' => false,
75 'reason' => 'not subscribed'
76 ));
77 }
78 }
79
80 public function delete()
81 {
82 $room = ilChatroom::byObjectId($this->gui->object->getId());
83 $subRoom = $_REQUEST['sub'];
84 $chat_user = new ilChatroomUser($this->ilUser, $room);
85
86 $this->exitIfNoRoomExists($room);
87 $this->exitIfNoRoomSubscription($room, $chat_user);
88
89 $room->closePrivateRoom($subRoom);
90
91 $connector = $this->gui->getConnector();
92 $response = $connector->sendDeletePrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
93
94 $this->sendResponse($response);
95 }
96
97 public function leave()
98 {
99 $room = ilChatroom::byObjectId($this->gui->object->getId());
100 $chat_user = new ilChatroomUser($this->ilUser, $room);
101 $subRoom = $_REQUEST['sub'];
102
103 $this->exitIfNoRoomExists($room);
104 $this->exitIfNoRoomSubscription($room, $chat_user);
105
106 $connector = $this->gui->getConnector();
107 $response = $connector->sendLeavePrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
108
109 if ($room->userIsInPrivateRoom($subRoom, $chat_user->getUserId())) {
110 $room->unsubscribeUserFromPrivateRoom($subRoom, $chat_user->getUserId());
111 }
112
113 $this->sendResponse($response);
114 }
115
116 public function enter()
117 {
118 global $ilUser;
119
120 $this->redirectIfNoPermission('read');
121
122 $room = ilChatroom::byObjectId($this->gui->object->getId());
123 $subRoom = $_REQUEST['sub'];
124 $chat_user = new ilChatroomUser($ilUser, $room);
125
126 $this->exitIfNoRoomExists($room);
127 $this->exitIfEnterRoomIsNotAllowed($room, $subRoom, $chat_user);
128
129 /*$params = array();
130
131 $params['user'] = $chat_user->getUserId();
132 $params['sub'] = $_REQUEST['sub'];
133 $params['message'] = json_encode( array(
134 'type' => 'private_room_entered',
135 'user' => $user_id
136 ));*/
137
138 //$query = http_build_query( $params );
139 $connector = $this->gui->getConnector();
140 $response = $connector->sendEnterPrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
141
142 if ($this->isSuccessful($response)) {
143 $room->subscribeUserToPrivateRoom($subRoom, $chat_user->getUserId());
144 }
145
146 /*$message = json_encode( array(
147 'type' => 'private_room_entered',
148 'user' => $params['user'],
149 'sub' => $params['sub']
150 ));
151
152 $connector->sendMessage( $room->getRoomId(), $message, array('public' => 1, 'sub' => $params['sub']) );*/
153
154 $this->sendResponse($response);
155 }
156
162 protected function exitIfEnterRoomIsNotAllowed($room, $subRoom, $chat_user)
163 {
164 if (!$room->isAllowedToEnterPrivateRoom($chat_user->getUserId(), $subRoom)) {
165 $this->sendResponse(array(
166 'success' => false,
167 'reason' => 'not allowed enter to private room'
168 ));
169 }
170 }
171
172 public function listUsers()
173 {
174 $room = ilChatroom::byObjectId($this->gui->object->getId());
175
176 $response = $room->listUsersInPrivateRoom($_REQUEST['sub']);
177 $this->sendResponse($response);
178 }
179}
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)
__construct(ilChatroomObjectGUI $gui)
ilChatroomPrivateRoomGUI constructor.
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