ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
ilChatroomServerConnector Class Reference

Class ilChatroomServerConnector. More...

+ Collaboration diagram for ilChatroomServerConnector:

Public Member Functions

 __construct (ilChatroomServerSettings $settings)
 Constructor Sets $this->settings using given $settings. More...
 
 connect ($scope, $userId)
 Returns connect URL Creates connect URL using given $scope and $userId and returns it. More...
 
 post ($scope, $query)
 Returns post URL Creates post URL using given $scope and $query and returns it. More...
 
 enterPrivateRoom ($scope, $query)
 
 leavePrivateRoom ($scope, $query)
 
 kick ($scope, $query)
 Returns kick URL Creates kick URL using given $scope and $query and returns it. More...
 
 getSettings ()
 Returns $this->settings. More...
 
 sendMessage ($scope, $message, $options=array())
 Returns if given message is sucessfully sent. More...
 
 inviteToPrivateRoom (ilChatRoom $room, $scope, ilObjUser $inviter, $invited_id)
 
 createPrivateRoom (ilChatroom $room, $title, ilChatroomUser $owner)
 
 isServerAlive ()
 

Static Public Member Functions

static checkServerConnection ()
 

Private Member Functions

 file_get_contents ($url, array $stream_context_params=null)
 
 sendCreatePrivateRoom ($scope, $query)
 

Private Attributes

 $settings
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilChatroomServerConnector::__construct ( ilChatroomServerSettings  $settings)

Constructor Sets $this->settings using given $settings.

Parameters
ilChatroomServerSettings$settings

Definition at line 22 of file class.ilChatroomServerConnector.php.

References $settings.

23  {
24  $this->settings = $settings;
25  }

Member Function Documentation

◆ checkServerConnection()

static ilChatroomServerConnector::checkServerConnection ( )
static
Returns
bool

Definition at line 280 of file class.ilChatroomServerConnector.php.

References $settings.

Referenced by ilChatroomViewTask\checkPrivHosts(), and ilChatroomBlockGUI\getHTML().

281  {
282  require_once 'Modules/Chatroom/classes/class.ilChatroomAdmin.php';
283  $settings = ilChatroomAdmin::getDefaultConfiguration()->getServerSettings();
284  $connector = new ilChatroomServerConnector($settings);
285  return $connector->isServerAlive();
286  }
Class ilChatroomServerConnector.
+ Here is the caller graph for this function:

◆ connect()

ilChatroomServerConnector::connect (   $scope,
  $userId 
)

Returns connect URL Creates connect URL using given $scope and $userId and returns it.

Parameters
string$scope
integer$userId
Returns
mixed

Definition at line 58 of file class.ilChatroomServerConnector.php.

References file_get_contents().

59  {
60  return $this->file_get_contents(
61  $this->settings->getURL('Connect', $scope) . '?id=' . $userId
62  );
63  }
file_get_contents($url, array $stream_context_params=null)
+ Here is the call graph for this function:

◆ createPrivateRoom()

ilChatroomServerConnector::createPrivateRoom ( ilChatroom  $room,
  $title,
ilChatroomUser  $owner 
)
Parameters
ilChatroom$room
string$title
ilChatroomUser$owner
Returns
mixed

Definition at line 208 of file class.ilChatroomServerConnector.php.

References $query, $result, $settings, ilChatroom\addPrivateRoom(), enterPrivateRoom(), ilChatroom\getRoomId(), ilChatroomUser\getUserId(), sendCreatePrivateRoom(), sendMessage(), and ilChatroom\subscribeUserToPrivateRoom().

