Skip to content
Browse files

Merge branch 'MDL-34050_m24' of git://github.com/rwijaya/moodle into …

…MOODLE_24_STABLE
  • Loading branch information...
2 parents 72389d1 + 96d6ab3 commit ebe2f5a19c7616e85f73f9da2b266394c67df1e3 @stronk7 stronk7 committed Jan 21, 2013
Showing with 38 additions and 27 deletions.
  1. +7 −2 mod/lesson/locallib.php
  2. +31 −25 mod/lesson/pagetypes/matching.php
View
9 mod/lesson/locallib.php
@@ -2309,9 +2309,14 @@ public function properties() {
}
if (count($this->answers)>0) {
$count = 0;
+ $qtype = $properties->qtype;
foreach ($this->answers as $answer) {
- $properties->{'answer_editor['.$count.']'} = array('text'=>$answer->answer, 'format'=>$answer->answerformat);
- $properties->{'response_editor['.$count.']'} = array('text'=>$answer->response, 'format'=>$answer->responseformat);
+ $properties->{'answer_editor['.$count.']'} = array('text' => $answer->answer, 'format' => $answer->answerformat);
+ if ($qtype != LESSON_PAGE_MATCHING) {
+ $properties->{'response_editor['.$count.']'} = array('text' => $answer->response, 'format' => $answer->responseformat);
+ } else {
+ $properties->{'response_editor['.$count.']'} = $answer->response;
+ }
$properties->{'jumpto['.$count.']'} = $answer->jumpto;
$properties->{'score['.$count.']'} = $answer->score;
$count++;
View
56 mod/lesson/pagetypes/matching.php
@@ -72,16 +72,17 @@ protected function make_answer_form($attempt=null) {
foreach ($answers as $answer) {
// get all the response
if ($answer->response != NULL) {
- $responses[] = trim($answer->response);
+ $responses[$answer->id] = trim($answer->response);
}
}
$responseoptions = array(''=>get_string('choosedots'));
if (!empty($responses)) {
- shuffle($responses);
- $responses = array_unique($responses);
- foreach ($responses as $response) {
- $responseoptions[htmlspecialchars(trim($response))] = $response;
+ $shuffleresponses = $responses;
+ shuffle($shuffleresponses);
+ foreach ($shuffleresponses as $response) {
+ $key = array_search($response, $responses);
+ $responseoptions[$key] = $response;
}
}
if (isset($USER->modattempts[$this->lesson->id]) && !empty($attempt->useranswer)) {
@@ -115,9 +116,9 @@ public function create_answers($properties) {
$answer->answer = $properties->answer_editor[$i]['text'];
$answer->answerformat = $properties->answer_editor[$i]['format'];
}
- if (!empty($properties->response_editor[$i]) && is_array($properties->response_editor[$i])) {
- $answer->response = $properties->response_editor[$i]['text'];
- $answer->responseformat = $properties->response_editor[$i]['format'];
+ if (!empty($properties->response_editor[$i])) {
+ $answer->response = $properties->response_editor[$i];
+ $answer->responseformat = 0;
}
if (isset($properties->jumpto[$i])) {
@@ -171,27 +172,26 @@ public function check_answer() {
$wrong = array_shift($answers);
foreach ($answers as $key=>$answer) {
- if ($answer->answer === '' or $answer->response === '') {
- // incomplete option!
- unset($answers[$key]);
+ if ($answer->answer !== '' or $answer->response !== '') {
+ $answers[$answer->id] = $answer;
}
+ unset($answers[$key]);
}
// get he users exact responses for record keeping
$hits = 0;
$userresponse = array();
- foreach ($response as $key => $value) {
- foreach($answers as $answer) {
- if ($value === $answer->response) {
- $userresponse[] = $answer->id;
- }
- if ((int)$answer->id === (int)$key) {
- $result->studentanswer .= '<br />'.format_text($answer->answer, $answer->answerformat, $formattextdefoptions).' = '.$value;
- }
- if ((int)$answer->id === (int)$key and $value === $answer->response) {
+ foreach ($response as $id => $value) {
+ $userresponse[] = $value;
+ // Make sure the user's answer is exist in question's answer
+ if (array_key_exists($id, $answers)) {
+ $answer = $answers[$id];
+ $result->studentanswer .= '<br />'.format_text($answer->answer, $answer->answerformat, $formattextdefoptions).' = '.$answers[$value]->response;
+ if ($id == $value) {
$hits++;
}
}
}
+
$result->userresponse = implode(",", $userresponse);
if ($hits == count($answers)) {
@@ -315,9 +315,9 @@ public function update($properties, $context = null, $maxbytes = null) {
$this->answers[$i]->answer = $properties->answer_editor[$i]['text'];
$this->answers[$i]->answerformat = $properties->answer_editor[$i]['format'];
}
- if (!empty($properties->response_editor[$i]) && is_array($properties->response_editor[$i])) {
- $this->answers[$i]->response = $properties->response_editor[$i]['text'];
- $this->answers[$i]->responseformat = $properties->response_editor[$i]['format'];
+ if (!empty($properties->response_editor[$i])) {
+ $this->answers[$i]->response = $properties->response_editor[$i];
+ $this->answers[$i]->responseformat = 0;
}
if (isset($properties->jumpto[$i])) {
@@ -473,12 +473,18 @@ public function custom_definition() {
for ($i = 2; $i < $this->_customdata['lesson']->maxanswers+2; $i++) {
$this->_form->addElement('header', 'matchingpair'.($i-1), get_string('matchingpair', 'lesson', $i-1));
$this->add_answer($i, NULL, ($i < 4));
- $this->add_response($i, get_string('matchesanswer','lesson'), ($i < 4));
+ $required = ($i < 4);
+ $label = get_string('matchesanswer','lesson');
+ $count = $i;
+ $this->_form->addElement('text', 'response_editor['.$count.']', $label, array('size'=>'50'));
+ $this->_form->setDefault('response_editor['.$count.']', '');
+ if ($required) {
+ $this->_form->addRule('response_editor['.$count.']', get_string('required'), 'required', null, 'client');
+ }
}
}
}
-
class lesson_display_answer_form_matching extends moodleform {
public function definition() {

0 comments on commit ebe2f5a

Please sign in to comment.
Something went wrong with that request. Please try again.