Minor - fixes PHP warnings.

1.9.x
Julio Montoya 11 years ago
parent 993c959981
commit 7787500132
  1. 64
      main/exercice/answer.class.php
  2. 125
      main/exercice/exercise.class.php
  3. 17
      main/exercice/exercise_result.php

@ -99,35 +99,39 @@ class Answer
} }
/** /**
* Reads answer informations from the data base * Reads answer information from the database
* *
* @author - Olivier Brouckaert * @author - Olivier Brouckaert
*/ */
function read() { public function read()
{
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
$questionId = $this->questionId; $questionId = $this->questionId;
$sql="SELECT id, id_auto, answer,correct,comment,ponderation, position, hotspot_coordinates, hotspot_type, destination FROM $sql = "SELECT * FROM $TBL_ANSWER
$TBL_ANSWER WHERE c_id = {$this->course_id} AND question_id ='".$questionId."' ORDER BY position"; WHERE
c_id = {$this->course_id} AND
question_id ='".$questionId."'
ORDER BY position";
$result = Database::query($sql); $result = Database::query($sql);
$i=1; $i=1;
// while a record is found // while a record is found
while ($object=Database::fetch_object($result)) { while ($object = Database::fetch_object($result)) {
$this->id[$i] = $object->id; $this->id[$i] = $object->id;
$this->answer[$i] = $object->answer; $this->answer[$i] = $object->answer;
$this->correct[$i] = $object->correct; $this->correct[$i] = $object->correct;
$this->comment[$i] = $object->comment; $this->comment[$i] = $object->comment;
$this->weighting[$i] = $object->ponderation; $this->weighting[$i] = $object->ponderation;
$this->position[$i] = $object->position; $this->position[$i] = $object->position;
$this->hotspot_coordinates[$i] = $object->hotspot_coordinates; $this->hotspot_coordinates[$i] = $object->hotspot_coordinates;
$this->hotspot_type[$i] = $object->hotspot_type; $this->hotspot_type[$i] = $object->hotspot_type;
$this->destination[$i] = $object->destination; $this->destination[$i] = $object->destination;
$this->autoId[$i] = $object->id_auto; $this->autoId[$i] = $object->id_auto;
$i++; $i++;
} }
$this->nbrAnswers=$i-1; $this->nbrAnswers = $i-1;
} }
/** /**
@ -136,27 +140,27 @@ class Answer
* @author - Yoselyn Castillo * @author - Yoselyn Castillo
* @return - array - $id (answer ids) * @return - array - $id (answer ids)
*/ */
function selectAnswerId() public function selectAnswerId()
{ {
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
$questionId = $this->questionId; $questionId = $this->questionId;
$sql="SELECT id FROM $sql="SELECT id FROM
$TBL_ANSWER WHERE c_id = {$this->course_id} AND question_id ='".$questionId."'"; $TBL_ANSWER WHERE c_id = {$this->course_id} AND question_id ='".$questionId."'";
$result = Database::query($sql); $result = Database::query($sql);
$id = array(); $id = array();
// while a record is found // while a record is found
if (Database::num_rows($result) > 0) { if (Database::num_rows($result) > 0) {
while ($object = Database::fetch_array($result)) { while ($object = Database::fetch_array($result)) {
$id[] = $object['id']; $id[] = $object['id'];
} }
} }
return $id; return $id;
} }
/** /**
* reads answer informations from the data base ordered by parameter * Reads answer information from the data base ordered by parameter
* @param string Field we want to order by * @param string Field we want to order by
* @param string DESC or ASC * @param string DESC or ASC
* @author Frederic Vauthier * @author Frederic Vauthier
@ -185,10 +189,10 @@ class Answer
"ORDER BY $field $order"; "ORDER BY $field $order";
$result=Database::query($sql); $result=Database::query($sql);
$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;

@ -1955,27 +1955,40 @@ class Exercise {
* @todo reduce parameters of this function * @todo reduce parameters of this function
* @return string html code * @return string html code
*/ */
public function manage_answer($exeId, $questionId, $choice, $from = 'exercise_show', $exerciseResultCoordinates = array(), $saved_results = true, $from_database = false, $show_result = true, $propagate_neg = 0, $hotspot_delineation_result = array()) public function manage_answer(
{ $exeId,
$questionId,
$choice,
$from = 'exercise_show',
$exerciseResultCoordinates = array(),
$saved_results = true,
$from_database = false,
$show_result = true,
$propagate_neg = 0,
$hotspot_delineation_result = array()
) {
global $debug; global $debug;
global $learnpath_id, $learnpath_item_id; //needed in order to use in the exercise_attempt() for the time //needed in order to use in the exercise_attempt() for the time
global $learnpath_id, $learnpath_item_id;
require_once api_get_path(LIBRARY_PATH).'geometry.lib.php';
$feedback_type = $this->selectFeedbackType(); $feedback_type = $this->selectFeedbackType();
$results_disabled = $this->selectResultsDisabled(); $results_disabled = $this->selectResultsDisabled();
require_once api_get_path(LIBRARY_PATH).'geometry.lib.php'; if ($debug) {
error_log("<------ manage_answer ------> ");
if ($debug) error_log("<------ manage_answer ------> "); error_log('exe_id: '.$exeId);
if ($debug) error_log('manage_answer called exe_id: '.$exeId); error_log('$from: '.$from);
if ($debug) error_log('manage_answer $from: '.$from); error_log('$saved_results: '.intval($saved_results));
if ($debug) error_log('manage_answer $saved_results: '.$saved_results); error_log('$from_database: '.intval($from_database));
if ($debug) error_log('manage_answer $from_database: '.$from_database); error_log('$show_result: '.$show_result);
if ($debug) error_log('manage_answer $show_result: '.$show_result); error_log('$propagate_neg: '.$propagate_neg);
if ($debug) error_log('manage_answer $propagate_neg: '.$propagate_neg); error_log('$exerciseResultCoordinates: '.print_r($exerciseResultCoordinates, 1));
if ($debug) error_log('manage_answer $exerciseResultCoordinates: '.print_r($exerciseResultCoordinates, 1)); error_log('$hotspot_delineation_result: '.print_r($hotspot_delineation_result, 1));
if ($debug) error_log('manage_answer $hotspot_delineation_result: '.print_r($hotspot_delineation_result, 1)); error_log('$learnpath_id: '.$learnpath_id);
if ($debug) error_log('manage_answer $learnpath_id: '.$learnpath_id); error_log('$learnpath_item_id: '.$learnpath_item_id);
if ($debug) error_log('manage_answer $learnpath_item_id: '.$learnpath_item_id); error_log('$choice: '.print_r($choice, 1));
}
$extra_data = array(); $extra_data = array();
$final_overlap = 0; $final_overlap = 0;
@ -1993,8 +2006,8 @@ class Exercise {
$questionId = intval($questionId); $questionId = intval($questionId);
$exeId = intval($exeId); $exeId = intval($exeId);
$TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER); $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
// Creates a temporary Question object // Creates a temporary Question object
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
@ -2012,11 +2025,11 @@ class Exercise {
$next = 1; //not for now $next = 1; //not for now
//Extra information of the question // Extra information of the question
if (!empty($extra)) { if (!empty($extra)) {
$extra = explode(':', $extra); $extra = explode(':', $extra);
if ($debug) error_log(print_r($extra, 1)); if ($debug) error_log(print_r($extra, 1));
//Fixes problems with negatives values using intval // Fixes problems with negatives values using intval
$true_score = intval($extra[0]); $true_score = intval($extra[0]);
$false_score = intval($extra[1]); $false_score = intval($extra[1]);
$doubt_score = intval($extra[2]); $doubt_score = intval($extra[2]);
@ -2026,14 +2039,16 @@ class Exercise {
$totalScore = 0; $totalScore = 0;
// Destruction of the Question object // Destruction of the Question object
unset ($objQuestionTmp); unset($objQuestionTmp);
// Construction of the Answer object // Construction of the Answer object
$objAnswerTmp = new Answer($questionId); $objAnswerTmp = new Answer($questionId);
$nbrAnswers = $objAnswerTmp->selectNbrAnswers(); $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
if ($debug) error_log('Count of answers: '.$nbrAnswers); if ($debug) {
if ($debug) error_log('$answerType: '.$answerType); error_log('Count of answers: '.$nbrAnswers);
error_log('$answerType: '.$answerType);
}
if ($answerType == FREE_ANSWER || $answerType == ORAL_EXPRESSION) { if ($answerType == FREE_ANSWER || $answerType == ORAL_EXPRESSION) {
$nbrAnswers = 1; $nbrAnswers = 1;
@ -2065,7 +2080,8 @@ class Exercise {
$user_answer = ''; $user_answer = '';
// Get answer list for matching // Get answer list for matching
$sql_answer = 'SELECT id, answer FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id = "'.$questionId.'" '; $sql_answer = 'SELECT id, answer FROM '.$table_ans.'
WHERE c_id = '.$course_id.' AND question_id = "'.$questionId.'"';
$res_answer = Database::query($sql_answer); $res_answer = Database::query($sql_answer);
$answer_matching =array(); $answer_matching =array();
@ -2077,7 +2093,6 @@ class Exercise {
$quiz_question_options = Question::readQuestionOption($questionId, $course_id); $quiz_question_options = Question::readQuestionOption($questionId, $course_id);
$organs_at_risk_hit = 0; $organs_at_risk_hit = 0;
$questionScore = 0; $questionScore = 0;
if ($debug) error_log('Start answer loop '); if ($debug) error_log('Start answer loop ');
@ -2085,20 +2100,20 @@ class Exercise {
$answer_correct_array = array(); $answer_correct_array = array();
for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
$answer = $objAnswerTmp->selectAnswer($answerId); $answer = $objAnswerTmp->selectAnswer($answerId);
$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);
$numAnswer = $objAnswerTmp->selectAutoId($answerId);
$answer_correct_array[$answerId] = (bool)$answerCorrect; $answer_correct_array[$answerId] = (bool)$answerCorrect;
if ($debug) error_log("answer auto id: $numAnswer "); if ($debug) {
if ($debug) error_log("answer correct : $answerCorrect "); error_log("answer auto id: $numAnswer ");
error_log("answer correct: $answerCorrect ");
}
//delineation // Delineation
$delineation_cord = $objAnswerTmp->selectHotspotCoordinates(1); $delineation_cord = $objAnswerTmp->selectHotspotCoordinates(1);
$answer_delineation_destination=$objAnswerTmp->selectDestination(1); $answer_delineation_destination=$objAnswerTmp->selectDestination(1);
switch ($answerType) { switch ($answerType) {
@ -2106,7 +2121,8 @@ class Exercise {
case UNIQUE_ANSWER : case UNIQUE_ANSWER :
case UNIQUE_ANSWER_NO_OPTION : case UNIQUE_ANSWER_NO_OPTION :
if ($from_database) { if ($from_database) {
$queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".$exeId."' and question_id= '".$questionId."'"; $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
WHERE exe_id = '".$exeId."' and question_id= '".$questionId."'";
$resultans = Database::query($queryans); $resultans = Database::query($queryans);
$choice = Database::result($resultans,0,"answer"); $choice = Database::result($resultans,0,"answer");
@ -2116,7 +2132,7 @@ class Exercise {
$totalScore+=$answerWeighting; $totalScore+=$answerWeighting;
} }
} else { } else {
$studentChoice = ($choice == $numAnswer)?1:0; $studentChoice = ($choice == $numAnswer) ? 1 : 0;
if ($studentChoice) { if ($studentChoice) {
$questionScore+=$answerWeighting; $questionScore+=$answerWeighting;
$totalScore+=$answerWeighting; $totalScore+=$answerWeighting;
@ -2127,32 +2143,33 @@ class Exercise {
case MULTIPLE_ANSWER_TRUE_FALSE: case MULTIPLE_ANSWER_TRUE_FALSE:
if ($from_database) { if ($from_database) {
$choice = array(); $choice = array();
$queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." where exe_id = ".$exeId." and question_id = ".$questionId; $sql = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
$resultans = Database::query($queryans); WHERE
exe_id = ".$exeId." AND
question_id = ".$questionId;
$resultans = Database::query($sql);
while ($row = Database::fetch_array($resultans)) { while ($row = Database::fetch_array($resultans)) {
$ind = $row['answer']; $ind = $row['answer'];
$result = explode(':',$ind); $result = explode(':', $ind);
$my_answer_id = $result[0]; $my_answer_id = $result[0];
$option = $result[1]; $option = $result[1];
$choice[$my_answer_id] = $option; $choice[$my_answer_id] = $option;
} }
$studentChoice =$choice[$numAnswer];
} else {
$studentChoice =$choice[$numAnswer];
} }
$studentChoice = isset($choice[$numAnswer]) ? $choice[$numAnswer] : null;
if (!empty($studentChoice)) { if (!empty($studentChoice)) {
if ($studentChoice == $answerCorrect ) { if ($studentChoice == $answerCorrect) {
$questionScore += $true_score; $questionScore += $true_score;
} else { } else {
if ($quiz_question_options[$studentChoice]['name'] != "Don't know") { if ($quiz_question_options[$studentChoice]['name'] != "Don't know") {
$questionScore += $false_score; $questionScore += $false_score;
} else { } else {
$questionScore += $doubt_score; $questionScore += $doubt_score;
} }
} }
} else { } else {
//if no result then the user just hit don't know // If no result then the user just hit don't know
$studentChoice = 3; $studentChoice = 3;
$questionScore += $doubt_score; $questionScore += $doubt_score;
} }
@ -2161,7 +2178,8 @@ class Exercise {
case MULTIPLE_ANSWER: //2 case MULTIPLE_ANSWER: //2
if ($from_database) { if ($from_database) {
$choice = array(); $choice = array();
$queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'"; $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'";
$resultans = Database::query($queryans); $resultans = Database::query($queryans);
while ($row = Database::fetch_array($resultans)) { while ($row = Database::fetch_array($resultans)) {
$ind = $row['answer']; $ind = $row['answer'];
@ -2182,7 +2200,7 @@ class Exercise {
$questionScore += $answerWeighting; $questionScore += $answerWeighting;
} }
} }
$totalScore += $answerWeighting; $totalScore += $answerWeighting;
if ($debug) error_log("studentChoice: $studentChoice"); if ($debug) error_log("studentChoice: $studentChoice");
break; break;
@ -2285,7 +2303,6 @@ class Exercise {
break; break;
// for fill in the blanks // for fill in the blanks
case FILL_IN_BLANKS: case FILL_IN_BLANKS:
// the question is encoded like this // the question is encoded like this
// [A] B [C] D [E] F::10,10,10@1 // [A] B [C] D [E] F::10,10,10@1
// number 1 before the "@" means that is a switchable fill in blank question // number 1 before the "@" means that is a switchable fill in blank question

@ -45,12 +45,21 @@ $this_section = SECTION_COURSES;
/* ACCESS RIGHTS */ /* ACCESS RIGHTS */
api_protect_course_script(true); api_protect_course_script(true);
if ($debug){ error_log('Entering exercise_result.php: '.print_r($_POST,1));} if ($debug) {
error_log('Entering exercise_result.php: '.print_r($_POST, 1));
}
// general parameters passed via POST/GET // general parameters passed via POST/GET
if ( empty ( $origin ) ) { $origin = Security::remove_XSS($_REQUEST['origin']);} // general parameters passed via POST/GET
if ( empty ( $objExercise ) ) { $objExercise = $_SESSION['objExercise'];} if (empty($origin)) {
if ( empty ( $remind_list ) ) { $remind_list = $_REQUEST['remind_list'];} $origin = Security::remove_XSS($_REQUEST['origin']);
}
if (empty($objExercise)) {
$objExercise = $_SESSION['objExercise'];
}
if (empty($remind_list)) {
$remind_list = isset($_REQUEST['remind_list']) ? $_REQUEST['remind_list'] : null;
}
$exe_id = isset($_REQUEST['exe_id']) ? intval($_REQUEST['exe_id']) : 0; $exe_id = isset($_REQUEST['exe_id']) ? intval($_REQUEST['exe_id']) : 0;

Loading…
Cancel
Save