Fix queries in order to use auto_id

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

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

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

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

@ -1256,7 +1256,6 @@ abstract class Question
</style>'; </style>';
echo '<script> echo '<script>
// hack to hide http://cksource.com/forums/viewtopic.php?f=6&t=8700 // hack to hide http://cksource.com/forums/viewtopic.php?f=6&t=8700
function FCKeditor_OnComplete( editorInstance ) { function FCKeditor_OnComplete( editorInstance ) {
if (document.getElementById ( \'HiddenFCK\' + editorInstance.Name )) { if (document.getElementById ( \'HiddenFCK\' + editorInstance.Name )) {
HideFCKEditorByInstanceName (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>'; </script>';
// question name // question name
@ -1326,10 +1308,6 @@ abstract class Question
$select_level = Question::get_default_levels(); $select_level = Question::get_default_levels();
$form->addElement('select', 'questionLevel', get_lang('Difficulty'), $select_level); $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 // Categories
$tabCat = TestCategory::getCategoriesIdAndName(); $tabCat = TestCategory::getCategoriesIdAndName();
$form->addElement('select', 'questionCategory', get_lang('Category'), $tabCat); $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('select', 'parent_id', get_lang('AttachToMedia'), $course_medias);
} }
$form->addElement ('html','</div>'); $form->addElement('html','</div>');
if (!isset($_GET['fromExercise'])) { if (!isset($_GET['fromExercise'])) {
switch ($answerType) { switch ($answerType) {
@ -1377,10 +1355,7 @@ abstract class Question
$defaults['questionLevel'] = $this->level; $defaults['questionLevel'] = $this->level;
$defaults['questionCategory'] = $this->category; $defaults['questionCategory'] = $this->category;
//$defaults['questionCategory'] = $this->category_list; // Came from he question pool
//$defaults['parent_id'] = $this->parent_id;
//Came from he question pool
if (isset($_GET['fromExercise'])) { if (isset($_GET['fromExercise'])) {
$form->setDefaults($defaults); $form->setDefaults($defaults);
} }
@ -1401,7 +1376,6 @@ abstract class Question
*/ */
public function processCreation($form, $objExercise = null) public function processCreation($form, $objExercise = null)
{ {
//$this->updateParentId($form->getSubmitValue('parent_id'));
$this->updateTitle($form->getSubmitValue('questionName')); $this->updateTitle($form->getSubmitValue('questionName'));
$this->updateDescription($form->getSubmitValue('questionDescription')); $this->updateDescription($form->getSubmitValue('questionDescription'));
$this->updateLevel($form->getSubmitValue('questionLevel')); $this->updateLevel($form->getSubmitValue('questionLevel'));
@ -1678,7 +1652,7 @@ abstract class Question
$question_id = Database::insert_id(); $question_id = Database::insert_id();
if ($question_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); Database::query($sql);
// Get the max question_order // Get the max question_order

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

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

Loading…
Cancel
Save