ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilSCORM2004StoreData Class Reference

Class ilSCORM2004StoreData. More...

+ Collaboration diagram for ilSCORM2004StoreData:

Static Public Member Functions

static scormPlayerUnload ($userId=null, $packageId, $time_from_lms)
 
static persistCMIData ($userId=null, $packageId, $defaultLessonMode, $comments, $interactions, $objectives, $time_from_lms, $data=null)
 
static checkIfAllowed ($packageId, $userId, $hash)
 
static setCMIData ($userId, $packageId, $data, $getComments, $getInteractions, $getObjectives)
 
static syncGlobalStatus ($userId, $packageId, $data, $new_global_status, $time_from_lms)
 
static writeGObjective ($g_data, $user, $package)
 

Static Protected Member Functions

static setGlobalObjectives ($userId, $packageId, $data)
 

Detailed Description

Member Function Documentation

◆ checkIfAllowed()

static ilSCORM2004StoreData::checkIfAllowed (   $packageId,
  $userId,
  $hash 
)
static

Definition at line 126 of file class.ilSCORM2004StoreData.php.

References $DIC, $ilDB, $packageId, and $res.

127  {
128  global $DIC;
129 
130  $ilDB = $DIC->database();
131  $res = $ilDB->queryF(
132  'select hash from sahs_user where obj_id=%s AND user_id=%s AND hash_end>%s',
133  array('integer','integer','timestamp'),
134  array($packageId,$userId,date('Y-m-d H:i:s'))
135  );
136  $rowtmp = $ilDB->fetchAssoc($res);
137  if ($rowtmp['hash'] == $hash) {
138  return;
139  } else {
140  die("not allowed");
141  }
142  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$packageId

◆ persistCMIData()

static ilSCORM2004StoreData::persistCMIData (   $userId = null,
  $packageId,
  $defaultLessonMode,
  $comments,
  $interactions,
  $objectives,
  $time_from_lms,
  $data = null 
)
static

Definition at line 69 of file class.ilSCORM2004StoreData.php.

References $_SERVER, $data, $DIC, $ilLog, $packageId, ilObjSCORM2004LearningModule\getQuantityOfSCOs(), ilLTIAppEventListener\handleOutcomeWithoutLP(), setCMIData(), setGlobalObjectives(), and syncGlobalStatus().

Referenced by ilSCORM13Player\executeCommand().

70  {
71  global $DIC;
72 
73  $ilLog = $DIC["ilLog"];
74 
75  if ($defaultLessonMode == "browse") {
76  return;
77  }
78 
79  $jsMode = strpos($_SERVER['HTTP_ACCEPT'], 'text/javascript') !== false;
80 
81  $data = json_decode(is_string($data) ? $data : file_get_contents('php://input'));
82  $ilLog->write("dataTo_setCMIData: " . file_get_contents('php://input'));
83  if (!$data) {
84  return;
85  }
86  if ($userId == null) {
87  $userId = (int) $data->p;
88  self::checkIfAllowed($packageId, $userId, $data->hash);
89  // header('Access-Control-Allow-Origin: http://localhost:50012');//just for tests - not for release UK
90  }
91  $return = array();
93  $userId,
94  $packageId,
95  $data,
96  $comments,
97  $interactions,
98  $objectives
99  );
100 
101  //$new_global_status=ilSCORM2004StoreData::setGlobalObjectivesAndGetGlobalStatus($userId, $packageId, $data);
103  $new_global_status = $data->now_global_status;
104  $return["new_global_status"] = $new_global_status;
105 
106  // mantis #30293
107  $score_scaled = $data->node[0][35];
108  if ($score_scaled != null) {
110  ilLTIAppEventListener::handleOutcomeWithoutLP($packageId, $userId, $score_scaled * 100);
111  }
112  }
113 
114  ilSCORM2004StoreData::syncGlobalStatus($userId, $packageId, $data, $new_global_status, $time_from_lms);
115 
116  $ilLog->write("SCORM: return of persistCMIData: " . json_encode($return));
117  if ($jsMode) {
118  header('Content-Type: text/javascript; charset=UTF-8');
119  print(json_encode($return));
120  } else {
121  header('Content-Type: text/html; charset=UTF-8');
122  print(var_export($return, true));
123  }
124  }
static syncGlobalStatus($userId, $packageId, $data, $new_global_status, $time_from_lms)
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
global $DIC
Definition: saml.php:7
static setGlobalObjectives($userId, $packageId, $data)
static handleOutcomeWithoutLP($a_obj_id, $a_usr_id, $a_percentage)
static setCMIData($userId, $packageId, $data, $getComments, $getInteractions, $getObjectives)
$packageId
$data
Definition: bench.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scormPlayerUnload()

