ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilECSImport.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
15{
16 protected $db = null;
17
18 protected $server_id = 0;
19 protected $obj_id = 0;
20 protected $econtent_id = 0;
21 protected $content_id = '';
22 protected $sub_id = null;
23 protected $mid = 0;
24 protected $imported = false;
25 protected $ecs_id = 0;
26
34 public function __construct($a_server_id, $a_obj_id)
35 {
36 global $ilDB;
37
38 $this->server_id = $a_server_id;
39 $this->obj_id = $a_obj_id;
40 $this->db = $ilDB;
41 $this->read();
42 }
43
53 public static function lookupContentId($a_server_id, $a_mid, $a_econtent_id)
54 {
55 global $ilDB;
56
57 $query = 'SELECT * from ecs_import ' .
58 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
59 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
60 'AND econtent_id = ' . $ilDB->quote($a_econtent_id, 'text');
61 $res = $ilDB->query($query);
62 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
63 return $row->content_id;
64 }
65 return '';
66 }
67
75 public static function lookupObjIdByContentId($a_server_id, $a_mid, $a_content_id, $a_sub_id = null)
76 {
77 global $ilDB;
78
79 $query = "SELECT obj_id FROM ecs_import " .
80 "WHERE content_id = " . $ilDB->quote($a_content_id, 'integer') . " " .
81 "AND mid = " . $ilDB->quote($a_mid, 'integer') . " " .
82 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ';
83
84 if (!is_null($a_sub_id)) {
85 $query .= 'AND sub_id = ' . $ilDB->quote($a_sub_id, 'text');
86 } else {
87 $query .= 'AND sub_id IS NULL';
88 }
89 $res = $ilDB->query($query);
90
91 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
92 return $row->obj_id;
93 }
94 return 0;
95 }
96
97 public static function lookupObjIdsByContentId($a_content_id)
98 {
99 global $ilDB;
100
101 $query = "SELECT obj_id FROM ecs_import " .
102 "WHERE content_id = " . $ilDB->quote($a_content_id, 'integer');
103
104 $res = $ilDB->query($query);
105
106 $obj_ids = array();
107 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
108 $obj_ids[] = $row->obj_id;
109 }
110 return $obj_ids;
111 }
112
113
122 public static function lookupEContentIdByContentId($a_server_id, $a_mid, $a_content_id)
123 {
124 global $ilDB;
125
126 $query = 'SELECT * from ecs_import ' .
127 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
128 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
129 'AND content_id = ' . $ilDB->quote($a_content_id, 'text');
130 $res = $ilDB->query($query);
131 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
132 return $row->econtent_id;
133 }
134 return 0;
135 }
136
144 public static function getAllImportedRemoteObjects($a_server_id)
145 {
146 global $ilDB;
147
148 include_once './Services/WebServices/ECS/classes/class.ilECSUtils.php';
149
150 $query = "SELECT * FROM ecs_import ei JOIN object_data obd ON ei.obj_id = obd.obj_id " .
151 'WHERE server_id = ' . $ilDB->quote($a_server_id) . ' ' .
152 'AND ' . $ilDB->in('type', ilECSUtils::getPossibleRemoteTypes(), false, 'text');
153 $res = $ilDB->query($query);
154 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
155 $all[$row->econtent_id] = $row->obj_id;
156 }
157
158 return $all ? $all : array();
159 }
160
169 public static function _lookupObjIdsByMID($a_server_id, $a_mid)
170 {
171 global $ilDB;
172
173 $query = "SELECT * FROM ecs_import " .
174 "WHERE mid = " . $ilDB->quote($a_mid, 'integer') . " " .
175 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer');
176
177 $res = $ilDB->query($query);
178 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
179 $obj_ids[] = $row->obj_id;
180 }
181 return $obj_ids ? $obj_ids : array();
182 }
183
192 public static function _lookupEContentId($a_obj_id)
193 {
194 global $ilDB;
195
196 $query = "SELECT * FROM ecs_import WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
197 $res = $ilDB->query($query);
198 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
199 return $row->econtent_id;
200 }
201 return 0;
202 }
203
210 public static function lookupServerId($a_obj_id)
211 {
212 global $ilDB;
213
214 $query = 'SELECT * FROM ecs_import WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
215 $res = $ilDB->query($query);
216 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
217 return $row->server_id;
218 }
219 return 0;
220 }
221
222
229 public static function _lookupObjIds($a_server_id, $a_econtent_id)
230 {
231 global $ilDB;
232
233 $query = "SELECT obj_id FROM ecs_import WHERE econtent_id = " . $ilDB->quote($a_econtent_id, 'text') . " " .
234 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer');
235 $res = $ilDB->query($query);
236 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
237 $obj_ids[] = $row->obj_id;
238 }
239 return $obj_ids ? $obj_ids : array();
240 }
241
250 public static function _lookupObjId($a_server_id, $a_econtent_id, $a_mid, $a_sub_id = null)
251 {
252 global $ilDB;
253
254 $query = "SELECT obj_id FROM ecs_import " .
255 "WHERE econtent_id = " . $ilDB->quote($a_econtent_id, 'text') . " " .
256 "AND mid = " . $ilDB->quote($a_mid, 'integer') . " " .
257 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ';
258
259 if (!is_null($a_sub_id)) {
260 $query .= 'AND sub_id = ' . $ilDB->quote($a_sub_id, 'text');
261 } else {
262 $query .= 'AND sub_id IS NULL';
263 }
264 $res = $ilDB->query($query);
265
266 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
267 return $row->obj_id;
268 }
269 return 0;
270 }
271
278 public static function _lookupMID($a_server_id, $a_obj_id)
279 {
280 global $ilDB;
281
282 $query = "SELECT * FROM ecs_emport WHERE obj_id = " . $ilDB->quote($a_obj_id) . " " .
283 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer');
284 $res = $ilDB->query($query);
285 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
286 return $row->mid;
287 }
288 return 0;
289 }
290
299 public static function _lookupMIDs($a_server_id, $a_econtent_id)
300 {
301 global $ilDB;
302
303 $query = "SELECT mid FROM ecs_import WHERE econtent_id = " . $ilDB->quote($a_econtent_id, 'text') . " " .
304 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer');
305 $res = $ilDB->query($query);
306 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
307 $mids[] = $row->mid;
308 }
309 return $mids ? $mids : array();
310 }
311
320 public static function _deleteByObjId($a_obj_id)
321 {
322 global $ilDB;
323
324 $query = "DELETE FROM ecs_import " .
325 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
326 $res = $ilDB->manipulate($query);
327 return true;
328 }
329
335 public static function deleteByServer($a_server_id)
336 {
337 global $ilDB;
338
339 $query = 'DELETE FROM ecs_import ' .
340 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
341 $ilDB->manipulate($query);
342 }
343
351 public static function deleteRessources($a_server_id, $a_mid, $a_econtent_ids)
352 {
353 global $ilDB;
354
355 $query = 'DELETE FROM ecs_import ' .
356 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
357 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
358 'AND ' . $ilDB->in('econtent_id', (array) $a_econtent_ids, false, 'text');
359 $ilDB->manipulate($query);
360 return true;
361 }
362
363
364
374 public static function _isImported($a_server_id, $a_econtent_id, $a_mid, $a_sub_id = null)
375 {
376 return ilECSImport::_lookupObjId($a_server_id, $a_econtent_id, $a_mid, $a_sub_id);
377 }
378
379 public function setServerId($a_server_id)
380 {
381 $this->server_id = $a_server_id;
382 }
383
384 public function getServerId()
385 {
386 return $this->server_id;
387 }
388
396 public function setImported($a_status)
397 {
398 $this->imported = $a_status;
399 }
400
401 public function setSubId($a_id)
402 {
403 $this->sub_id = $a_id;
404 }
405
406 public function getSubId()
407 {
408 return strlen($this->sub_id) ? $this->sub_id : null;
409 }
410
415 public function setContentId($a_content_id)
416 {
417 $this->content_id = $a_content_id;
418 }
419
424 public function getContentId()
425 {
426 return $this->content_id;
427 }
428
436 public function setMID($a_mid)
437 {
438 $this->mid = $a_mid;
439 }
440
447 public function getMID()
448 {
449 return $this->mid;
450 }
451
459 public function setEContentId($a_id)
460 {
461 $this->econtent_id = $a_id;
462 }
463
470 public function getEContentId()
471 {
472 return $this->econtent_id;
473 }
474
480 public function save()
481 {
482 global $ilDB;
483
484 $query = "DELETE FROM ecs_import " .
485 "WHERE obj_id = " . $this->db->quote($this->obj_id, 'integer') . " " .
486 'AND server_id = ' . $ilDB->quote($this->getServerId(), 'integer');
487 $res = $ilDB->manipulate($query);
488
489 $query = "INSERT INTO ecs_import (obj_id,mid,econtent_id,sub_id,server_id,content_id) " .
490 "VALUES ( " .
491 $this->db->quote($this->obj_id, 'integer') . ", " .
492 $this->db->quote($this->mid, 'integer') . ", " .
493 $this->db->quote($this->econtent_id, 'text') . ", " .
494 $this->db->quote($this->getSubId(), 'text') . ', ' .
495 $this->db->quote($this->getServerId(), 'integer') . ', ' .
496 $this->db->quote($this->getContentId(), 'text') . ' ' .
497 ")";
498
499 $res = $ilDB->manipulate($query);
500
501 return true;
502 }
503
508 private function read()
509 {
510 global $ilDB;
511
512 $query = "SELECT * FROM ecs_import WHERE " .
513 "obj_id = " . $this->db->quote($this->obj_id, 'integer') . " " .
514 'AND server_id = ' . $ilDB->quote($this->getServerId(), 'integer');
515 $res = $this->db->query($query);
516 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
517 $this->econtent_id = $row->econtent_id;
518 $this->mid = $row->mid;
519 $this->sub_id = $row->sub_id;
520 $this->content_id = $row->content_id;
521 }
522 }
523
524 public static function resetServerId($a_server_id)
525 {
526 global $ilDB;
527
528 $query = 'UPDATE ecs_import SET server_id = ' . $ilDB->quote(0, 'integer') .
529 ' WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
530 $ilDB->manipulate($query);
531 return true;
532 }
533
534
535 public function setECSId($a_id)
536 {
537 $this->ecs_id = $a_id;
538 }
539}
An exception for terminatinating execution or to throw for unit testing.
Storage of ECS imported objects.
setContentId($a_content_id)
Set content id.
setMID($a_mid)
set mid
getContentId()
get content id
static deleteByServer($a_server_id)
Delete by server id @global ilDB $ilDB.
setEContentId($a_id)
set econtent id
setServerId($a_server_id)
static _lookupEContentId($a_obj_id)
get econent_id
static _deleteByObjId($a_obj_id)
Delete by obj_id.
static getAllImportedRemoteObjects($a_server_id)
get all imported links
read()
Read @access private.
static _lookupMID($a_server_id, $a_obj_id)
Lookup mid.
__construct($a_server_id, $a_obj_id)
Constructor.
static lookupEContentIdByContentId($a_server_id, $a_mid, $a_content_id)
Lookup econtent id The econtent id is the unique id from ecs.
static lookupObjIdsByContentId($a_content_id)
static _lookupObjIdsByMID($a_server_id, $a_mid)
lookup obj ids by mid
getEContentId()
get econtent id
static _lookupObjIds($a_server_id, $a_econtent_id)
Lookup obj_id.
static deleteRessources($a_server_id, $a_mid, $a_econtent_ids)
Delete ressources @global $ilDB.
static lookupContentId($a_server_id, $a_mid, $a_econtent_id)
Lookup content id The content is the - not necessarily unique - id provided by the econtent type.
static resetServerId($a_server_id)
static _isImported($a_server_id, $a_econtent_id, $a_mid, $a_sub_id=null)
check if econtent is imported for a specific mid
static lookupServerId($a_obj_id)
Lookup server id of imported content @global <type> $ilDB.
static _lookupObjId($a_server_id, $a_econtent_id, $a_mid, $a_sub_id=null)
loogup obj_id by econtent and mid and server_id
setImported($a_status)
Set imported.
static _lookupMIDs($a_server_id, $a_econtent_id)
Lookup mids by.
static lookupObjIdByContentId($a_server_id, $a_mid, $a_content_id, $a_sub_id=null)
Lookup obj_id by content id.
static getPossibleRemoteTypes($a_with_captions=false)
Get all possible remote object types.
$query
foreach($_POST as $key=> $value) $res
global $ilDB