mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
MDL-20636 Finish conversion of the Opaque qtype/behaviour.
This commit is contained in:
parent
fe0412432f
commit
2eeb76f845
@ -69,12 +69,12 @@ class qbehaviour_opaque extends question_behaviour {
|
||||
}
|
||||
|
||||
// Set up the random seed to be the current time in milliseconds.
|
||||
list($micros, $sec) = explode(" ", microtime());
|
||||
list($micros, $sec) = explode(' ', microtime());
|
||||
$step->set_behaviour_var('_randomseed', $sec . floor($micros * 1000));
|
||||
$step->set_behaviour_var('_userid', $USER->id);
|
||||
$step->set_behaviour_var('_language', current_language());
|
||||
$step->set_behaviour_var('_preferredbehaviour', $this->preferredbehaviour);
|
||||
$opaquestate = update_opaque_state($this->qa, $step);
|
||||
$opaquestate = qtype_opaque_update_state($this->qa, $step);
|
||||
$step->set_behaviour_var('_statestring', $opaquestate->progressinfo);
|
||||
|
||||
// Remember the question summary.
|
||||
@ -147,10 +147,10 @@ class qbehaviour_opaque extends question_behaviour {
|
||||
}
|
||||
|
||||
public function process_remote_action(question_attempt_pending_step $pendingstep) {
|
||||
$opaquestate = update_opaque_state($this->qa, $pendingstep);
|
||||
|
||||
if (is_string($opaquestate)) {
|
||||
notify($opaquestate);
|
||||
try {
|
||||
$opaquestate = qtype_opaque_update_state($this->qa, $pendingstep);
|
||||
} catch (SoapFault $sf) {
|
||||
print_object($sf);
|
||||
return question_attempt::DISCARD; // TODO
|
||||
}
|
||||
|
||||
|
@ -33,31 +33,33 @@ class qbehaviour_opaque_renderer extends qbehaviour_renderer {
|
||||
array('class' => 'question_aborted'));
|
||||
}
|
||||
|
||||
$opaquestate =& update_opaque_state($qa);
|
||||
if (is_string($opaquestate)) {
|
||||
return notify($opaquestate, '', '', true);
|
||||
// TODO
|
||||
try {
|
||||
$opaquestate = qtype_opaque_update_state($qa);
|
||||
} catch (SoapFault $sf) {
|
||||
return html_writer::tag('div', get_string('errorconnecting', 'qtype_opaque') .
|
||||
html_writer::tag('pre', get_string('soapfault', 'qtype_opaque', $sf), array('class' => 'notifytiny')),
|
||||
array('class' => 'opaqueerror'));
|
||||
}
|
||||
|
||||
return html_writer::tag('div', $opaquestate->xhtml,
|
||||
array('class' => opaque_browser_type()));
|
||||
array('class' => qtype_opaque_browser_type()));
|
||||
}
|
||||
|
||||
public function head_code(question_attempt $qa) {
|
||||
$output = '';
|
||||
$opaquestate =& update_opaque_state($qa);
|
||||
try {
|
||||
$opaquestate = qtype_opaque_update_state($qa);
|
||||
} catch (SoapFault $sf) {
|
||||
// Errors are reported properly elsewhere.
|
||||
return '';
|
||||
}
|
||||
|
||||
$question = $qa->get_question();
|
||||
$resourcecache = new opaque_resource_cache($question->engineid,
|
||||
$resourcecache = new qtype_opaque_resource_cache($question->engineid,
|
||||
$question->remoteid, $question->remoteversion);
|
||||
|
||||
if (!empty($opaquestate->cssfilename) && $resourcecache->file_in_cache($opaquestate->cssfilename)) {
|
||||
$output .= '<link rel="stylesheet" type="text/css" href="' .
|
||||
$resourcecache->file_url($opaquestate->cssfilename) . '" />';
|
||||
}
|
||||
|
||||
if(!empty($opaquestate->headXHTML)) {
|
||||
$output .= $opaquestate->headXHTML;
|
||||
$this->page->requires->css($resourcecache->file_url($opaquestate->cssfilename));
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
@ -250,10 +250,10 @@ DONE question/behaviour/informationitem/lang/en_utf8/qbehaviour_informationitem.
|
||||
DONE question/behaviour/informationitem/renderer.php | 42 +
|
||||
DONE question/behaviour/informationitem/simpletest/testwalkthrough.php | 78 +
|
||||
|
||||
question/behaviour/interactive/behaviour.php | 232 ++
|
||||
DONE question/behaviour/interactive/behaviour.php | 232 ++
|
||||
DONE question/behaviour/interactive/lang/en_utf8/qbehaviour_interactive.php | 6 +
|
||||
DONE question/behaviour/interactive/renderer.php | 62 +
|
||||
question/behaviour/interactive/interactive/simpletest/testwalkthrough.php | 470 ++++
|
||||
DONE question/behaviour/interactive/interactive/simpletest/testwalkthrough.php | 470 ++++
|
||||
|
||||
DONE question/behaviour/interactivecountback/behaviour.php | 91 +
|
||||
DONE question/behaviour/interactivecountback/en_utf8/qbehaviour_interactivecountback.php | 3 +
|
||||
@ -270,10 +270,10 @@ DONE question/behaviour/missing/lang/en_utf8/qbehaviour_missing.php | 3 +
|
||||
DONE question/behaviour/missing/renderer.php | 35 +
|
||||
DONE question/behaviour/missing/simpletest/testmissingbehaviour.php | 96 +
|
||||
|
||||
question/behaviour/opaque/behaviour.php | 197 ++
|
||||
DONE question/behaviour/opaque/behaviour.php | 197 ++
|
||||
DONE question/behaviour/opaque/lang/en_utf8/qbehaviour_opaque.php | 4 +
|
||||
question/behaviour/opaque/renderer.php | 65 +
|
||||
question/behaviour/opaque/simpletest/testopaquebehaviour.php | 227 ++
|
||||
DONE question/behaviour/opaque/renderer.php | 65 +
|
||||
DONE question/behaviour/opaque/simpletest/testopaquebehaviour.php | 227 ++
|
||||
|
||||
DONE question/format.php | 15 +-
|
||||
DONE question/format/blackboard/format.php | 2 +-
|
||||
@ -381,7 +381,7 @@ DONE question/type/opaque/db/upgrade.php | 69 +
|
||||
DONE question/type/opaque/edit_opaque_form.php | 114 +
|
||||
DONE question/type/opaque/editengine.php | 152 +
|
||||
DONE question/type/opaque/engines.php | 78 +
|
||||
question/type/opaque/file.php | 31 +
|
||||
DONE question/type/opaque/file.php | 31 +
|
||||
DONE question/type/opaque/icon.gif | Bin 0 -> 97 bytes
|
||||
DONE question/type/opaque/lang/en_utf8/help/opaque/configuredengines.html | 6 +
|
||||
DONE question/type/opaque/lang/en_utf8/help/opaque/editengine.html | 16 +
|
||||
@ -394,8 +394,8 @@ DONE question/type/opaque/locallib.php | 826 ++++++
|
||||
DONE question/type/opaque/question.php | 55 +
|
||||
DONE question/type/opaque/questiontype.php | 220 ++
|
||||
DONE question/type/opaque/renderer.php | 37 +
|
||||
question/type/opaque/simpletest/testlocallib.php | 60 +
|
||||
question/type/opaque/simpletest/testquestiontype.php | 303 ++
|
||||
DONE question/type/opaque/simpletest/testlocallib.php | 60 +
|
||||
DONE question/type/opaque/simpletest/testquestiontype.php | 303 ++
|
||||
DONE question/type/opaque/styles.css | 14 +
|
||||
DONE question/type/opaque/testengine.php | 70 +
|
||||
DONE question/type/opaque/version.php | 5 +
|
||||
|
@ -71,7 +71,7 @@ class question_edit_opaque_form extends question_edit_form {
|
||||
$errors = parent::validation($data, $files);
|
||||
|
||||
// Check we can connect to this questoin engine.
|
||||
$engine = load_engine_def($data['engineid']);
|
||||
$engine = qtype_opaque_load_engine_def($data['engineid']);
|
||||
if (is_string($engine)) {
|
||||
$errors['engineid'] = $engine;
|
||||
}
|
||||
@ -90,7 +90,7 @@ class question_edit_opaque_form extends question_edit_form {
|
||||
// Try connecting to the remote question engine both as extra validation of the id, and
|
||||
// also to get the default grade.
|
||||
if ($remoteidok) {
|
||||
$metadata = get_question_metadata($engine, $data['remoteid'], $data['remoteversion']);
|
||||
$metadata = qtype_opaque_get_question_metadata($engine, $data['remoteid'], $data['remoteversion']);
|
||||
if (is_string($metadata)) {
|
||||
$errors['remoteid'] = $metadata;
|
||||
} else if (!isset($metadata['questionmetadata']['#']['scoring'][0]['#']['marks'][0]['#'])) {
|
||||
|
@ -1,15 +1,35 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Serves files from the Opaque resource cache.
|
||||
*
|
||||
* @copyright © 2007 The Open University
|
||||
* @author T.J.Hunt@open.ac.uk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @package package_name
|
||||
*//** */
|
||||
* @package qtype
|
||||
* @subpackage opaque
|
||||
* @copyright 2007 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../config.php');
|
||||
require_once(dirname(__FILE__) . '/locallib.php');
|
||||
|
||||
|
||||
$engineid = required_param('engineid', PARAM_INT);
|
||||
$remoteid = required_param('remoteid', PARAM_PATH);
|
||||
$remoteversion = required_param('remoteversion', PARAM_PATH);
|
||||
@ -26,6 +46,5 @@ if ($SESSION->cached_opaque_state->engineid != $engineid ||
|
||||
print_error('cannotaccessfile');
|
||||
}
|
||||
|
||||
$resourcecache = new opaque_resource_cache($engineid, $remoteid, $remoteversion);
|
||||
$resourcecache = new qtype_opaque_resource_cache($engineid, $remoteid, $remoteversion);
|
||||
$resourcecache->serve_file($filename);
|
||||
?>
|
||||
|
@ -20,6 +20,7 @@ $string['editquestionengine_help'] = 'Each remote system you configure must have
|
||||
$string['editquestionengineshort'] = 'Editing engine';
|
||||
$string['enginedeleted'] = 'Engine configuration deleted.';
|
||||
$string['enginename'] = 'Engine name';
|
||||
$string['errorconnecting'] = 'Error connecting to the remote question engine.';
|
||||
$string['getmetadatacallfailed'] = 'Failed to retrieve the metadata for this question. Are you sure the remote id and version are correct?';
|
||||
$string['invalidquestionidsyntax'] = 'This does not match the syntax for a question id';
|
||||
$string['invalidquestionversionsyntax'] = 'The question version should be of the form major.minor, where major and minor are integers.';
|
||||
@ -53,7 +54,11 @@ $string['questionengine_help'] = 'Select the remote question engine that hosts t
|
||||
$string['questionid'] = 'Question id';
|
||||
$string['questionid_help'] = 'Opaque questions are identified by both a question id and a question version number. The person who created the question you are trying to refer to will be able to tell you these.';
|
||||
$string['questionversion'] = 'Question version';
|
||||
$string['soapfault'] = 'Soap fault: Fault code: {$a->faultcode}. Fault actor: {$a->faultactor}. Fault string: {$a->faultstring}. Fault detail: {$a->faultdetail}.';
|
||||
$string['soapfault'] = 'Technical details:
|
||||
Fault code: {$a->faultcode}.
|
||||
Fault actor: {$a->faultactor}.
|
||||
Fault string: {$a->faultstring}.
|
||||
Fault detail: {$a->faultdetail}.';
|
||||
$string['startcallfailed'] = 'Failed to start a question session. {$a}';
|
||||
$string['stopcallfailed'] = 'Failed to close question session. {$a}';
|
||||
$string['testconnection'] = 'Test connection';
|
||||
|
@ -174,7 +174,7 @@ class qtype_opaque_engine_manager {
|
||||
$conditions[] = 'qb.url = :qburl';
|
||||
$params['qburl'] = $qburl;
|
||||
}
|
||||
return get_records_sql_menu('
|
||||
return $DB->get_records_sql_menu('
|
||||
SELECT e.id,1 ' . implode(' ', $tables) . ' WHERE ' .
|
||||
implode(' AND ', $conditions), $params);
|
||||
}
|
||||
@ -335,7 +335,7 @@ function qtype_opaque_start_question_session($engine, $remoteid, $remoteversion,
|
||||
'randomseed' => $data['-_randomseed'],
|
||||
'userid' => $data['-_userid'],
|
||||
'language' => $data['-_language'],
|
||||
'passKey' => generate_passkey($engine->passkey, $data['-_userid']),
|
||||
'passKey' => qtype_opaque_generate_passkey($engine->passkey, $data['-_userid']),
|
||||
'preferredbehaviour' => $data['-_preferredbehaviour'],
|
||||
);
|
||||
|
||||
@ -400,7 +400,7 @@ function qtype_opaque_update_state(question_attempt $qa, question_attempt_step $
|
||||
} else if ($SESSION->cached_opaque_state->qaid != $qa->get_database_id() ||
|
||||
$SESSION->cached_opaque_state->sequencenumber > $targetseq) {
|
||||
if (!empty($SESSION->cached_opaque_state->questionsessionid)) {
|
||||
$error = stop_question_session($SESSION->cached_opaque_state->engine,
|
||||
$error = qtype_opaque_stop_question_session($SESSION->cached_opaque_state->engine,
|
||||
$SESSION->cached_opaque_state->questionsessionid);
|
||||
if (is_string($error)) {
|
||||
unset($SESSION->cached_opaque_state);
|
||||
@ -415,7 +415,7 @@ function qtype_opaque_update_state(question_attempt $qa, question_attempt_step $
|
||||
$cachestatus = 'good';
|
||||
}
|
||||
|
||||
$resourcecache = new opaque_resource_cache($question->engineid,
|
||||
$resourcecache = new qtype_opaque_resource_cache($question->engineid,
|
||||
$question->remoteid, $question->remoteversion);
|
||||
|
||||
if ($cachestatus == 'empty') {
|
||||
@ -430,22 +430,22 @@ function qtype_opaque_update_state(question_attempt $qa, question_attempt_step $
|
||||
$opaquestate->sequencenumber = -1;
|
||||
$opaquestate->resultssequencenumber = -1;
|
||||
|
||||
$engine = load_engine_def($question->engineid);
|
||||
$engine = qtype_opaque_load_engine_def($question->engineid);
|
||||
if (is_string($engine)) {
|
||||
unset($SESSION->cached_opaque_state);
|
||||
return $engine;
|
||||
}
|
||||
$opaquestate->engine = $engine;
|
||||
|
||||
$step = opaque_get_step(0, $qa, $pendingstep);
|
||||
$startreturn = start_question_session($engine, $question->remoteid,
|
||||
$step = qtype_opaque_get_step(0, $qa, $pendingstep);
|
||||
$startreturn = qtype_opaque_start_question_session($engine, $question->remoteid,
|
||||
$question->remoteversion, $step->get_all_data(), $resourcecache->list_cached_resources());
|
||||
if (is_string($startreturn)) {
|
||||
unset($SESSION->cached_opaque_state);
|
||||
return $startreturn;
|
||||
}
|
||||
|
||||
extract_stuff_from_response($opaquestate, $startreturn, $resourcecache);
|
||||
qtype_opaque_extract_stuff_from_response($opaquestate, $startreturn, $resourcecache);
|
||||
$opaquestate->sequencenumber++;
|
||||
$cachestatus = 'catchup';
|
||||
} else {
|
||||
@ -454,13 +454,13 @@ function qtype_opaque_update_state(question_attempt $qa, question_attempt_step $
|
||||
|
||||
if ($cachestatus == 'catchup') {
|
||||
if ($opaquestate->sequencenumber >= $targetseq) {
|
||||
$error = stop_question_session($opaquestate->engine,
|
||||
$error = qtype_opaque_stop_question_session($opaquestate->engine,
|
||||
$opaquestate->questionsessionid);
|
||||
}
|
||||
while ($opaquestate->sequencenumber < $targetseq) {
|
||||
$step = opaque_get_step($opaquestate->sequencenumber + 1, $qa, $pendingstep);
|
||||
$step = qtype_opaque_get_step($opaquestate->sequencenumber + 1, $qa, $pendingstep);
|
||||
|
||||
$processreturn = opaque_process($opaquestate->engine, $opaquestate->questionsessionid, $step->get_submitted_data());
|
||||
$processreturn = qtype_opaque_process($opaquestate->engine, $opaquestate->questionsessionid, $step->get_submitted_data());
|
||||
if (is_string($processreturn)) {
|
||||
unset($SESSION->cached_opaque_state);
|
||||
return $processreturn;
|
||||
@ -473,11 +473,11 @@ function qtype_opaque_update_state(question_attempt $qa, question_attempt_step $
|
||||
if ($processreturn->questionEnd) {
|
||||
$opaquestate->questionended = true;
|
||||
$opaquestate->sequencenumber = $targetseq;
|
||||
$opaquestate->xhtml = strip_omact_buttons($opaquestate->xhtml);
|
||||
$opaquestate->xhtml = qtype_opaque_strip_omact_buttons($opaquestate->xhtml);
|
||||
unset($opaquestate->questionsessionid);
|
||||
break;
|
||||
}
|
||||
extract_stuff_from_response($opaquestate, $processreturn, $resourcecache);
|
||||
qtype_opaque_extract_stuff_from_response($opaquestate, $processreturn, $resourcecache);
|
||||
|
||||
$opaquestate->sequencenumber++;
|
||||
}
|
||||
@ -538,14 +538,14 @@ function qtype_opaque_extract_stuff_from_response($opaquestate, $response, $reso
|
||||
// Actually, we remove any non-disabled buttons, and the following script tag.
|
||||
// TODO think of a better way to do this.
|
||||
if ($opaquestate->resultssequencenumber >= 0) {
|
||||
$xhtml = strip_omact_buttons($xhtml);
|
||||
$xhtml = qtype_opaque_strip_omact_buttons($xhtml);
|
||||
}
|
||||
|
||||
$opaquestate->xhtml = $xhtml;
|
||||
|
||||
// Process the CSS (only when we have a StartResponse).
|
||||
if (!empty($response->CSS)) {
|
||||
$opaquestate->cssfilename = opaque_stylesheet_filename($response->questionSession);
|
||||
$opaquestate->cssfilename = qtype_opaque_stylesheet_filename($response->questionSession);
|
||||
$resourcecache->cache_file($opaquestate->cssfilename, 'text/css;charset=UTF-8', $response->CSS);
|
||||
}
|
||||
|
||||
@ -623,7 +623,7 @@ class qtype_opaque_resource_cache {
|
||||
protected $baseurl; // initial part of the URL to link to a file in the cache.
|
||||
|
||||
/**
|
||||
* Create a new opaque_resource_cache for a particular remote question.
|
||||
* Create a new qtype_opaque_resource_cache for a particular remote question.
|
||||
* @param integer $engineid the id of the question engine.
|
||||
* @param string $remoteid remote question id, as per Opaque spec.
|
||||
* @param string $remoteversion remote question version, as per Opaque spec.
|
||||
@ -639,9 +639,8 @@ class qtype_opaque_resource_cache {
|
||||
if (!is_dir($this->metadatafolder)) {
|
||||
$this->mkdir_recursive($this->metadatafolder);
|
||||
}
|
||||
$this->baseurl = $CFG->wwwroot . '/question/type/opaque/file.php?engineid=' .
|
||||
$engineid . '&remoteid=' . $remoteid .
|
||||
'&remoteversion=' . $remoteversion . '&filename=';
|
||||
$this->baseurl = new moodle_url('/question/type/opaque/file.php', array(
|
||||
'engineid' => $engineid, 'remoteid' => $remoteid, 'remoteversion' => $remoteversion));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -665,7 +664,7 @@ class qtype_opaque_resource_cache {
|
||||
* @return the URL to access this file.
|
||||
*/
|
||||
public function file_url($filename) {
|
||||
return $this->baseurl . $filename;
|
||||
return new moodle_url($this->baseurl, array('filename' => $filename));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,12 +59,12 @@ class qtype_opaque extends question_type {
|
||||
return array('question_opaque', 'engineid', 'remoteid', 'remoteversion');
|
||||
}
|
||||
|
||||
function save_question($question, $form, $course) {
|
||||
function save_question($question, $form) {
|
||||
$form->questiontext = '';
|
||||
$form->questiontextformat = FORMAT_MOODLE;
|
||||
$form->unlimited = 0;
|
||||
$form->penalty = 0;
|
||||
return parent::save_question($question, $form, $course);
|
||||
return parent::save_question($question, $form);
|
||||
}
|
||||
|
||||
protected function initialise_question_instance(question_definition $question, $questiondata) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user