aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--displayformula.php8
-rw-r--r--lang/en/qtype_algebra.php3
-rw-r--r--question.php9
-rw-r--r--questiontype.php14
-rw-r--r--settings.php9
5 files changed, 29 insertions, 14 deletions
diff --git a/displayformula.php b/displayformula.php
index dc495d6..dd49486 100644
--- a/displayformula.php
+++ b/displayformula.php
@@ -43,14 +43,18 @@ try {
$texexp='';
} else {
$exp = $p->parse($m[2], $vars);
- $texexp = '$$'.$exp->tex().'$$';
+ if ($CFG->qtype_algebra_texdelimiters == 'old') {
+ $texexp = '$$'.$exp->tex().'$$';
+ } else {
+ $texexp = '\['.$exp->tex().'\]';
+ }
}
} catch (Exception $e) {
$texexp = get_string('parseerror', 'qtype_algebra', $e->getMessage());
}
$formatoptions = new stdClass;
$formatoptions->para = false;
-$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+$PAGE->set_context(context_system::instance());
$text = format_text($texexp, FORMAT_MOODLE, $formatoptions);
?>
<html>
diff --git a/lang/en/qtype_algebra.php b/lang/en/qtype_algebra.php
index 1303dc1..c6a5290 100644
--- a/lang/en/qtype_algebra.php
+++ b/lang/en/qtype_algebra.php
@@ -138,3 +138,6 @@ $string['pluginnamesummary'] = 'Student enter a formula that can include one or
$string['host'] = 'Host url of SAGE server';
$string['port'] = 'Port of SAGE server';
$string['uri'] = 'uri of SAGE server';
+$string['texdelimiters'] = 'Delimiters for TeX expressions';
+$string['dollars'] = '$$...$$';
+$string['brackets'] = '\[...\]'; \ No newline at end of file
diff --git a/question.php b/question.php
index ab024a7..10978a3 100644
--- a/question.php
+++ b/question.php
@@ -126,6 +126,7 @@ class qtype_algebra_question extends question_graded_by_strategy
* @return top term of the parse tree or a string if an exception is thrown
*/
public function formated_expression($text) {
+ global $CFG;
// Create an array of variable names for the parser from the question if defined.
$varnames=array();
@@ -141,7 +142,12 @@ class qtype_algebra_question extends question_graded_by_strategy
// can be caught and converted into errors.
try {
$exp = $p->parse($text, $varnames);
- return '$$'.$exp->tex().'$$';
+ if ($CFG->qtype_algebra_texdelimiters == 'old') {
+ return '$$'.$exp->tex().'$$';
+ } else {
+ return '\['.$exp->tex().'\]';
+ }
+
} catch (Exception $e) {
return '';
}
@@ -216,6 +222,7 @@ class qtype_algebra_question extends question_graded_by_strategy
* @return boolean true if the response matches the answer, false otherwise
*/
public function test_response_by_sage($response, $answer) {
+ global $CFG;
$request=array(
'host' => $CFG->qtype_algebra_host,
'port' => $CFG->qtype_algebra_port,
diff --git a/questiontype.php b/questiontype.php
index 9311964..f755ce8 100644
--- a/questiontype.php
+++ b/questiontype.php
@@ -61,11 +61,13 @@ class qtype_algebra extends question_type {
public function move_files($questionid, $oldcontextid, $newcontextid) {
parent::move_files($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_answers($questionid, $oldcontextid, $newcontextid);
+ $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
}
protected function delete_files($questionid, $contextid) {
parent::delete_files($questionid, $contextid);
$this->delete_files_in_answers($questionid, $contextid);
+ $this->delete_files_in_hints($questionid, $contextid);
}
public function delete_question($questionid, $contextid) {
@@ -272,16 +274,8 @@ class qtype_algebra extends question_type {
$question->allowedfuncs=implode(',', array_keys($question->allowedfuncs));
}
- // Call the parent method to write the extensions fields to the database. This either returns null
- // or an error object so if we get anything then return it otherwise return our existing.
- $parentresult = parent::save_question_options($question);
- if ($parentresult !== null) {
- // Parent function returns null if all is OK.
- return $parentresult;
- } else {
- // Otherwise just return true - this mimics the shortanswer return format.
- return true;
- }
+ parent::save_question_options($question);
+ $this->save_hints($question);
}
/**
diff --git a/settings.php b/settings.php
index 7e19e42..399c04c 100644
--- a/settings.php
+++ b/settings.php
@@ -37,7 +37,14 @@ if ($ADMIN->fulltree) {
// SAGE server connection port.
$settings->add(new admin_setting_configtext('qtype_algebra_port',
get_string('port', 'qtype_algebra'), '', 7777, PARAM_INT));
- // SAGE server connection uri.
+ // SAGE server connection uri.
$settings->add(new admin_setting_configtext('qtype_algebra_uri',
get_string('uri', 'qtype_algebra'), '', '', PARAM_TEXT));
+ // TeX expressions delimiter.
+ $settings->add(new admin_setting_configselect('qtype_algebra_texdelimiters',
+ new lang_string('texdelimiters', 'qtype_algebra'),
+ '', 'old',
+ array('old' => new lang_string('dollars', 'qtype_algebra'),
+ 'new' => new lang_string('brackets', 'qtype_algebra')
+ )));
}