ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilECSParticipantSetting.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 {
34  const AUTH_VERSION_4 = 1;
35  const AUTH_VERSION_5 = 2;
36 
37  const PERSON_EPPN = 1;
38  const PERSON_LUID = 2;
39  const PERSON_LOGIN = 3;
40  const PERSON_UID = 4;
41 
42  protected static $instances = array();
43 
44 
45  // :TODO: what types are needed?
46  const IMPORT_UNCHANGED = 0;
47  const IMPORT_RCRS = 1;
48  const IMPORT_CRS = 2;
49  const IMPORT_CMS = 3;
50 
51  private $server_id = 0;
52  private $mid = 0;
53  private $export = false;
54  private $import = false;
55  private $import_type = 1;
56  private $title = '';
57  private $cname = '';
58  private $token = true;
59  private $dtoken = true;
60 
63 
64 
65  private $export_types = array();
66  private $import_types = array();
67 
68  private $exists = false;
69 
70 
77  public function __construct($a_server_id,$mid)
78  {
79  $this->server_id = $a_server_id;
80  $this->mid = $mid;
81  $this->read();
82  }
83 
90  public static function getInstance($a_server_id,$mid)
91  {
92  if(self::$instances[$a_server_id.'_'.$mid])
93  {
94  return self::$instances[$a_server_id.'_'.$mid];
95  }
96  return self::$instances[$a_server_id.'_'.$mid] = new self($a_server_id,$mid);
97  }
98 
99 
104  public function getServerId()
105  {
106  return $this->server_id;
107  }
108 
109  public function setMid($a_mid)
110  {
111  $this->mid = $a_mid;
112  }
113 
114  public function getMid()
115  {
116  return $this->mid;
117  }
118 
119  public function enableExport($a_status)
120  {
121  $this->export = $a_status;
122  }
123 
124  public function isExportEnabled()
125  {
126  return (bool) $this->export;
127  }
128 
129  public function enableImport($a_status)
130  {
131  $this->import = $a_status;
132  }
133 
134  public function isImportEnabled()
135  {
136  return $this->import;
137  }
138 
139  public function setImportType($a_type)
140  {
141  if($a_type != self::IMPORT_UNCHANGED)
142  {
143  $this->import_type = $a_type;
144  }
145  }
146 
147  public function getImportType()
148  {
149  return $this->import_type;
150  }
151 
152  public function setTitle($a_title)
153  {
154  $this->title = $a_title;
155  }
156 
157  public function getTitle()
158  {
159  return $this->title;
160  }
161 
162  public function getCommunityName()
163  {
164  return $this->cname;
165  }
166 
167  public function setCommunityName($a_name)
168  {
169  $this->cname = $a_name;
170  }
171 
172  public function isTokenEnabled()
173  {
174  return (bool) $this->token;
175  }
176 
177  public function enableToken($a_stat)
178  {
179  $this->token = $a_stat;
180  }
181 
182  public function setExportTypes($a_types)
183  {
184  $this->export_types = $a_types;
185  }
186 
187  public function getExportTypes()
188  {
189  return $this->export_types;
190  }
191 
192  public function setImportTypes($a_types)
193  {
194  $this->import_types = $a_types;
195  }
196 
197  public function isDeprecatedTokenEnabled()
198  {
199  return (bool) $this->dtoken;
200  }
201 
202  public function enableDeprecatedToken($a_stat)
203  {
204  $this->dtoken = $a_stat;
205  }
206 
207  public function getImportTypes()
208  {
209  return $this->import_types;
210  }
211 
212  private function exists()
213  {
214  return $this->exists;
215  }
216 
221  public function update()
222  {
223  global $ilDB;
224 
225  if(!$this->exists())
226  {
227  return $this->create();
228  }
229  $query = 'UPDATE ecs_part_settings '.
230  'SET '.
231  'sid = '.$ilDB->quote((int) $this->getServerId(),'integer').', '.
232  'mid = '.$ilDB->quote((int) $this->getMid(),'integer').', '.
233  'export = '.$ilDB->quote((int) $this->isExportEnabled(),'integer').', '.
234  'import = '.$ilDB->quote((int) $this->isImportEnabled(),'integer').', '.
235  'import_type = '.$ilDB->quote((int) $this->getImportType(),'integer').', '.
236  'title = '.$ilDB->quote($this->getTitle(),'text').', '.
237  'cname = '.$ilDB->quote($this->getCommunityName(),'text').', '.
238  'token = '.$ilDB->quote($this->isTokenEnabled(),'integer').', '.
239  'dtoken = '.$ilDB->quote($this->isDeprecatedTokenEnabled(),'integer').', '.
240  'export_types = '.$ilDB->quote(serialize($this->getExportTypes()),'text').', '.
241  'import_types = '.$ilDB->quote(serialize($this->getImportTypes()),'text').' '.
242  'WHERE sid = '.$ilDB->quote((int) $this->getServerId(),'integer').' '.
243  'AND mid = '.$ilDB->quote((int) $this->getMid(),'integer');
244  $aff = $ilDB->manipulate($query);
245  return true;
246  }
247 
248  private function create()
249  {
250  global $ilDB;
251 
252  $query = 'INSERT INTO ecs_part_settings '.
253  '(sid,mid,export,import,import_type,title,cname,token,dtoken,export_types, import_types) '.
254  'VALUES( '.
255  $ilDB->quote($this->getServerId(),'integer').', '.
256  $ilDB->quote($this->getMid(),'integer').', '.
257  $ilDB->quote((int) $this->isExportEnabled(),'integer').', '.
258  $ilDB->quote((int) $this->isImportEnabled(),'integer').', '.
259  $ilDB->quote((int) $this->getImportType(),'integer').', '.
260  $ilDB->quote($this->getTitle(),'text').', '.
261  $ilDB->quote($this->getCommunityName(),'text').', '.
262  $ilDB->quote($this->isTokenEnabled(),'integer').', '.
263  $ilDB->quote($this->isDeprecatedTokenEnabled(),'integer').', '.
264  $ilDB->quote(serialize($this->getExportTypes()),'text').', '.
265  $ilDB->quote(serialize($this->getImportTypes()),'text').' '.
266  ')';
267  $aff = $ilDB->manipulate($query);
268  return true;
269 
270  }
271 
277  public function delete()
278  {
279  global $ilDB;
280 
281  $query = 'DELETE FROM ecs_part_settings '.
282  'WHERE sid = '.$ilDB->quote($this->getServerId(),'integer').' '.
283  'AND mid = '.$ilDB->quote($this->getMid(),'integer');
284  $ilDB->manipulate($query);
285  return true;
286  }
287 
292  public function read()
293  {
294  global $ilDB;
295 
296  $query = 'SELECT * FROM ecs_part_settings '.
297  'WHERE sid = '.$ilDB->quote($this->getServerId(),'integer').' '.
298  'AND mid = '.$ilDB->quote($this->getMid(),'integer');
299 
300  $res = $ilDB->query($query);
301 
302  $this->exists = ($res->numRows() ? true : false);
303 
304  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
305  {
306  $this->enableExport($row->export);
307  $this->enableImport($row->import);
308  $this->setImportType($row->import_type);
309  $this->setTitle($row->title);
310  $this->setCommunityName($row->cname);
311  $this->enableToken($row->token);
312  $this->enableDeprecatedToken($row->dtoken);
313 
314  $this->setExportTypes((array) unserialize($row->export_types));
315  $this->setImportTypes((array) unserialize($row->import_types));
316  }
317  return true;
318  }
319 
320  public static function deleteByServerId($a_server_id)
321  {
322  global $ilDB;
323 
324  $query = 'DELETE FROM ecs_events'.
325  ' WHERE server_id = '.$ilDB->quote($a_server_id,'integer');
326  $ilDB->manipulate($query);
327  return true;
328  }
329 }
330 ?>