ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSAHSLearningModule.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "classes/class.ilObject.php";
6 require_once "./Modules/ScormAicc/classes/class.ilObjSCORMValidator.php";
7 //require_once "Services/MetaData/classes/class.ilMDLanguageItem.php";
8 
21 {
23 // var $meta_data;
24 
31  function ilObjSAHSLearningModule($a_id = 0, $a_call_by_reference = true)
32  {
33  $this->type = "sahs";
34  parent::ilObject($a_id,$a_call_by_reference);
35  }
36 
40  function create($upload=false)
41  {
42  global $ilDB;
43 
45  if(!$upload)
46  $this->createMetaData();
47 
48  $this->createDataDirectory();
49 
50  $ilDB->manipulateF('
51  INSERT INTO sahs_lm (id, c_online, api_adapter, c_type, editable, seq_exp_mode,localization)
52  VALUES (%s,%s,%s,%s,%s,%s,%s)',
53  array('integer', 'text', 'text', 'text', 'integer','integer','text'),
54  array($this->getId(),'n','API', $this->getSubType(),(int)$this->getEditable(),
55  (int)$this->getSequencingExpertMode(), $this->getLocalization()
56  ));
57  }
58 
62  function read()
63  {
64  global $ilDB;
65 
66  parent::read();
67 
68  $lm_set = $ilDB->queryF('SELECT * FROM sahs_lm WHERE id = %s',
69  array('integer'),array($this->getId()));
70 
71  while($lm_rec = $ilDB->fetchAssoc($lm_set))
72  {
73  $this->setOnline(ilUtil::yn2tf($lm_rec["c_online"]));
74  $this->setAutoReview(ilUtil::yn2tf($lm_rec["auto_review"]));
75  $this->setAPIAdapterName($lm_rec["api_adapter"]);
76  $this->setDefaultLessonMode($lm_rec["default_lesson_mode"]);
77  $this->setAPIFunctionsPrefix($lm_rec["api_func_prefix"]);
78  $this->setCreditMode($lm_rec["credit"]);
79  $this->setSubType($lm_rec["c_type"]);
80  $this->setEditable($lm_rec["editable"]);
81  $this->setStyleSheetId($lm_rec["stylesheet"]);
82  $this->setMaxAttempt($lm_rec["max_attempt"]);
83  $this->setModuleVersion($lm_rec["module_version"]);
84  $this->setAssignedGlossary($lm_rec["glossary"]);
85  $this->setTries($lm_rec["question_tries"]);
86  $this->setLocalization($lm_rec["localization"]);
87  $this->setSession(ilUtil::yn2tf($lm_rec["unlimited_session"]));
88  $this->setNoMenu(ilUtil::yn2tf($lm_rec["no_menu"]));
89  $this->setHideNavig(ilUtil::yn2tf($lm_rec["hide_navig"]));
90  $this->setSequencing(ilUtil::yn2tf($lm_rec["sequencing"]));
91  $this->setInteractions(ilUtil::yn2tf($lm_rec["interactions"]));
92  $this->setObjectives(ilUtil::yn2tf($lm_rec["objectives"]));
93  $this->setComments(ilUtil::yn2tf($lm_rec["comments"]));
94  $this->setTime_from_lms(ilUtil::yn2tf($lm_rec["time_from_lms"]));
95  $this->setDebug(ilUtil::yn2tf($lm_rec["debug"]));
96  $this->setDebugPw($lm_rec["debugpw"]);
97  $this->setSequencingExpertMode($lm_rec["seq_exp_mode"]);
98  $this->setOpenMode($lm_rec["open_mode"]);
99  $this->setWidth($lm_rec["width"]);
100  $this->setHeight($lm_rec["height"]);
101  $this->setAutoContinue(ilUtil::yn2tf($lm_rec["auto_continue"]));
102  }
103  }
104 
108  function _lookupOnline($a_id)
109  {
110  global $ilDB;
111 
112  $lm_set = $ilDB->queryF('SELECT c_online FROM sahs_lm WHERE id = %s',
113  array('integer'), array($a_id));
114  $lm_rec = $ilDB->fetchAssoc($lm_set);
115 
116  return ilUtil::yn2tf($lm_rec["c_online"]);
117  }
118 
124  function getAffectiveLocalization($a_id)
125  {
126  global $ilDB, $lng;
127 
128  $lm_set = $ilDB->queryF('SELECT localization FROM sahs_lm WHERE id = %s',
129  array('integer'), array($a_id));
130  $lm_rec = $ilDB->fetchAssoc($lm_set);
131  $inst_lang = $lng->getInstalledLanguages();
132  if ($lm_rec["localization"] != "" && in_array($lm_rec["localization"], $inst_lang))
133  {
134  return $lm_rec["localization"];
135  }
136  return $lng->getLangKey();
137  }
138 
144  function _lookupSubType($a_obj_id)
145  {
146  global $ilDB;
147 
148  $obj_set = $ilDB->queryF('SELECT c_type FROM sahs_lm WHERE id = %s',
149  array('integer'), array($a_obj_id));
150  $obj_rec = $ilDB->fetchAssoc($obj_set);
151 
152  return $obj_rec["c_type"];
153  }
154 
160  function setEditable($a_editable)
161  {
162  $this->editable = $a_editable;
163  }
164 
170  function getEditable()
171  {
172  return $this->editable;
173  }
174 
175 
181  function setTries($a_tries)
182  {
183  $this->tries = $a_tries;
184  }
185 
191  function getTries()
192  {
193  return $this->tries;
194  }
195 
201  function setLocalization($a_val)
202  {
203  $this->localization = $a_val;
204  }
205 
211  function getLocalization()
212  {
213  return $this->localization;
214  }
215 
216  static function _getTries($a_id)
217  {
218  global $ilDB;
219 
220  $lm_set = $ilDB->queryF('SELECT question_tries FROM sahs_lm WHERE id = %s',
221  array('integer'), array($a_id));
222  $lm_rec = $ilDB->fetchAssoc($lm_set);
223 
224  return $lm_rec['question_tries'];
225  }
232  function getDiskUsage()
233  {
234  require_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModuleAccess.php");
236  }
237 
238 
244  {
245  $lm_data_dir = ilUtil::getWebspaceDir()."/lm_data";
246  ilUtil::makeDir($lm_data_dir);
248  }
249 
253  function getDataDirectory($mode = "filesystem")
254  {
255  $lm_data_dir = ilUtil::getWebspaceDir($mode)."/lm_data";
256  $lm_dir = $lm_data_dir."/lm_".$this->getId();
257 
258  return $lm_dir;
259  }
260 
264  function getAPIAdapterName()
265  {
266  return $this->api_adapter;
267  }
268 
272  function setAPIAdapterName($a_api)
273  {
274  $this->api_adapter = $a_api;
275  }
276 
281  {
282  return $this->api_func_prefix;
283  }
284 
288  function setAPIFunctionsPrefix($a_prefix)
289  {
290  $this->api_func_prefix = $a_prefix;
291  }
292 
296  function getCreditMode()
297  {
298  return $this->credit_mode;
299  }
300 
304  function setCreditMode($a_credit_mode)
305  {
306  $this->credit_mode = $a_credit_mode;
307  }
308 
312  function setDefaultLessonMode($a_lesson_mode)
313  {
314  $this->lesson_mode = $a_lesson_mode;
315  }
316 
321  {
322  return $this->lesson_mode;
323  }
327  function getStyleSheetId()
328  {
329  return $this->style_id;
330  }
331 
335  function setStyleSheetId($a_style_id)
336  {
337  $this->style_id = $a_style_id;
338  }
339 
340 
344  function setAutoReview($a_auto_review)
345  {
346  $this->auto_review = $a_auto_review;
347  }
351  function getAutoReview()
352  {
353  return $this->auto_review;
354  }
355 
356 
360  function getMaxAttempt()
361  {
362  return $this->max_attempt;
363  }
364 
365 
369  function setMaxAttempt($a_max_attempt)
370  {
371  $this->max_attempt = $a_max_attempt;
372  }
373 
377  function getModuleVersion()
378  {
379  return $this->module_version;
380  }
381 
386  {
387  return $this->assigned_glossary;
388  }
389 
393  function setAssignedGlossary($a_assigned_glossary)
394  {
395  $this->assigned_glossary = $a_assigned_glossary;
396  }
400  function setModuleVersion($a_module_version)
401  {
402  $this->module_version = $a_module_version;
403  }
404 
408  function getSession()
409  {
410  return $this->session;
411  }
412 
416  function setSession($a_session)
417  {
418  $this->session = $a_session;
419  }
420 
424  function getNoMenu()
425  {
426  return $this->no_menu;
427  }
428 
432  function setNoMenu($a_no_menu)
433  {
434  $this->no_menu = $a_no_menu;
435  }
436 
440  function getHideNavig()
441  {
442  return $this->hide_navig;
443  }
444 
448  function setHideNavig($a_hide_navig)
449  {
450  $this->hide_navig = $a_hide_navig;
451  }
452 
457  {
458  global $ilSetting;
459  $lm_set = new ilSetting("lm");
460  if ($lm_set->get("scormdebug_disable_cache") == "1") return true;
461  return false;
462  }
463 
467  function getDebugActivated()
468  {
469  global $ilSetting;
470  $lm_set = new ilSetting("lm");
471  if ($lm_set->get("scormdebug_global_activate") == "1") return true;
472  return false;
473  }
474 
478  function getSequencing()
479  {
480  return $this->sequencing;
481  }
482 
483  function setSequencing($a_sequencing)
484  {
485  $this->sequencing = $a_sequencing;
486  }
487 
491  function getInteractions()
492  {
493  return $this->interactions;
494  }
495 
496  function setInteractions($a_interactions)
497  {
498  $this->interactions = $a_interactions;
499  }
500 
504  function getObjectives()
505  {
506  return $this->objectives;
507  }
508 
509  function setObjectives($a_objectives)
510  {
511  $this->objectives = $a_objectives;
512  }
513 
517  function getComments()
518  {
519  return $this->comments;
520  }
521 
522  function setComments($a_comments)
523  {
524  $this->comments = $a_comments;
525  }
526 
530  function getTime_from_lms()
531  {
532  return $this->time_from_lms;
533  }
534 
535  function setTime_from_lms($a_time_from_lms)
536  {
537  $this->time_from_lms = $a_time_from_lms;
538  }
539 
540 
544  function getDebug()
545  {
546  return $this->debug;
547  }
548 
552  function setDebug($a_debug)
553  {
554  $this->debug = $a_debug;
555  }
556 
560  function getDebugPw()
561  {
562  return $this->debug_pw;
563  }
564 
568  function setDebugPw($a_debug_pw)
569  {
570  $this->debug_pw = $a_debug_pw;
571  }
572 
576  function setAutoContinue($a_auto_continue)
577  {
578  $this->auto_continue = $a_auto_continue;
579  }
583  function getAutoContinue()
584  {
585  return $this->auto_continue;
586  }
587 
588 
594  function setSequencingExpertMode($a_val)
595  {
596  $this->seq_exp_mode = $a_val;
597  }
598 
605  {
606  return $this->seq_exp_mode;
607  }
608 
609 
620  function getOpenMode()
621  {
622  return $this->open_mode;
623  }
624  function setOpenMode($a_open_mode)
625  {
626  $this->open_mode = $a_open_mode;
627  }
628 
632  function getWidth()
633  {
634  return $this->width;
635  }
636  function setWidth($a_width)
637  {
638  $this->width = $a_width;
639  }
640 
644  function getHeight()
645  {
646  return $this->height;
647  }
648  function setHeight($a_height)
649  {
650  $this->height = $a_height;
651  }
652 
653 
657 /*
658  function updateMetaData()
659  {
660  $this->meta_data->update();
661  if ($this->meta_data->section != "General")
662  {
663  $meta = $this->meta_data->getElement("Title", "General");
664  $this->meta_data->setTitle($meta[0]["value"]);
665  $meta = $this->meta_data->getElement("Description", "General");
666  $this->meta_data->setDescription($meta[0]["value"]);
667  }
668  else
669  {
670  $this->setTitle($this->meta_data->getTitle());
671  $this->setDescription($this->meta_data->getDescription());
672  }
673  parent::update();
674 
675  }
676 */
677 
678 
685  function update()
686  {
687  global $ilDB;
688 
689  $this->updateMetaData();
690  parent::update();
691 
692  $statement = $ilDB->manipulateF('
693  UPDATE sahs_lm
694  SET c_online = %s,
695  api_adapter = %s,
696  api_func_prefix = %s,
697  auto_review = %s,
698  default_lesson_mode = %s,
699  c_type = %s,
700  stylesheet = %s,
701  editable = %s,
702  max_attempt = %s,
703  module_version = %s,
704  credit = %s,
705  glossary = %s,
706  question_tries = %s,
707  unlimited_session = %s,
708  no_menu = %s,
709  hide_navig = %s,
710  sequencing = %s,
711  interactions = %s,
712  objectives = %s,
713  comments = %s,
714  time_from_lms = %s,
715  debug = %s,
716  localization = %s,
717  seq_exp_mode = %s,
718  debugpw = %s,
719  open_mode = %s,
720  width = %s,
721  height = %s,
722  auto_continue = %s
723  WHERE id = %s',
724  array( 'text',
725  'text',
726  'text',
727  'text',
728  'text',
729  'text',
730  'integer',
731  'integer',
732  'integer',
733  'integer',
734  'text',
735  'integer',
736  'integer',
737  'text',
738  'text',
739  'text',
740  'text',
741  'text',
742  'text',
743  'text',
744  'text',
745  'text',
746  'text',
747  'integer',
748  'text',
749  'integer',
750  'integer',
751  'integer',
752  'text',
753  'integer'
754  ),
755  array( ilUtil::tf2yn($this->getOnline()),
756  $this->getAPIAdapterName(),
757  $this->getAPIFunctionsPrefix(),
758  ilUtil::tf2yn($this->getAutoReview()),
759  $this->getDefaultLessonMode(),
760  $this->getSubType(),
761  $this->getStyleSheetId(),
762  $this->getEditable(),
763  $this->getMaxAttempt(),
764  $this->getModuleVersion(),
765  $this->getCreditMode(),
766  $this->getAssignedGlossary(),
767  $this->getTries(),
768  ilUtil::tf2yn($this->getSession()),
769  ilUtil::tf2yn($this->getNoMenu()),
770  ilUtil::tf2yn($this->getHideNavig()),
771  ilUtil::tf2yn($this->getSequencing()),
772  ilUtil::tf2yn($this->getInteractions()),
773  ilUtil::tf2yn($this->getObjectives()),
774  ilUtil::tf2yn($this->getComments()),
776  ilUtil::tf2yn($this->getDebug()),
777  $this->getLocalization(),
778  $this->getSequencingExpertMode(),
779  $this->getDebugPw(),
780  $this->getOpenMode(),
781  $this->getWidth(),
782  $this->getHeight(),
783  ilUtil::tf2yn($this->getAutoContinue()),
784  $this->getId())
785  );
786 
787  return true;
788  }
789 
796  static function getScormModulesForGlossary($a_glo_id)
797  {
798  global $ilDB;
799 
800  $set = $ilDB->query("SELECT DISTINCT id FROM sahs_lm WHERE ".
801  " glossary = ".$ilDB->quote($a_glo_id, "integer"));
802  $sms = array();
803  while ($rec = $ilDB->fetchAssoc($set))
804  {
805  if (ilObject::_hasUntrashedReference($rec["id"]))
806  {
807  $sms[] = $rec["id"];
808  }
809  }
810  return $sms;
811  }
812 
816  function setOnline($a_online)
817  {
818  $this->online = $a_online;
819  }
820 
824  function getOnline()
825  {
826  return $this->online;
827  }
828 
832  function setSubType($a_sub_type)
833  {
834  $this->sub_type = $a_sub_type;
835  }
836 
840  function getSubType()
841  {
842  return $this->sub_type;
843  }
844 
856  function delete()
857  {
858  global $ilDB, $ilLog;
859 
860  // always call parent delete function first!!
861  if (!parent::delete())
862  {
863  return false;
864  }
865 
866  // delete meta data of scorm content object
867 /*
868  $nested = new ilNestedSetXML();
869  $nested->init($this->getId(), $this->getType());
870  $nested->deleteAllDBData();
871 */
872  $this->deleteMetaData();
873 
874  // delete data directory
876 
877  // delete scorm learning module record
878  $ilDB->manipulateF('DELETE FROM sahs_lm WHERE id = %s',
879  array('integer'), array($this->getId()));
880 
881  $ilLog->write("SAHS Delete(SAHSLM), Subtype: ".$this->getSubType());
882 
883  if ($this->getSubType() == "scorm")
884  {
885  // remove all scorm objects and scorm tree
886  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMTree.php");
887  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMObject.php");
888  $sc_tree = new ilSCORMTree($this->getId());
889  $r_id = $sc_tree->readRootId();
890  if ($r_id > 0)
891  {
892  $items = $sc_tree->getSubTree($sc_tree->getNodeData($r_id));
893  foreach($items as $item)
894  {
895  $sc_object =& ilSCORMObject::_getInstance($item["obj_id"], $this->getId());
896  if (is_object($sc_object))
897  {
898  $sc_object->delete();
899  }
900  }
901  $sc_tree->removeTree($sc_tree->getTreeId());
902  }
903  }
904 
905  if ($this->getSubType() != "scorm")
906  {
907  // delete aicc data
908  $res = $ilDB->queryF('
909  SELECT aicc_object.obj_id FROM aicc_object, aicc_units
910  WHERE aicc_object.obj_id = aicc_units.obj_id
911  AND aicc_object.slm_id = %s',
912  array('integer'), array($this->getId()));
913 
914  while($row = $ilDB->fetchAssoc($res))
915  {
916  $obj_id = $row['obj_id'];
917  $ilDB->manipulateF('
918  DELETE FROM aicc_units WHERE obj_id = %s',
919  array('integer'), array($obj_id));
920  }
921 
922  $res = $ilDB->queryF('
923  SELECT aicc_object.obj_id FROM aicc_object, aicc_course
924  WHERE aicc_object.obj_id = aicc_course.obj_id
925  AND aicc_object.slm_id = %s',
926  array('integer'), array($this->getId()));
927 
928  while($row = $ilDB->fetchAssoc($res))
929  {
930  $obj_id = $row['obj_id'];
931  $ilDB->manipulateF('
932  DELETE FROM aicc_course WHERE obj_id = %s',
933  array('integer'), array($obj_id));
934  }
935 
936  $ilDB->manipulateF('
937  DELETE FROM aicc_object WHERE slm_id = %s',
938  array('integer'), array($this->getId()));
939  }
940 
941  $q_log = "DELETE FROM scorm_tracking WHERE obj_id = ".$ilDB->quote($this->getId());
942  $ilLog->write("SAHS Delete(SAHSLM): ".$q_log);
943 
944  $ilDB->manipulateF('DELETE FROM scorm_tracking WHERE obj_id = %s',
945  array('integer'), array($this->getId()));
946 
947  // always call parent delete function at the end!!
948  return true;
949  }
950 
961  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
962  {
963  global $tree;
964 
965  switch ($a_event)
966  {
967  case "link":
968 
969  //var_dump("<pre>",$a_params,"</pre>");
970  //echo "SCORMLearningModule ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
971  //exit;
972  break;
973 
974  case "cut":
975 
976  //echo "SCORMLearningModule ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
977  //exit;
978  break;
979 
980  case "copy":
981 
982  //var_dump("<pre>",$a_params,"</pre>");
983  //echo "SCORMLearningModule ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
984  //exit;
985  break;
986 
987  case "paste":
988 
989  //echo "SCORMLearningModule ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
990  //exit;
991  break;
992 
993  case "new":
994 
995  //echo "SCORMLearningModule ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
996  //exit;
997  break;
998  }
999 
1000  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
1001  if ($a_node_id==$_GET["ref_id"])
1002  {
1003  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1004  $parent_type = $parent_obj->getType();
1005  if($parent_type == $this->getType())
1006  {
1007  $a_node_id = (int) $tree->getParentId($a_node_id);
1008  }
1009  }
1010 
1011  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
1012  }
1013 
1019  public function getPointsInPercent()
1020  {
1021  global $ilUser;
1022  if (strcmp($this->getSubType(), "scorm2004") == 0)
1023  {
1025  if (!is_null($res))
1026  {
1027  return $res * 100.0;
1028  }
1029  else
1030  {
1031  return $res;
1032  }
1033  }
1034  else
1035  {
1036  return null;
1037  }
1038  }
1039 
1050  public function getMaxPoints()
1051  {
1052  global $ilUser;
1053 
1054  if(strcmp($this->getSubType(), 'scorm2004') == 0)
1055  {
1056  $res = ilObjSCORM2004LearningModule::_getMaxScoreForUser($this->getId(), $ilUser->getId());
1057  return $res;
1058  }
1059  else
1060  {
1061  return null;
1062  }
1063  }
1064 } // END class.ilObjSCORMLearningModule
1065 ?>