static ilSCORM2004StoreData::scormPlayerUnload (   $userId = null,
  $packageId,
  $time_from_lms 
)
static

Definition at line 14 of file class.ilSCORM2004StoreData.php.

References $_GET, $data, $DIC, $ilDB, $packageId, and ilSCORM2004Tracking\_syncReadEvent().

Referenced by ilSCORM13Player\executeCommand().

15  {
16  global $DIC;
17 
18  $ilDB = $DIC->database();
19 
20  // $data = json_decode(is_string($data) ? $data : file_get_contents('php://input'));
21  $data = json_decode(file_get_contents('php://input'));
22  if (!$data) {
23  return;
24  }
25  if ($userId == null) {
26  $userId = (int) $data->p;
27  self::checkIfAllowed($packageId, $userId, $data->hash);
28  }
29  $last_visited = null;
30  if ($data->last != "") {
31  $last_visited = $data->last;
32  }
33  $endDate = date('Y-m-d H:i:s', mktime(date('H'), date('i') + 5, date('s'), date('m'), date('d'), date('Y')));
34  $total_time_sec = null;
35  if ($data->total_time_sec != "") {
36  $total_time_sec = $data->total_time_sec;
37  $ilDB->manipulateF(
38  'UPDATE sahs_user
39  SET total_time_sec = %s, last_visited = %s, hash_end =%s, last_access = %s
40  WHERE obj_id = %s AND user_id = %s',
41  array('integer', 'text', 'timestamp', 'timestamp', 'integer', 'integer'),
42  array($total_time_sec,$last_visited, $endDate, date('Y-m-d H:i:s'), $packageId, $userId)
43  );
44  if ($time_from_lms == true) {
45  self::ensureObjectDataCacheExistence();
46  global $DIC;
47 
48  $ilObjDataCache = $DIC["ilObjDataCache"];
49  // sync access number and time in read event table
50  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tracking.php");
51  ilSCORM2004Tracking::_syncReadEvent($packageId, $userId, "sahs", (int) $_GET['ref_id'], $time_from_lms);
52  //end sync access number and time in read event table
53  }
54  } else {
55  $ilDB->manipulateF(
56  'UPDATE sahs_user
57  SET last_visited = %s, hash_end =%s, last_access = %s
58  WHERE obj_id = %s AND user_id = %s',
59  array('text', 'timestamp', 'timestamp', 'integer', 'integer'),
60  array($last_visited, $endDate, date('Y-m-d H:i:s'), $packageId, $userId)
61  );
62  }
63 
64  header('Content-Type: text/plain; charset=UTF-8');
65  print("");
66  }
global $DIC
Definition: saml.php:7
$_GET["client_id"]
global $ilDB
$packageId
static _syncReadEvent($a_obj_id, $a_user_id, $a_type, $a_ref_id, $time_from_lms=null)
Synch read event table.
$data
Definition: bench.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCMIData()

static ilSCORM2004StoreData::setCMIData (   $userId,
  $packageId,
  $data,
  $getComments,
  $getInteractions,
  $getObjectives 
)
static

Definition at line 144 of file class.ilSCORM2004StoreData.php.

References $data, $DIC, $i, $ilDB, $ilLog, $res, $result, $row, and $table.

Referenced by persistCMIData(), and ilSCORMOfflineMode\sop2il().

