ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 ($use_cache=true)
 

Static Protected Attributes

static $connection_status = null
 

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 27 of file class.ilChatroomServerConnector.php.

References $settings.

28  {
29  $this->settings = $settings;
30  }

Member Function Documentation

◆ checkServerConnection()

static ilChatroomServerConnector::checkServerConnection (   $use_cache = true)
static
Parameters
bool | true$use_cache
Returns
bool

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

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

297  {
298  if($use_cache && self::$connection_status !== null)
299  {
300  return self::$connection_status;
301  }
302 
303  require_once 'Modules/Chatroom/classes/class.ilChatroomAdmin.php';
304  $connector = new self(ilChatroomAdmin::getDefaultConfiguration()->getServerSettings());
305  self::$connection_status = (bool)$connector->isServerAlive();
306 
307  return self::$connection_status;
308  }
+ 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 73 of file class.ilChatroomServerConnector.php.

References file_get_contents().

74  {
75  return $this->file_get_contents(
76  $this->settings->getURL('Connect', $scope) . '?id=' . $userId
77  );
78  }
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 223 of file class.ilChatroomServerConnector.php.

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

224  {
225  $settings = array(
226  'public' => false,
227  );
228 
229  $params['user'] = $owner->getUserId();
230  $params['id'] = $room->addPrivateRoom($title, $owner, $settings);
231 
232  $query = http_build_query($params);
233  $response = $this->sendCreatePrivateRoom($room->getRoomId(), $query);
234  $responseObject = json_decode($response);
235  $return = $responseObject;
236  if($responseObject->success == true)
237  {
238  $message = json_encode(array(
239  'type' => 'private_room_created',
240  'timestamp' => date('c'),
241  'public' => 0,
242  'title' => $title,
243  'id' => $responseObject->id,
244  'proom_id' => $responseObject->id,
245  'owner' => $owner->getUserId(),
246  ));
247 
248  $result = $this->sendMessage($room->getRoomId(), $message, array('public' => 0, 'recipients' => $owner->getUserId()));
249 
250  $params = array();
251  $params['user'] = $owner->getUserId();
252  $params['sub'] = $responseObject->id;
253 
254  $query = http_build_query($params);
255  $response = $this->enterPrivateRoom($room->getRoomId(), $query);
256 
257  $room->subscribeUserToPrivateRoom($params['sub'], $params['user']);
258 
259  $message = json_encode(array(
260  'type' => 'private_room_entered',
261  'user' => $owner->getUserId(),
262  'timestamp' => date('c'),
263  'sub' => $responseObject->id
264  ));
265  $this->sendMessage($room->getRoomId(), $message);
266  }
267  return $responseObject;
268  }
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)
$params
Definition: example_049.php:96
+ Here is the call graph for this function:

◆ enterPrivateRoom()

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

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

References $query, and file_get_contents().

Referenced by createPrivateRoom().

112  {
113  return $this->file_get_contents(
114  $this->settings->getURL('EnterPrivateRoom', $scope) . '?' . $query
115  );
116  }
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|false

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

References $url, and ilLoggerFactory\getLogger().

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

38  {
39  $ctx = array(
40  'http' => array(
41  'header' => 'Connection: close'
42  ),
43  'https' => array(
44  'header' => 'Connection: close'
45  )
46  );
47 
48  if(is_array($stream_context_params))
49  {
50  $ctx = array_merge_recursive($ctx, $stream_context_params);
51  }
52 
53  try
54  {
55  $response = file_get_contents($url, null, stream_context_create($ctx));
56  return $response;
57  }
58  catch(Exception $e)
59  {
60  ilLoggerFactory::getLogger('chatroom')->alert($e->getMessage());
61  }
62 
63  return false;
64  }
$url
Definition: shib_logout.php:72
file_get_contents($url, array $stream_context_params=null)
static getLogger($a_component_id)
Get component logger.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSettings()

ilChatroomServerConnector::getSettings ( )

Returns $this->settings.

Returns
ilChatroomServerSettings

Definition at line 148 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 176 of file class.ilChatroomServerConnector.php.

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

177  {
178  $chat_user = new ilChatroomUser($inviter, $room);
179  $user_id = $chat_user->getUserId();
180 
181  if($scope)
182  {
183  $room->inviteUserToPrivateRoom($invited_id, $scope);
184  $message = json_encode(array(
185  'type' => 'private_room_created',
186  'users' => $invited_id, //$users,
187  'timestamp' => date('c'),
188  'public' => 0,
189  'title' => ilChatroom::lookupPrivateRoomTitle($scope),
190  'proom_id' => $scope,
191  'message' => array(
192  'public' => '0',
193  'user' => 'system',
194  'owner' => $user_id
195  )
196  ));
197 
198  $this->sendMessage($room->getRoomId(), $message, array('public' => 0, 'recipients' => $invited_id));
199  }
200 
201  if($room->isSubscribed($user_id))
202  {
203  $message = json_encode(array(
204  'type' => 'user_invited',
205  'title' => ilChatroom::lookupPrivateRoomTitle($scope),
206  'proom_id' => $scope,
207  'inviter' => $inviter->getId(),
208  'invited' => $invited_id
209  ));
210 
211  $this->sendMessage($room->getRoomId(), $message, array('public' => 0, 'recipients' => $invited_id));
212  }
213 
214  return array('success' => true, 'message' => 'users invited');
215  }
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 273 of file class.ilChatroomServerConnector.php.

References file_get_contents().

274  {
275  $response = $this->file_get_contents(
276  $this->settings->getURL('Status', 0),
277  array(
278  'http' => array(
279  'timeout' => 2
280  ),
281  'https' => array(
282  'timeout' => 2
283  )
284  )
285  );
286 
287  $responseObject = json_decode($response);
288 
289  return $responseObject->success == true;
290  }
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 137 of file class.ilChatroomServerConnector.php.

References $query, and file_get_contents().

138  {
139  return $this->file_get_contents(
140  $this->settings->getURL('Kick', $scope) . '?' . $query
141  );
142  }
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 123 of file class.ilChatroomServerConnector.php.

References $query, and file_get_contents().

124  {
125  return $this->file_get_contents(
126  $this->settings->getURL('LeavePrivateRoom', $scope) . '?' . $query
127  );
128  }
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 87 of file class.ilChatroomServerConnector.php.

References $query, and file_get_contents().

Referenced by sendMessage().

88  {
89  return $this->file_get_contents(
90  $this->settings->getURL('Post', $scope) . '?' . $query
91  );
92  }
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 99 of file class.ilChatroomServerConnector.php.

References $query, and file_get_contents().

Referenced by createPrivateRoom().

100  {
101  return $this->file_get_contents(
102  $this->settings->getURL('CreatePrivateRoom', $scope) . '?' . $query
103  );
104  }
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 162 of file class.ilChatroomServerConnector.php.

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

Referenced by createPrivateRoom(), and inviteToPrivateRoom().

163  {
164  $query = http_build_query(array('message' => $message) + $options);
165  $response = $this->post($scope, $query);
166  return @json_decode($response);
167  }
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

◆ $connection_status

ilChatroomServerConnector::$connection_status = null
staticprotected

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

◆ $settings

ilChatroomServerConnector::$settings
private

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

Referenced by __construct(), createPrivateRoom(), and getSettings().


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