2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * This plugin is used to access merlot files
21 * @package repository_merlot
22 * @copyright 2010 Dongsheng Cai {@link http://dongsheng.org}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once($CFG->dirroot
. '/repository/lib.php');
28 * repository_merlot is used to search merlot.org in moodle
31 * @package repository_merlot
32 * @copyright 2009 Dongsheng Cai {@link http://dongsheng.org}
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 class repository_merlot
extends repository
{
37 public function __construct($repositoryid, $context = SYSCONTEXTID
, $options = array()) {
38 parent
::__construct($repositoryid, $context, $options);
39 $this->keyword
= optional_param('merlot_keyword', '', PARAM_RAW
);
40 $this->author
= optional_param('merlot_author', '', PARAM_RAW
);
41 $this->licensekey
= trim(get_config('merlot', 'licensekey'));
45 * Display login screen or not
49 public function check_login() {
50 return !empty($this->keyword
);
54 * Doesn't support global search
58 public function global_search() {
63 * Look for a link in merlot.org
64 * @param string $search_text
67 public function search($search_text, $page = 0) {
69 $ret['nologin'] = true;
70 $ret['list'] = $this->_get_collection($this->keyword
, $this->author
);
78 public function get_listing($path = '', $page = '') {
80 $ret['nologin'] = true;
81 $ret['list'] = $this->_get_collection($this->keyword
);
85 private function _get_collection($keyword) {
88 $this->api
= 'http://www.merlot.org/merlot/materials.rest?keywords=' . urlencode($keyword) . '&licenseKey='.$this->licensekey
;
89 $c = new curl(array('cache'=>true, 'module_cache'=>'repository'));
90 $content = $c->get($this->api
);
91 $xml = simplexml_load_string($content);
92 foreach ($xml->results
->material
as $entry) {
94 'title'=>(string)$entry->title
,
95 'thumbnail'=>$OUTPUT->pix_url(file_extension_icon($entry->title
, 90))->out(false),
96 'date'=>userdate((int)$entry->creationDate
),
98 'source'=>(string)$entry->URL
105 * Define a search form
109 public function print_login(){
111 $search = new stdClass();
112 $search->type
= 'text';
113 $search->id
= 'merlog_search';
114 $search->name
= 'merlot_keyword';
115 $search->label
= get_string('search').': ';
116 $author = new stdClass();
117 $author->type
= 'text';
118 $author->id
= 'merlog_author';
119 $author->name
= 'merlot_author';
120 $author->label
= get_string('author', 'search').': ';
122 $ret['login'] = array($search, $author);
123 $ret['login_btn_label'] = get_string('search');
124 $ret['login_btn_action'] = 'search';
129 * Names of the plugin settings
133 public static function get_type_option_names() {
134 return array('licensekey', 'pluginname');
138 * Add Plugin settings input to Moodle form
140 * @param object $mform
142 public static function type_config_form($mform, $classname = 'repository') {
143 parent
::type_config_form($mform);
144 $licensekey = get_config('merlot', 'licensekey');
145 if (empty($licensekey)) {
148 $strrequired = get_string('required');
149 $mform->addElement('text', 'licensekey', get_string('licensekey', 'repository_merlot'), array('value'=>$licensekey,'size' => '40'));
150 $mform->setType('licensekey', PARAM_RAW_TRIMMED
);
151 $mform->addRule('licensekey', $strrequired, 'required', null, 'client');
155 * Support external link only
159 public function supported_returntypes() {
160 return FILE_EXTERNAL
;
162 public function supported_filetypes() {
163 return array('link');
167 * Is this repository accessing private data?
171 public function contains_private_data() {