-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
132 lines (117 loc) · 4.27 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?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/>.
/**
* Repository plugin which enables users to select RES media URLs as resources.
*
* This requires a RES Moodle plugin service to act as its back-end and to
* present the file chooser.
*
* @package repository_res
* @copyright BBC 2017
* @author Elliot Smith <[email protected]>
* @license GPL v3 - https://www.gnu.org/licenses/gpl-3.0.txt
*/
defined('MOODLE_INTERNAL') || die;
global $CFG;
require_once($CFG->dirroot . '/repository/lib.php');
/**
* Repository plugin providing access to the RES index for media searches.
*
* @package repository_res
* @copyright BBC 2017
* @author Elliot Smith <[email protected]>
* @license GPL v3 - https://www.gnu.org/licenses/gpl-3.0.txt
*/
class repository_res extends repository {
/**
* Create a default instance of the plugin when the plugin starts.
* This will point at the default BBC-maintained RES Moodle plugin
* service.
*
* @return bool
*/
public static function plugin_init() {
$options = array(
'name' => 'RES',
'pluginservice_url' => getenv('PLUGINSERVICE_URL')
);
$id = repository::static_function('res', 'create', 'res', 0,
context_system::instance(),
$options, 0);
return !empty($id);
}
/**
* Expose the RES Moodle plugin service URL as a configuration option.
*
* @return array
*/
public static function get_instance_option_names() {
$optionnames = array('pluginservice_url');
return array_merge(parent::get_instance_option_names(), $optionnames);
}
/**
* An instance can be configured to point at any RES Moodle plugin service
* instance, but defaults to the one maintained by the BBC.
*
* @param object $mform
* @param string $classname
*/
public static function instance_config_form($mform,
$classname = 'repository_res') {
parent::instance_config_form($mform, 'repository_res');
$mform->setDefault('name', 'RES');
$mform->addElement('text', 'pluginservice_url',
get_string('res:pluginservice_url', 'repository_res'),
array('size' => '60'));
$mform->setType('pluginservice_url', PARAM_URL);
$mform->setDefault('pluginservice_url', getenv('PLUGINSERVICE_URL'));
$mform->addRule('pluginservice_url', get_string('required'),
'required', null, 'client');
}
/**
* The listing comes from an external file picker (provided by the RES
* Moodle plugin service).
*
* @param string $path
* @param int $page
* @return array
*/
public function get_listing($path = null, $page = null) {
// Load external filepicker.
$callbackurl = new moodle_url('/repository/res/callback.php') .
'?repo_id=' . $this->id .
'&repo_key=' . $this->get_secret_key();
$pluginserviceurl = $this->get_option('pluginservice_url') .
'?callback=' . urlencode($callbackurl);
return array(
'nologin' => true,
'norefresh' => true,
'nosearch' => true,
'object' => array(
'type' => 'text/html',
'src' => $pluginserviceurl
)
);
}
/**
* Return list of types of resource provided by this plugin.
*
* @return int
*/
public function supported_returntypes() {
return FILE_EXTERNAL;
}
}