145  {
146  global $DIC;
147 
148  $ilDB = $DIC->database();
149  $ilLog = $DIC["ilLog"];
150 
151  $result = array();
152 
153  if (!$data) {
154  return $result;
155  }
156 
157  $i_check = $data->i_check;
158  $i_set = $data->i_set;
159  $b_node_update = false;
160  $cmi_node_id = null;
161  $a_map_cmi_interaction_id = array();
162 
163  $tables = array('node', 'comment', 'interaction', 'objective', 'correct_response');
164 
165  foreach ($tables as $table) {
166  if (!is_array($data->$table)) {
167  continue;
168  }
169 
170  $ilLog->write("SCORM: setCMIData, table -" . $table . "-");
171 
172  // now iterate through data rows from input
173  foreach ($data->$table as &$row) {
174  $ilLog->write("Checking table: " . $table);
175 
176  switch ($table) {
177  case 'node': //is always first and has only 1 row
178 
179  $res = $ilDB->queryF(
180  'SELECT cmi_node_id FROM cmi_node WHERE cp_node_id = %s and user_id = %s',
181  array('integer','integer'),
182  array($row[19],$userId)
183  );
184  $rowtmp = $ilDB->fetchAssoc($res);
185  $cmi_node_id = $rowtmp['cmi_node_id'];
186  if ($cmi_node_id != null) {
187  $b_node_update = true;
188  } else {
189  $cmi_node_id = $ilDB->nextId('cmi_node');
190  $b_node_update = false;
191  }
192  $ilLog->write("setCMIdata with cmi_node_id = " . $cmi_node_id);
193  $a_data = array(
194  'accesscount' => array('integer', $row[0]),
195  'accessduration' => array('text', $row[1]),
196  'accessed' => array('text', $row[2]),
197  'activityabsduration' => array('text', $row[3]),
198  'activityattemptcount' => array('integer', $row[4]),
199  'activityexpduration' => array('text', $row[5]),
200  'activityprogstatus' => array('integer', $row[6]),
201  'attemptabsduration' => array('text', $row[7]),
202  'attemptcomplamount' => array('float', $row[8]),
203  'attemptcomplstatus' => array('integer', $row[9]),
204  'attemptexpduration' => array('text', $row[10]),
205  'attemptprogstatus' => array('integer', $row[11]),
206  'audio_captioning' => array('integer', $row[12]),
207  'audio_level' => array('float', $row[13]),
208  'availablechildren' => array('text', $row[14]),
209  'cmi_node_id' => array('integer', $cmi_node_id),
210  'completion' => array('float', $row[16]),
211  'completion_status' => array('text', $row[17]),
212  'completion_threshold' => array('text', $row[18]),
213  'cp_node_id' => array('integer', $row[19]),
214  'created' => array('text', $row[20]),
215  'credit' => array('text', $row[21]),
216  'delivery_speed' => array('float', $row[22]),
217  'c_entry' => array('text', $row[23]),
218  'c_exit' => array('text', $row[24]),
219  'c_language' => array('text', $row[25]),
220  'launch_data' => array('clob', $row[26]),
221  'learner_name' => array('text', $row[27]),
222  'location' => array('text', $row[28]),
223  'c_max' => array('float', $row[29]),
224  'c_min' => array('float', $row[30]),
225  'c_mode' => array('text', $row[31]),
226  'modified' => array('text', $row[32]),
227  'progress_measure' => array('float', $row[33]),
228  'c_raw' => array('float', $row[34]),
229  'scaled' => array('float', $row[35]),
230  'scaled_passing_score' => array('float', $row[36]),
231  'session_time' => array('text', $row[37]),
232  'success_status' => array('text', $row[38]),
233  'suspend_data' => array('clob', $row[39]),
234  'total_time' => array('text', $row[40]),
235  'user_id' => array('integer', $userId),
236  'c_timestamp' => array('timestamp', date('Y-m-d H:i:s')),
237  'additional_tables' => array('integer', $i_check)
238  );
239 
240  if ($b_node_update == false) {
241  $ilDB->insert('cmi_node', $a_data);
242  $ilLog->write("inserted");
243  } else {
244  $ilDB->update('cmi_node', $a_data, array('cmi_node_id' => array('integer', $cmi_node_id)));
245  $ilLog->write("updated");
246  }
247 
248  if ($b_node_update == true) {
249  //remove
250  if ($i_set > 7) {
251  $i_set -= 8;
252  if ($getComments) {
253  $q = 'DELETE FROM cmi_comment WHERE cmi_node_id = %s';
254  $ilDB->manipulateF($q, array('integer'), array($cmi_node_id));
255  }
256  }
257  if ($i_set > 3) {
258  $i_set -= 4;
259  if ($getInteractions) {
260  $q = 'DELETE FROM cmi_correct_response
261  WHERE cmi_interaction_id IN (
262  SELECT cmi_interaction.cmi_interaction_id FROM cmi_interaction WHERE cmi_interaction.cmi_node_id = %s)';
263  $ilDB->manipulateF($q, array('integer'), array($cmi_node_id));
264  }
265  }
266  if ($i_set > 1) {
267  $i_set -= 2;
268  if ($getInteractions) {
269  $q = 'DELETE FROM cmi_interaction WHERE cmi_node_id = %s';
270  $ilDB->manipulateF($q, array('integer'), array($cmi_node_id));
271  }
272  }
273  if ($i_set > 0) {
274  $i_set = 0;
275  if ($getObjectives) {
276  $q = 'DELETE FROM cmi_objective WHERE cmi_node_id = %s';
277  $ilDB->manipulateF($q, array('integer'), array($cmi_node_id));
278  }
279  }
280  //end remove
281  }
282  //to send to client
283  $result[(string) $row[19]] = $cmi_node_id;
284  break;
285 
286  case 'comment':
287  $row[0] = $ilDB->nextId('cmi_comment');
288 
289  $ilDB->insert('cmi_comment', array(
290  'cmi_comment_id' => array('integer', $row[0]),
291  'cmi_node_id' => array('integer', $cmi_node_id),
292  'c_comment' => array('clob', $row[2]),
293  'c_timestamp' => array('text', $row[3]),
294  'location' => array('text', $row[4]),
295  'sourceislms' => array('integer', $row[5])
296  ));
297  break;
298 
299  case 'interaction':
300  $cmi_interaction_id = $ilDB->nextId('cmi_interaction');
301  $a_map_cmi_interaction_id[] = array($row[0],$cmi_interaction_id);
302  $ilDB->insert('cmi_interaction', array(
303  'cmi_interaction_id' => array('integer', $cmi_interaction_id),
304  'cmi_node_id' => array('integer', $cmi_node_id),
305  'description' => array('clob', $row[2]),
306  'id' => array('text', $row[3]),
307  'latency' => array('text', $row[4]),
308  'learner_response' => array('clob', $row[5]),
309  'result' => array('text', $row[6]),
310  'c_timestamp' => array('text', $row[7]),
311  'c_type' => array('text', $row[8]),
312  'weighting' => array('float', $row[9])
313  ));
314  break;
315 
316  case 'objective':
317  $row[2] = $ilDB->nextId('cmi_objective');
318  $cmi_interaction_id = null;
319  if ($row[0] != null) {
320  for ($i = 0;$i < count($a_map_cmi_interaction_id);$i++) {
321  if ($row[0] == $a_map_cmi_interaction_id[$i][0]) {
322  $cmi_interaction_id = $a_map_cmi_interaction_id[$i][1];
323  }
324  }
325  }
326  $ilDB->insert('cmi_objective', array(
327  'cmi_interaction_id' => array('integer', $cmi_interaction_id),
328  'cmi_node_id' => array('integer', $cmi_node_id),
329  'cmi_objective_id' => array('integer', $row[2]),
330  'completion_status' => array('text', $row[3]),
331  'description' => array('clob', $row[4]),
332  'id' => array('text', $row[5]),
333  'c_max' => array('float', $row[6]),
334  'c_min' => array('float', $row[7]),
335  'c_raw' => array('float', $row[8]),
336  'scaled' => array('float', $row[9]),
337  'progress_measure' => array('float', $row[10]),
338  'success_status' => array('text', $row[11]),
339  'scope' => array('text', $row[12])
340  ));
341  break;
342 
343  case 'correct_response':
344  $cmi_interaction_id = null;
345  if ($row[1] !== null) {
346  for ($i = 0;$i < count($a_map_cmi_interaction_id);$i++) {
347  if ($row[1] == $a_map_cmi_interaction_id[$i][0]) {
348  $cmi_interaction_id = $a_map_cmi_interaction_id[$i][1];
349  }
350  }
351  $row[0] = $ilDB->nextId('cmi_correct_response');
352  $ilDB->insert('cmi_correct_response', array(
353  'cmi_correct_resp_id' => array('integer', $row[0]),
354  'cmi_interaction_id' => array('integer', $cmi_interaction_id),
355  'pattern' => array('text', $row[2])
356  ));
357  }
358  break;
359  }
360  }
361  }
362  return $result;
363  }
$result
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$row
global $ilDB
$i
Definition: disco.tpl.php:19
if(empty($password)) $table
Definition: pwgen.php:24
$data
Definition: bench.php:6
+ Here is the caller graph for this function:

