|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00028 class repository_merlot extends repository { 00029 00030 public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) { 00031 parent::__construct($repositoryid, $context, $options); 00032 $this->keyword = optional_param('merlot_keyword', '', PARAM_RAW); 00033 $this->author = optional_param('merlot_author', '', PARAM_RAW); 00034 $this->licensekey = trim(get_config('merlot', 'licensekey')); 00035 } 00036 00042 public function check_login() { 00043 return !empty($this->keyword); 00044 } 00045 00051 public function global_search() { 00052 return false; 00053 } 00054 00060 public function search($search_text) { 00061 $ret = array(); 00062 $ret['nologin'] = true; 00063 $ret['list'] = $this->_get_collection($this->keyword, $this->author); 00064 return $ret; 00065 } 00066 00071 public function get_listing() { 00072 $ret = array(); 00073 $ret['nologin'] = true; 00074 $ret['list'] = $this->_get_collection($this->keyword); 00075 return $ret; 00076 } 00077 00078 private function _get_collection($keyword) { 00079 global $OUTPUT; 00080 $list = array(); 00081 $this->api = 'http://www.merlot.org/merlot/materials.rest?keywords=' . urlencode($keyword) . '&licenseKey='.$this->licensekey; 00082 $c = new curl(array('cache'=>true, 'module_cache'=>'repository')); 00083 $content = $c->get($this->api); 00084 $xml = simplexml_load_string($content); 00085 foreach ($xml->results->material as $entry) { 00086 $list[] = array( 00087 'title'=>(string)$entry->title, 00088 'thumbnail'=>$OUTPUT->pix_url('f/unknown-32')->out(false), 00089 'date'=>userdate((int)$entry->creationDate), 00090 'size'=>'', 00091 'source'=>(string)$entry->URL 00092 ); 00093 } 00094 return $list; 00095 } 00096 00102 public function print_login(){ 00103 $ret = array(); 00104 $search = new stdClass(); 00105 $search->type = 'text'; 00106 $search->id = 'merlog_search'; 00107 $search->name = 'merlot_keyword'; 00108 $search->label = get_string('search').': '; 00109 $author = new stdClass(); 00110 $author->type = 'text'; 00111 $author->id = 'merlog_author'; 00112 $author->name = 'merlot_author'; 00113 $author->label = get_string('author', 'search').': '; 00114 00115 $ret['login'] = array($search, $author); 00116 $ret['login_btn_label'] = get_string('search'); 00117 $ret['login_btn_action'] = 'search'; 00118 return $ret; 00119 } 00120 00126 public static function get_type_option_names() { 00127 return array('licensekey', 'pluginname'); 00128 } 00129 00135 public function type_config_form($mform) { 00136 parent::type_config_form($mform); 00137 $licensekey = get_config('merlot', 'licensekey'); 00138 if (empty($licensekey)) { 00139 $licensekey = ''; 00140 } 00141 $strrequired = get_string('required'); 00142 $mform->addElement('text', 'licensekey', get_string('licensekey', 'repository_merlot'), array('value'=>$licensekey,'size' => '40')); 00143 $mform->addRule('licensekey', $strrequired, 'required', null, 'client'); 00144 } 00145 00151 public function supported_returntypes() { 00152 return FILE_EXTERNAL; 00153 } 00154 public function supported_filetypes() { 00155 return array('link'); 00156 } 00157 } 00158