3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * repository_merlot is used to search merlot.org in moodle
24 * @copyright 2009 Dongsheng Cai
25 * @author Dongsheng Cai <dongsheng@moodle.com>
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 class repository_merlot
extends repository
{
30 public function __construct($repositoryid, $context = SYSCONTEXTID
, $options = array()) {
31 parent
::__construct($repositoryid, $context, $options);
32 $this->keyword
= optional_param('merlot_keyword', '', PARAM_RAW
);
33 $this->author
= optional_param('merlot_author', '', PARAM_RAW
);
34 $this->licensekey
= trim(get_config('merlot', 'licensekey'));
38 * Display login screen or not
42 public function check_login() {
43 return !empty($this->keyword
);
47 * Doesn't support global search
51 public function global_search() {
56 * Look for a link in merlot.org
57 * @param string $search_text
60 public function search($search_text) {
62 $ret['nologin'] = true;
63 $ret['list'] = $this->_get_collection($this->keyword
, $this->author
);
71 public function get_listing() {
73 $ret['nologin'] = true;
74 $ret['list'] = $this->_get_collection($this->keyword
);
78 private function _get_collection($keyword) {
81 $this->api
= 'http://www.merlot.org/merlot/materials.rest?keywords=' . urlencode($keyword) . '&licenseKey='.$this->licensekey
;
82 $c = new curl(array('cache'=>true, 'module_cache'=>'repository'));
83 $content = $c->get($this->api
);
84 $xml = simplexml_load_string($content);
85 foreach ($xml->results
->material
as $entry) {
87 'title'=>(string)$entry->title
,
88 'thumbnail'=>$OUTPUT->pix_url('f/unknown-32')->out(false),
89 'date'=>userdate((int)$entry->creationDate
),
91 'source'=>(string)$entry->URL
98 * Define a search form
102 public function print_login(){
104 $search = new stdClass();
105 $search->type
= 'text';
106 $search->id
= 'merlog_search';
107 $search->name
= 'merlot_keyword';
108 $search->label
= get_string('search').': ';
109 $author = new stdClass();
110 $author->type
= 'text';
111 $author->id
= 'merlog_author';
112 $author->name
= 'merlot_author';
113 $author->label
= get_string('author', 'search').': ';
115 $ret['login'] = array($search, $author);
116 $ret['login_btn_label'] = get_string('search');
117 $ret['login_btn_action'] = 'search';
122 * Names of the plugin settings
126 public static function get_type_option_names() {
127 return array('licensekey', 'pluginname');
131 * Add Plugin settings input to Moodle form
133 * @param object $mform
135 public function type_config_form($mform) {
136 parent
::type_config_form($mform);
137 $licensekey = get_config('merlot', 'licensekey');
138 if (empty($licensekey)) {
141 $strrequired = get_string('required');
142 $mform->addElement('text', 'licensekey', get_string('licensekey', 'repository_merlot'), array('value'=>$licensekey,'size' => '40'));
143 $mform->addRule('licensekey', $strrequired, 'required', null, 'client');
147 * Support external link only
151 public function supported_returntypes() {
152 return FILE_EXTERNAL
;
154 public function supported_filetypes() {
155 return array('link');