• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

content/classes/SCORM/class.ilSCORMResource.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 require_once("content/classes/SCORM/class.ilSCORMObject.php");
00025 require_once("content/classes/SCORM/class.ilSCORMResourceFile.php");
00026 require_once("content/classes/SCORM/class.ilSCORMResourceDependency.php");
00027 
00037 class ilSCORMResource extends ilSCORMObject
00038 {
00039         var $import_id;
00040         var $resourcetype;
00041         var $scormtype;
00042         var $href;
00043         var $xml_base;
00044         var $files;
00045         var $dependencies;
00046 
00047 
00054         function ilSCORMResource($a_id = 0)
00055         {
00056                 $this->files = array();
00057                 $this->dependencies = array();
00058                 $this->setType("sre");
00059                 parent::ilSCORMObject($a_id);
00060 
00061         }
00062 
00063         function getImportId()
00064         {
00065                 return $this->import_id;
00066         }
00067 
00068         function setImportId($a_import_id)
00069         {
00070                 $this->import_id = $a_import_id;
00071         }
00072 
00073         function getResourceType()
00074         {
00075                 return $this->resourcetype;
00076         }
00077 
00078         function setResourceType($a_type)
00079         {
00080                 $this->resourcetype = $a_type;
00081         }
00082 
00083         function getScormType()
00084         {
00085                 return $this->scormtype;
00086         }
00087 
00088         function setScormType($a_scormtype)
00089         {
00090                 $this->scormtype = $a_scormtype;
00091         }
00092 
00093         function getHRef()
00094         {
00095                 return $this->href;
00096         }
00097 
00098         function setHRef($a_href)
00099         {
00100                 $this->href = $a_href;
00101                 $this->setTitle($a_href);
00102         }
00103 
00104         function getXmlBase()
00105         {
00106                 return $this->xml_base;
00107         }
00108 
00109         function setXmlBase($a_xml_base)
00110         {
00111                 $this->xml_base = $a_xml_base;
00112         }
00113 
00114         function addFile(&$a_file_obj)
00115         {
00116                 $this->files[] =& $a_file_obj;
00117         }
00118 
00119         function &getFiles()
00120         {
00121                 return $this->files;
00122         }
00123 
00124         function addDependency(&$a_dependency)
00125         {
00126                 $this->dependencies[] =& $a_dependency;
00127         }
00128 
00129         function &getDependencies()
00130         {
00131                 return $this->dependencies;
00132         }
00133 
00134         function read()
00135         {
00136                 parent::read();
00137 
00138                 $q = "SELECT * FROM sc_resource WHERE obj_id = '".$this->getId()."'";
00139 
00140                 $obj_set = $this->ilias->db->query($q);
00141                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00142                 $this->setImportId($obj_rec["import_id"]);
00143                 $this->setResourceType($obj_rec["resourcetype"]);
00144                 $this->setScormType($obj_rec["scormtype"]);
00145                 $this->setHRef($obj_rec["href"]);
00146                 $this->setXmlBase($obj_rec["xml_base"]);
00147 
00148                 // read files
00149                 $q = "SELECT * FROM sc_resource_file WHERE res_id = '".$this->getId().
00150                         "' ORDER BY nr";
00151                 $file_set = $this->ilias->db->query($q);
00152                 while ($file_rec = $file_set->fetchRow(DB_FETCHMODE_ASSOC))
00153                 {
00154                         $res_file =& new ilSCORMResourceFile();
00155                         $res_file->setHref($file_rec["href"]);
00156                         $this->addFile($res_file);
00157                 }
00158                 // read dependencies
00159                 $q = "SELECT * FROM sc_resource_dependency WHERE res_id = '".$this->getId().
00160                         "' ORDER BY nr";
00161                 $dep_set = $this->ilias->db->query($q);
00162                 while ($dep_rec = $dep_set->fetchRow(DB_FETCHMODE_ASSOC))
00163                 {
00164                         $res_dep =& new ilSCORMResourceDependency();
00165                         $res_dep->setIdentifierRef($dep_rec["identifierref"]);
00166                         $this->addDependency($res_dep);
00167                 }
00168         }
00169 
00170         function readByIdRef($a_id_ref, $a_slm_id)
00171         {
00172                 global $ilBench;
00173                 
00174                 $ilBench->start("SCORMResource", "readByIdRef_Query");
00175                 
00176                 $q = "SELECT ob.obj_id AS id FROM sc_resource AS res, scorm_object as ob ".
00177                 "WHERE ob.obj_id = res.obj_id ".
00178                 "AND res.import_id = '$a_id_ref'".
00179                 "AND ob.slm_id = '$a_slm_id'";
00180 
00181                 $id_set = $this->ilias->db->query($q);
00182                 $ilBench->stop("SCORMResource", "readByIdRef_Query");
00183                 
00184                 if ($id_rec = $id_set->fetchRow(DB_FETCHMODE_ASSOC))
00185                 {
00186                         $this->setId($id_rec["id"]);
00187                         $this->read();
00188                 }
00189         }
00190 
00191         function _lookupIdByIdRef($a_id_ref, $a_slm_id)
00192         {
00193                 global $ilBench, $ilDB;
00194                 
00195                 $q = "SELECT ob.obj_id AS id FROM sc_resource AS res, scorm_object as ob ".
00196                 "WHERE ob.obj_id = res.obj_id ".
00197                 "AND res.import_id = '$a_id_ref'".
00198                 "AND ob.slm_id = '$a_slm_id'";
00199 
00200                 $id_set = $ilDB->query($q);
00201                 if ($id_rec = $id_set->fetchRow(DB_FETCHMODE_ASSOC))
00202                 {
00203                         return $id_rec["id"];
00204                 }
00205                 return 0;
00206         }
00207         
00208         function _lookupScormType($a_obj_id)
00209         {
00210                 global $ilDB;
00211                 
00212                 $q = "SELECT scormtype FROM sc_resource WHERE obj_id = '".$a_obj_id."'";
00213                 $st_set = $ilDB->query($q);
00214                 if ($st_rec = $st_set->fetchRow(DB_FETCHMODE_ASSOC))
00215                 {
00216                         return $st_rec["scormtype"];
00217                 }
00218                 return "";
00219         }
00220 
00221         function create()
00222         {
00223                 parent::create();
00224 
00225                 $q = "INSERT INTO sc_resource (obj_id, import_id, resourcetype, scormtype, href, ".
00226                         "xml_base) VALUES ".
00227                         "('".$this->getId()."', '".$this->getImportId()."',".
00228                         "'".$this->getResourceType()."','".$this->getScormType()."','".$this->getHref()."'".
00229                         ",'".$this->getXmlBase()."')";
00230                 $this->ilias->db->query($q);
00231 
00232                 // save files
00233                 for($i=0; $i<count($this->files); $i++)
00234                 {
00235                         $q = "INSERT INTO sc_resource_file (res_id, href, nr) VALUES ".
00236                                 "('".$this->getId()."', '".$this->files[$i]->getHref()."','".($i + 1)."')";
00237                         $this->ilias->db->query($q);
00238                 }
00239 
00240                 // save dependencies
00241                 for($i=0; $i<count($this->dependencies); $i++)
00242                 {
00243                         $q = "INSERT INTO sc_resource_dependency (res_id, identifierref, nr) VALUES ".
00244                                 "('".$this->getId()."', '".$this->dependencies[$i]->getIdentifierRef().
00245                                 "','".($i + 1)."')";
00246                         $this->ilias->db->query($q);
00247                 }
00248         }
00249 
00250         function update()
00251         {
00252                 parent::update();
00253 
00254                 $q = "UPDATE sc_resource SET ".
00255                         "import_id = '".$this->getImportId()."', ".
00256                         "resourcetype = '".$this->getResourceType()."', ".
00257                         "scormtype = '".$this->getScormType()."', ".
00258                         "href = '".$this->getHRef()."', ".
00259                         "xml_base = '".$this->getXmlBase()."' ".
00260                         "WHERE obj_id = '".$this->getId()."'";
00261                 $this->ilias->db->query($q);
00262 
00263                 // save files
00264                 $q = "DELETE FROM sc_resource_file WHERE res_id = '".$this->getId()."'";
00265                 $this->ilias->db->query($q);
00266                 for($i=0; $i<count($this->files); $i++)
00267                 {
00268                         $q = "INSERT INTO sc_resource_file (res_id, href, nr) VALUES ".
00269                                 "('".$this->getId()."', '".$this->files[$i]->getHref()."','".($i + 1)."')";
00270                         $this->ilias->db->query($q);
00271                 }
00272 
00273                 // save dependencies
00274                 $q = "DELETE FROM sc_resource_dependency WHERE res_id = '".$this->getId()."'";
00275                 $this->ilias->db->query($q);
00276                 for($i=0; $i<count($this->dependencies); $i++)
00277                 {
00278                         $q = "INSERT INTO sc_resource_dependency (res_id, identifierref, nr) VALUES ".
00279                                 "('".$this->getId()."', '".$this->dependencies[$i]->getIdentifierRef().
00280                                 "','".($i + 1)."')";
00281                         $this->ilias->db->query($q);
00282                 }
00283         }
00284 
00285         function delete()
00286         {
00287                 global $ilDB;
00288 
00289                 parent::delete();
00290 
00291                 $q = "DELETE FROM sc_resource WHERE obj_id =".$ilDB->quote($this->getId());
00292                 $ilDB->query($q);
00293 
00294                 $q = "DELETE FROM sc_resource_file WHERE res_id =".$ilDB->quote($this->getId());
00295                 $ilDB->query($q);
00296 
00297                 $q = "DELETE FROM sc_resource_dependency WHERE res_id =".$ilDB->quote($this->getId());
00298                 $ilDB->query($q);
00299         }
00300 
00301 
00302 }
00303 ?>

Generated on Fri Dec 13 2013 13:52:10 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1