1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Content bank and its plugins settings.
|
|
|
19 |
*
|
|
|
20 |
* @package core
|
|
|
21 |
* @subpackage contentbank
|
|
|
22 |
* @copyright 2020 Amaia Anabitarte <amaia@moodle.com>
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
require_once('../config.php');
|
|
|
27 |
require_once($CFG->libdir.'/adminlib.php');
|
|
|
28 |
|
|
|
29 |
$action = required_param('action', PARAM_ALPHANUMEXT);
|
|
|
30 |
$name = required_param('name', PARAM_PLUGIN);
|
|
|
31 |
|
|
|
32 |
$syscontext = context_system::instance();
|
|
|
33 |
$PAGE->set_url('/admin/contentbank.php');
|
|
|
34 |
$PAGE->set_context($syscontext);
|
|
|
35 |
|
|
|
36 |
require_admin();
|
|
|
37 |
require_sesskey();
|
|
|
38 |
|
|
|
39 |
$return = new moodle_url('/admin/settings.php', array('section' => 'managecontentbanktypes'));
|
|
|
40 |
|
|
|
41 |
$plugins = core_plugin_manager::instance()->get_plugins_of_type('contenttype');
|
|
|
42 |
$sortorder = array_flip(array_keys($plugins));
|
|
|
43 |
|
|
|
44 |
if (!isset($plugins[$name])) {
|
|
|
45 |
throw new \moodle_exception('contenttypenotfound', 'error', $return, $name);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
switch ($action) {
|
|
|
49 |
case 'disable':
|
|
|
50 |
if ($plugins[$name]->is_enabled()) {
|
|
|
51 |
$class = \core_plugin_manager::resolve_plugininfo_class('contenttype');
|
|
|
52 |
$class::enable_plugin($name, false);
|
|
|
53 |
}
|
|
|
54 |
break;
|
|
|
55 |
case 'enable':
|
|
|
56 |
if (!$plugins[$name]->is_enabled()) {
|
|
|
57 |
$class = \core_plugin_manager::resolve_plugininfo_class('contenttype');
|
|
|
58 |
$class::enable_plugin($name, true);
|
|
|
59 |
}
|
|
|
60 |
break;
|
|
|
61 |
case 'up':
|
|
|
62 |
if ($sortorder[$name]) {
|
|
|
63 |
$currentindex = $sortorder[$name];
|
|
|
64 |
$seq = array_keys($plugins);
|
|
|
65 |
$seq[$currentindex] = $seq[$currentindex - 1];
|
|
|
66 |
$seq[$currentindex - 1] = $name;
|
|
|
67 |
set_config('contentbank_plugins_sortorder', implode(',', $seq));
|
|
|
68 |
core_plugin_manager::reset_caches();
|
|
|
69 |
}
|
|
|
70 |
break;
|
|
|
71 |
case 'down':
|
|
|
72 |
if ($sortorder[$name] < count($sortorder) - 1) {
|
|
|
73 |
$currentindex = $sortorder[$name];
|
|
|
74 |
$seq = array_keys($plugins);
|
|
|
75 |
$seq[$currentindex] = $seq[$currentindex + 1];
|
|
|
76 |
$seq[$currentindex + 1] = $name;
|
|
|
77 |
set_config('contentbank_plugins_sortorder', implode(',', $seq));
|
|
|
78 |
core_plugin_manager::reset_caches();
|
|
|
79 |
}
|
|
|
80 |
break;
|
|
|
81 |
}
|
|
|
82 |
$cache = cache::make('core', 'contentbank_enabled_extensions');
|
|
|
83 |
$cache->purge();
|
|
|
84 |
$cache = cache::make('core', 'contentbank_context_extensions');
|
|
|
85 |
$cache->purge();
|
|
|
86 |
|
|
|
87 |
redirect($return);
|