ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
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)
 
 isServerAlive ()
 
 connect (int $scope, int $userId)
 Creates connect URL using given $scope and $userId and returns it. More...
 
 sendCreatePrivateRoom (int $scope, int $subScope, int $user, string $title)
 
 sendDeletePrivateRoom (int $scope, int $subScope, int $user)
 
 enterPrivateRoom (int $scope, int $subScope, int $user)
 
 sendEnterPrivateRoom (int $scope, int $subScope, int $user)
 
 sendClearMessages (int $scope, int $subScope, int $user)
 
 leavePrivateRoom (int $scope, int $subScope, int $user)
 
 sendLeavePrivateRoom (int $scope, int $subScope, int $user)
 
 sendKick (int $scope, int $subScope, int $user)
 
 kick (int $scope, int $subScope, int $user)
 Returns kick URL Creates kick URL using given $scope and $query and returns it. More...
 
 sendBan (int $scope, int $subScope, int $user)
 
 getSettings ()
 
 sendInviteToPrivateRoom (int $scope, int $subScope, int $user, int $invited_id)
 
 sendUserConfigChange (string $message)
 

Static Public Member Functions

static checkServerConnection (bool $use_cache=true)
 

Protected Member Functions

 file_get_contents (string $url, ?array $stream_context_params=null)
 

Static Protected Attributes

static bool $connection_status = null
 

Private Attributes

ilChatroomServerSettings $settings
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilChatroomServerConnector::__construct ( ilChatroomServerSettings  $settings)

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

References $settings, and ILIAS\Repository\settings().

34  {
35  $this->settings = $settings;
36  }
+ Here is the call graph for this function:

Member Function Documentation

◆ checkServerConnection()

static ilChatroomServerConnector::checkServerConnection ( bool  $use_cache = true)
static

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

References ilChatroomAdmin\getDefaultConfiguration().

Referenced by ilChatroomAdminViewGUI\checkServerConnection().

38  : bool
39  {
40  if ($use_cache && self::$connection_status !== null) {
41  return self::$connection_status;
42  }
43 
44  $connector = new self(ilChatroomAdmin::getDefaultConfiguration()->getServerSettings());
45  self::$connection_status = $connector->isServerAlive();
46 
47  return self::$connection_status;
48  }
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ connect()

ilChatroomServerConnector::connect ( int  $scope,
int  $userId 
)

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

Parameters
int$scope
int$userId
Returns
string|false

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

References file_get_contents(), and ILIAS\Repository\settings().

80  {
81  return $this->file_get_contents(
82  $this->settings->getURL('Connect', (string) $scope) . '/' . $userId
83  );
84  }
$scope
Definition: ltiregstart.php:53
file_get_contents(string $url, ?array $stream_context_params=null)
+ Here is the call graph for this function:

◆ enterPrivateRoom()

ilChatroomServerConnector::enterPrivateRoom ( int  $scope,
int  $subScope,
int  $user 
)
Parameters
int$scope
int$subScope
int$user
Returns
string|false
Deprecated:
Please use sendEnterPrivateRoom instead

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

References sendEnterPrivateRoom().

165  {
166  return $this->sendEnterPrivateRoom($scope, $subScope, $user);
167  }
$scope
Definition: ltiregstart.php:53
sendEnterPrivateRoom(int $scope, int $subScope, int $user)
+ Here is the call graph for this function:

◆ file_get_contents()

ilChatroomServerConnector::file_get_contents ( string  $url,
?array  $stream_context_params = null 
)
protected
Parameters
string$url
array$stream_context_params
Returns
string|false

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

References Vendor\Package\$e, $message, ilLoggerFactory\getLogger(), and ILIAS\Repository\settings().

Referenced by connect(), isServerAlive(), kick(), sendBan(), sendClearMessages(), sendCreatePrivateRoom(), sendDeletePrivateRoom(), sendEnterPrivateRoom(), sendInviteToPrivateRoom(), sendLeavePrivateRoom(), and sendUserConfigChange().

