mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
attempt.php now includes view.php for "mobile" outputformat; added checks, hints and score for "mobile" outputformat
This commit is contained in:
parent
ae11b653f1
commit
6cadcaf077
3 changed files with 137 additions and 81 deletions
|
@ -45,8 +45,11 @@
|
||||||
// set clickreportid, (for click reporting)
|
// set clickreportid, (for click reporting)
|
||||||
$attempt->clickreportid = $attempt->id;
|
$attempt->clickreportid = $attempt->id;
|
||||||
|
|
||||||
if (empty($attempt->details)) { // "mobile" output format
|
if (empty($attempt->details)) {
|
||||||
hotpot_set_attempt_details($attempt);
|
hotpot_set_attempt_details($attempt);
|
||||||
|
$javascript_is_off = true;
|
||||||
|
} else {
|
||||||
|
$javascript_is_off = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($attempt->status)) {
|
if (empty($attempt->status)) {
|
||||||
|
@ -127,9 +130,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($attempt->status==HOTPOT_STATUS_INPROGRESS) {
|
if ($attempt->status==HOTPOT_STATUS_INPROGRESS) {
|
||||||
// continue the quiz
|
if ($javascript_is_off) {
|
||||||
header("Status: 204");
|
// regenerate HTML page
|
||||||
header("HTTP/1.0 204 No Response");
|
define('HOTPOT_FIRST_ATTEMPT', false);
|
||||||
|
include ("$CFG->hotpotroot/view.php");
|
||||||
|
} else {
|
||||||
|
// continue without reloading the page
|
||||||
|
header("Status: 204");
|
||||||
|
header("HTTP/1.0 204 No Response");
|
||||||
|
}
|
||||||
|
|
||||||
} else { // quiz is finished
|
} else { // quiz is finished
|
||||||
|
|
||||||
|
@ -174,6 +183,7 @@ function hotpot_get_next_cm(&$cm) {
|
||||||
function hotpot_set_attempt_details(&$attempt) {
|
function hotpot_set_attempt_details(&$attempt) {
|
||||||
|
|
||||||
$attempt->details = '';
|
$attempt->details = '';
|
||||||
|
$attempt->score = 0;
|
||||||
$attempt->status = HOTPOT_STATUS_COMPLETED;
|
$attempt->status = HOTPOT_STATUS_COMPLETED;
|
||||||
|
|
||||||
$buttons = array('clues', 'hints', 'checks');
|
$buttons = array('clues', 'hints', 'checks');
|
||||||
|
@ -183,7 +193,7 @@ function hotpot_set_attempt_details(&$attempt) {
|
||||||
|
|
||||||
$q = 0;
|
$q = 0;
|
||||||
while (($responsefield="q{$q}") && isset($_POST[$responsefield])) {
|
while (($responsefield="q{$q}") && isset($_POST[$responsefield])) {
|
||||||
$responsevalue = optional_param($responsefield, '', PARAM_ALPHA);
|
$responsevalue = optional_param($responsefield, '');
|
||||||
|
|
||||||
// initialize $response object
|
// initialize $response object
|
||||||
$response = NULL;
|
$response = NULL;
|
||||||
|
@ -206,10 +216,15 @@ function hotpot_set_attempt_details(&$attempt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// loop through possible answers to this question
|
// loop through possible answers to this question
|
||||||
|
$firstcorrectvalue = '';
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while (($correctfield="q{$q}_correct_{$i}") && isset($_POST[$correctfield])) {
|
while (($correctfield="q{$q}_correct_{$i}") && isset($_POST[$correctfield])) {
|
||||||
$correctvalue = optional_param($correctfield, '', PARAM_RAW);
|
$correctvalue = optional_param($correctfield, '', PARAM_RAW);
|
||||||
|
|
||||||
|
if (empty($firstcorrectvalue)) {
|
||||||
|
$firstcorrectvalue = $correctvalue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($responsevalue==$correctvalue) {
|
if ($responsevalue==$correctvalue) {
|
||||||
$response->correct = $responsevalue;
|
$response->correct = $responsevalue;
|
||||||
} else {
|
} else {
|
||||||
|
@ -222,8 +237,34 @@ function hotpot_set_attempt_details(&$attempt) {
|
||||||
if (empty($response->correct)) {
|
if (empty($response->correct)) {
|
||||||
$response->wrong = $responsevalue;
|
$response->wrong = $responsevalue;
|
||||||
$attempt->status = HOTPOT_STATUS_INPROGRESS;
|
$attempt->status = HOTPOT_STATUS_INPROGRESS;
|
||||||
|
|
||||||
|
// give a hint, if necessary
|
||||||
|
if (isset($_POST['HintButton']) && $firstcorrectvalue) {
|
||||||
|
|
||||||
|
// make sure we only come through here once
|
||||||
|
unset($_POST['HintButton']);
|
||||||
|
|
||||||
|
$correctlen = strlen($firstcorrectvalue);
|
||||||
|
$responselen = strlen($responsevalue);
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
while ($i<$responselen && $i<$correctlen && $responsevalue{$i}==$firstcorrectvalue{$i}) {
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($i<$responselen) {
|
||||||
|
// remove incorrect characters on the end of the response
|
||||||
|
$responsevalue = substr($responsevalue, 0, $i);
|
||||||
|
}
|
||||||
|
if ($i<$correctlen) {
|
||||||
|
// append next correct letter
|
||||||
|
$responsevalue .= $firstcorrectvalue{$i};
|
||||||
|
}
|
||||||
|
$_POST[$responsefield] = $responsevalue;
|
||||||
|
$response->hints++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert "ignored" array to string
|
// convert "ignored" array to string
|
||||||
$response->ignored = implode(',', $response->ignored);
|
$response->ignored = implode(',', $response->ignored);
|
||||||
|
|
||||||
|
@ -232,6 +273,15 @@ function hotpot_set_attempt_details(&$attempt) {
|
||||||
$response->clue_text = optional_param($field, '', PARAM_RAW);
|
$response->clue_text = optional_param($field, '', PARAM_RAW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$oldresponse = NULL;
|
||||||
|
foreach ($buttons as $button) {
|
||||||
|
$oldresponse->$button = 0;
|
||||||
|
}
|
||||||
|
foreach ($textfields as $field) {
|
||||||
|
$oldresponse->$field = array();
|
||||||
|
$response->$field = empty($response->$field) ? array() : explode(',', $response->$field);
|
||||||
|
}
|
||||||
|
|
||||||
// get question name
|
// get question name
|
||||||
$qq = sprintf('%02d', $q); // (a padded, two-digit version of $q)
|
$qq = sprintf('%02d', $q); // (a padded, two-digit version of $q)
|
||||||
if (($field="q{$q}_name") && isset($_POST[$field])) {
|
if (($field="q{$q}_name") && isset($_POST[$field])) {
|
||||||
|
@ -248,43 +298,53 @@ function hotpot_set_attempt_details(&$attempt) {
|
||||||
$records = false;
|
$records = false;
|
||||||
}
|
}
|
||||||
if ($records) {
|
if ($records) {
|
||||||
|
|
||||||
$max = array();
|
|
||||||
foreach ($buttons as $button) {
|
|
||||||
$max[$button] = 0;
|
|
||||||
}
|
|
||||||
foreach ($textfields as $field) {
|
|
||||||
$response->$field = empty($response->$field) ? array() : explode(',', $response->$field);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($records as $record) {
|
foreach ($records as $record) {
|
||||||
foreach ($buttons as $button) {
|
foreach ($buttons as $button) {
|
||||||
$max[$button] = max($max[$button], $record->$button);
|
$oldresponse->$button = max($oldresponse->$button, $record->$button);
|
||||||
}
|
}
|
||||||
foreach ($textfields as $field) {
|
foreach ($textfields as $field) {
|
||||||
if ($record->$field) {
|
if ($record->$field) {
|
||||||
$values = explode(',', hotpot_strings($record->$field));
|
$values = explode(',', hotpot_strings($record->$field));
|
||||||
$response->$field = array_merge($response->$field, $values);
|
$oldresponse->$field = array_merge($oldresponse->$field, $values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// remove "correct" and "wrong" values from "ignored" values
|
||||||
|
$response->ignored = array_diff(
|
||||||
|
$response->ignored,
|
||||||
|
$response->correct, $response->wrong, $oldresponse->correct, $oldresponse->wrong
|
||||||
|
);
|
||||||
|
foreach ($buttons as $button) {
|
||||||
|
$response->$button += $oldresponse->$button;
|
||||||
|
}
|
||||||
|
$value_has_changed = false;
|
||||||
|
foreach ($textfields as $field) {
|
||||||
|
$response->$field = array_merge($response->$field, $oldresponse->$field);
|
||||||
|
$response->$field = array_unique($response->$field);
|
||||||
|
$response->$field = implode(',', $response->$field);
|
||||||
|
|
||||||
// remove "correct" and "wrong" values from "ignored" values
|
$oldresponse->$field = array_unique($oldresponse->$field);
|
||||||
$response->ignored = array_diff($response->ignored, $response->correct, $response->wrong);
|
$oldresponse->$field = implode(',', $oldresponse->$field);
|
||||||
|
|
||||||
foreach ($buttons as $button) {
|
|
||||||
$response->$button += $max[$button];
|
|
||||||
}
|
|
||||||
foreach ($textfields as $field) {
|
|
||||||
$response->$field = array_unique($response->$field);
|
|
||||||
$response->$field = implode(',', $response->$field);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end if $records
|
if ($field=='correct' || $field=='wrong') {
|
||||||
|
if ($response->$field<>$oldresponse->$field) {
|
||||||
|
$value_has_changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($value_has_changed) {
|
||||||
|
$response->checks++;
|
||||||
|
}
|
||||||
|
|
||||||
// $response now holds amalgamation of all responses so far to this question
|
// $response now holds amalgamation of all responses so far to this question
|
||||||
|
|
||||||
// set score and weighting
|
// set score and weighting
|
||||||
|
if ($response->correct) {
|
||||||
|
$strlen = strlen($response->correct);
|
||||||
|
$response->score = 100*($strlen-($response->checks-1))/$strlen;
|
||||||
|
$attempt->score += $response->score;
|
||||||
|
}
|
||||||
|
|
||||||
// encode $response fields as XML
|
// encode $response fields as XML
|
||||||
$vars = get_object_vars($response);
|
$vars = get_object_vars($response);
|
||||||
|
@ -297,6 +357,10 @@ function hotpot_set_attempt_details(&$attempt) {
|
||||||
$q++;
|
$q++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($q>0) {
|
||||||
|
$attempt->score = floor($attempt->score / $q);
|
||||||
|
}
|
||||||
|
|
||||||
if ($attempt->details) {
|
if ($attempt->details) {
|
||||||
$attempt->details = '<?xml version="1.0"?><hpjsresult><fields>'.$attempt->details.'</fields></hpjsresult>';
|
$attempt->details = '<?xml version="1.0"?><hpjsresult><fields>'.$attempt->details.'</fields></hpjsresult>';
|
||||||
}
|
}
|
||||||
|
@ -306,25 +370,4 @@ function hotpot_set_attempt_details(&$attempt) {
|
||||||
$attempt->status = HOTPOT_STATUS_INPROGRESS;
|
$attempt->status = HOTPOT_STATUS_INPROGRESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function hotpot_XXX() {
|
|
||||||
$values = explode(',', $value);
|
|
||||||
foreach ($values as $value) {
|
|
||||||
|
|
||||||
$i_max =strlen($value);
|
|
||||||
for ($i=0; $i<$i_max; $i++) {
|
|
||||||
|
|
||||||
$char = $value{$i};
|
|
||||||
$ord = ord($char);
|
|
||||||
if ($ord==43 || $ord==44 || $ord>128) { // comma, plus-sign or multibyte char
|
|
||||||
$fielddata .= '&#x'.sprintf('%04X', $char).';';
|
|
||||||
} else {
|
|
||||||
$fielddata .= $char;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preg_match('#[<>]#', $fielddata)) {
|
|
||||||
$fielddata = '<![CDATA[' + $fielddata + ']]>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
?>
|
|
@ -1134,6 +1134,7 @@ function hotpot_add_attempt($hotpotid) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set all previous "in progress" attempts at this quiz to "abandoned"
|
||||||
$db->Execute("
|
$db->Execute("
|
||||||
UPDATE
|
UPDATE
|
||||||
{$CFG->prefix}hotpot_attempts as a
|
{$CFG->prefix}hotpot_attempts as a
|
||||||
|
|
|
@ -2,40 +2,48 @@
|
||||||
|
|
||||||
/// This page prints a hotpot quiz
|
/// This page prints a hotpot quiz
|
||||||
|
|
||||||
require_once("../../config.php");
|
if (defined('HOTPOT_FIRST_ATTEMPT') && HOTPOT_FIRST_ATTEMPT==false) {
|
||||||
require_once("lib.php");
|
// this script is being included (by attempt.php)
|
||||||
|
|
||||||
$id = optional_param("id"); // Course Module ID, or
|
|
||||||
$hp = optional_param("hp"); // hotpot ID
|
|
||||||
|
|
||||||
if ($id) {
|
|
||||||
if (! $cm = get_record("course_modules", "id", $id)) {
|
|
||||||
error("Course Module ID was incorrect");
|
|
||||||
}
|
|
||||||
if (! $course = get_record("course", "id", $cm->course)) {
|
|
||||||
error("Course is misconfigured");
|
|
||||||
}
|
|
||||||
if (! $hotpot = get_record("hotpot", "id", $cm->instance)) {
|
|
||||||
error("Course module is incorrect");
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (! $hotpot = get_record("hotpot", "id", $hp)) {
|
// this script is being called directly from the browser
|
||||||
error("Course module is incorrect");
|
define('HOTPOT_FIRST_ATTEMPT', true);
|
||||||
}
|
|
||||||
if (! $course = get_record("course", "id", $hotpot->course)) {
|
require_once("../../config.php");
|
||||||
error("Course is misconfigured");
|
require_once("lib.php");
|
||||||
}
|
|
||||||
if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) {
|
$id = optional_param("id"); // Course Module ID, or
|
||||||
error("Course Module ID was incorrect");
|
$hp = optional_param("hp"); // hotpot ID
|
||||||
|
|
||||||
|
if ($id) {
|
||||||
|
if (! $cm = get_record("course_modules", "id", $id)) {
|
||||||
|
error("Course Module ID was incorrect");
|
||||||
|
}
|
||||||
|
if (! $course = get_record("course", "id", $cm->course)) {
|
||||||
|
error("Course is misconfigured");
|
||||||
|
}
|
||||||
|
if (! $hotpot = get_record("hotpot", "id", $cm->instance)) {
|
||||||
|
error("Course module is incorrect");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (! $hotpot = get_record("hotpot", "id", $hp)) {
|
||||||
|
error("Course module is incorrect");
|
||||||
|
}
|
||||||
|
if (! $course = get_record("course", "id", $hotpot->course)) {
|
||||||
|
error("Course is misconfigured");
|
||||||
|
}
|
||||||
|
if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) {
|
||||||
|
error("Course Module ID was incorrect");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require_login($course->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set nextpage (for error messages)
|
// set nextpage (for error messages)
|
||||||
$nextpage = "$CFG->wwwroot/course/view.php?id=$course->id";
|
$nextpage = "$CFG->wwwroot/course/view.php?id=$course->id";
|
||||||
|
|
||||||
require_login($course->id);
|
|
||||||
|
|
||||||
// header strings
|
// header strings
|
||||||
$title = strip_tags($course->shortname.': '.$hotpot->name);
|
$title = strip_tags($course->shortname.': '.$hotpot->name);
|
||||||
$heading = "$course->fullname";
|
$heading = "$course->fullname";
|
||||||
|
@ -52,7 +60,7 @@
|
||||||
$time = time();
|
$time = time();
|
||||||
$hppassword = optional_param('hppassword');
|
$hppassword = optional_param('hppassword');
|
||||||
|
|
||||||
if (!isteacher($course->id)) {
|
if (HOTPOT_FIRST_ATTEMPT && !isteacher($course->id)) {
|
||||||
// check this quiz is available to this student
|
// check this quiz is available to this student
|
||||||
|
|
||||||
// error message, if quiz is unavailable
|
// error message, if quiz is unavailable
|
||||||
|
@ -131,6 +139,7 @@
|
||||||
$available_msg = get_string("quizavailable", "quiz", userdate($hotpot->timeclose))."<br />\n";
|
$available_msg = get_string("quizavailable", "quiz", userdate($hotpot->timeclose))."<br />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// open and parse the source file
|
// open and parse the source file
|
||||||
if(!$hp = new hotpot_xml_quiz($hotpot)) {
|
if(!$hp = new hotpot_xml_quiz($hotpot)) {
|
||||||
error("Quiz is unavailable at the moment");
|
error("Quiz is unavailable at the moment");
|
||||||
|
@ -165,11 +174,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($get_html) {
|
if ($get_html) {
|
||||||
add_to_log($course->id, "hotpot", "view", "view.php?id=$cm->id", "$hotpot->id", "$cm->id");
|
|
||||||
|
if (HOTPOT_FIRST_ATTEMPT) {
|
||||||
$attemptid = hotpot_add_attempt($hotpot->id);
|
add_to_log($course->id, "hotpot", "view", "view.php?id=$cm->id", "$hotpot->id", "$cm->id");
|
||||||
if (! is_numeric($attemptid)) {
|
|
||||||
error('Could not insert attempt record: '.$db->ErrorMsg);
|
$attemptid = hotpot_add_attempt($hotpot->id);
|
||||||
|
if (! is_numeric($attemptid)) {
|
||||||
|
error('Could not insert attempt record: '.$db->ErrorMsg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$hp->adjust_media_urls();
|
$hp->adjust_media_urls();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue