Fix queries in order to use auto_id

1.10.x
Julio Montoya 10 years ago
parent 6ae063d98d
commit e49b2f8d7c
  1. 104
      main/exercice/answer.class.php
  2. 117
      main/exercice/exercise.class.php
  3. 24
      main/exercice/export/aiken/aiken_import.inc.php
  4. 53
      main/exercice/matching.class.php
  5. 32
      main/exercice/question.class.php
  6. 20
      main/exercice/upload_exercise.php
  7. 6
      main/inc/ajax/exercise.ajax.php

@ -31,7 +31,7 @@ class Answer
public $new_position;
public $new_hotspot_coordinates;
public $new_hotspot_type;
public $autoId;
public $nbrAnswers;
public $new_nbrAnswers;
public $new_destination; // id of the next question if feedback option is set to Directfeedback
@ -192,7 +192,7 @@ class Answer
$i = 1;
// while a record is found
$doubt_data = null;
while($object = Database::fetch_object($result)) {
while ($object = Database::fetch_object($result)) {
if ($question_type['type'] == UNIQUE_ANSWER_NO_OPTION && $object->position == 666) {
$doubt_data = $object;
continue;
@ -290,8 +290,10 @@ class Answer
if (Database::num_rows($rs) > 0) {
$row = Database::fetch_array($rs);
return $row;
}
return false;
}
@ -380,6 +382,7 @@ class Answer
return null;
}
$row = Database::fetch_array($res);
return $row['type'];
}
@ -505,27 +508,24 @@ class Answer
* @param string $hotspot_coordinates
* @param string $hotspot_type
*/
public function updateAnswers($answer, $comment, $correct, $weighting, $position, $destination, $hotspot_coordinates, $hotspot_type)
public function updateAnswers($autoId, $answer, $comment, $correct, $weighting, $position, $destination, $hotspot_coordinates, $hotspot_type)
{
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
$idAnswer = $this->selectAnswerId();
$id = $this->getQuestionType() == 3 ? $idAnswer[0] : Database::escape_string($position);
$questionId = $this->questionId;
$answerTable = Database :: get_course_table(TABLE_QUIZ_ANSWER);
//$id = $this->getQuestionType() == FILL_IN_BLANKS ? $idAnswer[0] : Database::escape_string($position);
$autoId = intval($autoId);
$sql = "UPDATE $answerTable SET
answer = '".Database::escape_string($answer)."',
comment = '".Database::escape_string($comment)."',
correct = '".Database::escape_string($correct)."',
ponderation = '".Database::escape_string($weighting)."',
position = '".Database::escape_string($position)."',
destination = '".Database::escape_string($destination)."',
hotspot_coordinates = '".Database::escape_string($hotspot_coordinates)."',
hotspot_type = '".Database::escape_string($hotspot_type)."'
WHERE
id_auto = $autoId";
$sql = "UPDATE $TBL_REPONSES SET
answer = '".Database::escape_string($answer)."',
comment = '".Database::escape_string($comment)."',
correct = '".Database::escape_string($correct)."',
ponderation = '".Database::escape_string($weighting)."',
position = '".Database::escape_string($position)."',
destination = '".Database::escape_string($destination)."',
hotspot_coordinates = '".Database::escape_string($hotspot_coordinates)."',
hotspot_type = '".Database::escape_string($hotspot_type)."'
WHERE
c_id = {$this->course_id} AND
id = '$id' AND
question_id = ".intval($questionId)."";
Database::query($sql);
}
@ -536,11 +536,14 @@ class Answer
*/
public function save()
{
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$answerTable = Database::get_course_table(TABLE_QUIZ_ANSWER);
$questionId = intval($this->questionId);
$c_id = $this->course['real_id'];
for ($i=1;$i <= $this->new_nbrAnswers; $i++) {
$correctList = [];
$answerList = [];
for ($i=1; $i <= $this->new_nbrAnswers; $i++) {
$answer = Database::escape_string($this->new_answer[$i]);
$correct = Database::escape_string($this->new_correct[$i]);
@ -550,22 +553,34 @@ class Answer
$hotspot_coordinates = Database::escape_string($this->new_hotspot_coordinates[$i]);
$hotspot_type = Database::escape_string($this->new_hotspot_type[$i]);
$destination = Database::escape_string($this->new_destination[$i]);
$autoId = $this->selectAutoId($i);
if (!(isset($this->position[$i]))) {
$sql = "INSERT INTO $TBL_REPONSES (c_id, question_id, answer, correct, comment, ponderation, position, hotspot_coordinates, hotspot_type, destination) VALUES ";
$sql .= "($c_id, '$questionId','$answer','$correct','$comment','$weighting','$position','$hotspot_coordinates','$hotspot_type','$destination');";
Database::query($sql);
$id = Database::insert_id();
$params = [
'c_id' => $c_id,
'question_id' => $questionId,
'answer' => $answer,
'correct' => $correct,
'comment' => $comment,
'ponderation' => $weighting,
'position' => $position,
'hotspot_coordinates' => $hotspot_coordinates,
'hotspot_type' => $hotspot_type,
'destination' => $destination
];
$id = Database::insert($answerTable, $params);
if ($id) {
$sql = "UPDATE $TBL_REPONSES SET id = id_auto WHERE id_auto = $id";
$sql = "UPDATE $answerTable SET id = id_auto WHERE id_auto = $id";
Database::query($sql);
$correctList[$id] = array('id' => $i, 'correct' => $correct);
$answerList[$id] = $i;
}
} else {
// https://support.chamilo.org/issues/6558
// function updateAnswers already escape_string, error if we do it twice.
// Feed function updateAnswers with none escaped strings
$this->updateAnswers(
$autoId,
$this->new_answer[$i],
$this->new_comment[$i],
$this->new_correct[$i],
@ -578,11 +593,40 @@ class Answer
}
}
/*if (!empty($correctList)) {
foreach ($correctList as $autoId => $data) {
$correct = $data['correct'];
if ($correct) {
$sql = "UPDATE $answerTable
SET correct = $autoId
WHERE
correct = $correct AND
c_id = $c_id AND
question_id = $questionId
";
Database::query($sql);
}
}
}*/
/*if (!empty($answerList)) {
foreach ($answerList as $autoId => $counterId) {
$sql = "UPDATE $answerTable SET answer = $autoId
WHERE
answer = $counterId AND
c_id = $c_id AND
question_id = $questionId
";
Database::query($sql);
}
}*/
if (count($this->position) > $this->new_nbrAnswers) {
$i = $this->new_nbrAnswers + 1;
while ($this->position[$i]) {
$position = $this->position[$i];
$sql = "DELETE FROM $TBL_REPONSES
$sql = "DELETE FROM $answerTable
WHERE
c_id = {$this->course_id} AND
question_id = '".$questionId."' AND

@ -760,8 +760,8 @@ class Exercise
$description = $this->description;
$sound = $this->sound;
$type = $this->type;
$attempts = $this->attempts;
$feedback_type = $this->feedback_type;
$attempts = isset($this->attempts) ? $this->attempts : 0;
$feedback_type = isset($this->feedback_type) ? $this->feedback_type : 0;
$random = $this->random;
$random_answers = $this->random_answers;
$active = $this->active;
@ -2237,13 +2237,13 @@ class Exercise
$user_answer = '';
// Get answer list for matching
$sql_answer = 'SELECT id, answer FROM '.$table_ans.'
$sql_answer = 'SELECT id_auto, id, answer FROM '.$table_ans.'
WHERE c_id = '.$course_id.' AND question_id = "'.$questionId.'"';
$res_answer = Database::query($sql_answer);
$answer_matching =array();
$answerMatching = array();
while ($real_answer = Database::fetch_array($res_answer)) {
$answer_matching[$real_answer['id']] = $real_answer['answer'];
$answerMatching[$real_answer['id_auto']] = $real_answer['answer'];
}
$real_answers = array();
@ -2261,12 +2261,12 @@ class Exercise
$answerComment = $objAnswerTmp->selectComment($answerId);
$answerCorrect = $objAnswerTmp->isCorrect($answerId);
$answerWeighting = (float)$objAnswerTmp->selectWeighting($answerId);
$numAnswer = $objAnswerTmp->selectAutoId($answerId);
$answerAutoId = $objAnswerTmp->selectAutoId($answerId);
$answer_correct_array[$answerId] = (bool)$answerCorrect;
if ($debug) {
error_log("answer auto id: $numAnswer ");
error_log("answer auto id: $answerAutoId ");
error_log("answer correct: $answerCorrect ");
}
@ -2286,16 +2286,16 @@ class Exercise
$result = Database::query($sql);
$choice = Database::result($result,0,"answer");
$studentChoice = ($choice == $numAnswer)?1:0;
$studentChoice = $choice == $answerAutoId ? 1 : 0;
if ($studentChoice) {
$questionScore+=$answerWeighting;
$totalScore+=$answerWeighting;
$questionScore += $answerWeighting;
$totalScore += $answerWeighting;
}
} else {
$studentChoice = ($choice == $numAnswer) ? 1 : 0;
$studentChoice = $choice == $answerAutoId ? 1 : 0;
if ($studentChoice) {
$questionScore+=$answerWeighting;
$totalScore+=$answerWeighting;
$questionScore += $answerWeighting;
$totalScore += $answerWeighting;
}
}
break;
@ -2318,7 +2318,7 @@ class Exercise
}
}
$studentChoice = isset($choice[$numAnswer]) ? $choice[$numAnswer] : null;
$studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
if (!empty($studentChoice)) {
if ($studentChoice == $answerCorrect) {
@ -2348,14 +2348,14 @@ class Exercise
$choice[$ind] = 1;
}
$studentChoice = isset($choice[$numAnswer]) ? $choice[$numAnswer] : null;
$studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
$real_answers[$answerId] = (bool)$studentChoice;
if ($studentChoice) {
$questionScore +=$answerWeighting;
}
} else {
$studentChoice = isset($choice[$numAnswer]) ? $choice[$numAnswer] : null;
$studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
$real_answers[$answerId] = (bool)$studentChoice;
if (isset($studentChoice)) {
@ -2376,13 +2376,13 @@ class Exercise
$ind = $row['answer'];
$choice[$ind] = 1;
}
$studentChoice = isset($choice[$numAnswer]) ? $choice[$numAnswer] : null;
$studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
$real_answers[$answerId] = (bool)$studentChoice;
if ($studentChoice) {
$questionScore +=$answerWeighting;
}
} else {
$studentChoice = isset($choice[$numAnswer]) ? $choice[$numAnswer] : null;
$studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
if (isset($studentChoice)) {
$questionScore += $answerWeighting;
}
@ -2403,8 +2403,7 @@ class Exercise
$option = $result[1];
$choice[$my_answer_id] = $option;
}
$numAnswer = $objAnswerTmp->selectAutoId($answerId);
$studentChoice = $choice[$numAnswer];
$studentChoice = $choice[$answerAutoId];
if ($answerCorrect == $studentChoice) {
//$answerCorrect = 1;
@ -2414,7 +2413,7 @@ class Exercise
$real_answers[$answerId] = false;
}
} else {
$studentChoice = $choice[$numAnswer];
$studentChoice = $choice[$answerAutoId];
if ($answerCorrect == $studentChoice) {
//$answerCorrect = 1;
$real_answers[$answerId] = true;
@ -2433,8 +2432,7 @@ class Exercise
$ind = $row['answer'];
$choice[$ind] = 1;
}
$numAnswer=$objAnswerTmp->selectAutoId($answerId);
$studentChoice = isset($choice[$numAnswer]) ? $choice[$numAnswer] : null;
$studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
if ($answerCorrect == 1) {
if ($studentChoice) {
@ -2450,7 +2448,7 @@ class Exercise
}
}
} else {
$studentChoice = isset($choice[$numAnswer]) ? $choice[$numAnswer] : null;
$studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
if ($answerCorrect == 1) {
if ($studentChoice) {
$real_answers[$answerId] = true;
@ -2762,50 +2760,59 @@ class Exercise
break;
case MATCHING:
if ($from_database) {
$sql_answer = 'SELECT id, answer, id_auto FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id="'.$questionId.'" AND correct = 0';
$res_answer = Database::query($sql_answer);
$sql = 'SELECT id, answer, id_auto
FROM '.$table_ans.'
WHERE
c_id = '.$course_id.' AND
question_id = "'.$questionId.'" AND
correct = 0';
$res_answer = Database::query($sql);
// Getting the real answer
$real_list = array();
while ($real_answer = Database::fetch_array($res_answer)) {
$real_list[$real_answer['id']] = $real_answer['answer'];
$real_list[$real_answer['id_auto']] = $real_answer['answer'];
}
$sql_select_answer = 'SELECT id, answer, correct, id_auto, ponderation FROM '.$table_ans.'
WHERE c_id = '.$course_id.' AND question_id="'.$questionId.'" AND correct <> 0
ORDER BY id_auto';
$res_answers = Database::query($sql_select_answer);
$sql = 'SELECT id, answer, correct, id_auto, ponderation
FROM '.$table_ans.'
WHERE
c_id = '.$course_id.' AND
question_id="'.$questionId.'" AND
correct <> 0
ORDER BY id_auto';
$res_answers = Database::query($sql);
$questionScore = 0;
while ($a_answers = Database::fetch_array($res_answers)) {
$i_answer_id = $a_answers['id']; //3
$i_answer_id = $a_answers['id']; //3
$s_answer_label = $a_answers['answer']; // your daddy - your mother
$i_answer_correct_answer = $a_answers['correct']; //1 - 2
$i_answer_id_auto = $a_answers['id_auto']; // 3 - 4
$sql_user_answer = "SELECT answer FROM $TBL_TRACK_ATTEMPT
WHERE exe_id = '$exeId' AND question_id = '$questionId' AND position = '$i_answer_id_auto'";
$res_user_answer = Database::query($sql_user_answer);
$sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT
WHERE
exe_id = '$exeId' AND
question_id = '$questionId' AND
position = '$i_answer_id_auto'";
$res_user_answer = Database::query($sql);
if (Database::num_rows($res_user_answer)>0 ) {
if (Database::num_rows($res_user_answer) > 0) {
$s_user_answer = Database::result($res_user_answer, 0, 0); // rich - good looking
//$s_user_answer = Database::result($res_user_answer, 0, 1); // rich - good looking
} else {
$s_user_answer = 0;
}
//$i_answerWeighting = $objAnswerTmp->selectWeighting($i_answer_id);
$i_answerWeighting = $a_answers['ponderation'];
$user_answer = '';
if (!empty($s_user_answer)) {
if ($s_user_answer == $i_answer_correct_answer) {
$questionScore += $i_answerWeighting;
$totalScore += $i_answerWeighting;
$user_answer = '<span>'.$real_list[$i_answer_id].'</span>';
$questionScore += $i_answerWeighting;
$totalScore += $i_answerWeighting;
if (isset($real_list[$i_answer_id])) {
$user_answer = '<span>'.$real_list[$i_answer_id].'</span>';
}
} else {
$user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$real_list[$s_user_answer].'</span>';
}
@ -2824,19 +2831,18 @@ class Exercise
}
break(2); // break the switch and the "for" condition
} else {
$numAnswer = $objAnswerTmp->selectAutoId($answerId);
if ($answerCorrect) {
if ($answerCorrect == $choice[$numAnswer]) {
if ($answerCorrect == $choice[$answerAutoId]) {
$questionScore += $answerWeighting;
$totalScore += $answerWeighting;
$user_answer = '<span>'.$answer_matching[$choice[$numAnswer]].'</span>';
$user_answer = '<span>'.$answerMatching[$choice[$answerAutoId]].'</span>';
} else {
if (isset($answer_matching[$choice[$numAnswer]])) {
$user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$answer_matching[$choice[$numAnswer]].'</span>';
if (isset($answerMatching[$choice[$answerAutoId]])) {
$user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$answerMatching[$choice[$answerAutoId]].'</span>';
}
}
$matching[$numAnswer] = $choice[$numAnswer];
$matching[$answerAutoId] = $choice[$answerAutoId];
}
break;
}
@ -3116,11 +3122,10 @@ class Exercise
}
}
} elseif($answerType == MATCHING) {
// if ($origin != 'learnpath') {
echo '<tr>';
echo '<td>'.$answer_matching[$answerId].'</td><td>'.$user_answer.' / <b><span style="color: #008000;">'.$answer_matching[$answerCorrect].'</span></b></td>';
echo '<td>'.$answerMatching[$answerId].'</td>';
echo '<td>'.$user_answer.' / <b><span style="color: #008000;">'.$answerMatching[$answerCorrect].'</span></b></td>';
echo '</tr>';
//}
}
}
} else {
@ -3319,11 +3324,11 @@ class Exercise
ExerciseShowFunctions::display_hotspot_order_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment);
break;
case MATCHING:
// if ($origin != 'learnpath') {
echo '<tr>';
echo '<td>'.$answer_matching[$answerId].'</td><td>'.$user_answer.' / <b><span style="color: #008000;">'.$answer_matching[$answerCorrect].'</span></b></td>';
echo '<td>'.$answerMatching[$answerId].'</td>';
echo '<td>'.$user_answer.' / <b><span style="color: #008000;">'.$answerMatching[$answerCorrect].'</span></b></td>';
echo '</tr>';
//}
break;
}
}

@ -173,15 +173,20 @@ function aiken_import_exercise($file)
$question->type = $question_array['type'];
$question->setAnswer();
$question->updateTitle($question_array['title']);
$question->updateDescription($question_array['description']);
if (isset($question_array['description'])) {
$question->updateDescription($question_array['description']);
}
$type = $question->selectType();
$question->type = constant($type);
$question->save($last_exercise_id);
$last_question_id = $question->selectId();
//3.create answer
//3. Create answer
$answer = new Answer($last_question_id);
$answer->new_nbrAnswers = count($question_array['answer']);
$max_score = 0;
foreach ($question_array['answer'] as $key => $answers) {
$key++;
$answer->new_answer[$key] = $answers['value'];
@ -189,19 +194,26 @@ function aiken_import_exercise($file)
// Correct answers ...
if (in_array($key, $question_array['correct_answers'])) {
$answer->new_correct[$key] = 1;
$answer->new_comment[$key] = $question_array['feedback'];
if (isset($question_array['feedback'])) {
$answer->new_comment[$key] = $question_array['feedback'];
}
} else {
$answer->new_correct[$key] = 0;
}
$answer->new_weighting[$key] = $question_array['weighting'][$key - 1];
$max_score += $question_array['weighting'][$key - 1];
if (isset($question_array['weighting'][$key - 1])) {
$answer->new_weighting[$key] = $question_array['weighting'][$key - 1];
$max_score += $question_array['weighting'][$key - 1];
}
}
$answer->save();
// Now that we know the question score, set it!
$question->updateWeighting($max_score);
$question->save();
}
// delete the temp dir where the exercise was unzipped
// Delete the temp dir where the exercise was unzipped
my_delete($baseWorkDir . $uploadPath);
$operation = $last_exercise_id;
}