92  {
93  $credentials = $this->settings->getAuthKey() . ':' . $this->settings->getAuthSecret();
94  $header =
95  "Connection: close\r\n" .
96  "Content-Type: application/json; charset=utf-8\r\n" .
97  "Authorization: Basic " . base64_encode($credentials);
98 
99  $ctx = [
100  'http' => [
101  'method' => 'GET',
102  'header' => $header
103  ],
104  'https' => [
105  'method' => 'GET',
106  'header' => $header
107  ]
108  ];
109 
110  if (is_array($stream_context_params)) {
111  $ctx = array_merge_recursive($ctx, $stream_context_params);
112  }
113 
114  set_error_handler(static function (int $severity, string $message, string $file, int $line): void {
115  throw new ErrorException($message, $severity, $severity, $file, $line);
116  });
117 
118  try {
119  return file_get_contents($url, false, stream_context_create($ctx));
120  } catch (Exception $e) {
121  ilLoggerFactory::getLogger('chatroom')->alert($e->getMessage());
122  } finally {
123  restore_error_handler();
124  }
125 
126  return false;
127  }
static getLogger(string $a_component_id)
Get component logger.
$message
Definition: xapiexit.php:32
$url
file_get_contents(string $url, ?array $stream_context_params=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSettings()

ilChatroomServerConnector::getSettings ( )

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

References $settings.

259  {
260  return $this->settings;
261  }
Class ilChatroomServerSettings.

◆ isServerAlive()

ilChatroomServerConnector::isServerAlive ( )

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

References $response, file_get_contents(), ILIAS\Repository\int(), and ILIAS\Repository\settings().

50  : bool
51  {
53  $this->settings->getURL('Heartbeat'),
54  [
55  'http' => [
56  'timeout' => 2
57  ],
58  'https' => [
59  'timeout' => 2
60  ]
61  ]
62  );
63 
64  if (false === $response) {
65  return false;
66  }
67 
68  $responseObject = json_decode($response, false, 512, JSON_THROW_ON_ERROR);
69 
70  return $responseObject instanceof stdClass && ((int) $responseObject->status) === 200;
71  }
file_get_contents(string $url, ?array $stream_context_params=null)
$response
+ Here is the call graph for this function:

◆ kick()

ilChatroomServerConnector::kick ( int  $scope,
int  $subScope,
int  $user 
)

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

Parameters
int$scope
int$subScope
int$user
Returns
string|false

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

References file_get_contents(), and ILIAS\Repository\settings().

Referenced by sendKick().

