require('../../config.php');
require_once($CFG->dirroot . '/blocks/community/locallib.php');
require_once($CFG->dirroot . '/blocks/community/forms.php');
-require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
require_login();
$courseid = required_param('courseid', PARAM_INT); //if no courseid is given
$search = optional_param('search', null, PARAM_TEXT);
//if no capability to search course, display an error message
-$usercansearch = has_capability('moodle/community:add', $context);
+require_capability('moodle/community:add', $context);
$usercandownload = has_capability('moodle/community:download', $context);
-if (empty($usercansearch)) {
- $notificationerror = get_string('cannotsearchcommunity', 'hub');
-} else if (!extension_loaded('xmlrpc')) {
- $notificationerror = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', '');
- $notificationerror .= get_string('xmlrpcdisabledcommunity', 'hub');
-}
-if (!empty($notificationerror)) {
- echo $OUTPUT->header();
- echo $OUTPUT->heading(get_string('searchcommunitycourse', 'block_community'), 3, 'main');
- echo $OUTPUT->notification($notificationerror);
- echo $OUTPUT->footer();
- die();
-}
$communitymanager = new block_community_manager();
$renderer = $PAGE->get_renderer('block_community');
}
/// Download
-$huburl = optional_param('huburl', false, PARAM_URL);
$download = optional_param('download', -1, PARAM_INT);
$downloadcourseid = optional_param('downloadcourseid', '', PARAM_INT);
$coursefullname = optional_param('coursefullname', '', PARAM_ALPHANUMEXT);
$backupsize = optional_param('backupsize', 0, PARAM_INT);
if ($usercandownload and $download != -1 and !empty($downloadcourseid) and confirm_sesskey()) {
- $course = new stdClass();
- $course->fullname = $coursefullname;
- $course->id = $downloadcourseid;
- $course->huburl = $huburl;
-
//OUTPUT: display restore choice page
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('downloadingcourse', 'block_community'), 3, 'main');
ob_flush();
}
flush();
- $filenames = $communitymanager->block_community_download_course_backup($course);
+ list($privatefilename, $tmpfilename) = \core\hub\publication::download_course_backup($downloadcourseid, $coursefullname);
echo html_writer::tag('div', get_string('downloaded', 'block_community'),
array('class' => 'textinfo'));
echo $OUTPUT->notification(get_string('downloadconfirmed', 'block_community',
- '/downloaded_backup/' . $filenames['privatefile']), 'notifysuccess');
- echo $renderer->restore_confirmation_box($filenames['tmpfile'], $context);
+ $privatefilename), 'notifysuccess');
+ echo $renderer->restore_confirmation_box($tmpfilename, $context);
echo $OUTPUT->footer();
die();
}
$fromformdata['educationallevel'] = optional_param('educationallevel', 'all', PARAM_ALPHANUMEXT);
$fromformdata['downloadable'] = optional_param('downloadable', $usercandownload, PARAM_ALPHANUM);
$fromformdata['orderby'] = optional_param('orderby', 'newest', PARAM_ALPHA);
-$fromformdata['huburl'] = optional_param('huburl', HUB_MOODLEORGHUBURL, PARAM_URL);
$fromformdata['search'] = $search;
$fromformdata['courseid'] = $courseid;
$hubselectorform = new community_hub_search_form('', $fromformdata);
//the range of course requested
$options->givememore = optional_param('givememore', 0, PARAM_INT);
- //check if the selected hub is from the registered list (in this case we use the private token)
- $token = 'publichub';
- $registrationmanager = new registration_manager();
- $registeredhubs = $registrationmanager->get_registered_on_hubs();
- foreach ($registeredhubs as $registeredhub) {
- if ($huburl == $registeredhub->huburl) {
- $token = $registeredhub->token;
- }
- }
-
- $function = 'hub_get_courses';
- $params = array('search' => $search, 'downloadable' => $downloadable,
- 'enrollable' => intval(!$downloadable), 'options' => $options);
- $serverurl = $huburl . "/local/hub/webservice/webservices.php";
- require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
- $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $token);
- try {
- $result = $xmlrpcclient->call($function, array_values($params));
- $courses = $result['courses'];
- $coursetotal = $result['coursetotal'];
- } catch (Exception $e) {
- $errormessage = $OUTPUT->notification(
- get_string('errorcourselisting', 'block_community', $e->getMessage()));
- }
+ list($courses, $coursetotal) = \core\hub\publication::search($search, $downloadable, $options);
}
// OUTPUT
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('searchcommunitycourse', 'block_community'), 3, 'main');
+echo $renderer->moodlenet_info();
+
$hubselectorform->display();
if (!empty($errormessage)) {
echo $errormessage;
array(array('commentids' => $commentedcourseids, 'closeButtonTitle' => get_string('close', 'editor'))));
$PAGE->requires->yui_module('moodle-block_community-imagegallery', 'M.blocks_community.init_imagegallery',
array(array('imageids' => $courseids, 'imagenumbers' => $courseimagenumbers,
- 'huburl' => $huburl, 'closeButtonTitle' => get_string('close', 'editor'))));
+ 'huburl' => HUB_MOODLEORGHUBURL, 'closeButtonTitle' => get_string('close', 'editor'))));
-echo highlight($search, $renderer->course_list($courses, $huburl, $courseid));
+echo highlight($search, $renderer->course_list($courses, null, $courseid));
//display givememore/Next link if more course can be displayed
if (!empty($courses)) {
*/
require_once($CFG->libdir . '/formslib.php');
-require_once($CFG->dirroot . '/course/publish/lib.php');
-require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
class community_hub_search_form extends moodleform {
public function definition() {
- global $CFG, $USER, $OUTPUT;
- $strrequired = get_string('required');
+ global $CFG;
$mform = & $this->_form;
//set default value
} else {
$orderby = 'newest';
}
- if (isset($this->_customdata['huburl'])) {
- $huburl = $this->_customdata['huburl'];
- } else {
- $huburl = HUB_MOODLEORGHUBURL;
- }
$mform->addElement('header', 'site', get_string('search', 'block_community'));
$mform->addElement('hidden', 'executesearch', 1);
$mform->setType('executesearch', PARAM_INT);
- //retrieve the hub list on the hub directory by web service
- $function = 'hubdirectory_get_hubs';
- $params = array();
- $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php";
- require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
- $xmlrpcclient = new webservice_xmlrpc_client($serverurl, 'publichubdirectory');
- try {
- $hubs = $xmlrpcclient->call($function, $params);
- } catch (Exception $e) {
- $hubs = array();
- $error = $OUTPUT->notification(get_string('errorhublisting', 'block_community', $e->getMessage()));
- $mform->addElement('static', 'errorhub', '', $error);
- }
-
- // Hubdirectory returns old URL for the moodle.net hub, substitute it.
- foreach ($hubs as $key => $hub) {
- if ($hub['url'] === HUB_OLDMOODLEORGHUBURL) {
- $hubs[$key]['url'] = HUB_MOODLEORGHUBURL;
- }
- }
-
- //display list of registered on hub
- $registrationmanager = new registration_manager();
- $registeredhubs = $registrationmanager->get_registered_on_hubs();
- //retrieve some additional hubs that we will add to
- //the hub list got from the hub directory
- $additionalhubs = array();
- foreach ($registeredhubs as $registeredhub) {
- $inthepubliclist = false;
- foreach ($hubs as $hub) {
- if ($hub['url'] == $registeredhub->huburl) {
- $inthepubliclist = true;
- $hub['registeredon'] = true;
- }
- }
- if (!$inthepubliclist) {
- $additionalhub = array();
- $additionalhub['name'] = $registeredhub->hubname;
- $additionalhub['url'] = $registeredhub->huburl;
- $additionalhubs[] = $additionalhub;
- }
- }
- if (!empty($additionalhubs)) {
- $hubs = array_merge($hubs, $additionalhubs);
- }
-
- if (!empty($hubs)) {
- $htmlhubs = array();
- foreach ($hubs as $hub) {
- // Name can come from hub directory - need some cleaning.
- $hubname = clean_text($hub['name'], PARAM_TEXT);
- $smalllogohtml = '';
- if (array_key_exists('id', $hub)) {
-
- // Retrieve hub logo + generate small logo.
- $params = array('hubid' => $hub['id'], 'filetype' => HUB_HUBSCREENSHOT_FILE_TYPE);
- $imgurl = new moodle_url(HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/download.php", $params);
- $imgsize = getimagesize($imgurl->out(false));
- if ($imgsize[0] > 1) {
- $ascreenshothtml = html_writer::empty_tag('img', array('src' => $imgurl, 'alt' => $hubname));
- $smalllogohtml = html_writer::empty_tag('img', array('src' => $imgurl, 'alt' => $hubname
- , 'height' => 30, 'width' => 40));
- } else {
- $ascreenshothtml = '';
- }
- $hubimage = html_writer::tag('div', $ascreenshothtml, array('class' => 'hubimage'));
-
- // Statistics + trusted info.
- $hubstats = '';
- if (isset($hub['enrollablecourses'])) { //check needed to avoid warnings for Moodle version < 2011081700
- $additionaldesc = get_string('enrollablecourses', 'block_community') . ': ' . $hub['enrollablecourses'] . ' - ' .
- get_string('downloadablecourses', 'block_community') . ': ' . $hub['downloadablecourses'];
- $hubstats .= html_writer::tag('div', $additionaldesc);
- }
- if ($hub['trusted']) {
- $hubtrusted = get_string('hubtrusted', 'block_community');
- $hubstats .= $OUTPUT->doc_link('trusted_hubs') . html_writer::tag('div', $hubtrusted);
- }
- $hubstats = html_writer::tag('div', $hubstats, array('class' => 'hubstats'));
-
- // hub name link + hub description.
- $hubnamelink = html_writer::link($hub['url'], html_writer::tag('h2',$hubname),
- array('class' => 'hubtitlelink'));
- // The description can come from the hub directory - need to clean.
- $hubdescription = clean_param($hub['description'], PARAM_TEXT);
- $hubdescriptiontext = html_writer::tag('div', format_text($hubdescription, FORMAT_PLAIN),
- array('class' => 'hubdescription'));
-
- $hubtext = html_writer::tag('div', $hubdescriptiontext . $hubstats, array('class' => 'hubtext'));
-
- $hubimgandtext = html_writer::tag('div', $hubimage . $hubtext, array('class' => 'hubimgandtext'));
-
- $hubfulldesc = html_writer::tag('div', $hubnamelink . $hubimgandtext, array('class' => 'hubmainhmtl'));
- } else {
- $hubfulldesc = html_writer::link($hub['url'], $hubname);
- }
-
- // Add hub to the hub items.
- $hubinfo = new stdClass();
- $hubinfo->mainhtml = $hubfulldesc;
- $hubinfo->rowhtml = html_writer::tag('div', $smalllogohtml , array('class' => 'hubsmalllogo')) . $hubname;
- $hubitems[$hub['url']] = $hubinfo;
- }
-
- // Hub listing form element.
- $mform->addElement('listing','huburl', '', '', array('items' => $hubitems,
- 'showall' => get_string('showall', 'block_community'),
- 'hideall' => get_string('hideall', 'block_community')));
- $mform->setDefault('huburl', $huburl);
+ // Display enrol/download select box if the USER has the download capability on the course.
+ if (has_capability('moodle/community:download',
+ context_course::instance($this->_customdata['courseid']))) {
+ $options = array(0 => get_string('enrollable', 'block_community'),
+ 1 => get_string('downloadable', 'block_community'));
+ $mform->addElement('select', 'downloadable', get_string('enroldownload', 'block_community'),
+ $options);
+ $mform->addHelpButton('downloadable', 'enroldownload', 'block_community');
- //display enrol/download select box if the USER has the download capability on the course
- if (has_capability('moodle/community:download',
- context_course::instance($this->_customdata['courseid']))) {
- $options = array(0 => get_string('enrollable', 'block_community'),
- 1 => get_string('downloadable', 'block_community'));
- $mform->addElement('select', 'downloadable', get_string('enroldownload', 'block_community'),
- $options);
- $mform->addHelpButton('downloadable', 'enroldownload', 'block_community');
-
- $mform->setDefault('downloadable', $downloadable);
- } else {
- $mform->addElement('hidden', 'downloadable', 0);
- }
- $mform->setType('downloadable', PARAM_INT);
-
- $options = array();
- $options['all'] = get_string('any');
- $options[HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub');
- $options[HUB_AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub');
- $options[HUB_AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub');
- $mform->addElement('select', 'audience', get_string('audience', 'block_community'), $options);
- $mform->setDefault('audience', $audience);
- unset($options);
- $mform->addHelpButton('audience', 'audience', 'block_community');
-
- $options = array();
- $options['all'] = get_string('any');
- $options[HUB_EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'hub');
- $options[HUB_EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'hub');
- $options[HUB_EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'hub');
- $options[HUB_EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'hub');
- $options[HUB_EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'hub');
- $options[HUB_EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub');
- $options[HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'hub');
- $mform->addElement('select', 'educationallevel',
- get_string('educationallevel', 'block_community'), $options);
- $mform->setDefault('educationallevel', $educationallevel);
- unset($options);
- $mform->addHelpButton('educationallevel', 'educationallevel', 'block_community');
-
- $publicationmanager = new course_publish_manager();
- $options = $publicationmanager->get_sorted_subjects();
- $mform->addElement('searchableselector', 'subject', get_string('subject', 'block_community'),
- $options, array('id' => 'communitysubject'));
- $mform->setDefault('subject', $subject);
- unset($options);
- $mform->addHelpButton('subject', 'subject', 'block_community');
-
- require_once($CFG->libdir . "/licenselib.php");
- $licensemanager = new license_manager();
- $licences = $licensemanager->get_licenses();
- $options = array();
- $options['all'] = get_string('any');
- foreach ($licences as $license) {
- $options[$license->shortname] = get_string($license->shortname, 'license');
- }
- $mform->addElement('select', 'licence', get_string('licence', 'block_community'), $options);
- unset($options);
- $mform->addHelpButton('licence', 'licence', 'block_community');
- $mform->setDefault('licence', $licence);
-
- $languages = get_string_manager()->get_list_of_languages();
- core_collator::asort($languages);
- $languages = array_merge(array('all' => get_string('any')), $languages);
- $mform->addElement('select', 'language', get_string('language'), $languages);
-
- $mform->setDefault('language', $language);
- $mform->addHelpButton('language', 'language', 'block_community');
-
- $mform->addElement('select', 'orderby', get_string('orderby', 'block_community'),
- array('newest' => get_string('orderbynewest', 'block_community'),
- 'eldest' => get_string('orderbyeldest', 'block_community'),
- 'fullname' => get_string('orderbyname', 'block_community'),
- 'publisher' => get_string('orderbypublisher', 'block_community'),
- 'ratingaverage' => get_string('orderbyratingaverage', 'block_community')));
-
- $mform->setDefault('orderby', $orderby);
- $mform->addHelpButton('orderby', 'orderby', 'block_community');
- $mform->setType('orderby', PARAM_ALPHA);
-
- $mform->setAdvanced('audience');
- $mform->setAdvanced('educationallevel');
- $mform->setAdvanced('subject');
- $mform->setAdvanced('licence');
- $mform->setAdvanced('language');
- $mform->setAdvanced('orderby');
-
- $mform->addElement('text', 'search', get_string('keywords', 'block_community'),
- array('size' => 30));
- $mform->addHelpButton('search', 'keywords', 'block_community');
- $mform->setType('search', PARAM_NOTAGS);
-
- $mform->addElement('submit', 'submitbutton', get_string('search', 'block_community'));
+ $mform->setDefault('downloadable', $downloadable);
+ } else {
+ $mform->addElement('hidden', 'downloadable', 0);
}
- }
-
- function validation($data, $files) {
- global $CFG;
-
- $errors = array();
-
- if (empty($this->_form->_submitValues['huburl'])) {
- $errors['huburl'] = get_string('nohubselected', 'hub');
+ $mform->setType('downloadable', PARAM_INT);
+
+ $options = \core\hub\publication::audience_options(true);
+ $mform->addElement('select', 'audience', get_string('audience', 'block_community'), $options);
+ $mform->setDefault('audience', $audience);
+ unset($options);
+ $mform->addHelpButton('audience', 'audience', 'block_community');
+
+ $options = \core\hub\publication::educational_level_options(true);
+ $mform->addElement('select', 'educationallevel',
+ get_string('educationallevel', 'block_community'), $options);
+ $mform->setDefault('educationallevel', $educationallevel);
+ unset($options);
+ $mform->addHelpButton('educationallevel', 'educationallevel', 'block_community');
+
+ $options = \core\hub\publication::get_sorted_subjects();
+ $mform->addElement('searchableselector', 'subject', get_string('subject', 'block_community'),
+ $options, array('id' => 'communitysubject'));
+ $mform->setDefault('subject', $subject);
+ unset($options);
+ $mform->addHelpButton('subject', 'subject', 'block_community');
+
+ require_once($CFG->libdir . "/licenselib.php");
+ $licensemanager = new license_manager();
+ $licences = $licensemanager->get_licenses();
+ $options = array();
+ $options['all'] = get_string('any');
+ foreach ($licences as $license) {
+ $options[$license->shortname] = get_string($license->shortname, 'license');
}
+ $mform->addElement('select', 'licence', get_string('licence', 'block_community'), $options);
+ unset($options);
+ $mform->addHelpButton('licence', 'licence', 'block_community');
+ $mform->setDefault('licence', $licence);
+
+ $languages = get_string_manager()->get_list_of_languages();
+ core_collator::asort($languages);
+ $languages = array_merge(array('all' => get_string('any')), $languages);
+ $mform->addElement('select', 'language', get_string('language'), $languages);
+
+ $mform->setDefault('language', $language);
+ $mform->addHelpButton('language', 'language', 'block_community');
+
+ $mform->addElement('select', 'orderby', get_string('orderby', 'block_community'),
+ array('newest' => get_string('orderbynewest', 'block_community'),
+ 'eldest' => get_string('orderbyeldest', 'block_community'),
+ 'fullname' => get_string('orderbyname', 'block_community'),
+ 'publisher' => get_string('orderbypublisher', 'block_community'),
+ 'ratingaverage' => get_string('orderbyratingaverage', 'block_community')));
+
+ $mform->setDefault('orderby', $orderby);
+ $mform->addHelpButton('orderby', 'orderby', 'block_community');
+ $mform->setType('orderby', PARAM_ALPHA);
+
+ $mform->setAdvanced('audience');
+ $mform->setAdvanced('educationallevel');
+ $mform->setAdvanced('subject');
+ $mform->setAdvanced('licence');
+ $mform->setAdvanced('language');
+ $mform->setAdvanced('orderby');
+
+ $mform->addElement('text', 'search', get_string('keywords', 'block_community'),
+ array('size' => 30));
+ $mform->addHelpButton('search', 'keywords', 'block_community');
+ $mform->setType('search', PARAM_NOTAGS);
+
+ $mform->addElement('submit', 'submitbutton', get_string('search', 'block_community'));
- return $errors;
}
}
return html_writer::tag('div', $nextlink, array( 'class' => 'nextlink'));
}
+ /**
+ * Displays information about moodle.net above course search form
+ *
+ * @return string
+ */
+ public function moodlenet_info() {
+ if (!$info = \core\hub\registration::get_moodlenet_info()) {
+ return '';
+ }
+
+ $image = html_writer::div(html_writer::img($info['imgurl'], $info['name']), 'hubimage');
+
+ $namelink = html_writer::link($info['url'], html_writer::tag('h2', $info['name']), array('class' => 'hubtitlelink'));
+ $description = clean_param($info['description'], PARAM_TEXT);
+ $descriptiontext = html_writer::div(format_text($description, FORMAT_PLAIN), 'hubdescription');
+
+ $additionaldesc = get_string('enrollablecourses', 'block_community') . ': ' . $info['enrollablecourses'] . ' - ' .
+ get_string('downloadablecourses', 'block_community') . ': ' . $info['downloadablecourses'];
+ $stats = html_writer::div(html_writer::tag('div', $additionaldesc), 'hubstats');
+
+ $text = html_writer::div($descriptiontext . $stats, 'hubtext');
+
+ $imgandtext = html_writer::div($image . $text, 'hubimgandtext');
+
+ $fulldesc = html_writer::div($namelink . $imgandtext, 'hubmainhmtl clearfix');
+
+ return html_writer::div($fulldesc, 'formlisting');
+ }
+
/**
* Display a list of courses
* @param array $courses
- * @param boolean $withwriteaccess
+ * @param mixed $unused parameter is not used
* @param int $contextcourseid context course id
* @return string
*/
- public function course_list($courses, $huburl, $contextcourseid) {
+ public function course_list($courses, $unused, $contextcourseid) {
global $CFG;
$renderedhtml = '';
// create screenshots html
$screenshothtml = '';
- if (!empty($course->screenshots)) {
- $baseurl = new moodle_url($huburl . '/local/hub/webservice/download.php',
- array('courseid' => $course->id,
- 'filetype' => HUB_SCREENSHOT_FILE_TYPE));
+ if (!empty($course->screenshotbaseurl)) {
$screenshothtml = html_writer::empty_tag('img',
- array('src' => $baseurl, 'alt' => $course->fullname));
+ array('src' => $course->screenshotbaseurl, 'alt' => $course->fullname));
}
$coursescreenshot = html_writer::tag('div', $screenshothtml,
array('class' => 'coursescreenshot',
if (!$course->enrollable) {
$params = array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
'remotemoodleurl' => $CFG->wwwroot, 'courseid' => $contextcourseid,
- 'downloadcourseid' => $course->id, 'huburl' => $huburl,
+ 'downloadcourseid' => $course->id,
'coursefullname' => $course->fullname, 'backupsize' => $course->backupsize);
$downloadurl = new moodle_url("/blocks/community/communitycourse.php", $params);
$downloadbuttonhtml = html_writer::tag('a', get_string('install', 'block_community'),
//link rate and comment
$rateandcomment = html_writer::tag('div',
- html_writer::tag('a', get_string('rateandcomment', 'block_community'),
- array('href' => new moodle_url($huburl,
- array('courseid' => $course->id, 'mustbelogged' => true)),
- 'onclick' => 'this.target="_blank"')),
+ html_writer::link($course->commenturl, get_string('rateandcomment', 'block_community'),
+ ['onclick' => 'this.target="_blank"']),
array('class' => 'hubrateandcomment'));
//the main DIV tags