ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
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 
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  if (!$settings['log_level']) {
179  $settings['log_level'] = 'info';
180  }
181 
182  return $settings;
183  }
184 
185  return array();
186  }
187 
192  public function loadClientSettings()
193  {
194  global $DIC;
195 
196  $query = 'SELECT * FROM ' . self::$settingsTable . ' WHERE instance_id = ' . $DIC->database()->quote($this->config_id, 'integer');
197  if (($row = $DIC->database()->fetchAssoc($DIC->database()->query($query))) && $row['client_settings']) {
198  $settings = json_decode($row['client_settings'], true);
199 
200  if (!$settings['osd_intervall']) {
201  $settings['osd_intervall'] = 60;
202  }
203 
204  if (!$settings['client']) {
205  $settings['client'] = CLIENT_ID;
206  }
207 
208  $settings['client_name'] = (string) $settings['name'];
209  if (!$settings['client_name']) {
210  $settings['client_name'] = CLIENT_ID;
211  }
212 
213  return $settings;
214  }
215 
216  return array();
217  }
218 }
settings()
Definition: settings.php:2
saveGeneralSettings(stdClass $settings)
Saves given $settings into settingsTable.
global $DIC
Definition: saml.php:7
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable...
foreach($_POST as $key=> $value) $res
Class ilChatroomAdmin.
loadGeneralSettings()
Returns an array containing server settings from settingsTable.
$query
loadClientSettings()
Returns an array containing client settings from settingsTable.
$row
__construct($config_id, stdClass $settings=null)
Constructor Sets $this->config_id and $this->settings using given $config_id and $settings.
saveClientSettings(stdClass $settings)
Saves given client $settings into settingsTable.
getServerSettings()
Instantiates ilChatroomServerSettings object, sets data using $this->settings->server_settings and re...