ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
class.ilSCORMResource.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
24 require_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMObject.php");
25 require_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMResourceFile.php");
26 require_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMResourceDependency.php");
27 
37 {
41  var $href;
42  var $xml_base;
43  var $files;
45 
46 
53  function ilSCORMResource($a_id = 0)
54  {
55  $this->files = array();
56  $this->dependencies = array();
57  $this->setType("sre");
58  parent::ilSCORMObject($a_id);
59 
60  }
61 
62  function getImportId()
63  {
64  return $this->import_id;
65  }
66 
67  function setImportId($a_import_id)
68  {
69  $this->import_id = $a_import_id;
70  }
71 
72  function getResourceType()
73  {
74  return $this->resourcetype;
75  }
76 
77  function setResourceType($a_type)
78  {
79  $this->resourcetype = $a_type;
80  }
81 
82  function getScormType()
83  {
84  return $this->scormtype;
85  }
86 
87  function setScormType($a_scormtype)
88  {
89  $this->scormtype = $a_scormtype;
90  }
91 
92  function getHRef()
93  {
94  return $this->href;
95  }
96 
97  function setHRef($a_href)
98  {
99  $this->href = $a_href;
100  $this->setTitle($a_href);
101  }
102 
103  function getXmlBase()
104  {
105  return $this->xml_base;
106  }
107 
108  function setXmlBase($a_xml_base)
109  {
110  $this->xml_base = $a_xml_base;
111  }
112 
113  function addFile(&$a_file_obj)
114  {
115  $this->files[] =& $a_file_obj;
116  }
117 
118  function &getFiles()
119  {
120  return $this->files;
121  }
122 
123  function addDependency(&$a_dependency)
124  {
125  $this->dependencies[] =& $a_dependency;
126  }
127 
128  function &getDependencies()
129  {
130  return $this->dependencies;
131  }
132 
133  function read()
134  {
135  global $ilDB;
136 
137  parent::read();
138 
139  $obj_set = $ilDB->queryF(
140  'SELECT * FROM sc_resource WHERE obj_id = %s',
141  array('integer'),
142  array($this->getId())
143  );
144  $obj_rec = $ilDB->fetchAssoc($obj_set);
145  $this->setImportId($obj_rec["import_id"]);
146  $this->setResourceType($obj_rec["resourcetype"]);
147  $this->setScormType($obj_rec["scormtype"]);
148  $this->setHRef($obj_rec["href"]);
149  $this->setXmlBase($obj_rec["xml_base"]);
150 
151  // read files
152  $file_set = $ilDB->queryF(
153  'SELECT href FROM sc_resource_file WHERE res_id = %s ORDER BY nr',
154  array('integer'),
155  array($this->getId())
156  );
157  while ($file_rec =$ilDB->fetchAssoc($file_set))
158  {
159  $res_file =& new ilSCORMResourceFile();
160  $res_file->setHref($file_rec["href"]);
161  $this->addFile($res_file);
162  }
163  // read dependencies
164 
165  $dep_set = $ilDB->queryF(
166  'SELECT identifierref FROM sc_resource_dependen WHERE res_id = %s ORDER BY nr',
167  array('integer'),
168  array($this->getId())
169  );
170  while ($dep_rec =$ilDB->fetchAssoc($dep_set))
171  {
172  $res_dep =& new ilSCORMResourceDependency();
173  $res_dep->setIdentifierRef($dep_rec["identifierref"]);
174  $this->addDependency($res_dep);
175  }
176  }
177 
178  function readByIdRef($a_id_ref, $a_slm_id)
179  {
180  global $ilBench, $ilDB;
181 
182  $ilBench->start("SCORMResource", "readByIdRef_Query");
183 
184  $id_set = $ilDB->queryF(
185  'SELECT ob.obj_id id FROM sc_resource res, scorm_object ob
186  WHERE ob.obj_id = res.obj_id
187  AND res.import_id = %s
188  AND ob.slm_id = %s',
189  array('text', 'integer'),
190  array($a_id_ref, $a_slm_id)
191  );
192 
193  $ilBench->stop("SCORMResource", "readByIdRef_Query");
194 
195  if ($id_rec = $ilDB->fetchAssoc($id_set))
196  {
197  $this->setId($id_rec["id"]);
198  $this->read();
199  }
200  }
201 
202  function _lookupIdByIdRef($a_id_ref, $a_slm_id)
203  {
204  global $ilBench, $ilDB;
205 
206  $id_set = $ilDB->queryF(
207  'SELECT ob.obj_id id FROM sc_resource res, scorm_object ob
208  WHERE ob.obj_id = res.obj_id
209  AND res.import_id = %s
210  AND ob.slm_id = %s',
211  array('text', 'integer'),
212  array($a_id_ref ,$a_slm_id)
213  );
214 
215  if ($id_rec = $ilDB->fetchAssoc($id_set))
216  {
217  return $id_rec["id"];
218  }
219  return 0;
220  }
221 
222  function _lookupScormType($a_obj_id)
223  {
224  global $ilDB;
225 
226  $st_set = $ilDB->queryF(
227  'SELECT scormtype FROM sc_resource WHERE obj_id = %s',
228  array('integer'),
229  array($a_obj_id)
230  );
231  if ($st_rec = $ilDB->fetchAssoc($st_set))
232  {
233  return $st_rec["scormtype"];
234  }
235  return "";
236  }
237 
238  function create()
239  {
240  global $ilDB;
241 
242  parent::create();
243 
244  $ilDB->manipulateF('
245  INSERT INTO sc_resource
246  (obj_id, import_id, resourcetype, scormtype, href, xml_base)
247  VALUES(%s, %s, %s, %s, %s, %s)',
248  array('integer','text','text','text','text','text'),
249  array( $this->getId(),
250  $this->getImportId(),
251  $this->getResourceType(),
252  $this->getScormType(),
253  $this->getHref(),
254  $this->getXmlBase()
255  )
256  );
257 
258  // save files
259  for($i=0; $i<count($this->files); $i++)
260  {
261  $nextId = $ilDB->nextId('sc_resource_file');
262 
263  $ilDB->manipulateF('
264  INSERT INTO sc_resource_file (id,res_id, href, nr)
265  VALUES(%s, %s, %s, %s)',
266  array('integer', 'integer', 'text', 'integer'),
267  array($nextId, $this->getId(), $this->files[$i]->getHref(), ($i + 1))
268  );
269 
270  }
271 
272  // save dependencies
273  for($i=0; $i<count($this->dependencies); $i++)
274  {
275  $nextId = $ilDB->nextId('sc_resource_dependen');
276 
277  $ilDB->manipulateF('
278  INSERT INTO sc_resource_dependen (id, res_id, identifierref, nr)
279  VALUES(%s, %s, %s, %s)',
280  array('integer', 'integer', 'text', 'integer'),
281  array($nextId, $this->getId(), $this->files[$i]->getHref(), ($i + 1))
282  );
283  }
284  }
285 
286  function update()
287  {
288  global $ilDB;
289 
290  parent::update();
291 
292  $ilDB->manipulateF('
293  UPDATE sc_resource
294  SET import_id = %s,
295  resourcetype = %s,
296  scormtype = %s,
297  href = %s,
298  xml_base = %s
299  WHERE obj_id = %s',
300  array('text', 'text', 'text', 'text', 'text', 'integer'),
301  array( $this->getImportId(),
302  $this->getResourceType(),
303  $this->getScormType(),
304  $this->getHRef(),
305  $this->getXmlBase(),
306  $this->getId())
307  );
308 
309  // save files
310  $ilDB->manipulateF(
311  'DELETE FROM sc_resource_file WHERE res_id = %s',
312  array('integer'),
313  array($this->getId())
314  );
315 
316  for($i=0; $i<count($this->files); $i++)
317  {
318  $nextId = $ilDB->nextId('sc_resource_file');
319 
320  $ilDB->manipulateF(
321  'INSERT INTO sc_resource_file (id, res_id, href, nr)
322  VALUES (%s, %s, %s, %s)',
323  array('integer', 'integer', 'text', 'integer'),
324  array($nextId, $this->getId(), $this->files[$i]->getHref(), ($i + 1))
325  );
326  }
327 
328  // save dependencies
329  $ilDB->manipulateF(
330  'DELETE FROM sc_resource_dependen WHERE res_id = %s',
331  array('integer'),
332  array($this->getId())
333  );
334 
335  for($i = 0; $i < count($this->dependencies); $i++)
336  {
337  $nextId = $ilDB->nextId('sc_resource_dependen');
338 
339  $ilDB->manipulateF('
340  INSERT INTO sc_resource_dependen (id, res_id, identifierref, nr) VALUES
341  (%s, %s, %s, %s) ',
342  array('integer', 'integer', 'text', 'integer'),
343  array($nextId, $this->getId(), $this->dependencies[$i]->getIdentifierRef(), ($i + 1))
344  );
345  }
346  }
347 
348  function delete()
349  {
350  global $ilDB;
351 
352  parent::delete();
353 
354  $ilDB->manipulateF(
355  'DELETE FROM sc_resource WHERE obj_id = %s',
356  array('integer'),
357  array($this->getId())
358  );
359 
360  $ilDB->manipulateF(
361  'DELETE FROM sc_resource_file WHERE res_id = %s',
362  array('integer'),
363  array($this->getId())
364  );
365 
366  $ilDB->manipulateF(
367  'DELETE FROM sc_resource_dependen WHERE res_id = %s',
368  array('integer'),
369  array($this->getId())
370  );
371  }
372 }
373 ?>
SCORM Resource Dependency, DB accesses are done in ilSCORMResource.
setScormType($a_scormtype)
addDependency(&$a_dependency)
readByIdRef($a_id_ref, $a_slm_id)
ilSCORMResource($a_id=0)
Constructor.
Parent object for all SCORM objects, that are stored in table scorm_object.
setImportId($a_import_id)
SCORM Resource File, DB accesses are done in ilSCORMResource.
global $ilBench
Definition: ilias.php:18
global $ilDB
_lookupIdByIdRef($a_id_ref, $a_slm_id)