ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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';
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  return json_decode($row['server_settings']);
181  }
182 
183  return null;
184  }
185 
190  public function loadClientSettings()
191  {
195  global $ilDB;
196 
197  $query = 'SELECT * FROM ' . self::$settingsTable . ' WHERE instance_id = ' . $ilDB->quote($this->config_id, 'integer');
198  if(($row = $ilDB->fetchAssoc($ilDB->query($query))) && $row['client_settings'])
199  {
200  return json_decode($row['client_settings']);
201  }
202 
203  return null;
204  }
205 }