stevepb Posted July 9, 2007 Share Posted July 9, 2007 Hello All, Firstly let me explain. I have an elearning website with a form of lessons (learning materials with questions) containing questions. These questions are Multichoice (i.e. can be more than one correct answer) these answers are currently not tallying (adding together) only the result (points) for one answer is being displayed and used to calulate the final score for the entire lesson, rather than the result of these answers added together to give total points for that question. I have a modified version of the lesson module (taken from the Moodle CMS/VLE), which i've called Exam. The exam does not give feedback to students answers, emails tutors upon completion, will not allow more than one login session per user (stops a user opening content in another windows whilst answering the exam) and a few other small changes. I was under the impression that when answering multi choice question with more than one correct answer that the score for each answer is tallied to give a total score for the question. UNFORTUNATELY LESSON MOD DOES NOT BEHAVE LIKE THIS!!! i.e. If the answers are worth the below amount of points per answer. The scores are not added/tallied together, only the first answer checked/selected in the order written in edit mode is given as the total score and NOT the scores for each answer added together as the total score. no.1 with score=1 no.2 with score=1 no.3 with score=1 no.4 with score=0 so I check answers 1 & 2 then the total score that I want is 1point+1point=2points, however the score is actually 1point in total. this means that I get all correct answers the score would equal this:- checked answers 1 & 2 & 3 Currently behaves likes so: 1point+1point+1point= 1point I want lesson to behave like so: 1point+1point+1point= 3points The behaviour of the lesson mod is that the score awarded is the score of the first item that was chosen, where "first" means "first in the order of items as they were declared by the creator/teacher (edit mode) in the original question". Note that the order of the items may be different when the question is presented to the student. Could anyone advised me on how to change this behaviour by editing the php files to what i am after. i.e. I want each score for each correct answer to be added together to give a total score for the question. Also I do not want the changes to inadvertantly mess up scoring for other question types, namely the essay question type. Any help would be wonderful!! I hope i have clearly described what i am after, i'm sure its quite a simple edit, but i'm at a loss where to start. I have isolated the 140 ish lines of code which i need to alter somewhere, this code is contained within a file called continue.php. here is the code i isolated: case LESSON_MULTICHOICE : if ($page->qoption) { // MULTIANSWER allowed, user's answer is an array if (isset($_POST['answer'])) { $useranswers = $_POST['answer']; foreach ($useranswers as $key => $useranswer) { $useranswers[$key] = clean_param($useranswer, PARAM_INT); } } else { $noanswer = true; break; } // get what the user answered $userresponse = implode(",", $useranswers); // get the answers in a set order, the id order if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { error("Continue: No answers found"); } $ncorrect = 0; $nhits = 0; $correctresponse = ''; $wrongresponse = ''; // store student's answers for displaying on feedback page foreach ($answers as $answer) { foreach ($useranswers as $key => $answerid) { if ($answerid == $answer->id) { $studentanswer .= '<br />'.$answer->answer; } } } // this is for custom scores. If score on answer is positive, it is correct if ($lesson->custom) { $ncorrect = 0; $nhits = 0; foreach ($answers as $answer) { if ($answer->score > 0) { $ncorrect++; foreach ($useranswers as $key => $answerid) { if ($answerid == $answer->id) { $nhits++; } } // save the first jumpto page id, may be needed!... if (!isset($correctpageid)) { // leave in its "raw" state - will converted into a proper page id later $correctpageid = $answer->jumpto; } // ...also save any response from the correct answers... if (trim(strip_tags($answer->response))) { $correctresponse = $answer->response; } } else { // save the first jumpto page id, may be needed!... if (!isset($wrongpageid)) { // leave in its "raw" state - will converted into a proper page id later $wrongpageid = $answer->jumpto; } // ...and from the incorrect ones, don't know which to use at this stage if (trim(strip_tags($answer->response))) { $wrongresponse = $answer->response; } } } } else { foreach ($answers as $answer) { if (lesson_iscorrect($pageid, $answer->jumpto)) { $ncorrect++; foreach ($useranswers as $key => $answerid) { if ($answerid == $answer->id) { $nhits++; } } // save the first jumpto page id, may be needed!... if (!isset($correctpageid)) { // leave in its "raw" state - will converted into a proper page id later $correctpageid = $answer->jumpto; } // ...also save any response from the correct answers... if (trim(strip_tags($answer->response))) { $correctresponse = $answer->response; } } else { // save the first jumpto page id, may be needed!... if (!isset($wrongpageid)) { // leave in its "raw" state - will converted into a proper page id later $wrongpageid = $answer->jumpto; } // ...and from the incorrect ones, don't know which to use at this stage if (trim(strip_tags($answer->response))) { $wrongresponse = $answer->response; } } } } if ((count($useranswers) == $ncorrect) and ($nhits == $ncorrect)) { $correctanswer = true; if (!$response = $correctresponse) { $response = get_string("thatsthecorrectanswer", "lesson"); } $newpageid = $correctpageid; } else { if (!$response = $wrongresponse) { $response = get_string("thatsthewronganswer", "lesson"); } $newpageid = $wrongpageid; } } else { // only one answer allowed if (empty($_POST['answerid'])) { $noanswer = true; break; } $answerid = required_param('answerid', PARAM_INT); if (!$answer = get_record("lesson_answers", "id", $answerid)) { error("Continue: answer record not found"); } if (lesson_iscorrect($pageid, $answer->jumpto)) { $correctanswer = true; } if ($lesson->custom) { if ($answer->score > 0) { $correctanswer = true; } else { $correctanswer = false; } } $newpageid = $answer->jumpto; if (!$response = trim($answer->response)) { if ($correctanswer) { $response = get_string("thatsthecorrectanswer", "lesson"); } else { $response = get_string("thatsthewronganswer", "lesson"); } } $studentanswer = $answer->answer; } break; I hope someone can help me with this i'd be incredible greatful. Many Thanks Steve Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 9, 2007 Share Posted July 9, 2007 1. Please edit your post and surround your code with [code] and [/code] tags. Too much text - can you explain in basic terms? Quote Link to comment Share on other sites More sharing options...
stevepb Posted July 11, 2007 Author Share Posted July 11, 2007 1. Please edit your post and surround your code with [code] and [/code] tags. Too much text - can you explain in basic terms? Hello, Apologies for too much text. and not putting code in tags. cant find where to edit previous posts ??? Anyway. This php code calculates the answer from the points scored on multiple choice questions. For each correct answer (can be multiple correct answers) a number of points is given, such as 1 point per correct answer. I discovered that the score awarded is the score of the first item that was chosen, where "first" means "first in the order of items as they were declared by the teacher/editor in the original question". Note that the order of the items may be different when the question is presented to the student as they are displayed in a random order. In the simple example I created there were 4 choices; 1 (1 point) 2 (2 points) 3 (3 points) 4 (0 points) If the student selected just one item, then they were awarded the score for that item. However, if the student chose two items, say "1" and "3", then the score is not the total of the points, it is the points for the first item chosen, in this case "1". It seems that you require the points to be the total of all the correct answers selected, but the marking does not seem to work like that I want each answer to ADD! together to produce a correct final score. I hope i have been more clear. Thanks Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 If you're using checkboxes then you can't find out which one was selected first as they both get sent at the same time. Not sure I understand! Quote Link to comment Share on other sites More sharing options...
OLG Posted July 11, 2007 Share Posted July 11, 2007 I for once agree with Yesideez, Your after javascript for what you want, not PHP Quote Link to comment Share on other sites More sharing options...
stevepb Posted July 11, 2007 Author Share Posted July 11, 2007 Hello, I do not want to use JavaScript. This code is only part of one script used in a module (lesson module). The module has over 45 php files and is pretty complex. However the 140 lines are where i need to edit, somewhere... I do not particularlly care about the order of results, i simply described the modules observed behaviour (through rigorous testing), this is probably due to the fact that only one answer is given and recorded for the final score/points earned. The points for that question then only reflects the score for that particular answers point worth/value. What i want is for the points for each correctly given answer to be added together and give a result of these as the final total score for that question. that's it. Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.