ILIAS  release_8 Revision v8.24
class.ilChatroomServerSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 private const DEFAULT_PORT = 8585;
30 private const DEFAULT_PROCOTOL = 'http://';
31 private const DEFAULT_HOST = '192.168.1.94';
32
33 public const PREFIX = '/backend';
36 private string $domain = self::DEFAULT_HOST;
37 private string $instance = '123456';
38 private bool $smilies_enabled = false;
39 private string $authKey = '';
40 private string $authSecret = '';
41 private bool $clientUrlEnabled = false;
42 private string $clientUrl = '';
43 private bool $iliasUrlEnabled = false;
44 private string $iliasUrl = '';
45 private string $subDirectory = '';
46
47 public static function loadDefault(): self
48 {
49 global $DIC;
50
51 $query = 'SELECT * FROM chatroom_admconfig';
52 $rset = $DIC->database()->query($query);
53 $row = $DIC->database()->fetchAssoc($rset);
54
55 $client_settings = json_decode($row['client_settings'], false, 512, JSON_THROW_ON_ERROR);
56 $server_settings = json_decode($row['server_settings'], false, 512, JSON_THROW_ON_ERROR);
57
58 $settings = new self();
59 if ($server_settings instanceof stdClass) {
60 $settings->setPort((int) ($server_settings->port ?? self::DEFAULT_PORT));
61 $settings->setProtocol((string) ($server_settings->protocol ?? self::DEFAULT_PROCOTOL));
62 $settings->setDomain((string) ($server_settings->address ?? self::DEFAULT_HOST));
63 $settings->setSmiliesEnabled((bool) ($client_settings->enable_smilies ?? false));
64 $settings->setClientUrlEnabled((bool) ($server_settings->client_proxy ?? false));
65 $settings->setIliasUrlEnabled((bool) ($server_settings->ilias_proxy ?? false));
66 $settings->setClientUrl((string) ($server_settings->client_url ?? ''));
67 $settings->setIliasUrl((string) ($server_settings->ilias_url ?? ''));
68 $settings->setSubDirectory((string) ($server_settings->sub_directory ?? ''));
69 }
70
71 if ($client_settings instanceof stdClass) {
72 $settings->setInstance((string) ($client_settings->name ?? ''));
73 $settings->setAuthKey((string) ($client_settings->auth->key ?? ''));
74 $settings->setAuthSecret((string) ($client_settings->auth->secret ?? ''));
75 }
76
77 return $settings;
78 }
79
87 public function getURL(string $action, $scope = null): string
88 {
89 $url = $this->generateIliasUrl() . self::PREFIX . '/' . $action . '/' . $this->getInstance();
90
91 if ($scope !== null) {
92 $url .= '/' . $scope;
93 }
94
95 return $url;
96 }
97
98 public function generateIliasUrl(): string
99 {
100 if ($this->getIliasUrlEnabled()) {
101 $url = $this->getIliasUrl();
102
103 if (strpos($url, '://') === false) {
104 $url = $this->getProtocol() . $url;
105 }
106
107 return $url;
108 }
109
110 return $this->getBaseURL();
111 }
112
113 public function getIliasUrlEnabled(): bool
114 {
116 }
117
118 public function setIliasUrlEnabled(bool $iliasUrlEnabled): void
119 {
120 $this->iliasUrlEnabled = $iliasUrlEnabled;
121 }
122
123 public function getProtocol(): string
124 {
125 return $this->protocol;
126 }
127
128 public function setProtocol(string $protocol): void
129 {
130 if (strpos($protocol, '://') === false) {
131 $this->protocol = $protocol . '://';
132 }
133 }
134
135 public function getIliasUrl(): string
136 {
137 return $this->iliasUrl;
138 }
139
140 public function setIliasUrl(string $iliasUrl): void
141 {
142 $this->iliasUrl = $iliasUrl;
143 }
144
150 public function getBaseURL(): string
151 {
152 return $this->getProtocol() . $this->getDomain() . ':' . $this->getPort();
153 }
154
155 public function getDomain(): string
156 {
157 return $this->domain;
158 }
159
160 public function setDomain(string $domain): void
161 {
162 $this->domain = $domain;
163 }
164
165 public function getPort(): int
166 {
167 return $this->port;
168 }
169
170 public function setPort(int $port): void
171 {
172 $this->port = $port;
173 }
174
175 public function getInstance(): string
176 {
177 return $this->instance;
178 }
179
180 public function setInstance(string $instance): void
181 {
182 $this->instance = $instance;
183 }
184
185 public function generateClientUrl(): string
186 {
187 if ($this->getClientUrlEnabled()) {
188 $url = $this->getClientUrl();
189
190 if (strpos($url, '://') === false) {
191 $url = $this->getProtocol() . $url;
192 }
193
194 return $url;
195 }
196 return $this->getBaseURL();
197 }
198
199 public function getClientUrlEnabled(): bool
200 {
202 }
203
204 public function setClientUrlEnabled(bool $clientUrlEnabled): void
205 {
206 $this->clientUrlEnabled = $clientUrlEnabled;
207 }
208
209 public function getClientUrl(): string
210 {
211 return $this->clientUrl;
212 }
213
214 public function setClientUrl(string $clientUrl): void
215 {
216 $this->clientUrl = $clientUrl;
217 }
218
219 public function getSmiliesEnabled(): bool
220 {
222 }
223
224 public function setSmiliesEnabled(bool $a_bool): void
225 {
226 $this->smilies_enabled = $a_bool;
227 }
228
229 public function getAuthKey(): string
230 {
231 return $this->authKey;
232 }
233
234 public function setAuthKey(string $authKey): void
235 {
236 $this->authKey = $authKey;
237 }
238
239 public function getAuthSecret(): string
240 {
241 return $this->authSecret;
242 }
243
244 public function setAuthSecret(string $authSecret): void
245 {
246 $this->authSecret = $authSecret;
247 }
248
249 public function getSubDirectory(): string
250 {
251 return $this->subDirectory;
252 }
253
254 public function setSubDirectory(string $subDirectory): void
255 {
256 $this->subDirectory = $subDirectory;
257 }
258}
Class ilChatroomServerSettings.
setClientUrlEnabled(bool $clientUrlEnabled)
getBaseURL()
Creates base URL by calling $this->getProtocol(), $this->getDomain() and $this->getPort() and returne...
getURL(string $action, $scope=null)
Creates URL by calling $this->getBaseURL and using given $action and $scope and returns it.
global $DIC
Definition: feed.php:28
$scope
Definition: ltiregstart.php:53
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
$query
$url