@ -34,23 +34,43 @@ class Matching extends Question
{
$defaults = array();
$nb_matches = $nb_options = 2;
$matches = array();
$answer = null;
if (isset($this->id)) {
$answer = new Answer($this->id);
$answer->read();
if (count($answer->nbrAnswers) > 0) {
$counter = 1;
for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
$correct = $answer->isCorrect($i);
if (empty($correct)) {
$matches[$answer->selectAutoId($i)] = chr(64 + $counter);
$counter++;
}
}
}
}
if ($form->isSubmitted()) {
$nb_matches = $form->getSubmitValue('nb_matches');
$nb_options = $form->getSubmitValue('nb_options');
if (isset($_POST['lessMatches']))
if (isset($_POST['lessMatches'])) {
$nb_matches--;
if (isset($_POST['moreMatches']))
}
if (isset($_POST['moreMatches'])) {
$nb_matches++;
if (isset($_POST['lessOptions']))
}
if (isset($_POST['lessOptions'])) {
$nb_options--;
if (isset($_POST['moreOptions']))
}
if (isset($_POST['moreOptions'])) {
$nb_options++;
}
} else if (!empty($this->id)) {
$answer = new Answer($this->id);
$answer->read();
if (count($answer->nbrAnswers) > 0) {
$a_matches = $a_options = array();
$nb_matches = $nb_options = 0;
for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
if ($answer->isCorrect($i)) {
@ -71,9 +91,12 @@ class Matching extends Question
$defaults['option[1]'] = get_lang('DefaultMatchingOptA');
$defaults['option[2]'] = get_lang('DefaultMatchingOptB');
}
$a_matches = array();
for ($i = 1; $i <= $nb_options; ++$i) {
$a_matches[$i] = chr(64 + $i); // fill the array with A, B, C.....
if (empty($matches)) {
for ($i = 1; $i <= $nb_options; ++$i) {
// fill the array with A, B, C.....
$matches[$i] = chr(64 + $i);
}
}
$form->addElement('hidden', 'nb_matches', $nb_matches);
@ -119,7 +142,8 @@ class Matching extends Question
$form->addHtml("<td>$i</td>");
$form->addText("answer[$i]", null);
$form->addSelect("matches[$i]", null, $a_matches);
$form->addSelect("matches[$i]", null, $matches);
$form->addText("weighting[$i]", null, true, ['value' => 10]);
$form->addHtml('</tr>');
@ -171,7 +195,7 @@ class Matching extends Question
$form->addHtml('</table>');
$group = array();
global $text, $class;
global $text;
// setting the save button here and not in the question class.php
$group[] = $form->addButtonDelete(get_lang('DelElem'), 'lessOptions', true);
@ -209,14 +233,14 @@ class Matching extends Question
$objAnswer = new Answer($this->id);
// insert the options
// Insert the options
for ($i = 1; $i <= $nb_options; ++$i) {
$position++;
$option = $form->getSubmitValue('option['.$i.']');
$objAnswer->createAnswer($option, 0, '', 0, $position);
}
// insert the answers
// Insert the answers
for ($i = 1; $i <= $nb_matches; ++$i) {
$position++;
$answer = $form->getSubmitValue('answer['.$i.']');
@ -234,6 +258,7 @@ class Matching extends Question
$objAnswer->save();
$this->save();
exit;
}
/**

@ -1256,7 +1256,6 @@ abstract class Question
</style>';
echo '<script>
// hack to hide http://cksource.com/forums/viewtopic.php?f=6&t=8700
function FCKeditor_OnComplete( editorInstance ) {
if (document.getElementById ( \'HiddenFCK\' + editorInstance.Name )) {
HideFCKEditorByInstanceName (editorInstance.Name);
@ -1270,23 +1269,6 @@ abstract class Question
}
}
// hub 13-12-2010
function visiblerDevisibler(in_id) {
if (document.getElementById(in_id)) {
if (document.getElementById(in_id).style.display == "none") {
document.getElementById(in_id).style.display = "block";
if (document.getElementById(in_id+"Img")) {
document.getElementById(in_id+"Img").src = "../img/div_hide.gif";
}
}
else {
document.getElementById(in_id).style.display = "none";
if (document.getElementById(in_id+"Img")) {
document.getElementById(in_id+"Img").src = "../img/div_show.gif";
}
}
}
}
</script>';
// question name
@ -1326,10 +1308,6 @@ abstract class Question
$select_level = Question::get_default_levels();
$form->addElement('select', 'questionLevel', get_lang('Difficulty'), $select_level);
// Categories
//$category_list = TestCategory::getCategoriesIdAndName();
//$form->addElement('select', 'questionCategory', get_lang('Category'), $category_list, array('multiple' => 'multiple'));
// Categories
$tabCat = TestCategory::getCategoriesIdAndName();
$form->addElement('select', 'questionCategory', get_lang('Category'), $tabCat);
@ -1344,7 +1322,7 @@ abstract class Question
//$form->addElement('select', 'parent_id', get_lang('AttachToMedia'), $course_medias);
}
$form->addElement ('html','</div>');
$form->addElement('html','</div>');
if (!isset($_GET['fromExercise'])) {
switch ($answerType) {
@ -1377,10 +1355,7 @@ abstract class Question
$defaults['questionLevel'] = $this->level;
$defaults['questionCategory'] = $this->category;
//$defaults['questionCategory'] = $this->category_list;
//$defaults['parent_id'] = $this->parent_id;
//Came from he question pool
// Came from he question pool
if (isset($_GET['fromExercise'])) {
$form->setDefaults($defaults);
}
@ -1401,7 +1376,6 @@ abstract class Question
*/
public function processCreation($form, $objExercise = null)
{
//$this->updateParentId($form->getSubmitValue('parent_id'));
$this->updateTitle($form->getSubmitValue('questionName'));
$this->updateDescription($form->getSubmitValue('questionDescription'));
$this->updateLevel($form->getSubmitValue('questionLevel'));
@ -1678,7 +1652,7 @@ abstract class Question
$question_id = Database::insert_id();
if ($question_id) {
$sql = "UPDATE $tbl_quiz_question SET id = iid WHERE iid = $id";
$sql = "UPDATE $tbl_quiz_question SET id = iid WHERE iid = $question_id";
Database::query($sql);
// Get the max question_order

@ -446,21 +446,23 @@ function lp_upload_quiz_action_handling() {
* @param array $answers_data
* @return int
*/
function detectQuestionType($answers_data) {
function detectQuestionType($answers_data)
{
$correct = 0;
$isNumeric = false;
foreach ($answers_data as $answer_data) {
if (strtolower($answer_data[3]) == 'x') {
$correct++;
} else {
if (is_numeric($answer_data[3])) {
$isNumeric = true;
if (!empty($answers_data)) {
foreach ($answers_data as $answer_data) {
if (strtolower($answer_data[3]) == 'x') {
$correct++;
} else {
if (is_numeric($answer_data[3])) {
$isNumeric = true;
}
}
}
}
$type = '';
if ($correct == 1) {
$type = UNIQUE_ANSWER;
} else if ($correct > 1) {

@ -286,11 +286,11 @@ switch ($action) {
} else {
// We know the user we get the exe_id.
$exe_id = $exercise_stat_info['exe_id'];
$total_score = $exercise_stat_info['exe_result'];
$exe_id = $exercise_stat_info['exe_id'];
$total_score = $exercise_stat_info['exe_result'];
//Getting the list of attempts
$attempt_list = Event::getAllExerciseEventByExeId($exe_id);
$attempt_list = Event::getAllExerciseEventByExeId($exe_id);
}
// Updating Reminder algorythm.

Loading…
Cancel
Save