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

Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.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 
00025 require_once "classes/class.ilObject.php";
00026 require_once "./Modules/ScormAicc/classes/class.ilObjSCORMValidator.php";
00027 //require_once "Services/MetaData/classes/class.ilMDLanguageItem.php";
00028 
00040 class ilObjSAHSLearningModule extends ilObject
00041 {
00042         var $validator;
00043 //      var $meta_data;
00044 
00051         function ilObjSAHSLearningModule($a_id = 0, $a_call_by_reference = true)
00052         {
00053                 $this->type = "sahs";
00054                 parent::ilObject($a_id,$a_call_by_reference);
00055 
00056         }
00057 
00061         function create()
00062         {
00063                 global $ilDB;
00064 
00065                 parent::create();
00066                 $this->createMetaData();
00067 
00068                 $this->createDataDirectory();
00069 
00070 /*
00071                 $this->meta_data->setId($this->getId());
00072 //echo "<br>title:".$this->getId();
00073                 $this->meta_data->setType($this->getType());
00074 //echo "<br>title:".$this->getType();
00075                 $this->meta_data->setTitle($this->getTitle());
00076 //echo "<br>title:".$this->getTitle();
00077                 $this->meta_data->setDescription($this->getDescription());
00078                 $this->meta_data->setObject($this);
00079                 $this->meta_data->create();
00080 */
00081 
00082                 $q = "INSERT INTO sahs_lm (id, online, api_adapter, type) VALUES ".
00083                         " (".$ilDB->quote($this->getID()).",".$ilDB->quote("n").",".
00084                         $ilDB->quote("API").",".$ilDB->quote($this->getSubType()).")";
00085                 $ilDB->query($q);
00086         }
00087 
00091         function read()
00092         {
00093                 global $ilDB;
00094                 
00095                 parent::read();
00096                 $q = "SELECT * FROM sahs_lm WHERE id = ".$ilDB->quote($this->getId());
00097                 $lm_set = $this->ilias->db->query($q);
00098                 $lm_rec = $lm_set->fetchRow(DB_FETCHMODE_ASSOC);
00099                 $this->setOnline(ilUtil::yn2tf($lm_rec["online"]));
00100                 $this->setAutoReview(ilUtil::yn2tf($lm_rec["auto_review"]));
00101                 $this->setAPIAdapterName($lm_rec["api_adapter"]);
00102                 $this->setDefaultLessonMode($lm_rec["default_lesson_mode"]);
00103                 $this->setAPIFunctionsPrefix($lm_rec["api_func_prefix"]);
00104                 $this->setCreditMode($lm_rec["credit"]);
00105                 $this->setSubType($lm_rec["type"]);
00106         }
00107 
00111         function _lookupOnline($a_id)
00112         {
00113                 global $ilDB;
00114                 
00115                 $q = "SELECT * FROM sahs_lm WHERE id = ".$ilDB->quote($a_id);
00116                 $lm_set = $this->ilias->db->query($q);
00117                 $lm_rec = $lm_set->fetchRow(DB_FETCHMODE_ASSOC);
00118 
00119                 return ilUtil::yn2tf($lm_rec["online"]);
00120         }
00121 
00127         function _lookupSubType($a_obj_id)
00128         {
00129                 global $ilDB;
00130 
00131                 $q = "SELECT * FROM sahs_lm WHERE id = ".$ilDB->quote($a_obj_id);
00132                 $obj_set = $ilDB->query($q);
00133                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00134 
00135                 return $obj_rec["type"];
00136         }
00137 
00143 /*
00144         function getTitle()
00145         {
00146                 return parent::getTitle();
00147         }
00148 */
00149 
00155 /*
00156         function setTitle($a_title)
00157         {
00158                 parent::setTitle($a_title);
00159 //              $this->meta_data->setTitle($a_title);
00160         }
00161 */
00162 
00168 /*
00169         function getDescription()
00170         {
00171                 return $this->meta_data->getDescription();
00172         }
00173 */
00174 
00180 /*
00181         function setDescription($a_description)
00182         {
00183                 $this->meta_data->setDescription($a_description);
00184         }
00185 */
00186 
00192 /*
00193         function assignMetaData(&$a_meta_data)
00194         {
00195                 $this->meta_data =& $a_meta_data;
00196         }
00197 */
00198 
00204 /*
00205         function &getMetaData()
00206         {
00207                 return $this->meta_data;
00208         }
00209 */
00210 
00211 
00216         function createDataDirectory()
00217         {
00218                 $lm_data_dir = ilUtil::getWebspaceDir()."/lm_data";
00219                 ilUtil::makeDir($lm_data_dir);
00220                 ilUtil::makeDir($this->getDataDirectory());
00221         }
00222 
00226         function getDataDirectory($mode = "filesystem")
00227         {
00228                 $lm_data_dir = ilUtil::getWebspaceDir($mode)."/lm_data";
00229                 $lm_dir = $lm_data_dir."/lm_".$this->getId();
00230 
00231                 return $lm_dir;
00232         }
00233 
00237         function getAPIAdapterName()
00238         {
00239                 return $this->api_adapter;
00240         }
00241 
00245         function setAPIAdapterName($a_api)
00246         {
00247                 $this->api_adapter = $a_api;
00248         }
00249 
00253         function getAPIFunctionsPrefix()
00254         {
00255                 return $this->api_func_prefix;
00256         }
00257 
00261         function setAPIFunctionsPrefix($a_prefix)
00262         {
00263                 $this->api_func_prefix = $a_prefix;
00264         }
00265 
00269         function getCreditMode()
00270         {
00271                 return $this->credit_mode;
00272         }
00273 
00277         function setCreditMode($a_credit_mode)
00278         {
00279                 $this->credit_mode = $a_credit_mode;
00280         }
00281 
00285         function setDefaultLessonMode($a_lesson_mode)
00286         {
00287                 $this->lesson_mode = $a_lesson_mode;
00288         }
00289 
00293         function getDefaultLessonMode()
00294         {
00295                 return $this->lesson_mode;
00296         }
00297 
00301         function setAutoReview($a_auto_review)
00302         {
00303                 $this->auto_review = $a_auto_review;
00304         }
00305 
00309         function getAutoReview()
00310         {
00311                 return $this->auto_review;
00312         }
00313 
00317 /*
00318         function updateMetaData()
00319         {
00320                 $this->meta_data->update();
00321                 if ($this->meta_data->section != "General")
00322                 {
00323                         $meta = $this->meta_data->getElement("Title", "General");
00324                         $this->meta_data->setTitle($meta[0]["value"]);
00325                         $meta = $this->meta_data->getElement("Description", "General");
00326                         $this->meta_data->setDescription($meta[0]["value"]);
00327                 }
00328                 else
00329                 {
00330                         $this->setTitle($this->meta_data->getTitle());
00331                         $this->setDescription($this->meta_data->getDescription());
00332                 }
00333                 parent::update();
00334 
00335         }
00336 */
00337 
00338 
00345         function update()
00346         {
00347                 global $ilDB;
00348 
00349                 $this->updateMetaData();
00350                 parent::update();
00351 
00352                 $q = "UPDATE sahs_lm SET ".
00353                         " online = ".$ilDB->quote(ilUtil::tf2yn($this->getOnline())).",".
00354                         " api_adapter = ".$ilDB->quote($this->getAPIAdapterName()).",".
00355                         " api_func_prefix = ".$ilDB->quote($this->getAPIFunctionsPrefix()).",".
00356                         " auto_review = ".$ilDB->quote(ilUtil::tf2yn($this->getAutoReview())).",".
00357                         " default_lesson_mode = ".$ilDB->quote($this->getDefaultLessonMode()).",".
00358                         " type = ".$ilDB->quote($this->getSubType()).",".
00359                         " credit = ".$ilDB->quote($this->getCreditMode())."".
00360                         " WHERE id = ".$ilDB->quote($this->getId());
00361                 $this->ilias->db->query($q);
00362 
00363                 return true;
00364         }
00365 
00369         function setOnline($a_online)
00370         {
00371                 $this->online = $a_online;
00372         }
00373 
00377         function getOnline()
00378         {
00379                 return $this->online;
00380         }
00381 
00385         function setSubType($a_sub_type)
00386         {
00387                 $this->sub_type = $a_sub_type;
00388         }
00389 
00393         function getSubType()
00394         {
00395                 return $this->sub_type;
00396         }
00397 
00409         function delete()
00410         {
00411                 global $ilDB, $ilLog;
00412 
00413                 // always call parent delete function first!!
00414                 if (!parent::delete())
00415                 {
00416                         return false;
00417                 }
00418 
00419                 // delete meta data of scorm content object
00420 /*
00421                 $nested = new ilNestedSetXML();
00422                 $nested->init($this->getId(), $this->getType());
00423                 $nested->deleteAllDBData();
00424 */
00425                 $this->deleteMetaData();
00426 
00427                 // delete data directory
00428                 ilUtil::delDir($this->getDataDirectory());
00429 
00430                 // delete scorm learning module record
00431                 $q = "DELETE FROM sahs_lm WHERE id = ".$ilDB->quote($this->getId());
00432                 $this->ilias->db->query($q);
00433                 $ilLog->write("SAHS Delete(SAHSLM), Subtype: ".$this->getSubType());
00434                 
00435                 if ($this->getSubType() == "scorm")
00436                 {
00437                         // remove all scorm objects and scorm tree
00438                         include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMTree.php");
00439                         include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMObject.php");
00440                         $sc_tree = new ilSCORMTree($this->getId());
00441                         $r_id = $sc_tree->readRootId();
00442                         if ($r_id > 0)
00443                         {
00444                                 $items = $sc_tree->getSubTree($sc_tree->getNodeData($r_id));
00445                                 foreach($items as $item)
00446                                 {
00447                                         $sc_object =& ilSCORMObject::_getInstance($item["obj_id"], $this->getId());
00448                                         if (is_object($sc_object))
00449                                         {
00450                                                 $sc_object->delete();
00451                                         }
00452                                 }
00453                                 $sc_tree->removeTree($sc_tree->getTreeId());
00454                         }
00455                 }
00456 
00457                 if ($this->getSubType() != "scorm")
00458                 {
00459                         // delete aicc data
00460                         // this is highly dependent on the database
00461                         $q = "DELETE FROM aicc_units USING aicc_object, aicc_units WHERE aicc_object.obj_id=aicc_units.obj_id and aicc_object.slm_id=".$ilDB->quote($this->getId());
00462                         $this->ilias->db->query($q);
00463         
00464                         $q = "DELETE FROM aicc_course USING aicc_object, aicc_course WHERE aicc_object.obj_id=aicc_course.obj_id and aicc_object.slm_id=".$ilDB->quote($this->getId());
00465                         $this->ilias->db->query($q);
00466         
00467                         $q = "DELETE FROM aicc_object WHERE slm_id = ".$ilDB->quote($this->getId());
00468                         $this->ilias->db->query($q);
00469                 }
00470 
00471                 $q = "DELETE FROM scorm_tracking WHERE obj_id = ".$ilDB->quote($this->getId());
00472 $ilLog->write("SAHS Delete(SAHSLM): ".$q);
00473                 $this->ilias->db->query($q);
00474 
00475                 // always call parent delete function at the end!!
00476                 return true;
00477         }
00478 
00489         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00490         {
00491                 global $tree;
00492 
00493                 switch ($a_event)
00494                 {
00495                         case "link":
00496 
00497                                 //var_dump("<pre>",$a_params,"</pre>");
00498                                 //echo "SCORMLearningModule ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
00499                                 //exit;
00500                                 break;
00501 
00502                         case "cut":
00503 
00504                                 //echo "SCORMLearningModule ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
00505                                 //exit;
00506                                 break;
00507 
00508                         case "copy":
00509 
00510                                 //var_dump("<pre>",$a_params,"</pre>");
00511                                 //echo "SCORMLearningModule ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
00512                                 //exit;
00513                                 break;
00514 
00515                         case "paste":
00516 
00517                                 //echo "SCORMLearningModule ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
00518                                 //exit;
00519                                 break;
00520 
00521                         case "new":
00522 
00523                                 //echo "SCORMLearningModule ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
00524                                 //exit;
00525                                 break;
00526                 }
00527 
00528                 // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
00529                 if ($a_node_id==$_GET["ref_id"])
00530                 {
00531                         $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00532                         $parent_type = $parent_obj->getType();
00533                         if($parent_type == $this->getType())
00534                         {
00535                                 $a_node_id = (int) $tree->getParentId($a_node_id);
00536                         }
00537                 }
00538 
00539                 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
00540         }
00541 
00542 } // END class.ilObjSCORMLearningModule
00543 ?>

Generated on Fri Dec 13 2013 17:56:52 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1