ILIAS  Release_3_10_x_branch Revision 61812
 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-2001 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  }
57 
61  function create()
62  {
63  global $ilDB;
64 
66  $this->createMetaData();
67 
68  $this->createDataDirectory();
69 
70 /*
71  $this->meta_data->setId($this->getId());
72 //echo "<br>title:".$this->getId();
73  $this->meta_data->setType($this->getType());
74 //echo "<br>title:".$this->getType();
75  $this->meta_data->setTitle($this->getTitle());
76 //echo "<br>title:".$this->getTitle();
77  $this->meta_data->setDescription($this->getDescription());
78  $this->meta_data->setObject($this);
79  $this->meta_data->create();
80 */
81 
82  $q = "INSERT INTO sahs_lm (id, online, api_adapter, type) VALUES ".
83  " (".$ilDB->quote($this->getID()).",".$ilDB->quote("n").",".
84  $ilDB->quote("API").",".$ilDB->quote($this->getSubType()).")";
85  $ilDB->query($q);
86  }
87 
91  function read()
92  {
93  global $ilDB;
94 
95  parent::read();
96  $q = "SELECT * FROM sahs_lm WHERE id = ".$ilDB->quote($this->getId());
97  $lm_set = $this->ilias->db->query($q);
98  $lm_rec = $lm_set->fetchRow(DB_FETCHMODE_ASSOC);
99  $this->setOnline(ilUtil::yn2tf($lm_rec["online"]));
100  $this->setAutoReview(ilUtil::yn2tf($lm_rec["auto_review"]));
101  $this->setAPIAdapterName($lm_rec["api_adapter"]);
102  $this->setDefaultLessonMode($lm_rec["default_lesson_mode"]);
103  $this->setAPIFunctionsPrefix($lm_rec["api_func_prefix"]);
104  $this->setCreditMode($lm_rec["credit"]);
105  $this->setSubType($lm_rec["type"]);
106  $this->setSubType($lm_rec["type"]);
107  $this->setMaxAttempt($lm_rec["max_attempt"]);
108  $this->setModuleVersion($lm_rec["module_version"]);
109 
110 
111  }
112 
116  function _lookupOnline($a_id)
117  {
118  global $ilDB;
119 
120  $q = "SELECT * FROM sahs_lm WHERE id = ".$ilDB->quote($a_id);
121  $lm_set = $this->ilias->db->query($q);
122  $lm_rec = $lm_set->fetchRow(DB_FETCHMODE_ASSOC);
123 
124  return ilUtil::yn2tf($lm_rec["online"]);
125  }
126 
132  function _lookupSubType($a_obj_id)
133  {
134  global $ilDB;
135 
136  $q = "SELECT * FROM sahs_lm WHERE id = ".$ilDB->quote($a_obj_id);
137  $obj_set = $ilDB->query($q);
138  $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
139 
140  return $obj_rec["type"];
141  }
142 
148 /*
149  function getTitle()
150  {
151  return parent::getTitle();
152  }
153 */
154 
160 /*
161  function setTitle($a_title)
162  {
163  parent::setTitle($a_title);
164 // $this->meta_data->setTitle($a_title);
165  }
166 */
167 
173 /*
174  function getDescription()
175  {
176  return $this->meta_data->getDescription();
177  }
178 */
179 
185 /*
186  function setDescription($a_description)
187  {
188  $this->meta_data->setDescription($a_description);
189  }
190 */
191 
197 /*
198  function assignMetaData(&$a_meta_data)
199  {
200  $this->meta_data =& $a_meta_data;
201  }
202 */
203 
209 /*
210  function &getMetaData()
211  {
212  return $this->meta_data;
213  }
214 */
215 
216 
222  {
223  $lm_data_dir = ilUtil::getWebspaceDir()."/lm_data";
224  ilUtil::makeDir($lm_data_dir);
226  }
227 
231  function getDataDirectory($mode = "filesystem")
232  {
233  $lm_data_dir = ilUtil::getWebspaceDir($mode)."/lm_data";
234  $lm_dir = $lm_data_dir."/lm_".$this->getId();
235 
236  return $lm_dir;
237  }
238 
242  function getAPIAdapterName()
243  {
244  return $this->api_adapter;
245  }
246 
250  function setAPIAdapterName($a_api)
251  {
252  $this->api_adapter = $a_api;
253  }
254 
259  {
260  return $this->api_func_prefix;
261  }
262 
266  function setAPIFunctionsPrefix($a_prefix)
267  {
268  $this->api_func_prefix = $a_prefix;
269  }
270 
274  function getCreditMode()
275  {
276  return $this->credit_mode;
277  }
278 
282  function setCreditMode($a_credit_mode)
283  {
284  $this->credit_mode = $a_credit_mode;
285  }
286 
290  function setDefaultLessonMode($a_lesson_mode)
291  {
292  $this->lesson_mode = $a_lesson_mode;
293  }
294 
299  {
300  return $this->lesson_mode;
301  }
302 
306  function setAutoReview($a_auto_review)
307  {
308  $this->auto_review = $a_auto_review;
309  }
313  function getAutoReview()
314  {
315  return $this->auto_review;
316  }
317 
318 
322  function getMaxAttempt()
323  {
324  return $this->max_attempt;
325  }
326 
327 
331  function setMaxAttempt($a_max_attempt)
332  {
333  $this->max_attempt = $a_max_attempt;
334  }
335 
339  function getModuleVersion()
340  {
341  return $this->module_version;
342  }
343 
347  function setModuleVersion($a_module_version)
348  {
349  $this->module_version = $a_module_version;
350  }
351 
355 /*
356  function updateMetaData()
357  {
358  $this->meta_data->update();
359  if ($this->meta_data->section != "General")
360  {
361  $meta = $this->meta_data->getElement("Title", "General");
362  $this->meta_data->setTitle($meta[0]["value"]);
363  $meta = $this->meta_data->getElement("Description", "General");
364  $this->meta_data->setDescription($meta[0]["value"]);
365  }
366  else
367  {
368  $this->setTitle($this->meta_data->getTitle());
369  $this->setDescription($this->meta_data->getDescription());
370  }
371  parent::update();
372 
373  }
374 */
375 
376 
383  function update()
384  {
385  global $ilDB;
386 
387  $this->updateMetaData();
388  parent::update();
389 
390  $q = "UPDATE sahs_lm SET ".
391  " online = ".$ilDB->quote(ilUtil::tf2yn($this->getOnline())).",".
392  " api_adapter = ".$ilDB->quote($this->getAPIAdapterName()).",".
393  " api_func_prefix = ".$ilDB->quote($this->getAPIFunctionsPrefix()).",".
394  " auto_review = ".$ilDB->quote(ilUtil::tf2yn($this->getAutoReview())).",".
395  " default_lesson_mode = ".$ilDB->quote($this->getDefaultLessonMode()).",".
396  " type = ".$ilDB->quote($this->getSubType()).",".
397  " max_attempt = ".$ilDB->quote($this->getMaxAttempt()).",".
398  " module_version = ".$ilDB->quote($this->getModuleVersion()).",".
399  " credit = ".$ilDB->quote($this->getCreditMode())."".
400  " WHERE id = ".$ilDB->quote($this->getId());
401  $this->ilias->db->query($q);
402 
403  return true;
404  }
405 
409  function setOnline($a_online)
410  {
411  $this->online = $a_online;
412  }
413 
417  function getOnline()
418  {
419  return $this->online;
420  }
421 
425  function setSubType($a_sub_type)
426  {
427  $this->sub_type = $a_sub_type;
428  }
429 
433  function getSubType()
434  {
435  return $this->sub_type;
436  }
437 
449  function delete()
450  {
451  global $ilDB, $ilLog;
452 
453  // always call parent delete function first!!
454  if (!parent::delete())
455  {
456  return false;
457  }
458 
459  // delete meta data of scorm content object
460 /*
461  $nested = new ilNestedSetXML();
462  $nested->init($this->getId(), $this->getType());
463  $nested->deleteAllDBData();
464 */
465  $this->deleteMetaData();
466 
467  // delete data directory
469 
470  // delete scorm learning module record
471  $q = "DELETE FROM sahs_lm WHERE id = ".$ilDB->quote($this->getId());
472  $this->ilias->db->query($q);
473  $ilLog->write("SAHS Delete(SAHSLM), Subtype: ".$this->getSubType());
474 
475  if ($this->getSubType() == "scorm")
476  {
477  // remove all scorm objects and scorm tree
478  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMTree.php");
479  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMObject.php");
480  $sc_tree = new ilSCORMTree($this->getId());
481  $r_id = $sc_tree->readRootId();
482  if ($r_id > 0)
483  {
484  $items = $sc_tree->getSubTree($sc_tree->getNodeData($r_id));
485  foreach($items as $item)
486  {
487  $sc_object =& ilSCORMObject::_getInstance($item["obj_id"], $this->getId());
488  if (is_object($sc_object))
489  {
490  $sc_object->delete();
491  }
492  }
493  $sc_tree->removeTree($sc_tree->getTreeId());
494  }
495  }
496 
497  if ($this->getSubType() != "scorm")
498  {
499  // delete aicc data
500  // this is highly dependent on the database
501  $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());
502  $this->ilias->db->query($q);
503 
504  $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());
505  $this->ilias->db->query($q);
506 
507  $q = "DELETE FROM aicc_object WHERE slm_id = ".$ilDB->quote($this->getId());
508  $this->ilias->db->query($q);
509  }
510 
511  $q = "DELETE FROM scorm_tracking WHERE obj_id = ".$ilDB->quote($this->getId());
512 $ilLog->write("SAHS Delete(SAHSLM): ".$q);
513  $this->ilias->db->query($q);
514 
515  // always call parent delete function at the end!!
516  return true;
517  }
518 
529  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
530  {
531  global $tree;
532 
533  switch ($a_event)
534  {
535  case "link":
536 
537  //var_dump("<pre>",$a_params,"</pre>");
538  //echo "SCORMLearningModule ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
539  //exit;
540  break;
541 
542  case "cut":
543 
544  //echo "SCORMLearningModule ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
545  //exit;
546  break;
547 
548  case "copy":
549 
550  //var_dump("<pre>",$a_params,"</pre>");
551  //echo "SCORMLearningModule ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
552  //exit;
553  break;
554 
555  case "paste":
556 
557  //echo "SCORMLearningModule ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
558  //exit;
559  break;
560 
561  case "new":
562 
563  //echo "SCORMLearningModule ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
564  //exit;
565  break;
566  }
567 
568  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
569  if ($a_node_id==$_GET["ref_id"])
570  {
571  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
572  $parent_type = $parent_obj->getType();
573  if($parent_type == $this->getType())
574  {
575  $a_node_id = (int) $tree->getParentId($a_node_id);
576  }
577  }
578 
579  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
580  }
581 
582 } // END class.ilObjSCORMLearningModule
583 ?>