Skip to content

Commit

Permalink
Merge branch 'MDL-49913' of git://github.com/jmvedrine/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Apr 27, 2015
2 parents 6e28c03 + c914c92 commit 08c8fc5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
80 changes: 39 additions & 41 deletions mod/lesson/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ function lesson_save_question_options($question, $lesson, $contextid) {

$timenow = time();
$result = new stdClass();

// Default answer to avoid code duplication.
$defaultanswer = new stdClass();
$defaultanswer->lessonid = $question->lessonid;
$defaultanswer->pageid = $question->id;
$defaultanswer->timecreated = $timenow;
$defaultanswer->answerformat = FORMAT_HTML;
$defaultanswer->jumpto = LESSON_THISPAGE;
$defaultanswer->grade = 0;
$defaultanswer->score = 0;

switch ($question->qtype) {
case LESSON_PAGE_SHORTANSWER:

Expand All @@ -89,14 +100,12 @@ function lesson_save_question_options($question, $lesson, $contextid) {
// Insert all the new answers
foreach ($question->answer as $key => $dataanswer) {
if ($dataanswer != "") {
$answer = new stdClass;
$answer->lessonid = $question->lessonid;
$answer->pageid = $question->id;
$answer = clone($defaultanswer);
if ($question->fraction[$key] >=0.5) {
$answer->jumpto = LESSON_NEXTPAGE;
$answer->score = 1;
}
$answer->timecreated = $timenow;
$answer->grade = $question->fraction[$key] * 100;
$answer->grade = round($question->fraction[$key] * 100);
$answer->answer = $dataanswer;
$answer->response = $question->feedback[$key]['text'];
$answer->responseformat = $question->feedback[$key]['format'];
Expand Down Expand Up @@ -127,16 +136,15 @@ function lesson_save_question_options($question, $lesson, $contextid) {
// for each answer store the pair of min and max values even if they are the same
foreach ($question->answer as $key => $dataanswer) {
if ($dataanswer != "") {
$answer = new stdClass;
$answer->lessonid = $question->lessonid;
$answer->pageid = $question->id;
$answer->jumpto = LESSON_NEXTPAGE;
$answer->timecreated = $timenow;
$answer->grade = $question->fraction[$key] * 100;
$answer = clone($defaultanswer);
if ($question->fraction[$key] >= 0.5) {
$answer->jumpto = LESSON_NEXTPAGE;
$answer->score = 1;
}
$answer->grade = round($question->fraction[$key] * 100);
$min = $question->answer[$key] - $question->tolerance[$key];
$max = $question->answer[$key] + $question->tolerance[$key];
$answer->answer = $min.":".$max;
// $answer->answer = $question->min[$key].":".$question->max[$key]; original line for min/max
$answer->response = $question->feedback[$key]['text'];
$answer->responseformat = $question->feedback[$key]['format'];
$answer->id = $DB->insert_record("lesson_answers", $answer);
Expand All @@ -161,14 +169,12 @@ function lesson_save_question_options($question, $lesson, $contextid) {
case LESSON_PAGE_TRUEFALSE:

// the truth
$answer = new stdClass();
$answer->lessonid = $question->lessonid;
$answer->pageid = $question->id;
$answer->timecreated = $timenow;
$answer = clone($defaultanswer);
$answer->answer = get_string("true", "lesson");
$answer->grade = $question->correctanswer * 100;
if ($answer->grade > 50 ) {
$answer->jumpto = LESSON_NEXTPAGE;
$answer->score = 1;
}
if (isset($question->feedbacktrue)) {
$answer->response = $question->feedbacktrue['text'];
Expand All @@ -178,14 +184,12 @@ function lesson_save_question_options($question, $lesson, $contextid) {
lesson_import_question_files('response', $question->feedbacktrue, $answer, $contextid);

// the lie
$answer = new stdClass;
$answer->lessonid = $question->lessonid;
$answer->pageid = $question->id;
$answer->timecreated = $timenow;
$answer = clone($defaultanswer);
$answer->answer = get_string("false", "lesson");
$answer->grade = (1 - (int)$question->correctanswer) * 100;
if ($answer->grade > 50 ) {
$answer->jumpto = LESSON_NEXTPAGE;
$answer->score = 1;
}
if (isset($question->feedbackfalse)) {
$answer->response = $question->feedbackfalse['text'];
Expand All @@ -206,22 +210,21 @@ function lesson_save_question_options($question, $lesson, $contextid) {
// Insert all the new answers
foreach ($question->answer as $key => $dataanswer) {
if ($dataanswer != "") {
$answer = new stdClass;
$answer->lessonid = $question->lessonid;
$answer->pageid = $question->id;
$answer->timecreated = $timenow;
$answer->grade = $question->fraction[$key] * 100;
// changed some defaults
/* Original Code
if ($answer->grade > 50 ) {
$answer->jumpto = LESSON_NEXTPAGE;
}
Replaced with: */
if ($answer->grade > 50 ) {
$answer->jumpto = LESSON_NEXTPAGE;
$answer->score = 1;
$answer = clone($defaultanswer);
$answer->grade = round($question->fraction[$key] * 100);

if ($question->single) {
if ($answer->grade > 50) {
$answer->jumpto = LESSON_NEXTPAGE;
$answer->score = 1;
}
} else {
// If multi answer allowed, any answer with fraction > 0 is considered correct.
if ($question->fraction[$key] > 0) {
$answer->jumpto = LESSON_NEXTPAGE;
$answer->score = 1;
}
}
// end Replace
$answer->answer = $dataanswer['text'];
$answer->answerformat = $dataanswer['format'];
$answer->response = $question->feedback[$key]['text'];
Expand Down Expand Up @@ -261,16 +264,11 @@ function lesson_save_question_options($question, $lesson, $contextid) {

$subquestions = array();

$defaultanswer = new stdClass;
$defaultanswer->lessonid = $question->lessonid;
$defaultanswer->pageid = $question->id;
$defaultanswer->timecreated = $timenow;
$defaultanswer->grade = 0;

// The first answer should always be the correct answer
$correctanswer = clone($defaultanswer);
$correctanswer->answer = get_string('thatsthecorrectanswer', 'lesson');
$correctanswer->jumpto = LESSON_NEXTPAGE;
$correctanswer->score = 1;
$DB->insert_record("lesson_answers", $correctanswer);

// The second answer should always be the wrong answer
Expand Down
1 change: 1 addition & 0 deletions mod/lesson/pagetypes/matching.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public function check_answer() {
// get the user's exact responses for record keeping
$hits = 0;
$userresponse = array();
$result->studentanswerformat = FORMAT_HTML;
foreach ($response as $id => $value) {
if ($value == '') {
$result->noanswer = true;
Expand Down
1 change: 1 addition & 0 deletions mod/lesson/pagetypes/multichoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public function check_answer() {
$wronganswerid = 0;
// store student's answers for displaying on feedback page
$result->studentanswer = '';
$result->studentanswerformat = FORMAT_HTML;
foreach ($answers as $answer) {
foreach ($studentanswers as $answerid) {
if ($answerid == $answer->id) {
Expand Down

0 comments on commit 08c8fc5

Please sign in to comment.