Skip to content

Commit

Permalink
Merge branch 'MDL-34050_m23' of git://github.com/rwijaya/moodle into …
Browse files Browse the repository at this point in the history
…MOODLE_23_STABLE
  • Loading branch information
stronk7 committed Jan 21, 2013
2 parents d971df8 + 091a0b7 commit fd843c7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
9 changes: 7 additions & 2 deletions mod/lesson/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
56 changes: 31 additions & 25 deletions mod/lesson/pagetypes/matching.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit fd843c7

Please sign in to comment.