function LoadQuestionBase($store, $q_row, $o_rows) { // store id that we loaded as so can be referenced later $store->load_id = $q_row['q_id']; // load in things common to all questions $store->leadin = $q_row['leadin']; $store->theme = $q_row['theme']; $store->notes = $q_row['notes']; $store->q_group = isset($q_row['q_group']) ? $q_row['q_group'] : ''; $store->bloom = $q_row['bloom']; $store->score_method = $q_row['score_method']; if ($q_row['ownerID'] > 0) { $store->author = GetAuthorName($q_row['ownerID']); } // Get keywords for question $db = new Database(); $db->SetTable('keywords_user', 'ku'); $db->AddField('keyword'); $db->AddInnerJoin('keywords_question', 'kq', 'id', 'keywordID'); $db->AddWhere('kq.q_id', $q_row['q_id'], 'i'); $o_rows = $db->GetMultiRow(); $keywords = array(); if (count($o_rows) > 0) { $keywords[] = $o_rows[0]['keyword']; for ($i = 1; $i < count($o_rows); $i++) { $keywords[] = $o_rows[$i]['keyword']; } } $store->keywords = $keywords; // standard media, gets cleared for extmatch $this->AddMedia($store, $q_row['q_media'], $q_row['q_media_width'], $q_row['q_media_height']); $store->status = $this->statuses[$q_row['status']]; }
function Save($params, &$data) { global $mysqli, $string; echo "<h4>{$string['params']}</h4>"; print_p($params); echo "<h4>{$string['othherdebug']}</h4>"; $this->db = new Database(); if (count($data->questions) == 0) { $this->AddError($string['noquestions']); return; } $paperid = $params->paper; $userObj = UserObject::get_instance(); $userID = $userObj->get_user_ID(); $db = new Database(); $db->SetTable('properties'); $db->AddField('*'); $db->AddWhere('property_id', $paperid, 'i'); $paper_row = $db->GetSingleRow(); $ownerid = $userID; $data->ownerID = $userID; $nextscreen = 1; $nextid = 1; if ($paperid) { echo "{$string['addingtopaper']} {$paperid}<br>"; $this->db->SetTable('papers'); $this->db->AddField("max(screen) as screen"); $this->db->AddField("max(display_pos) as display_pos"); $this->db->AddWhere('paper', $paperid, 'i'); $curpos = $this->db->GetSingleRow(); $nextscreen = $curpos['screen'] + 1; $nextid = $curpos['display_pos'] + 1; } /* // Get the actual ID of the module $this->db->SetTable('modules'); $this->db->AddField('id'); // Temp fix - if more than one team just get the first. Avoids error but doesn't fix the problem completely if (strpos($q_group, ',') !== false) { $q_group = strstr($q_group, ',', true); } $this->db->AddWhere('moduleid', $q_group, 's'); $module_row = $this->db->GetSingleRow(); */ $module_id = -1; $paperutils = Paper_utils::get_instance(); $module_id1 = $paperutils->get_modules($paper_row['property_id'], $mysqli); if ($module_id1 !== false) { $module_id = $module_id1; } $modutils = module_utils::get_instance(); $q_group = $modutils->get_moduleid_from_id($module_id, $mysqli); if ($module_id !== false) { // Get a list of the team and user's keywords $user_keywords = array(); if (is_array($module_id)) { foreach (array_keys($module_id) as $mod_id) { $user_keywordsl = $this->GetExistingKeywords($mod_id); $user_keywords = array_merge($user_keywords, $user_keywordsl); } } else { $user_keywords = $this->GetExistingKeywords($module_id); } } foreach ($data->questions as &$question) { $this->q_row = $this->db->GetBlankTableRow("questions"); $this->o_row = $this->db->GetBlankTableRow("options"); $this->o_rows = array(); // stuff from parameters $this->q_row['ownerID'] = $ownerid; // general stuff that needs to be done for every qtype $this->q_row['creation_date'] = date("Y-m-d H:i:s"); $this->q_row['last_edited'] = date("Y-m-d H:i:s"); $this->q_row['q_type'] = $question->type; $this->q_row['status'] = isset($this->statuses[$question->status]) ? $this->statuses[$question->status] : $this->default_status; $this->q_row['theme'] = $question->theme; $this->q_row['notes'] = $question->notes; $this->q_row['leadin'] = $question->leadin; $this->q_row['bloom'] = $question->bloom; $this->q_row['q_media'] = $question->media; $this->q_row['q_media_width'] = $question->media_width; $this->q_row['q_media_height'] = $question->media_height; $this->q_row['deleted'] = null; $this->q_row['locked'] = null; $this->q_row['std'] = null; $this->q_row['q_option_order'] = $question->q_option_order; if (isset($question->settings)) { $this->q_row['settings'] = $question->settings; } $oiii = print_r($question, true); $t = 8; if ($question->type == "blank") { $this->SaveBlank($question); } elseif ($question->type == "calculation") { $this->SaveCalculation($question); $this->q_row['q_type'] = 'enhancedcalc'; } elseif ($question->type == "dichotomous") { $this->SaveDichotomous($question); } elseif ($question->type == "extmatch") { $this->SaveExtMatch($question); } elseif ($question->type == "flash") { $this->SaveFlash($question); } elseif ($question->type == "hotspot") { $this->SaveHotspot($question); } elseif ($question->type == "info") { $this->SaveInfo($question); } elseif ($question->type == "labelling") { $this->SaveLabelling($question); } elseif ($question->type == "likert") { $this->SaveLikert($question); } elseif ($question->type == "matrix") { $this->SaveMatrix($question); } elseif ($question->type == "mcq") { $this->SaveMcq($question); } elseif ($question->type == "true_false") { $this->SaveTrueFalse($question); } elseif ($question->type == "mrq") { $this->SaveMrq($question); } elseif ($question->type == "rank") { $this->SaveRank($question); } elseif ($question->type == "textbox") { $this->SaveTextbox($question); } else { $this->AddError("Question type " . $question->type . " not yet supported", $question->load_id); continue; } if (!in_array($this->q_row['q_option_order'], array('display order', 'alphabetic', 'random'))) { $this->q_row['q_option_order'] = 'display order'; print "correcting q_option_order"; } if (!empty($this->q_row['scenario']) && strcasecmp("<p> </p>", $this->q_row['scenario']) == 0) { $this->q_row['scenario'] = ''; } // create plain version of scenario and leadin $this->q_row['scenario_plain'] = empty($this->q_row['scenario']) ? '' : trim(strip_tags($this->q_row['scenario'])); $this->q_row['leadin_plain'] = empty($this->q_row['leadin']) ? '' : trim(strip_tags($this->q_row['leadin'])); if (!empty($this->q_row['correct_fback']) && !empty($this->q_row['incorrect_fback']) && $this->q_row['correct_fback'] == $this->q_row['incorrect_fback']) { $this->q_row['incorrect_fback'] = ''; } // if no o_row, create a blank one if (count($this->o_rows) == 0 and $question->type != "calculation") { $this->o_row['marks_correct'] = 1; $this->o_row['marks_incorrect'] = 0; $this->o_row['marks_partial'] = 0; $this->o_rows[] = $this->o_row; } // store question row $this->db->InsertRow("questions", "q_id", $this->q_row); $question->save_id = $this->q_row['q_id']; $this->qm_row = $this->db->GetBlankTableRow("questions_modules"); $this->qm_row['q_id'] = $this->q_row['q_id']; if (is_array($module_id)) { foreach (array_keys($module_id) as $mod_id) { $this->qm_row['idMod'] = $mod_id; $this->db->InsertRow("questions_modules", "temp", $this->qm_row); } } else { $this->qm_row['idMod'] = $module_id; $this->db->InsertRow("questions_modules", "temp", $this->qm_row); } $new_keywords = array(); if ($module_id != -1) { if (is_array($module_id)) { $user_keywords2 = array(); foreach (array_keys($module_id) as $mod_id) { $new_keywords1 = $this->SaveKeywords($this->q_row['q_id'], $question->keywords, $mod_id, $user_keywords, $user_keywords2); $new_keywords = array_merge($new_keywords, $new_keywords1); } $user_keywords = array_merge($user_keywords, $user_keywords2); } else { $new_keywords = $this->SaveKeywords($this->q_row['q_id'], $question->keywords, $module_id, $user_keywords); } } // store option rows foreach ($this->o_rows as &$o_row) { $o_row['o_id'] = $this->q_row['q_id']; if (!empty($o_row['feedback_right']) && $o_row['feedback_right'] == $o_row['feedback_wrong']) { $o_row['feedback_wrong'] = ""; } $this->db->InsertRow("options", "id_num", $o_row); } // store additional metadata if ($question->load_id != '') { $meta_row = array('id' => null, 'questionID' => $question->save_id, 'type' => 'QTI Ident', 'value' => $question->load_id); } $this->db->InsertRow("questions_metadata", "id", $meta_row); echo "<h4>{$string['questiontables']}</h4>"; echo "<div>{$string['questionsrow']}</div>"; print_p($this->q_row, false); echo "<div>{$string['optionsrows']}</div>"; print_p($this->o_rows, false, 100); echo "<div>{$string['newkeywords']}</div>"; print_p($new_keywords, false); $track = array(); $track['type'] = $string['qtiimport']; $track['typeID'] = $this->q_row['q_id']; $track['editor'] = $userID; $track['new'] = "{$string['imported1_2']} " . $params->original_filename; $track['part'] = "all"; $track['changed'] = date("Y-m-d H:i:s"); $db->InsertRow("track_changes", "id", $track); // we have a paper, add this question onto the list of questions for the paper if ($paperid && empty($data->papers)) { $p_row = $this->db->GetBlankTableRow('papers'); $p_row['paper'] = $paperid; $p_row['question'] = $question->save_id; $p_row['screen'] = $nextscreen; $p_row['display_pos'] = $nextid++; $this->db->InsertRow('papers', 'p_id', $p_row); } } $logger = new Logger($mysqli); if (!empty($data->papers)) { foreach ($data->papers as &$paper) { foreach ($paper->screens as &$screen) { foreach ($screen->question_ids as $q_id) { $p_row = $this->db->GetBlankTableRow('papers'); echo sprintf($string['addingquestiondetails'], $q_id, $nextid, $nextscreen) . '<br>'; $p_row['paper'] = $paperid; $q = FindQuestion($data->questions, $q_id); $p_row['question'] = $q->save_id; $p_row['screen'] = $nextscreen; $p_row['display_pos'] = $nextid++; $this->db->InsertRow('papers', 'p_id', $p_row); $logger->track_change('Paper', $paperid, $userID, '', $q_id, 'Add Question (from QTI)'); } $nextscreen++; } } } }