ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilECSExport.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
35{
36 protected $db = null;
37
38 protected $server_id = 0;
39 protected $obj_id = 0;
40 protected $econtent_id = 0;
41 protected $exported = false;
42
50 public function __construct($a_server_id, $a_obj_id)
51 {
52 global $DIC;
53
54 $ilDB = $DIC['ilDB'];
55
56 $this->server_id = $a_server_id;
57 $this->obj_id = $a_obj_id;
58
59 $this->db = $ilDB;
60 $this->read();
61 }
62
67 public function getServerId()
68 {
69 return $this->server_id;
70 }
71
76 public function setServerId($a_server_id)
77 {
78 $this->server_id = $a_server_id;
79 }
80
86 public static function _isExported($a_obj_id)
87 {
88 global $DIC;
89
90 $ilDB = $DIC['ilDB'];
91
92 $query = 'SELECT * FROM ecs_export ' .
93 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
94 $res = $ilDB->query($query);
95 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
96 return true;
97 }
98 return false;
99 }
100
101
109 public static function _getAllEContentIds($a_server_id)
110 {
111 global $DIC;
112
113 $ilDB = $DIC['ilDB'];
114
115 $query = "SELECT econtent_id,obj_id FROM ecs_export " .
116 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
117
118 $res = $ilDB->query($query);
119 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
120 $econtent_ids[$row->econtent_id] = $row->obj_id;
121 }
122 return $econtent_ids ? $econtent_ids : array();
123 }
124
130 public static function getExportedIds()
131 {
132 global $DIC;
133
134 $ilDB = $DIC['ilDB'];
135 $query = "SELECT obj_id FROM ecs_export ";
136 $res = $ilDB->query($query);
137 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
138 $obj_ids[] = $row->obj_id;
139 }
140 return $obj_ids ? $obj_ids : array();
141 }
142
148 public static function getExportedIdsByType($a_type)
149 {
150 global $DIC;
151
152 $ilDB = $DIC['ilDB'];
153 $query = "SELECT e.obj_id FROM ecs_export e" .
154 " JOIN object_data o ON (e.obj_id = o.obj_id)" .
155 " WHERE o.type = " . $ilDB->quote($a_type, "text");
156 $res = $ilDB->query($query);
157 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
158 $obj_ids[] = $row->obj_id;
159 }
160 return $obj_ids ? $obj_ids : array();
161 }
162
169 public static function getExportServerIds($a_obj_id)
170 {
171 global $DIC;
172
173 $ilDB = $DIC['ilDB'];
174
175 $query = 'SELECT * FROM ecs_export ' .
176 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
177 $res = $ilDB->query($query);
178
179 $sids = array();
180 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
181 $sids[] = $row->server_id;
182 }
183 return $sids;
184 }
185
193 public static function _getExportedIDsByServer($a_server_id)
194 {
195 global $DIC;
196
197 $ilDB = $DIC['ilDB'];
198 $query = "SELECT obj_id FROM ecs_export " .
199 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
200 $res = $ilDB->query($query);
201 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
202 $obj_ids[] = $row->obj_id;
203 }
204 return $obj_ids ? $obj_ids : array();
205 }
206
213 public static function lookupServerIds($a_obj_id)
214 {
215 global $DIC;
216
217 $ilDB = $DIC['ilDB'];
218
219 $query = 'SELECT * FROM ecs_export ' .
220 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ';
221 $res = $ilDB->query($query);
222 $sids = array();
223 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
224 $sids[] = $row->server_id;
225 }
226 return $sids;
227 }
228
237 public static function _deleteEContentIds($a_server_id, $a_ids)
238 {
239 global $DIC;
240
241 $ilDB = $DIC['ilDB'];
242
243 if (!is_array($a_ids) or !count($a_ids)) {
244 return true;
245 }
246 #$query = "DELETE FROM ecs_export WHERE econtent_id IN (".implode(',',ilUtil::quoteArray($a_ids)).')';
247 $query = "DELETE FROM ecs_export WHERE " . $ilDB->in('econtent_id', $a_ids, false, 'integer') . ' ' .
248 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer');
249 $res = $ilDB->manipulate($query);
250 return true;
251 }
252
258 public static function deleteByServer($a_server_id)
259 {
260 global $DIC;
261
262 $ilDB = $DIC['ilDB'];
263
264 $query = 'DELETE FROM ecs_export ' .
265 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
266 $ilDB->manipulate($query);
267 }
268
277 public static function _isRemote($a_server_id, $a_econtent_id)
278 {
279 global $DIC;
280
281 $ilDB = $DIC['ilDB'];
282
283 $query = "SELECT obj_id FROM ecs_export " .
284 "WHERE econtent_id = " . $ilDB->quote($a_econtent_id, 'integer') . " " .
285 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer');
286 $res = $ilDB->query($query);
287 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
288 return false;
289 }
290 return true;
291 }
292
300 public function setExported($a_status)
301 {
302 $this->exported = $a_status;
303 }
304
311 public function isExported()
312 {
313 return (bool) $this->exported;
314 }
315
323 public function setEContentId($a_id)
324 {
325 $this->econtent_id = $a_id;
326 }
327
335 public function getEContentId()
336 {
337 return $this->econtent_id;
338 }
339
345 public function save()
346 {
347 global $DIC;
348
349 $ilDB = $DIC['ilDB'];
350
351 $query = "DELETE FROM ecs_export " .
352 "WHERE obj_id = " . $this->db->quote($this->obj_id, 'integer') . " " .
353 'AND server_id = ' . $ilDB->quote($this->getServerId());
354 $res = $ilDB->manipulate($query);
355
356 if ($this->isExported()) {
357 $query = "INSERT INTO ecs_export (server_id,obj_id,econtent_id) " .
358 "VALUES ( " .
359 $this->db->quote($this->getServerId(), 'integer') . ', ' .
360 $this->db->quote($this->obj_id, 'integer') . ", " .
361 $this->db->quote($this->getEContentId(), 'integer') . " " .
362 ")";
363 $res = $ilDB->manipulate($query);
364 }
365
366 return true;
367 }
368
373 private function read()
374 {
375 global $DIC;
376
377 $ilDB = $DIC['ilDB'];
378
379 $query = "SELECT * FROM ecs_export WHERE " .
380 "obj_id = " . $this->db->quote($this->obj_id, 'integer') . " AND " .
381 'server_id = ' . $ilDB->quote($this->getServerId(), 'integer');
382 $res = $this->db->query($query);
383 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
384 $this->econtent_id = $row->econtent_id;
385 $this->exported = true;
386 }
387 }
388
389 public static function deleteByServerId($a_server_id)
390 {
391 global $DIC;
392
393 $ilDB = $DIC['ilDB'];
394
395 $query = 'DELETE FROM ecs_export' .
396 ' WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
397 $ilDB->manipulate($query);
398 return true;
399 }
400}
An exception for terminatinating execution or to throw for unit testing.
Storage of ECS exported objects.
static deleteByServer($a_server_id)
Delete by server id @global ilDB $ilDB.
getEContentId()
get econtent id
setServerId($a_server_id)
Set server id.
static getExportedIds()
Get exported ids @global ilDB $ilDB.
static _isRemote($a_server_id, $a_econtent_id)
is remote object
getServerId()
Get server id.
setExported($a_status)
Set exported.
isExported()
check if an object is exported or not
static getExportedIdsByType($a_type)
Get exported ids by type @global ilDB $ilDB.
static _isExported($a_obj_id)
Check if object is exported.
static _deleteEContentIds($a_server_id, $a_ids)
Delete econtent ids for server.
__construct($a_server_id, $a_obj_id)
Constructor.
static lookupServerIds($a_obj_id)
Lookup server ids of exported objects @global ilDB $ilDB.
static _getAllEContentIds($a_server_id)
get all exported econtent ids per server
read()
Read @access private.
static getExportServerIds($a_obj_id)
lookup server ids of exported materials @global ilDB $ilDB
setEContentId($a_id)
set econtent id
static _getExportedIDsByServer($a_server_id)
get exported ids for server
static deleteByServerId($a_server_id)
$row
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$a_type
Definition: workflow.php:92