◆ setGlobalObjectives()

static ilSCORM2004StoreData::setGlobalObjectives (   $userId,
  $packageId,
  $data 
)
staticprotected

Definition at line 392 of file class.ilSCORM2004StoreData.php.

References $data, $DIC, $ilLog, $packageId, and writeGObjective().

Referenced by persistCMIData().

393  {
394  global $DIC;
395 
396  $ilLog = $DIC["ilLog"];
397  $changed_seq_utilities = $data->changed_seq_utilities;
398  $ilLog->write("SCORM2004 adl_seq_utilities changed: " . $changed_seq_utilities);
399  if ($changed_seq_utilities == 1) {
400  $returnAr = ilSCORM2004StoreData::writeGObjective($data->adl_seq_utilities, $userId, $packageId);
401  }
402  }
global $DIC
Definition: saml.php:7
$packageId
static writeGObjective($g_data, $user, $package)
$data
Definition: bench.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ syncGlobalStatus()

static ilSCORM2004StoreData::syncGlobalStatus (   $userId,
  $packageId,
  $data,
  $new_global_status,
  $time_from_lms 
)
static

Definition at line 404 of file class.ilSCORM2004StoreData.php.

References $_GET, $data, $DIC, $ilDB, $ilLog, $packageId, ilSCORM2004Tracking\_syncReadEvent(), and ilLPStatus\writeStatus().

