-
Notifications
You must be signed in to change notification settings - Fork 7
/
lib.php
80 lines (75 loc) · 2.67 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
<?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/>.
/**
* Templates Lib.
* @package atto_templates4u
* @author Mark Sharp <m.sharp@chi.ac.uk>
* @copyright 2017 University of Chichester {@link https://www.chi.ac.uk}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Set language strings for js
*/
function atto_templates4u_strings_for_js() {
global $PAGE;
$PAGE->requires->strings_for_js(
['dialogtitle',
'template',
'selectatemplate',
'description',
'insert',
'cancel',
'preview',
], 'atto_templates4u');
}
/**
* Return the js params required for this module
* @param string $elementid Selected element
* @param stdClass $options - the options for the editor
* @param stdClass $fpoptions - unused
* @return array List of templates
*/
function atto_templates4u_params_for_js($elementid, $options, $fpoptions) {
global $COURSE;
$templates = get_config('atto_templates4u');
$tcount = ($templates->templatecount) ? $templates->templatecount : 5;
$items = [];
for ($i = 1; $i <= $tcount; $i++) {
$key = 'templatekey_' . $i;
if (isset($templates->{$key}) && !empty(trim($templates->{$key}))) {
$item = new stdClass();
$item->templatekey = trim($templates->{'templatekey_' . $i});
if ($templates->cleanhtml) {
$item->template = purify_html(
$templates->{'template_' . $i}, ['allowid' => true]);
} else {
$item->template = $templates->{'template_' . $i};
}
$items[] = $item;
}
}
$coursecontext = context_course::instance($COURSE->id);
$enablebutton = ($templates->requirecap) ? has_capability('atto/templates4u:usetemplates', $coursecontext) : true;
return ['templates' => $items, 'enablebutton' => $enablebutton];
}
/**
* Get icon mapping for font-awesome.
*/
function atto_templates4u_get_fontawesome_icon_map() {
return [
'atto_templates4u:icon' => 'fa-wpforms',
];
}