ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 $DIC;
37
38 $ilDB = $DIC['ilDB'];
39
40 $this->server_id = $a_server_id;
41 $this->obj_id = $a_obj_id;
42 $this->db = $ilDB;
43 $this->read();
44 }
45
55 public static function lookupContentId($a_server_id, $a_mid, $a_econtent_id)
56 {
57 global $DIC;
58
59 $ilDB = $DIC['ilDB'];
60
61 $query = 'SELECT * from ecs_import ' .
62 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
63 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
64 'AND econtent_id = ' . $ilDB->quote($a_econtent_id, 'text');
65 $res = $ilDB->query($query);
66 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
67 return $row->content_id;
68 }
69 return '';
70 }
71
79 public static function lookupObjIdByContentId($a_server_id, $a_mid, $a_content_id, $a_sub_id = null)
80 {
81 global $DIC;
82
83 $ilDB = $DIC['ilDB'];
84
85 $query = "SELECT obj_id FROM ecs_import " .
86 "WHERE content_id = " . $ilDB->quote($a_content_id, 'integer') . " " .
87 "AND mid = " . $ilDB->quote($a_mid, 'integer') . " " .
88 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ';
89
90 if (!is_null($a_sub_id)) {
91 $query .= 'AND sub_id = ' . $ilDB->quote($a_sub_id, 'text');
92 } else {
93 $query .= 'AND sub_id IS NULL';
94 }
95 $res = $ilDB->query($query);
96
97 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
98 return $row->obj_id;
99 }
100 return 0;
101 }
102
103 public static function lookupObjIdsByContentId($a_content_id)
104 {
105 global $DIC;
106
107 $ilDB = $DIC['ilDB'];
108
109 $query = "SELECT obj_id FROM ecs_import " .
110 "WHERE content_id = " . $ilDB->quote($a_content_id, 'integer');
111
112 $res = $ilDB->query($query);
113
114 $obj_ids = array();
115 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
116 $obj_ids[] = $row->obj_id;
117 }
118 return $obj_ids;
119 }
120
121
130 public static function lookupEContentIdByContentId($a_server_id, $a_mid, $a_content_id)
131 {
132 global $DIC;
133
134 $ilDB = $DIC['ilDB'];
135
136 $query = 'SELECT * from ecs_import ' .
137 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
138 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
139 'AND content_id = ' . $ilDB->quote($a_content_id, 'text');
140 $res = $ilDB->query($query);
141 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
142 return $row->econtent_id;
143 }
144 return 0;
145 }
146
154 public static function getAllImportedRemoteObjects($a_server_id)
155 {
156 global $DIC;
157
158 $ilDB = $DIC['ilDB'];
159
160 include_once './Services/WebServices/ECS/classes/class.ilECSUtils.php';
161
162 $query = "SELECT * FROM ecs_import ei JOIN object_data obd ON ei.obj_id = obd.obj_id " .
163 'WHERE server_id = ' . $ilDB->quote($a_server_id) . ' ' .
164 'AND ' . $ilDB->in('type', ilECSUtils::getPossibleRemoteTypes(), false, 'text');
165 $res = $ilDB->query($query);
166 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
167 $all[$row->econtent_id] = $row->obj_id;
168 }
169
170 return $all ? $all : array();
171 }
172
181 public static function _lookupObjIdsByMID($a_server_id, $a_mid)
182 {
183 global $DIC;
184
185 $ilDB = $DIC['ilDB'];
186
187 $query = "SELECT * FROM ecs_import " .
188 "WHERE mid = " . $ilDB->quote($a_mid, 'integer') . " " .
189 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer');
190
191 $res = $ilDB->query($query);
192 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
193 $obj_ids[] = $row->obj_id;
194 }
195 return $obj_ids ? $obj_ids : array();
196 }
197
206 public static function _lookupEContentId($a_obj_id)
207 {
208 global $DIC;
209
210 $ilDB = $DIC['ilDB'];
211
212 $query = "SELECT * FROM ecs_import WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
213 $res = $ilDB->query($query);
214 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
215 return $row->econtent_id;
216 }
217 return 0;
218 }
219
226 public static function lookupServerId($a_obj_id)
227 {
228 global $DIC;
229
230 $ilDB = $DIC['ilDB'];
231
232 $query = 'SELECT * FROM ecs_import WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
233 $res = $ilDB->query($query);
234 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
235 return $row->server_id;
236 }
237 return 0;
238 }
239
240
247 public static function _lookupObjIds($a_server_id, $a_econtent_id)
248 {
249 global $DIC;
250
251 $ilDB = $DIC['ilDB'];
252
253 $query = "SELECT obj_id FROM ecs_import WHERE econtent_id = " . $ilDB->quote($a_econtent_id, 'text') . " " .
254 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer');
255 $res = $ilDB->query($query);
256 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
257 $obj_ids[] = $row->obj_id;
258 }
259 return $obj_ids ? $obj_ids : array();
260 }
261
270 public static function _lookupObjId($a_server_id, $a_econtent_id, $a_mid, $a_sub_id = null)
271 {
272 global $DIC;
273
274 $ilDB = $DIC['ilDB'];
275
276 $query = "SELECT obj_id FROM ecs_import " .
277 "WHERE econtent_id = " . $ilDB->quote($a_econtent_id, 'text') . " " .
278 "AND mid = " . $ilDB->quote($a_mid, 'integer') . " " .
279 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ';
280
281 if (!is_null($a_sub_id)) {
282 $query .= 'AND sub_id = ' . $ilDB->quote($a_sub_id, 'text');
283 } else {
284 $query .= 'AND sub_id IS NULL';
285 }
286 $res = $ilDB->query($query);
287
288 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
289 return $row->obj_id;
290 }
291 return 0;
292 }
293
300 public static function _lookupMID($a_server_id, $a_obj_id)
301 {
302 global $DIC;
303
304 $ilDB = $DIC['ilDB'];
305
306 $query = "SELECT * FROM ecs_emport WHERE obj_id = " . $ilDB->quote($a_obj_id) . " " .
307 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer');
308 $res = $ilDB->query($query);
309 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
310 return $row->mid;
311 }
312 return 0;
313 }
314
323 public static function _lookupMIDs($a_server_id, $a_econtent_id)
324 {
325 global $DIC;
326
327 $ilDB = $DIC['ilDB'];
328
329 $query = "SELECT mid FROM ecs_import WHERE econtent_id = " . $ilDB->quote($a_econtent_id, 'text') . " " .
330 'AND server_id = ' . $ilDB->quote($a_server_id, 'integer');
331 $res = $ilDB->query($query);
332 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
333 $mids[] = $row->mid;
334 }
335 return $mids ? $mids : array();
336 }
337
346 public static function _deleteByObjId($a_obj_id)
347 {
348 global $DIC;
349
350 $ilDB = $DIC['ilDB'];
351
352 $query = "DELETE FROM ecs_import " .
353 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
354 $res = $ilDB->manipulate($query);
355 return true;
356 }
357
363 public static function deleteByServer($a_server_id)
364 {
365 global $DIC;
366
367 $ilDB = $DIC['ilDB'];
368
369 $query = 'DELETE FROM ecs_import ' .
370 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
371 $ilDB->manipulate($query);
372 }
373
381 public static function deleteRessources($a_server_id, $a_mid, $a_econtent_ids)
382 {
383 global $DIC;
384
385 $ilDB = $DIC['ilDB'];
386
387 $query = 'DELETE FROM ecs_import ' .
388 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
389 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
390 'AND ' . $ilDB->in('econtent_id', (array) $a_econtent_ids, false, 'text');
391 $ilDB->manipulate($query);
392 return true;
393 }
394
395
396
406 public static function _isImported($a_server_id, $a_econtent_id, $a_mid, $a_sub_id = null)
407 {
408 return ilECSImport::_lookupObjId($a_server_id, $a_econtent_id, $a_mid, $a_sub_id);
409 }
410
411 public function setServerId($a_server_id)
412 {
413 $this->server_id = $a_server_id;
414 }
415
416 public function getServerId()
417 {
418 return $this->server_id;
419 }
420
428 public function setImported($a_status)
429 {
430 $this->imported = $a_status;
431 }
432
433 public function setSubId($a_id)
434 {
435 $this->sub_id = $a_id;
436 }
437
438 public function getSubId()
439 {
440 return strlen($this->sub_id) ? $this->sub_id : null;
441 }
442
447 public function setContentId($a_content_id)
448 {
449 $this->content_id = $a_content_id;
450 }
451
456 public function getContentId()
457 {
458 return $this->content_id;
459 }
460
468 public function setMID($a_mid)
469 {
470 $this->mid = $a_mid;
471 }
472
479 public function getMID()
480 {
481 return $this->mid;
482 }
483
491 public function setEContentId($a_id)
492 {
493 $this->econtent_id = $a_id;
494 }
495
502 public function getEContentId()
503 {
504 return $this->econtent_id;
505 }
506
512 public function save()
513 {
514 global $DIC;
515
516 $ilDB = $DIC['ilDB'];
517
518 $query = "DELETE FROM ecs_import " .
519 "WHERE obj_id = " . $this->db->quote($this->obj_id, 'integer') . " " .
520 'AND server_id = ' . $ilDB->quote($this->getServerId(), 'integer');
521 $res = $ilDB->manipulate($query);
522
523 $query = "INSERT INTO ecs_import (obj_id,mid,econtent_id,sub_id,server_id,content_id) " .
524 "VALUES ( " .
525 $this->db->quote($this->obj_id, 'integer') . ", " .
526 $this->db->quote($this->mid, 'integer') . ", " .
527 $this->db->quote($this->econtent_id, 'text') . ", " .
528 $this->db->quote($this->getSubId(), 'text') . ', ' .
529 $this->db->quote($this->getServerId(), 'integer') . ', ' .
530 $this->db->quote($this->getContentId(), 'text') . ' ' .
531 ")";
532
533 $res = $ilDB->manipulate($query);
534
535 return true;
536 }
537
542 private function read()
543 {
544 global $DIC;
545
546 $ilDB = $DIC['ilDB'];
547
548 $query = "SELECT * FROM ecs_import WHERE " .
549 "obj_id = " . $this->db->quote($this->obj_id, 'integer') . " " .
550 'AND server_id = ' . $ilDB->quote($this->getServerId(), 'integer');
551 $res = $this->db->query($query);
552 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
553 $this->econtent_id = $row->econtent_id;
554 $this->mid = $row->mid;
555 $this->sub_id = $row->sub_id;
556 $this->content_id = $row->content_id;
557 }
558 }
559
560 public static function resetServerId($a_server_id)
561 {
562 global $DIC;
563
564 $ilDB = $DIC['ilDB'];
565
566 $query = 'UPDATE ecs_import SET server_id = ' . $ilDB->quote(0, 'integer') .
567 ' WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer');
568 $ilDB->manipulate($query);
569 return true;
570 }
571
572
573 public function setECSId($a_id)
574 {
575 $this->ecs_id = $a_id;
576 }
577}
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
$DIC
Definition: xapitoken.php:46