ILIAS  Release_4_2_x_branch Revision 61807
 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 
4 
14 {
15 
16  private static $settingsTable = 'chatroom_admconfig';
17  private $settings;
18  private $config_id;
19 
29  public function __construct($config_id, stdClass $settings = null)
30  {
31  $this->config_id = $config_id;
32  $this->settings = $settings;
33  }
34 
42  public static function getDefaultConfiguration()
43  {
44  global $ilDB;
45 
46  $ilDB->setLimit( 1 );
47  $query = 'SELECT * FROM ' . self::$settingsTable; // . ' WHERE default_config = 1';
48 
49  $rset = $ilDB->query( $query );
50 
51  if( $row = $ilDB->fetchObject( $rset ) )
52  {
53  $obj = new ilChatroomAdmin( $row->instance_id, $row );
54  return $obj;
55  }
56  }
57 
64  public function getServerSettings()
65  {
66  require_once 'Modules/Chatroom/classes/class.ilChatroomServerSettings.php';
68  /*$data = json_decode( $this->settings->server_settings );
69 
70  $settings = new ilChatroomServerSettings();
71 
72  $settings->setDomain( $data->address );
73  $settings->setPort( $data->port );
74  $settings->setProtocol( $data->protocol );
75  $settings->setInstance( $data->instance );
76 
77  return $settings;*/
78  }
79 
86  public function saveGeneralSettings(stdClass $settings)
87  {
88  global $ilDB;
89 
90  $res = $ilDB->queryF("
91  SELECT *
92  FROM chatroom_admconfig
93  WHERE instance_id = %s",
94 
95  array('integer'),
96  array($this->config_id)
97  );
98 
99  $row = $ilDB->fetchAssoc($res);
100 
101  $ilDB->manipulateF("
102  DELETE
103  FROM chatroom_admconfig
104  WHERE instance_id = %s",
105 
106  array('integer'),
107  array($this->config_id)
108  );
109 
110  $row['default_config'] !== null ? $def_conf = $row['default_config'] : $def_conf = "{}";
111  $row['client_settings'] !== null ? $clnt_set = $row['client_settings'] : $clnt_set = "{}";
112 
113  $ilDB->manipulateF("
114  INSERT INTO chatroom_admconfig
115  (instance_id, server_settings, default_config, client_settings)
116  VALUES (%s, %s, %s, %s)",
117 
118  array('integer', 'text', 'integer', 'text'),
119  array($this->config_id, json_encode( $settings ), $def_conf, $clnt_set)
120  );
121  }
122 
123 
130  public function saveClientSettings(stdClass $settings)
131  {
132  global $ilDB;
133 
134  $res = $ilDB->queryF("
135  SELECT *
136  FROM chatroom_admconfig
137  WHERE instance_id = %s",
138 
139  array('integer'),
140  array($this->config_id)
141  );
142 
143  $row = $ilDB->fetchAssoc($res);
144 
145  $ilDB->manipulateF("
146  DELETE
147  FROM chatroom_admconfig
148  WHERE instance_id = %s",
149 
150  array('integer'),
151  array($this->config_id)
152  );
153 
154  $row['default_config'] !== null ? $def_conf = $row['default_config'] : $def_conf = "{}";
155  $row['server_settings'] !== null ? $srv_set = $row['server_settings'] : $srv_set = "{}";
156 
157  $ilDB->manipulateF("
158  INSERT INTO chatroom_admconfig
159  (instance_id, server_settings, default_config, client_settings)
160  VALUES (%s, %s, %s, %s)",
161 
162  array('integer', 'text', 'integer', 'text'),
163  array($this->config_id, $srv_set, $def_conf, json_encode( $settings ))
164  );
165  }
166 
173  public function loadGeneralSettings()
174  {
175  global $ilDB;
176 
177  $query = 'SELECT * FROM ' . self::$settingsTable . ' WHERE instance_id = ' .
178  $ilDB->quote( $this->config_id, 'integer' );
179 
180  if( ($row = $ilDB->fetchAssoc( $ilDB->query( $query ) )) && $row['server_settings'] )
181  {
182  return json_decode( $row['server_settings'] );
183  }
184 
185  return null;
186  }
187 
194  public function loadClientSettings()
195  {
196  global $ilDB;
197 
198  $query = 'SELECT * FROM ' . self::$settingsTable . ' WHERE instance_id = ' .
199  $ilDB->quote( $this->config_id, 'integer' );
200 
201  if( ($row = $ilDB->fetchAssoc( $ilDB->query( $query ) )) && $row['client_settings'] )
202  {
203  return json_decode( $row['client_settings'] );
204  }
205 
206  return null;
207  }
208 
209 }
210 
211 ?>