Skip to content

Commit

Permalink
Revert "Fix CALCULATED_ANSWER see #8237"
Browse files Browse the repository at this point in the history
This reverts commit 8104fe7.
  • Loading branch information
AngelFQC committed May 20, 2016
1 parent d3a5c1e commit a82e76b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 101 deletions.
1 change: 1 addition & 0 deletions main/exercice/answer.class.php
Expand Up @@ -72,6 +72,7 @@ public function __construct($questionId, $course_id = null)
$objExercise = new Exercise($this->course_id);
$exerciseId = isset($_REQUEST['exerciseId']) ? $_REQUEST['exerciseId'] : null;
$objExercise->read($exerciseId);

if ($objExercise->random_answers == '1') {
$this->readOrderedBy('rand()', '');// randomize answers
} else {
Expand Down
30 changes: 5 additions & 25 deletions main/exercice/exercise.class.php
@@ -1,8 +1,6 @@
<?php
/* For licensing terms, see /license.txt */

use ChamiloSession as Session;

/**
* Class Exercise
*
Expand Down Expand Up @@ -164,7 +162,9 @@ public function read($id, $parseQuestionList = true)
$this->display_category_name = $object->display_category_name;
$this->pass_percentage = $object->pass_percentage;
$this->sessionId = $object->session_id;

$this->is_gradebook_locked = api_resource_is_locked_by_gradebook($id, LINK_EXERCISE);

$this->review_answers = (isset($object->review_answers) && $object->review_answers == 1) ? true : false;
$this->globalCategoryId = isset($object->global_category_id) ? $object->global_category_id : null;
$this->questionSelectionType = isset($object->question_selection_type) ? $object->question_selection_type : null;
Expand All @@ -190,10 +190,10 @@ public function read($id, $parseQuestionList = true)
}

if ($object->end_time != '0000-00-00 00:00:00') {
$this->end_time = $object->end_time;
$this->end_time = $object->end_time;
}
if ($object->start_time != '0000-00-00 00:00:00') {
$this->start_time = $object->start_time;
$this->start_time = $object->start_time;
}

//control time
Expand Down Expand Up @@ -3746,16 +3746,7 @@ public function manage_answer(
}
break;
case CALCULATED_ANSWER:
$calculatedAnswerId = Session::read('calculatedAnswerId');
$answer = '';
if ($calculatedAnswerId) {
$calculatedAnswerInfo = Session::read('calculatedAnswerInfo');
if (isset($calculatedAnswerInfo[$questionId])) {
$answer = $calculatedAnswerInfo[$questionId];
} else {
$answer = $objAnswerTmp->selectAnswer($calculatedAnswerId[$questionId]);
}
}
$answer = $objAnswerTmp->selectAnswer($_SESSION['calculatedAnswerId'][$questionId]);
$preArray = explode('@@', $answer);
$last = count($preArray) - 1;
$answer = '';
Expand Down Expand Up @@ -3821,16 +3812,6 @@ public function manage_answer(
}
$answer = '';
$realCorrectTags = $correctTags;

if ($from_database && empty($calculatedAnswerId)) {
$queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
WHERE
exe_id = '".$exeId."' AND
question_id= ".intval($questionId)."";
$resfill = Database::query($queryfill);
$answer = Database::result($resfill, 0, 'answer');
}

for ($i = 0; $i < count($realCorrectTags); $i++) {
if ($i == 0) {
$answer .= $realText[0];
Expand Down Expand Up @@ -4603,7 +4584,6 @@ public function manage_answer(
$answer,
$studentChoice,
$answerComment,
$results_disabled
$results_disabled,
$answerId
);
Expand Down
5 changes: 1 addition & 4 deletions main/exercice/exercise_result.php
Expand Up @@ -165,6 +165,7 @@
$learnpath_id,
$learnpath_item_id
);

ExerciseLib::delete_chat_exercise_session($exe_id);

if ($origin != 'learnpath') {
Expand All @@ -179,8 +180,6 @@
if (api_is_allowed_to_session_edit()) {
Session::erase('objExercise');
Session::erase('exe_id');
Session::erase('calculatedAnswerId');
Session::erase('calculatedAnswerInfo');
}
Display::display_footer();
} else {
Expand All @@ -191,8 +190,6 @@
if (api_is_allowed_to_session_edit()) {
Session::erase('objExercise');
Session::erase('exe_id');
Session::erase('calculatedAnswerId');
Session::erase('calculatedAnswerInfo');
}

// Record the results in the learning path, using the SCORM interface (API)
Expand Down
74 changes: 27 additions & 47 deletions main/exercice/exercise_show.php
@@ -1,8 +1,6 @@
<?php
/* For licensing terms, see /license.txt */

use ChamiloSession as Session;

/**
* Shows the exercise results
*
Expand All @@ -14,6 +12,8 @@
*
*/

use ChamiloSession as Session;

require_once '../inc/global.inc.php';
$debug = false;
if (empty($origin) ) {
Expand All @@ -27,10 +27,10 @@
}

// Database table definitions
$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_TRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_TRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);