Referenced by persistCMIData(), and ilSCORMOfflineMode\sop2il().

405  {
406  global $DIC;
407 
408  $ilDB = $DIC->database();
409  $ilLog = $DIC["ilLog"];
410  $saved_global_status = $data->saved_global_status;
411  $ilLog->write("saved_global_status=" . $saved_global_status);
412 
413 
414  //update percentage_completed, sco_total_time_sec,status in sahs_user
415  $totalTime = (int) $data->totalTimeCentisec;
416  $totalTime = round($totalTime / 100);
417  $ilDB->queryF(
418  'UPDATE sahs_user SET sco_total_time_sec=%s, status=%s, percentage_completed=%s WHERE obj_id = %s AND user_id = %s',
419  array('integer', 'integer', 'integer', 'integer', 'integer'),
420  array($totalTime, $new_global_status, $data->percentageCompleted, $packageId, $userId)
421  );
422 
423  self::ensureObjectDataCacheExistence();
424  global $DIC;
425 
426  $ilObjDataCache = $DIC["ilObjDataCache"];
427 
428  // update learning progress
429  if ($new_global_status != null) {//could only happen when synchronising from SCORM Offline Player
430  include_once("./Services/Tracking/classes/class.ilObjUserTracking.php");
431  include_once("./Services/Tracking/classes/class.ilLPStatus.php");
432  ilLPStatus::writeStatus($packageId, $userId, $new_global_status, $data->percentageCompleted);
433 
434  // here put code for soap to MaxCMS e.g. when if($saved_global_status != $new_global_status)
435  }
436  // sync access number and time in read event table
437  if ($time_from_lms == false) {
438  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tracking.php");
439  ilSCORM2004Tracking::_syncReadEvent($packageId, $userId, "sahs", (int) $_GET['ref_id'], $time_from_lms);
440  }
441  //end sync access number and time in read event table
442 
443  return true;
444  }
global $DIC
Definition: saml.php:7
$_GET["client_id"]
static writeStatus($a_obj_id, $a_user_id, $a_status, $a_percentage=false, $a_force_per=false)
Write status for user and object.
global $ilDB
$packageId
static _syncReadEvent($a_obj_id, $a_user_id, $a_type, $a_ref_id, $time_from_lms=null)
Synch read event table.
$data
Definition: bench.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeGObjective()

