ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
5 require_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($_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  {
56  $response = array(
57  'success' => true,
58  'title' => $title,
59  'owner' => $chat_user->getUserId(),
60  'subRoomId' => $subRoomId
61  );
62  }
63 
64  $this->sendResponse($response);
65  }
66 
71  protected function exitIfNoRoomSubscription($room, $chat_user)
72  {
73  if(!$room->isSubscribed($chat_user->getUserId()))
74  {
75  $this->sendResponse(array(
76  'success' => false,
77  'reason' => 'not subscribed'
78  ));
79  }
80  }
81 
82  public function delete()
83  {
84  $room = ilChatroom::byObjectId($this->gui->object->getId());
85  $subRoom = $_REQUEST['sub'];
86  $chat_user = new ilChatroomUser($this->ilUser, $room);
87 
88  $this->exitIfNoRoomExists($room);
89  $this->exitIfNoRoomSubscription($room, $chat_user);
90 
91  $room->closePrivateRoom($subRoom);
92 
93  $connector = $this->gui->getConnector();
94  $response = $connector->sendDeletePrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
95 
96  $this->sendResponse($response);
97  }
98 
99  public function leave()
100  {
101  $room = ilChatroom::byObjectId($this->gui->object->getId());
102  $chat_user = new ilChatroomUser($this->ilUser, $room);
103  $subRoom = $_REQUEST['sub'];
104 
105  $this->exitIfNoRoomExists($room);
106  $this->exitIfNoRoomSubscription($room, $chat_user);
107 
108  $connector = $this->gui->getConnector();
109  $response = $connector->sendLeavePrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
110 
111  if($room->userIsInPrivateRoom($subRoom, $chat_user->getUserId()))
112  {
113  $room->unsubscribeUserFromPrivateRoom($subRoom, $chat_user->getUserId());
114  }
115 
116  $this->sendResponse($response);
117  }
118 
119  public function enter()
120  {
121  global $ilUser;
122 
123  ilChatroom::checkUserPermissions('read', $this->gui->ref_id);
124 
125  $room = ilChatroom::byObjectId($this->gui->object->getId());
126  $subRoom = $_REQUEST['sub'];
127  $chat_user = new ilChatroomUser($ilUser, $room);
128 
129  $this->exitIfNoRoomExists($room);
130  $this->exitIfEnterRoomIsNotAllowed($room, $subRoom, $chat_user);
131 
132  /*$params = array();
133 
134  $params['user'] = $chat_user->getUserId();
135  $params['sub'] = $_REQUEST['sub'];
136  $params['message'] = json_encode( array(
137  'type' => 'private_room_entered',
138  'user' => $user_id
139  ));*/
140 
141  //$query = http_build_query( $params );
142  $connector = $this->gui->getConnector();
143  $response = $connector->sendEnterPrivateRoom($room->getRoomId(), $subRoom, $chat_user->getUserId());
144 
145  if($this->isSuccessful($response))
146  {
147  $room->subscribeUserToPrivateRoom($subRoom, $chat_user->getUserId());
148  }
149 
150  /*$message = json_encode( array(
151  'type' => 'private_room_entered',
152  'user' => $params['user'],
153  'sub' => $params['sub']
154  ));
155 
156  $connector->sendMessage( $room->getRoomId(), $message, array('public' => 1, 'sub' => $params['sub']) );*/
157 
158  $this->sendResponse($response);
159  }
160 
166  protected function exitIfEnterRoomIsNotAllowed($room, $subRoom, $chat_user)
167  {
168  if(!$room->isAllowedToEnterPrivateRoom($chat_user->getUserId(), $subRoom))
169  {
170  $this->sendResponse(array(
171  'success' => false,
172  'reason' => 'not allowed enter to private room'
173  ));
174  }
175  }
176 
177  public function listUsers()
178  {
179  $room = ilChatroom::byObjectId($this->gui->object->getId());
180 
181  $response = $room->listUsersInPrivateRoom($_REQUEST['sub']);
182  $this->sendResponse($response);
183  }
184 }
185 
186 ?>
Class ilChatroomPrivateRoomGUI.
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.
exitIfEnterRoomIsNotAllowed($room, $subRoom, $chat_user)
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
Class ilChatroomGUIHandler.
isSuccessful($response)
Checks for success param in an json decoded response.
Create styles array
The data for the language used.
__construct(ilChatroomObjectGUI $gui)
ilChatroomPrivateRoomGUI constructor.
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.