From 02f223a1a9ea9c5f500785b035d6a1355a833724 Mon Sep 17 00:00:00 2001 From: Tim Hunt <T.J.Hunt@open.ac.uk> Date: Thu, 28 Jan 2016 09:47:43 +0000 Subject: [PATCH] Add support for the new OU maths filter. #178 --- lang/en/qtype_stack.php | 3 +- settingslib.php | 4 ++ .../mathsoutput/mathsoutputoumaths.class.php | 56 +++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 stack/mathsoutput/mathsoutputoumaths.class.php diff --git a/lang/en/qtype_stack.php b/lang/en/qtype_stack.php index 3f47c59dc..0ab37eae0 100644 --- a/lang/en/qtype_stack.php +++ b/lang/en/qtype_stack.php @@ -333,7 +333,8 @@ $string['settingdefaultquestionoptions_desc'] = 'Used when creating a new questi $string['settingmathsdisplay'] = 'Maths filter'; $string['settingmathsdisplay_mathjax'] = 'MathJax'; $string['settingmathsdisplay_tex'] = 'Moodle TeX filter'; -$string['settingmathsdisplay_maths'] = 'OU maths filter'; +$string['settingmathsdisplay_maths'] = 'Old OU maths filter'; +$string['settingmathsdisplay_oumaths'] = 'New OU maths filter'; $string['settingmathsdisplay_desc'] = 'The method used to display maths. If you select MathJax, then you will need to follow the instructions on the Healthcheck page to set it up. If you select a filter, then you must ensure that filter is enabled on the Manage filters configuration page.'; $string['settingsmathsdisplayheading'] = 'Maths display options'; $string['settingsmaximasettings'] = 'Connecting to Maxima'; diff --git a/settingslib.php b/settingslib.php index 63754078d..c2bd61e3f 100644 --- a/settingslib.php +++ b/settingslib.php @@ -56,6 +56,10 @@ class qtype_stack_admin_setting_maths_display_method extends admin_setting_confi $this->choices['maths'] = get_string('settingmathsdisplay_maths', 'qtype_stack'); } + if (array_key_exists('oumaths', $filters)) { + $this->choices['oumaths'] = get_string('settingmathsdisplay_oumaths', 'qtype_stack'); + } + return true; } } diff --git a/stack/mathsoutput/mathsoutputoumaths.class.php b/stack/mathsoutput/mathsoutputoumaths.class.php new file mode 100644 index 000000000..f7f0c1104 --- /dev/null +++ b/stack/mathsoutput/mathsoutputoumaths.class.php @@ -0,0 +1,56 @@ +<?php +// This file is part of Stack - http://stack.bham.ac.uk/ +// +// Stack 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. +// +// Stack 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 Stack. If not, see <http://www.gnu.org/licenses/>. + + +global $CFG; +require_once($CFG->libdir . '/filterlib.php'); +require_once(__DIR__ . '/mathsoutputfilterbase.class.php'); + + +/** + * STACK maths output methods for using The OU's maths filter. + * + * @copyright 2012 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class stack_maths_output_oumaths extends stack_maths_output_filter_base { + + /** + * @return boolean is the OU maths filter installed? + */ + public static function filter_is_installed() { + global $CFG; + return file_exists($CFG->dirroot . '/filter/maths/filter.php'); + } + + protected function initialise_delimiters() { + $this->displaystart = '<tex mode="display">'; + $this->displayend = '</tex>'; + $this->inlinestart = '<tex mode="inline">'; + $this->inlineend = '</tex>'; + } + + protected function make_filter() { + global $CFG; + + if (!self::filter_is_installed()) { + throw new coding_exception('The OU maths filter is not installed.'); + } + + require_once($CFG->dirroot . '/filter/oumaths/filter.php'); + return new filter_oumaths(context_system::instance(), array()); + } +} -- GitLab