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 24require_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMObject.php"); 25require_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMResourceFile.php"); 26require_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMResourceDependency.php"); 27 28/** 29* SCORM Resource 30* 31* @author Alex Killing <alex.killing@gmx.de> 32* @version $Id$ 33* 34* @ingroup ModulesScormAicc 35*/ 36class ilSCORMResource extends ilSCORMObject 37{ 38 public $import_id; 39 public $resourcetype; 40 public $scormtype; 41 public $href; 42 public $xml_base; 43 public $files; 44 public $dependencies; 45 46 47 /** 48 * Constructor 49 * 50 * @param int $a_id Object ID 51 * @access public 52 */ 53 public function __construct($a_id = 0) 54 { 55 $this->files = array(); 56 $this->dependencies = array(); 57 $this->setType("sre"); 58 parent::__construct($a_id); 59 } 60 61 public function getImportId() 62 { 63 return $this->import_id; 64 } 65 66 public function setImportId($a_import_id) 67 { 68 $this->import_id = $a_import_id; 69 } 70 71 public function getResourceType() 72 { 73 return $this->resourcetype; 74 } 75 76 public function setResourceType($a_type) 77 { 78 $this->resourcetype = $a_type; 79 } 80 81 public function getScormType() 82 { 83 return $this->scormtype; 84 } 85 86 public function setScormType($a_scormtype) 87 { 88 $this->scormtype = $a_scormtype; 89 } 90 91 public function getHRef() 92 { 93 return $this->href; 94 } 95 96 public function setHRef($a_href) 97 { 98 $this->href = $a_href; 99 $this->setTitle($a_href); 100 } 101 102 public function getXmlBase() 103 { 104 return $this->xml_base; 105 } 106 107 public function setXmlBase($a_xml_base) 108 { 109 $this->xml_base = $a_xml_base; 110 } 111 112 public function addFile(&$a_file_obj) 113 { 114 $this->files[] = &$a_file_obj; 115 } 116 117 public function &getFiles() 118 { 119 return $this->files; 120 } 121 122 public function addDependency(&$a_dependency) 123 { 124 $this->dependencies[] = &$a_dependency; 125 } 126 127 public function &getDependencies() 128 { 129 return $this->dependencies; 130 } 131 132 public function read() 133 { 134 global $DIC; 135 $ilDB = $DIC['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 $res_file = new ilSCORMResourceFile(); 159 $res_file->setHref($file_rec["href"]); 160 $this->addFile($res_file); 161 } 162 // read dependencies 163 164 $dep_set = $ilDB->queryF( 165 'SELECT identifierref FROM sc_resource_dependen WHERE res_id = %s ORDER BY nr', 166 array('integer'), 167 array($this->getId()) 168 ); 169 while ($dep_rec = $ilDB->fetchAssoc($dep_set)) { 170 $res_dep = new ilSCORMResourceDependency(); 171 $res_dep->setIdentifierRef($dep_rec["identifierref"]); 172 $this->addDependency($res_dep); 173 } 174 } 175 176 public function readByIdRef($a_id_ref, $a_slm_id) 177 { 178 global $DIC; 179 $ilBench = $DIC['ilBench']; 180 $ilDB = $DIC['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 $this->setId($id_rec["id"]); 197 $this->read(); 198 } 199 } 200 201 public static function _lookupIdByIdRef($a_id_ref, $a_slm_id) 202 { 203 global $DIC; 204 $ilBench = $DIC['ilBench']; 205 $ilDB = $DIC['ilDB']; 206 207 $id_set = $ilDB->queryF( 208 'SELECT ob.obj_id id FROM sc_resource res, scorm_object ob 209 WHERE ob.obj_id = res.obj_id 210 AND res.import_id = %s 211 AND ob.slm_id = %s', 212 array('text', 'integer'), 213 array($a_id_ref ,$a_slm_id) 214 ); 215 216 if ($id_rec = $ilDB->fetchAssoc($id_set)) { 217 return $id_rec["id"]; 218 } 219 return 0; 220 } 221 222 public static function _lookupScormType($a_obj_id) 223 { 224 global $DIC; 225 $ilDB = $DIC['ilDB']; 226 227 $st_set = $ilDB->queryF( 228 'SELECT scormtype FROM sc_resource WHERE obj_id = %s', 229 array('integer'), 230 array($a_obj_id) 231 ); 232 if ($st_rec = $ilDB->fetchAssoc($st_set)) { 233 return $st_rec["scormtype"]; 234 } 235 return ""; 236 } 237 238 public function create() 239 { 240 global $DIC; 241 $ilDB = $DIC['ilDB']; 242 243 parent::create(); 244 245 $ilDB->manipulateF( 246 ' 247 INSERT INTO sc_resource 248 (obj_id, import_id, resourcetype, scormtype, href, xml_base) 249 VALUES(%s, %s, %s, %s, %s, %s)', 250 array('integer','text','text','text','text','text'), 251 array( $this->getId(), 252 $this->getImportId(), 253 $this->getResourceType(), 254 $this->getScormType(), 255 $this->getHref(), 256 $this->getXmlBase() 257 ) 258 ); 259 260 // save files 261 for ($i = 0; $i < count($this->files); $i++) { 262 $nextId = $ilDB->nextId('sc_resource_file'); 263 264 $ilDB->manipulateF( 265 ' 266 INSERT INTO sc_resource_file (id,res_id, href, nr) 267 VALUES(%s, %s, %s, %s)', 268 array('integer', 'integer', 'text', 'integer'), 269 array($nextId, $this->getId(), $this->files[$i]->getHref(), ($i + 1)) 270 ); 271 } 272 273 // save dependencies 274 for ($i = 0; $i < count($this->dependencies); $i++) { 275 $nextId = $ilDB->nextId('sc_resource_dependen'); 276 277 $ilDB->manipulateF( 278 ' 279 INSERT INTO sc_resource_dependen (id, res_id, identifierref, nr) 280 VALUES(%s, %s, %s, %s)', 281 array('integer', 'integer', 'text', 'integer'), 282 array($nextId, $this->getId(), $this->files[$i]->getHref(), ($i + 1)) 283 ); 284 } 285 } 286 287 public function update() 288 { 289 global $DIC; 290 $ilDB = $DIC['ilDB']; 291 292 parent::update(); 293 294 $ilDB->manipulateF( 295 ' 296 UPDATE sc_resource 297 SET import_id = %s, 298 resourcetype = %s, 299 scormtype = %s, 300 href = %s, 301 xml_base = %s 302 WHERE obj_id = %s', 303 array('text', 'text', 'text', 'text', 'text', 'integer'), 304 array( $this->getImportId(), 305 $this->getResourceType(), 306 $this->getScormType(), 307 $this->getHRef(), 308 $this->getXmlBase(), 309 $this->getId()) 310 ); 311 312 // save files 313 $ilDB->manipulateF( 314 'DELETE FROM sc_resource_file WHERE res_id = %s', 315 array('integer'), 316 array($this->getId()) 317 ); 318 319 for ($i = 0; $i < count($this->files); $i++) { 320 $nextId = $ilDB->nextId('sc_resource_file'); 321 322 $ilDB->manipulateF( 323 'INSERT INTO sc_resource_file (id, res_id, href, nr) 324 VALUES (%s, %s, %s, %s)', 325 array('integer', 'integer', 'text', 'integer'), 326 array($nextId, $this->getId(), $this->files[$i]->getHref(), ($i + 1)) 327 ); 328 } 329 330 // save dependencies 331 $ilDB->manipulateF( 332 'DELETE FROM sc_resource_dependen WHERE res_id = %s', 333 array('integer'), 334 array($this->getId()) 335 ); 336 337 for ($i = 0; $i < count($this->dependencies); $i++) { 338 $nextId = $ilDB->nextId('sc_resource_dependen'); 339 340 $ilDB->manipulateF( 341 ' 342 INSERT INTO sc_resource_dependen (id, res_id, identifierref, nr) VALUES 343 (%s, %s, %s, %s) ', 344 array('integer', 'integer', 'text', 'integer'), 345 array($nextId, $this->getId(), $this->dependencies[$i]->getIdentifierRef(), ($i + 1)) 346 ); 347 } 348 } 349 350 public function delete() 351 { 352 global $DIC; 353 $ilDB = $DIC['ilDB']; 354 355 parent::delete(); 356 357 $ilDB->manipulateF( 358 'DELETE FROM sc_resource WHERE obj_id = %s', 359 array('integer'), 360 array($this->getId()) 361 ); 362 363 $ilDB->manipulateF( 364 'DELETE FROM sc_resource_file WHERE res_id = %s', 365 array('integer'), 366 array($this->getId()) 367 ); 368 369 $ilDB->manipulateF( 370 'DELETE FROM sc_resource_dependen WHERE res_id = %s', 371 array('integer'), 372 array($this->getId()) 373 ); 374 } 375} 376