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

content/classes/class.ilObjSCORMLearningModule.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 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 
00025 require_once "classes/class.ilObject.php";
00026 require_once "content/classes/class.ilObjSCORMValidator.php";
00027 require_once "content/classes/class.ilObjSAHSLearningModule.php";
00028 //require_once "classes/class.ilMetaData.php";
00029 
00039 class ilObjSCORMLearningModule extends ilObjSAHSLearningModule
00040 {
00041         var $validator;
00042 //      var $meta_data;
00043 
00050         function ilObjSCORMLearningModule($a_id = 0, $a_call_by_reference = true)
00051         {
00052                 $this->type = "sahs";
00053                 parent::ilObject($a_id,$a_call_by_reference);
00054 /*
00055                 if ($a_id == 0)
00056                 {
00057                         $new_meta =& new ilMetaData();
00058                         $this->assignMetaData($new_meta);
00059                 }
00060 */
00061 
00062         }
00063 
00064 
00071         function validate($directory)
00072         {
00073                 $this->validator =& new ilObjSCORMValidator($directory);
00074                 $returnValue = $this->validator->validate();
00075                 return $returnValue;
00076         }
00077 
00078         function getValidationSummary()
00079         {
00080                 if(is_object($this->validator))
00081                 {
00082                         return $this->validator->getSummary();
00083                 }
00084                 return "";
00085         }
00086 
00087         function getTrackingItems()
00088         {
00089                 return ilObjSCORMLearningModule::_getTrackingItems($this->getId());
00090         }
00091 
00092 
00097         function _getTrackingItems($a_obj_id)
00098         {
00099                 include_once("content/classes/SCORM/class.ilSCORMTree.php");
00100                 $tree = new ilSCORMTree($a_obj_id);
00101                 $root_id = $tree->readRootId();
00102 
00103                 $items = array();
00104                 $childs = $tree->getSubTree($tree->getNodeData($root_id));
00105                 foreach($childs as $child)
00106                 {
00107                         if($child["type"] == "sit")
00108                         {
00109                                 include_once("content/classes/SCORM/class.ilSCORMItem.php");
00110                                 $sc_item =& new ilSCORMItem($child["obj_id"]);
00111                                 if ($sc_item->getIdentifierRef() != "")
00112                                 {
00113                                         $items[count($items)] =& $sc_item;
00114                                 }
00115                         }
00116                 }
00117 
00118                 return $items;
00119         }
00120 
00125         function readObject()
00126         {
00127                 // the seems_utf8($str) function
00128                 include_once("include/inc.utf8checker.php");
00129                 $needs_convert = false;
00130 
00131                 // convert imsmanifest.xml file in iso to utf8 if needed
00132                 // include_once("include/inc.convertcharset.php");
00133                 $manifest_file = $this->getDataDirectory()."/imsmanifest.xml";
00134 
00135                 // check if manifestfile exists and space left on device...
00136                 $check_for_manifest_file = is_file($manifest_file);
00137 
00138                 // if no manifestfile
00139                 if (!$check_for_manifest_file)
00140                 {
00141                         $this->ilias->raiseError($this->lng->txt("Manifestfile $manifest_file not found!"), $this->ilias->error_obj->MESSAGE);
00142                         return;
00143                 }
00144 
00145                 if ($check_for_manifest_file)
00146                 {
00147                         $manifest_file_array = file($manifest_file);
00148                         foreach($manifest_file_array as $mfa)
00149                         {
00150                                 if (!seems_not_utf8($mfa))
00151                                 {
00152                                         $needs_convert = true;
00153                                         break;
00154                                 }
00155                         }
00156 
00157                         // to copy the file we need some extraspace, counted in bytes *2 ... we need 2 copies....
00158                         $estimated_manifest_filesize = filesize($manifest_file) * 2;
00159                         
00160                         // i deactivated this, because it seems to fail on some windows systems (see bug #1795)
00161                         //$check_disc_free = disk_free_space($this->getDataDirectory()) - $estimated_manifest_filesize;
00162                         $check_disc_free = 2;
00163                 }
00164 
00165                 // if $manifest_file needs to be converted to UTF8
00166                 if ($needs_convert)
00167                 {
00168                         // if file exists and enough space left on device
00169                         if ($check_for_manifest_file && ($check_disc_free > 1))
00170                         {
00171 
00172                                 // create backup from original
00173                                 if (!copy($manifest_file, $manifest_file.".old"))
00174                                 {
00175                                         echo "Failed to copy $manifest_file...<br>\n";
00176                                 }
00177 
00178                                 // read backupfile, convert each line to utf8, write line to new file
00179                                 // php < 4.3 style
00180                                 $f_write_handler = fopen($manifest_file.".new", "w");
00181                                 $f_read_handler = fopen($manifest_file.".old", "r");
00182                                 while (!feof($f_read_handler))
00183                                 {
00184                                         $zeile = fgets($f_read_handler);
00185                                         //echo mb_detect_encoding($zeile);
00186                                         fputs($f_write_handler, utf8_encode($zeile));
00187                                 }
00188                                 fclose($f_read_handler);
00189                                 fclose($f_write_handler);
00190 
00191                                 // copy new utf8-file to imsmanifest.xml
00192                                 if (!copy($manifest_file.".new", $manifest_file))
00193                                 {
00194                                         echo "Failed to copy $manifest_file...<br>\n";
00195                                 }
00196 
00197                                 if (!@is_file($manifest_file))
00198                                 {
00199                                         $this->ilias->raiseError($this->lng->txt("cont_no_manifest"),
00200                                         $this->ilias->error_obj->WARNING);
00201                                 }
00202                         }
00203                         else
00204                         {
00205                                 // gives out the specific error
00206 
00207                                 if (!($check_disc_free > 1))
00208                                         $this->ilias->raiseError($this->lng->txt("Not enough space left on device!"),$this->ilias->error_obj->MESSAGE);
00209                                         return;
00210                         }
00211 
00212                 }
00213                 else
00214                 {
00215                         // check whether file starts with BOM (that confuses some sax parsers, see bug #1795)
00216                         $hmani = fopen($manifest_file, "r");
00217                         $start = fread($hmani, 3);
00218                         if (strtolower(bin2hex($start)) == "efbbbf")
00219                         {
00220                                 $f_write_handler = fopen($manifest_file.".new", "w");
00221                                 while (!feof($hmani))
00222                                 {
00223                                         $n = fread($hmani, 900);
00224                                         fputs($f_write_handler, $n);
00225                                 }
00226                                 fclose($f_write_handler);
00227                                 fclose($hmani);
00228 
00229                                 // copy new utf8-file to imsmanifest.xml
00230                                 if (!copy($manifest_file.".new", $manifest_file))
00231                                 {
00232                                         echo "Failed to copy $manifest_file...<br>\n";
00233                                 }
00234                         }
00235                         else
00236                         {
00237                                 fclose($hmani);
00238                         }
00239                 }
00240 
00241                 //validate the XML-Files in the SCORM-Package
00242                 if ($_POST["validate"] == "y")
00243                 {
00244                         if (!$this->validate($this->getDataDirectory()))
00245                         {
00246                                 $this->ilias->raiseError("<b>Validation Error(s):</b><br>".$this->getValidationSummary(),
00247                                         $this->ilias->error_obj->WARNING);
00248                         }
00249                 }
00250 
00251                 // start SCORM package parser
00252                 include_once ("content/classes/SCORM/class.ilSCORMPackageParser.php");
00253                 // todo determine imsmanifest.xml path here...
00254                 $slmParser = new ilSCORMPackageParser($this, $manifest_file);
00255                 $slmParser->startParsing();
00256                 return $slmParser->getPackageTitle();
00257         }
00258 
00259 
00263         function getTrackedItems()
00264         {
00265                 global $ilUser, $ilDB, $ilUser;
00266 
00267                 $query = "SELECT DISTINCT sco_id FROM scorm_tracking WHERE".
00268                         " obj_id = ".$ilDB->quote($this->getId());
00269 
00270                 $sco_set = $ilDB->query($query);
00271 
00272                 $items = array();
00273                 while($sco_rec = $sco_set->fetchRow(DB_FETCHMODE_ASSOC))
00274                 {
00275                         include_once("content/classes/SCORM/class.ilSCORMItem.php");
00276                         $sc_item =& new ilSCORMItem($sco_rec["sco_id"]);
00277                         if ($sc_item->getIdentifierRef() != "")
00278                         {
00279                                 $items[count($items)] =& $sc_item;
00280                         }
00281                 }
00282 
00283                 return $items;
00284         }
00285 
00286         function getTrackingDataPerUser($a_sco_id, $a_user_id)
00287         {
00288                 global $ilDB;
00289 
00290                 $query = "SELECT * FROM scorm_tracking WHERE".
00291                         " obj_id = ".$ilDB->quote($this->getId()).
00292                         " AND sco_id = ".$ilDB->quote($a_sco_id).
00293                         " AND user_id = ".$ilDB->quote($a_user_id).
00294                         " ORDER BY lvalue";
00295                 $data_set = $ilDB->query($query);
00296 
00297                 $data = array();
00298                 while($data_rec = $data_set->fetchRow(DB_FETCHMODE_ASSOC))
00299                 {
00300                         $data[] = $data_rec;
00301                 }
00302 
00303                 return $data;
00304         }
00305 
00306         function getTrackingDataAgg($a_sco_id)
00307         {
00308                 global $ilDB;
00309 
00310                 // get all users with any tracking data
00311                 $query = "SELECT DISTINCT user_id FROM scorm_tracking WHERE".
00312                         " obj_id = ".$ilDB->quote($this->getId()).
00313                         " AND sco_id = ".$ilDB->quote($a_sco_id);
00314                         //" ORDER BY user_id, lvalue";
00315                 $user_set = $ilDB->query($query);
00316 
00317                 $data = array();
00318                 while($user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC))
00319                 {
00320                         $query = "SELECT * FROM scorm_tracking WHERE".
00321                                 " obj_id = ".$ilDB->quote($this->getId()).
00322                                 " AND sco_id = ".$ilDB->quote($a_sco_id).
00323                                 " AND user_id =".$ilDB->quote($user_rec["user_id"]).
00324                                 " AND (lvalue =".$ilDB->quote("cmi.core.lesson_status").
00325                                 " OR lvalue =".$ilDB->quote("cmi.core.total_time").
00326                                 " OR lvalue =".$ilDB->quote("cmi.core.score.raw").")";
00327                         $data_set = $ilDB->query($query);
00328                         $score = $time = $status = "";
00329                         while($data_rec = $data_set->fetchRow(DB_FETCHMODE_ASSOC))
00330                         {
00331                                 switch($data_rec["lvalue"])
00332                                 {
00333                                         case "cmi.core.lesson_status":
00334                                                 $status = $data_rec["rvalue"];
00335                                                 break;
00336 
00337                                         case "cmi.core.total_time":
00338                                                 $time = $data_rec["rvalue"];
00339                                                 break;
00340 
00341                                         case "cmi.core.score.raw":
00342                                                 $score = $data_rec["rvalue"];
00343                                                 break;
00344                                 }
00345                         }
00346 
00347                         $data[] = array("user_id" => $user_rec["user_id"],
00348                                 "score" => $score, "time" => $time, "status" => $status);
00349                 }
00350 
00351                 return $data;
00352         }
00353 
00354 } // END class.ilObjSCORMLearningModule
00355 ?>

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