-
Notifications
You must be signed in to change notification settings - Fork 13
/
lib.php
82 lines (76 loc) · 3.1 KB
/
lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?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/>.
/**
* Library functions for MathType for Atto.
*
* @package atto_wiris
* @subpackage wiris
* @copyright WIRIS Europe (Maths for more S.L)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Initialise the js strings required for this module.
*/
function atto_wiris_strings_for_js() {
global $PAGE;
$PAGE->requires->strings_for_js(
[
'wiris_editor_title',
'wiris_chem_editor_title',
],
'atto_wiris');
}
/**
* Set parameters to be passed to the js plugin constructor.
*/
function atto_wiris_params_for_js() {
global $COURSE, $PAGE, $CFG;
// We need to know if MathType filter are active in the context of the course.
// If not MathType for Atto should be disabled.
$filterwirisactive = true;
// Get MathType and Chemistry buttons enabled configuration.
$editorisactive = get_config('filter_wiris', 'editor_enable');
$chemistryisactive = get_config('filter_wiris', 'chem_editor_enable');
// Filter disabled at course level.
if (!get_config('filter_wiris', 'allow_editorplugin_active_course')) {
$context = context_course::instance($COURSE->id);
$activefilters = filter_get_active_in_context($context);
$filterwirisactive = array_key_exists('wiris', $activefilters);
// Filter disabled at activity level.
if ($filterwirisactive) {
// Check if context is context module.
$pagecontext = $PAGE->context;
// We need to check only module context. Other contexts (like block context)
// shouldn't be checked.
if ($pagecontext instanceof context_module) {
$activefilters = filter_get_active_in_context($PAGE->context);
$filterwirisactive = array_key_exists('wiris', $activefilters);
}
} else {
// If filter is deactivated and allowalways is disabled we don't add buttons.
$editorisactive = false;
$chemistryisactive = false;
}
}
// Atto js plugin checks if the filter is - or not - active.
return ['lang' => current_language(),
'filter_enabled' => $filterwirisactive,
'version' => get_config('atto_wiris', 'version'),
'editor_is_active' => $editorisactive,
'chemistry_is_active' => $chemistryisactive,
"moodleCourse" => $COURSE,
'moodleVersion' => $CFG->branch];
}