ILIAS  Release_4_4_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  protected static $instances = array();
35 
36 
37  // :TODO: what types are needed?
38  const IMPORT_UNCHANGED = 0;
39  const IMPORT_RCRS = 1;
40  const IMPORT_CRS = 2;
41  const IMPORT_CMS = 3;
42 
43  private $server_id = 0;
44  private $mid = 0;
45  private $export = false;
46  private $import = false;
47  private $import_type = 1;
48  private $title = '';
49  private $cname = '';
50 
51 
52  private $exists = false;
53 
54 
61  public function __construct($a_server_id,$mid)
62  {
63  $this->server_id = $a_server_id;
64  $this->mid = $mid;
65  $this->read();
66  }
67 
74  public static function getInstance($a_server_id,$mid)
75  {
76  if(self::$instances[$a_server_id.'_'.$mid])
77  {
78  return self::$instances[$a_server_id.'_'.$mid];
79  }
80  return self::$instances[$a_server_id.'_'.$mid] = new self($a_server_id,$mid);
81  }
82 
83 
88  public function getServerId()
89  {
90  return $this->server_id;
91  }
92 
93  public function setMid($a_mid)
94  {
95  $this->mid = $a_mid;
96  }
97 
98  public function getMid()
99  {
100  return $this->mid;
101  }
102 
103  public function enableExport($a_status)
104  {
105  $this->export = $a_status;
106  }
107 
108  public function isExportEnabled()
109  {
110  return (bool) $this->export;
111  }
112 
113  public function enableImport($a_status)
114  {
115  $this->import = $a_status;
116  }
117 
118  public function isImportEnabled()
119  {
120  return $this->import;
121  }
122 
123  public function setImportType($a_type)
124  {
125  if($a_type != self::IMPORT_UNCHANGED)
126  {
127  $this->import_type = $a_type;
128  }
129  }
130 
131  public function getImportType()
132  {
133  return $this->import_type;
134  }
135 
136  public function setTitle($a_title)
137  {
138  $this->title = $a_title;
139  }
140 
141  public function getTitle()
142  {
143  return $this->title;
144  }
145 
146  public function getCommunityName()
147  {
148  return $this->cname;
149  }
150 
151  public function setCommunityName($a_name)
152  {
153  $this->cname = $a_name;
154  }
155 
156  private function exists()
157  {
158  return $this->exists;
159  }
160 
165  public function update()
166  {
167  global $ilDB;
168 
169  if(!$this->exists())
170  {
171  return $this->create();
172  }
173  $query = 'UPDATE ecs_part_settings '.
174  'SET '.
175  'sid = '.$ilDB->quote((int) $this->getServerId(),'integer').', '.
176  'mid = '.$ilDB->quote((int) $this->getMid(),'integer').', '.
177  'export = '.$ilDB->quote((int) $this->isExportEnabled(),'integer').', '.
178  'import = '.$ilDB->quote((int) $this->isImportEnabled(),'integer').', '.
179  'import_type = '.$ilDB->quote((int) $this->getImportType(),'integer').', '.
180  'title = '.$ilDB->quote($this->getTitle(),'text').', '.
181  'cname = '.$ilDB->quote($this->getCommunityName(),'text').' '.
182  'WHERE sid = '.$ilDB->quote((int) $this->getServerId(),'integer').' '.
183  'AND mid = '.$ilDB->quote((int) $this->getMid(),'integer');
184  $aff = $ilDB->manipulate($query);
185  return true;
186  }
187 
188  private function create()
189  {
190  global $ilDB;
191 
192  $query = 'INSERT INTO ecs_part_settings '.
193  '(sid,mid,export,import,import_type,title,cname) '.
194  'VALUES( '.
195  $ilDB->quote($this->getServerId(),'integer').', '.
196  $ilDB->quote($this->getMid(),'integer').', '.
197  $ilDB->quote((int) $this->isExportEnabled(),'integer').', '.
198  $ilDB->quote((int) $this->isImportEnabled(),'integer').', '.
199  $ilDB->quote((int) $this->getImportType(),'integer').', '.
200  $ilDB->quote($this->getTitle(),'text').', '.
201  $ilDB->quote($this->getCommunityName(),'text').' '.
202  ')';
203  $aff = $ilDB->manipulate($query);
204  return true;
205 
206  }
207 
213  public function delete()
214  {
215  global $ilDB;
216 
217  $query = 'DELETE FROM ecs_part_settings '.
218  'WHERE sid = '.$ilDB->quote($this->getServerId(),'integer').' '.
219  'AND mid = '.$ilDB->quote($this->getMid(),'integer');
220  $ilDB->manipulate($query);
221  return true;
222  }
223 
228  public function read()
229  {
230  global $ilDB;
231 
232  $query = 'SELECT * FROM ecs_part_settings '.
233  'WHERE sid = '.$ilDB->quote($this->getServerId(),'integer').' '.
234  'AND mid = '.$ilDB->quote($this->getMid(),'integer');
235 
236  $res = $ilDB->query($query);
237 
238  $this->exists = ($res->numRows() ? true : false);
239 
240  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
241  {
242  $this->enableExport($row->export);
243  $this->enableImport($row->import);
244  $this->setImportType($row->import_type);
245  $this->setTitle($row->title);
246  $this->setCommunityName($row->cname);
247  }
248  return true;
249  }
250 
251  public static function deleteByServerId($a_server_id)
252  {
253  global $ilDB;
254 
255  $query = 'DELETE FROM ecs_events'.
256  ' WHERE server_id = '.$ilDB->quote($a_server_id,'integer');
257  $ilDB->manipulate($query);
258  return true;
259  }
260 }
261 ?>