209  {
210  $settings = array(
211  'public' => false,
212  );
213 
214  $params['user'] = $owner->getUserId();
215  $params['id'] = $room->addPrivateRoom($title, $owner, $settings);
216 
217  $query = http_build_query($params);
218  $response = $this->sendCreatePrivateRoom($room->getRoomId(), $query);
219  $responseObject = json_decode($response);
220  $return = $responseObject;
221  if($responseObject->success == true)
222  {
223  $message = json_encode(array(
224  'type' => 'private_room_created',
225  'timestamp' => date('c'),
226  'public' => 0,
227  'title' => $title,
228  'id' => $responseObject->id,
229  'proom_id' => $responseObject->id,
230  'owner' => $owner->getUserId(),
231  ));
232 
233  $result = $this->sendMessage($room->getRoomId(), $message, array('public' => 0, 'recipients' => $owner->getUserId()));
234 
235  $params = array();
236  $params['user'] = $owner->getUserId();
237  $params['sub'] = $responseObject->id;
238 
239  $query = http_build_query($params);
240  $response = $this->enterPrivateRoom($room->getRoomId(), $query);
241 
242  $room->subscribeUserToPrivateRoom($params['sub'], $params['user']);
243 
244  $message = json_encode(array(
245  'type' => 'private_room_entered',
246  'user' => $owner->getUserId(),
247  'timestamp' => date('c'),
248  'sub' => $responseObject->id
249  ));
250  $this->sendMessage($room->getRoomId(), $message);
251  }
252  return $responseObject;
253  }
getUserId()
Returns Ilias User ID.
getRoomId()
Returns roomID from $this->roomId.
$result
sendMessage($scope, $message, $options=array())
Returns if given message is sucessfully sent.
addPrivateRoom($title, ilChatroomUser $owner, $settings)
subscribeUserToPrivateRoom($room_id, $user_id)
+ Here is the call graph for this function:

◆ enterPrivateRoom()

ilChatroomServerConnector::enterPrivateRoom (   $scope,
  $query 
)
Parameters
string$scope
string$query
Returns
mixed

Definition at line 96 of file class.ilChatroomServerConnector.php.

References $query, and file_get_contents().

Referenced by createPrivateRoom().