// General parameters passed via POST/GET
if ($debug) { error_log('Entered exercise_result.php: '.print_r($_POST,1)); }
Expand Down Expand Up @@ -77,13 +77,13 @@
api_not_allowed(true);
}

$exercise_id = $track_exercise_info['id'];
$exercise_date = $track_exercise_info['start_date'];
$student_id = $track_exercise_info['exe_user_id'];
$learnpath_id = $track_exercise_info['orig_lp_id'];
$learnpath_item_id = $track_exercise_info['orig_lp_item_id'];
$lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
$current_user_id = api_get_user_id();
$exercise_id = $track_exercise_info['id'];
$exercise_date = $track_exercise_info['start_date'];
$student_id = $track_exercise_info['exe_user_id'];
$learnpath_id = $track_exercise_info['orig_lp_id'];
$learnpath_item_id = $track_exercise_info['orig_lp_item_id'];
$lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
$current_user_id = api_get_user_id();

if (api_is_excluded_user_type(true, $student_id)) {
api_not_allowed(true);
Expand Down Expand Up @@ -116,7 +116,7 @@

$interbreadcrumb[]= array("url" => "exercise.php?".api_get_cidreq(),"name" => get_lang('Exercises'));
$interbreadcrumb[]= array("url" => "overview.php?exerciseId=".$exercise_id.'&'.api_get_cidreq(),"name" => $objExercise->name);
$interbreadcrumb[]= array("url" => "#", "name" => get_lang('Result'));
$interbreadcrumb[]= array("url" => "#","name" => get_lang('Result'));

$this_section = SECTION_COURSES;

Expand Down Expand Up @@ -322,6 +322,7 @@ function getFCK(vals,marksid) {
$counter = 1;
$exercise_content = null;
$category_list = array();

$useAdvancedEditor = true;

if (!empty($maxEditors) && count($questionList) > $maxEditors) {
Expand All @@ -334,10 +335,10 @@ function getFCK(vals,marksid) {
// destruction of the Question object
unset($objQuestionTmp);

// creates a temporary Question object
$objQuestionTmp = Question::read($questionId);
$questionWeighting = $objQuestionTmp->selectWeighting();
$answerType = $objQuestionTmp->selectType();
// creates a temporary Question object
$objQuestionTmp = Question::read($questionId);
$questionWeighting = $objQuestionTmp->selectWeighting();
$answerType = $objQuestionTmp->selectType();

// Start buffer
ob_start();
Expand Down Expand Up @@ -410,22 +411,6 @@ function getFCK(vals,marksid) {
);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
} elseif ($answerType == CALCULATED_ANSWER) {
$question_result = $objExercise->manage_answer(
$id,
$questionId,
$choice,
'exercise_show',
array(),
false,
true,
$show_results,
$objExercise->selectPropagateNeg(),
[],
$showTotalScoreAndUserChoices
);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
} elseif ($answerType == GLOBAL_MULTIPLE_ANSWER) {
$question_result = $objExercise->manage_answer(
$id,
Expand Down Expand Up @@ -665,8 +650,7 @@ function getFCK(vals,marksid) {
}

//showing the score
$queryfree = "SELECT marks FROM ".$TBL_TRACK_ATTEMPT."
WHERE exe_id = ".intval($id)." and question_id= ".intval($questionId)."";
$queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." WHERE exe_id = ".intval($id)." and question_id= ".intval($questionId)."";
$resfree = Database::query($queryfree);
$questionScore= Database::result($resfree,0,"marks");
$totalScore+=$questionScore;
Expand Down Expand Up @@ -731,13 +715,7 @@ function getFCK(vals,marksid) {
}
}
echo '<br />';
echo Display::url(
$url_name,
'javascript://',
array(
'class' => 'btn btn-default',
'onclick' => "showfck('".$name."', '".$marksname."');")
);
echo Display::url($url_name, 'javascript://', array('class' => 'btn', 'onclick'=>"showfck('".$name."', '".$marksname."');"));
echo '<br />';

echo '<div id="feedback_'.$name.'" style="width:100%">';
Expand Down Expand Up @@ -866,9 +844,9 @@ function getFCK(vals,marksid) {
$score = array();
if ($show_results) {
$score['result'] = get_lang('Score')." : ".ExerciseLib::show_score($my_total_score, $my_total_weight, false, false);
$score['pass'] = $my_total_score >= $my_total_weight ? true : false;
$score['type'] = $answerType;
$score['score'] = $my_total_score;
$score['pass'] = $my_total_score >= $my_total_weight ? true : false;
$score['type'] = $answerType;
$score['score'] = $my_total_score;
$score['weight'] = $my_total_weight;
$score['comments'] = isset($comnt) ? $comnt : null;
}
Expand All @@ -877,9 +855,11 @@ function getFCK(vals,marksid) {
$i++;

$contents = ob_get_clean();

$question_content = '<div class="question_row">';

if ($show_results) {
// Shows question title an description
//Shows question title an description
$question_content .= $objQuestionTmp->return_header(null, $counter, $score);
}
$counter++;
Expand Down
5 changes: 3 additions & 2 deletions main/inc/ajax/exercise.ajax.php
Expand Up @@ -351,7 +351,8 @@
continue;
}

$my_choice = isset($choice[$my_question_id]) ? $choice[$my_question_id] : null;
$my_choice = isset($choice[$my_question_id]) ?
$choice[$my_question_id] : null;

if ($debug) {
error_log("my_choice = ".print_r($my_choice, 1)."");
Expand All @@ -361,7 +362,7 @@
$objQuestionTmp = Question::read($my_question_id, $course_id);

// Getting free choice data.
if ($objQuestionTmp->type == FREE_ANSWER && $type == 'all') {
if ($objQuestionTmp->type == FREE_ANSWER && $type == 'all') {
$my_choice = isset($_REQUEST['free_choice'][$my_question_id]) && !empty($_REQUEST['free_choice'][$my_question_id]) ? $_REQUEST['free_choice'][$my_question_id]: null;
}

Expand Down
34 changes: 11 additions & 23 deletions main/inc/lib/exercise.lib.php
Expand Up @@ -622,35 +622,24 @@ public static function showQuestion(
* the text to find mustn't contains HTML tags
* the text to find mustn't contains char "
*/
global $exe_id;
$trackAttempts = Database::get_main_table(
TABLE_STATISTIC_TRACK_E_ATTEMPT
);
$sql = 'SELECT answer FROM ' . $trackAttempts . '
WHERE exe_id=' . $exe_id . ' AND question_id=' . $questionId;
$rsLastAttempt = Database::query($sql);
$rowLastAttempt = Database::fetch_array($rsLastAttempt);
$answer = $rowLastAttempt['answer'];

$calculatedAnswerId = Session::read('calculatedAnswerId');
$calculatedAnswerInfo = Session::read('calculatedAnswerInfo');
if (empty($answer)) {
if (empty($calculatedAnswerId)) {
if ($origin !== null) {
global $exe_id;
$trackAttempts = Database::get_main_table(
TABLE_STATISTIC_TRACK_E_ATTEMPT
);
$sql = 'SELECT answer FROM ' . $trackAttempts . '
WHERE exe_id=' . $exe_id . ' AND question_id=' . $questionId;
$rsLastAttempt = Database::query($sql);
$rowLastAttempt = Database::fetch_array($rsLastAttempt);
$answer = $rowLastAttempt['answer'];
if (empty($answer)) {
$_SESSION['calculatedAnswerId'][$questionId] = mt_rand(
1,
$nbrAnswers
);
$answer = $objAnswerTmp->selectAnswer(
$_SESSION['calculatedAnswerId'][$questionId]
);

Session::write('calculatedAnswerInfo', [$questionId => $answer]);

} else {
$calculatedAnswerInfo = Session::read('calculatedAnswerInfo');
if (isset($calculatedAnswerInfo[$questionId])) {
$answer = $calculatedAnswerInfo[$questionId];
}
}
}

Expand All @@ -662,7 +651,6 @@ public static function showQuestion(
$correctAnswerList
);


// get student answer to display it if student go back to previous calculated answer question in a test
if (isset($user_choice[0]['answer'])) {
api_preg_match_all(
Expand Down

0 comments on commit a82e76b

Please sign in to comment.