ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjSCORMInitData.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 
16 {
17 
18  function encodeURIComponent($str) {
19  $revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')', '%7E'=>'~');
20  return strtr(rawurlencode($str), $revert);
21  }
22 
23  function getIliasScormVars($slm_obj) {
24  global $ilias, $ilLog, $ilUser, $lng, $ilDB;
25 // $slm_obj =& new ilObjSCORMLearningModule($_GET["ref_id"]);
26 
27  //variables to set in administration interface
28  $b_storeObjectives='false';
29  if ($slm_obj->getObjectives()) $b_storeObjectives='true';
30  $b_storeInteractions='false';
31  if ($slm_obj->getInteractions()) $b_storeInteractions='true';
32  $b_readInteractions='false';
33  $c_storeSessionTime='s';//n=no, s=sco, i=ilias
34  if ($slm_obj->getTime_from_lms()) $c_storeSessionTime='i';
35  $i_lessonScoreMax='-1';
36  $i_lessonMasteryScore='-1';
37 
38  //other variables
39  $b_messageLog='false';
40  if ($ilLog->current_log_level == 30) $b_messageLog='true';
41  $launchId='0';
42  if ($_GET["autolaunch"] != "") $launchId=$_GET["autolaunch"];
43  $session_timeout = 0; //unlimited sessions
44  if ($slm_obj->getSession()) {
45  $session_timeout = (int)($ilias->ini->readVariable("session","expire"))/2;
46  }
47  $b_autoReview='false';
48  if ($slm_obj->getAutoReview()) $b_autoReview='true';
49  $b_debug='false';
50  if ($slm_obj->getDebug()) $b_debug='true';
51  $b_autoContinue='false';
52  if ($slm_obj->getAutoContinue()) $b_autoContinue='true';
53  $b_checkSetValues='false';
54  if ($slm_obj->getCheck_values()) $b_checkSetValues='true';
55  $b_autoLastVisited='false';
56  if ($slm_obj->getAuto_last_visited()) {
57  $b_autoLastVisited='true';
58  if ($launchId == '0') $launchId=$slm_obj->getLastVisited($ilUser->getID());
59  }
60 
61  //manifestData //extra to IliasScormManifestData
62  // $s_man = "";
63  $a_man = array();
64  $val_set = $ilDB->queryF('
65  SELECT sc_item.obj_id,prereq_type,prerequisites,maxtimeallowed,timelimitaction,datafromlms,masteryscore
66  FROM sc_item, scorm_object
67  WHERE scorm_object.obj_id=sc_item.obj_id
68  AND scorm_object.c_type = %s
69  AND scorm_object.slm_id = %s',
70  array('text','integer'),
71  array('sit',$slm_obj->getId())
72  );
73  while($val_rec = $ilDB->fetchAssoc($val_set)) {
74  if($val_rec["prereq_type"]!=null || $val_rec["prerequisites"]!=null || $val_rec["maxtimeallowed"]!=null || $val_rec["timelimitaction"]!=null || $val_rec["datafromlms"]!=null || $val_rec["masteryscore"]!=null) {
75  $tmp_man=array((int)$val_rec["obj_id"],null,null,null,null,null,null);
76  if($val_rec["prereq_type"]!=null) $tmp_man[1]=self::encodeURIComponent($val_rec["prereq_type"]);
77  if($val_rec["prerequisites"]!=null) $tmp_man[2]=self::encodeURIComponent($val_rec["prerequisites"]);
78  if($val_rec["maxtimeallowed"]!=null) $tmp_man[3]=self::encodeURIComponent($val_rec["maxtimeallowed"]);
79  if($val_rec["timelimitaction"]!=null) $tmp_man[4]=self::encodeURIComponent($val_rec["timelimitaction"]);
80  if($val_rec["datafromlms"]!=null) $tmp_man[5]=self::encodeURIComponent($val_rec["datafromlms"]);
81  if($val_rec["masteryscore"]!=null) $tmp_man[6]=self::encodeURIComponent($val_rec["masteryscore"]);
82  $a_man[]=$tmp_man;
83  }
84  }
85 
86  $s_out='{'
87  .'"refId":'.$_GET["ref_id"].','
88  .'"objId":'.$slm_obj->getId().','
89  .'"launchId":'.$launchId.','
90  .'"launchNr":0,'
91  .'"pingSession":'. $session_timeout.','
92  .'"studentId":'.$ilias->account->getId().','
93  .'"studentName":"'.self::encodeURIComponent($ilias->account->getLastname().', '.$ilias->account->getFirstname()).'",'
94  .'"studentLogin":"'.self::encodeURIComponent($ilias->account->getLogin()).'",'
95  .'"studentOu":"'.self::encodeURIComponent($ilias->account->getDepartment()).'",'
96  .'"credit":"'.str_replace("_", "-", $slm_obj->getCreditMode()).'",'
97  .'"lesson_mode":"'.$slm_obj->getDefaultLessonMode().'",'
98  .'"b_autoReview":'.$b_autoReview.','
99  .'"b_messageLog":'.$b_messageLog.','
100  .'"b_checkSetValues":'.$b_checkSetValues.','
101  .'"b_storeObjectives":'.$b_storeObjectives.','
102  .'"b_storeInteractions":'.$b_storeInteractions.','
103  .'"b_readInteractions":'.$b_readInteractions.','
104  .'"c_storeSessionTime":"'.$c_storeSessionTime.'",'
105  .'"b_autoContinue":'.$b_autoContinue.','
106  .'"b_autoLastVisited":'.$b_autoLastVisited.','
107  .'"i_lessonScoreMax":'.$i_lessonScoreMax.','
108  .'"i_lessonMasteryScore":'.$i_lessonMasteryScore.','
109  .'"b_debug":'.$b_debug.','
110  .'"a_itemParameter":'.json_encode($a_man).','
111  .'"status":'.json_encode(self::getStatus($slm_obj->getId(), $ilUser->getID())).','
112  .'"dataDirectory":"'.self::encodeURIComponent($slm_obj->getDataDirectory("output").'/').'",'
113  .'"img":{'
114  .'"asset":"'.self::encodeURIComponent(ilUtil::getImagePath('scorm/asset.png')).'",'
115  .'"browsed":"'.self::encodeURIComponent(ilUtil::getImagePath('scorm/browsed.png')).'",'
116  .'"completed":"'.self::encodeURIComponent(ilUtil::getImagePath('scorm/completed.png')).'",'
117  .'"failed":"'.self::encodeURIComponent(ilUtil::getImagePath('scorm/failed.png')).'",'
118  .'"incomplete":"'.self::encodeURIComponent(ilUtil::getImagePath('scorm/incomplete.png')).'",'
119  .'"not_attempted":"'.self::encodeURIComponent(ilUtil::getImagePath('scorm/not_attempted.png')).'",'
120  .'"passed":"'.self::encodeURIComponent(ilUtil::getImagePath('scorm/passed.png')).'",'
121  .'"running":"'.self::encodeURIComponent(ilUtil::getImagePath('scorm/running.png')).'"'
122  .'},'
123  .'"statusTxt":{'
124  .'"wait":"'.self::encodeURIComponent($lng->txt("please_wait")).'",'
125  .'"status":"'.self::encodeURIComponent($lng->txt("cont_status")).'",'
126  .'"browsed":"'.self::encodeURIComponent($lng->txt("cont_sc_stat_browsed")).'",'
127  .'"completed":"'.self::encodeURIComponent($lng->txt("cont_sc_stat_completed")).'",'
128  .'"failed":"'.self::encodeURIComponent($lng->txt("cont_sc_stat_failed")).'",'
129  .'"incomplete":"'.self::encodeURIComponent($lng->txt("cont_sc_stat_incomplete")).'",'
130  .'"not_attempted":"'.self::encodeURIComponent($lng->txt("cont_sc_stat_not_attempted")).'",'
131  .'"passed":"'.self::encodeURIComponent($lng->txt("cont_sc_stat_passed")).'",'
132  .'"running":"'.self::encodeURIComponent($lng->txt("cont_sc_stat_running")).'"'
133  .'}'
134  .'}';
135  return $s_out;
136  }
137 
138  function getIliasScormData($a_packageId) {
139  global $ilias, $ilUser, $ilDB;
140  $b_readInteractions='false';
141  $a_out=array();
142  $tquery = 'SELECT sco_id,lvalue,rvalue FROM scorm_tracking '
143  .'WHERE user_id = %s AND obj_id = %s '
144  ."AND sco_id > 0 AND lvalue != 'cmi.core.entry' AND lvalue != 'cmi.core.session_time'";
145  if ($b_readInteractions == 'false') $tquery.=" AND SUBSTR(lvalue, 1, 16) != 'cmi.interactions'";
146  $val_set = $ilDB->queryF($tquery,
147  array('integer','integer'),
148  array($ilUser->getId(),$a_packageId)
149  );
150  while($val_rec = $ilDB->fetchAssoc($val_set)) {
151  if (!strpos($val_rec["lvalue"],"._count"))
152  $a_out[]=array( (int)$val_rec["sco_id"], $val_rec["lvalue"], self::encodeURIComponent($val_rec["rvalue"]) );
153  }
154  return json_encode($a_out);
155  }
156 
157  function getIliasScormResources($a_packageId) {
158  global $ilias, $ilDB;
159 // $s_out="";
160  $a_out=array();
161  $s_resourceIds="";//necessary if resources exist having different href with same identifier
162  $val_set = $ilDB->queryF("
163  SELECT sc_resource.obj_id
164  FROM scorm_tree, sc_resource
165  WHERE scorm_tree.slm_id=%s
166  AND sc_resource.obj_id=scorm_tree.child",
167  array('integer'),
168  array($a_packageId)
169  );
170  while($val_rec = $ilDB->fetchAssoc($val_set)) {
171  $s_resourceIds .= ",".$val_rec["obj_id"];
172  }
173  $s_resourceIds = substr($s_resourceIds,1);
174 
175  $tquery="SELECT scorm_tree.lft, scorm_tree.child,
176  CASE WHEN sc_resource.scormtype = 'asset' THEN 1 ELSE 0 END AS asset,
177  sc_resource.href
178  FROM scorm_tree, sc_resource, sc_item
179  WHERE scorm_tree.slm_id=%s
180  AND sc_item.obj_id=scorm_tree.child
181  AND sc_resource.import_id=sc_item.identifierref
182  AND sc_resource.obj_id in (".$s_resourceIds.")
183  ORDER BY scorm_tree.lft";
184  $val_set = $ilDB->queryF($tquery,
185  array('integer'),
186  array($a_packageId)
187  );
188  while($val_rec = $ilDB->fetchAssoc($val_set)) {
189 // $s_out.='['.$val_rec["lft"].','.$val_rec["child"].','.$val_rec["asset"].',"'.self::encodeURIComponent($val_rec["href"]).'"],';
190  $a_out[]=array( (int)$val_rec["lft"], (int)$val_rec["child"], (int)$val_rec["asset"], self::encodeURIComponent($val_rec["href"]) );
191  }
192 // if(substr($s_out,(strlen($s_out)-1))==",") $s_out=substr($s_out,0,(strlen($s_out)-1));
193 // return "[".$s_out."]";
194  return json_encode($a_out);
195  }
196 
197  function getIliasScormTree($a_packageId) {
198  global $ilias, $ilDB;
199  $a_out=array();
200  $tquery="SELECT scorm_tree.child, scorm_tree.depth-3 depth, scorm_object.title, scorm_object.c_type
201  FROM scorm_tree, scorm_object
202  WHERE scorm_object.obj_id=scorm_tree.child
203  AND scorm_tree.slm_id=%s
204  AND (scorm_object.c_type='sor' OR scorm_object.c_type='sit')
205  ORDER BY scorm_tree.lft";
206  $val_set = $ilDB->queryF($tquery,
207  array('integer'),
208  array($a_packageId)
209  );
210  while($val_rec = $ilDB->fetchAssoc($val_set)) {
211  $a_out[]=array((int)$val_rec["child"],(int)$val_rec["depth"],self::encodeURIComponent($val_rec["title"]),$val_rec["c_type"]);
212  }
213  return json_encode($a_out);
214  }
215 
216  function getStatus($a_packageId,$a_user_id) {
217  include_once './Services/Tracking/classes/class.ilLPStatus.php';
218  $oldStatus = ilLPStatus::_lookupStatus($a_packageId, $a_user_id);
219  $status['saved_global_status']=(int) $oldStatus;
220  include_once './Services/Object/classes/class.ilObjectLP.php';
221  $olp = ilObjectLP::getInstance($a_packageId);
222  $status['lp_mode'] = $olp->getCurrentMode();
223  $collection = $olp->getCollectionInstance();
224  if($collection)
225  {
226  $status['scos'] = $collection->getItems();
227  }
228  else $status['scos'] = array();
229  $status['hash'] = ilObjSCORMInitData::setHash($a_packageId,$a_user_id);
230  $status['p'] = $a_user_id;
231  return $status;
232  }
233  // hash for storing data without session
234  private function setHash($a_packageId,$a_user_id) {
235  global $ilDB;
236  $hash = mt_rand(1000000000,9999999999);
237  $endDate = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m'), date('d')+1, date('Y')));
238 
239  $res = $ilDB->queryF('SELECT count(*) cnt FROM sahs_user WHERE obj_id = %s AND user_id = %s',
240  array('integer', 'integer'),
241  array($a_packageId,$a_user_id)
242  );
243  $val_rec = $ilDB->fetchAssoc($res);
244  if ($val_rec["cnt"] == 0) { //offline_mode could be inserted
245  $ilDB->manipulateF('INSERT INTO sahs_user (obj_id, user_id, hash, hash_end) VALUES(%s, %s, %s, %s)',
246  array('integer', 'integer', 'text', 'timestamp'),
247  array($a_packageId, $a_user_id, "".$hash, $endDate)
248  );
249  }
250  else
251  {
252  $ilDB->manipulateF('UPDATE sahs_user SET hash = %s, hash_end = %s WHERE obj_id = %s AND user_id = %s',
253  array('text', 'timestamp', 'integer', 'integer'),
254  array("".$hash, $endDate, $a_packageId, $a_user_id)
255  );
256  }
257  //clean table
258  // if (fmod($hash,100) == 0) //note: do not use % for large numbers; here php-min-Version: 4.2.0
259  // {
260  // $endDate = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m'), date('d')-2, date('Y')));
261  // $ilDB->manipulateF('DELETE FROM cmi_custom WHERE lvalue = %s AND c_timestamp < %s',
262  // array('text', 'timestamp'),
263  // array('hash', $endDate)
264  // );
265  // }
266  return $hash;
267  }
268 
272  function get_max_attempts($a_packageId)
273  {
274  global $ilDB;
275 
276  $res = $ilDB->queryF(
277  'SELECT max_attempt FROM sahs_lm WHERE id = %s',
278  array('integer'),
279  array($a_packageId)
280  );
281  $row = $ilDB->fetchAssoc($res);
282 
283  return $row['max_attempt'];
284  }
285 
286 }
static _lookupStatus($a_obj_id, $a_user_id)
Lookup status.
$_GET["client_id"]
setHash($a_packageId, $a_user_id)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
get_max_attempts($a_packageId)
Get max.
global $ilUser
Definition: imgupload.php:15
global $lng
Definition: privfeed.php:40
static getInstance($a_obj_id)
getStatus($a_packageId, $a_user_id)
Class ilObjSCORMInitData.