Commit | Line | Data |
---|---|---|
07ab0c80 | 1 | <?php |
178f282b | 2 | |
07ab0c80 | 3 | /////////////////////////////////////////////////////////////////////////// |
4 | // // | |
5 | // This file is part of Moodle - http://moodle.org/ // | |
6 | // Moodle - Modular Object-Oriented Dynamic Learning Environment // | |
7 | // // | |
8 | // Moodle is free software: you can redistribute it and/or modify // | |
9 | // it under the terms of the GNU General Public License as published by // | |
10 | // the Free Software Foundation, either version 3 of the License, or // | |
11 | // (at your option) any later version. // | |
12 | // // | |
13 | // Moodle is distributed in the hope that it will be useful, // | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
16 | // GNU General Public License for more details. // | |
17 | // // | |
18 | // You should have received a copy of the GNU General Public License // | |
19 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. // | |
20 | // // | |
21 | /////////////////////////////////////////////////////////////////////////// | |
22 | ||
23 | /* | |
24 | * @package blocks | |
25 | * @subpackage community | |
26 | * @author Jerome Mouneyrac <jerome@mouneyrac.com> | |
27 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL | |
28 | * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com | |
29 | * | |
30 | * Form for community search | |
178f282b | 31 | */ |
07ab0c80 | 32 | |
a8e174cc | 33 | require_once($CFG->libdir . '/formslib.php'); |
178f282b | 34 | require_once($CFG->dirroot . '/course/publish/lib.php'); |
a8e174cc | 35 | require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php'); |
07ab0c80 | 36 | |
37 | class community_hub_search_form extends moodleform { | |
38 | ||
39 | public function definition() { | |
178f282b | 40 | global $CFG, $USER, $OUTPUT; |
07ab0c80 | 41 | $strrequired = get_string('required'); |
178f282b | 42 | $mform = & $this->_form; |
c48ab36a | 43 | |
44 | //set default value | |
07ab0c80 | 45 | $search = $this->_customdata['search']; |
c48ab36a | 46 | if (isset($this->_customdata['coverage'])) { |
47 | $coverage = $this->_customdata['coverage']; | |
48 | } else { | |
49 | $coverage = 'all'; | |
50 | } | |
51 | if (isset($this->_customdata['licence'])) { | |
52 | $licence = $this->_customdata['licence']; | |
53 | } else { | |
54 | $licence = 'all'; | |
55 | } | |
56 | if (isset($this->_customdata['subject'])) { | |
57 | $subject = $this->_customdata['subject']; | |
58 | } else { | |
59 | $subject = 'all'; | |
60 | } | |
61 | if (isset($this->_customdata['audience'])) { | |
62 | $audience = $this->_customdata['audience']; | |
63 | } else { | |
64 | $audience = 'all'; | |
65 | } | |
66 | if (isset($this->_customdata['language'])) { | |
67 | $language = $this->_customdata['language']; | |
68 | } else { | |
fb5302b5 | 69 | $language = current_language(); |
c48ab36a | 70 | } |
71 | if (isset($this->_customdata['educationallevel'])) { | |
72 | $educationallevel = $this->_customdata['educationallevel']; | |
73 | } else { | |
74 | $educationallevel = 'all'; | |
75 | } | |
76 | if (isset($this->_customdata['downloadable'])) { | |
77 | $downloadable = $this->_customdata['downloadable']; | |
78 | } else { | |
79 | $downloadable = 0; | |
80 | } | |
81 | if (isset($this->_customdata['orderby'])) { | |
82 | $orderby = $this->_customdata['orderby']; | |
83 | } else { | |
84 | $orderby = 'newest'; | |
85 | } | |
86 | if (isset($this->_customdata['huburl'])) { | |
87 | $huburl = $this->_customdata['huburl']; | |
88 | } else { | |
89 | $huburl = HUB_MOODLEORGHUBURL; | |
90 | } | |
91 | ||
07ab0c80 | 92 | $mform->addElement('header', 'site', get_string('search', 'block_community')); |
93 | ||
b48c4478 | 94 | //add the course id (of the context) |
95 | $mform->addElement('hidden', 'courseid', $this->_customdata['courseid']); | |
c48ab36a | 96 | $mform->addElement('hidden', 'executesearch', 1); |
b48c4478 | 97 | |
07ab0c80 | 98 | //retrieve the hub list on the hub directory by web service |
99 | $function = 'hubdirectory_get_hubs'; | |
100 | $params = array(); | |
178f282b | 101 | $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php"; |
102 | require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php"); | |
001251f2 | 103 | $xmlrpcclient = new webservice_xmlrpc_client($serverurl, 'publichubdirectory'); |
178f282b | 104 | try { |
001251f2 | 105 | $hubs = $xmlrpcclient->call($function, $params); |
178f282b | 106 | } catch (Exception $e) { |
107 | $hubs = array(); | |
108 | $error = $OUTPUT->notification(get_string('errorhublisting', 'block_community', $e->getMessage())); | |
109 | $mform->addElement('static', 'errorhub', '', $error); | |
07ab0c80 | 110 | } |
ac90abb4 | 111 | |
112 | //display list of registered on hub | |
113 | $registrationmanager = new registration_manager(); | |
114 | $registeredhubs = $registrationmanager->get_registered_on_hubs(); | |
115 | //retrieve some additional hubs that we will add to | |
116 | //the hub list got from the hub directory | |
117 | $additionalhubs = array(); | |
118 | foreach ($registeredhubs as $registeredhub) { | |
119 | $inthepubliclist = false; | |
120 | foreach ($hubs as $hub) { | |
121 | if ($hub['url'] == $registeredhub->huburl) { | |
122 | $inthepubliclist = true; | |
123 | $hub['registeredon'] = true; | |
124 | } | |
125 | } | |
126 | if (!$inthepubliclist) { | |
127 | $additionalhub = array(); | |
128 | $additionalhub['name'] = $registeredhub->hubname; | |
129 | $additionalhub['url'] = $registeredhub->huburl; | |
130 | $additionalhubs[] = $additionalhub; | |
131 | } | |
132 | } | |
133 | if (!empty($additionalhubs)) { | |
6a658c91 | 134 | $hubs = array_merge($hubs, $additionalhubs); |
ac90abb4 | 135 | } |
136 | ||
137 | if (!empty($hubs)) { | |
138 | //TODO: sort hubs by trusted/prioritize | |
178f282b | 139 | //Public hub list |
140 | $options = array(); | |
d2a8163d | 141 | $firsthub = false; |
178f282b | 142 | foreach ($hubs as $hub) { |
ac90abb4 | 143 | if (key_exists('id', $hub)) { |
144 | $params = array('hubid' => $hub['id'], | |
145 | 'filetype' => HUB_HUBSCREENSHOT_FILE_TYPE); | |
fb6b4542 | 146 | $imgurl = new moodle_url(HUB_HUBDIRECTORYURL . |
2031735b | 147 | "/local/hubdirectory/webservice/download.php", $params); |
fb6b4542 | 148 | $ascreenshothtml = html_writer::empty_tag('img', |
2031735b | 149 | array('src' => $imgurl, 'alt' => $hub['name'])); |
c6947ba7 | 150 | |
2031735b | 151 | $hubdescription = html_writer::tag('a', $hub['name'], |
152 | array('class' => 'hublink clearfix', 'href' => $hub['url'], | |
fb6b4542 | 153 | 'onclick' => 'this.target="_blank"')); |
fb6b4542 | 154 | $hubdescription .= html_writer::tag('span', $ascreenshothtml, |
2031735b | 155 | array('class' => 'hubscreenshot')); |
d4f866ea | 156 | $hubdescriptiontext = html_writer::tag('span', format_text($hub['description'], FORMAT_PLAIN), |
2031735b | 157 | array('class' => 'hubdescription')); |
dd0c9fb1 | 158 | if (isset($hub['enrollablecourses'])) { //check needed to avoid warnings for Moodle version < 2011081700 |
4962df40 JM |
159 | $additionaldesc = get_string('enrollablecourses', 'block_community') . ': ' . $hub['enrollablecourses'] . ' - ' . |
160 | get_string('downloadablecourses', 'block_community') . ': ' . $hub['downloadablecourses']; | |
161 | $hubdescriptiontext .= html_writer::tag('span', $additionaldesc, | |
162 | array('class' => 'hubadditionaldesc')); | |
163 | } | |
d4f866ea | 164 | if ($hub['trusted']) { |
165 | $hubtrusted = get_string('hubtrusted', 'block_community'); | |
166 | $hubdescriptiontext .= html_writer::tag('span', | |
2031735b | 167 | $hubtrusted . ' ' . $OUTPUT->doc_link('trusted_hubs'), |
d4f866ea | 168 | array('class' => 'trusted')); |
169 | ||
170 | } | |
171 | $hubdescriptiontext = html_writer::tag('span', $hubdescriptiontext, | |
172 | array('class' => 'hubdescriptiontext')); | |
2031735b | 173 | |
ac90abb4 | 174 | $hubdescription = html_writer::tag('span', |
d4f866ea | 175 | $hubdescription . $hubdescriptiontext, |
ac90abb4 | 176 | array('class' => $hub['trusted'] ? 'hubtrusted' : 'hubnottrusted')); |
177 | } else { | |
cbe80ba5 | 178 | $hubdescription = html_writer::tag('a', $hub['name'], |
6a658c91 | 179 | array('class' => 'hublink hubtrusted', 'href' => $hub['url'])); |
ac90abb4 | 180 | } |
178f282b | 181 | |
182 | if (empty($firsthub)) { | |
183 | $mform->addElement('radio', 'huburl', get_string('selecthub', 'block_community'), | |
184 | $hubdescription, $hub['url']); | |
c48ab36a | 185 | $mform->setDefault('huburl', $huburl); |
178f282b | 186 | $firsthub = true; |
187 | } else { | |
188 | $mform->addElement('radio', 'huburl', '', $hubdescription, $hub['url']); | |
189 | } | |
190 | } | |
07ab0c80 | 191 | |
8a3b20ce | 192 | //display enrol/download select box if the USER has the download capability on the course |
fb6b4542 | 193 | if (has_capability('moodle/community:download', |
194 | get_context_instance(CONTEXT_COURSE, $this->_customdata['courseid']))) { | |
178f282b | 195 | $options = array(0 => get_string('enrollable', 'block_community'), |
755f96f8 | 196 | 1 => get_string('downloadable', 'block_community')); |
178f282b | 197 | $mform->addElement('select', 'downloadable', get_string('enroldownload', 'block_community'), |
198 | $options); | |
199 | $mform->addHelpButton('downloadable', 'enroldownload', 'block_community'); | |
200 | } else { | |
201 | $mform->addElement('hidden', 'downloadable', 0); | |
202 | } | |
07ab0c80 | 203 | |
178f282b | 204 | $options = array(); |
205 | $options['all'] = get_string('any'); | |
206 | $options[HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub'); | |
207 | $options[HUB_AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub'); | |
208 | $options[HUB_AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub'); | |
209 | $mform->addElement('select', 'audience', get_string('audience', 'block_community'), $options); | |
c48ab36a | 210 | $mform->setDefault('audience', $audience); |
178f282b | 211 | unset($options); |
212 | $mform->addHelpButton('audience', 'audience', 'block_community'); | |
213 | ||
214 | $options = array(); | |
215 | $options['all'] = get_string('any'); | |
216 | $options[HUB_EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'hub'); | |
217 | $options[HUB_EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'hub'); | |
218 | $options[HUB_EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'hub'); | |
219 | $options[HUB_EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'hub'); | |
220 | $options[HUB_EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'hub'); | |
221 | $options[HUB_EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub'); | |
222 | $options[HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'hub'); | |
223 | $mform->addElement('select', 'educationallevel', | |
224 | get_string('educationallevel', 'block_community'), $options); | |
c48ab36a | 225 | $mform->setDefault('educationallevel', $educationallevel); |
178f282b | 226 | unset($options); |
227 | $mform->addHelpButton('educationallevel', 'educationallevel', 'block_community'); | |
228 | ||
efba7034 | 229 | $publicationmanager = new course_publish_manager(); |
230 | $options = $publicationmanager->get_sorted_subjects(); | |
178f282b | 231 | foreach ($options as $key => &$option) { |
232 | $keylength = strlen($key); | |
233 | if ($keylength == 10) { | |
234 | $option = " " . $option; | |
235 | } else if ($keylength == 12) { | |
236 | $option = " " . $option; | |
237 | } | |
abf63f98 | 238 | } |
178f282b | 239 | $options = array_merge(array('all' => get_string('any')), $options); |
240 | $mform->addElement('select', 'subject', get_string('subject', 'block_community'), | |
241 | $options, array('id' => 'communitysubject')); | |
c48ab36a | 242 | $mform->setDefault('subject', $subject); |
178f282b | 243 | unset($options); |
244 | $mform->addHelpButton('subject', 'subject', 'block_community'); | |
245 | $this->init_javascript_enhancement('subject', 'smartselect', | |
246 | array('selectablecategories' => true, 'mode' => 'compact')); | |
247 | ||
a8e174cc | 248 | require_once($CFG->libdir . "/licenselib.php"); |
178f282b | 249 | $licensemanager = new license_manager(); |
250 | $licences = $licensemanager->get_licenses(); | |
251 | $options = array(); | |
252 | $options['all'] = get_string('any'); | |
253 | foreach ($licences as $license) { | |
254 | $options[$license->shortname] = get_string($license->shortname, 'license'); | |
255 | } | |
256 | $mform->addElement('select', 'licence', get_string('licence', 'block_community'), $options); | |
178f282b | 257 | unset($options); |
258 | $mform->addHelpButton('licence', 'licence', 'block_community'); | |
c48ab36a | 259 | $mform->setDefault('licence', $licence); |
276f590e | 260 | |
178f282b | 261 | $languages = get_string_manager()->get_list_of_languages(); |
c6947ba7 | 262 | textlib_get_instance()->asort($languages); |
178f282b | 263 | $languages = array_merge(array('all' => get_string('any')), $languages); |
264 | $mform->addElement('select', 'language', get_string('language'), $languages); | |
c48ab36a | 265 | $mform->setDefault('language', $language); |
178f282b | 266 | $mform->addHelpButton('language', 'language', 'block_community'); |
276f590e | 267 | |
43a58be7 | 268 | $mform->addElement('radio', 'orderby', get_string('orderby', 'block_community'), |
269 | get_string('orderbynewest', 'block_community'), 'newest'); | |
270 | $mform->addElement('radio', 'orderby', null, | |
271 | get_string('orderbyeldest', 'block_community'), 'eldest'); | |
272 | $mform->addElement('radio', 'orderby', null, | |
273 | get_string('orderbyname', 'block_community'), 'fullname'); | |
274 | $mform->addElement('radio', 'orderby', null, | |
275 | get_string('orderbypublisher', 'block_community'), 'publisher'); | |
7a0d0804 | 276 | $mform->addElement('radio', 'orderby', null, |
277 | get_string('orderbyratingaverage', 'block_community'), 'ratingaverage'); | |
c48ab36a | 278 | $mform->setDefault('orderby', $orderby); |
43a58be7 | 279 | $mform->setType('orderby', PARAM_ALPHA); |
280 | ||
178f282b | 281 | $mform->addElement('text', 'search', get_string('keywords', 'block_community')); |
282 | $mform->addHelpButton('search', 'keywords', 'block_community'); | |
276f590e | 283 | |
07ab0c80 | 284 | |
178f282b | 285 | $mform->addElement('submit', 'submitbutton', get_string('search', 'block_community')); |
286 | } | |
07ab0c80 | 287 | } |
288 | ||
276f590e | 289 | function validation($data, $files) { |
290 | global $CFG; | |
291 | ||
292 | $errors = array(); | |
293 | ||
294 | if (empty($this->_form->_submitValues['huburl'])) { | |
295 | $errors['huburl'] = get_string('nohubselected', 'hub'); | |
296 | } | |
297 | ||
298 | return $errors; | |
299 | } | |
300 | ||
07ab0c80 | 301 | } |