97  {
98  return $this->file_get_contents(
99  $this->settings->getURL('EnterPrivateRoom', $scope) . '?' . $query
100  );
101  }
file_get_contents($url, array $stream_context_params=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ file_get_contents()

ilChatroomServerConnector::file_get_contents (   $url,
array  $stream_context_params = null 
)
private
Parameters
string$url
array$stream_context_params
Returns
string

Definition at line 32 of file class.ilChatroomServerConnector.php.

Referenced by connect(), enterPrivateRoom(), isServerAlive(), kick(), leavePrivateRoom(), post(), and sendCreatePrivateRoom().

33  {
34  $ctx = array(
35  'http' => array(
36  'header' => 'Connection: close'
37  ),
38  'https' => array(
39  'header' => 'Connection: close'
40  )
41  );
42 
43  if(is_array($stream_context_params))
44  {
45  $ctx = array_merge_recursive($ctx, $stream_context_params);
46  }
47 
48  return file_get_contents($url, null, stream_context_create($ctx));
49  }
file_get_contents($url, array $stream_context_params=null)
+ Here is the caller graph for this function:

◆ getSettings()

ilChatroomServerConnector::getSettings ( )

Returns $this->settings.

Returns
ilChatroomServerSettings

Definition at line 133 of file class.ilChatroomServerConnector.php.

References $settings.

◆ inviteToPrivateRoom()

ilChatroomServerConnector::inviteToPrivateRoom ( ilChatRoom  $room,
  $scope,
ilObjUser  $inviter,
  $invited_id 
)
Parameters
ilChatRoom$room
int$scope
ilObjUser$inviter
int$invited_id
Returns
array

Definition at line 161 of file class.ilChatroomServerConnector.php.

References ilObject\getId(), ilChatroom\lookupPrivateRoomTitle(), and sendMessage().

162  {
163  $chat_user = new ilChatroomUser($inviter, $room);
164  $user_id = $chat_user->getUserId();
165 
166  if($scope)
167  {
168  $room->inviteUserToPrivateRoom($invited_id, $scope);
169  $message = json_encode(array(
170  'type' => 'private_room_created',
171  'users' => $invited_id, //$users,
172  'timestamp' => date('c'),
173  'public' => 0,
174  'title' => ilChatroom::lookupPrivateRoomTitle($scope),
175  'proom_id' => $scope,
176  'message' => array(
177  'public' => '0',
178  'user' => 'system',
179  'owner' => $user_id
180  )
181  ));
182 
183  $this->sendMessage($room->getRoomId(), $message, array('public' => 0, 'recipients' => $invited_id));
184  }
185 
186  if($room->isSubscribed($user_id))
187  {
188  $message = json_encode(array(
189  'type' => 'user_invited',
190  'title' => ilChatroom::lookupPrivateRoomTitle($scope),
191  'proom_id' => $scope,
192  'inviter' => $inviter->getId(),
193  'invited' => $invited_id
194  ));
195 
196  $this->sendMessage($room->getRoomId(), $message, array('public' => 0, 'recipients' => $invited_id));
197  }
198 
199  return array('success' => true, 'message' => 'users invited');
200  }
sendMessage($scope, $message, $options=array())
Returns if given message is sucessfully sent.
getId()
get object id public
static lookupPrivateRoomTitle($proom_id)
Class ilChatroomUser.
+ Here is the call graph for this function:

◆ isServerAlive()

ilChatroomServerConnector::isServerAlive ( )
Returns
bool

Definition at line 258 of file class.ilChatroomServerConnector.php.

References file_get_contents().

259  {
260  $response = @$this->file_get_contents(
261  $this->settings->getURL('Status', 0),
262  array(
263  'http' => array(
264  'timeout' => 2
265  ),
266  'https' => array(
267  'timeout' => 2
268  )
269  )
270  );
271 
272  $responseObject = json_decode($response);
273 
274  return $responseObject->success == true;
275  }
file_get_contents($url, array $stream_context_params=null)
+ Here is the call graph for this function:

◆ kick()

ilChatroomServerConnector::kick (   $scope,
  $query 
)

Returns kick URL Creates kick URL using given $scope and $query and returns it.

Parameters
string$scope
string$query
Returns
mixed

Definition at line 122 of file class.ilChatroomServerConnector.php.

References $query, and file_get_contents().

123  {
124  return $this->file_get_contents(
125  $this->settings->getURL('Kick', $scope) . '?' . $query
126  );
127  }
file_get_contents($url, array $stream_context_params=null)
+ Here is the call graph for this function:

◆ leavePrivateRoom()

ilChatroomServerConnector::leavePrivateRoom (   $scope,
  $query 
)
Parameters
string$scope
string$query
Returns
mixed

Definition at line 108 of file class.ilChatroomServerConnector.php.

References $query, and file_get_contents().

109  {
110  return $this->file_get_contents(
111  $this->settings->getURL('LeavePrivateRoom', $scope) . '?' . $query
112  );
113  }
file_get_contents($url, array $stream_context_params=null)
+ Here is the call graph for this function:

◆ post()

ilChatroomServerConnector::post (   $scope,
  $query 
)

Returns post URL Creates post URL using given $scope and $query and returns it.

Parameters
string$scope
string$query
Returns
mixed

Definition at line 72 of file class.ilChatroomServerConnector.php.

References $query, and file_get_contents().

Referenced by sendMessage().

73  {
74  return $this->file_get_contents(
75  $this->settings->getURL('Post', $scope) . '?' . $query
76  );
77  }
file_get_contents($url, array $stream_context_params=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendCreatePrivateRoom()

ilChatroomServerConnector::sendCreatePrivateRoom (   $scope,
  $query 
)
private
Parameters
string$scope
string$query
Returns
mixed

Definition at line 84 of file class.ilChatroomServerConnector.php.

References $query, and file_get_contents().

Referenced by createPrivateRoom().

85  {
86  return $this->file_get_contents(
87  $this->settings->getURL('CreatePrivateRoom', $scope) . '?' . $query
88  );
89  }
file_get_contents($url, array $stream_context_params=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendMessage()

ilChatroomServerConnector::sendMessage (   $scope,
  $message,
  $options = array() 
)

Returns if given message is sucessfully sent.

Calls $this->post using given $scope and $query built by http_build_query with given $message and returns if message was sent sucessfully.

Parameters
string$scope
string$message
Returns
stdClass

Definition at line 147 of file class.ilChatroomServerConnector.php.

References $options, $query, and post().

Referenced by createPrivateRoom(), and inviteToPrivateRoom().

148  {
149  $query = http_build_query(array('message' => $message) + $options);
150  $response = $this->post($scope, $query);
151  return @json_decode($response);
152  }
post($scope, $query)
Returns post URL Creates post URL using given $scope and $query and returns it.
if(!is_array($argv)) $options
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $settings

ilChatroomServerConnector::$settings
private

The documentation for this class was generated from the following file: