ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
64  return $row->content_id;
65  }
66  return '';
67  }
68 
76  public static function lookupObjIdByContentId($a_server_id, $a_mid, $a_content_id, $a_sub_id = null)
77  {
78  global $ilDB;
79 
80  $query = "SELECT obj_id FROM ecs_import ".
81  "WHERE content_id = ".$ilDB->quote($a_content_id,'integer')." ".
82  "AND mid = ".$ilDB->quote($a_mid,'integer')." ".
83  'AND server_id = '.$ilDB->quote($a_server_id,'integer').' ';
84 
85  if(!is_null($a_sub_id))
86  {
87  $query .= 'AND sub_id = '.$ilDB->quote($a_sub_id,'text');
88  }
89  else
90  {
91  $query .= 'AND sub_id IS NULL';
92  }
93  $res = $ilDB->query($query);
94 
95  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
96  {
97  return $row->obj_id;
98  }
99  return 0;
100 
101  }
102 
103  public static function lookupObjIdsByContentId($a_content_id)
104  {
105  global $ilDB;
106 
107  $query = "SELECT obj_id FROM ecs_import ".
108  "WHERE content_id = ".$ilDB->quote($a_content_id,'integer');
109 
110  $res = $ilDB->query($query);
111 
112  $obj_ids = array();
113  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
114  {
115  $obj_ids[] = $row->obj_id;
116  }
117  return $obj_ids;
118  }
119 
120 
129  public static function lookupEContentIdByContentId($a_server_id,$a_mid,$a_content_id)
130  {
131  global $ilDB;
132 
133  $query = 'SELECT * from ecs_import '.
134  'WHERE server_id = '.$ilDB->quote($a_server_id,'integer').' '.
135  'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
136  'AND content_id = '.$ilDB->quote($a_content_id,'text');
137  $res = $ilDB->query($query);
138  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
139  {
140  return $row->econtent_id;
141  }
142  return 0;
143  }
144 
152  public static function getAllImportedRemoteObjects($a_server_id)
153  {
154  global $ilDB;
155 
156  include_once './Services/WebServices/ECS/classes/class.ilECSUtils.php';
157 
158  $query = "SELECT * FROM ecs_import ei JOIN object_data obd ON ei.obj_id = obd.obj_id ".
159  'WHERE server_id = '.$ilDB->quote($a_server_id).' '.
160  'AND '.$ilDB->in('type', ilECSUtils::getPossibleRemoteTypes(), false, 'text');
161  $res = $ilDB->query($query);
162  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
163  {
164  $all[$row->econtent_id] = $row->obj_id;
165  }
166 
167  return $all ? $all : array();
168  }
169 
178  public static function _lookupObjIdsByMID($a_server_id,$a_mid)
179  {
180  global $ilDB;
181 
182  $query = "SELECT * FROM ecs_import ".
183  "WHERE mid = ".$ilDB->quote($a_mid,'integer')." ".
184  'AND server_id = '.$ilDB->quote($a_server_id,'integer');
185 
186  $res = $ilDB->query($query);
187  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
188  {
189  $obj_ids[] = $row->obj_id;
190  }
191  return $obj_ids ? $obj_ids : array();
192  }
193 
202  public static function _lookupEContentId($a_obj_id)
203  {
204  global $ilDB;
205 
206  $query = "SELECT * FROM ecs_import WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ";
207  $res = $ilDB->query($query);
208  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
209  {
210  return $row->econtent_id;
211  }
212  return 0;
213  }
214 
221  public static function lookupServerId($a_obj_id)
222  {
223  global $ilDB;
224 
225  $query = 'SELECT * FROM ecs_import WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
226  $res = $ilDB->query($query);
227  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
228  {
229  return $row->server_id;
230  }
231  return 0;
232  }
233 
234 
241  public static function _lookupObjIds($a_server_id,$a_econtent_id)
242  {
243  global $ilDB;
244 
245  $query = "SELECT obj_id FROM ecs_import WHERE econtent_id = ".$ilDB->quote($a_econtent_id,'text')." ".
246  'AND server_id = '.$ilDB->quote($a_server_id,'integer');
247  $res = $ilDB->query($query);
248  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
249  {
250  $obj_ids[] = $row->obj_id;
251  }
252  return $obj_ids ? $obj_ids : array();
253  }
254 
263  public static function _lookupObjId($a_server_id,$a_econtent_id,$a_mid, $a_sub_id = null)
264  {
265  global $ilDB;
266 
267  $query = "SELECT obj_id FROM ecs_import ".
268  "WHERE econtent_id = ".$ilDB->quote($a_econtent_id,'text')." ".
269  "AND mid = ".$ilDB->quote($a_mid,'integer')." ".
270  'AND server_id = '.$ilDB->quote($a_server_id,'integer').' ';
271 
272  if(!is_null($a_sub_id))
273  {
274  $query .= 'AND sub_id = '.$ilDB->quote($a_sub_id,'text');
275  }
276  else
277  {
278  $query .= 'AND sub_id IS NULL';
279  }
280  $res = $ilDB->query($query);
281 
282  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
283  {
284  return $row->obj_id;
285  }
286  return 0;
287  }
288 
295  public static function _lookupMID($a_server_id,$a_obj_id)
296  {
297  global $ilDB;
298 
299  $query = "SELECT * FROM ecs_emport WHERE obj_id = ".$ilDB->quote($a_obj_id)." ".
300  'AND server_id = '.$ilDB->quote($a_server_id,'integer');
301  $res = $ilDB->query($query);
302  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
303  {
304  return $row->mid;
305  }
306  return 0;
307 
308  }
309 
318  public static function _lookupMIDs($a_server_id,$a_econtent_id)
319  {
320  global $ilDB;
321 
322  $query = "SELECT mid FROM ecs_import WHERE econtent_id = ".$ilDB->quote($a_econtent_id,'text')." ".
323  'AND server_id = '.$ilDB->quote($a_server_id,'integer');
324  $res = $ilDB->query($query);
325  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
326  {
327  $mids[] = $row->mid;
328  }
329  return $mids ? $mids : array();
330  }
331 
340  public static function _deleteByObjId($a_obj_id)
341  {
342  global $ilDB;
343 
344  $query = "DELETE FROM ecs_import ".
345  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ";
346  $res = $ilDB->manipulate($query);
347  return true;
348  }
349 
355  public static function deleteByServer($a_server_id)
356  {
357  global $ilDB;
358 
359  $query = 'DELETE FROM ecs_import '.
360  'WHERE server_id = '.$ilDB->quote($a_server_id,'integer');
361  $ilDB->manipulate($query);
362  }
363 
371  public static function deleteRessources($a_server_id, $a_mid, $a_econtent_ids)
372  {
373  global $ilDB;
374 
375  $query = 'DELETE FROM ecs_import '.
376  'WHERE server_id = '.$ilDB->quote($a_server_id,'integer'). ' '.
377  'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
378  'AND '.$ilDB->in('econtent_id',(array) $a_econtent_ids,false,'text');
379  $ilDB->manipulate($query);
380  return true;
381  }
382 
383 
384 
394  public static function _isImported($a_server_id,$a_econtent_id,$a_mid, $a_sub_id = null)
395  {
396  return ilECSImport::_lookupObjId($a_server_id,$a_econtent_id,$a_mid, $a_sub_id);
397  }
398 
399  public function setServerId($a_server_id)
400  {
401  $this->server_id = $a_server_id;
402  }
403 
404  public function getServerId()
405  {
406  return $this->server_id;
407  }
408 
416  public function setImported($a_status)
417  {
418  $this->imported = $a_status;
419  }
420 
421  public function setSubId($a_id)
422  {
423  $this->sub_id = $a_id;
424  }
425 
426  public function getSubId()
427  {
428  return strlen($this->sub_id) ? $this->sub_id : NULL;
429  }
430 
435  public function setContentId($a_content_id)
436  {
437  $this->content_id = $a_content_id;
438  }
439 
444  public function getContentId()
445  {
446  return $this->content_id;
447  }
448 
456  public function setMID($a_mid)
457  {
458  $this->mid = $a_mid;
459  }
460 
467  public function getMID()
468  {
469  return $this->mid;
470  }
471 
479  public function setEContentId($a_id)
480  {
481  $this->econtent_id = $a_id;
482  }
483 
490  public function getEContentId()
491  {
492  return $this->econtent_id;
493  }
494 
500  public function save()
501  {
502  global $ilDB;
503 
504  $query = "DELETE FROM ecs_import ".
505  "WHERE obj_id = ".$this->db->quote($this->obj_id,'integer')." ".
506  'AND server_id = '.$ilDB->quote($this->getServerId(),'integer');
507  $res = $ilDB->manipulate($query);
508 
509  $query = "INSERT INTO ecs_import (obj_id,mid,econtent_id,sub_id,server_id,content_id) ".
510  "VALUES ( ".
511  $this->db->quote($this->obj_id,'integer').", ".
512  $this->db->quote($this->mid,'integer').", ".
513  $this->db->quote($this->econtent_id,'text').", ".
514  $this->db->quote($this->getSubId(),'text'). ', '.
515  $this->db->quote($this->getServerId(),'integer').', '.
516  $this->db->quote($this->getContentId(),'text').' '.
517  ")";
518 
519  $res = $ilDB->manipulate($query);
520 
521  return true;
522  }
523 
528  private function read()
529  {
530  global $ilDB;
531 
532  $query = "SELECT * FROM ecs_import WHERE ".
533  "obj_id = ".$this->db->quote($this->obj_id,'integer')." ".
534  'AND server_id = '.$ilDB->quote($this->getServerId(),'integer');
535  $res = $this->db->query($query);
536  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
537  {
538  $this->econtent_id = $row->econtent_id;
539  $this->mid = $row->mid;
540  $this->sub_id = $row->sub_id;
541  $this->content_id = $row->content_id;
542  }
543  }
544 
545  public static function resetServerId($a_server_id)
546  {
547  global $ilDB;
548 
549  $query = 'UPDATE ecs_import SET server_id = '.$ilDB->quote(0,'integer').
550  ' WHERE server_id = '.$ilDB->quote($a_server_id,'integer');
551  $ilDB->manipulate($query);
552  return true;
553  }
554 
555 
556  public function setECSId($a_id)
557  {
558  $this->ecs_id = $a_id;
559  }
560 }
561 ?>
setServerId($a_server_id)
static getAllImportedRemoteObjects($a_server_id)
get all imported links
static getPossibleRemoteTypes($a_with_captions=false)
Get all possible remote object types.
static _lookupEContentId($a_obj_id)
get econent_id
static _lookupObjId($a_server_id, $a_econtent_id, $a_mid, $a_sub_id=null)
loogup obj_id by econtent and mid and server_id
static lookupObjIdByContentId($a_server_id, $a_mid, $a_content_id, $a_sub_id=null)
Lookup obj_id by content id.
static _deleteByObjId($a_obj_id)
Delete by obj_id.
static deleteByServer($a_server_id)
Delete by server id ilDB $ilDB.
static _lookupObjIdsByMID($a_server_id, $a_mid)
lookup obj ids by mid
static resetServerId($a_server_id)
Storage of ECS imported objects.
static _isImported($a_server_id, $a_econtent_id, $a_mid, $a_sub_id=null)
check if econtent is imported for a specific mid
getEContentId()
get econtent id
static lookupEContentIdByContentId($a_server_id, $a_mid, $a_content_id)
Lookup econtent id The econtent id is the unique id from ecs.
static lookupServerId($a_obj_id)
Lookup server id of imported content <type> $ilDB.
static _lookupMIDs($a_server_id, $a_econtent_id)
Lookup mids by.
read()
Read private.
Create styles array
The data for the language used.
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...
setImported($a_status)
Set imported.
getContentId()
get content id
static deleteRessources($a_server_id, $a_mid, $a_econtent_ids)
Delete ressources $ilDB.
setContentId($a_content_id)
Set content id.
static _lookupObjIds($a_server_id, $a_econtent_id)
Lookup obj_id.
global $ilDB
setEContentId($a_id)
set econtent id
static _lookupMID($a_server_id, $a_obj_id)
Lookup mid.
static lookupObjIdsByContentId($a_content_id)
setMID($a_mid)
set mid
__construct($a_server_id, $a_obj_id)
Constructor.