ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilChatroomAdmin.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
15 private static $settingsTable = 'chatroom_admconfig';
16
20 private $settings;
21
25 private $config_id;
26
34 public function __construct($config_id, stdClass $settings = null)
35 {
36 $this->config_id = $config_id;
37 $this->settings = $settings;
38 }
39
45 public static function getDefaultConfiguration()
46 {
47 global $DIC;
48
49 $DIC->database()->setLimit(1);
50 $query = 'SELECT * FROM ' . self::$settingsTable;
51
52 $rset = $DIC->database()->query($query);
53 if ($row = $DIC->database()->fetchObject($rset)) {
54 return new self((int) $row->instance_id, $row);
55 }
56 }
57
63 public function getServerSettings()
64 {
65 require_once 'Modules/Chatroom/classes/class.ilChatroomServerSettings.php';
67 }
68
73 public function saveGeneralSettings(stdClass $settings)
74 {
75 global $DIC;
76
77 $res = $DIC->database()->queryF(
78 "
79 SELECT *
80 FROM chatroom_admconfig
81 WHERE instance_id = %s",
82 array('integer'),
83 array($this->config_id)
84 );
85
86 $row = $DIC->database()->fetchAssoc($res);
87
88 $DIC->database()->manipulateF(
89 "
90 DELETE
91 FROM chatroom_admconfig
92 WHERE instance_id = %s",
93 array('integer'),
94 array($this->config_id)
95 );
96
97 $row['default_config'] !== null ? $def_conf = $row['default_config'] : $def_conf = "{}";
98 $row['client_settings'] !== null ? $clnt_set = $row['client_settings'] : $clnt_set = "{}";
99
100 $DIC->database()->manipulateF(
101 "
102 INSERT INTO chatroom_admconfig
103 (instance_id, server_settings, default_config, client_settings)
104 VALUES (%s, %s, %s, %s)",
105 array('integer', 'text', 'integer', 'text'),
106 array($this->config_id, json_encode($settings), $def_conf, $clnt_set)
107 );
108 }
109
114 public function saveClientSettings(stdClass $settings)
115 {
116 global $DIC;
117
118 $res = $DIC->database()->queryF(
119 "
120 SELECT *
121 FROM chatroom_admconfig
122 WHERE instance_id = %s",
123 array('integer'),
124 array($this->config_id)
125 );
126
127 $row = $DIC->database()->fetchAssoc($res);
128
129 $DIC->database()->manipulateF(
130 "
131 DELETE
132 FROM chatroom_admconfig
133 WHERE instance_id = %s",
134 array('integer'),
135 array($this->config_id)
136 );
137
138 $row['default_config'] !== null ? $def_conf = $row['default_config'] : $def_conf = "{}";
139 $row['server_settings'] !== null ? $srv_set = $row['server_settings'] : $srv_set = "{}";
140
141 $DIC->database()->manipulateF(
142 "
143 INSERT INTO chatroom_admconfig
144 (instance_id, server_settings, default_config, client_settings)
145 VALUES (%s, %s, %s, %s)",
146 array(
147 'integer',
148 'text',
149 'integer',
150 'text'
151 ),
152 array(
153 $this->config_id,
154 $srv_set,
155 $def_conf,
156 json_encode($settings)
157 )
158 );
159 }
160
165 public function loadGeneralSettings()
166 {
167 global $DIC;
168
169 $query = 'SELECT * FROM ' . self::$settingsTable . ' WHERE instance_id = ' . $DIC->database()->quote($this->config_id, 'integer');
170
171 if (($row = $DIC->database()->fetchAssoc($DIC->database()->query($query))) && $row['server_settings']) {
172 $settings = json_decode($row['server_settings'], true);
173
174 if (!$settings['protocol']) {
175 $settings['protocol'] = 'http';
176 }
177
178 return $settings;
179 }
180
181 return array();
182 }
183
188 public function loadClientSettings()
189 {
190 global $DIC;
191
192 $query = 'SELECT * FROM ' . self::$settingsTable . ' WHERE instance_id = ' . $DIC->database()->quote($this->config_id, 'integer');
193 if (($row = $DIC->database()->fetchAssoc($DIC->database()->query($query))) && $row['client_settings']) {
194 $settings = json_decode($row['client_settings'], true);
195
196 if (!$settings['osd_intervall']) {
197 $settings['osd_intervall'] = 60;
198 }
199
200 if (!$settings['client']) {
201 $settings['client'] = CLIENT_ID;
202 }
203
204 $settings['client_name'] = (string) $settings['name'];
205 if (!$settings['client_name']) {
206 $settings['client_name'] = CLIENT_ID;
207 }
208
209 return $settings;
210 }
211
212 return array();
213 }
214}
An exception for terminatinating execution or to throw for unit testing.
Class ilChatroomAdmin.
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable.
saveClientSettings(stdClass $settings)
Saves given client $settings into settingsTable.
getServerSettings()
Instantiates ilChatroomServerSettings object, sets data using $this->settings->server_settings and re...
saveGeneralSettings(stdClass $settings)
Saves given $settings into settingsTable.
__construct($config_id, stdClass $settings=null)
Constructor Sets $this->config_id and $this->settings using given $config_id and $settings.
loadGeneralSettings()
Returns an array containing server settings from settingsTable.
loadClientSettings()
Returns an array containing client settings from settingsTable.
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
settings()
Definition: settings.php:2