19 declare(strict_types=1);
49 $DIC->database()->setLimit(1);
50 $query =
'SELECT * FROM ' . self::$settingsTable;
52 $rset = $DIC->database()->query(
$query);
53 if ($row = $DIC->database()->fetchObject($rset)) {
54 return new self((
int) $row->instance_id, $row);
57 throw new LogicException(
'Could not determine any default configuration');
78 $res = $DIC->database()->queryF(
79 "SELECT* FROM chatroom_admconfig WHERE instance_id = %s",
84 $row = $DIC->database()->fetchAssoc(
$res);
86 $DIC->database()->manipulateF(
87 "DELETE FROM chatroom_admconfig WHERE instance_id = %s",
95 if ($row[
'default_config'] !== null) {
96 $def_conf = $row[
'default_config'];
99 if ($row[
'client_settings'] !== null) {
100 $clnt_set = $row[
'client_settings'];
104 $DIC->database()->manipulateF(
106 INSERT INTO chatroom_admconfig 107 (instance_id, server_settings, default_config, client_settings) 108 VALUES (%s, %s, %s, %s)",
109 [
'integer',
'text',
'integer',
'text'],
110 [$this->config_id, json_encode($settings, JSON_THROW_ON_ERROR), $def_conf, $clnt_set]
122 $res = $DIC->database()->queryF(
123 "SELECT * FROM chatroom_admconfig WHERE instance_id = %s",
128 $row = $DIC->database()->fetchAssoc(
$res);
130 $DIC->database()->manipulateF(
131 "DELETE FROM chatroom_admconfig WHERE instance_id = %s",
136 ($row[
'default_config'] ?? null) !== null ? $def_conf = $row[
'default_config'] : $def_conf =
"{}";
137 ($row[
'server_settings'] ?? null) !== null ? $srv_set = $row[
'server_settings'] : $srv_set =
"{}";
139 $DIC->database()->manipulateF(
141 INSERT INTO chatroom_admconfig 142 (instance_id, server_settings, default_config, client_settings) 143 VALUES (%s, %s, %s, %s)",
154 json_encode($settings, JSON_THROW_ON_ERROR)
163 $query =
'SELECT * FROM ' . self::$settingsTable .
164 ' WHERE instance_id = ' . $DIC->database()->quote($this->config_id,
'integer');
166 if (($row = $DIC->database()->fetchAssoc($DIC->database()->query(
$query))) && $row[
'server_settings']) {
167 $settings = json_decode($row[
'server_settings'],
true, 512, JSON_THROW_ON_ERROR);
169 if (!isset($settings[
'protocol'])) {
170 $settings[
'protocol'] =
'http';
173 if (!isset($settings[
'log_level'])) {
174 $settings[
'log_level'] =
'info';
187 $query =
'SELECT * FROM ' . self::$settingsTable .
188 ' WHERE instance_id = ' . $DIC->database()->quote($this->config_id,
'integer');
189 if (($row = $DIC->database()->fetchAssoc($DIC->database()->query(
$query))) && $row[
'client_settings']) {
190 $settings = json_decode($row[
'client_settings'],
true, 512, JSON_THROW_ON_ERROR);
192 if (!isset($settings[
'client']) || !is_string($settings[
'client']) || $settings[
'client'] ===
'') {
196 if (isset($settings[
'name']) && is_string($settings[
'name']) && !$settings[
'name'] ===
'') {
197 $settings[
'client_name'] = (string) $settings[
'name'];
202 if (isset($settings[
'conversation_idle_state_in_minutes']) && is_numeric($settings[
'conversation_idle_state_in_minutes'])) {
203 $settings[
'conversation_idle_state_in_minutes'] = max(1, $settings[
'conversation_idle_state_in_minutes']);
205 $settings[
'conversation_idle_state_in_minutes'] = 1;
208 if (!isset($settings[
'auth']) || !is_array($settings[
'auth'])) {
209 $settings[
'auth'] = [];
211 if (!isset($settings[
'auth'][
'key']) || !is_string($settings[
'auth'][
'key'])) {
212 $settings[
'auth'][
'key'] =
'';
214 if (!isset($settings[
'auth'][
'secret']) || !is_string($settings[
'auth'][
'secret'])) {
215 $settings[
'auth'][
'secret'] =
'';
saveGeneralSettings(stdClass $settings)
Saves given $settings into settingsTable.
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable...
static string $settingsTable
__construct(int $config_id, stdClass $settings=null)
Class ilChatroomServerSettings.
saveClientSettings(stdClass $settings)
Saves given client $settings into settingsTable.
getServerSettings()
Instantiates ilChatroomServerSettings object, sets data using $this->settings->server_settings and re...