static ilSCORM2004StoreData::writeGObjective (   $g_data,
  $user,
  $package 
)
static

Definition at line 449 of file class.ilSCORM2004StoreData.php.

References $DIC, $GLOBALS, $ilDB, $ilLog, $key, $res, $row, and $user.

Referenced by setGlobalObjectives().

450  {
451  global $DIC;
452 
453  $ilDB = $DIC->database();
454  $ilLog = $DIC["ilLog"];
455  $ilLog->write("SCORM2004 writeGObjective");
456 
457  $returnAr = array(null,null,null);
458 
459  //iterate over assoziative array
460  if ($g_data == null) {
461  return $returnAr;
462  }
463 
464  $rows_to_insert = array();
465 
466  foreach ($g_data as $key => $value) {
467  $ilLog->write("SCORM2004 writeGObjective -key: " . $key);
468  //objective
469  //learner = ilias learner id
470  //scope = null / course
471  foreach ($value as $skey => $svalue) {
472  $ilLog->write("SCORM2004 writeGObjective -skey: " . $skey);
473  //we always have objective and learner id
474  if ($g_data->$key->$skey->$user->$package) {
475  $o_value = $g_data->$key->$skey->$user->$package;
476  $scope = $package;
477  } else { //UK: is this okay? can $scope=0 and $user->{"null"}; when is $scope used?
478  //scope 0
479  $o_value = $g_data->$key->$skey->$user->{"null"};
480  //has to be converted to NULL in JS Later
481  $scope = 0;
482  }
483 
484  //insert into database
485  $objective_id = $skey;
486  $toset = $o_value;
487  $dbuser = $user;
488 
489  if ($key == "status") {
490 
491  //special handling for status
492  $completed = $g_data->$key->$skey->$user->{"completed"};
493  $measure = $g_data->$key->$skey->$user->{"measure"};
494  $satisfied = $g_data->$key->$skey->$user->{"satisfied"};
495 
496  $returnAr = array($completed, $satisfied, $measure);
497 
498  $obj = '-course_overall_status-';
499  $pkg_id = $package;
500 
501  $res = $ilDB->queryF(
502  '
503  SELECT user_id FROM cmi_gobjective
504  WHERE objective_id =%s
505  AND user_id = %s
506  AND scope_id = %s',
507  array('text', 'integer', 'integer'),
508  array($obj, $dbuser, $pkg_id)
509  );
510  $ilLog->write("SCORM2004 Count is: " . $ilDB->numRows($res));
511  if (!$ilDB->numRows($res)) {
512  $ilDB->manipulateF(
513  '
514  INSERT INTO cmi_gobjective
515  (user_id, status, scope_id, measure, satisfied, objective_id)
516  VALUES (%s, %s, %s, %s, %s, %s)',
517  array('integer', 'text', 'integer', 'text', 'text', 'text'),
518  array($dbuser, $completed, $pkg_id, $measure, $satisfied, $obj)
519  );
520  $ilLog->write("SCORM2004 cmi_gobjective Insert status=" . $completed . " scope_id=" . $pkg_id . " measure=" . $measure . " satisfied=" . $satisfied . " objective_id=" . $obj);
521  } else {
522  $ilDB->manipulateF(
523  '
524  UPDATE cmi_gobjective
525  SET status = %s,
526  measure = %s,
527  satisfied = %s
528  WHERE objective_id = %s
529  AND user_id = %s
530  AND scope_id = %s',
531  array('text', 'text', 'text', 'text', 'integer', 'integer'),
532  array($completed, $measure, $satisfied, $obj, $dbuser, $pkg_id)
533  );
534  $ilLog->write("SCORM2004 cmi_gobjective Update status=" . $completed . " scope_id=" . $pkg_id . " measure=" . $measure . " satisfied=" . $satisfied . " objective_id=" . $obj);
535  }
536  } else { //add it to the rows_to_insert
537  //create the row if this is the first time it has been found
538  if ($rows_to_insert[$objective_id] == null) {
539  $rows_to_insert[$objective_id] = array();
540  }
541  $rows_to_insert[$objective_id][$key] = $toset;
542  }
543  }
544  }
545 
546  //Get the scope for all the global objectives!!!
547  $res = $ilDB->queryF(
548  "SELECT global_to_system
549  FROM cp_package
550  WHERE obj_id = %s",
551  array('text'),
552  array($package)
553  );
554 
555  $scope_id = ($ilDB->fetchObject($res)->global_to_system) ? 0 : $package;
556 
557  //build up the set to look for in the query
558  $existing_key_template = "";
559  foreach (array_keys($rows_to_insert) as $obj_id) {
560  $existing_key_template .= "'{$obj_id}',";
561  }
562  //remove trailing ','
563  $existing_key_template = substr($existing_key_template, 0, strlen($existing_key_template) - 1);
564  $existing_keys = array();
565 
566  if ($existing_key_template != "") {
567  //Get the ones that need to be updated in a single query
568  $res = $ilDB->queryF(
569  "SELECT objective_id
570  FROM cmi_gobjective
571  WHERE user_id = %s
572  AND scope_id = %s
573  AND objective_id IN ($existing_key_template)",
574  array('integer', 'integer'),
575  array($dbuser, $scope_id)
576  );
577 
578  while ($row = $ilDB->fetchAssoc($res)) {
579  $existing_keys[] = $row['objective_id'];
580  }
581  }
582 
583  foreach ($rows_to_insert as $obj_id => $vals) {
584  if (in_array($obj_id, $existing_keys)) {
585  $ilDB->manipulateF(
586  "UPDATE cmi_gobjective
587  SET satisfied=%s,
588  measure=%s,
589  score_raw=%s,
590  score_min=%s,
591  score_max=%s,
592  completion_status=%s,
593  progress_measure=%s
594  WHERE objective_id = %s
595  AND user_id = %s
596  AND scope_id = %s",
597  array('text','text', 'text', 'text', 'text', 'text',
598  'text', 'text', 'integer', 'integer'),
599  array($vals['satisfied'], $vals["measure"], $vals["score_raw"],
600  $vals["score_min"], $vals["score_max"],
601  $vals["completion_status"], $vals["progress_measure"],
602  $obj_id, $dbuser, $scope_id)
603  );
604  } else {
605  $ilDB->manipulateF(
606  "INSERT INTO cmi_gobjective
607  (user_id, satisfied, measure, scope_id, status, objective_id,
608  score_raw, score_min, score_max, progress_measure, completion_status)
609  VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
610  array('integer', 'text', 'text', 'integer', 'text', 'text',
611  'text', 'text', 'text', 'text', 'text'),
612  array($dbuser, $vals['satisfied'], $vals['measure'],
613  $scope_id, null, $obj_id, $vals['score_raw'],
614  $vals['score_min'], $vals['score_max'],
615  $vals['progress_measure'], $vals['completion_status'])
616  );
617  }
618  }
619 
620  // update learning progress here not necessary because integrated in setCMIdata
621  // check _updateStatus for cmi_gobjective
622  // include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
623  // ilLPStatusWrapper::_updateStatus($package, $user);
624 
625  return $returnAr;
626  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$user
Definition: migrateto20.php:57
$row
global $ilDB
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: