ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilECSImport.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 $obj_id = 0;
39  protected $econtent_id = 0;
40  protected $mid = 0;
41  protected $imported = false;
42 
50  public function __construct($a_obj_id)
51  {
52  global $ilDB;
53 
54  $this->obj_id = $a_obj_id;
55  $this->db = $ilDB;
56  $this->read();
57  }
58 
66  public static function _getAllImportedLinks()
67  {
68  global $ilDB;
69 
70  $query = "SELECT * FROM ecs_import ";
71  $res = $ilDB->query($query);
72  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
73  {
74  $all[$row->econtent_id] = $row->obj_id;
75  }
76  return $all ? $all : array();
77  }
78 
86  public static function _getAll()
87  {
88  global $ilDB;
89 
90  $query = "SELECT * FROM ecs_import ";
91  $res = $ilDB->query($query);
92  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
93  {
94  $all[$row->obj_id]['mid'] = $row->mid;
95  $all[$row->obj_id]['econtent_id'] = $row->econtent_id;
96  $all[$row->obj_id]['obj_id'] = $row->obj_id;
97  }
98  return $all ? $all : array();
99  }
100 
109  public static function _lookupObjIdsByMID($a_mid)
110  {
111  global $ilDB;
112 
113  $query = "SELECT * FROM ecs_import ".
114  "WHERE mid = ".$ilDB->quote($a_mid,'integer')." ";
115 
116  $res = $ilDB->query($query);
117  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
118  {
119  $obj_ids[] = $row->obj_id;
120  }
121  return $obj_ids ? $obj_ids : array();
122  }
123 
132  public static function _lookupEContentId($a_obj_id)
133  {
134  global $ilDB;
135 
136  $query = "SELECT * FROM ecs_import WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ";
137  $res = $ilDB->query($query);
138  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
139  {
140  return $row->econtent_id;
141  }
142  return 0;
143  }
144 
151  public function _lookupObjIds($a_econtent_id)
152  {
153  global $ilDB;
154 
155  $query = "SELECT obj_id FROM ecs_import WHERE econtent_id = ".$ilDB->quote($a_econtent_id,'integer')." ";
156  $res = $ilDB->query($query);
157  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
158  {
159  $obj_ids[] = $row->obj_id;
160  }
161  return $obj_ids ? $obj_ids : array();
162  }
163 
172  public function _lookupObjId($a_econtent_id,$a_mid)
173  {
174  global $ilDB;
175 
176  $query = "SELECT obj_id FROM ecs_import ".
177  "WHERE econtent_id = ".$ilDB->quote($a_econtent_id,'integer')." ".
178  "AND mid = ".$ilDB->quote($a_mid,'integer')." ";
179  $res = $ilDB->query($query);
180  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
181  {
182  return $row->obj_id;
183  }
184  return 0;
185  }
186 
193  public function _lookupMID($a_obj_id)
194  {
195  global $ilDB;
196 
197  $query = "SELECT * FROM ecs_emport WHERE obj_id = ".$ilDB->quote($a_obj_id)." ";
198  $res = $ilDB->query($query);
199  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
200  {
201  return $row->mid;
202  }
203  return 0;
204 
205  }
206 
215  public static function _lookupMIDs($a_econtent_id)
216  {
217  global $ilDB;
218 
219  $query = "SELECT mid FROM ecs_import WHERE econtent_id = ".$ilDB->quote($a_econtent_id,'integer')." ";
220  $res = $ilDB->query($query);
221  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
222  {
223  $mids[] = $row->mid;
224  }
225  return $mids ? $mids : array();
226  }
227 
236  public static function _deleteByObjId($a_obj_id)
237  {
238  global $ilDB;
239 
240  $query = "DELETE FROM ecs_import ".
241  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ";
242  $res = $ilDB->manipulate($query);
243  return true;
244  }
245 
246 
256  public static function _isImported($a_econtent_id,$a_mid)
257  {
258  return ilECSImport::_lookupObjId($a_econtent_id,$a_mid);
259  }
260 
268  public function setImported($a_status)
269  {
270  $this->imported = $a_status;
271  }
272 
280  public function setMID($a_mid)
281  {
282  $this->mid = $a_mid;
283  }
284 
291  public function getMID()
292  {
293  return $this->mid;
294  }
295 
303  public function setEContentId($a_id)
304  {
305  $this->econtent_id = $a_id;
306  }
307 
314  public function getEContentId()
315  {
316  return $this->econtent_id;
317  }
318 
324  public function save()
325  {
326  global $ilDB;
327 
328  $query = "DELETE FROM ecs_import ".
329  "WHERE obj_id = ".$this->db->quote($this->obj_id,'integer')." ";
330  $res = $ilDB->manipulate($query);
331 
332  $query = "INSERT INTO ecs_import (obj_id,mid,econtent_id) ".
333  "VALUES ( ".
334  $this->db->quote($this->obj_id,'integer').", ".
335  $this->db->quote($this->mid,'integer').", ".
336  $this->db->quote($this->econtent_id,'integer')." ".
337  ")";
338  $res = $ilDB->manipulate($query);
339 
340  return true;
341  }
342 
347  private function read()
348  {
349  global $ilDB;
350 
351  $query = "SELECT * FROM ecs_import WHERE ".
352  "obj_id = ".$this->db->quote($this->obj_id,'integer')." ";
353  $res = $this->db->query($query);
354  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
355  {
356  $this->econtent_id = $row->econtent_id;
357  $this->mid = $row->mid;
358  }
359  }
360 }
361 
362 
363 ?>