mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merged changes from STABLE.
Not sure I did the right thing on questiontypes/calculated/questiontype.php Hope I didn't create a bug there. (can people please remember to merge changes into head whenever they change stable?)
This commit is contained in:
parent
1e462286f7
commit
708b521a6d
@ -218,6 +218,9 @@ function quiz_delete_instance($id) {
|
||||
if (! delete_records("quiz_newest_states", "attemptid", "$attempt->uniqueid")) {
|
||||
$result = false;
|
||||
}
|
||||
if (! delete_records("quiz_newest_states", "attemptid", "$attempt->id")) {
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -310,12 +313,12 @@ function quiz_delete_course($course, $feedback=true) {
|
||||
$concatid = insert_record('quiz_categories', $concat);
|
||||
|
||||
//Fill feedback
|
||||
$feedbackdata[] = array($concat->name, $strcatcontainer);
|
||||
$feedbackdata[] = array($concat->name, $strcatcontainer);
|
||||
}
|
||||
//Move the category to the container category in SITEID course
|
||||
$category->course = SITEID;
|
||||
//Assign to container if the category hasn't parent or if the parent is wrong (not belongs to the course)
|
||||
if (!$category->parent || !isset($categories[$category->parent])) {
|
||||
if (!$category->parent || !isset($categories[$category->parent])) {
|
||||
$category->parent = $concatid;
|
||||
}
|
||||
//If it's being used, its publish field should be 1
|
||||
@ -327,7 +330,7 @@ function quiz_delete_course($course, $feedback=true) {
|
||||
$parentchanged[$category->id] = $category->parent;
|
||||
|
||||
//Fill feedback
|
||||
$feedbackdata[] = array($category->name, $strcatmoved);
|
||||
$feedbackdata[] = array($category->name, $strcatmoved);
|
||||
|
||||
} else {
|
||||
//Category isn't being used so:
|
||||
@ -356,7 +359,7 @@ function quiz_delete_course($course, $feedback=true) {
|
||||
}
|
||||
delete_records("quiz_questions", "category", $category->id);
|
||||
}
|
||||
//delete the category
|
||||
//delete the category
|
||||
delete_records('quiz_categories', 'id', $category->id);
|
||||
|
||||
//Save this parent change for future use
|
||||
@ -370,7 +373,7 @@ function quiz_delete_course($course, $feedback=true) {
|
||||
set_field ('quiz_categories', 'parent', $parentchanged[$category->id], 'parent', $category->id);
|
||||
|
||||
//Fill feedback
|
||||
$feedbackdata[] = array($category->name, $strcatdeleted);
|
||||
$feedbackdata[] = array($category->name, $strcatdeleted);
|
||||
}
|
||||
}
|
||||
//Inform about changes performed if feedback is enabled
|
||||
|
@ -203,37 +203,59 @@ class quiz_calculated_qtype extends quiz_dataset_dependent_questiontype {
|
||||
// virtual type for printing
|
||||
$virtualqtype = $this->get_virtual_qtype();
|
||||
$unit = $virtualqtype->get_default_numerical_unit($question);
|
||||
|
||||
// We modify the question to look like a numerical question
|
||||
$numericalquestion = clone($question);
|
||||
$numericalquestion->options = clone($question->options);
|
||||
foreach ($question->options->answers as $key => $answer) {
|
||||
$answer = &$question->options->answers[$key]; // for PHP 4.x
|
||||
$answer->answer = $this->substitute_variables($answer->answer,
|
||||
$state->options->dataset);
|
||||
$numericalquestion->options->answers[$key] = clone($answer);
|
||||
}
|
||||
$question->questiontext = parent::substitute_variables(
|
||||
$question->questiontext, $state->options->dataset);
|
||||
$virtualqtype->print_question_formulation_and_controls($question,
|
||||
$state, $cmoptions, $options);
|
||||
foreach ($numericalquestion->options->answers as $key => $answer) {
|
||||
$answer = &$numericalquestion->options->answers[$key]; // for PHP 4.x
|
||||
$correctanswer = quiz_qtype_calculated_calculate_answer(
|
||||
$answer->answer, $state->options->dataset, $answer->tolerance,
|
||||
$answer->tolerancetype, $answer->correctanswerlength,
|
||||
$answer->correctanswerformat, $unit->unit);
|
||||
$answer->answer = $correctanswer->answer;
|
||||
}
|
||||
$numericalquestion->questiontext = parent::substitute_variables(
|
||||
$numericalquestion->questiontext, $state->options->dataset);
|
||||
$virtualqtype->print_question_formulation_and_controls($numericalquestion,
|
||||
$state, $quiz, $options);
|
||||
}
|
||||
|
||||
function grade_responses(&$question, &$state, $cmoptions) {
|
||||
// Forward the grading to the virtual qtype
|
||||
|
||||
// We modify the question to look like a numerical question
|
||||
$numericalquestion = clone($question);
|
||||
$numericalquestion->options = clone($question->options);
|
||||
foreach ($question->options->answers as $key => $answer) {
|
||||
$answer = &$question->options->answers[$key]; // for PHP 4.x
|
||||
$numericalquestion->options->answers[$key] = clone($answer);
|
||||
}
|
||||
foreach ($numericalquestion->options->answers as $key => $answer) {
|
||||
$answer = &$numericalquestion->options->answers[$key]; // for PHP 4.x
|
||||
$answer->answer = $this->substitute_variables($answer->answer,
|
||||
$state->options->dataset);
|
||||
}
|
||||
return parent::grade_responses($question, $state, $cmoptions);
|
||||
return parent::grade_responses($numericalquestion, $state, $quiz);
|
||||
}
|
||||
|
||||
// ULPGC ecastro
|
||||
function check_response(&$question, &$state) {
|
||||
// Forward the checking to the virtual qtype
|
||||
// We modify the question to look like a numerical question
|
||||
$numericalquestion = clone($question);
|
||||
$numericalquestion->options = clone($question->options);
|
||||
foreach ($question->options->answers as $key => $answer) {
|
||||
$answer = &$question->options->answers[$key]; // for PHP 4.x
|
||||
$numericalquestion->options->answers[$key] = clone($answer);
|
||||
}
|
||||
foreach ($numericalquestion->options->answers as $key => $answer) {
|
||||
$answer = &$numericalquestion->options->answers[$key]; // for PHP 4.x
|
||||
$answer->answer = $this->substitute_variables($answer->answer,
|
||||
$state->options->dataset);
|
||||
}
|
||||
//return false;
|
||||
return parent::check_response($question, $state);
|
||||
return parent::check_response($numericalquestion, $state);
|
||||
}
|
||||
|
||||
// ULPGC ecastro
|
||||
@ -242,19 +264,26 @@ class quiz_calculated_qtype extends quiz_dataset_dependent_questiontype {
|
||||
// virtual type
|
||||
$virtualqtype = $this->get_virtual_qtype();
|
||||
$unit = $virtualqtype->get_default_numerical_unit($question);
|
||||
|
||||
// We modify the question to look like a numerical question
|
||||
$numericalquestion = clone($question);
|
||||
$numericalquestion->options = clone($question->options);
|
||||
foreach ($question->options->answers as $key => $answer) {
|
||||
$answer = &$question->options->answers[$key]; // for PHP 4.x
|
||||
$numericalquestion->options->answers[$key] = clone($answer);
|
||||
}
|
||||
foreach ($numericalquestion->options->answers as $key => $answer) {
|
||||
$answer = &$numericalquestion->options->answers[$key]; // for PHP 4.x
|
||||
$answer->answer = $this->substitute_variables($answer->answer,
|
||||
$state->options->dataset);
|
||||
// apply_unit
|
||||
}
|
||||
$question->questiontext = parent::substitute_variables(
|
||||
$question->questiontext, $state->options->dataset);
|
||||
$responses = $virtualqtype->get_all_responses($question, $state);
|
||||
$numericalquestion->questiontext = parent::substitute_variables(
|
||||
$numericalquestion->questiontext, $state->options->dataset);
|
||||
$responses = $virtualqtype->get_all_responses($numericalquestion, $state);
|
||||
$response = reset($responses->responses);
|
||||
$correct = $response->answer.' : ';
|
||||
|
||||
$responses = $virtualqtype->get_actual_response($question, $state);
|
||||
$responses = $virtualqtype->get_actual_response($numericalquestion, $state);
|
||||
|
||||
foreach ($responses as $key=>$response){
|
||||
$responses[$key] = $correct.$response;
|
||||
|
@ -314,7 +314,7 @@ class quiz_numerical_qtype extends quiz_shortanswer_qtype {
|
||||
$state->raw_grade = 0;
|
||||
foreach($answers as $answer) {
|
||||
if($this->test_response($question, $state, $answer)) {
|
||||
if (empty($state->raw_grade) && $state->raw_grade < $answer->fraction) {
|
||||
if ($state->raw_grade < $answer->fraction) {
|
||||
$state->raw_grade = $answer->fraction;
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ class quiz_shortanswer_qtype extends quiz_default_questiontype {
|
||||
|
||||
$stranswer = get_string("answer", "quiz");
|
||||
if (isset($state->responses[''])) {
|
||||
$value = ' value="'.htmlSpecialChars($state->responses['']).'" ';
|
||||
$value = ' value="'.s($state->responses['']).'" ';
|
||||
} else {
|
||||
$value = ' value="" ';
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ class quiz_report extends quiz_default_report {
|
||||
}
|
||||
echo '<br/ >';
|
||||
// the following makes sure that the output is sent immediately.
|
||||
flush();ob_flush();
|
||||
@flush();@ob_flush();
|
||||
}
|
||||
|
||||
/// Loop through all questions and recalculate $attempt->sumgrade
|
||||
|
Loading…
x
Reference in New Issue
Block a user