ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 public function executeDefault($method)
16 {
17 }
18
19 public function create()
20 {
21 $this->redirectIfNoPermission('read');
22
23 $room = ilChatroom::byObjectId($this->gui->object->getId());
24 $chat_user = new ilChatroomUser($this->ilUser, $room);
25
26 $this->exitIfNoRoomExists($room);
27 $this->exitIfNoRoomSubscription($room, $chat_user);
28
29 $title = $room->getUniquePrivateRoomTitle(ilUtil::stripSlashes((string) $_REQUEST['title']));
30 $subRoomId = $room->addPrivateRoom($title, $chat_user, array('public' => false));
31
32 $connector = $this->gui->getConnector();
33 $response = $connector->sendCreatePrivateRoom($room->getRoomId(), $subRoomId, $chat_user->getUserId(), $title);
34
35 if ($this->isSuccessful($response)) {
36 $response = array(
37 'success' => true,
38 'title' => $title,
39 'owner' => $chat_user->getUserId(),
40 'subRoomId' => $subRoomId
41 );
42 }
43
44 $this->sendResponse($response);
45 }
46
51 protected function exitIfNoRoomSubscription($room, $chat_user)
52 {
53 if (!$room->isSubscribed($chat_user->getUserId())) {
54 $this->sendResponse(array(
55 'success' => false,
56 'reason' => 'not subscribed'
57 ));
58 }
59 }
60
61 public function delete()
62 {
63 $room = ilChatroom::byObjectId($this->gui->object->getId());
64 $subRoom = $_REQUEST['sub'];
65 $chat_user = new ilChatroomUser($this->ilUser, $room);
66
67 $this->exitIfNoRoomExists($room);
68 $this->exitIfNoRoomSubscription($room, $chat_user);
69
70 $room->closePrivateRoom($subRoom);
71
72 $connector = $this->gui->getConnector();
73 $response = $connector->sendDeletePrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
74
75 $this->sendResponse($response);
76 }
77
78 public function leave()
79 {
80 $room = ilChatroom::byObjectId($this->gui->object->getId());
81 $chat_user = new ilChatroomUser($this->ilUser, $room);
82 $subRoom = $_REQUEST['sub'];
83
84 $this->exitIfNoRoomExists($room);
85 $this->exitIfNoRoomSubscription($room, $chat_user);
86
87 $connector = $this->gui->getConnector();
88 $response = $connector->sendLeavePrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
89
90 if ($room->userIsInPrivateRoom($subRoom, $chat_user->getUserId())) {
91 $room->unsubscribeUserFromPrivateRoom($subRoom, $chat_user->getUserId());
92 }
93
94 $this->sendResponse($response);
95 }
96
97 public function enter()
98 {
99 $this->redirectIfNoPermission('read');
100
101 $room = ilChatroom::byObjectId($this->gui->object->getId());
102 $subRoom = $_REQUEST['sub'];
103 $chat_user = new ilChatroomUser($this->ilUser, $room);
104
105 $this->exitIfNoRoomExists($room);
106 $this->exitIfEnterRoomIsNotAllowed($room, $subRoom, $chat_user);
107
108 $connector = $this->gui->getConnector();
109 $response = $connector->sendEnterPrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
110
111 if ($this->isSuccessful($response)) {
112 $room->subscribeUserToPrivateRoom($subRoom, $chat_user->getUserId());
113 }
114
115 $this->sendResponse($response);
116 }
117
123 protected function exitIfEnterRoomIsNotAllowed($room, $subRoom, $chat_user)
124 {
125 if (!$room->isAllowedToEnterPrivateRoom($chat_user->getUserId(), $subRoom)) {
126 $this->sendResponse(array(
127 'success' => false,
128 'reason' => 'not allowed enter to private room'
129 ));
130 }
131 }
132
133 public function listUsers()
134 {
135 $room = ilChatroom::byObjectId($this->gui->object->getId());
136
137 $response = $room->listUsersInPrivateRoom($_REQUEST['sub']);
138 $this->sendResponse($response);
139 }
140}
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)
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