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