ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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?
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 return self::$instances[$a_server_id . '_' . $mid];
94 }
95 return self::$instances[$a_server_id . '_' . $mid] = new self($a_server_id, $mid);
96 }
97
98
103 public function getServerId()
104 {
105 return $this->server_id;
106 }
107
108 public function setMid($a_mid)
109 {
110 $this->mid = $a_mid;
111 }
112
113 public function getMid()
114 {
115 return $this->mid;
116 }
117
118 public function enableExport($a_status)
119 {
120 $this->export = $a_status;
121 }
122
123 public function isExportEnabled()
124 {
125 return (bool) $this->export;
126 }
127
128 public function enableImport($a_status)
129 {
130 $this->import = $a_status;
131 }
132
133 public function isImportEnabled()
134 {
135 return $this->import;
136 }
137
138 public function setImportType($a_type)
139 {
140 if ($a_type != self::IMPORT_UNCHANGED) {
141 $this->import_type = $a_type;
142 }
143 }
144
145 public function getImportType()
146 {
147 return $this->import_type;
148 }
149
150 public function setTitle($a_title)
151 {
152 $this->title = $a_title;
153 }
154
155 public function getTitle()
156 {
157 return $this->title;
158 }
159
160 public function getCommunityName()
161 {
162 return $this->cname;
163 }
164
165 public function setCommunityName($a_name)
166 {
167 $this->cname = $a_name;
168 }
169
170 public function isTokenEnabled()
171 {
172 return (bool) $this->token;
173 }
174
175 public function enableToken($a_stat)
176 {
177 $this->token = $a_stat;
178 }
179
180 public function setExportTypes($a_types)
181 {
182 $this->export_types = $a_types;
183 }
184
185 public function getExportTypes()
186 {
187 return $this->export_types;
188 }
189
190 public function setImportTypes($a_types)
191 {
192 $this->import_types = $a_types;
193 }
194
195 public function isDeprecatedTokenEnabled()
196 {
197 return (bool) $this->dtoken;
198 }
199
200 public function enableDeprecatedToken($a_stat)
201 {
202 $this->dtoken = $a_stat;
203 }
204
205 public function getImportTypes()
206 {
207 return $this->import_types;
208 }
209
210 private function exists()
211 {
212 return $this->exists;
213 }
214
219 public function update()
220 {
221 global $ilDB;
222
223 if (!$this->exists()) {
224 return $this->create();
225 }
226 $query = 'UPDATE ecs_part_settings ' .
227 'SET ' .
228 'sid = ' . $ilDB->quote((int) $this->getServerId(), 'integer') . ', ' .
229 'mid = ' . $ilDB->quote((int) $this->getMid(), 'integer') . ', ' .
230 'export = ' . $ilDB->quote((int) $this->isExportEnabled(), 'integer') . ', ' .
231 'import = ' . $ilDB->quote((int) $this->isImportEnabled(), 'integer') . ', ' .
232 'import_type = ' . $ilDB->quote((int) $this->getImportType(), 'integer') . ', ' .
233 'title = ' . $ilDB->quote($this->getTitle(), 'text') . ', ' .
234 'cname = ' . $ilDB->quote($this->getCommunityName(), 'text') . ', ' .
235 'token = ' . $ilDB->quote($this->isTokenEnabled(), 'integer') . ', ' .
236 'dtoken = ' . $ilDB->quote($this->isDeprecatedTokenEnabled(), 'integer') . ', ' .
237 'export_types = ' . $ilDB->quote(serialize($this->getExportTypes()), 'text') . ', ' .
238 'import_types = ' . $ilDB->quote(serialize($this->getImportTypes()), 'text') . ' ' .
239 'WHERE sid = ' . $ilDB->quote((int) $this->getServerId(), 'integer') . ' ' .
240 'AND mid = ' . $ilDB->quote((int) $this->getMid(), 'integer');
241 $aff = $ilDB->manipulate($query);
242 return true;
243 }
244
245 private function create()
246 {
247 global $ilDB;
248
249 $query = 'INSERT INTO ecs_part_settings ' .
250 '(sid,mid,export,import,import_type,title,cname,token,dtoken,export_types, import_types) ' .
251 'VALUES( ' .
252 $ilDB->quote($this->getServerId(), 'integer') . ', ' .
253 $ilDB->quote($this->getMid(), 'integer') . ', ' .
254 $ilDB->quote((int) $this->isExportEnabled(), 'integer') . ', ' .
255 $ilDB->quote((int) $this->isImportEnabled(), 'integer') . ', ' .
256 $ilDB->quote((int) $this->getImportType(), 'integer') . ', ' .
257 $ilDB->quote($this->getTitle(), 'text') . ', ' .
258 $ilDB->quote($this->getCommunityName(), 'text') . ', ' .
259 $ilDB->quote($this->isTokenEnabled(), 'integer') . ', ' .
260 $ilDB->quote($this->isDeprecatedTokenEnabled(), 'integer') . ', ' .
261 $ilDB->quote(serialize($this->getExportTypes()), 'text') . ', ' .
262 $ilDB->quote(serialize($this->getImportTypes()), 'text') . ' ' .
263 ')';
264 $aff = $ilDB->manipulate($query);
265 return true;
266 }
267
273 public function delete()
274 {
275 global $ilDB;
276
277 $query = 'DELETE FROM ecs_part_settings ' .
278 'WHERE sid = ' . $ilDB->quote($this->getServerId(), 'integer') . ' ' .
279 'AND mid = ' . $ilDB->quote($this->getMid(), 'integer');
280 $ilDB->manipulate($query);
281 return true;
282 }
283
288 public function read()
289 {
290 global $ilDB;
291
292 $query = 'SELECT * FROM ecs_part_settings ' .
293 'WHERE sid = ' . $ilDB->quote($this->getServerId(), 'integer') . ' ' .
294 'AND mid = ' . $ilDB->quote($this->getMid(), 'integer');
295
296 $res = $ilDB->query($query);
297
298 $this->exists = ($res->numRows() ? true : false);
299
300 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
301 $this->enableExport($row->export);
302 $this->enableImport($row->import);
303 $this->setImportType($row->import_type);
304 $this->setTitle($row->title);
305 $this->setCommunityName($row->cname);
306 $this->enableToken($row->token);
307 $this->enableDeprecatedToken($row->dtoken);
308
309 $this->setExportTypes((array) unserialize($row->export_types));
310 $this->setImportTypes((array) unserialize($row->import_types));
311 }
312 return true;
313 }
314
315 public static function deleteByServerId($a_server_id)
316 {
317 global $ilDB;
318
319 $query = 'DELETE FROM ecs_events' .
320 ' WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
321 $ilDB->manipulate($query);
322 return true;
323 }
324}
An exception for terminatinating execution or to throw for unit testing.
update()
Update Calls create automatically when no entry exists.
static getInstance($a_server_id, $mid)
Get instance by server id and mid.
__construct($a_server_id, $mid)
Constructor.
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$a_type
Definition: workflow.php:92