ILIAS  Release_4_1_x_branch Revision 61804
 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($upload=false)
61  {
62  global $ilDB;
63 
65  if(!$upload)
66  $this->createMetaData();
67 
68  $this->createDataDirectory();
69 
70  $ilDB->manipulateF('
71  INSERT INTO sahs_lm (id, c_online, api_adapter, c_type, editable)
72  VALUES (%s,%s,%s,%s,%s)',
73  array('integer', 'text', 'text', 'text', 'integer'),
74  array($this->getId(),'n','API', $this->getSubType(),(int)$this->getEditable()));
75  }
76 
80  function read()
81  {
82  global $ilDB;
83 
84  parent::read();
85 
86  $lm_set = $ilDB->queryF('SELECT * FROM sahs_lm WHERE id = %s',
87  array('integer'),array($this->getId()));
88 
89  while($lm_rec = $ilDB->fetchAssoc($lm_set))
90  {
91  $this->setOnline(ilUtil::yn2tf($lm_rec["c_online"]));
92  $this->setAutoReview(ilUtil::yn2tf($lm_rec["auto_review"]));
93  $this->setAPIAdapterName($lm_rec["api_adapter"]);
94  $this->setDefaultLessonMode($lm_rec["default_lesson_mode"]);
95  $this->setAPIFunctionsPrefix($lm_rec["api_func_prefix"]);
96  $this->setCreditMode($lm_rec["credit"]);
97  $this->setSubType($lm_rec["c_type"]);
98  $this->setEditable($lm_rec["editable"]);
99  $this->setStyleSheetId($lm_rec["stylesheet"]);
100  $this->setMaxAttempt($lm_rec["max_attempt"]);
101  $this->setModuleVersion($lm_rec["module_version"]);
102  $this->setAssignedGlossary($lm_rec["glossary"]);
103  $this->setTries($lm_rec["question_tries"]);
104  $this->setSession(ilUtil::yn2tf($lm_rec["unlimited_session"]));
105  $this->setNoMenu(ilUtil::yn2tf($lm_rec["no_menu"]));
106  $this->setHideNavig(ilUtil::yn2tf($lm_rec["hide_navig"]));
107  $this->setDebug(ilUtil::yn2tf($lm_rec["debug"]));
108  $this->setDebugPw($lm_rec["debugpw"]);
109  $this->setAutoContinue(ilUtil::yn2tf($lm_rec["auto_continue"]));
110  }
111  }
112 
116  function _lookupOnline($a_id)
117  {
118  global $ilDB;
119 
120  $lm_set = $ilDB->queryF('SELECT c_online FROM sahs_lm WHERE id = %s',
121  array('integer'), array($a_id));
122  $lm_rec = $ilDB->fetchAssoc($lm_set);
123 
124  return ilUtil::yn2tf($lm_rec["c_online"]);
125  }
126 
132  function _lookupSubType($a_obj_id)
133  {
134  global $ilDB;
135 
136  $obj_set = $ilDB->queryF('SELECT c_type FROM sahs_lm WHERE id = %s',
137  array('integer'), array($a_obj_id));
138  $obj_rec = $ilDB->fetchAssoc($obj_set);
139 
140  return $obj_rec["c_type"];
141  }
142 
148  function setEditable($a_editable)
149  {
150  $this->editable = $a_editable;
151  }
152 
158  function getEditable()
159  {
160  return $this->editable;
161  }
162 
163 
169  function setTries($a_tries)
170  {
171  $this->tries = $a_tries;
172  }
173 
179  function getTries()
180  {
181  return $this->tries;
182  }
183 
184  static function _getTries($a_id)
185  {
186  global $ilDB;
187 
188  $lm_set = $ilDB->queryF('SELECT question_tries FROM sahs_lm WHERE id = %s',
189  array('integer'), array($a_id));
190  $lm_rec = $ilDB->fetchAssoc($lm_set);
191 
192  return $lm_rec['question_tries'];
193  }
200  function getDiskUsage()
201  {
202  require_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModuleAccess.php");
204  }
205 
206 
212  {
213  $lm_data_dir = ilUtil::getWebspaceDir()."/lm_data";
214  ilUtil::makeDir($lm_data_dir);
216  }
217 
221  function getDataDirectory($mode = "filesystem")
222  {
223  $lm_data_dir = ilUtil::getWebspaceDir($mode)."/lm_data";
224  $lm_dir = $lm_data_dir."/lm_".$this->getId();
225 
226  return $lm_dir;
227  }
228 
232  function getAPIAdapterName()
233  {
234  return $this->api_adapter;
235  }
236 
240  function setAPIAdapterName($a_api)
241  {
242  $this->api_adapter = $a_api;
243  }
244 
249  {
250  return $this->api_func_prefix;
251  }
252 
256  function setAPIFunctionsPrefix($a_prefix)
257  {
258  $this->api_func_prefix = $a_prefix;
259  }
260 
264  function getCreditMode()
265  {
266  return $this->credit_mode;
267  }
268 
272  function setCreditMode($a_credit_mode)
273  {
274  $this->credit_mode = $a_credit_mode;
275  }
276 
280  function setDefaultLessonMode($a_lesson_mode)
281  {
282  $this->lesson_mode = $a_lesson_mode;
283  }
284 
289  {
290  return $this->lesson_mode;
291  }
295  function getStyleSheetId()
296  {
297  return $this->style_id;
298  }
299 
303  function setStyleSheetId($a_style_id)
304  {
305  $this->style_id = $a_style_id;
306  }
307 
308 
312  function setAutoReview($a_auto_review)
313  {
314  $this->auto_review = $a_auto_review;
315  }
319  function getAutoReview()
320  {
321  return $this->auto_review;
322  }
323 
324 
328  function getMaxAttempt()
329  {
330  return $this->max_attempt;
331  }
332 
333 
337  function setMaxAttempt($a_max_attempt)
338  {
339  $this->max_attempt = $a_max_attempt;
340  }
341 
345  function getModuleVersion()
346  {
347  return $this->module_version;
348  }
349 
354  {
355  return $this->assigned_glossary;
356  }
357 
361  function setAssignedGlossary($a_assigned_glossary)
362  {
363  $this->assigned_glossary = $a_assigned_glossary;
364  }
368  function setModuleVersion($a_module_version)
369  {
370  $this->module_version = $a_module_version;
371  }
372 
376  function getSession()
377  {
378  return $this->session;
379  }
380 
384  function setSession($a_session)
385  {
386  $this->session = $a_session;
387  }
388 
392  function getNoMenu()
393  {
394  return $this->no_menu;
395  }
396 
400  function setNoMenu($a_no_menu)
401  {
402  $this->no_menu = $a_no_menu;
403  }
404 
408  function getHideNavig()
409  {
410  return $this->hide_navig;
411  }
412 
416  function setHideNavig($a_hide_navig)
417  {
418  $this->hide_navig = $a_hide_navig;
419  }
420 
421 
425  function getDebug()
426  {
427  return $this->debug;
428  }
429 
433  function setDebug($a_debug)
434  {
435  $this->debug = $a_debug;
436  }
437 
441  function getDebugPw()
442  {
443  return $this->debug_pw;
444  }
445 
449  function setDebugPw($a_debug_pw)
450  {
451  $this->debug_pw = $a_debug_pw;
452  }
453 
457  function setAutoContinue($a_auto_continue)
458  {
459  $this->auto_continue = $a_auto_continue;
460  }
464  function getAutoContinue()
465  {
466  return $this->auto_continue;
467  }
471 /*
472  function updateMetaData()
473  {
474  $this->meta_data->update();
475  if ($this->meta_data->section != "General")
476  {
477  $meta = $this->meta_data->getElement("Title", "General");
478  $this->meta_data->setTitle($meta[0]["value"]);
479  $meta = $this->meta_data->getElement("Description", "General");
480  $this->meta_data->setDescription($meta[0]["value"]);
481  }
482  else
483  {
484  $this->setTitle($this->meta_data->getTitle());
485  $this->setDescription($this->meta_data->getDescription());
486  }
487  parent::update();
488 
489  }
490 */
491 
492 
499  function update()
500  {
501  global $ilDB;
502 
503  $this->updateMetaData();
504  parent::update();
505 
506  $statement = $ilDB->manipulateF('
507  UPDATE sahs_lm
508  SET c_online = %s,
509  api_adapter = %s,
510  api_func_prefix = %s,
511  auto_review = %s,
512  default_lesson_mode = %s,
513  c_type = %s,
514  stylesheet = %s,
515  editable = %s,
516  max_attempt = %s,
517  module_version = %s,
518  credit = %s,
519  glossary = %s,
520  question_tries = %s,
521  unlimited_session = %s,
522  no_menu = %s,
523  hide_navig = %s,
524  debug = %s,
525  debugpw = %s,
526  auto_continue = %s
527  WHERE id = %s',
528  array( 'text',
529  'text',
530  'text',
531  'text',
532  'text',
533  'text',
534  'integer',
535  'integer',
536  'integer',
537  'integer',
538  'text',
539  'integer',
540  'integer',
541  'text',
542  'text',
543  'text',
544  'text',
545  'text',
546  'text',
547  'integer'
548  ),
549  array( ilUtil::tf2yn($this->getOnline()),
550  $this->getAPIAdapterName(),
551  $this->getAPIFunctionsPrefix(),
552  ilUtil::tf2yn($this->getAutoReview()),
553  $this->getDefaultLessonMode(),
554  $this->getSubType(),
555  $this->getStyleSheetId(),
556  $this->getEditable(),
557  $this->getMaxAttempt(),
558  $this->getModuleVersion(),
559  $this->getCreditMode(),
560  $this->getAssignedGlossary(),
561  $this->getTries(),
562  ilUtil::tf2yn($this->getSession()),
563  ilUtil::tf2yn($this->getNoMenu()),
564  ilUtil::tf2yn($this->getHideNavig()),
565  ilUtil::tf2yn($this->getDebug()),
566  $this->getDebugPw(),
567  ilUtil::tf2yn($this->getAutoContinue()),
568  $this->getId())
569  );
570 
571  return true;
572  }
573 
580  static function getScormModulesForGlossary($a_glo_id)
581  {
582  global $ilDB;
583 
584  $set = $ilDB->query("SELECT DISTINCT id FROM sahs_lm WHERE ".
585  " glossary = ".$ilDB->quote($a_glo_id, "integer"));
586  $sms = array();
587  while ($rec = $ilDB->fetchAssoc($set))
588  {
589  if (ilObject::_hasUntrashedReference($rec["id"]))
590  {
591  $sms[] = $rec["id"];
592  }
593  }
594  return $sms;
595  }
596 
600  function setOnline($a_online)
601  {
602  $this->online = $a_online;
603  }
604 
608  function getOnline()
609  {
610  return $this->online;
611  }
612 
616  function setSubType($a_sub_type)
617  {
618  $this->sub_type = $a_sub_type;
619  }
620 
624  function getSubType()
625  {
626  return $this->sub_type;
627  }
628 
640  function delete()
641  {
642  global $ilDB, $ilLog;
643 
644  // always call parent delete function first!!
645  if (!parent::delete())
646  {
647  return false;
648  }
649 
650  // delete meta data of scorm content object
651 /*
652  $nested = new ilNestedSetXML();
653  $nested->init($this->getId(), $this->getType());
654  $nested->deleteAllDBData();
655 */
656  $this->deleteMetaData();
657 
658  // delete data directory
660 
661  // delete scorm learning module record
662  $ilDB->manipulateF('DELETE FROM sahs_lm WHERE id = %s',
663  array('integer'), array($this->getId()));
664 
665  $ilLog->write("SAHS Delete(SAHSLM), Subtype: ".$this->getSubType());
666 
667  if ($this->getSubType() == "scorm")
668  {
669  // remove all scorm objects and scorm tree
670  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMTree.php");
671  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMObject.php");
672  $sc_tree = new ilSCORMTree($this->getId());
673  $r_id = $sc_tree->readRootId();
674  if ($r_id > 0)
675  {
676  $items = $sc_tree->getSubTree($sc_tree->getNodeData($r_id));
677  foreach($items as $item)
678  {
679  $sc_object =& ilSCORMObject::_getInstance($item["obj_id"], $this->getId());
680  if (is_object($sc_object))
681  {
682  $sc_object->delete();
683  }
684  }
685  $sc_tree->removeTree($sc_tree->getTreeId());
686  }
687  }
688 
689  if ($this->getSubType() != "scorm")
690  {
691  // delete aicc data
692  $res = $ilDB->queryF('
693  SELECT aicc_object.obj_id FROM aicc_object, aicc_units
694  WHERE aicc_object.obj_id = aicc_units.obj_id
695  AND aicc_object.slm_id = %s',
696  array('integer'), array($this->getId()));
697 
698  while($row = $ilDB->fetchAssoc($res))
699  {
700  $obj_id = $row['obj_id'];
701  $ilDB->manipulateF('
702  DELETE FROM aicc_units WHERE obj_id = %s',
703  array('integer'), array($obj_id));
704  }
705 
706  $res = $ilDB->queryF('
707  SELECT aicc_object.obj_id FROM aicc_object, aicc_course
708  WHERE aicc_object.obj_id = aicc_course.obj_id
709  AND aicc_object.slm_id = %s',
710  array('integer'), array($this->getId()));
711 
712  while($row = $ilDB->fetchAssoc($res))
713  {
714  $obj_id = $row['obj_id'];
715  $ilDB->manipulateF('
716  DELETE FROM aicc_course WHERE obj_id = %s',
717  array('integer'), array($obj_id));
718  }
719 
720  $ilDB->manipulateF('
721  DELETE FROM aicc_object WHERE slm_id = %s',
722  array('integer'), array($this->getId()));
723  }
724 
725  $q_log = "DELETE FROM scorm_tracking WHERE obj_id = ".$ilDB->quote($this->getId());
726  $ilLog->write("SAHS Delete(SAHSLM): ".$q_log);
727 
728  $ilDB->manipulateF('DELETE FROM scorm_tracking WHERE obj_id = %s',
729  array('integer'), array($this->getId()));
730 
731  // always call parent delete function at the end!!
732  return true;
733  }
734 
745  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
746  {
747  global $tree;
748 
749  switch ($a_event)
750  {
751  case "link":
752 
753  //var_dump("<pre>",$a_params,"</pre>");
754  //echo "SCORMLearningModule ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
755  //exit;
756  break;
757 
758  case "cut":
759 
760  //echo "SCORMLearningModule ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
761  //exit;
762  break;
763 
764  case "copy":
765 
766  //var_dump("<pre>",$a_params,"</pre>");
767  //echo "SCORMLearningModule ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
768  //exit;
769  break;
770 
771  case "paste":
772 
773  //echo "SCORMLearningModule ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
774  //exit;
775  break;
776 
777  case "new":
778 
779  //echo "SCORMLearningModule ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
780  //exit;
781  break;
782  }
783 
784  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
785  if ($a_node_id==$_GET["ref_id"])
786  {
787  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
788  $parent_type = $parent_obj->getType();
789  if($parent_type == $this->getType())
790  {
791  $a_node_id = (int) $tree->getParentId($a_node_id);
792  }
793  }
794 
795  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
796  }
797 
803  public function getPointsInPercent()
804  {
805  global $ilUser;
806  if (strcmp($this->getSubType(), "scorm2004") == 0)
807  {
809  if (!is_null($res))
810  {
811  return $res * 100.0;
812  }
813  else
814  {
815  return $res;
816  }
817  }
818  else
819  {
820  return null;
821  }
822  }
823 
824 } // END class.ilObjSCORMLearningModule
825 ?>