200 : array {
202
205
206 $result = array();
207
209 return $result;
210 }
211
212 $i_check =
$data->i_check;
213 $i_set =
$data->i_set;
214 $b_node_update = false;
215 $cmi_node_id = null;
216 $a_map_cmi_interaction_id = array();
217
218 $tables = array('node', 'comment', 'interaction', 'objective', 'correct_response');
219
220 foreach ($tables as $table) {
221 if (!is_array(
$data->$table)) {
222 continue;
223 }
224
225 $ilLog->debug("SCORM: setCMIData, table -" . $table . "-");
226
227
228 foreach (
$data->$table as &$row) {
229 $ilLog->debug("Checking table: " . $table);
230
231 switch ($table) {
232 case 'node':
233
235 'SELECT cmi_node_id FROM cmi_node WHERE cp_node_id = %s and user_id = %s',
236 array('integer', 'integer'),
237 array($row[19], $userId)
238 );
240
241 if ($rowtmp != null) {
242 $cmi_node_id = $rowtmp['cmi_node_id'];
243 $b_node_update = true;
244 } else {
245 $cmi_node_id =
$ilDB->nextId(
'cmi_node');
246 $b_node_update = false;
247 }
248 $ilLog->debug("setCMIdata with cmi_node_id = " . $cmi_node_id);
249 $a_data = array(
250 'accesscount' => array('integer', $row[0]),
251 'accessduration' => array('text', $row[1]),
252 'accessed' => array('text', $row[2]),
253 'activityabsduration' => array('text', $row[3]),
254 'activityattemptcount' => array('integer', $row[4]),
255 'activityexpduration' => array('text', $row[5]),
256 'activityprogstatus' => array('integer', $row[6]),
257 'attemptabsduration' => array('text', $row[7]),
258 'attemptcomplamount' => array('float', $row[8]),
259 'attemptcomplstatus' => array('integer', $row[9]),
260 'attemptexpduration' => array('text', $row[10]),
261 'attemptprogstatus' => array('integer', $row[11]),
262 'audio_captioning' => array('integer', $row[12]),
263 'audio_level' => array('float', $row[13]),
264 'availablechildren' => array('text', $row[14]),
265 'cmi_node_id' => array('integer', $cmi_node_id),
266 'completion' => array('float', $row[16]),
267 'completion_status' => array('text', $row[17]),
268 'completion_threshold' => array('text', $row[18]),
269 'cp_node_id' => array('integer', $row[19]),
270 'created' => array('text', $row[20]),
271 'credit' => array('text', $row[21]),
272 'delivery_speed' => array('float', $row[22]),
273 'c_entry' => array('text', $row[23]),
274 'c_exit' => array('text', $row[24]),
275 'c_language' => array('text', $row[25]),
276 'launch_data' => array('clob', $row[26]),
277 'learner_name' => array('text', $row[27]),
278 'location' => array('text', $row[28]),
279 'c_max' => array('float', $row[29]),
280 'c_min' => array('float', $row[30]),
281 'c_mode' => array('text', $row[31]),
282 'modified' => array('text', $row[32]),
283 'progress_measure' => array('float', $row[33]),
284 'c_raw' => array('float', $row[34]),
285 'scaled' => array('float', $row[35]),
286 'scaled_passing_score' => array('float', $row[36]),
287 'session_time' => array('text', $row[37]),
288 'success_status' => array('text', $row[38]),
289 'suspend_data' => array('clob', $row[39]),
290 'total_time' => array('text', $row[40]),
291 'user_id' => array('integer', $userId),
292 'c_timestamp' => array('timestamp', date('Y-m-d H:i:s')),
293 'additional_tables' => array('integer', $i_check)
294 );
295
296 if ($b_node_update == false) {
297 $ilDB->insert(
'cmi_node', $a_data);
298 $ilLog->debug("inserted");
299 } else {
300 $ilDB->update(
'cmi_node', $a_data, array(
'cmi_node_id' => array(
'integer', $cmi_node_id)));
301 $ilLog->debug("updated");
302 }
303
304 if ($b_node_update == true) {
305
306 if ($i_set > 7) {
307 $i_set -= 8;
308 if ($getComments) {
309 $q =
'DELETE FROM cmi_comment WHERE cmi_node_id = %s';
310 $ilDB->manipulateF(
$q, array(
'integer'), array($cmi_node_id));
311 }
312 }
313 if ($i_set > 3) {
314 $i_set -= 4;
315 if ($getInteractions) {
317 DELETE cmir
318 FROM cmi_correct_response cmir
319 INNER JOIN cmi_interaction cmii ON cmii.cmi_interaction_id = cmir.cmi_interaction_id
320 WHERE cmii.cmi_node_id = %s
321 ';
322 $ilDB->manipulateF(
$q, array(
'integer'), array($cmi_node_id));
323 }
324 }
325 if ($i_set > 1) {
326 $i_set -= 2;
327 if ($getInteractions) {
328 $q =
'DELETE FROM cmi_interaction WHERE cmi_node_id = %s';
329 $ilDB->manipulateF(
$q, array(
'integer'), array($cmi_node_id));
330 }
331 }
332 if ($i_set > 0) {
333 $i_set = 0;
334 if ($getObjectives) {
335 $q =
'DELETE FROM cmi_objective WHERE cmi_node_id = %s';
336 $ilDB->manipulateF(
$q, array(
'integer'), array($cmi_node_id));
337 }
338 }
339
340 }
341
342 $result[(string) $row[19]] = $cmi_node_id;
343 break;
344
345 case 'comment':
346 $row[0] =
$ilDB->nextId(
'cmi_comment');
347
348 $ilDB->insert(
'cmi_comment', array(
349 'cmi_comment_id' => array('integer', $row[0]),
350 'cmi_node_id' => array('integer', $cmi_node_id),
351 'c_comment' => array('clob', $row[2]),
352 'c_timestamp' => array('text', $row[3]),
353 'location' => array('text', $row[4]),
354 'sourceislms' => array('integer', $row[5])
355 ));
356 break;
357
358 case 'interaction':
359 $cmi_interaction_id =
$ilDB->nextId(
'cmi_interaction');
360 $a_map_cmi_interaction_id[] = array($row[0], $cmi_interaction_id);
361 $ilDB->insert(
'cmi_interaction', array(
362 'cmi_interaction_id' => array('integer', $cmi_interaction_id),
363 'cmi_node_id' => array('integer', $cmi_node_id),
364 'description' => array('clob', $row[2]),
365 'id' => array('text', $row[3]),
366 'latency' => array('text', $row[4]),
367 'learner_response' => array('clob', $row[5]),
368 'result' => array('text', $row[6]),
369 'c_timestamp' => array('text', $row[7]),
370 'c_type' => array('text', $row[8]),
371 'weighting' => array('float', $row[9])
372 ));
373 break;
374
375 case 'objective':
376 $row[2] =
$ilDB->nextId(
'cmi_objective');
377 $cmi_interaction_id = null;
378 if ($row[0] != null) {
379 foreach ($a_map_cmi_interaction_id as $i => $value) {
380 if ($row[0] == $value[0]) {
381 $cmi_interaction_id = $value[1];
382 }
383 }
384 }
385 $ilDB->insert(
'cmi_objective', array(
386 'cmi_interaction_id' => array('integer', $cmi_interaction_id),
387 'cmi_node_id' => array('integer', $cmi_node_id),
388 'cmi_objective_id' => array('integer', $row[2]),
389 'completion_status' => array('text', $row[3]),
390 'description' => array('clob', $row[4]),
391 'id' => array('text', $row[5]),
392 'c_max' => array('float', $row[6]),
393 'c_min' => array('float', $row[7]),
394 'c_raw' => array('float', $row[8]),
395 'scaled' => array('float', $row[9]),
396 'progress_measure' => array('float', $row[10]),
397 'success_status' => array('text', $row[11]),
398 'scope' => array('text', $row[12])
399 ));
400 break;
401
402 case 'correct_response':
403 $cmi_interaction_id = null;
404 if ($row[1] !== null) {
405 foreach ($a_map_cmi_interaction_id as $i => $value) {
406 if ($row[1] == $value[0]) {
407 $cmi_interaction_id = $value[1];
408 }
409 }
410 $row[0] =
$ilDB->nextId(
'cmi_correct_response');
411 $ilDB->insert(
'cmi_correct_response', array(
412 'cmi_correct_resp_id' => array('integer', $row[0]),
413 'cmi_interaction_id' => array('integer', $cmi_interaction_id),
414 'pattern' => array('text', $row[2])
415 ));
416 }
417 break;
418 }
419 }
420 }
421 return $result;
422 }