239  {
240  return $this->file_get_contents(
241  $this->settings->getURL('Kick', (string) $scope) . '/' . $subScope . '/' . $user
242  );
243  }
$scope
Definition: ltiregstart.php:53
file_get_contents(string $url, ?array $stream_context_params=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ leavePrivateRoom()

ilChatroomServerConnector::leavePrivateRoom ( int  $scope,
int  $subScope,
int  $user 
)
Parameters
int$scope
int$subScope
int$user
Returns
string|false

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

References sendLeavePrivateRoom().

202  {
203  return $this->sendLeavePrivateRoom($scope, $subScope, $user);
204  }
$scope
Definition: ltiregstart.php:53
sendLeavePrivateRoom(int $scope, int $subScope, int $user)
+ Here is the call graph for this function:

◆ sendBan()

ilChatroomServerConnector::sendBan ( int  $scope,
int  $subScope,
int  $user 
)
Parameters
int$scope
int$subScope
int$user
Returns
string|false

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

References file_get_contents(), and ILIAS\Repository\settings().

252  {
253  return $this->file_get_contents(
254  $this->settings->getURL('Ban', (string) $scope) . '/' . $subScope . '/' . $user
255  );
256  }
$scope
Definition: ltiregstart.php:53
file_get_contents(string $url, ?array $stream_context_params=null)
+ Here is the call graph for this function:

◆ sendClearMessages()

ilChatroomServerConnector::sendClearMessages ( int  $scope,
int  $subScope,
int  $user 
)
Parameters
int$scope
int$subScope
int$user
Returns
string|false

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

References file_get_contents(), and ILIAS\Repository\settings().

189  {
190  return $this->file_get_contents(
191  $this->settings->getURL('ClearMessages', (string) $scope) . '/' . $subScope . '/' . $user
192  );
193  }
$scope
Definition: ltiregstart.php:53
file_get_contents(string $url, ?array $stream_context_params=null)
+ Here is the call graph for this function:

◆ sendCreatePrivateRoom()

ilChatroomServerConnector::sendCreatePrivateRoom ( int  $scope,
int  $subScope,
int  $user,
string  $title 
)
Parameters
int$scope
int$subScope
int$user
string$title
Returns
string|false

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

References file_get_contents(), and ILIAS\Repository\settings().

137  {
138  return $this->file_get_contents(
139  $this->settings->getURL('CreatePrivateRoom', (string) $scope) .
140  '/' . $subScope . '/' . $user . '/' . rawurlencode($title)
141  );
142  }
$scope
Definition: ltiregstart.php:53
file_get_contents(string $url, ?array $stream_context_params=null)
+ Here is the call graph for this function:

◆ sendDeletePrivateRoom()

ilChatroomServerConnector::sendDeletePrivateRoom ( int  $scope,
int  $subScope,
int  $user 
)
Parameters
int$scope
int$subScope
int$user
Returns
string|false

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

References file_get_contents(), and ILIAS\Repository\settings().

151  {
152  return $this->file_get_contents(
153  $this->settings->getURL('DeletePrivateRoom', (string) $scope) . '/' . $subScope . '/' . $user
154  );
155  }
$scope
Definition: ltiregstart.php:53
file_get_contents(string $url, ?array $stream_context_params=null)
+ Here is the call graph for this function:

◆ sendEnterPrivateRoom()

ilChatroomServerConnector::sendEnterPrivateRoom ( int  $scope,
int  $subScope,
int  $user 
)
Parameters
int$scope
int$subScope
int$user
Returns
string|false

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

References file_get_contents(), and ILIAS\Repository\settings().

Referenced by enterPrivateRoom().

176  {
177  return $this->file_get_contents(
178  $this->settings->getURL('EnterPrivateRoom', (string) $scope) . '/' . $subScope . '/' . $user
179  );
180  }
$scope
Definition: ltiregstart.php:53
file_get_contents(string $url, ?array $stream_context_params=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendInviteToPrivateRoom()

ilChatroomServerConnector::sendInviteToPrivateRoom ( int  $scope,
int  $subScope,
int  $user,
int  $invited_id 
)
Parameters
int$scope
int$subScope
int$user
int$invited_id
Returns
string|false

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

References file_get_contents(), and ILIAS\Repository\settings().

271  {
272  return $this->file_get_contents(
273  $this->settings->getURL('InvitePrivateRoom', (string) $scope) .
274  '/' . $subScope . '/' . $user . '/' . $invited_id
275  );
276  }
$scope
Definition: ltiregstart.php:53
file_get_contents(string $url, ?array $stream_context_params=null)
+ Here is the call graph for this function:

◆ sendKick()

ilChatroomServerConnector::sendKick ( int  $scope,
int  $subScope,
int  $user 
)
Parameters
int$scope
int$subScope
int$user
Returns
string|false

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

References kick().

226  {
227  return $this->kick($scope, $subScope, $user);
228  }
kick(int $scope, int $subScope, int $user)
Returns kick URL Creates kick URL using given $scope and $query and returns it.
$scope
Definition: ltiregstart.php:53
+ Here is the call graph for this function:

◆ sendLeavePrivateRoom()

ilChatroomServerConnector::sendLeavePrivateRoom ( int  $scope,
int  $subScope,
int  $user 
)
Parameters
int$scope
int$subScope
int$user
Returns
string|false

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

References file_get_contents(), and ILIAS\Repository\settings().

Referenced by leavePrivateRoom().

213  {
214  return $this->file_get_contents(
215  $this->settings->getURL('LeavePrivateRoom', (string) $scope) . '/' . $subScope . '/' . $user
216  );
217  }
$scope
Definition: ltiregstart.php:53
file_get_contents(string $url, ?array $stream_context_params=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendUserConfigChange()

ilChatroomServerConnector::sendUserConfigChange ( string  $message)
Parameters
string$message
Returns
string|false

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

References $query, file_get_contents(), and ILIAS\Repository\settings().

283  {
284  $query = http_build_query(['message' => $message]);
285 
286  return $this->file_get_contents(
287  $this->settings->getURL('UserConfigChange', null) . '?' . $query
288  );
289  }
$query
$message
Definition: xapiexit.php:32
file_get_contents(string $url, ?array $stream_context_params=null)
+ Here is the call graph for this function:

Field Documentation

◆ $connection_status

bool ilChatroomServerConnector::$connection_status = null
staticprotected

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

◆ $settings

ilChatroomServerSettings ilChatroomServerConnector::$settings
private

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

Referenced by __construct(), and getSettings().


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