forked from HaakonME/moodle-booktool_importepub
-
Notifications
You must be signed in to change notification settings - Fork 18
/
lib.php
71 lines (64 loc) · 3.14 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
<?php
// This file is part of Moodle - http://moodle.org/
//
// This program 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.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
/**
* Import Microsoft Word file - menu configuration.
*
* @package booktool_wordimport
* @copyright 2016 Eoin Campbell
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Adds module specific settings to the settings block
*
* @param settings_navigation $settings The settings navigation object
* @param navigation_node $node The node to add module settings to
*/
function booktool_wordimport_extend_settings_navigation(settings_navigation $settings, navigation_node $node) {
global $PAGE;
if (empty($PAGE->cm) && $PAGE->cm->modname !== 'book') {
return;
}
$params = $PAGE->url->params();
if (empty($params['id']) && empty($params['cmid'])) {
return;
}
if (empty($params['chapterid'])) {
$params['chapterid'] = 0;
}
if (empty($PAGE->cm->context)) {
$PAGE->cm->context = get_context_module::instance($PAGE->cm->instance);
}
if (!(has_capability('mod/book:edit', $PAGE->cm->context))) {
return;
}
// Configure Import link, and pass in the current chapter in case the insert should happen here rather than at the end.
if (has_capability('booktool/wordimport:import', $PAGE->cm->context)) {
$url1 = new moodle_url('/mod/book/tool/wordimport/index.php',
array('id' => $PAGE->cm->id, 'chapterid' => $params['chapterid']));
$node->add(get_string('importchapters', 'booktool_wordimport'), $url1, navigation_node::TYPE_SETTING, null, null,
new pix_icon('f/document', '', 'moodle', array('class' => 'iconsmall', 'title' => '')));
}
// Configure Export links for book and current chapter.
if (has_capability('booktool/wordimport:export', $PAGE->cm->context)) {
$url2 = new moodle_url('/mod/book/tool/wordimport/index.php', array('id' => $PAGE->cm->id, 'action' => 'export'));
$url3 = new moodle_url('/mod/book/tool/wordimport/index.php',
array('id' => $PAGE->cm->id, 'chapterid' => $params['chapterid'], 'action' => 'export'));
$node->add(get_string('exportbook', 'booktool_wordimport'), $url2, navigation_node::TYPE_SETTING,
null, null, new pix_icon('f/document', '', 'moodle', array('class' => 'iconsmall', 'title' => '')));
$node->add(get_string('exportchapter', 'booktool_wordimport'), $url3, navigation_node::TYPE_SETTING,
null, null, new pix_icon('f/document', '', 'moodle', array('class' => 'iconsmall', 'title' => '')));
}
}