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) {
316 $q = 'DELETE FROM cmi_correct_response
317 WHERE cmi_interaction_id IN (
318 SELECT cmi_interaction.cmi_interaction_id FROM cmi_interaction WHERE cmi_interaction.cmi_node_id = %s)';
319 $ilDB->manipulateF($q, array(
'integer'), array($cmi_node_id));
320 }
321 }
322 if ($i_set > 1) {
323 $i_set -= 2;
324 if ($getInteractions) {
325 $q = 'DELETE FROM cmi_interaction WHERE cmi_node_id = %s';
326 $ilDB->manipulateF($q, array(
'integer'), array($cmi_node_id));
327 }
328 }
329 if ($i_set > 0) {
330 $i_set = 0;
331 if ($getObjectives) {
332 $q = 'DELETE FROM cmi_objective WHERE cmi_node_id = %s';
333 $ilDB->manipulateF($q, array(
'integer'), array($cmi_node_id));
334 }
335 }
336
337 }
338
339 $result[(string) $row[19]] = $cmi_node_id;
340 break;
341
342 case 'comment':
343 $row[0] =
$ilDB->nextId(
'cmi_comment');
344
345 $ilDB->insert(
'cmi_comment', array(
346 'cmi_comment_id' => array('integer', $row[0]),
347 'cmi_node_id' => array('integer', $cmi_node_id),
348 'c_comment' => array('clob', $row[2]),
349 'c_timestamp' => array('text', $row[3]),
350 'location' => array('text', $row[4]),
351 'sourceislms' => array('integer', $row[5])
352 ));
353 break;
354
355 case 'interaction':
356 $cmi_interaction_id =
$ilDB->nextId(
'cmi_interaction');
357 $a_map_cmi_interaction_id[] = array($row[0], $cmi_interaction_id);
358 $ilDB->insert(
'cmi_interaction', array(
359 'cmi_interaction_id' => array('integer', $cmi_interaction_id),
360 'cmi_node_id' => array('integer', $cmi_node_id),
361 'description' => array('clob', $row[2]),
362 'id' => array('text', $row[3]),
363 'latency' => array('text', $row[4]),
364 'learner_response' => array('clob', $row[5]),
365 'result' => array('text', $row[6]),
366 'c_timestamp' => array('text', $row[7]),
367 'c_type' => array('text', $row[8]),
368 'weighting' => array('float', $row[9])
369 ));
370 break;
371
372 case 'objective':
373 $row[2] =
$ilDB->nextId(
'cmi_objective');
374 $cmi_interaction_id = null;
375 if ($row[0] != null) {
376 foreach ($a_map_cmi_interaction_id as
$i => $value) {
377 if ($row[0] == $value[0]) {
378 $cmi_interaction_id = $value[1];
379 }
380 }
381 }
382 $ilDB->insert(
'cmi_objective', array(
383 'cmi_interaction_id' => array('integer', $cmi_interaction_id),
384 'cmi_node_id' => array('integer', $cmi_node_id),
385 'cmi_objective_id' => array('integer', $row[2]),
386 'completion_status' => array('text', $row[3]),
387 'description' => array('clob', $row[4]),
388 'id' => array('text', $row[5]),
389 'c_max' => array('float', $row[6]),
390 'c_min' => array('float', $row[7]),
391 'c_raw' => array('float', $row[8]),
392 'scaled' => array('float', $row[9]),
393 'progress_measure' => array('float', $row[10]),
394 'success_status' => array('text', $row[11]),
395 'scope' => array('text', $row[12])
396 ));
397 break;
398
399 case 'correct_response':
400 $cmi_interaction_id = null;
401 if ($row[1] !== null) {
402 foreach ($a_map_cmi_interaction_id as
$i => $value) {
403 if ($row[1] == $value[0]) {
404 $cmi_interaction_id = $value[1];
405 }
406 }
407 $row[0] =
$ilDB->nextId(
'cmi_correct_response');
408 $ilDB->insert(
'cmi_correct_response', array(
409 'cmi_correct_resp_id' => array('integer', $row[0]),
410 'cmi_interaction_id' => array('integer', $cmi_interaction_id),
411 'pattern' => array('text', $row[2])
412 ));
413 }
414 break;
415 }
416 }
417 }
418 return $result;
419 }