145    {
  147 
  150 
  152 
  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            
  173            foreach (
$data->$table as &$row) {
 
  174                $ilLog->write(
"Checking table: " . $table);
 
  175 
  176                switch ($table) {
  177                    case 'node': 
  178 
  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                        );
  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)));
 
  246                        }
  247                        
  248                        if ($b_node_update == true) {
  249                            
  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                            
  281                        }
  282                        
  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        }
  363    }