ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSAHSLearningModule.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 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 
24 
25 require_once "classes/class.ilObject.php";
26 require_once "./Modules/ScormAicc/classes/class.ilObjSCORMValidator.php";
27 //require_once "Services/MetaData/classes/class.ilMDLanguageItem.php";
28 
41 {
43 // var $meta_data;
44 
51  function ilObjSAHSLearningModule($a_id = 0, $a_call_by_reference = true)
52  {
53  $this->type = "sahs";
54  parent::ilObject($a_id,$a_call_by_reference);
55  }
56 
60  function create()
61  {
62  global $ilDB;
63 
65  $this->createMetaData();
66 
67  $this->createDataDirectory();
68 
69  $ilDB->manipulateF('
70  INSERT INTO sahs_lm (id, c_online, api_adapter, c_type, editable)
71  VALUES (%s,%s,%s,%s,%s)',
72  array('integer', 'text', 'text', 'text', 'integer'),
73  array($this->getId(),'n','API', $this->getSubType(),(int)$this->getEditable()));
74  }
75 
79  function read()
80  {
81  global $ilDB;
82 
83  parent::read();
84 
85  $lm_set = $ilDB->queryF('SELECT * FROM sahs_lm WHERE id = %s',
86  array('integer'),array($this->getId()));
87 
88  while($lm_rec = $ilDB->fetchAssoc($lm_set))
89  {
90  $this->setOnline(ilUtil::yn2tf($lm_rec["c_online"]));
91  $this->setAutoReview(ilUtil::yn2tf($lm_rec["auto_review"]));
92  $this->setAPIAdapterName($lm_rec["api_adapter"]);
93  $this->setDefaultLessonMode($lm_rec["default_lesson_mode"]);
94  $this->setAPIFunctionsPrefix($lm_rec["api_func_prefix"]);
95  $this->setCreditMode($lm_rec["credit"]);
96  $this->setSubType($lm_rec["c_type"]);
97  $this->setEditable($lm_rec["editable"]);
98  $this->setStyleSheetId($lm_rec["stylesheet"]);
99  $this->setMaxAttempt($lm_rec["max_attempt"]);
100  $this->setModuleVersion($lm_rec["module_version"]);
101  $this->setAssignedGlossary($lm_rec["glossary"]);
102  $this->setTries($lm_rec["question_tries"]);
103  $this->setSession(ilUtil::yn2tf($lm_rec["unlimited_session"]));
104  $this->setNoMenu(ilUtil::yn2tf($lm_rec["no_menu"]));
105  $this->setHideNavig(ilUtil::yn2tf($lm_rec["hide_navig"]));
106  $this->setDebug(ilUtil::yn2tf($lm_rec["debug"]));
107  $this->setDebugPw($lm_rec["debugpw"]);
108  }
109  }
110 
114  function _lookupOnline($a_id)
115  {
116  global $ilDB;
117 
118  $lm_set = $ilDB->queryF('SELECT c_online FROM sahs_lm WHERE id = %s',
119  array('integer'), array($a_id));
120  $lm_rec = $ilDB->fetchAssoc($lm_set);
121 
122  return ilUtil::yn2tf($lm_rec["c_online"]);
123  }
124 
130  function _lookupSubType($a_obj_id)
131  {
132  global $ilDB;
133 
134  $obj_set = $ilDB->queryF('SELECT c_type FROM sahs_lm WHERE id = %s',
135  array('integer'), array($a_obj_id));
136  $obj_rec = $ilDB->fetchAssoc($obj_set);
137 
138  return $obj_rec["c_type"];
139  }
140 
146  function setEditable($a_editable)
147  {
148  $this->editable = $a_editable;
149  }
150 
156  function getEditable()
157  {
158  return $this->editable;
159  }
160 
161 
167  function setTries($a_tries)
168  {
169  $this->tries = $a_tries;
170  }
171 
177  function getTries()
178  {
179  return $this->tries;
180  }
181 
182  static function _getTries($a_id)
183  {
184  global $ilDB;
185 
186  $lm_set = $ilDB->queryF('SELECT question_tries FROM sahs_lm WHERE id = %s',
187  array('integer'), array($a_id));
188  $lm_rec = $ilDB->fetchAssoc($lm_set);
189 
190  return $lm_rec['question_tries'];
191  }
198  function getDiskUsage()
199  {
200  require_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModuleAccess.php");
202  }
203 
204 
210  {
211  $lm_data_dir = ilUtil::getWebspaceDir()."/lm_data";
212  ilUtil::makeDir($lm_data_dir);
214  }
215 
219  function getDataDirectory($mode = "filesystem")
220  {
221  $lm_data_dir = ilUtil::getWebspaceDir($mode)."/lm_data";
222  $lm_dir = $lm_data_dir."/lm_".$this->getId();
223 
224  return $lm_dir;
225  }
226 
230  function getAPIAdapterName()
231  {
232  return $this->api_adapter;
233  }
234 
238  function setAPIAdapterName($a_api)
239  {
240  $this->api_adapter = $a_api;
241  }
242 
247  {
248  return $this->api_func_prefix;
249  }
250 
254  function setAPIFunctionsPrefix($a_prefix)
255  {
256  $this->api_func_prefix = $a_prefix;
257  }
258 
262  function getCreditMode()
263  {
264  return $this->credit_mode;
265  }
266 
270  function setCreditMode($a_credit_mode)
271  {
272  $this->credit_mode = $a_credit_mode;
273  }
274 
278  function setDefaultLessonMode($a_lesson_mode)
279  {
280  $this->lesson_mode = $a_lesson_mode;
281  }
282 
287  {
288  return $this->lesson_mode;
289  }
293  function getStyleSheetId()
294  {
295  return $this->style_id;
296  }
297 
301  function setStyleSheetId($a_style_id)
302  {
303  $this->style_id = $a_style_id;
304  }
305 
306 
310  function setAutoReview($a_auto_review)
311  {
312  $this->auto_review = $a_auto_review;
313  }
317  function getAutoReview()
318  {
319  return $this->auto_review;
320  }
321 
322 
326  function getMaxAttempt()
327  {
328  return $this->max_attempt;
329  }
330 
331 
335  function setMaxAttempt($a_max_attempt)
336  {
337  $this->max_attempt = $a_max_attempt;
338  }
339 
343  function getModuleVersion()
344  {
345  return $this->module_version;
346  }
347 
352  {
353  return $this->assigned_glossary;
354  }
355 
359  function setAssignedGlossary($a_assigned_glossary)
360  {
361  $this->assigned_glossary = $a_assigned_glossary;
362  }
366  function setModuleVersion($a_module_version)
367  {
368  $this->module_version = $a_module_version;
369  }
370 
374  function getSession()
375  {
376  return $this->session;
377  }
378 
382  function setSession($a_session)
383  {
384  $this->session = $a_session;
385  }
386 
390  function getNoMenu()
391  {
392  return $this->no_menu;
393  }
394 
398  function setNoMenu($a_no_menu)
399  {
400  $this->no_menu = $a_no_menu;
401  }
402 
406  function getHideNavig()
407  {
408  return $this->hide_navig;
409  }
410 
414  function setHideNavig($a_hide_navig)
415  {
416  $this->hide_navig = $a_hide_navig;
417  }
418 
419 
423  function getDebug()
424  {
425  return $this->debug;
426  }
427 
431  function setDebug($a_debug)
432  {
433  $this->debug = $a_debug;
434  }
435 
439  function getDebugPw()
440  {
441  return $this->debug_pw;
442  }
443 
447  function setDebugPw($a_debug_pw)
448  {
449  $this->debug_pw = $a_debug_pw;
450  }
451 
455 /*
456  function updateMetaData()
457  {
458  $this->meta_data->update();
459  if ($this->meta_data->section != "General")
460  {
461  $meta = $this->meta_data->getElement("Title", "General");
462  $this->meta_data->setTitle($meta[0]["value"]);
463  $meta = $this->meta_data->getElement("Description", "General");
464  $this->meta_data->setDescription($meta[0]["value"]);
465  }
466  else
467  {
468  $this->setTitle($this->meta_data->getTitle());
469  $this->setDescription($this->meta_data->getDescription());
470  }
471  parent::update();
472 
473  }
474 */
475 
476 
483  function update()
484  {
485  global $ilDB;
486 
487  $this->updateMetaData();
488  parent::update();
489 
490  $statement = $ilDB->manipulateF('
491  UPDATE sahs_lm
492  SET c_online = %s,
493  api_adapter = %s,
494  api_func_prefix = %s,
495  auto_review = %s,
496  default_lesson_mode = %s,
497  c_type = %s,
498  stylesheet = %s,
499  editable = %s,
500  max_attempt = %s,
501  module_version = %s,
502  credit = %s,
503  glossary = %s,
504  question_tries = %s,
505  unlimited_session = %s,
506  no_menu = %s,
507  hide_navig = %s,
508  debug = %s,
509  debugpw = %s
510 
511  WHERE id = %s',
512  array( 'text',
513  'text',
514  'text',
515  'text',
516  'text',
517  'text',
518  'integer',
519  'integer',
520  'integer',
521  'integer',
522  'text',
523  'integer',
524  'integer',
525  'text',
526  'text',
527  'text',
528  'text',
529  'text',
530  'integer'
531  ),
532  array( ilUtil::tf2yn($this->getOnline()),
533  $this->getAPIAdapterName(),
534  $this->getAPIFunctionsPrefix(),
535  ilUtil::tf2yn($this->getAutoReview()),
536  $this->getDefaultLessonMode(),
537  $this->getSubType(),
538  $this->getStyleSheetId(),
539  $this->getEditable(),
540  $this->getMaxAttempt(),
541  $this->getModuleVersion(),
542  $this->getCreditMode(),
543  $this->getAssignedGlossary(),
544  $this->getTries(),
545  ilUtil::tf2yn($this->getSession()),
546  ilUtil::tf2yn($this->getNoMenu()),
547  ilUtil::tf2yn($this->getHideNavig()),
548  ilUtil::tf2yn($this->getDebug()),
549  $this->getDebugPw(),
550  $this->getId())
551  );
552 
553  return true;
554  }
555 
559  function setOnline($a_online)
560  {
561  $this->online = $a_online;
562  }
563 
567  function getOnline()
568  {
569  return $this->online;
570  }
571 
575  function setSubType($a_sub_type)
576  {
577  $this->sub_type = $a_sub_type;
578  }
579 
583  function getSubType()
584  {
585  return $this->sub_type;
586  }
587 
599  function delete()
600  {
601  global $ilDB, $ilLog;
602 
603  // always call parent delete function first!!
604  if (!parent::delete())
605  {
606  return false;
607  }
608 
609  // delete meta data of scorm content object
610 /*
611  $nested = new ilNestedSetXML();
612  $nested->init($this->getId(), $this->getType());
613  $nested->deleteAllDBData();
614 */
615  $this->deleteMetaData();
616 
617  // delete data directory
619 
620  // delete scorm learning module record
621  $ilDB->manipulateF('DELETE FROM sahs_lm WHERE id = %s',
622  array('integer'), array($this->getId()));
623 
624  $ilLog->write("SAHS Delete(SAHSLM), Subtype: ".$this->getSubType());
625 
626  if ($this->getSubType() == "scorm")
627  {
628  // remove all scorm objects and scorm tree
629  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMTree.php");
630  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMObject.php");
631  $sc_tree = new ilSCORMTree($this->getId());
632  $r_id = $sc_tree->readRootId();
633  if ($r_id > 0)
634  {
635  $items = $sc_tree->getSubTree($sc_tree->getNodeData($r_id));
636  foreach($items as $item)
637  {
638  $sc_object =& ilSCORMObject::_getInstance($item["obj_id"], $this->getId());
639  if (is_object($sc_object))
640  {
641  $sc_object->delete();
642  }
643  }
644  $sc_tree->removeTree($sc_tree->getTreeId());
645  }
646  }
647 
648  if ($this->getSubType() != "scorm")
649  {
650  // delete aicc data
651  $res = $ilDB->queryF('
652  SELECT aicc_object.obj_id FROM aicc_object, aicc_units
653  WHERE aicc_object.obj_id = aicc_units.obj_id
654  AND aicc_object.slm_id = %s',
655  array('integer'), array($this->getId()));
656 
657  while($row = $ilDB->fetchAssoc($res))
658  {
659  $obj_id = $row['obj_id'];
660  $ilDB->manipulateF('
661  DELETE FROM aicc_units WHERE obj_id = %s',
662  array('integer'), array($obj_id));
663  }
664 
665  $res = $ilDB->queryF('
666  SELECT aicc_object.obj_id FROM aicc_object, aicc_course
667  WHERE aicc_object.obj_id = aicc_course.obj_id
668  AND aicc_object.slm_id = %s',
669  array('integer'), array($this->getId()));
670 
671  while($row = $ilDB->fetchAssoc($res))
672  {
673  $obj_id = $row['obj_id'];
674  $ilDB->manipulateF('
675  DELETE FROM aicc_course WHERE obj_id = %s',
676  array('integer'), array($obj_id));
677  }
678 
679  $ilDB->manipulateF('
680  DELETE FROM aicc_object WHERE slm_id = %s',
681  array('integer'), array($this->getId()));
682  }
683 
684  $q_log = "DELETE FROM scorm_tracking WHERE obj_id = ".$ilDB->quote($this->getId());
685  $ilLog->write("SAHS Delete(SAHSLM): ".$q_log);
686 
687  $ilDB->manipulateF('DELETE FROM scorm_tracking WHERE obj_id = %s',
688  array('integer'), array($this->getId()));
689 
690  // always call parent delete function at the end!!
691  return true;
692  }
693 
704  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
705  {
706  global $tree;
707 
708  switch ($a_event)
709  {
710  case "link":
711 
712  //var_dump("<pre>",$a_params,"</pre>");
713  //echo "SCORMLearningModule ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
714  //exit;
715  break;
716 
717  case "cut":
718 
719  //echo "SCORMLearningModule ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
720  //exit;
721  break;
722 
723  case "copy":
724 
725  //var_dump("<pre>",$a_params,"</pre>");
726  //echo "SCORMLearningModule ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
727  //exit;
728  break;
729 
730  case "paste":
731 
732  //echo "SCORMLearningModule ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
733  //exit;
734  break;
735 
736  case "new":
737 
738  //echo "SCORMLearningModule ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
739  //exit;
740  break;
741  }
742 
743  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
744  if ($a_node_id==$_GET["ref_id"])
745  {
746  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
747  $parent_type = $parent_obj->getType();
748  if($parent_type == $this->getType())
749  {
750  $a_node_id = (int) $tree->getParentId($a_node_id);
751  }
752  }
753 
754  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
755  }
756 
762  public function getPointsInPercent()
763  {
764  global $ilUser;
765  if (strcmp($this->getSubType(), "scorm2004") == 0)
766  {
768  if (!is_null($res))
769  {
770  return $res * 100.0;
771  }
772  else
773  {
774  return $res;
775  }
776  }
777  else
778  {
779  return null;
780  }
781  }
782 
783 } // END class.ilObjSCORMLearningModule
784 ?>