ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilDB;
53
54 $this->server_id = $a_server_id;
55 $this->obj_id = $a_obj_id;
56
57 $this->db = $ilDB;
58 $this->read();
59 }
60
65 public function getServerId()
66 {
67 return $this->server_id;
68 }
69
74 public function setServerId($a_server_id)
75 {
76 $this->server_id = $a_server_id;
77 }
78
84 public static function _isExported($a_obj_id)
85 {
86 global $ilDB;
87
88 $query = 'SELECT * FROM ecs_export ' .
89 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
90 $res = $ilDB->query($query);
91 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
92 return true;
93 }
94 return false;
95 }
96
97
105 public static function _getAllEContentIds($a_server_id)
106 {
107 global $ilDB;
108
109 $query = "SELECT econtent_id,obj_id FROM ecs_export " .
110 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
111
112 $res = $ilDB->query($query);
113 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
114 $econtent_ids[$row->econtent_id] = $row->obj_id;
115 }
116 return $econtent_ids ? $econtent_ids : array();
117 }
118
124 public static function getExportedIds()
125 {
126 global $ilDB;
127 $query = "SELECT obj_id FROM ecs_export ";
128 $res = $ilDB->query($query);
129 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
130 $obj_ids[] = $row->obj_id;
131 }
132 return $obj_ids ? $obj_ids : array();
133 }
134
140 public static function getExportedIdsByType($a_type)
141 {
142 global $ilDB;
143 $query = "SELECT e.obj_id FROM ecs_export e" .
144 " JOIN object_data o ON (e.obj_id = o.obj_id)" .
145 " WHERE o.type = " . $ilDB->quote($a_type, "text");
146 $res = $ilDB->query($query);
147 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
148 $obj_ids[] = $row->obj_id;
149 }
150 return $obj_ids ? $obj_ids : array();
151 }
152
159 public static function getExportServerIds($a_obj_id)
160 {
161 global $ilDB;
162
163 $query = 'SELECT * FROM ecs_export ' .
164 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
165 $res = $ilDB->query($query);
166
167 $sids = array();
168 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
169 $sids[] = $row->server_id;
170 }
171 return $sids;
172 }
173
181 public static function _getExportedIDsByServer($a_server_id)
182 {
183 global $ilDB;
184 $query = "SELECT obj_id FROM ecs_export " .
185 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
186 $res = $ilDB->query($query);
187 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
188 $obj_ids[] = $row->obj_id;
189 }
190 return $obj_ids ? $obj_ids : array();
191 }
192
199 public static function lookupServerIds($a_obj_id)
200 {
201 global $ilDB;
202
203 $query = 'SELECT * FROM ecs_export ' .
204 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ';
205 $res = $ilDB->query($query);
206 $sids = array();
207 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
208 $sids[] = $row->server_id;
209 }
210 return $sids;
211 }
212
221 public static function _deleteEContentIds($a_server_id, $a_ids)
222 {
223 global $ilDB;
224
225 if (!is_array($a_ids) or !count($a_ids)) {
226 return true;
227 }
228 #$query = "DELETE FROM ecs_export WHERE econtent_id IN (".implode(',',ilUtil::quoteArray($a_ids)).')';
229 $query = "DELETE FROM ecs_export WHERE " . $ilDB->in('econtent_id', $a_ids, false, 'integer') . ' ' .
230 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer');
231 $res = $ilDB->manipulate($query);
232 return true;
233 }
234
240 public static function deleteByServer($a_server_id)
241 {
242 global $ilDB;
243
244 $query = 'DELETE FROM ecs_export ' .
245 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
246 $ilDB->manipulate($query);
247 }
248
257 public static function _isRemote($a_server_id, $a_econtent_id)
258 {
259 global $ilDB;
260
261 $query = "SELECT obj_id FROM ecs_export " .
262 "WHERE econtent_id = " . $ilDB->quote($a_econtent_id, 'integer') . " " .
263 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer');
264 $res = $ilDB->query($query);
265 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
266 return false;
267 }
268 return true;
269 }
270
278 public function setExported($a_status)
279 {
280 $this->exported = $a_status;
281 }
282
289 public function isExported()
290 {
291 return (bool) $this->exported;
292 }
293
301 public function setEContentId($a_id)
302 {
303 $this->econtent_id = $a_id;
304 }
305
313 public function getEContentId()
314 {
315 return $this->econtent_id;
316 }
317
323 public function save()
324 {
325 global $ilDB;
326
327 $query = "DELETE FROM ecs_export " .
328 "WHERE obj_id = " . $this->db->quote($this->obj_id, 'integer') . " " .
329 'AND server_id = ' . $ilDB->quote($this->getServerId());
330 $res = $ilDB->manipulate($query);
331
332 if ($this->isExported()) {
333 $query = "INSERT INTO ecs_export (server_id,obj_id,econtent_id) " .
334 "VALUES ( " .
335 $this->db->quote($this->getServerId(), 'integer') . ', ' .
336 $this->db->quote($this->obj_id, 'integer') . ", " .
337 $this->db->quote($this->getEContentId(), 'integer') . " " .
338 ")";
339 $res = $ilDB->manipulate($query);
340 }
341
342 return true;
343 }
344
349 private function read()
350 {
351 global $ilDB;
352
353 $query = "SELECT * FROM ecs_export WHERE " .
354 "obj_id = " . $this->db->quote($this->obj_id, 'integer') . " AND " .
355 'server_id = ' . $ilDB->quote($this->getServerId(), 'integer');
356 $res = $this->db->query($query);
357 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
358 $this->econtent_id = $row->econtent_id;
359 $this->exported = true;
360 }
361 }
362
363 public static function deleteByServerId($a_server_id)
364 {
365 global $ilDB;
366
367 $query = 'DELETE FROM ecs_export' .
368 ' WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
369 $ilDB->manipulate($query);
370 return true;
371 }
372}
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)
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$a_type
Definition: workflow.php:92