ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
50 global $ilDB;
51
52 $ilDB->setLimit(1);
53 $query = 'SELECT * FROM ' . self::$settingsTable;
54
55 $rset = $ilDB->query($query);
56 if($row = $ilDB->fetchObject($rset))
57 {
58 return new self((int)$row->instance_id, $row);
59 }
60 }
61
67 public function getServerSettings()
68 {
69 require_once 'Modules/Chatroom/classes/class.ilChatroomServerSettings.php';
70 return ilChatroomServerSettings::loadDefault();
71 }
72
77 public function saveGeneralSettings(stdClass $settings)
78 {
82 global $ilDB;
83
84 $res = $ilDB->queryF("
85 SELECT *
86 FROM chatroom_admconfig
87 WHERE instance_id = %s",
88 array('integer'),
89 array($this->config_id)
90 );
91
92 $row = $ilDB->fetchAssoc($res);
93
94 $ilDB->manipulateF("
95 DELETE
96 FROM chatroom_admconfig
97 WHERE instance_id = %s",
98 array('integer'),
99 array($this->config_id)
100 );
101
102 $row['default_config'] !== null ? $def_conf = $row['default_config'] : $def_conf = "{}";
103 $row['client_settings'] !== null ? $clnt_set = $row['client_settings'] : $clnt_set = "{}";
104
105 $ilDB->manipulateF("
106 INSERT INTO chatroom_admconfig
107 (instance_id, server_settings, default_config, client_settings)
108 VALUES (%s, %s, %s, %s)",
109 array('integer', 'text', 'integer', 'text'),
110 array($this->config_id, json_encode($settings), $def_conf, $clnt_set)
111 );
112 }
113
118 public function saveClientSettings(stdClass $settings)
119 {
123 global $ilDB;
124
125 $res = $ilDB->queryF("
126 SELECT *
127 FROM chatroom_admconfig
128 WHERE instance_id = %s",
129 array('integer'),
130 array($this->config_id)
131 );
132
133 $row = $ilDB->fetchAssoc($res);
134
135 $ilDB->manipulateF("
136 DELETE
137 FROM chatroom_admconfig
138 WHERE instance_id = %s",
139 array('integer'),
140 array($this->config_id)
141 );
142
143 $row['default_config'] !== null ? $def_conf = $row['default_config'] : $def_conf = "{}";
144 $row['server_settings'] !== null ? $srv_set = $row['server_settings'] : $srv_set = "{}";
145
146 $ilDB->manipulateF("
147 INSERT INTO chatroom_admconfig
148 (instance_id, server_settings, default_config, client_settings)
149 VALUES (%s, %s, %s, %s)",
150 array(
151 'integer',
152 'text',
153 'integer',
154 'text'
155 ),
156 array(
157 $this->config_id,
158 $srv_set,
159 $def_conf,
160 json_encode($settings)
161 )
162 );
163 }
164
169 public function loadGeneralSettings()
170 {
174 global $ilDB;
175
176 $query = 'SELECT * FROM ' . self::$settingsTable . ' WHERE instance_id = ' . $ilDB->quote($this->config_id, 'integer');
177
178 if(($row = $ilDB->fetchAssoc($ilDB->query($query))) && $row['server_settings'])
179 {
180 $settings = json_decode($row['server_settings'], true);
181
182 if(!$settings['protocol'])
183 {
184 $settings['protocol'] = 'http';
185 }
186
187 return $settings;
188 }
189
190 return array();
191 }
192
197 public function loadClientSettings()
198 {
202 global $ilDB;
203
204 $query = 'SELECT * FROM ' . self::$settingsTable . ' WHERE instance_id = ' . $ilDB->quote($this->config_id, 'integer');
205 if(($row = $ilDB->fetchAssoc($ilDB->query($query))) && $row['client_settings'])
206 {
207 $settings = json_decode($row['client_settings'], true);
208
209 if(!$settings['osd_intervall'])
210 {
211 $settings['osd_intervall'] = 60;
212 }
213
214 if(!$settings['client'])
215 {
216 $settings['client'] = CLIENT_ID;
217 }
218
219 $settings['client_name'] = (string)$settings['name'];
220 if (!$settings['client_name']) {
221 $settings['client_name'] = CLIENT_ID;
222 }
223
224 return $settings;
225 }
226
227 return array();
228 }
229}
An exception for terminatinating execution or to throw for unit testing.
Class ilChatroomAdmin.
getServerSettings()
Instantiates ilChatroomServerSettings object, sets data using $this->settings->server_settings and re...
__construct($config_id, stdClass $settings=null)
Constructor Sets $this->config_id and $this->settings using given $config_id and $settings.
settings()
Definition: settings.php:2
global $ilDB