Merge branch 'wip-MDL-59495-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Andrew Nicols
2017-09-27 15:11:20 +08:00
36 changed files with 2469 additions and 2832 deletions
+1 -1
View File
@@ -857,7 +857,7 @@ if ($updateschecker->enabled()) {
$buggyiconvnomb = (!function_exists('mb_convert_encoding') and @iconv('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€');
//check if the site is registered on Moodle.org
$registered = $DB->count_records('registration_hubs', array('huburl' => HUB_MOODLEORGHUBURL, 'confirmed' => 1));
$registered = \core\hub\registration::is_registered();
// Check if there are any cache warnings.
$cachewarnings = cache_helper::warnings();
// Check if there are events 1 API handlers.
+17 -32
View File
@@ -20,7 +20,7 @@
// //
///////////////////////////////////////////////////////////////////////////
/*
/**
* @package moodle
* @subpackage registration
* @author Jerome Mouneyrac <[email protected]>
@@ -36,7 +36,6 @@
require('../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
$newtoken = optional_param('newtoken', '', PARAM_ALPHANUM);
$url = optional_param('url', '', PARAM_URL);
@@ -44,7 +43,11 @@ $hubname = optional_param('hubname', '', PARAM_TEXT);
$token = optional_param('token', '', PARAM_TEXT);
$error = optional_param('error', '', PARAM_ALPHANUM);
admin_externalpage_setup('registrationhubs');
admin_externalpage_setup('registrationmoodleorg');
if ($url !== HUB_MOODLEORGHUBURL) {
throw new moodle_exception('errorotherhubsnotsupported', 'hub');
}
if (!empty($error) and $error == 'urlalreadyexist') {
throw new moodle_exception('urlalreadyregistered', 'hub',
@@ -52,38 +55,20 @@ if (!empty($error) and $error == 'urlalreadyexist') {
}
//check that we are waiting a confirmation from this hub, and check that the token is correct
$registrationmanager = new registration_manager();
$registeredhub = $registrationmanager->get_unconfirmedhub($url);
if (!empty($registeredhub) and $registeredhub->token == $token) {
core\hub\registration::confirm_registration($token, $newtoken, $hubname);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('registrationconfirmed', 'hub'), 3, 'main');
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('registrationconfirmed', 'hub'), 3, 'main');
$registeredhub->token = $newtoken;
$registeredhub->confirmed = 1;
$registeredhub->hubname = $hubname;
$registrationmanager->update_registeredhub($registeredhub);
// Display notification message.
echo $OUTPUT->notification(get_string('registrationconfirmedon', 'hub'), 'notifysuccess');
// Display notification message.
echo $OUTPUT->notification(get_string('registrationconfirmedon', 'hub'), 'notifysuccess');
// Display continue button.
$registrationpage = new moodle_url('/admin/registration/index.php');
$continuebutton = $OUTPUT->render(new single_button($registrationpage, get_string('continue')));
$continuebutton = html_writer::tag('div', $continuebutton, array('class' => 'mdl-align'));
echo $continuebutton;
//display continue button
$registrationpage = new moodle_url('/admin/registration/index.php');
$continuebutton = $OUTPUT->render(new single_button($registrationpage, get_string('continue', 'hub')));
$continuebutton = html_writer::tag('div', $continuebutton, array('class' => 'mdl-align'));
echo $continuebutton;
if (!extension_loaded('xmlrpc')) {
//display notice about xmlrpc
$xmlrpcnotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', '');
$xmlrpcnotification .= get_string('xmlrpcdisabledregistration', 'hub');
echo $OUTPUT->notification($xmlrpcnotification);
}
echo $OUTPUT->footer();
} else {
throw new moodle_exception('wrongtoken', 'hub',
$CFG->wwwroot . '/' . $CFG->admin . '/registration/index.php');
}
echo $OUTPUT->footer();
+4 -551
View File
@@ -20,7 +20,7 @@
// //
///////////////////////////////////////////////////////////////////////////
/*
/**
* @package moodle
* @subpackage registration
* @author Jerome Mouneyrac <[email protected]>
@@ -30,554 +30,7 @@
* The forms needed by registration pages.
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
/**
* This form display a unregistration form.
*/
class site_unregistration_form extends moodleform {
public function definition() {
$mform = & $this->_form;
$mform->addElement('header', 'site', get_string('unregister', 'hub'));
$huburl = $this->_customdata['huburl'];
$hubname = $this->_customdata['hubname'];
$unregisterlabel = get_string('unregister', 'hub');
$mform->addElement('checkbox', 'unpublishalladvertisedcourses', '',
' ' . get_string('unpublishalladvertisedcourses', 'hub'));
$mform->setType('unpublishalladvertisedcourses', PARAM_INT);
$mform->addElement('checkbox', 'unpublishalluploadedcourses', '',
' ' . get_string('unpublishalluploadedcourses', 'hub'));
$mform->setType('unpublishalluploadedcourses', PARAM_INT);
$mform->addElement('hidden', 'confirm', 1);
$mform->setType('confirm', PARAM_INT);
$mform->addElement('hidden', 'unregistration', 1);
$mform->setType('unregistration', PARAM_INT);
$mform->addElement('hidden', 'huburl', $huburl);
$mform->setType('huburl', PARAM_URL);
$mform->addElement('hidden', 'hubname', $hubname);
$mform->setType('hubname', PARAM_TEXT);
$this->add_action_buttons(true, $unregisterlabel);
}
}
/**
* This form display a clean registration data form.
*/
class site_clean_registration_data_form extends moodleform {
public function definition() {
$mform = & $this->_form;
$mform->addElement('header', 'site', get_string('unregister', 'hub'));
$huburl = $this->_customdata['huburl'];
$hubname = $this->_customdata['hubname'];
$unregisterlabel = get_string('forceunregister', 'hub');
$mform->addElement('static', '', get_string('warning', 'hub'), get_string('forceunregisterconfirmation', 'hub', $hubname));
$mform->addElement('hidden', 'confirm', 1);
$mform->setType('confirm', PARAM_INT);
$mform->addElement('hidden', 'unregistration', 1);
$mform->setType('unregistration', PARAM_INT);
$mform->addElement('hidden', 'cleanregdata', 1);
$mform->setType('cleanregdata', PARAM_INT);
$mform->addElement('hidden', 'huburl', $huburl);
$mform->setType('huburl', PARAM_URL);
$mform->addElement('hidden', 'hubname', $hubname);
$mform->setType('hubname', PARAM_TEXT);
$this->add_action_buttons(true, $unregisterlabel);
}
}
/**
* This form display a hub selector.
* The hub list is retrieved from Moodle.org hub directory.
* Also displayed, a text field to enter private hub url + its password
*/
class hub_selector_form extends moodleform {
public function definition() {
global $CFG, $OUTPUT;
$mform = & $this->_form;
$mform->addElement('header', 'site', get_string('selecthub', 'hub'));
//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) {
$error = $OUTPUT->notification(get_string('errorhublisting', 'hub', $e->getMessage()));
$mform->addElement('static', 'errorhub', '', $error);
$hubs = array();
}
//remove moodle.org from the hub list
foreach ($hubs as $key => $hub) {
if ($hub['url'] == HUB_MOODLEORGHUBURL || $hub['url'] == HUB_OLDMOODLEORGHUBURL) {
unset($hubs[$key]);
}
}
//Public hub list
$options = array();
foreach ($hubs as $hub) {
//to not display a name longer than 100 character (too big)
if (core_text::strlen($hub['name']) > 100) {
$hubname = core_text::substr($hub['name'], 0, 100);
$hubname = $hubname . "...";
} else {
$hubname = $hub['name'];
}
$options[$hub['url']] = $hubname;
$mform->addElement('hidden', clean_param($hub['url'], PARAM_ALPHANUMEXT), $hubname);
$mform->setType(clean_param($hub['url'], PARAM_ALPHANUMEXT), PARAM_ALPHANUMEXT);
}
if (!empty($hubs)) {
$mform->addElement('select', 'publichub', get_string('publichub', 'hub'),
$options, array("size" => 15));
$mform->setType('publichub', PARAM_URL);
}
$mform->addElement('static', 'or', '', get_string('orenterprivatehub', 'hub'));
//Private hub
$mform->addElement('text', 'unlistedurl', get_string('privatehuburl', 'hub'),
array('class' => 'registration_textfield'));
$mform->setType('unlistedurl', PARAM_URL);
$mform->addElement('text', 'password', get_string('password'),
array('class' => 'registration_textfield'));
$mform->setType('password', PARAM_RAW);
$this->add_action_buttons(false, get_string('selecthub', 'hub'));
}
/**
* Check the unlisted URL is a URL
*/
function validation($data, $files) {
global $CFG;
$errors = parent::validation($data, $files);
$unlistedurl = $this->_form->_submitValues['unlistedurl'];
if (empty($unlistedurl)) {
$errors['unlistedurl'] = get_string('badurlformat', 'hub');
}
return $errors;
}
}
/**
* The site registration form. Information will be sent to a given hub.
*/
class site_registration_form extends moodleform {
public function definition() {
global $CFG, $DB;
$strrequired = get_string('required');
$mform = & $this->_form;
$huburl = $this->_customdata['huburl'];
$hubname = $this->_customdata['hubname'];
$password = $this->_customdata['password'];
$admin = get_admin();
$site = get_site();
//retrieve config for this hub and set default if they don't exist
$cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
$sitename = get_config('hub', 'site_name_' . $cleanhuburl);
if ($sitename === false) {
$sitename = format_string($site->fullname, true, array('context' => context_course::instance(SITEID)));
}
$sitedescription = get_config('hub', 'site_description_' . $cleanhuburl);
if ($sitedescription === false) {
$sitedescription = $site->summary;
}
$contactname = get_config('hub', 'site_contactname_' . $cleanhuburl);
if ($contactname === false) {
$contactname = fullname($admin, true);
}
$contactemail = get_config('hub', 'site_contactemail_' . $cleanhuburl);
if ($contactemail === false) {
$contactemail = $admin->email;
}
$contactphone = get_config('hub', 'site_contactphone_' . $cleanhuburl);
if ($contactphone === false) {
$contactphone = $admin->phone1;
}
$imageurl = get_config('hub', 'site_imageurl_' . $cleanhuburl);
$privacy = get_config('hub', 'site_privacy_' . $cleanhuburl);
$address = get_config('hub', 'site_address_' . $cleanhuburl);
if ($address === false) {
$address = '';
}
$region = get_config('hub', 'site_region_' . $cleanhuburl);
$country = get_config('hub', 'site_country_' . $cleanhuburl);
if (empty($country)) {
$country = $admin->country ?: $CFG->country;
}
$language = get_config('hub', 'site_language_' . $cleanhuburl);
if ($language === false) {
$language = explode('_', current_language())[0];
}
$geolocation = get_config('hub', 'site_geolocation_' . $cleanhuburl);
if ($geolocation === false) {
$geolocation = '';
}
$contactable = get_config('hub', 'site_contactable_' . $cleanhuburl);
$emailalert = get_config('hub', 'site_emailalert_' . $cleanhuburl);
$emailalert = ($emailalert === false || $emailalert) ? 1 : 0;
$coursesnumber = get_config('hub', 'site_coursesnumber_' . $cleanhuburl);
$usersnumber = get_config('hub', 'site_usersnumber_' . $cleanhuburl);
$roleassignmentsnumber = get_config('hub', 'site_roleassignmentsnumber_' . $cleanhuburl);
$postsnumber = get_config('hub', 'site_postsnumber_' . $cleanhuburl);
$questionsnumber = get_config('hub', 'site_questionsnumber_' . $cleanhuburl);
$resourcesnumber = get_config('hub', 'site_resourcesnumber_' . $cleanhuburl);
$badgesnumber = get_config('hub', 'site_badges_' . $cleanhuburl);
$issuedbadgesnumber = get_config('hub', 'site_issuedbadges_' . $cleanhuburl);
$mediancoursesize = get_config('hub', 'site_mediancoursesize_' . $cleanhuburl);
$participantnumberaveragecfg = get_config('hub', 'site_participantnumberaverage_' . $cleanhuburl);
$modulenumberaveragecfg = get_config('hub', 'site_modulenumberaverage_' . $cleanhuburl);
// Mobile related information.
$mobileservicesenabled = get_config('hub', 'site_mobileservicesenabled_' . $cleanhuburl);
$mobilenotificationsenabled = get_config('hub', 'site_mobilenotificationsenabled_' . $cleanhuburl);
$registereduserdevices = get_config('hub', 'site_registereduserdevices_' . $cleanhuburl);
$registeredactiveuserdevices = get_config('hub', 'site_registeredactiveuserdevices_' . $cleanhuburl);
//hidden parameters
$mform->addElement('hidden', 'huburl', $huburl);
$mform->setType('huburl', PARAM_URL);
$mform->addElement('hidden', 'hubname', $hubname);
$mform->setType('hubname', PARAM_TEXT);
$mform->addElement('hidden', 'password', $password);
$mform->setType('password', PARAM_RAW);
//the input parameters
$mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub'));
$mform->addElement('text', 'name', get_string('sitename', 'hub'),
array('class' => 'registration_textfield'));
$mform->addRule('name', $strrequired, 'required', null, 'client');
$mform->setType('name', PARAM_TEXT);
$mform->setDefault('name', $sitename);
$mform->addHelpButton('name', 'sitename', 'hub');
$options = array();
$registrationmanager = new registration_manager();
$options[HUB_SITENOTPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITENOTPUBLISHED);
$options[HUB_SITENAMEPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITENAMEPUBLISHED);
$options[HUB_SITELINKPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITELINKPUBLISHED);
$mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), $options);
$mform->setDefault('privacy', $privacy);
$mform->setType('privacy', PARAM_ALPHA);
$mform->addHelpButton('privacy', 'privacy', 'hub');
unset($options);
$mform->addElement('textarea', 'description', get_string('sitedesc', 'hub'),
array('rows' => 8, 'cols' => 41));
$mform->addRule('description', $strrequired, 'required', null, 'client');
$mform->setDefault('description', $sitedescription);
$mform->setType('description', PARAM_TEXT);
$mform->addHelpButton('description', 'sitedesc', 'hub');
$languages = get_string_manager()->get_list_of_languages();
core_collator::asort($languages);
$mform->addElement('select', 'language', get_string('sitelang', 'hub'),
$languages);
$mform->setType('language', PARAM_ALPHANUMEXT);
$mform->addHelpButton('language', 'sitelang', 'hub');
$mform->setDefault('language', $language);
$mform->addElement('textarea', 'address', get_string('postaladdress', 'hub'),
array('rows' => 4, 'cols' => 41));
$mform->setType('address', PARAM_TEXT);
$mform->setDefault('address', $address);
$mform->addHelpButton('address', 'postaladdress', 'hub');
//TODO: use the region array I generated
// $mform->addElement('select', 'region', get_string('selectaregion'), array('-' => '-'));
// $mform->setDefault('region', $region);
$mform->addElement('hidden', 'regioncode', '-');
$mform->setType('regioncode', PARAM_ALPHANUMEXT);
$countries = ['' => ''] + get_string_manager()->get_list_of_countries();
$mform->addElement('select', 'countrycode', get_string('sitecountry', 'hub'), $countries);
$mform->setDefault('countrycode', $country);
$mform->setType('countrycode', PARAM_ALPHANUMEXT);
$mform->addHelpButton('countrycode', 'sitecountry', 'hub');
$mform->addRule('countrycode', $strrequired, 'required', null, 'client');
$mform->addElement('text', 'geolocation', get_string('sitegeolocation', 'hub'),
array('class' => 'registration_textfield'));
$mform->setDefault('geolocation', $geolocation);
$mform->setType('geolocation', PARAM_RAW);
$mform->addHelpButton('geolocation', 'sitegeolocation', 'hub');
$mform->addElement('text', 'contactname', get_string('siteadmin', 'hub'),
array('class' => 'registration_textfield'));
$mform->addRule('contactname', $strrequired, 'required', null, 'client');
$mform->setType('contactname', PARAM_TEXT);
$mform->setDefault('contactname', $contactname);
$mform->addHelpButton('contactname', 'siteadmin', 'hub');
$mform->addElement('text', 'contactphone', get_string('sitephone', 'hub'),
array('class' => 'registration_textfield'));
$mform->setType('contactphone', PARAM_TEXT);
$mform->setDefault('contactphone', $contactphone);
$mform->addHelpButton('contactphone', 'sitephone', 'hub');
$mform->setForceLtr('contactphone');
$mform->addElement('text', 'contactemail', get_string('siteemail', 'hub'),
array('class' => 'registration_textfield'));
$mform->addRule('contactemail', $strrequired, 'required', null, 'client');
$mform->setType('contactemail', PARAM_EMAIL);
$mform->setDefault('contactemail', $contactemail);
$mform->addHelpButton('contactemail', 'siteemail', 'hub');
$options = array();
$options[0] = get_string("registrationcontactno");
$options[1] = get_string("registrationcontactyes");
$mform->addElement('select', 'contactable', get_string('siteregistrationcontact', 'hub'), $options);
$mform->setDefault('contactable', $contactable);
$mform->setType('contactable', PARAM_INT);
$mform->addHelpButton('contactable', 'siteregistrationcontact', 'hub');
unset($options);
$options = array();
$options[0] = get_string("registrationno");
$options[1] = get_string("registrationyes");
$mform->addElement('select', 'emailalert', get_string('siteregistrationemail', 'hub'), $options);
$mform->setDefault('emailalert', $emailalert);
$mform->setType('emailalert', PARAM_INT);
$mform->addHelpButton('emailalert', 'siteregistrationemail', 'hub');
unset($options);
//TODO site logo
$mform->addElement('hidden', 'imageurl', ''); //TODO: temporary
$mform->setType('imageurl', PARAM_URL);
$mform->addElement('static', 'urlstring', get_string('siteurl', 'hub'), $CFG->wwwroot);
$mform->addHelpButton('urlstring', 'siteurl', 'hub');
$mform->addElement('static', 'versionstring', get_string('siteversion', 'hub'), $CFG->version);
$mform->addElement('hidden', 'moodleversion', $CFG->version);
$mform->setType('moodleversion', PARAM_INT);
$mform->addHelpButton('versionstring', 'siteversion', 'hub');
$mform->addElement('static', 'releasestring', get_string('siterelease', 'hub'), $CFG->release);
$mform->addElement('hidden', 'moodlerelease', $CFG->release);
$mform->setType('moodlerelease', PARAM_TEXT);
$mform->addHelpButton('releasestring', 'siterelease', 'hub');
/// Display statistic that are going to be retrieve by the hub
$coursecount = $DB->count_records('course') - 1;
$usercount = $DB->count_records('user', array('deleted' => 0));
$roleassigncount = $DB->count_records('role_assignments');
$postcount = $DB->count_records('forum_posts');
$questioncount = $DB->count_records('question');
$resourcecount = $DB->count_records('resource');
require_once($CFG->dirroot . "/course/lib.php");
$participantnumberaverage = number_format(average_number_of_participants(), 2);
$modulenumberaverage = number_format(average_number_of_courses_modules(), 2);
require_once($CFG->libdir . '/badgeslib.php');
$badges = $DB->count_records_select('badge', 'status <> ' . BADGE_STATUS_ARCHIVED);
$issuedbadges = $DB->count_records('badge_issued');
// Mobile related information.
$ismobileenabled = false;
$aremobilenotificationsenabled = false;
$registereduserdevicescount = 0;
$registeredactiveuserdevicescount = 0;
if (!empty($CFG->enablewebservices) && !empty($CFG->enablemobilewebservice)) {
$ismobileenabled = true;
$registereduserdevicescount = $DB->count_records('user_devices');
$airnotifierextpath = $CFG->dirroot . '/message/output/airnotifier/externallib.php';
if (file_exists($airnotifierextpath)) { // Maybe some one uninstalled the plugin.
require_once($airnotifierextpath);
$aremobilenotificationsenabled = (bool) message_airnotifier_external::is_system_configured();
$registeredactiveuserdevicescount = $DB->count_records('message_airnotifier_devices', array('enable' => 1));
}
}
if (HUB_MOODLEORGHUBURL != $huburl) {
$mform->addElement('checkbox', 'courses', get_string('sendfollowinginfo', 'hub'),
" " . get_string('coursesnumber', 'hub', $coursecount));
$mform->setDefault('courses', $coursesnumber != -1);
$mform->setType('courses', PARAM_INT);
$mform->addHelpButton('courses', 'sendfollowinginfo', 'hub');
$mform->addElement('checkbox', 'users', '',
" " . get_string('usersnumber', 'hub', $usercount));
$mform->setDefault('users', $usersnumber != -1);
$mform->setType('users', PARAM_INT);
$mform->addElement('checkbox', 'roleassignments', '',
" " . get_string('roleassignmentsnumber', 'hub', $roleassigncount));
$mform->setDefault('roleassignments', $roleassignmentsnumber != -1);
$mform->setType('roleassignments', PARAM_INT);
$mform->addElement('checkbox', 'posts', '',
" " . get_string('postsnumber', 'hub', $postcount));
$mform->setDefault('posts', $postsnumber != -1);
$mform->setType('posts', PARAM_INT);
$mform->addElement('checkbox', 'questions', '',
" " . get_string('questionsnumber', 'hub', $questioncount));
$mform->setDefault('questions', $questionsnumber != -1);
$mform->setType('questions', PARAM_INT);
$mform->addElement('checkbox', 'resources', '',
" " . get_string('resourcesnumber', 'hub', $resourcecount));
$mform->setDefault('resources', $resourcesnumber != -1);
$mform->setType('resources', PARAM_INT);
$mform->addElement('checkbox', 'badges', '',
" " . get_string('badgesnumber', 'hub', $badges));
$mform->setDefault('badges', $badgesnumber != -1);
$mform->setType('badges', PARAM_INT);
$mform->addElement('checkbox', 'issuedbadges', '',
" " . get_string('issuedbadgesnumber', 'hub', $issuedbadges));
$mform->setDefault('issuedbadges', $issuedbadgesnumber != -1);
$mform->setType('issuedbadges', PARAM_INT);
$mform->addElement('checkbox', 'participantnumberaverage', '',
" " . get_string('participantnumberaverage', 'hub', $participantnumberaverage));
$mform->setDefault('participantnumberaverage', $participantnumberaveragecfg != -1);
$mform->setType('participantnumberaverage', PARAM_FLOAT);
$mform->addElement('checkbox', 'modulenumberaverage', '',
" " . get_string('modulenumberaverage', 'hub', $modulenumberaverage));
$mform->setDefault('modulenumberaverage', $modulenumberaveragecfg != -1);
$mform->setType('modulenumberaverage', PARAM_FLOAT);
$mobileservicestatus = $ismobileenabled ? 'yes' : 'no';
$mform->addElement('checkbox', 'mobileservicesenabled', '',
" " . get_string('mobileservicesenabled', 'hub', $mobileservicestatus));
$mform->setDefault('mobileservicesenabled', $mobileservicesenabled != -1);
$mform->setType('mobileservicesenabled', PARAM_INT);
$mobilenotificationsstatus = $aremobilenotificationsenabled ? 'yes' : 'no';
$mform->addElement('checkbox', 'mobilenotificationsenabled', '',
" " . get_string('mobilenotificationsenabled', 'hub', $mobilenotificationsstatus));
$mform->setDefault('mobilenotificationsenabled', $mobilenotificationsenabled != -1);
$mform->setType('mobilenotificationsenabled', PARAM_INT);
$mform->addElement('checkbox', 'registereduserdevices', '',
" " . get_string('registereduserdevices', 'hub', $registereduserdevicescount));
$mform->setDefault('registereduserdevices', $registereduserdevices != -1);
$mform->setType('registereduserdevices', PARAM_INT);
$mform->addElement('checkbox', 'registeredactiveuserdevices', '',
" " . get_string('registeredactiveuserdevices', 'hub', $registeredactiveuserdevicescount));
$mform->setDefault('registeredactiveuserdevices', $registeredactiveuserdevices != -1);
$mform->setType('registeredactiveuserdevices', PARAM_INT);
} else {
$mform->addElement('static', 'courseslabel', get_string('sendfollowinginfo', 'hub'),
" " . get_string('coursesnumber', 'hub', $coursecount));
$mform->addElement('hidden', 'courses', 1);
$mform->setType('courses', PARAM_INT);
$mform->addHelpButton('courseslabel', 'sendfollowinginfo', 'hub');
$mform->addElement('static', 'userslabel', '',
" " . get_string('usersnumber', 'hub', $usercount));
$mform->addElement('hidden', 'users', 1);
$mform->setType('users', PARAM_INT);
$mform->addElement('static', 'roleassignmentslabel', '',
" " . get_string('roleassignmentsnumber', 'hub', $roleassigncount));
$mform->addElement('hidden', 'roleassignments', 1);
$mform->setType('roleassignments', PARAM_INT);
$mform->addElement('static', 'postslabel', '',
" " . get_string('postsnumber', 'hub', $postcount));
$mform->addElement('hidden', 'posts', 1);
$mform->setType('posts', PARAM_INT);
$mform->addElement('static', 'questionslabel', '',
" " . get_string('questionsnumber', 'hub', $questioncount));
$mform->addElement('hidden', 'questions', 1);
$mform->setType('questions', PARAM_INT);
$mform->addElement('static', 'resourceslabel', '',
" " . get_string('resourcesnumber', 'hub', $resourcecount));
$mform->addElement('hidden', 'resources', 1);
$mform->setType('resources', PARAM_INT);
$mform->addElement('static', 'badgeslabel', '',
" " . get_string('badgesnumber', 'hub', $badges));
$mform->addElement('hidden', 'badges', 1);
$mform->setType('badges', PARAM_INT);
$mform->addElement('static', 'issuedbadgeslabel', '',
" " . get_string('issuedbadgesnumber', 'hub', $issuedbadges));
$mform->addElement('hidden', 'issuedbadges', true);
$mform->setType('issuedbadges', PARAM_INT);
$mform->addElement('static', 'participantnumberaveragelabel', '',
" " . get_string('participantnumberaverage', 'hub', $participantnumberaverage));
$mform->addElement('hidden', 'participantnumberaverage', 1);
$mform->setType('participantnumberaverage', PARAM_FLOAT);
$mform->addElement('static', 'modulenumberaveragelabel', '',
" " . get_string('modulenumberaverage', 'hub', $modulenumberaverage));
$mform->addElement('hidden', 'modulenumberaverage', 1);
$mform->setType('modulenumberaverage', PARAM_FLOAT);
$mobileservicestatus = $ismobileenabled ? 'yes' : 'no';
$mform->addElement('static', 'mobileservicesenabledlabel', '',
" " . get_string('mobileservicesenabled', 'hub', $mobileservicestatus));
$mform->addElement('hidden', 'mobileservicesenabled', 1);
$mform->setType('mobileservicesenabled', PARAM_INT);
$mobilenotificationsstatus = $aremobilenotificationsenabled ? 'yes' : 'no';
$mform->addElement('static', 'mobilenotificationsenabledlabel', '',
" " . get_string('mobilenotificationsenabled', 'hub', $mobilenotificationsstatus));
$mform->addElement('hidden', 'mobilenotificationsenabled', 1);
$mform->setType('mobilenotificationsenabled', PARAM_INT);
$mform->addElement('static', 'registereduserdeviceslabel', '',
" " . get_string('registereduserdevices', 'hub', $registereduserdevicescount));
$mform->addElement('hidden', 'registereduserdevices', 1);
$mform->setType('registereduserdevices', PARAM_INT);
$mform->addElement('static', 'registeredactiveuserdeviceslabel', '',
" " . get_string('registeredactiveuserdevices', 'hub', $registeredactiveuserdevicescount));
$mform->addElement('hidden', 'registeredactiveuserdevices', 1);
$mform->setType('registeredactiveuserdevices', PARAM_INT);
}
//check if it's a first registration or update
$hubregistered = $registrationmanager->get_registeredhub($huburl);
if (!empty($hubregistered)) {
$buttonlabel = get_string('updatesite', 'hub',
!empty($hubname) ? $hubname : $huburl);
$mform->addElement('hidden', 'update', true);
$mform->setType('update', PARAM_BOOL);
} else {
$buttonlabel = get_string('registersite', 'hub',
!empty($hubname) ? $hubname : $huburl);
}
$this->add_action_buttons(false, $buttonlabel);
}
}
debugging('Support for alternative hubs has been removed from Moodle in 3.4. For communication with moodle.net ' .
'see lib/classes/hub/ .', DEBUG_DEVELOPER);
+63 -160
View File
@@ -15,194 +15,97 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/*
/**
* @package moodle
* @subpackage registration
* @author Jerome Mouneyrac <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
*
* On this page the administrator selects which hub he wants to register (except for moodle.net)
* Admins can register with moodle.net via the site admin menu "Registration" link.
* On this page the administrator can also unregister from any hubs including moodle.net.
* This page displays the site registration form for Moodle.net.
* It handles redirection to the hub to continue the registration workflow process.
* It also handles update operation by web service.
*/
require('../../config.php');
require_once('../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/forms.php');
require_once($CFG->dirroot . '/course/publish/lib.php');
require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
admin_externalpage_setup('registrationhubs');
$renderer = $PAGE->get_renderer('core', 'register');
admin_externalpage_setup('registrationmoodleorg');
$unregistration = optional_param('unregistration', 0, PARAM_INT);
$cleanregdata = optional_param('cleanregdata', 0, PARAM_BOOL);
$confirm = optional_param('confirm', 0, PARAM_INT);
$huburl = optional_param('huburl', '', PARAM_URL);
$cancel = optional_param('cancel', null, PARAM_ALPHA);
$registrationmanager = new registration_manager();
$publicationmanager = new course_publish_manager();
$errormessage = '';
if (empty($cancel) and $unregistration and $confirm and confirm_sesskey()) {
if ($unregistration && \core\hub\registration::is_registered()) {
$siteunregistrationform = new \core\hub\site_unregistration_form();
$hub = $registrationmanager->get_registeredhub($huburl);
//unpublish course and unregister the site by web service
if (!$cleanregdata) {
//check if we need to unpublish courses
//enrollable courses
$unpublishalladvertisedcourses = optional_param('unpublishalladvertisedcourses', 0, PARAM_INT);
$hubcourseids = array();
if ($unpublishalladvertisedcourses) {
$enrollablecourses = $publicationmanager->get_publications($huburl, null, 1);
if (!empty($enrollablecourses)) {
foreach ($enrollablecourses as $enrollablecourse) {
$hubcourseids[] = $enrollablecourse->hubcourseid;
}
}
}
//downloadable courses
$unpublishalluploadedcourses = optional_param('unpublishalluploadedcourses', 0, PARAM_INT);
if ($unpublishalluploadedcourses) {
$downloadablecourses = $publicationmanager->get_publications($huburl, null, 0);
if (!empty($downloadablecourses)) {
foreach ($downloadablecourses as $downloadablecourse) {
$hubcourseids[] = $downloadablecourse->hubcourseid;
}
}
}
//unpublish the courses by web service
if (!empty($hubcourseids)) {
$function = 'hub_unregister_courses';
$params = array('courseids' => $hubcourseids);
$serverurl = $huburl . "/local/hub/webservice/webservices.php";
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token);
try {
$result = $xmlrpcclient->call($function, $params);
//delete the published courses
if (!empty($enrollablecourses)) {
$publicationmanager->delete_hub_publications($huburl, 1);
}
if (!empty($downloadablecourses)) {
$publicationmanager->delete_hub_publications($huburl, 0);
}
} catch (Exception $e) {
$errormessage = $e->getMessage();
$errormessage .= html_writer::empty_tag('br') .
get_string('errorunpublishcourses', 'hub');
$confirm = false;
$cleanregdata = 1;
}
if ($siteunregistrationform->is_cancelled()) {
redirect(new moodle_url('/admin/registration/index.php'));
} else if ($data = $siteunregistrationform->get_data()) {
if (\core\hub\registration::unregister($data->unpublishalladvertisedcourses,
$data->unpublishalluploadedcourses)) {
redirect(new moodle_url('/admin/registration/index.php'));
}
}
//course unpublish went ok, unregister the site now
if ($confirm) {
$function = 'hub_unregister_site';
$params = array();
$serverurl = $huburl . "/local/hub/webservice/webservices.php";
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token);
try {
$result = $xmlrpcclient->call($function, $params);
} catch (Exception $e) {
if (!$cleanregdata) {
$errormessage = $e->getMessage();
$confirm = false;
$cleanregdata = 1;
}
}
}
//check that we are still processing the unregistration,
//it could have been unset if an exception were previsouly catched
if ($confirm) {
$registrationmanager->delete_registeredhub($huburl);
}
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('unregisterfrom', 'hub', 'Moodle.net'), 3, 'main');
$siteunregistrationform->display();
echo $OUTPUT->footer();
exit;
}
if (empty($cancel) and $unregistration and !$confirm) {
$siteregistrationform = new \core\hub\site_registration_form();
if ($fromform = $siteregistrationform->get_data()) {
echo $OUTPUT->header();
// Save the settings.
\core\hub\registration::save_site_info($fromform);
//do not check sesskey if confirm = false because this script is linked into email message
if (!empty($errormessage)) {
echo $OUTPUT->notification(get_string('unregistrationerror', 'hub', $errormessage));
}
$hub = $registrationmanager->get_registeredhub($huburl);
echo $OUTPUT->heading(get_string('unregisterfrom', 'hub', $hub->hubname), 3, 'main');
if ($cleanregdata) {
$siteunregistrationform = new site_clean_registration_data_form('',
array('huburl' => $huburl, 'hubname' => $hub->hubname));
if (\core\hub\registration::is_registered()) {
\core\hub\registration::update_manual();
redirect(new moodle_url('/admin/registration/index.php'));
} else {
$siteunregistrationform = new site_unregistration_form('',
array('huburl' => $huburl, 'hubname' => $hub->hubname));
\core\hub\registration::register();
// This method will redirect away.
}
$siteunregistrationform->display();
}
// OUTPUT SECTION.
echo $OUTPUT->header();
// Current status of registration on Moodle.net.
$notificationtype = \core\output\notification::NOTIFY_ERROR;
if (\core\hub\registration::is_registered()) {
$lastupdated = \core\hub\registration::get_last_updated();
if ($lastupdated == 0) {
$registrationmessage = get_string('pleaserefreshregistrationunknown', 'admin');
} else {
$lastupdated = userdate($lastupdated, get_string('strftimedate', 'langconfig'));
$registrationmessage = get_string('pleaserefreshregistration', 'admin', $lastupdated);
$notificationtype = \core\output\notification::NOTIFY_INFO;
}
echo $OUTPUT->notification($registrationmessage, $notificationtype);
} else {
$registeredonmoodleorg = false;
$moodleorghub = $registrationmanager->get_registeredhub(HUB_MOODLEORGHUBURL);
if (!empty($moodleorghub)) {
$registeredonmoodleorg = true;
}
$registrationmessage = get_string('registrationwarning', 'admin');
echo $OUTPUT->notification($registrationmessage, $notificationtype);
}
// load the hub selector form
$hubselectorform = new hub_selector_form();
$fromform = $hubselectorform->get_data();
$selectedhuburl = optional_param('publichub', false, PARAM_URL);
$unlistedhuburl = optional_param('unlistedurl', false, PARAM_TEXT);
$password = optional_param('password', '', PARAM_RAW);
$registeringhuburl = null;
if (!empty($unlistedhuburl)) {
if (clean_param($unlistedhuburl, PARAM_URL) !== '') {
$registeringhuburl = $unlistedhuburl;
}
} else if (!empty($selectedhuburl)) {
$registeringhuburl = $selectedhuburl;
}
// Heading.
if (\core\hub\registration::is_registered()) {
echo $OUTPUT->heading(get_string('updatesite', 'hub', 'Moodle.net'));
} else {
echo $OUTPUT->heading(get_string('registerwithmoodleorg', 'admin'));
}
// a hub has been selected, redirect to the hub registration page
if (empty($cancel) and !empty($registeringhuburl) and confirm_sesskey()) {
$hubname = optional_param(clean_param($registeringhuburl, PARAM_ALPHANUMEXT), '', PARAM_TEXT);
$params = array('sesskey' => sesskey(), 'huburl' => $registeringhuburl,
'password' => $password, 'hubname' => $hubname);
redirect(new moodle_url($CFG->wwwroot . "/" . $CFG->admin . "/registration/register.php",
$params));
}
$renderer = $PAGE->get_renderer('core', 'register');
echo $renderer->moodleorg_registration_message();
echo $OUTPUT->header();
$siteregistrationform->display();
//check if the site is registered on Moodle.org and display a message about registering on MOOCH
$adminrenderer = $PAGE->get_renderer('core', 'admin');
echo $adminrenderer->warn_if_not_registered();
//do not check sesskey if confirm = false because this script is linked into email message
if (!empty($errormessage)) {
echo $OUTPUT->notification(get_string('unregistrationerror', 'hub', $errormessage));
}
echo $OUTPUT->heading(get_string('registerwith', 'hub'));
$hubselectorform->display();
if (extension_loaded('xmlrpc')) {
$hubs = $registrationmanager->get_registered_on_hubs();
if (!empty($hubs)) {
echo $OUTPUT->heading(get_string('registeredon', 'hub'), 3, 'main');
echo $renderer->registeredonhublisting($hubs);
}
} else { //display notice about xmlrpc
$xmlrpcnotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', '');
$xmlrpcnotification .= get_string('xmlrpcdisabledregistration', 'hub');
echo $OUTPUT->notification($xmlrpcnotification);
}
if (\core\hub\registration::is_registered()) {
// Unregister link.
$unregisterhuburl = new moodle_url("/admin/registration/index.php", ['unregistration' => 1]);
echo html_writer::div(html_writer::link($unregisterhuburl, get_string('unregister', 'hub')), 'unregister');
}
echo $OUTPUT->footer();
+1 -310
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -15,312 +14,4 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
//// SITE PRIVACY /////
/**
* Site privacy: private
*/
define('HUB_SITENOTPUBLISHED', 'notdisplayed');
/**
* Site privacy: public
*/
define('HUB_SITENAMEPUBLISHED', 'named');
/**
* Site privacy: public and global
*/
define('HUB_SITELINKPUBLISHED', 'linked');
/**
*
* Site registration library
*
* @package course
* @copyright 2010 Moodle Pty Ltd (http://moodle.com)
* @author Jerome Mouneyrac
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class registration_manager {
/**
* Automatically update the registration on all hubs
*/
public function cron() {
global $CFG;
if (extension_loaded('xmlrpc')) {
$function = 'hub_update_site_info';
require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
// Update all hubs where the site is registered.
$hubs = $this->get_registered_on_hubs();
if (empty($hubs)) {
mtrace(get_string('registrationwarning', 'admin'));
}
foreach ($hubs as $hub) {
// Update the registration.
$siteinfo = $this->get_site_info($hub->huburl);
$params = array('siteinfo' => $siteinfo);
$serverurl = $hub->huburl . "/local/hub/webservice/webservices.php";
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token);
try {
$result = $xmlrpcclient->call($function, $params);
$this->update_registeredhub($hub); // To update timemodified.
mtrace(get_string('siteupdatedcron', 'hub', $hub->hubname));
} catch (Exception $e) {
$errorparam = new stdClass();
$errorparam->errormessage = $e->getMessage();
$errorparam->hubname = $hub->hubname;
mtrace(get_string('errorcron', 'hub', $errorparam));
}
}
} else {
mtrace(get_string('errorcronnoxmlrpc', 'hub'));
}
}
/**
* Return the site secret for a given hub
* site identifier is assigned to Mooch
* each hub has a unique and personal site secret.
* @param string $huburl
* @return string site secret
*/
public function get_site_secret_for_hub($huburl) {
global $DB;
$existingregistration = $DB->get_record('registration_hubs',
array('huburl' => $huburl));
if (!empty($existingregistration)) {
return $existingregistration->secret;
}
if ($huburl == HUB_MOODLEORGHUBURL) {
$siteidentifier = get_site_identifier();
} else {
$siteidentifier = random_string(32) . $_SERVER['HTTP_HOST'];
}
return $siteidentifier;
}
/**
* When the site register on a hub, he must call this function
* @param object $hub where the site is registered on
* @return integer id of the record
*/
public function add_registeredhub($hub) {
global $DB;
$hub->timemodified = time();
$id = $DB->insert_record('registration_hubs', $hub);
return $id;
}
/**
* When a site unregister from a hub, he must call this function
* @param string $huburl the huburl to delete
*/
public function delete_registeredhub($huburl) {
global $DB;
$DB->delete_records('registration_hubs', array('huburl' => $huburl));
}
/**
* Get a hub on which the site is registered for a given url or token
* Mostly use to check if the site is registered on a specific hub
* @param string $huburl
* @param string $token
* @return object the hub
*/
public function get_registeredhub($huburl = null, $token = null) {
global $DB;
$params = array();
if (!empty($huburl)) {
$params['huburl'] = $huburl;
}
if (!empty($token)) {
$params['token'] = $token;
}
$params['confirmed'] = 1;
$token = $DB->get_record('registration_hubs', $params);
return $token;
}
/**
* Get the hub which has not confirmed that the site is registered on,
* but for which a request has been sent
* @param string $huburl
* @return object the hub
*/
public function get_unconfirmedhub($huburl) {
global $DB;
$params = array();
$params['huburl'] = $huburl;
$params['confirmed'] = 0;
$token = $DB->get_record('registration_hubs', $params);
return $token;
}
/**
* Update a registered hub (mostly use to update the confirmation status)
* @param object $hub the hub
*/
public function update_registeredhub($hub) {
global $DB;
$hub->timemodified = time();
$DB->update_record('registration_hubs', $hub);
}
/**
* Return all hubs where the site is registered
*/
public function get_registered_on_hubs() {
global $DB;
$hubs = $DB->get_records('registration_hubs', array('confirmed' => 1));
return $hubs;
}
/**
* Return site information for a specific hub
* @param string $huburl
* @return array site info
*/
public function get_site_info($huburl) {
global $CFG, $DB;
$siteinfo = array();
$cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
$siteinfo['name'] = get_config('hub', 'site_name_' . $cleanhuburl);
$siteinfo['description'] = get_config('hub', 'site_description_' . $cleanhuburl);
$siteinfo['contactname'] = get_config('hub', 'site_contactname_' . $cleanhuburl);
$siteinfo['contactemail'] = get_config('hub', 'site_contactemail_' . $cleanhuburl);
$siteinfo['contactphone'] = get_config('hub', 'site_contactphone_' . $cleanhuburl);
$siteinfo['imageurl'] = get_config('hub', 'site_imageurl_' . $cleanhuburl);
$siteinfo['privacy'] = get_config('hub', 'site_privacy_' . $cleanhuburl);
$siteinfo['street'] = get_config('hub', 'site_address_' . $cleanhuburl);
$siteinfo['regioncode'] = get_config('hub', 'site_region_' . $cleanhuburl);
$siteinfo['countrycode'] = get_config('hub', 'site_country_' . $cleanhuburl);
$siteinfo['geolocation'] = get_config('hub', 'site_geolocation_' . $cleanhuburl);
$siteinfo['contactable'] = get_config('hub', 'site_contactable_' . $cleanhuburl);
$siteinfo['emailalert'] = get_config('hub', 'site_emailalert_' . $cleanhuburl);
if (get_config('hub', 'site_coursesnumber_' . $cleanhuburl) == -1) {
$coursecount = -1;
} else {
$coursecount = $DB->count_records('course') - 1;
}
$siteinfo['courses'] = $coursecount;
if (get_config('hub', 'site_usersnumber_' . $cleanhuburl) == -1) {
$usercount = -1;
} else {
$usercount = $DB->count_records('user', array('deleted' => 0));
}
$siteinfo['users'] = $usercount;
if (get_config('hub', 'site_roleassignmentsnumber_' . $cleanhuburl) == -1) {
$roleassigncount = -1;
} else {
$roleassigncount = $DB->count_records('role_assignments');
}
$siteinfo['enrolments'] = $roleassigncount;
if (get_config('hub', 'site_postsnumber_' . $cleanhuburl) == -1) {
$postcount = -1;
} else {
$postcount = $DB->count_records('forum_posts');
}
$siteinfo['posts'] = $postcount;
if (get_config('hub', 'site_questionsnumber_' . $cleanhuburl) == -1) {
$questioncount = -1;
} else {
$questioncount = $DB->count_records('question');
}
$siteinfo['questions'] = $questioncount;
if (get_config('hub', 'site_resourcesnumber_' . $cleanhuburl) == -1) {
$resourcecount = -1;
} else {
$resourcecount = $DB->count_records('resource');
}
$siteinfo['resources'] = $resourcecount;
// Badge statistics.
require_once($CFG->libdir . '/badgeslib.php');
if (get_config('hub', 'site_badges_' . $cleanhuburl) == -1) {
$badges = -1;
} else {
$badges = $DB->count_records_select('badge', 'status <> ' . BADGE_STATUS_ARCHIVED);
}
$siteinfo['badges'] = $badges;
if (get_config('hub', 'site_issuedbadges_' . $cleanhuburl) == -1) {
$issuedbadges = -1;
} else {
$issuedbadges = $DB->count_records('badge_issued');
}
$siteinfo['issuedbadges'] = $issuedbadges;
//TODO
require_once($CFG->dirroot . "/course/lib.php");
if (get_config('hub', 'site_participantnumberaverage_' . $cleanhuburl) == -1) {
$participantnumberaverage = -1;
} else {
$participantnumberaverage = average_number_of_participants();
}
$siteinfo['participantnumberaverage'] = $participantnumberaverage;
if (get_config('hub', 'site_modulenumberaverage_' . $cleanhuburl) == -1) {
$modulenumberaverage = -1;
} else {
$modulenumberaverage = average_number_of_courses_modules();
}
$siteinfo['modulenumberaverage'] = $modulenumberaverage;
$siteinfo['language'] = get_config('hub', 'site_language_' . $cleanhuburl);
$siteinfo['moodleversion'] = $CFG->version;
$siteinfo['moodlerelease'] = $CFG->release;
$siteinfo['url'] = $CFG->wwwroot;
// Mobile related information.
$siteinfo['mobileservicesenabled'] = 0;
$siteinfo['mobilenotificationsenabled'] = 0;
$siteinfo['registereduserdevices'] = 0;
$siteinfo['registeredactiveuserdevices'] = 0;
if (!empty($CFG->enablewebservices) && !empty($CFG->enablemobilewebservice)) {
$siteinfo['mobileservicesenabled'] = 1;
$siteinfo['registereduserdevices'] = $DB->count_records('user_devices');
$airnotifierextpath = $CFG->dirroot . '/message/output/airnotifier/externallib.php';
if (file_exists($airnotifierextpath)) { // Maybe some one uninstalled the plugin.
require_once($airnotifierextpath);
$siteinfo['mobilenotificationsenabled'] = message_airnotifier_external::is_system_configured();
$siteinfo['registeredactiveuserdevices'] = $DB->count_records('message_airnotifier_devices', array('enable' => 1));
}
}
return $siteinfo;
}
/**
* Retrieve the site privacy string matching the define value
* @param string $privacy must match the define into moodlelib.php
* @return string
*/
public function get_site_privacy_string($privacy) {
switch ($privacy) {
case HUB_SITENOTPUBLISHED:
$privacystring = get_string('siteprivacynotpublished', 'hub');
break;
case HUB_SITENAMEPUBLISHED:
$privacystring = get_string('siteprivacypublished', 'hub');
break;
case HUB_SITELINKPUBLISHED:
$privacystring = get_string('siteprivacylinked', 'hub');
break;
}
if (empty($privacystring)) {
throw new moodle_exception('unknownprivacy');
}
return $privacystring;
}
}
?>
defined('MOODLE_INTERNAL') || die();
+2 -176
View File
@@ -20,7 +20,7 @@
// //
///////////////////////////////////////////////////////////////////////////
/*
/**
* @package moodle
* @subpackage registration
* @author Jerome Mouneyrac <[email protected]>
@@ -34,179 +34,5 @@
require_once('../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/forms.php');
require_once($CFG->dirroot . '/webservice/lib.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
require_sesskey();
$huburl = required_param('huburl', PARAM_URL);
$huburl = rtrim($huburl, "/");
if ($huburl == HUB_MOODLEORGHUBURL) { // register to Moodle.org
admin_externalpage_setup('registrationmoodleorg');
} else { //register to a hub
admin_externalpage_setup('registrationhub');
}
$password = optional_param('password', '', PARAM_TEXT);
$hubname = optional_param('hubname', '', PARAM_TEXT);
$registrationmanager = new registration_manager();
$registeredhub = $registrationmanager->get_registeredhub($huburl);
$siteregistrationform = new site_registration_form('',
array('alreadyregistered' => !empty($registeredhub->token),
'huburl' => $huburl, 'hubname' => $hubname,
'password' => $password));
$fromform = $siteregistrationform->get_data();
if (!empty($fromform) and confirm_sesskey()) {
// Set to -1 all optional data marked as "don't send" by the admin.
// The function get_site_info() will not calculate the optional data if config is set to -1.
$inputnames = array('courses', 'users', 'roleassignments', 'posts', 'questions', 'resources',
'badges', 'issuedbadges', 'modulenumberaverage', 'participantnumberaverage',
'mobileservicesenabled', 'mobilenotificationsenabled', 'registereduserdevices', 'registeredactiveuserdevices');
foreach ($inputnames as $inputname) {
if (empty($fromform->{$inputname})) {
$fromform->{$inputname} = -1;
}
}
// Save the settings.
$cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
set_config('site_name_' . $cleanhuburl, $fromform->name, 'hub');
set_config('site_description_' . $cleanhuburl, $fromform->description, 'hub');
set_config('site_contactname_' . $cleanhuburl, $fromform->contactname, 'hub');
set_config('site_contactemail_' . $cleanhuburl, $fromform->contactemail, 'hub');
set_config('site_contactphone_' . $cleanhuburl, $fromform->contactphone, 'hub');
set_config('site_imageurl_' . $cleanhuburl, $fromform->imageurl, 'hub');
set_config('site_privacy_' . $cleanhuburl, $fromform->privacy, 'hub');
set_config('site_address_' . $cleanhuburl, $fromform->address, 'hub');
set_config('site_region_' . $cleanhuburl, $fromform->regioncode, 'hub');
set_config('site_country_' . $cleanhuburl, $fromform->countrycode, 'hub');
set_config('site_language_' . $cleanhuburl, $fromform->language, 'hub');
set_config('site_geolocation_' . $cleanhuburl, $fromform->geolocation, 'hub');
set_config('site_contactable_' . $cleanhuburl, $fromform->contactable, 'hub');
set_config('site_emailalert_' . $cleanhuburl, $fromform->emailalert, 'hub');
set_config('site_coursesnumber_' . $cleanhuburl, $fromform->courses, 'hub');
set_config('site_usersnumber_' . $cleanhuburl, $fromform->users, 'hub');
set_config('site_roleassignmentsnumber_' . $cleanhuburl, $fromform->roleassignments, 'hub');
set_config('site_postsnumber_' . $cleanhuburl, $fromform->posts, 'hub');
set_config('site_questionsnumber_' . $cleanhuburl, $fromform->questions, 'hub');
set_config('site_resourcesnumber_' . $cleanhuburl, $fromform->resources, 'hub');
set_config('site_badges_' . $cleanhuburl, $fromform->badges, 'hub');
set_config('site_issuedbadges_' . $cleanhuburl, $fromform->issuedbadges, 'hub');
set_config('site_modulenumberaverage_' . $cleanhuburl, $fromform->modulenumberaverage, 'hub');
set_config('site_participantnumberaverage_' . $cleanhuburl, $fromform->participantnumberaverage, 'hub');
set_config('site_mobileservicesenabled_' . $cleanhuburl, $fromform->mobileservicesenabled, 'hub');
set_config('site_mobilenotificationsenabled_' . $cleanhuburl, $fromform->mobilenotificationsenabled, 'hub');
set_config('site_registereduserdevices_' . $cleanhuburl, $fromform->registereduserdevices, 'hub');
set_config('site_registeredactiveuserdevices_' . $cleanhuburl, $fromform->registeredactiveuserdevices, 'hub');
}
/////// UPDATE ACTION ////////
// update the hub registration
$update = optional_param('update', 0, PARAM_INT);
if ($update and confirm_sesskey()) {
//update the registration
$function = 'hub_update_site_info';
$siteinfo = $registrationmanager->get_site_info($huburl);
$params = array('siteinfo' => $siteinfo);
$serverurl = $huburl . "/local/hub/webservice/webservices.php";
require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token);
try {
$result = $xmlrpcclient->call($function, $params);
$registrationmanager->update_registeredhub($registeredhub); // To update timemodified.
} catch (Exception $e) {
$error = $OUTPUT->notification(get_string('errorregistration', 'hub', $e->getMessage()));
}
}
/////// FORM REGISTRATION ACTION //////
if (!empty($fromform) and empty($update) and confirm_sesskey()) {
if (!empty($fromform) and confirm_sesskey()) { // if the register button has been clicked
// Retrieve the optional info (specially course number, user number, module number average...).
$siteinfo = $registrationmanager->get_site_info($huburl);
$fromform->courses = $siteinfo['courses'];
$fromform->users = $siteinfo['users'];
$fromform->enrolments = $siteinfo['enrolments'];
$fromform->posts = $siteinfo['posts'];
$fromform->questions = $siteinfo['questions'];
$fromform->resources = $siteinfo['resources'];
$fromform->badges = $siteinfo['badges'];
$fromform->issuedbadges = $siteinfo['issuedbadges'];
$fromform->modulenumberaverage = $siteinfo['modulenumberaverage'];
$fromform->participantnumberaverage = $siteinfo['participantnumberaverage'];
$fromform->street = $siteinfo['street'];
$fromform->mobileservicesenabled = $siteinfo['mobileservicesenabled'];
$fromform->mobilenotificationsenabled = $siteinfo['mobilenotificationsenabled'];
$fromform->registereduserdevices = $siteinfo['registereduserdevices'];
$fromform->registeredactiveuserdevices = $siteinfo['registeredactiveuserdevices'];
$params = (array) $fromform; //we are using the form input as the redirection parameters (token, url and name)
$unconfirmedhub = $registrationmanager->get_unconfirmedhub($huburl);
if (empty($unconfirmedhub)) {
//we save the token into the communication table in order to have a reference
$unconfirmedhub = new stdClass();
$unconfirmedhub->token = $registrationmanager->get_site_secret_for_hub($huburl);
$unconfirmedhub->secret = $unconfirmedhub->token;
$unconfirmedhub->huburl = $huburl;
$unconfirmedhub->hubname = $hubname;
$unconfirmedhub->confirmed = 0;
$unconfirmedhub->id = $registrationmanager->add_registeredhub($unconfirmedhub);
}
$params['token'] = $unconfirmedhub->token;
$params['url'] = $CFG->wwwroot;
redirect(new moodle_url($huburl . '/local/hub/siteregistration.php', $params));
}
}
/////// OUTPUT SECTION /////////////
echo $OUTPUT->header();
//Display update notification result
if (!empty($registeredhub->confirmed)) {
if (!empty($result)) {
echo $OUTPUT->notification(get_string('siteregistrationupdated', 'hub'), 'notifysuccess');
}
}
if (!empty($error)) {
echo $error;
}
// Some Moodle.org registration explanation.
if ($huburl == HUB_MOODLEORGHUBURL) {
$notificationtype = \core\output\notification::NOTIFY_ERROR;
if (!empty($registeredhub->token)) {
if ($registeredhub->timemodified == 0) {
$registrationmessage = get_string('pleaserefreshregistrationunknown', 'admin');
} else {
$lastupdated = userdate($registeredhub->timemodified, get_string('strftimedate', 'langconfig'));
$registrationmessage = get_string('pleaserefreshregistration', 'admin', $lastupdated);
$notificationtype = \core\output\notification::NOTIFY_INFO;
}
} else {
$registrationmessage = get_string('registrationwarning', 'admin');
}
echo $OUTPUT->notification($registrationmessage, $notificationtype);
echo $OUTPUT->heading(get_string('registerwithmoodleorg', 'admin'));
$renderer = $PAGE->get_renderer('core', 'register');
echo $renderer->moodleorg_registration_message();
}
$siteregistrationform->display();
echo $OUTPUT->footer();
redirect(new moodle_url('/admin/registration/index.php'));
-46
View File
@@ -46,50 +46,4 @@ class core_register_renderer extends plugin_renderer_base {
$moodleorgregmsg .= html_writer::alist($items);
return $moodleorgregmsg;
}
/**
* Display a box message confirming a site registration (add or update)
* @param string $confirmationmessage
* @return string
*/
public function registration_confirmation($confirmationmessage) {
$linktositelist = html_writer::tag('a', get_string('sitelist', 'hub'),
array('href' => new moodle_url('/local/hub/index.php')));
$message = $confirmationmessage . html_writer::empty_tag('br') . $linktositelist;
return $this->output->box($message);
}
/**
* Display the listing of registered on hub
*/
public function registeredonhublisting($hubs) {
global $CFG;
$table = new html_table();
$table->head = array(get_string('hub', 'hub'), get_string('operation', 'hub'));
$table->size = array('80%', '20%');
foreach ($hubs as $hub) {
if ($hub->huburl == HUB_MOODLEORGHUBURL) {
$hub->hubname = get_string('registeredmoodleorg', 'hub', $hub->hubname);
}
$hublink = html_writer::tag('a', $hub->hubname, array('href' => $hub->huburl));
$hublinkcell = html_writer::tag('div', $hublink, array('class' => 'registeredhubrow'));
$unregisterhuburl = new moodle_url("/" . $CFG->admin . "/registration/index.php",
array('sesskey' => sesskey(), 'huburl' => $hub->huburl,
'unregistration' => 1));
$unregisterbutton = new single_button($unregisterhuburl,
get_string('unregister', 'hub'));
$unregisterbutton->class = 'centeredbutton';
$unregisterbuttonhtml = $this->output->render($unregisterbutton);
//add button cells
$cells = array($hublinkcell, $unregisterbuttonhtml);
$row = new html_table_row($cells);
$table->data[] = $row;
}
return html_writer::table($table);
}
}
+22 -34
View File
@@ -20,7 +20,7 @@
// //
///////////////////////////////////////////////////////////////////////////
/*
/**
* @package moodle
* @subpackage registration
* @author Jerome Mouneyrac <[email protected]>
@@ -33,44 +33,32 @@
require('../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
$url = optional_param('url', '', PARAM_URL);
$hubname = optional_param('hubname', '', PARAM_TEXT);
$token = optional_param('token', '', PARAM_TEXT);
admin_externalpage_setup('registrationhubs');
admin_externalpage_setup('registrationmoodleorg');
//check that we are waiting a confirmation from this hub, and check that the token is correct
$registrationmanager = new registration_manager();
$registeredhub = $registrationmanager->get_unconfirmedhub($url);
if (!empty($registeredhub) and $registeredhub->token == $token) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('renewregistration', 'hub'), 3, 'main');
$hublink = html_writer::tag('a', $hubname, array('href' => $url));
$registrationmanager->delete_registeredhub($url);
//Mooch case, need to recreate the siteidentifier
if ($url == HUB_MOODLEORGHUBURL) {
$CFG->siteidentifier = null;
get_site_identifier();
}
$deletedregmsg = get_string('previousregistrationdeleted', 'hub', $hublink);
$button = new single_button(new moodle_url('/admin/registration/index.php'),
get_string('restartregistration', 'hub'));
$button->class = 'restartregbutton';
echo html_writer::tag('div', $deletedregmsg . $OUTPUT->render($button),
array('class' => 'mdl-align'));
echo $OUTPUT->footer();
} else {
throw new moodle_exception('wrongtoken', 'hub',
$CFG->wwwroot . '/' . $CFG->admin . '/registration/index.php');
if ($url !== HUB_MOODLEORGHUBURL) {
throw new moodle_exception('errorotherhubsnotsupported', 'hub');
}
// Check that we are waiting a confirmation from this hub, and check that the token is correct.
\core\hub\registration::reset_site_identifier($token);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('renewregistration', 'hub'), 3, 'main');
$hublink = html_writer::tag('a', 'Moodle.net', array('href' => HUB_MOODLEORGHUBURL));
$deletedregmsg = get_string('previousregistrationdeleted', 'hub', $hublink);
$button = new single_button(new moodle_url('/admin/registration/index.php'),
get_string('restartregistration', 'hub'));
$button->class = 'restartregbutton';
echo html_writer::tag('div', $deletedregmsg . $OUTPUT->render($button),
array('class' => 'mdl-align'));
echo $OUTPUT->footer();
+2 -6
View File
@@ -805,8 +805,7 @@ class core_admin_renderer extends plugin_renderer_base {
if (!$registered) {
if (has_capability('moodle/site:config', context_system::instance())) {
$registerbutton = $this->single_button(new moodle_url('/admin/registration/register.php',
array('huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.net')),
$registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
get_string('register', 'admin'));
$str = 'registrationwarning';
} else {
@@ -828,10 +827,7 @@ class core_admin_renderer extends plugin_renderer_base {
* @return string
*/
public function warn_if_not_registered() {
global $CFG;
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
$registrationmanager = new registration_manager();
return $this->registration_warning($registrationmanager->get_registeredhub(HUB_MOODLEORGHUBURL) ? true : false);
return $this->registration_warning(\core\hub\registration::is_registered());
}
/**
-3
View File
@@ -211,9 +211,6 @@ $temp->add(new admin_setting_configtext('curltimeoutkbitrate', new lang_string('
$ADMIN->add('server', $temp);
$ADMIN->add('server', new admin_externalpage('adminregistration', new lang_string('hubs', 'admin'),
"$CFG->wwwroot/$CFG->admin/registration/index.php"));
// E-mail settings.
$ADMIN->add('server', new admin_category('email', new lang_string('categoryemail', 'admin')));
+1 -8
View File
@@ -11,14 +11,7 @@ $hassiteconfig = has_capability('moodle/site:config', $systemcontext);
$ADMIN->add('root', new admin_externalpage('adminnotifications', new lang_string('notifications'), "$CFG->wwwroot/$CFG->admin/index.php"));
$ADMIN->add('root', new admin_externalpage('registrationmoodleorg', new lang_string('registration', 'admin'),
"$CFG->wwwroot/$CFG->admin/registration/register.php?huburl=" . HUB_MOODLEORGHUBURL . "&hubname=Moodle.net&sesskey=" . sesskey()));
$ADMIN->add('root', new admin_externalpage('registrationhub', new lang_string('registerwith', 'hub'),
"$CFG->wwwroot/$CFG->admin/registration/register.php", 'moodle/site:config', true));
$ADMIN->add('root', new admin_externalpage('registrationhubs', new lang_string('hubs', 'admin'),
"$CFG->wwwroot/$CFG->admin/registration/index.php", 'moodle/site:config', true));
$ADMIN->add('root', new admin_externalpage('siteregistrationconfirmed',
new lang_string('registrationconfirmed', 'hub'),
$CFG->wwwroot."/".$CFG->admin."/registration/confirmregistration.php", 'moodle/site:config', true));
new moodle_url("/admin/registration/index.php")));
// hidden upgrade script
$ADMIN->add('root', new admin_externalpage('upgradesettings', new lang_string('upgradesettings', 'admin'), "$CFG->wwwroot/$CFG->admin/upgradesettings.php", 'moodle/site:config', true));
+9 -51
View File
@@ -31,7 +31,6 @@
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
@@ -48,21 +47,8 @@ $PAGE->navbar->add(get_string('searchcourse', 'block_community'));
$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');
@@ -93,17 +79,11 @@ if ($usercandownload and $cancelrestore and confirm_sesskey()) {
}
/// 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');
@@ -115,12 +95,12 @@ if ($usercandownload and $download != -1 and !empty($downloadcourseid) and confi
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();
}
@@ -145,7 +125,6 @@ $fromformdata['language'] = optional_param('language', current_language(), PARAM
$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);
@@ -181,35 +160,14 @@ if (optional_param('executesearch', 0, PARAM_INT) and confirm_sesskey()) {
//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;
@@ -232,9 +190,9 @@ $PAGE->requires->yui_module('moodle-block_community-comments', 'M.blocks_communi
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)) {
+71 -214
View File
@@ -29,14 +29,11 @@
*/
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
@@ -81,11 +78,6 @@ class community_hub_search_form extends moodleform {
} 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'));
@@ -95,222 +87,87 @@ class community_hub_search_form extends moodleform {
$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);
// 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);
// 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;
}
$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);
//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);
}
$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);
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)) {
$mform->setDefault('language', $language);
$mform->addHelpButton('language', 'language', 'block_community');
// 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'));
$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')));
// 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'));
$mform->setDefault('orderby', $orderby);
$mform->addHelpButton('orderby', 'orderby', 'block_community');
$mform->setType('orderby', PARAM_ALPHA);
// 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'));
$mform->setAdvanced('audience');
$mform->setAdvanced('educationallevel');
$mform->setAdvanced('subject');
$mform->setAdvanced('licence');
$mform->setAdvanced('language');
$mform->setAdvanced('orderby');
$hubtext = html_writer::tag('div', $hubdescriptiontext . $hubstats, array('class' => 'hubtext'));
$mform->addElement('text', 'search', get_string('keywords', 'block_community'),
array('size' => 30));
$mform->addHelpButton('search', 'keywords', 'block_community');
$mform->setType('search', PARAM_NOTAGS);
$hubimgandtext = html_writer::tag('div', $hubimage . $hubtext, array('class' => 'hubimgandtext'));
$mform->addElement('submit', 'submitbutton', get_string('search', 'block_community'));
$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');
$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'));
}
}
function validation($data, $files) {
global $CFG;
$errors = array();
if (empty($this->_form->_submitValues['huburl'])) {
$errors['huburl'] = get_string('nohubselected', 'hub');
}
return $errors;
}
}
-60
View File
@@ -73,66 +73,6 @@ class block_community_manager {
array('courseurl' => $courseurl, 'userid' => $userid));
}
/**
* Download the community course backup and save it in file API
* @param integer $courseid
* @param string $huburl
* @return array 'privatefile' the file name saved in private area
* 'tmpfile' the file name saved in the moodledata temp dir (for restore)
*/
public function block_community_download_course_backup($course) {
global $CFG, $USER;
require_once($CFG->libdir . "/filelib.php");
require_once($CFG->dirroot. "/course/publish/lib.php");
$params['courseid'] = $course->id;
$params['filetype'] = HUB_BACKUP_FILE_TYPE;
make_temp_directory('backup');
$filename = md5(time() . '-' . $course->id . '-'. $USER->id . '-'. random_string(20));
$url = new moodle_url($course->huburl.'/local/hub/webservice/download.php', $params);
$path = $CFG->tempdir.'/backup/'.$filename.".mbz";
$fp = fopen($path, 'w');
$curlurl = $course->huburl.'/local/hub/webservice/download.php?filetype='
.HUB_BACKUP_FILE_TYPE.'&courseid='.$course->id;
//send an identification token if the site is registered on the hub
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
$registrationmanager = new registration_manager();
$registeredhub = $registrationmanager->get_registeredhub($course->huburl);
if (!empty($registeredhub)) {
$token = $registeredhub->token;
$curlurl .= '&token='.$token;
}
$ch = curl_init($curlurl);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);
$fs = get_file_storage();
$record = new stdClass();
$record->contextid = context_user::instance($USER->id)->id;
$record->component = 'user';
$record->filearea = 'private';
$record->itemid = 0;
$record->filename = urlencode($course->fullname)."_".time().".mbz";
$record->filepath = '/downloaded_backup/';
if (!$fs->file_exists($record->contextid, $record->component,
$record->filearea, 0, $record->filepath, $record->filename)) {
$fs->create_file_from_pathname($record,
$CFG->tempdir.'/backup/'.$filename.".mbz");
}
$filenames = array();
$filenames['privatefile'] = $record->filename;
$filenames['tmpfile'] = $filename;
return $filenames;
}
/**
* Delete a community course
* @param integer $communityid
+36 -12
View File
@@ -85,14 +85,43 @@ class block_community_renderer extends plugin_renderer_base {
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 = '';
@@ -128,12 +157,9 @@ class block_community_renderer extends plugin_renderer_base {
// 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',
@@ -269,7 +295,7 @@ class block_community_renderer extends plugin_renderer_base {
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'),
@@ -339,10 +365,8 @@ class block_community_renderer extends plugin_renderer_base {
//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
-4
View File
@@ -21,10 +21,6 @@
padding-left: 165px;
}
#page-blocks-community-communitycourse .hubimgandtext {
display: table;
}
#page-blocks-community-communitycourse .hubimage {
float: left;
display: block;
+4 -18
View File
@@ -35,16 +35,12 @@ define('NO_OUTPUT_BUFFERING', true);
require_once('../../config.php');
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_plan_builder.class.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
require_once($CFG->dirroot . '/course/publish/lib.php');
require_once($CFG->libdir . '/filelib.php');
//retrieve initial page parameters
$id = required_param('id', PARAM_INT);
$hubcourseid = required_param('hubcourseid', PARAM_INT);
$huburl = required_param('huburl', PARAM_URL);
$hubname = optional_param('hubname', '', PARAM_TEXT);
//some permissions and parameters checking
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
@@ -67,7 +63,7 @@ if (!($bc = backup_ui::load_controller($backupid))) {
backup::INTERACTIVE_YES, backup::MODE_HUB, $USER->id);
}
$backup = new backup_ui($bc,
array('id' => $id, 'hubcourseid' => $hubcourseid, 'huburl' => $huburl, 'hubname' => $hubname));
array('id' => $id, 'hubcourseid' => $hubcourseid, 'huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.net'));
$backup->process();
if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
$backup->execute();
@@ -78,7 +74,7 @@ if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
if ($backup->get_stage() !== backup_ui::STAGE_COMPLETE) {
$renderer = $PAGE->get_renderer('core', 'backup');
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('publishcourseon', 'hub', !empty($hubname)?$hubname:$huburl), 3, 'main');
echo $OUTPUT->heading(get_string('publishcourseon', 'hub', 'Moodle.net'), 3, 'main');
if ($backup->enforce_changed_dependencies()) {
debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER);
}
@@ -93,10 +89,6 @@ $backupfile = $bc->get_results();
$backupfile = $backupfile['backup_destination'];
//END backup processing
//retrieve the token to call the hub
$registrationmanager = new registration_manager();
$registeredhub = $registrationmanager->get_registeredhub($huburl);
//display the sending file page
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('sendingcourse', 'hub'), 3, 'main');
@@ -108,19 +100,13 @@ if (ob_get_level()) {
flush();
//send backup file to the hub
$curl = new curl();
$params = array();
$params['filetype'] = HUB_BACKUP_FILE_TYPE;
$params['courseid'] = $hubcourseid;
$params['file'] = $backupfile;
$params['token'] = $registeredhub->token;
$curl->post($huburl . "/local/hub/webservice/upload.php", $params);
\core\hub\publication::upload_course_backup($hubcourseid, $backupfile);
//delete the temp backup file from user_tohub aera
$backupfile->delete();
$bc->destroy();
//Output sending success
echo $renderer->sentbackupinfo($id, $huburl, $hubname);
echo $renderer->sentbackupinfo($id, HUB_MOODLEORGHUBURL, 'Moodle.net');
echo $OUTPUT->footer();
+4 -362
View File
@@ -20,7 +20,7 @@
// //
///////////////////////////////////////////////////////////////////////////
/*
/**
* @package course
* @subpackage publish
* @author Jerome Mouneyrac <[email protected]>
@@ -30,365 +30,7 @@
* The forms used for course publication
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot . "/" . $CFG->admin . "/registration/lib.php");
require_once($CFG->dirroot . "/course/publish/lib.php");
/*
* Hub selector to choose on which hub we want to publish.
*/
class hub_publish_selector_form extends moodleform {
public function definition() {
global $CFG;
$mform = & $this->_form;
$share = $this->_customdata['share'];
$mform->addElement('header', 'site', get_string('selecthub', 'hub'));
$mform->addElement('static', 'info', '', get_string('selecthubinfo', 'hub') . html_writer::empty_tag('br'));
$registrationmanager = new registration_manager();
$registeredhubs = $registrationmanager->get_registered_on_hubs();
//Public hub list
$options = array();
foreach ($registeredhubs as $hub) {
$hubname = $hub->hubname;
$mform->addElement('hidden', clean_param($hub->huburl, PARAM_ALPHANUMEXT), $hubname);
$mform->setType(clean_param($hub->huburl, PARAM_ALPHANUMEXT), PARAM_ALPHANUMEXT);
if (empty($hubname)) {
$hubname = $hub->huburl;
}
$mform->addElement('radio', 'huburl', null, ' ' . $hubname, $hub->huburl);
if ($hub->huburl == HUB_MOODLEORGHUBURL) {
$mform->setDefault('huburl', $hub->huburl);
}
}
$mform->addElement('hidden', 'id', $this->_customdata['id']);
$mform->setType('id', PARAM_INT);
if ($share) {
$buttonlabel = get_string('shareonhub', 'hub');
$mform->addElement('hidden', 'share', true);
$mform->setType('share', PARAM_BOOL);
} else {
$buttonlabel = get_string('advertiseonhub', 'hub');
$mform->addElement('hidden', 'advertise', true);
$mform->setType('advertise', PARAM_BOOL);
}
$this->add_action_buttons(false, $buttonlabel);
}
}
/*
* Course publication form
*/
class course_publication_form extends moodleform {
public function definition() {
global $CFG, $DB, $USER, $OUTPUT;
$strrequired = get_string('required');
$mform = & $this->_form;
$huburl = $this->_customdata['huburl'];
$hubname = $this->_customdata['hubname'];
$course = $this->_customdata['course'];
$advertise = $this->_customdata['advertise'];
$share = $this->_customdata['share'];
$page = $this->_customdata['page'];
$site = get_site();
//hidden parameters
$mform->addElement('hidden', 'huburl', $huburl);
$mform->setType('huburl', PARAM_URL);
$mform->addElement('hidden', 'hubname', $hubname);
$mform->setType('hubname', PARAM_TEXT);
//check on the hub if the course has already been published
$registrationmanager = new registration_manager();
$registeredhub = $registrationmanager->get_registeredhub($huburl);
$publicationmanager = new course_publish_manager();
$publications = $publicationmanager->get_publications($registeredhub->huburl, $course->id, $advertise);
if (!empty($publications)) {
//get the last publication of this course
$publication = array_pop($publications);
$function = 'hub_get_courses';
$options = new stdClass();
$options->ids = array($publication->hubcourseid);
$options->allsitecourses = 1;
$params = array('search' => '', 'downloadable' => $share,
'enrollable' => !$share, 'options' => $options);
$serverurl = $huburl . "/local/hub/webservice/webservices.php";
require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token);
try {
$result = $xmlrpcclient->call($function, $params);
$publishedcourses = $result['courses'];
} catch (Exception $e) {
$error = $OUTPUT->notification(get_string('errorcourseinfo', 'hub', $e->getMessage()));
$mform->addElement('static', 'errorhub', '', $error);
}
}
if (!empty($publishedcourses)) {
$publishedcourse = $publishedcourses[0];
$hubcourseid = $publishedcourse['id'];
$defaultfullname = $publishedcourse['fullname'];
$defaultshortname = $publishedcourse['shortname'];
$defaultsummary = $publishedcourse['description'];
$defaultlanguage = $publishedcourse['language'];
$defaultpublishername = $publishedcourse['publishername'];
$defaultpublisheremail = $publishedcourse['publisheremail'];
$defaultcontributornames = $publishedcourse['contributornames'];
$defaultcoverage = $publishedcourse['coverage'];
$defaultcreatorname = $publishedcourse['creatorname'];
$defaultlicenceshortname = $publishedcourse['licenceshortname'];
$defaultsubject = $publishedcourse['subject'];
$defaultaudience = $publishedcourse['audience'];
$defaulteducationallevel = $publishedcourse['educationallevel'];
$defaultcreatornotes = $publishedcourse['creatornotes'];
$defaultcreatornotesformat = $publishedcourse['creatornotesformat'];
$screenshotsnumber = $publishedcourse['screenshots'];
$privacy = $publishedcourse['privacy'];
if (($screenshotsnumber > 0) and !empty($privacy)) {
$page->requires->yui_module('moodle-block_community-imagegallery',
'M.blocks_community.init_imagegallery',
array(array('imageids' => array($hubcourseid),
'imagenumbers' => array($screenshotsnumber),
'huburl' => $huburl)));
}
} else {
$defaultfullname = $course->fullname;
$defaultshortname = $course->shortname;
$defaultsummary = clean_param($course->summary, PARAM_TEXT);
if (empty($course->lang)) {
$language = get_site()->lang;
if (empty($language)) {
$defaultlanguage = current_language();
} else {
$defaultlanguage = $language;
}
} else {
$defaultlanguage = $course->lang;
}
$defaultpublishername = $USER->firstname . ' ' . $USER->lastname;
$defaultpublisheremail = $USER->email;
$defaultcontributornames = '';
$defaultcoverage = '';
$defaultcreatorname = $USER->firstname . ' ' . $USER->lastname;
$defaultlicenceshortname = 'cc';
$defaultsubject = 'none';
$defaultaudience = HUB_AUDIENCE_STUDENTS;
$defaulteducationallevel = HUB_EDULEVEL_TERTIARY;
$defaultcreatornotes = '';
$defaultcreatornotesformat = FORMAT_HTML;
$screenshotsnumber = 0;
}
//the input parameters
$mform->addElement('header', 'moodle', get_string('publicationinfo', 'hub'));
$mform->addElement('text', 'name', get_string('coursename', 'hub'),
array('class' => 'metadatatext'));
$mform->addRule('name', $strrequired, 'required', null, 'client');
$mform->setType('name', PARAM_TEXT);
$mform->setDefault('name', $defaultfullname);
$mform->addHelpButton('name', 'name', 'hub');
$mform->addElement('hidden', 'id', $this->_customdata['id']);
$mform->setType('id', PARAM_INT);
if ($share) {
$buttonlabel = get_string('shareon', 'hub', !empty($hubname) ? $hubname : $huburl);
$mform->addElement('hidden', 'share', $share);
$mform->setType('share', PARAM_BOOL);
$mform->addElement('text', 'demourl', get_string('demourl', 'hub'),
array('class' => 'metadatatext'));
$mform->setType('demourl', PARAM_URL);
$mform->setDefault('demourl', new moodle_url("/course/view.php?id=" . $course->id));
$mform->addHelpButton('demourl', 'demourl', 'hub');
}
if ($advertise) {
if (empty($publishedcourses)) {
$buttonlabel = get_string('advertiseon', 'hub', !empty($hubname) ? $hubname : $huburl);
} else {
$buttonlabel = get_string('readvertiseon', 'hub', !empty($hubname) ? $hubname : $huburl);
}
$mform->addElement('hidden', 'advertise', $advertise);
$mform->setType('advertise', PARAM_BOOL);
$mform->addElement('hidden', 'courseurl', $CFG->wwwroot . "/course/view.php?id=" . $course->id);
$mform->setType('courseurl', PARAM_URL);
$mform->addElement('static', 'courseurlstring', get_string('courseurl', 'hub'));
$mform->setDefault('courseurlstring', new moodle_url("/course/view.php?id=" . $course->id));
$mform->addHelpButton('courseurlstring', 'courseurl', 'hub');
}
$mform->addElement('text', 'courseshortname', get_string('courseshortname', 'hub'),
array('class' => 'metadatatext'));
$mform->setDefault('courseshortname', $defaultshortname);
$mform->addHelpButton('courseshortname', 'courseshortname', 'hub');
$mform->setType('courseshortname', PARAM_TEXT);
$mform->addElement('textarea', 'description', get_string('description'), array('rows' => 10,
'cols' => 57));
$mform->addRule('description', $strrequired, 'required', null, 'client');
$mform->setDefault('description', $defaultsummary);
$mform->setType('description', PARAM_TEXT);
$mform->addHelpButton('description', 'description', 'hub');
$languages = get_string_manager()->get_list_of_languages();
core_collator::asort($languages);
$mform->addElement('select', 'language', get_string('language'), $languages);
$mform->setDefault('language', $defaultlanguage);
$mform->addHelpButton('language', 'language', 'hub');
$mform->addElement('text', 'publishername', get_string('publishername', 'hub'),
array('class' => 'metadatatext'));
$mform->setDefault('publishername', $defaultpublishername);
$mform->addRule('publishername', $strrequired, 'required', null, 'client');
$mform->addHelpButton('publishername', 'publishername', 'hub');
$mform->setType('publishername', PARAM_NOTAGS);
$mform->addElement('text', 'publisheremail', get_string('publisheremail', 'hub'),
array('class' => 'metadatatext'));
$mform->setDefault('publisheremail', $defaultpublisheremail);
$mform->addRule('publisheremail', $strrequired, 'required', null, 'client');
$mform->addHelpButton('publisheremail', 'publisheremail', 'hub');
$mform->setType('publisheremail', PARAM_EMAIL);
$mform->addElement('text', 'creatorname', get_string('creatorname', 'hub'),
array('class' => 'metadatatext'));
$mform->addRule('creatorname', $strrequired, 'required', null, 'client');
$mform->setType('creatorname', PARAM_NOTAGS);
$mform->setDefault('creatorname', $defaultcreatorname);
$mform->addHelpButton('creatorname', 'creatorname', 'hub');
$mform->addElement('text', 'contributornames', get_string('contributornames', 'hub'),
array('class' => 'metadatatext'));
$mform->setDefault('contributornames', $defaultcontributornames);
$mform->addHelpButton('contributornames', 'contributornames', 'hub');
$mform->setType('contributornames', PARAM_NOTAGS);
$mform->addElement('text', 'coverage', get_string('tags', 'hub'),
array('class' => 'metadatatext'));
$mform->setType('coverage', PARAM_TEXT);
$mform->setDefault('coverage', $defaultcoverage);
$mform->addHelpButton('coverage', 'tags', 'hub');
require_once($CFG->libdir . "/licenselib.php");
$licensemanager = new license_manager();
$licences = $licensemanager->get_licenses();
$options = array();
foreach ($licences as $license) {
$options[$license->shortname] = get_string($license->shortname, 'license');
}
$mform->addElement('select', 'licence', get_string('license'), $options);
$mform->setDefault('licence', $defaultlicenceshortname);
unset($options);
$mform->addHelpButton('licence', 'licence', 'hub');
$options = $publicationmanager->get_sorted_subjects();
$mform->addElement('searchableselector', 'subject',
get_string('subject', 'hub'), $options);
unset($options);
$mform->addHelpButton('subject', 'subject', 'hub');
$mform->setDefault('subject', $defaultsubject);
$mform->addRule('subject', $strrequired, 'required', null, 'client');
$options = array();
$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', 'hub'), $options);
$mform->setDefault('audience', $defaultaudience);
unset($options);
$mform->addHelpButton('audience', 'audience', 'hub');
$options = array();
$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', 'hub'), $options);
$mform->setDefault('educationallevel', $defaulteducationallevel);
unset($options);
$mform->addHelpButton('educationallevel', 'educationallevel', 'hub');
$editoroptions = array('maxfiles' => 0, 'maxbytes' => 0, 'trusttext' => false, 'forcehttps' => false);
$mform->addElement('editor', 'creatornotes', get_string('creatornotes', 'hub'), '', $editoroptions);
$mform->addRule('creatornotes', $strrequired, 'required', null, 'client');
$mform->setType('creatornotes', PARAM_CLEANHTML);
$mform->addHelpButton('creatornotes', 'creatornotes', 'hub');
if ($advertise) {
if (!empty($screenshotsnumber)) {
if (!empty($privacy)) {
$baseurl = new moodle_url($huburl . '/local/hub/webservice/download.php',
array('courseid' => $hubcourseid, 'filetype' => HUB_SCREENSHOT_FILE_TYPE));
$screenshothtml = html_writer::empty_tag('img',
array('src' => $baseurl, 'alt' => $defaultfullname));
$screenshothtml = html_writer::tag('div', $screenshothtml,
array('class' => 'coursescreenshot',
'id' => 'image-' . $hubcourseid));
} else {
$screenshothtml = get_string('existingscreenshotnumber', 'hub', $screenshotsnumber);
}
$mform->addElement('static', 'existingscreenshots', get_string('existingscreenshots', 'hub'), $screenshothtml);
$mform->addHelpButton('existingscreenshots', 'deletescreenshots', 'hub');
$mform->addElement('checkbox', 'deletescreenshots', '', ' ' . get_string('deletescreenshots', 'hub'));
}
$mform->addElement('hidden', 'existingscreenshotnumber', $screenshotsnumber);
$mform->setType('existingscreenshotnumber', PARAM_INT);
}
$mform->addElement('filemanager', 'screenshots', get_string('addscreenshots', 'hub'), null,
array('subdirs' => 0,
'maxbytes' => 1000000,
'maxfiles' => 3
));
$mform->addHelpButton('screenshots', 'screenshots', 'hub');
$this->add_action_buttons(false, $buttonlabel);
//set default value for creatornotes editor
$data = new stdClass();
$data->creatornotes = array();
$data->creatornotes['text'] = $defaultcreatornotes;
$data->creatornotes['format'] = $defaultcreatornotesformat;
$this->set_data($data);
}
function validation($data, $files) {
global $CFG;
$errors = array();
if ($this->_form->_submitValues['subject'] == 'none') {
$errors['subject'] = get_string('mustselectsubject', 'hub');
}
return $errors;
}
}
debugging('Support for alternative hubs has been removed from Moodle in 3.4. For communication with moodle.net ' .
'see lib/classes/hub/ .', DEBUG_DEVELOPER);
+1 -48
View File
@@ -26,52 +26,5 @@
require('../../config.php');
require_once($CFG->dirroot.'/' . $CFG->admin . '/registration/lib.php');
require_once($CFG->dirroot.'/course/publish/forms.php');
$id = required_param('id', PARAM_INT);
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
require_login($course);
$PAGE->set_url('/course/publish/hubselector.php', array('id' => $course->id));
$PAGE->set_pagelayout('incourse');
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
$PAGE->set_heading($course->fullname);
$registrationmanager = new registration_manager();
$registeredhubs = $registrationmanager->get_registered_on_hubs();
if (empty($registeredhubs)) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('publishon', 'hub'), 3, 'main');
echo $OUTPUT->box(get_string('notregisteredonhub', 'hub'));
echo $OUTPUT->footer();
die();
}
$share = optional_param('share', false, PARAM_BOOL);
$advertise = optional_param('advertise', false, PARAM_BOOL);
$hubselectorform = new hub_publish_selector_form('',
array('id' => $id, 'share' => $share, 'advertise' => $advertise));
$fromform = $hubselectorform->get_data();
//// Redirect to the registration form if an URL has been chosen ////
$huburl = optional_param('huburl', false, PARAM_URL);
//redirect
if (!empty($huburl) and confirm_sesskey()) {
$hubname = optional_param(clean_param($huburl, PARAM_ALPHANUMEXT), '', PARAM_TEXT);
$params = array('sesskey' => sesskey(), 'id' => $id,
'huburl' => $huburl, 'hubname' => $hubname, 'share' => $share, 'advertise' => $advertise);
redirect(new moodle_url($CFG->wwwroot."/course/publish/metadata.php",
$params));
}
//// OUTPUT ////
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('publishon', 'hub'), 3, 'main');
$hubselectorform->display();
echo $OUTPUT->footer();
redirect(new moodle_url('/course/publish/index.php', ['id' => $id]));
+50 -135
View File
@@ -27,155 +27,70 @@
*/
require('../../config.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
require_once($CFG->dirroot . '/course/publish/lib.php');
$id = required_param('id', PARAM_INT);
$hubname = optional_param('hubname', 0, PARAM_TEXT);
$huburl = optional_param('huburl', 0, PARAM_URL);
$courseid = required_param('id', PARAM_INT); // Course id.
$publicationid = optional_param('publicationid', 0, PARAM_INT); // Id of course publication to unpublish.
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
require_login($courseid);
$shortname = format_string($COURSE->shortname);
require_login($course);
$context = context_course::instance($course->id);
$shortname = format_string($course->shortname, true, array('context' => $context));
$PAGE->set_url('/course/publish/index.php', array('id' => $course->id));
$PAGE->set_url('/course/publish/index.php', array('id' => $courseid));
$PAGE->set_pagelayout('incourse');
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
$PAGE->set_heading($course->fullname);
$PAGE->set_title(get_string('publish') . ': ' . $COURSE->fullname);
$PAGE->set_heading($COURSE->fullname);
//check that the PHP xmlrpc extension is enabled
if (!extension_loaded('xmlrpc')) {
$notificationerror = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', '');
$notificationerror .= get_string('xmlrpcdisabledpublish', 'hub');
require_capability('moodle/course:publish', context_course::instance($courseid));
// If the site is not registered display an error page.
if (!\core\hub\registration::is_registered()) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main');
echo $OUTPUT->notification($notificationerror);
echo $OUTPUT->heading(get_string('publishcourseon', 'hub', 'Moodle.net'), 3, 'main');
echo $OUTPUT->box(get_string('notregisteredonhub', 'hub'));
if (has_capability('moodle/site:config', context_system::instance())) {
echo $OUTPUT->single_button(new moodle_url('/admin/registration/index.php'), get_string('register', 'admin'));
}
echo $OUTPUT->footer();
die();
}
if (has_capability('moodle/course:publish', context_course::instance($id))) {
$publicationmanager = new course_publish_manager();
$confirmmessage = '';
//update the courses status
$updatestatusid = optional_param('updatestatusid', false, PARAM_INT);
if (!empty($updatestatusid) and confirm_sesskey()) {
//get the communication token from the publication
$hub = $publicationmanager->get_registeredhub_by_publication($updatestatusid);
if (empty($hub)) {
$confirmmessage = $OUTPUT->notification(get_string('nocheckstatusfromunreghub', 'hub'));
} else {
//get all site courses registered on this hub
$function = 'hub_get_courses';
$params = array('search' => '', 'downloadable' => 1,
'enrollable' => 1, 'options' => array( 'allsitecourses' => 1));
$serverurl = $hub->huburl."/local/hub/webservice/webservices.php";
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token);
$result = $xmlrpcclient->call($function, $params);
$sitecourses = $result['courses'];
//update status for all these course
foreach ($sitecourses as $sitecourse) {
//get the publication from the hub course id
$publication = $publicationmanager->get_publication($sitecourse['id'], $hub->huburl);
if (!empty($publication)) {
$publication->status = $sitecourse['privacy'];
$publication->timechecked = time();
$publicationmanager->update_publication($publication);
} else {
$msgparams = new stdClass();
$msgparams->id = $sitecourse['id'];
$msgparams->hubname = html_writer::tag('a', $hub->hubname, array('href' => $hub->huburl));
$confirmmessage .= $OUTPUT->notification(
get_string('detectednotexistingpublication', 'hub', $msgparams));
}
}
}
// When hub listing status is requested update statuses of all published courses.
$updatestatusid = optional_param('updatestatusid', false, PARAM_INT);
if (!empty($updatestatusid) && confirm_sesskey()) {
if (core\hub\publication::get_publication($updatestatusid, $courseid)) {
core\hub\publication::request_status_update();
redirect($PAGE->url);
}
}
//if the site os registered on no hub display an error page
$registrationmanager = new registration_manager();
$registeredhubs = $registrationmanager->get_registered_on_hubs();
if (empty($registeredhubs)) {
$renderer = $PAGE->get_renderer('core', 'publish');
// Unpublish course.
if ($publication = \core\hub\publication::get_publication($publicationid, $courseid)) {
$confirm = optional_param('confirm', 0, PARAM_BOOL);
if ($confirm && confirm_sesskey()) {
\core\hub\publication::unpublish($publication);
} else {
// Display confirmation page for unpublishing.
$publication = \core\hub\publication::get_publication($publicationid, $courseid, MUST_EXIST);
$publication->courseshortname = format_string($COURSE->shortname);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('publishon', 'hub'), 3, 'main');
echo $OUTPUT->box(get_string('notregisteredonhub', 'hub'));
echo $OUTPUT->heading(get_string('unpublishcourse', 'hub', $shortname), 3, 'main');
echo $renderer->confirmunpublishing($publication);
echo $OUTPUT->footer();
die();
}
$renderer = $PAGE->get_renderer('core', 'publish');
/// UNPUBLISH
$cancel = optional_param('cancel', 0, PARAM_BOOL);
if (!empty($cancel) and confirm_sesskey()) {
$confirm = optional_param('confirm', 0, PARAM_BOOL);
$hubcourseid = optional_param('hubcourseid', 0, PARAM_INT);
$publicationid = optional_param('publicationid', 0, PARAM_INT);
$timepublished = optional_param('timepublished', 0, PARAM_INT);
$publication = new stdClass();
$publication->courseshortname = $course->shortname;
$publication->courseid = $course->id;
$publication->hubname = $hubname;
$publication->huburl = $huburl;
$publication->hubcourseid = $hubcourseid;
$publication->timepublished = $timepublished;
if (empty($publication->hubname)) {
$publication->hubname = $huburl;
}
$publication->id = $publicationid;
if($confirm) {
//unpublish the publication by web service
$registeredhub = $registrationmanager->get_registeredhub($huburl);
$function = 'hub_unregister_courses';
$params = array('courseids' => array( $publication->hubcourseid));
$serverurl = $huburl."/local/hub/webservice/webservices.php";
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token);
$result = $xmlrpcclient->call($function, $params);
//delete the publication from the database
$publicationmanager->delete_publication($publicationid);
//display confirmation message
$confirmmessage = $OUTPUT->notification(get_string('courseunpublished', 'hub', $publication), 'notifysuccess');
} else {
//display confirmation page for unpublishing
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('unpublishcourse', 'hub', $shortname), 3, 'main');
echo $renderer->confirmunpublishing($publication);
echo $OUTPUT->footer();
die();
}
}
//check if a course was published
if (optional_param('published', 0, PARAM_TEXT)) {
$confirmmessage = $OUTPUT->notification(get_string('coursepublished', 'hub',
empty($hubname)?$huburl:$hubname), 'notifysuccess');
}
/// OUTPUT
echo $OUTPUT->header();
echo $confirmmessage;
echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main');
echo $renderer->publicationselector($course->id);
$publications = $publicationmanager->get_course_publications($course->id);
if (!empty($publications)) {
echo $OUTPUT->heading(get_string('publishedon', 'hub'), 3, 'main');
echo $renderer->registeredonhublisting($course->id, $publications);
}
echo $OUTPUT->footer();
}
// List current publications and "Publish" buttons.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main');
echo $renderer->publicationselector($courseid);
$publications = \core\hub\publication::get_course_publications($courseid);
if (!empty($publications)) {
echo $OUTPUT->heading(get_string('publishedon', 'hub'), 3, 'main');
echo $renderer->registeredonhublisting($courseid, $publications);
}
echo $OUTPUT->footer();
+1 -267
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -14,270 +13,5 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/// TIME PERIOD ///
define('HUB_LASTMODIFIED_WEEK', 7);
define('HUB_LASTMODIFIED_FORTEENNIGHT', 14);
define('HUB_LASTMODIFIED_MONTH', 30);
//// AUDIENCE ////
/**
* Audience: educators
*/
define('HUB_AUDIENCE_EDUCATORS', 'educators');
/**
* Audience: students
*/
define('HUB_AUDIENCE_STUDENTS', 'students');
/**
* Audience: admins
*/
define('HUB_AUDIENCE_ADMINS', 'admins');
///// EDUCATIONAL LEVEL /////
/**
* Educational level: primary
*/
define('HUB_EDULEVEL_PRIMARY', 'primary');
/**
* Educational level: secondary
*/
define('HUB_EDULEVEL_SECONDARY', 'secondary');
/**
* Educational level: tertiary
*/
define('HUB_EDULEVEL_TERTIARY', 'tertiary');
/**
* Educational level: government
*/
define('HUB_EDULEVEL_GOVERNMENT', 'government');
/**
* Educational level: association
*/
define('HUB_EDULEVEL_ASSOCIATION', 'association');
/**
* Educational level: corporate
*/
define('HUB_EDULEVEL_CORPORATE', 'corporate');
/**
* Educational level: other
*/
define('HUB_EDULEVEL_OTHER', 'other');
///// FILE TYPES /////
/**
* FILE TYPE: COURSE SCREENSHOT
*/
define('HUB_SCREENSHOT_FILE_TYPE', 'screenshot');
/**
* FILE TYPE: HUB SCREENSHOT
*/
define('HUB_HUBSCREENSHOT_FILE_TYPE', 'hubscreenshot');
/**
* FILE TYPE: BACKUP
*/
define('HUB_BACKUP_FILE_TYPE', 'backup');
/**
*
* Course publication library
*
* @package course
* @copyright 2010 Moodle Pty Ltd (http://moodle.com)
* @author Jerome Mouneyrac
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_publish_manager {
/**
* Record a course publication
* @param int $hubid the hub id from the 'registered on hub' table
* @param int $courseid the course id from site point of view
* @param int $enrollable if the course is enrollable = 1, if downloadable = 0
* @param int $hubcourseid the course id from the hub point of view
*/
public function add_course_publication($huburl, $courseid, $enrollable, $hubcourseid) {
global $DB;
$publication = new stdClass();
$publication->huburl = $huburl;
$publication->courseid = $courseid;
$publication->hubcourseid = $hubcourseid;
$publication->enrollable = (int) $enrollable;
$publication->timepublished = time();
$DB->insert_record('course_published', $publication);
}
/**
* Update a enrollable course publication
* @param int $publicationid
*/
public function update_enrollable_course_publication($publicationid) {
global $DB;
$publication = new stdClass();
$publication->id = $publicationid;
$publication->timepublished = time();
$DB->update_record('course_published', $publication);
}
/**
* Update a course publication
* @param object $publication
*/
public function update_publication($publication) {
global $DB;
$DB->update_record('course_published', $publication);
}
/**
* Get courses publications
* @param int $hubid specify a hub
* @param int $courseid specify a course
* @param int $enrollable specify type of publication (enrollable or downloadable)
* @return array of publications
*/
public function get_publications($huburl = null, $courseid = null, $enrollable = -1) {
global $DB;
$params = array();
if (!empty($huburl)) {
$params['huburl'] = $huburl;
}
if (!empty($courseid)) {
$params['courseid'] = $courseid;
}
if ($enrollable != -1) {
$params['enrollable'] = (int) $enrollable;
}
return $DB->get_records('course_published', $params);
}
/**
* Get a publication for a course id on a hub
* (which is either the id of the unique possible enrollable publication of a course,
* either an id of one of the downloadable publication)
* @param int $hubcourseid
* @param string $huburl
* @return object publication
*/
public function get_publication($hubcourseid, $huburl) {
global $DB;
return $DB->get_record('course_published',
array('hubcourseid' => $hubcourseid, 'huburl' => $huburl));
}
/**
* Get all publication for a course
* @param int $courseid
* @return array of publication
*/
public function get_course_publications($courseid) {
global $DB;
$sql = 'SELECT cp.id, cp.status, cp.timechecked, cp.timepublished, rh.hubname,
rh.huburl, cp.courseid, cp.enrollable, cp.hubcourseid
FROM {course_published} cp, {registration_hubs} rh
WHERE cp.huburl = rh.huburl and cp.courseid = :courseid
ORDER BY cp.enrollable DESC, rh.hubname, cp.timepublished';
$params = array('courseid' => $courseid);
return $DB->get_records_sql($sql, $params);
}
/**
* Get the hub concerned by a publication
* @param int $publicationid
* @return object the hub (id, name, url, token)
*/
public function get_registeredhub_by_publication($publicationid) {
global $DB;
$sql = 'SELECT rh.huburl, rh.hubname, rh.token
FROM {course_published} cp, {registration_hubs} rh
WHERE cp.huburl = rh.huburl and cp.id = :publicationid';
$params = array('publicationid' => $publicationid);
return $DB->get_record_sql($sql, $params);
}
/**
* Delete a publication
* @param int $publicationid
*/
public function delete_publication($publicationid) {
global $DB;
$DB->delete_records('course_published', array('id' => $publicationid));
}
/**
* Delete publications for a hub
* @param string $huburl
* @param int $enrollable
*/
public function delete_hub_publications($huburl, $enrollable = -1) {
global $DB;
$params = array();
if (!empty($huburl)) {
$params['huburl'] = $huburl;
}
if ($enrollable != -1) {
$params['enrollable'] = (int) $enrollable;
}
$DB->delete_records('course_published', $params);
}
/**
* Get an array of all block instances for a given context
* @param int $contextid a context id
* @return array of block instances.
*/
public function get_block_instances_by_context($contextid, $sort = '') {
global $DB;
return $DB->get_records('block_instances', array('parentcontextid' => $contextid), $sort);
}
/**
* Retrieve all the sorted course subjects
* @return array $subjects
*/
public function get_sorted_subjects() {
$subjects = get_string_manager()->load_component_strings('edufields', current_language());
// Sort the subjects.
$return = [];
asort($subjects);
foreach ($subjects as $key => $option) {
$keylength = strlen($key);
if ($keylength == 12) {
$return[$key] = $option; // We want only selectable categories.
}
}
return $return;
}
}
defined('MOODLE_INTERNAL') || die();
+123 -208
View File
@@ -31,9 +31,6 @@
*/
require_once('../../config.php');
require_once($CFG->dirroot . '/course/publish/forms.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
require_once($CFG->dirroot . '/course/publish/lib.php');
require_once($CFG->libdir . '/filelib.php');
@@ -49,226 +46,144 @@ $PAGE->set_pagelayout('incourse');
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
$PAGE->set_heading($course->fullname);
//check that the PHP xmlrpc extension is enabled
if (!extension_loaded('xmlrpc')) {
$errornotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', '');
$errornotification .= get_string('xmlrpcdisabledpublish', 'hub');
$context = context_course::instance($course->id);
$shortname = format_string($course->shortname, true, array('context' => $context));
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main');
echo $OUTPUT->notification($errornotification);
echo $OUTPUT->footer();
die();
require_capability('moodle/course:publish', context_course::instance($id));
// Retrieve hub name and hub url.
require_sesskey();
// Set the publication form.
$advertise = optional_param('advertise', false, PARAM_BOOL);
$publicationid = optional_param('publicationid', false, PARAM_INT);
$formparams = array('course' => $course, 'advertise' => $advertise);
if ($publicationid) {
$publication = \core\hub\publication::get_publication($publicationid, $course->id, MUST_EXIST);
$formparams['publication'] = $publication;
$advertise = $formparams['advertise'] = $publication->enrollable;
}
$share = !$advertise;
$coursepublicationform = new \core\hub\course_publication_form('', $formparams);
$fromform = $coursepublicationform->get_data();
if (has_capability('moodle/course:publish', context_course::instance($id))) {
if (!empty($fromform)) {
//retrieve hub name and hub url
$huburl = optional_param('huburl', '', PARAM_URL);
$hubname = optional_param('hubname', '', PARAM_TEXT);
if (empty($huburl) or !confirm_sesskey()) {
throw new moodle_exception('missingparameter');
// Retrieve the course information.
$courseinfo = new stdClass();
$courseinfo->fullname = $fromform->name;
$courseinfo->shortname = $fromform->courseshortname;
$courseinfo->description = $fromform->description;
$courseinfo->language = $fromform->language;
$courseinfo->publishername = $fromform->publishername;
$courseinfo->publisheremail = $fromform->publisheremail;
$courseinfo->contributornames = $fromform->contributornames;
$courseinfo->coverage = $fromform->coverage;
$courseinfo->creatorname = $fromform->creatorname;
$courseinfo->licenceshortname = $fromform->licence;
$courseinfo->subject = $fromform->subject;
$courseinfo->audience = $fromform->audience;
$courseinfo->educationallevel = $fromform->educationallevel;
$creatornotes = $fromform->creatornotes;
$courseinfo->creatornotes = $creatornotes['text'];
$courseinfo->creatornotesformat = $creatornotes['format'];
$courseinfo->sitecourseid = $id;
if (!empty($fromform->deletescreenshots)) {
$courseinfo->deletescreenshots = $fromform->deletescreenshots;
}
if ($share) {
$courseinfo->demourl = $fromform->demourl;
$courseinfo->enrollable = false;
} else {
$courseinfo->courseurl = $fromform->courseurl;
$courseinfo->enrollable = true;
}
//set the publication form
$advertise = optional_param('advertise', false, PARAM_BOOL);
$share = optional_param('share', false, PARAM_BOOL);
$coursepublicationform = new course_publication_form('',
array('huburl' => $huburl, 'hubname' => $hubname, 'sesskey' => sesskey(),
'course' => $course, 'advertise' => $advertise, 'share' => $share,
'id' => $id, 'page' => $PAGE));
$fromform = $coursepublicationform->get_data();
//retrieve the token to call the hub
$registrationmanager = new registration_manager();
$registeredhub = $registrationmanager->get_registeredhub($huburl);
//setup web service xml-rpc client
$serverurl = $huburl . "/local/hub/webservice/webservices.php";
require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token);
if (!empty($fromform)) {
$publicationmanager = new course_publish_manager();
//retrieve the course information
$courseinfo = new stdClass();
$courseinfo->fullname = $fromform->name;
$courseinfo->shortname = $fromform->courseshortname;
$courseinfo->description = $fromform->description;
$courseinfo->language = $fromform->language;
$courseinfo->publishername = $fromform->publishername;
$courseinfo->publisheremail = $fromform->publisheremail;
$courseinfo->contributornames = $fromform->contributornames;
$courseinfo->coverage = $fromform->coverage;
$courseinfo->creatorname = $fromform->creatorname;
$courseinfo->licenceshortname = $fromform->licence;
$courseinfo->subject = $fromform->subject;
$courseinfo->audience = $fromform->audience;
$courseinfo->educationallevel = $fromform->educationallevel;
$creatornotes = $fromform->creatornotes;
$courseinfo->creatornotes = $creatornotes['text'];
$courseinfo->creatornotesformat = $creatornotes['format'];
$courseinfo->sitecourseid = $id;
if (!empty($fromform->deletescreenshots)) {
$courseinfo->deletescreenshots = $fromform->deletescreenshots;
}
if ($share) {
$courseinfo->demourl = $fromform->demourl;
$courseinfo->enrollable = false;
} else {
$courseinfo->courseurl = $fromform->courseurl;
$courseinfo->enrollable = true;
// Retrieve the outcomes of this course.
require_once($CFG->libdir . '/grade/grade_outcome.php');
$outcomes = grade_outcome::fetch_all_available($id);
if (!empty($outcomes)) {
foreach ($outcomes as $outcome) {
$sentoutcome = new stdClass();
$sentoutcome->fullname = $outcome->fullname;
$courseinfo->outcomes[] = $sentoutcome;
}
}
//retrieve the outcomes of this course
require_once($CFG->libdir . '/grade/grade_outcome.php');
$outcomes = grade_outcome::fetch_all_available($id);
if (!empty($outcomes)) {
foreach ($outcomes as $outcome) {
$sentoutcome = new stdClass();
$sentoutcome->fullname = $outcome->fullname;
$courseinfo->outcomes[] = $sentoutcome;
}
}
// Retrieve the content information from the course.
$coursecontext = context_course::instance($course->id);
$courseblocks = \core\hub\publication::get_block_instances_by_context($coursecontext->id);
//retrieve the content information from the course
$coursecontext = context_course::instance($course->id);
$courseblocks = $publicationmanager->get_block_instances_by_context($coursecontext->id, 'blockname');
if (!empty($courseblocks)) {
$blockname = '';
foreach ($courseblocks as $courseblock) {
if ($courseblock->blockname != $blockname) {
if (!empty($blockname)) {
$courseinfo->contents[] = $content;
}
$blockname = $courseblock->blockname;
$content = new stdClass();
$content->moduletype = 'block';
$content->modulename = $courseblock->blockname;
$content->contentcount = 1;
} else {
$content->contentcount = $content->contentcount + 1;
if (!empty($courseblocks)) {
$blockname = '';
foreach ($courseblocks as $courseblock) {
if ($courseblock->blockname != $blockname) {
if (!empty($blockname)) {
$courseinfo->contents[] = $content;
}
}
$courseinfo->contents[] = $content;
}
$activities = get_fast_modinfo($course, $USER->id);
foreach ($activities->instances as $activityname => $activitydetails) {
$content = new stdClass();
$content->moduletype = 'activity';
$content->modulename = $activityname;
$content->contentcount = count($activities->instances[$activityname]);
$courseinfo->contents[] = $content;
}
//save into screenshots field the references to the screenshot content hash
//(it will be like a unique id from the hub perspective)
if (!empty($fromform->deletescreenshots) or $share) {
$courseinfo->screenshots = 0;
} else {
$courseinfo->screenshots = $fromform->existingscreenshotnumber;
}
if (!empty($fromform->screenshots)) {
$screenshots = $fromform->screenshots;
$fs = get_file_storage();
$files = $fs->get_area_files(context_user::instance($USER->id)->id, 'user', 'draft', $screenshots);
if (!empty($files)) {
$courseinfo->screenshots = $courseinfo->screenshots + count($files) - 1; //minus the ./ directory
}
}
// PUBLISH ACTION
//publish the course information
$function = 'hub_register_courses';
$params = array('courses' => array($courseinfo));
try {
$courseids = $xmlrpcclient->call($function, $params);
} catch (Exception $e) {
throw new moodle_exception('errorcoursepublish', 'hub',
new moodle_url('/course/view.php', array('id' => $id)), $e->getMessage());
}
if (count($courseids) != 1) {
throw new moodle_exception('errorcoursewronglypublished', 'hub');
}
//save the record into the published course table
$publication = $publicationmanager->get_publication($courseids[0], $huburl);
if (empty($publication)) {
//if never been published or if we share, we need to save this new publication record
$publicationmanager->add_course_publication($registeredhub->huburl, $course->id, !$share, $courseids[0]);
} else {
//if we update the enrollable course publication we update the publication record
$publicationmanager->update_enrollable_course_publication($publication->id);
}
// SEND FILES
$curl = new curl();
// send screenshots
if (!empty($fromform->screenshots)) {
if (!empty($fromform->deletescreenshots) or $share) {
$screenshotnumber = 0;
$blockname = $courseblock->blockname;
$content = new stdClass();
$content->moduletype = 'block';
$content->modulename = $courseblock->blockname;
$content->contentcount = 1;
} else {
$screenshotnumber = $fromform->existingscreenshotnumber;
}
foreach ($files as $file) {
if ($file->is_valid_image()) {
$screenshotnumber = $screenshotnumber + 1;
$params = array();
$params['filetype'] = HUB_SCREENSHOT_FILE_TYPE;
$params['file'] = $file;
$params['courseid'] = $courseids[0];
$params['filename'] = $file->get_filename();
$params['screenshotnumber'] = $screenshotnumber;
$params['token'] = $registeredhub->token;
$curl->post($huburl . "/local/hub/webservice/upload.php", $params);
}
$content->contentcount = $content->contentcount + 1;
}
}
//redirect to the backup process page
if ($share) {
$params = array('sesskey' => sesskey(), 'id' => $id, 'hubcourseid' => $courseids[0],
'huburl' => $huburl, 'hubname' => $hubname);
$backupprocessurl = new moodle_url("/course/publish/backup.php", $params);
redirect($backupprocessurl);
} else {
//redirect to the index publis page
redirect(new moodle_url('/course/publish/index.php',
array('sesskey' => sesskey(), 'id' => $id, 'published' => true,
'hubname' => $hubname, 'huburl' => $huburl)));
}
$courseinfo->contents[] = $content;
}
/////// OUTPUT SECTION /////////////
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('publishcourseon', 'hub', !empty($hubname) ? $hubname : $huburl), 3, 'main');
//display hub information (logo, name, description)
$function = 'hub_get_info';
$params = array();
try {
$hubinfo = $xmlrpcclient->call($function, $params);
} catch (Exception $e) {
//only print error log in apache (for backward compatibility)
error_log(print_r($e->getMessage(), true));
}
$renderer = $PAGE->get_renderer('core', 'publish');
if (!empty($hubinfo)) {
echo $renderer->hubinfo($hubinfo);
$activities = get_fast_modinfo($course, $USER->id);
foreach ($activities->instances as $activityname => $activitydetails) {
$content = new stdClass();
$content->moduletype = 'activity';
$content->modulename = $activityname;
$content->contentcount = count($activities->instances[$activityname]);
$courseinfo->contents[] = $content;
}
//display metadata form
$coursepublicationform->display();
echo $OUTPUT->footer();
// Save into screenshots field the references to the screenshot content hash
// (it will be like a unique id from the hub perspective).
if (!empty($fromform->deletescreenshots) or $share) {
$courseinfo->screenshots = 0;
} else {
$courseinfo->screenshots = $fromform->existingscreenshotnumber;
}
$files = [];
if (!empty($fromform->screenshots)) {
$fs = get_file_storage();
$files = $fs->get_area_files(context_user::instance($USER->id)->id, 'user', 'draft', $fromform->screenshots,
'filepath, filename', false);
$files = array_filter($files, function(stored_file $file) {
return $file->is_valid_image();
});
$courseinfo->screenshots += count($files);
}
// PUBLISH ACTION.
$hubcourseid = \core\hub\publication::publish_course($courseinfo, $files);
// Redirect to the backup process page.
if ($share) {
$params = array('sesskey' => sesskey(), 'id' => $id, 'hubcourseid' => $hubcourseid);
$backupprocessurl = new moodle_url("/course/publish/backup.php", $params);
redirect($backupprocessurl);
} else {
// Redirect to the index publis page.
redirect(new moodle_url('/course/publish/index.php', ['id' => $id]),
get_string('coursepublished', 'hub', 'Moodle.net'), null, \core\output\notification::NOTIFY_SUCCESS);
}
}
// OUTPUT SECTION.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('publishcourseon', 'hub', 'Moodle.net'), 3, 'main');
// Display hub information (logo, name, description).
$renderer = $PAGE->get_renderer('core', 'publish');
if ($hubinfo = \core\hub\registration::get_moodlenet_info()) {
echo $renderer->hubinfo($hubinfo);
}
// Display metadata form.
$coursepublicationform->display();
echo $OUTPUT->footer();
+17 -31
View File
@@ -36,7 +36,7 @@ class core_publish_renderer extends plugin_renderer_base {
public function publicationselector($courseid) {
$text = '';
$advertiseurl = new moodle_url("/course/publish/hubselector.php",
$advertiseurl = new moodle_url("/course/publish/metadata.php",
array('sesskey' => sesskey(), 'id' => $courseid, 'advertise' => true));
$advertisebutton = new single_button($advertiseurl, get_string('advertise', 'hub'));
$text .= $this->output->render($advertisebutton);
@@ -45,7 +45,7 @@ class core_publish_renderer extends plugin_renderer_base {
$text .= html_writer::empty_tag('br'); /// TODO Delete
$uploadurl = new moodle_url("/course/publish/hubselector.php",
$uploadurl = new moodle_url("/course/publish/metadata.php",
array('sesskey' => sesskey(), 'id' => $courseid, 'share' => true));
$uploadbutton = new single_button($uploadurl, get_string('share', 'hub'));
$text .= $this->output->render($uploadbutton);
@@ -61,30 +61,22 @@ class core_publish_renderer extends plugin_renderer_base {
public function registeredonhublisting($courseid, $publications) {
global $CFG;
$table = new html_table();
$table->head = array(get_string('type', 'hub'), get_string('hub', 'hub'),
$table->head = array(get_string('type', 'hub'),
get_string('date'), get_string('status', 'hub'), get_string('operation', 'hub'));
$table->size = array('10%', '40%', '20%', '%10', '%15');
$table->size = array('20%', '30%', '%20', '%25');
$brtag = html_writer::empty_tag('br');
foreach ($publications as $publication) {
$updatebuttonhtml = '';
$params = array('sesskey' => sesskey(), 'id' => $publication->courseid,
'hubcourseid' => $publication->hubcourseid,
'huburl' => $publication->huburl, 'hubname' => $publication->hubname,
'cancel' => true, 'publicationid' => $publication->id,
'timepublished' => $publication->timepublished);
$params = array('id' => $publication->courseid, 'publicationid' => $publication->id);
$cancelurl = new moodle_url("/course/publish/index.php", $params);
$cancelbutton = new single_button($cancelurl, get_string('removefromhub', 'hub'));
$cancelbutton->class = 'centeredbutton';
$cancelbuttonhtml = $this->output->render($cancelbutton);
if ($publication->enrollable) {
$params = array('sesskey' => sesskey(), 'id' => $publication->courseid,
'huburl' => $publication->huburl, 'hubname' => $publication->hubname,
'share' => !$publication->enrollable, 'advertise' => $publication->enrollable);
$params = array('sesskey' => sesskey(), 'id' => $publication->courseid, 'publicationid' => $publication->id);
$updateurl = new moodle_url("/course/publish/metadata.php", $params);
$updatebutton = new single_button($updateurl, get_string('update', 'hub'));
$updatebutton->class = 'centeredbutton';
@@ -95,15 +87,15 @@ class core_publish_renderer extends plugin_renderer_base {
$operations = $cancelbuttonhtml;
}
$hubname = html_writer::tag('a',
$publication->hubname ? $publication->hubname : $publication->huburl,
array('href' => $publication->huburl));
//if the publication check time if bigger than May 2010, it has been checked
if ($publication->timechecked > 1273127954) {
if ($publication->status == 0) {
$status = get_string('statusunpublished', 'hub');
} else {
$status = get_string('statuspublished', 'hub');
if (!empty($publication->link)) {
$status = html_writer::link($publication->link, $status);
}
}
$status .= $brtag . html_writer::tag('a', get_string('updatestatus', 'hub'),
@@ -122,7 +114,7 @@ class core_publish_renderer extends plugin_renderer_base {
//add button cells
$cells = array($publication->enrollable ?
get_string('advertised', 'hub') : get_string('shared', 'hub'),
$hubname, userdate($publication->timepublished,
userdate($publication->timepublished,
get_string('strftimedatetimeshort')), $status, $operations);
$row = new html_table_row($cells);
$table->data[] = $row;
@@ -145,11 +137,10 @@ class core_publish_renderer extends plugin_renderer_base {
public function confirmunpublishing($publication) {
$optionsyes = array('sesskey' => sesskey(), 'id' => $publication->courseid,
'hubcourseid' => $publication->hubcourseid,
'huburl' => $publication->huburl, 'hubname' => $publication->hubname,
'cancel' => true, 'publicationid' => $publication->id, 'confirm' => true);
$optionsno = array('sesskey' => sesskey(), 'id' => $publication->courseid);
$publication->hubname = html_writer::tag('a', $publication->hubname,
array('href' => $publication->huburl));
$publication->hubname = html_writer::tag('a', 'Moodle.net',
array('href' => HUB_MOODLEORGHUBURL));
$formcontinue = new single_button(new moodle_url("/course/publish/index.php",
$optionsyes), get_string('unpublish', 'hub'), 'post');
$formcancel = new single_button(new moodle_url("/course/publish/index.php",
@@ -174,18 +165,16 @@ class core_publish_renderer extends plugin_renderer_base {
/**
* Display upload successfull message and a button to the publish index page
* @param int $id the course id
* @param string $huburl the hub url where the course is published
* @param string $hubname the hub name where the course is published
* @return $html string
*/
public function sentbackupinfo($id, $huburl, $hubname) {
public function sentbackupinfo($id) {
$html = html_writer::tag('div', get_string('sent', 'hub'),
array('class' => 'courseuploadtextinfo'));
$publishindexurl = new moodle_url('/course/publish/index.php',
array('sesskey' => sesskey(), 'id' => $id,
'published' => true, 'huburl' => $huburl, 'hubname' => $hubname));
'published' => true));
$continue = $this->output->render(
new single_button($publishindexurl, get_string('continue', 'hub')));
new single_button($publishindexurl, get_string('continue')));
$html .= html_writer::tag('div', $continue, array('class' => 'sharecoursecontinue'));
return $html;
}
@@ -196,11 +185,8 @@ class core_publish_renderer extends plugin_renderer_base {
* @return string html code
*/
public function hubinfo($hubinfo) {
$params = array('filetype' => HUB_HUBSCREENSHOT_FILE_TYPE);
$imgurl = new moodle_url($hubinfo['url'] .
"/local/hub/webservice/download.php", $params);
$screenshothtml = html_writer::empty_tag('img',
array('src' => $imgurl, 'alt' => $hubinfo['name']));
array('src' => $hubinfo['imgurl'], 'alt' => $hubinfo['name']));
$hubdescription = html_writer::tag('div', $screenshothtml,
array('class' => 'hubscreenshot'));
@@ -210,7 +196,7 @@ class core_publish_renderer extends plugin_renderer_base {
$hubdescription .= html_writer::tag('div', format_text($hubinfo['description'], FORMAT_PLAIN),
array('class' => 'hubdescription'));
$hubdescription = html_writer::tag('div', $hubdescription, array('class' => 'hubinfo'));
$hubdescription = html_writer::tag('div', $hubdescription, array('class' => 'hubinfo clearfix'));
return $hubdescription;
}
+4 -3
View File
@@ -602,7 +602,6 @@ $string['htmleditorsettings'] = 'HTML editor settings';
$string['htmlsettings'] = 'HTML settings';
$string['http'] = 'HTTP';
$string['httpsecurity'] = 'HTTP security';
$string['hubs'] = 'Hubs';
$string['incompleteunicodesupport'] = 'The current setup of MySQL or MariaDB is using \'utf8\'. This character set does not support four byte characters which include some emoji. Trying to use these characters will result in an error when updating a record, and any information being sent to the database will be lost. Please consider changing your settings to \'utf8mb4\'. See the documentation for full details.';
$string['change'] = 'change';
$string['checkboxno'] = 'No';
@@ -740,7 +739,6 @@ $string['messaging'] = 'Enable messaging system';
$string['messagingallowemailoverride'] = 'Notification email override';
$string['messaginghidereadnotifications'] = 'Hide read notifications';
$string['messagingdeletereadnotificationsdelay'] = 'Delete read notifications';
$string['moodleorghubname'] = 'Moodle.net';
$string['minpassworddigits'] = 'Digits';
$string['minpasswordlength'] = 'Password length';
$string['minpasswordlower'] = 'Lowercase letters';
@@ -1249,7 +1247,7 @@ $string['warningcurrentsetting'] = 'Invalid current value: {$a}';
$string['warningiconvbuggy'] = 'Your version of the iconv library does not support the //IGNORE modifier. You should install the mbstring extension which can be used instead for cleaning strings containing invalid UTF-8 characters.';
$string['webproxy'] = 'Web proxy';
$string['webproxyinfo'] = 'Fill in following options if your Moodle server can not access internet directly. Internet access is required for download of environment data, language packs, RSS feeds, timezones, etc.<br /><em>PHP cURL extension is highly recommended.</em>';
$string['xmlrpcrecommended'] = 'The xmlrpc extension is needed for hub communication, and useful for web services and Moodle networking';
$string['xmlrpcrecommended'] = 'The xmlrpc extension is useful for web services and Moodle networking';
$string['yuicomboloading'] = 'YUI combo loading';
$string['ziprequired'] = 'The Zip PHP extension is now required by Moodle, info-ZIP binaries or PclZip library are not used anymore.';
@@ -1268,3 +1266,6 @@ $string['mobile'] = 'Mobile';
$string['loginpasswordautocomplete'] = 'Prevent password autocompletion on login form';
$string['loginpasswordautocomplete_help'] = 'If enabled, users are not allowed to save their account password in their browser.';
$string['unoconvwarning'] = 'The version of unoconv you have installed is not supported.';
// Deprecated since Moodle 3.4
$string['moodleorghubname'] = 'Moodle.net';
$string['hubs'] = 'Hubs';
+73
View File
@@ -79,3 +79,76 @@ showcourseevents,core_calendar
showglobalevents,core_calendar
showgroupsevents,core_calendar
showuserevents,core_calendar
errorcronnoxmlrpc,core_hub
advertiseonhub,core_hub
advertiseonmoodleorg,core_hub
all,core_hub
allowglobalsearch,core_hub
allowpublicsearch,core_hub
badurlformat,core_hub
community,core_hub
cannotsearchcommunity,core_hub
contactable,core_hub
contactable_help,core_hub
contactemail,core_hub
contactname,core_hub
contactphone,core_hub
contactphone_help,core_hub
continue,core_hub
coursemap,core_hub
courseprivate,core_hub
coursepublic,core_hub
errorcron,core_hub
errorhublisting,core_hub
errorlangnotrecognized,core_hub
forceunregister,core_hub
forceunregisterconfirmation,core_hub
hub,core_hub
information,core_hub
moodleorg,core_hub
nocheckstatusfromunreghub,core_hub
nohubselected,core_hub
none,core_hub
nosearch,core_hub
notregisteredonmoodleorg,core_hub
orenterprivatehub,core_hub
prioritise,core_hub
private,core_hub
privatehuburl,core_hub
publichub,core_hub
publishon,core_hub
publishonspecifichub,core_hub
registeredmoodleorg,core_hub
registeredon,core_hub
registerwith,core_hub
registrationupdated,core_hub
registrationupdatedfailed,core_hub
selecthub,core_hub
selecthubinfo,core_hub
selecthubforadvertise,core_hub
selecthubforsharing,core_hub
settings,core_hub
settingsupdated,core_hub
shareonhub,core_hub
sitecreated,core_hub
siteregconfcomment,core_hub
siteupdatedcron,core_hub
siteupdatesend,core_hub
siteupdatesstart,core_hub
specifichubregistrationdetail,core_hub
statistics,core_hub
trustme,core_hub
unknownstatus,core_hub
unlistedurl,core_hub
unprioritise,core_hub
unregisterconfirmation,core_hub
untrustme,core_hub
uploaded,core_hub
url,core_hub
warning,core_hub
wrongurlformat,core_hub
xmlrpcdisabledcommunity,core_hub
xmlrpcdisabledpublish,core_hub
xmlrpcdisabledregistration,core_hub
moodleorghubname,core_admin
hubs,core_admin
+89 -82
View File
@@ -28,36 +28,18 @@ $string['advertise'] = 'Advertise this course for people to join';
$string['advertised'] = 'Advertised';
$string['advertiseon'] = 'Advertise this course on {$a}';
$string['readvertiseon'] = 'Update advertising information on {$a}';
$string['advertiseonhub'] = 'Advertise this course on a hub';
$string['advertiseonmoodleorg'] = 'Advertise this course on moodle.org';
$string['advertisepublication_help'] = 'Advertising your course on a community hub server allows people to find this course and come here to enrol.';
$string['all'] = 'All';
$string['allowglobalsearch'] = 'Publish this hub and allow global search of all courses';
$string['allowpublicsearch'] = 'Publish this hub so people can join it';
$string['advertisepublication_help'] = 'Advertising your course on a community server allows people to find this course and come here to enrol.';
$string['audience'] = 'Audience';
$string['audience_help'] = 'Select the intended audience for the course.';
$string['audienceeducators'] = 'Educators';
$string['audiencestudents'] = 'Students';
$string['audienceadmins'] = 'Moodle administrators';
$string['badurlformat'] = 'Bad URL format';
$string['badgesnumber'] = 'Number of badges ({$a})';
$string['community'] = 'Community';
$string['communityremoved'] = 'That course link has been removed from your list';
$string['confirmregistration'] = 'Confirm registration';
$string['cannotsearchcommunity'] = 'Sorry, you don\'t have the right permissions to see this page';
$string['contactable'] = 'Contact from the public';
$string['contactable_help'] = 'Set to yes, the hub will display your email address.';
$string['contactemail'] = 'Contact email';
$string['contactname'] = 'Contact name';
$string['contactphone'] = 'Phone';
$string['contactphone_help'] = 'Phone numbers are displayed to the Hub administrator only and are not shown publicly.';
$string['continue'] = 'Continue';
$string['contributornames'] = 'Other contributors';
$string['contributornames_help'] = 'You can use this field to list the names of anyone else who contributed to this course.';
$string['coursemap'] = 'Course map';
$string['coursename'] = 'Name';
$string['courseprivate'] = 'Private';
$string['coursepublic'] = 'Public';
$string['coursepublished'] = 'This course has been published successfully on \'{$a}\'.';
$string['courseshortname'] = 'Shortname';
$string['courseshortname_help'] = 'Enter a short name for your course. It does not need to be unique.';
@@ -74,8 +56,8 @@ $string['deletescreenshots_help'] = 'Delete all the currently uploaded screensho
$string['demourl'] = 'Demo URL';
$string['demourl_help'] = 'Enter the demo URL of your course. By default it is the URL of your course. The demo URL is displayed as a link in a search result.';
$string['description'] = 'Description';
$string['description_help'] = 'This description text will be showing in the course listing on the hub.';
$string['detectednotexistingpublication'] = '{$a->hubname} is listing a course that does not exist any more. Alert this hub administrator that the publication number {$a->id} should be removed.';
$string['description_help'] = 'This description text will be showing in the course listing on Moodle.net.';
$string['detectednotexistingpublication'] = '{$a->hubname} is listing a course that does not exist any more. Alert {$a->hubname} administrator that the publication number {$a->id} should be removed.';
$string['downloadable'] = 'Downloadable';
$string['educationallevel'] = 'Educational level';
$string['educationallevel_help'] = 'Select the most appropriate educational level that the course fits into.';
@@ -90,25 +72,20 @@ $string['emailalert'] = 'Email notifications';
$string['emailalert_help'] = 'If this is enabled the hub administrator will send you emails about security issues and other important news.';
$string['enrollable'] = 'Enrollable';
$string['errorbadimageheightwidth'] = 'The image should have a maximum size of {$a->width} X {$a->height}';
$string['errorcourseinfo'] = 'An error occurred when retrieving course metadata from the hub ({$a}). Please try again to retrieve the course metadata from the hub by reloading this page later. Otherwise you can decide to continue the registration process with the following default metadata. ';
$string['errorcourseinfo'] = 'An error occurred when retrieving course metadata from {$a}. Please try again to retrieve the course metadata by reloading this page later. Otherwise you can decide to continue the registration process with the following default metadata. ';
$string['errorcoursepublish'] = 'An error occurred during the course publication ({$a}). Please try again later.';
$string['errorcoursewronglypublished'] = 'A publication error has been returned by the hub. Please try again later.';
$string['errorcron'] = 'An error occurred during registration update on "{$a->hubname}" ({$a->errormessage})';
$string['errorcronnoxmlrpc'] = 'XML-RPC must be enabled in order to update the registration.';
$string['errorhublisting'] = 'An error occurred when retrieving the hub listing from Moodle. Please try again later. ({$a})';
$string['errorlangnotrecognized'] = 'The provided language code is unknown by Moodle. Please contact {$a}';
$string['errorcoursewronglypublished'] = 'A publication error has been returned by Moodle.net. Please try again later.';
$string['errorotherhubsnotsupported'] = 'This page can no longer be used for registration with sites other than Moodle.net';
$string['errorregistration'] = 'An error occurred during registration, please try again later. ({$a})';
$string['errorunpublishcourses'] = 'Due to an unexpected error, the courses could not be deleted on the hub. Try again later (recommended) or contact the hub administrator.';
$string['existingscreenshotnumber'] = '{$a} existing screenshots. You will be able to see these screenshots on this page, only once the hub administrator enables your course.';
$string['errorunpublishcourses'] = 'Due to an unexpected error, the courses could not be deleted from Moodle.net. Try again later (recommended) or contact Moodle.net administrator.';
$string['errorws'] = '{$a}';
$string['existingscreenshotnumber'] = '{$a} existing screenshots. You will be able to see these screenshots on this page, only once the Moodle.net administrator enables your course.';
$string['errorregistrationupdate'] = 'An error occurred during registration update ({$a})';
$string['existingscreenshots'] = 'Existing screenshots';
$string['forceunregister'] = 'Yes, clean registration data';
$string['forceunregisterconfirmation'] = 'Your site cannot reach {$a}. This hub could be temporarily down. Unless you are sure you want to continue to remove registration locally, please cancel and try again later.';
$string['geolocation'] = 'Geolocation';
$string['geolocation_help'] = 'In future we may provide location-based searching. If you want to specify the location for your course use a latitude/longitude value here (eg: -31.947884,115.871285). One way to find this is to use Google Maps.';
$string['hub'] = 'Hub';
$string['imageurl'] = 'Image URL';
$string['imageurl_help'] = 'This image will be displayed on the hub. This image must be available from the hub at any moment. The image should have a maximum size of {$a->width} X {$a->height}';
$string['information'] = 'Information';
$string['issuedbadgesnumber'] = 'Number of issued badges ({$a})';
$string['language'] = 'Language';
$string['language_help'] = 'The main language of this course.';
@@ -120,7 +97,6 @@ $string['logourl'] = 'Logo URL';
$string['mobilenotificationsenabled'] = 'Mobile notifications enabled ({$a})';
$string['mobileservicesenabled'] = 'Mobile services enabled ({$a})';
$string['modulenumberaverage'] = 'Average number of course modules ({$a})';
$string['moodleorg'] = 'Moodle';
$string['mustselectsubject'] = 'You must select a subject';
$string['name'] = 'Name';
$string['name_help'] = 'This name will be showing in the course listing.';
@@ -131,46 +107,33 @@ $string['nocheckstatusfromunreghub'] = 'The site is not registered on the hub so
$string['nohubselected'] = 'No hub selected';
$string['none'] = 'None';
$string['nosearch'] = 'Don\'t publish hub or courses';
$string['notregisteredonhub'] = 'Your administrator needs to register this site with at least one hub before you can publish a course. Contact your site administrator.';
$string['notregisteredonmoodleorg'] = 'Your administrator needs to register this site with moodle.org.';
$string['notregisteredonhub'] = 'Your administrator needs to register this site with Moodle.net before you can publish a course.';
$string['operation'] = 'Actions';
$string['orenterprivatehub'] = 'Alternatively, enter a private hub URL:';
$string['participantnumberaverage'] = 'Average number of participants ({$a})';
$string['postaladdress'] = 'Postal address';
$string['postaladdress_help'] = 'Postal address of this site, or of the entity represented by this site.';
$string['postsnumber'] = 'Number of posts ({$a})';
$string['previousregistrationdeleted'] = 'The previous registration has been deleted from {$a}. You can restart the registration process. Thank you.';
$string['prioritise'] = 'Prioritise';
$string['privacy'] = 'Privacy';
$string['privacy_help'] = 'The hub may want to display a list of registered sites. If it does then you can choose whether or not you want to appear on that list.';
$string['private'] = 'Private';
$string['privatehuburl'] = 'Private hub URL';
$string['publicationinfo'] = 'Course publication information';
$string['publichub'] = 'Public hub';
$string['publishcourse'] = 'Publish {$a}';
$string['publishcourseon'] = 'Publish on {$a}';
$string['publishedon'] = 'Published on';
$string['publishedon'] = 'Publications';
$string['publisheremail'] = 'Publisher email';
$string['publisheremail_help'] = 'The publisher email address allows the hub administrator to alert the publisher about any changes to the status of the published course.';
$string['publishername'] = 'Publisher';
$string['publishername_help'] = 'The publisher is the person or organisation that is the official publisher of the course. Unless you are publishing it on behalf of someone else, it will usually be you.';
$string['publishon'] = 'Publish on';
$string['publishonspecifichub'] = 'Publish on another Hub';
$string['questionsnumber'] = 'Number of questions ({$a})';
$string['registeredcourses'] = 'Registered courses';
$string['registeredsites'] = 'Registered sites';
$string['registrationinfo'] = 'Registration information';
$string['registeredmoodleorg'] = 'Moodle ({$a})';
$string['registeredon'] = 'Where your site is registered';
$string['registereduserdevices'] = 'Number of users with registered mobile devices ({$a})';
$string['registeredactiveuserdevices'] = 'Number of active users with registered mobile devices which are receiving notifications ({$a})';
$string['registersite'] = 'Register with {$a}';
$string['registerwith'] = 'Register with a hub';
$string['registrationconfirmed'] = 'Site registration confirmed';
$string['registrationconfirmedon'] = 'Thank you for registering your site. Registration information will be kept up to date by the \'Site registration\' scheduled task.';
$string['registrationupdated'] = 'Registration has been updated.';
$string['registrationupdatedfailed'] = 'Registration update failed.';
$string['removefromhub'] = 'Remove from hub';
$string['removefromhub'] = 'Remove from Moodle.net';
$string['renewregistration'] = 'Renew registration';
$string['resourcesnumber'] = 'Number of resources ({$a})';
$string['restartregistration'] = 'Restart registration';
@@ -178,27 +141,19 @@ $string['roleassignmentsnumber'] = 'Number of role assignments ({$a})';
$string['screenshots'] = 'Screenshots';
$string['screenshots_help'] = 'Any screenshots of the course will be displayed in search results.';
$string['search'] = 'Search';
$string['selecthub'] = 'Select hub';
$string['selecthubinfo'] = 'A community hub is a server that lists courses. You can only publish your courses on hubs that this Moodle site is registered with. If the hub you want is not listed below, please contact your site administrator.';
$string['selecthubforadvertise'] = 'Select hub for advertising';
$string['selecthubforsharing'] = 'Select hub for uploading';
$string['sendingcourse'] = 'Sending course';
$string['sendingsize'] = 'Please wait the course file is uploading ({$a->total}Mb)...';
$string['sendfollowinginfo'] = 'More information';
$string['sendfollowinginfo_help'] = 'The following information will be sent to contribute to overall statistics only. It will not be made public on any site listing.';
$string['sent'] = '...finished';
$string['settings'] = 'Settings';
$string['settingsupdated'] = 'Settings have been updated.';
$string['share'] = 'Share this course for people to download';
$string['shared'] = 'Shared';
$string['shareon'] = 'Upload this course to {$a}';
$string['shareonhub'] = 'Upload this course to a hub';
$string['sharepublication_help'] = 'Uploading this course to a community hub server will enable people to download it and install it on their own Moodle sites.';
$string['sharepublication_help'] = 'Uploading this course to a community server will enable people to download it and install it on their own Moodle sites.';
$string['siteadmin'] = 'Administrator';
$string['siteadmin_help'] = 'The full name of the site administrator.';
$string['sitecountry'] = 'Country';
$string['sitecountry_help'] = 'The country your organisation is in.';
$string['sitecreated'] = 'Site created';
$string['sitedesc'] = 'Description';
$string['sitedesc_help'] = 'This description of your site may be shown in the site listing. Please use plain text only.';
$string['sitegeolocation'] = 'Geolocation';
@@ -215,7 +170,6 @@ $string['siteprivacy'] = 'Privacy';
$string['siteprivacynotpublished'] = 'Please do not publish this site';
$string['siteprivacypublished'] = 'Publish the site name only';
$string['siteprivacylinked'] = 'Publish the site name with a link';
$string['siteregconfcomment'] = 'Your site needs a final confirmation on {$a} (in order to avoid spam on {$a})';
$string['siteregistrationcontact'] = 'Contact form';
$string['siteregistrationcontact_help'] = 'If you allow it, other people may be able to contact you via a contact form on the hub. They will never be able to see your email address.';
$string['siteregistrationemail'] = 'Email notifications';
@@ -223,50 +177,103 @@ $string['siteregistrationemail_help'] = 'If you enable this the hub administrato
$string['siteregistrationupdated'] = 'Site registration updated';
$string['siterelease'] = 'Moodle release';
$string['siterelease_help'] = 'Moodle release number of this site.';
$string['siteupdatedcron'] = 'Site registration updated on "{$a}"';
$string['siteupdatesend'] = 'Finished registration update on hubs.';
$string['siteupdatesstart'] = 'Starting registration update on hubs...';
$string['siteurl'] = 'Site URL';
$string['siteurl_help'] = 'The URL is the address of this site. If privacy settings allow people to see site addresses then this is the URL that will be used.';
$string['siteversion'] = 'Moodle version';
$string['siteversion_help'] = 'The Moodle version of this site.';
$string['subject'] = 'Subject';
$string['subject_help'] = 'Select the main subject area which the course covers.';
$string['specifichubregistrationdetail'] = 'You can also register your site with other community hubs.';
$string['statistics'] = 'Statistics privacy';
$string['status'] = 'Hub listing';
$string['status'] = 'Listing status';
$string['statuspublished'] = 'Listed';
$string['statusunpublished'] = 'Not listed';
$string['tags'] = 'Tags';
$string['tags_help'] = 'Tags help to further categorise your course and help it to be found. Please use simple, meaningful words and separate them with a comma. Example: math, algebra, geometry';
$string['trustme'] = 'Trust';
$string['type'] = 'Advertised / Shared';
$string['unknownstatus'] = 'Unknown';
$string['unlistedurl'] = 'Unlisted hub URL';
$string['unprioritise'] = 'Unprioritise';
$string['unpublish'] = 'Unpublish';
$string['unpublishalladvertisedcourses'] = 'Remove all courses currently being advertised on a hub';
$string['unpublishalluploadedcourses'] = 'Removed all courses that were uploaded to a hub';
$string['unpublishconfirmation'] = 'Do you really want to remove the course "{$a->courseshortname}" from the hub "{$a->hubname}"';
$string['unpublishalladvertisedcourses'] = 'Remove all courses currently being advertised on Moodle.net';
$string['unpublishalluploadedcourses'] = 'Removed all courses that were uploaded to Moodle.net';
$string['unpublishconfirmation'] = 'Do you really want to remove the course "{$a->courseshortname}" from "{$a->hubname}"';
$string['unpublishcourse'] = 'Unpublish {$a}';
$string['unregister'] = 'Unregister';
$string['unregisterfrom'] = 'Unregister from {$a}';
$string['unregisterconfirmation'] = 'You are about to unregister this site from the hub {$a}. Once you disconnect from it, you will not be able to manage any courses you left there. Are you sure you want to unregister?';
$string['unregistrationerror'] = 'An error occurred when the site tried to unregister from the hub: {$a}';
$string['untrustme'] = 'Not trusted';
$string['unregistrationerror'] = 'An error occurred when the site tried to unregister from Moodle.net: {$a}';
$string['update'] = 'Update';
$string['updatesite'] = 'Update registration on {$a}';
$string['updatestatus'] = 'Check it now.';
$string['urlalreadyregistered'] = 'Your site seems to be already registered on Moodle.net, which means something has gone wrong. Please contact the Moodle.net administrator to reset your registration so you can try again.';
$string['usersnumber'] = 'Number of users ({$a})';
$string['wrongtoken'] = 'The registration failed for some unknown reason (network?). Please try again.';
// Deprecated since Moodle 3.4.
$string['registermoochtips'] = 'Register your site with Moodle to get security alerts and access to Moodle.net, our course sharing platform.';
$string['errorcronnoxmlrpc'] = 'XML-RPC must be enabled in order to update the registration.';
$string['advertiseonhub'] = 'Advertise this course on a hub';
$string['advertiseonmoodleorg'] = 'Advertise this course on moodle.org';
$string['all'] = 'All';
$string['allowglobalsearch'] = 'Publish this hub and allow global search of all courses';
$string['allowpublicsearch'] = 'Publish this hub so people can join it';
$string['badurlformat'] = 'Bad URL format';
$string['community'] = 'Community';
$string['cannotsearchcommunity'] = 'Sorry, you don\'t have the right permissions to see this page';
$string['contactable'] = 'Contact from the public';
$string['contactable_help'] = 'Set to yes, the hub will display your email address.';
$string['contactemail'] = 'Contact email';
$string['contactname'] = 'Contact name';
$string['contactphone'] = 'Phone';
$string['contactphone_help'] = 'Phone numbers are displayed to the Hub administrator only and are not shown publicly.';
$string['continue'] = 'Continue';
$string['coursemap'] = 'Course map';
$string['courseprivate'] = 'Private';
$string['coursepublic'] = 'Public';
$string['errorcron'] = 'An error occurred during registration update on "{$a->hubname}" ({$a->errormessage})';
$string['errorhublisting'] = 'An error occurred when retrieving the hub listing from Moodle. Please try again later. ({$a})';
$string['errorlangnotrecognized'] = 'The provided language code is unknown by Moodle. Please contact {$a}';
$string['forceunregister'] = 'Yes, clean registration data';
$string['forceunregisterconfirmation'] = 'Your site cannot reach {$a}. This hub could be temporarily down. Unless you are sure you want to continue to remove registration locally, please cancel and try again later.';
$string['hub'] = 'Hub';
$string['information'] = 'Information';
$string['moodleorg'] = 'Moodle';
$string['nocheckstatusfromunreghub'] = 'The site is not registered on the hub so the status can not be checked.';
$string['nohubselected'] = 'No hub selected';
$string['none'] = 'None';
$string['nosearch'] = 'Don\'t publish hub or courses';
$string['notregisteredonmoodleorg'] = 'Your administrator needs to register this site with moodle.org.';
$string['orenterprivatehub'] = 'Alternatively, enter a private hub URL:';
$string['prioritise'] = 'Prioritise';
$string['private'] = 'Private';
$string['privatehuburl'] = 'Private hub URL';
$string['publichub'] = 'Public hub';
$string['publishon'] = 'Publish on';
$string['publishonspecifichub'] = 'Publish on another Hub';
$string['registeredmoodleorg'] = 'Moodle ({$a})';
$string['registeredon'] = 'Where your site is registered';
$string['registerwith'] = 'Register with a hub';
$string['registrationupdated'] = 'Registration has been updated.';
$string['registrationupdatedfailed'] = 'Registration update failed.';
$string['selecthub'] = 'Select hub';
$string['selecthubinfo'] = 'A community hub is a server that lists courses. You can only publish your courses on hubs that this Moodle site is registered with. If the hub you want is not listed below, please contact your site administrator.';
$string['selecthubforadvertise'] = 'Select hub for advertising';
$string['selecthubforsharing'] = 'Select hub for uploading';
$string['settings'] = 'Settings';
$string['settingsupdated'] = 'Settings have been updated.';
$string['shareonhub'] = 'Upload this course to a hub';
$string['sitecreated'] = 'Site created';
$string['siteregconfcomment'] = 'Your site needs a final confirmation on {$a} (in order to avoid spam on {$a})';
$string['siteupdatedcron'] = 'Site registration updated on "{$a}"';
$string['siteupdatesend'] = 'Finished registration update on hubs.';
$string['siteupdatesstart'] = 'Starting registration update on hubs...';
$string['specifichubregistrationdetail'] = 'You can also register your site with other community hubs.';
$string['statistics'] = 'Statistics privacy';
$string['trustme'] = 'Trust';
$string['unknownstatus'] = 'Unknown';
$string['unlistedurl'] = 'Unlisted hub URL';
$string['unprioritise'] = 'Unprioritise';
$string['unregisterconfirmation'] = 'You are about to unregister this site from the hub {$a}. Once you disconnect from it, you will not be able to manage any courses you left there. Are you sure you want to unregister?';
$string['untrustme'] = 'Not trusted';
$string['uploaded'] = 'Uploaded';
$string['url'] = 'hub URL';
$string['urlalreadyregistered'] = 'Your site seems to be already registered on this hub, which means something has gone wrong. Please contact the hub administrator to reset your registration so you can try again.';
$string['usersnumber'] = 'Number of users ({$a})';
$string['warning'] = 'WARNING';
$string['wrongtoken'] = 'The registration failed for some unknown reason (network?). Please try again.';
$string['wrongurlformat'] = 'Bad URL format';
$string['xmlrpcdisabledcommunity'] = 'The XML-RPC extension is not enabled on the server. You can not search and download courses.';
$string['xmlrpcdisabledpublish'] = 'The XML-RPC extension is not enabled on the server. You can not publish courses or manage published courses.';
$string['xmlrpcdisabledregistration'] = 'The XML-RPC extension is not enabled on the server. You will not be able to unregister or update your registration until you enable it.';
// Deprecated since Moodle 3.4.
$string['registermoochtips'] = 'Register your site with Moodle to get security alerts and access to Moodle.net, our course sharing platform.';
+4 -4
View File
@@ -66,7 +66,7 @@ $string['backup:backupcourse'] = 'Backup courses';
$string['backup:backupsection'] = 'Backup sections';
$string['backup:configure'] = 'Configure backup options';
$string['backup:downloadfile'] = 'Download files from backup areas';
$string['backup:backuptargethub'] = 'Backup for hub';
$string['backup:backuptargethub'] = 'Backup for publishing on Moodle.net';
$string['backup:backuptargetimport'] = 'Backup for import';
$string['backup:userinfo'] = 'Backup user data';
$string['badges:awardbadge'] = 'Award badge to a user';
@@ -107,7 +107,7 @@ $string['cohort:manage'] = 'Create, delete and move cohorts';
$string['comment:delete'] = 'Delete comments';
$string['comment:post'] = 'Post comments';
$string['comment:view'] = 'View comments';
$string['community:add'] = 'Use the community block to search hubs and find courses';
$string['community:add'] = 'Use the community block to search Moodle.net and find courses';
$string['community:download'] = 'Download a course from the community block';
$string['competency:competencymanage'] = 'Manage competency frameworks';
$string['competency:competencygrade'] = 'Set competency rating';
@@ -172,7 +172,7 @@ $string['course:managegroups'] = 'Manage groups';
$string['course:managescales'] = 'Manage scales';
$string['course:markcomplete'] = 'Mark users as complete in course completion';
$string['course:movesections'] = 'Move sections';
$string['course:publish'] = 'Publish a course into hub';
$string['course:publish'] = 'Publish a course';
$string['course:renameroles'] = 'Rename roles';
$string['course:request'] = 'Request new courses';
$string['course:reset'] = 'Reset course';
@@ -347,7 +347,7 @@ $string['restore:createuser'] = 'Create users on restore';
$string['restore:restoreactivity'] = 'Restore activities';
$string['restore:restoresection'] = 'Restore sections';
$string['restore:restorecourse'] = 'Restore courses';
$string['restore:restoretargethub'] = 'Restore from files targeted as hub';
$string['restore:restoretargethub'] = 'Restore courses downloaded from Moodle.net';
$string['restore:restoretargetimport'] = 'Restore from files targeted as import';
$string['restore:rolldates'] = 'Allowed to roll activity configuration dates on restore';
$string['restore:uploadfile'] = 'Upload files to backup areas';
+433
View File
@@ -0,0 +1,433 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class communication
*
* @package core
* @copyright 2017 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\hub;
defined('MOODLE_INTERNAL') || die();
use webservice_xmlrpc_client;
use moodle_exception;
use curl;
use stdClass;
use coding_exception;
use moodle_url;
/**
* Methods to communicate with moodle.net web services
*
* @package core
* @copyright 2017 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class api {
/** @var File type: Course screenshot */
const HUB_SCREENSHOT_FILE_TYPE = 'screenshot';
/** @var File type: Hub screenshot */
const HUB_HUBSCREENSHOT_FILE_TYPE = 'hubscreenshot';
/** @var File type: Backup */
const HUB_BACKUP_FILE_TYPE = 'backup';
/**
* Calls moodle.net WS
*
* @param string $function name of WS function
* @param array $data parameters of WS function
* @param bool $allowpublic allow request without moodle.net registration
* @return mixed depends on the function
* @throws moodle_exception
*/
protected static function call($function, array $data = [], $allowpublic = false) {
$token = registration::get_token() ?: 'publichub';
if (!$allowpublic && $token === 'publichub') {
// This will throw an exception.
registration::require_registration();
}
if (extension_loaded('xmlrpc')) {
// Use XMLRPC protocol.
return self::call_xmlrpc($token, $function, $data);
} else {
// Use REST.
return self::call_rest($token, $function, $data);
}
}
/**
* Performs REST request to moodle.net (using GET method)
*
* @param string $token
* @param string $function
* @param array $data
* @return mixed
* @throws moodle_exception
*/
protected static function call_xmlrpc($token, $function, array $data) {
global $CFG;
require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
$serverurl = HUB_MOODLEORGHUBURL . "/local/hub/webservice/webservices.php";
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $token);
try {
return $xmlrpcclient->call($function, $data);
} catch (\Exception $e) {
// Function webservice_xmlrpc_client::call() can throw Exception, wrap it into moodle_exception.
throw new moodle_exception('errorws', 'hub', '', $e->getMessage());
}
}
/**
* Performs REST request to moodle.net (using GET method)
*
* @param string $token
* @param string $function
* @param array $data
* @return mixed
* @throws moodle_exception
*/
protected static function call_rest($token, $function, array $data) {
$params = [
'wstoken' => $token,
'wsfunction' => $function,
'moodlewsrestformat' => 'json'
] + $data;
$curl = new curl();
$serverurl = HUB_MOODLEORGHUBURL . "/local/hub/webservice/webservices.php";
$curloutput = @json_decode($curl->get($serverurl, $params), true);
$info = $curl->get_info();
if ($curl->get_errno()) {
throw new moodle_exception('errorconnect', 'hub', '', $curl->error);
} else if (isset($curloutput['exception'])) {
// Error message returned by web service.
throw new moodle_exception('errorws', 'hub', '', $curloutput['message']);
} else if ($info['http_code'] != 200) {
throw new moodle_exception('errorconnect', 'hub', '', $info['http_code']);
} else {
return $curloutput;
}
}
/**
* Update site registration on moodle.net
*
* @param array $siteinfo
* @throws moodle_exception
*/
public static function update_registration(array $siteinfo) {
$params = array('siteinfo' => $siteinfo);
self::call('hub_update_site_info', $params);
}
/**
* Returns information about moodle.net
*
* Example of the return array:
* {
* "courses": 384,
* "description": "Moodle.net connects you with free content and courses shared by Moodle ...",
* "downloadablecourses": 190,
* "enrollablecourses": 194,
* "hublogo": 1,
* "language": "en",
* "name": "Moodle.net",
* "sites": 274175,
* "url": "https://moodle.net",
* "imgurl": "https://moodle.net/local/hub/webservice/download.php?filetype=hubscreenshot"
* }
*
* @return array
* @throws moodle_exception
*/
public static function get_hub_info() {
$info = self::call('hub_get_info', [], true);
$info['imgurl'] = new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/webservice/download.php',
['filetype' => self::HUB_HUBSCREENSHOT_FILE_TYPE]);
return $info;
}
/**
* Calls WS function hub_get_courses
*
* Parameter $options may have any of these fields:
* [
* 'ids' => new external_multiple_structure(new external_value(PARAM_INTEGER, 'id of a course in the hub course
* directory'), 'ids of course', VALUE_OPTIONAL),
* 'sitecourseids' => new external_multiple_structure(new external_value(PARAM_INTEGER, 'id of a course in the
* site'), 'ids of course in the site', VALUE_OPTIONAL),
* 'coverage' => new external_value(PARAM_TEXT, 'coverage', VALUE_OPTIONAL),
* 'licenceshortname' => new external_value(PARAM_ALPHANUMEXT, 'licence short name', VALUE_OPTIONAL),
* 'subject' => new external_value(PARAM_ALPHANUM, 'subject', VALUE_OPTIONAL),
* 'audience' => new external_value(PARAM_ALPHA, 'audience', VALUE_OPTIONAL),
* 'educationallevel' => new external_value(PARAM_ALPHA, 'educational level', VALUE_OPTIONAL),
* 'language' => new external_value(PARAM_ALPHANUMEXT, 'language', VALUE_OPTIONAL),
* 'orderby' => new external_value(PARAM_ALPHA, 'orderby method: newest, eldest, publisher, fullname,
* ratingaverage', VALUE_OPTIONAL),
* 'givememore' => new external_value(PARAM_INT, 'next range of result - range size being set by the hub
* server ', VALUE_OPTIONAL),
* 'allsitecourses' => new external_value(PARAM_INTEGER,
* 'if 1 return all not visible and visible courses whose siteid is the site
* matching token. Only courses of this site are returned.
* givememore parameter is ignored if this param = 1.
* In case of public token access, this param option is ignored', VALUE_DEFAULT, 0),
* ]
*
* Each course in the returned array of courses will have fields:
* [
* 'id' => new external_value(PARAM_INTEGER, 'id'),
* 'fullname' => new external_value(PARAM_TEXT, 'course name'),
* 'shortname' => new external_value(PARAM_TEXT, 'course short name'),
* 'description' => new external_value(PARAM_TEXT, 'course description'),
* 'language' => new external_value(PARAM_ALPHANUMEXT, 'course language'),
* 'publishername' => new external_value(PARAM_TEXT, 'publisher name'),
* 'publisheremail' => new external_value(PARAM_EMAIL, 'publisher email', VALUE_OPTIONAL),
* 'privacy' => new external_value(PARAM_INT, 'privacy: published or not', VALUE_OPTIONAL),
* 'sitecourseid' => new external_value(PARAM_INT, 'course id on the site', VALUE_OPTIONAL),
* 'contributornames' => new external_value(PARAM_TEXT, 'contributor names', VALUE_OPTIONAL),
* 'coverage' => new external_value(PARAM_TEXT, 'coverage', VALUE_OPTIONAL),
* 'creatorname' => new external_value(PARAM_TEXT, 'creator name'),
* 'licenceshortname' => new external_value(PARAM_ALPHANUMEXT, 'licence short name'),
* 'subject' => new external_value(PARAM_ALPHANUM, 'subject'),
* 'audience' => new external_value(PARAM_ALPHA, 'audience'),
* 'educationallevel' => new external_value(PARAM_ALPHA, 'educational level'),
* 'creatornotes' => new external_value(PARAM_RAW, 'creator notes'),
* 'creatornotesformat' => new external_value(PARAM_INTEGER, 'notes format'),
* 'demourl' => new external_value(PARAM_URL, 'demo URL', VALUE_OPTIONAL),
* 'courseurl' => new external_value(PARAM_URL, 'course URL', VALUE_OPTIONAL),
* 'backupsize' => new external_value(PARAM_INT, 'course backup size in bytes', VALUE_OPTIONAL),
* 'enrollable' => new external_value(PARAM_BOOL, 'is the course enrollable'),
* 'screenshots' => new external_value(PARAM_INT, 'total number of screenshots'),
* 'timemodified' => new external_value(PARAM_INT, 'time of last modification - timestamp'),
* 'contents' => new external_multiple_structure(new external_single_structure(
* array(
* 'moduletype' => new external_value(PARAM_ALPHA, 'the type of module (activity/block)'),
* 'modulename' => new external_value(PARAM_TEXT, 'the name of the module (forum, resource etc)'),
* 'contentcount' => new external_value(PARAM_INT, 'how many time the module is used in the course'),
* )), 'contents', VALUE_OPTIONAL),
* 'rating' => new external_single_structure (
* array(
* 'aggregate' => new external_value(PARAM_FLOAT, 'Rating average', VALUE_OPTIONAL),
* 'scaleid' => new external_value(PARAM_INT, 'Rating scale'),
* 'count' => new external_value(PARAM_INT, 'Rating count'),
* ), 'rating', VALUE_OPTIONAL),
* 'comments' => new external_multiple_structure(new external_single_structure (
* array(
* 'comment' => new external_value(PARAM_TEXT, 'the comment'),
* 'commentator' => new external_value(PARAM_TEXT, 'the name of commentator'),
* 'date' => new external_value(PARAM_INT, 'date of the comment'),
* )), 'contents', VALUE_OPTIONAL),
* 'outcomes' => new external_multiple_structure(new external_single_structure(
* array(
* 'fullname' => new external_value(PARAM_TEXT, 'the outcome fullname')
* )), 'outcomes', VALUE_OPTIONAL)
* ]
*
* Additional fields for each course:
* 'screenshotbaseurl' (moodle_url) URL of the first screenshot, only set if $course['screenshots']>0
* 'commenturl' (moodle_url) URL for comments
*
* @param string $search search string
* @param bool $downloadable return downloadable courses
* @param bool $enrollable return enrollable courses
* @param array|\stdClass $options other options from the list of allowed options:
* 'ids', 'sitecourseids', 'coverage', 'licenceshortname', 'subject', 'audience',
* 'educationallevel', 'language', 'orderby', 'givememore', 'allsitecourses'
* @return array of two elements: [$courses, $coursetotal]
* @throws \coding_exception
* @throws moodle_exception
*/
public static function get_courses($search, $downloadable, $enrollable, $options) {
static $availableoptions = ['ids', 'sitecourseids', 'coverage', 'licenceshortname', 'subject', 'audience',
'educationallevel', 'language', 'orderby', 'givememore', 'allsitecourses'];
if (empty($options)) {
$options = [];
} else if (is_object($options)) {
$options = (array)$options;
} else if (!is_array($options)) {
throw new \coding_exception('Parameter $options is invalid');
}
if ($unknownkeys = array_diff(array_keys($options), $availableoptions)) {
throw new \coding_exception('Unknown option(s): ' . join(', ', $unknownkeys));
}
$params = [
'search' => $search,
'downloadable' => (int)(bool)$downloadable,
'enrollable' => (int)(bool)$enrollable,
'options' => $options
];
$result = self::call('hub_get_courses', $params, true);
$courses = $result['courses'];
$coursetotal = $result['coursetotal'];
foreach ($courses as $idx => $course) {
$courses[$idx]['screenshotbaseurl'] = null;
if (!empty($course['screenshots'])) {
$courses[$idx]['screenshotbaseurl'] = new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/webservice/download.php',
array('courseid' => $course['id'],
'filetype' => self::HUB_SCREENSHOT_FILE_TYPE));
}
$courses[$idx]['commenturl'] = new moodle_url(HUB_MOODLEORGHUBURL,
array('courseid' => $course['id'], 'mustbelogged' => true));
}
return [$courses, $coursetotal];
}
/**
* Unregister the site
*
* @throws moodle_exception
*/
public static function unregister_site() {
self::call('hub_unregister_site');
}
/**
* Unpublish courses
*
* @param int[]|int $courseids
* @throws moodle_exception
*/
public static function unregister_courses($courseids) {
$courseids = (array)$courseids;
$params = array('courseids' => $courseids);
self::call('hub_unregister_courses', $params);
}
/**
* Publish one course
*
* Expected contents of $courseinfo:
* [
* 'sitecourseid' => new external_value(PARAM_INT, 'the id of the course on the publishing site'),
* 'fullname' => new external_value(PARAM_TEXT, 'course name'),
* 'shortname' => new external_value(PARAM_TEXT, 'course short name'),
* 'description' => new external_value(PARAM_TEXT, 'course description'),
* 'language' => new external_value(PARAM_ALPHANUMEXT, 'course language'),
* 'publishername' => new external_value(PARAM_TEXT, 'publisher name'),
* 'publisheremail' => new external_value(PARAM_EMAIL, 'publisher email'),
* 'contributornames' => new external_value(PARAM_TEXT, 'contributor names'),
* 'coverage' => new external_value(PARAM_TEXT, 'coverage'),
* 'creatorname' => new external_value(PARAM_TEXT, 'creator name'),
* 'licenceshortname' => new external_value(PARAM_ALPHANUMEXT, 'licence short name'),
* 'subject' => new external_value(PARAM_ALPHANUM, 'subject'),
* 'audience' => new external_value(PARAM_ALPHA, 'audience'),
* 'educationallevel' => new external_value(PARAM_ALPHA, 'educational level'),
* 'creatornotes' => new external_value(PARAM_RAW, 'creator notes'),
* 'creatornotesformat' => new external_value(PARAM_INTEGER, 'notes format'),
* 'demourl' => new external_value(PARAM_URL, 'demo URL', VALUE_OPTIONAL),
* 'courseurl' => new external_value(PARAM_URL, 'course URL', VALUE_OPTIONAL),
* 'enrollable' => new external_value(PARAM_BOOL, 'is the course enrollable', VALUE_DEFAULT, 0),
* 'screenshots' => new external_value(PARAM_INT, 'the number of screenhots', VALUE_OPTIONAL),
* 'deletescreenshots' => new external_value(PARAM_INT, 'ask to delete all the existing screenshot files
* (it does not reset the screenshot number)', VALUE_DEFAULT, 0),
* 'contents' => new external_multiple_structure(new external_single_structure(
* array(
* 'moduletype' => new external_value(PARAM_ALPHA, 'the type of module (activity/block)'),
* 'modulename' => new external_value(PARAM_TEXT, 'the name of the module (forum, resource etc)'),
* 'contentcount' => new external_value(PARAM_INT, 'how many time the module is used in the course'),
* )), 'contents', VALUE_OPTIONAL),
* 'outcomes' => new external_multiple_structure(new external_single_structure(
* array(
* 'fullname' => new external_value(PARAM_TEXT, 'the outcome fullname')
* )), 'outcomes', VALUE_OPTIONAL)
* ]
*
* @param array|\stdClass $courseinfo
* @return int id of the published course on the hub
* @throws moodle_exception if communication to moodle.net failed or course could not be published
*/
public static function register_course($courseinfo) {
$params = array('courses' => array($courseinfo));
$hubcourseids = self::call('hub_register_courses', $params);
if (count($hubcourseids) != 1) {
throw new moodle_exception('errorcoursewronglypublished', 'hub');
}
return $hubcourseids[0];
}
/**
* Uploads a screenshot for the published course
*
* @param int $hubcourseid id of the published course on moodle.net, it must be published from this site
* @param \stored_file $file
* @param int $screenshotnumber ordinal number of the screenshot
*/
public static function add_screenshot($hubcourseid, \stored_file $file, $screenshotnumber) {
$curl = new \curl();
$params = array();
$params['filetype'] = self::HUB_SCREENSHOT_FILE_TYPE;
$params['file'] = $file;
$params['courseid'] = $hubcourseid;
$params['filename'] = $file->get_filename();
$params['screenshotnumber'] = $screenshotnumber;
$params['token'] = registration::get_token(MUST_EXIST);
$curl->post(HUB_MOODLEORGHUBURL . "/local/hub/webservice/upload.php", $params);
}
/**
* Downloads course backup
*
* @param int $hubcourseid id of the course on moodle.net
* @param string $path local path (in tempdir) to save the downloaded backup to.
*/
public static function download_course_backup($hubcourseid, $path) {
$fp = fopen($path, 'w');
$curlurl = new \moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/webservice/download.php',
['filetype' => self::HUB_BACKUP_FILE_TYPE, 'courseid' => $hubcourseid]);
// Send an identification token if the site is registered.
if ($token = registration::get_token()) {
$curlurl->param('token', $token);
}
$ch = curl_init($curlurl->out(false));
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
/**
* Uploads a course backup
*
* @param int $hubcourseid id of the published course on moodle.net, it must be published from this site
* @param \stored_file $backupfile
*/
public static function upload_course_backup($hubcourseid, \stored_file $backupfile) {
$curl = new \curl();
$params = array();
$params['filetype'] = self::HUB_BACKUP_FILE_TYPE;
$params['courseid'] = $hubcourseid;
$params['file'] = $backupfile;
$params['token'] = registration::get_token();
$curl->post(HUB_MOODLEORGHUBURL . '/local/hub/webservice/upload.php', $params);
}
}
+308
View File
@@ -0,0 +1,308 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class course_publication_form
*
* @package core
* @copyright 2017 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\hub;
defined('MOODLE_INTERNAL') || die();
use stdClass;
use license_manager;
use moodle_url;
use core_collator;
global $CFG;
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->libdir . '/licenselib.php');
/**
* The forms used for course publication
*
* @package core
* @copyright 2017 Marina Glancy
* @author Jerome Mouneyrac <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_publication_form extends \moodleform {
/**
* Form definition
*/
public function definition() {
global $CFG, $USER, $PAGE;
$strrequired = get_string('required');
$mform = & $this->_form;
$course = $this->_customdata['course'];
if (!empty($this->_customdata['publication'])) {
// We are editing existing publication.
$publication = $this->_customdata['publication'];
$advertise = $publication->enrollable;
$publishedcourse = publication::get_published_course($publication);
} else {
$publication = null;
$advertise = $this->_customdata['advertise'];
}
$share = !$advertise;
if (!empty($publishedcourse)) {
$hubcourseid = $publishedcourse['id'];
$defaultfullname = $publishedcourse['fullname'];
$defaultshortname = $publishedcourse['shortname'];
$defaultsummary = $publishedcourse['description'];
$defaultlanguage = $publishedcourse['language'];
$defaultpublishername = $publishedcourse['publishername'];
$defaultpublisheremail = $publishedcourse['publisheremail'];
$defaultcontributornames = $publishedcourse['contributornames'];
$defaultcoverage = $publishedcourse['coverage'];
$defaultcreatorname = $publishedcourse['creatorname'];
$defaultlicenceshortname = $publishedcourse['licenceshortname'];
$defaultsubject = $publishedcourse['subject'];
$defaultaudience = $publishedcourse['audience'];
$defaulteducationallevel = $publishedcourse['educationallevel'];
$defaultcreatornotes = $publishedcourse['creatornotes'];
$defaultcreatornotesformat = $publishedcourse['creatornotesformat'];
$screenshotsnumber = $publishedcourse['screenshots'];
$screenshotbaseurl = $publishedcourse['screenshotbaseurl'];
$privacy = $publishedcourse['privacy'];
if (($screenshotsnumber > 0) and !empty($privacy)) {
$PAGE->requires->yui_module('moodle-block_community-imagegallery',
'M.blocks_community.init_imagegallery',
array(array('imageids' => array($hubcourseid),
'imagenumbers' => array($screenshotsnumber),
'huburl' => HUB_MOODLEORGHUBURL)));
}
} else {
$defaultfullname = $course->fullname;
$defaultshortname = $course->shortname;
$defaultsummary = clean_param($course->summary, PARAM_TEXT);
if (empty($course->lang)) {
$language = get_site()->lang;
if (empty($language)) {
$defaultlanguage = current_language();
} else {
$defaultlanguage = $language;
}
} else {
$defaultlanguage = $course->lang;
}
$defaultpublishername = $USER->firstname . ' ' . $USER->lastname;
$defaultpublisheremail = $USER->email;
$defaultcontributornames = '';
$defaultcoverage = '';
$defaultcreatorname = $USER->firstname . ' ' . $USER->lastname;
$defaultlicenceshortname = 'cc';
$defaultsubject = 'none';
$defaultaudience = publication::HUB_AUDIENCE_STUDENTS;
$defaulteducationallevel = publication::HUB_EDULEVEL_TERTIARY;
$defaultcreatornotes = '';
$defaultcreatornotesformat = FORMAT_HTML;
$screenshotsnumber = 0;
$screenshotbaseurl = null;
}
// The input parameters.
$mform->addElement('header', 'moodle', get_string('publicationinfo', 'hub'));
$mform->addElement('text', 'name', get_string('coursename', 'hub'),
array('class' => 'metadatatext'));
$mform->addRule('name', $strrequired, 'required', null, 'client');
$mform->setType('name', PARAM_TEXT);
$mform->setDefault('name', $defaultfullname);
$mform->addHelpButton('name', 'name', 'hub');
$mform->addElement('hidden', 'id', $course->id);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'publicationid', $publication ? $publication->id : null);
$mform->setType('publicationid', PARAM_INT);
if ($share) {
$buttonlabel = get_string('shareon', 'hub', 'Moodle.net');
$mform->addElement('hidden', 'share', $share);
$mform->setType('share', PARAM_BOOL);
$mform->addElement('text', 'demourl', get_string('demourl', 'hub'),
array('class' => 'metadatatext'));
$mform->setType('demourl', PARAM_URL);
$mform->setDefault('demourl', new moodle_url("/course/view.php?id=" . $course->id));
$mform->addHelpButton('demourl', 'demourl', 'hub');
}
if ($advertise) {
if (!$publication) {
$buttonlabel = get_string('advertiseon', 'hub', 'Moodle.net');
} else {
$buttonlabel = get_string('readvertiseon', 'hub', 'Moodle.net');
}
$mform->addElement('hidden', 'advertise', $advertise);
$mform->setType('advertise', PARAM_BOOL);
$mform->addElement('hidden', 'courseurl', $CFG->wwwroot . "/course/view.php?id=" . $course->id);
$mform->setType('courseurl', PARAM_URL);
$mform->addElement('static', 'courseurlstring', get_string('courseurl', 'hub'));
$mform->setDefault('courseurlstring', new moodle_url("/course/view.php?id=" . $course->id));
$mform->addHelpButton('courseurlstring', 'courseurl', 'hub');
}
$mform->addElement('text', 'courseshortname', get_string('courseshortname', 'hub'),
array('class' => 'metadatatext'));
$mform->setDefault('courseshortname', $defaultshortname);
$mform->addHelpButton('courseshortname', 'courseshortname', 'hub');
$mform->setType('courseshortname', PARAM_TEXT);
$mform->addElement('textarea', 'description', get_string('description', 'hub'), array('rows' => 10,
'cols' => 57));
$mform->addRule('description', $strrequired, 'required', null, 'client');
$mform->setDefault('description', $defaultsummary);
$mform->setType('description', PARAM_TEXT);
$mform->addHelpButton('description', 'description', 'hub');
$languages = get_string_manager()->get_list_of_languages();
core_collator::asort($languages);
$mform->addElement('select', 'language', get_string('language'), $languages);
$mform->setDefault('language', $defaultlanguage);
$mform->addHelpButton('language', 'language', 'hub');
$mform->addElement('text', 'publishername', get_string('publishername', 'hub'),
array('class' => 'metadatatext'));
$mform->setDefault('publishername', $defaultpublishername);
$mform->addRule('publishername', $strrequired, 'required', null, 'client');
$mform->addHelpButton('publishername', 'publishername', 'hub');
$mform->setType('publishername', PARAM_NOTAGS);
$mform->addElement('text', 'publisheremail', get_string('publisheremail', 'hub'),
array('class' => 'metadatatext'));
$mform->setDefault('publisheremail', $defaultpublisheremail);
$mform->addRule('publisheremail', $strrequired, 'required', null, 'client');
$mform->addHelpButton('publisheremail', 'publisheremail', 'hub');
$mform->setType('publisheremail', PARAM_EMAIL);
$mform->addElement('text', 'creatorname', get_string('creatorname', 'hub'),
array('class' => 'metadatatext'));
$mform->addRule('creatorname', $strrequired, 'required', null, 'client');
$mform->setType('creatorname', PARAM_NOTAGS);
$mform->setDefault('creatorname', $defaultcreatorname);
$mform->addHelpButton('creatorname', 'creatorname', 'hub');
$mform->addElement('text', 'contributornames', get_string('contributornames', 'hub'),
array('class' => 'metadatatext'));
$mform->setDefault('contributornames', $defaultcontributornames);
$mform->addHelpButton('contributornames', 'contributornames', 'hub');
$mform->setType('contributornames', PARAM_NOTAGS);
$mform->addElement('text', 'coverage', get_string('tags', 'hub'),
array('class' => 'metadatatext'));
$mform->setType('coverage', PARAM_TEXT);
$mform->setDefault('coverage', $defaultcoverage);
$mform->addHelpButton('coverage', 'tags', 'hub');
$licensemanager = new license_manager();
$licences = $licensemanager->get_licenses();
$options = array();
foreach ($licences as $license) {
$options[$license->shortname] = get_string($license->shortname, 'license');
}
$mform->addElement('select', 'licence', get_string('license'), $options);
$mform->setDefault('licence', $defaultlicenceshortname);
unset($options);
$mform->addHelpButton('licence', 'licence', 'hub');
$options = publication::get_sorted_subjects();
$mform->addElement('searchableselector', 'subject',
get_string('subject', 'hub'), $options);
unset($options);
$mform->addHelpButton('subject', 'subject', 'hub');
$mform->setDefault('subject', $defaultsubject);
$mform->addRule('subject', $strrequired, 'required', null, 'client');
$options = publication::audience_options();
$mform->addElement('select', 'audience', get_string('audience', 'hub'), $options);
$mform->setDefault('audience', $defaultaudience);
unset($options);
$mform->addHelpButton('audience', 'audience', 'hub');
$options = publication::educational_level_options();
$mform->addElement('select', 'educationallevel', get_string('educationallevel', 'hub'), $options);
$mform->setDefault('educationallevel', $defaulteducationallevel);
unset($options);
$mform->addHelpButton('educationallevel', 'educationallevel', 'hub');
$editoroptions = array('maxfiles' => 0, 'maxbytes' => 0, 'trusttext' => false, 'forcehttps' => false);
$mform->addElement('editor', 'creatornotes', get_string('creatornotes', 'hub'), '', $editoroptions);
$mform->addRule('creatornotes', $strrequired, 'required', null, 'client');
$mform->setType('creatornotes', PARAM_CLEANHTML);
$mform->addHelpButton('creatornotes', 'creatornotes', 'hub');
if ($advertise) {
if (!empty($screenshotsnumber)) {
if (!empty($privacy)) {
$screenshothtml = \html_writer::empty_tag('img',
array('src' => $screenshotbaseurl, 'alt' => $defaultfullname));
$screenshothtml = \html_writer::tag('div', $screenshothtml,
array('class' => 'coursescreenshot',
'id' => 'image-' . $hubcourseid));
} else {
$screenshothtml = get_string('existingscreenshotnumber', 'hub', $screenshotsnumber);
}
$mform->addElement('static', 'existingscreenshots', get_string('existingscreenshots', 'hub'), $screenshothtml);
$mform->addHelpButton('existingscreenshots', 'deletescreenshots', 'hub');
$mform->addElement('checkbox', 'deletescreenshots', '', ' ' . get_string('deletescreenshots', 'hub'));
}
$mform->addElement('hidden', 'existingscreenshotnumber', $screenshotsnumber);
$mform->setType('existingscreenshotnumber', PARAM_INT);
}
$mform->addElement('filemanager', 'screenshots', get_string('addscreenshots', 'hub'), null,
array('subdirs' => 0,
'maxbytes' => 1000000,
'maxfiles' => 3
));
$mform->addHelpButton('screenshots', 'screenshots', 'hub');
$this->add_action_buttons(false, $buttonlabel);
// Set default value for creatornotes editor.
$data = new stdClass();
$data->creatornotes = array();
$data->creatornotes['text'] = $defaultcreatornotes;
$data->creatornotes['format'] = $defaultcreatornotesformat;
$this->set_data($data);
}
/**
* Custom form validation
*
* @param array $data
* @param array $files
* @return array
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);
if ($this->_form->_submitValues['subject'] == 'none') {
$errors['subject'] = get_string('mustselectsubject', 'hub');
}
return $errors;
}
}
+409
View File
@@ -0,0 +1,409 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class publication
*
* @package core
* @copyright 2017 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\hub;
defined('MOODLE_INTERNAL') || die();
use moodle_exception;
use moodle_url;
use context_user;
use stdClass;
use html_writer;
/**
* Methods to work with site registration on moodle.net
*
* @package core
* @copyright 2017 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class publication {
/** @var Audience: educators */
const HUB_AUDIENCE_EDUCATORS = 'educators';
/** @var Audience: students */
const HUB_AUDIENCE_STUDENTS = 'students';
/** @var Audience: admins */
const HUB_AUDIENCE_ADMINS = 'admins';
/** @var Educational level: primary */
const HUB_EDULEVEL_PRIMARY = 'primary';
/** @var Educational level: secondary */
const HUB_EDULEVEL_SECONDARY = 'secondary';
/** @var Educational level: tertiary */
const HUB_EDULEVEL_TERTIARY = 'tertiary';
/** @var Educational level: government */
const HUB_EDULEVEL_GOVERNMENT = 'government';
/** @var Educational level: association */
const HUB_EDULEVEL_ASSOCIATION = 'association';
/** @var Educational level: corporate */
const HUB_EDULEVEL_CORPORATE = 'corporate';
/** @var Educational level: other */
const HUB_EDULEVEL_OTHER = 'other';
/**
* Retrieve all the sorted course subjects
*
* @return array $subjects
*/
public static function get_sorted_subjects() {
$subjects = get_string_manager()->load_component_strings('edufields', current_language());
// Sort the subjects.
$return = [];
asort($subjects);
foreach ($subjects as $key => $option) {
$keylength = strlen($key);
if ($keylength == 12) {
$return[$key] = $option; // We want only selectable categories.
}
}
return $return;
}
/**
* Get all publication for a course
*
* @param int $courseid local course id
* @return array of publication
*/
public static function get_course_publications($courseid) {
global $DB;
$sql = 'SELECT cp.id, cp.status, cp.timechecked, cp.timepublished, rh.hubname,
rh.huburl, cp.courseid, cp.enrollable, cp.hubcourseid
FROM {course_published} cp, {registration_hubs} rh
WHERE cp.huburl = rh.huburl and cp.courseid = :courseid and rh.huburl = :huburl
ORDER BY cp.enrollable DESC, rh.hubname, cp.timepublished';
$params = array('courseid' => $courseid, 'huburl' => HUB_MOODLEORGHUBURL);
$records = $DB->get_records_sql($sql, $params);
// Add links for publications that are listed.
foreach ($records as $id => $record) {
if ($record->status) {
$records[$id]->link = new moodle_url(HUB_MOODLEORGHUBURL, ['courseid' => $record->hubcourseid]);
}
}
return $records;
}
/**
* Load publication information from local db
*
* @param int $id
* @param int $courseid if specified publication will be checked that it is in the current course
* @param int $strictness
* @return stdClass
*/
public static function get_publication($id, $courseid = 0, $strictness = IGNORE_MISSING) {
global $DB;
if (!$id && $strictness != MUST_EXIST) {
return false;
}
$params = ['id' => $id, 'huburl' => HUB_MOODLEORGHUBURL];
if ($courseid) {
$params['courseid'] = $courseid;
}
return $DB->get_record('course_published', $params, '*', $strictness);
}
/**
* Update a course publication
* @param stdClass $publication
*/
protected static function update_publication($publication) {
global $DB;
$DB->update_record('course_published', $publication);
}
/**
* Check all courses published from this site if they have been approved
*/
public static function request_status_update() {
global $DB;
list($sitecourses, $coursetotal) = api::get_courses('', 1, 1, ['allsitecourses' => 1]);
// Update status for all these course.
foreach ($sitecourses as $sitecourse) {
// Get the publication from the hub course id.
$publication = $DB->get_record('course_published', ['hubcourseid' => $sitecourse['id']]);
if (!empty($publication)) {
$publication->status = $sitecourse['privacy'];
$publication->timechecked = time();
self::update_publication($publication);
} else {
$msgparams = new stdClass();
$msgparams->id = $sitecourse['id'];
$msgparams->hubname = html_writer::tag('a', 'Moodle.net', array('href' => HUB_MOODLEORGHUBURL));
\core\notification::add(get_string('detectednotexistingpublication', 'hub', $msgparams)); // TODO action?
}
}
}
/**
* Unpublish a course
*
* @param stdClass $publication
*/
public static function unpublish($publication) {
global $DB;
// Unpublish the publication by web service.
api::unregister_courses($publication->hubcourseid);
// Delete the publication from the database.
$DB->delete_records('course_published', array('id' => $publication->id));
// Add confirmation message.
$course = get_course($publication->courseid);
$context = \context_course::instance($course->id);
$publication->courseshortname = format_string($course->shortname, true, ['context' => $context]);
$publication->hubname = 'Moodle.net';
\core\notification::add(get_string('courseunpublished', 'hub', $publication), \core\output\notification::NOTIFY_SUCCESS);
}
/**
* Publish a course
*
* @param \stdClass $courseinfo
* @param \stored_file[] $files
*/
public static function publish_course($courseinfo, $files) {
global $DB;
// Register course and get id of the course on moodle.net ($hubcourseid).
$courseid = $courseinfo->sitecourseid;
try {
$hubcourseid = api::register_course($courseinfo);
} catch (Exception $e) {
throw new moodle_exception('errorcoursepublish', 'hub',
new moodle_url('/course/view.php', array('id' => $courseid)), $e->getMessage());
}
// Insert/update publication record in the local DB.
$publication = $DB->get_record('course_published', array('hubcourseid' => $hubcourseid, 'huburl' => HUB_MOODLEORGHUBURL));
if ($publication) {
$DB->update_record('course_published', ['id' => $publication->id, 'timepublished' => time()]);
} else {
$publication = new stdClass();
$publication->huburl = HUB_MOODLEORGHUBURL;
$publication->courseid = $courseid;
$publication->hubcourseid = $hubcourseid;
$publication->enrollable = (int)$courseinfo->enrollable;
$publication->timepublished = time();
$publication->id = $DB->insert_record('course_published', $publication);
}
// Send screenshots.
if ($files) {
$screenshotnumber = $courseinfo->screenshots - count($files);
foreach ($files as $file) {
$screenshotnumber++;
api::add_screenshot($hubcourseid, $file, $screenshotnumber);
}
}
return $hubcourseid;
}
/**
* Delete all publications
*
* @param int $advertised search for advertised courses
* @param int $shared search for shared courses
* @throws moodle_exception
*/
public static function delete_all_publications($advertised = true, $shared = true) {
global $DB;
if (!$advertised && !$shared) {
// Nothing to do.
return true;
}
$params = ['huburl' => HUB_MOODLEORGHUBURL];
if (!$advertised || !$shared) {
// Retrieve ONLY advertised or ONLY shared.
$params['enrollable'] = $advertised ? 1 : 0;
}
if (!$publications = $DB->get_records('course_published', $params)) {
// Nothing to unpublish.
return true;
}
foreach ($publications as $publication) {
$hubcourseids[] = $publication->hubcourseid;
}
api::unregister_courses($hubcourseids);
// Delete the published courses from local db.
$DB->delete_records('course_published', $params);
return true;
}
/**
* Get an array of all block instances for a given context
* @param int $contextid a context id
* @return array of block instances.
*/
public static function get_block_instances_by_context($contextid) {
global $DB;
return $DB->get_records('block_instances', array('parentcontextid' => $contextid), 'blockname');
}
/**
* List of available educational levels
*
* @param bool $any add option for "Any" (for search forms)
* @return array
*/
public static function educational_level_options($any = false) {
$options = array();
if ($any) {
$options['all'] = get_string('any');
}
$options[self::HUB_EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'hub');
$options[self::HUB_EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'hub');
$options[self::HUB_EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'hub');
$options[self::HUB_EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'hub');
$options[self::HUB_EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'hub');
$options[self::HUB_EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub');
$options[self::HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'hub');
return $options;
}
/**
* List of available audience options
*
* @param bool $any add option for "Any" (for search forms)
* @return array
*/
public static function audience_options($any = false) {
$options = array();
if ($any) {
$options['all'] = get_string('any');
}
$options[self::HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub');
$options[self::HUB_AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub');
$options[self::HUB_AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub');
return $options;
}
/**
* Search for courses
*
* For the list of fields returned for each course see {@link communication::get_courses}
*
* @param string $search search string
* @param bool $downloadable true - return downloadable courses, false - return enrollable courses
* @param array|\stdClass $options other options from the list of allowed options:
* 'ids', 'sitecourseids', 'coverage', 'licenceshortname', 'subject', 'audience',
* 'educationallevel', 'language', 'orderby', 'givememore', 'allsitecourses'
* @return array of two elements: [$courses, $coursetotal]
*/
public static function search($search, $downloadable, $options) {
try {
return api::get_courses($search, $downloadable, !$downloadable, $options);
} catch (moodle_exception $e) {
\core\notification::add(get_string('errorcourselisting', 'block_community', $e->getMessage()),
\core\output\notification::NOTIFY_ERROR);
return [[], 0];
}
}
/**
* Retrieves information about published course
*
* For the list of fields returned for the course see {@link communication::get_courses}
*
* @param stdClass $publication
* @return array|null
*/
public static function get_published_course($publication) {
try {
list($courses, $unused) = api::get_courses('', !$publication->enrollable,
$publication->enrollable, ['ids' => [$publication->hubcourseid], 'allsitecourses' => 1]);
return reset($courses);
} catch (\Exception $e) {
\core\notification::add(get_string('errorcourseinfo', 'hub', $e->getMessage()),
\core\output\notification::NOTIFY_ERROR);
}
return null;
}
/**
* Downloads course backup and stores it in the user private files
*
* @param int $hubcourseid
* @param string $coursename
* @return array
*/
public static function download_course_backup($hubcourseid, $coursename) {
global $CFG, $USER;
require_once($CFG->libdir . "/filelib.php");
make_temp_directory('backup');
$filename = md5(time() . '-' . $hubcourseid . '-'. $USER->id . '-'. random_string(20));
$path = $CFG->tempdir.'/backup/'.$filename.".mbz";
api::download_course_backup($hubcourseid, $path);
$fs = get_file_storage();
$record = new stdClass();
$record->contextid = context_user::instance($USER->id)->id;
$record->component = 'user';
$record->filearea = 'private';
$record->itemid = 0;
$record->filename = urlencode($coursename).'_'.time().".mbz";
$record->filepath = '/downloaded_backup/';
if (!$fs->file_exists($record->contextid, $record->component,
$record->filearea, 0, $record->filepath, $record->filename)) {
$fs->create_file_from_pathname($record, $path);
}
return [$record->filepath . $record->filename, $filename];
}
/**
* Uploads a course backup
*
* @param int $hubcourseid id of the published course on moodle.net, it must be published from this site
* @param \stored_file $backupfile
*/
public static function upload_course_backup($hubcourseid, \stored_file $backupfile) {
api::upload_course_backup($hubcourseid, $backupfile);
}
}
+410
View File
@@ -0,0 +1,410 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class registration
*
* @package core
* @copyright 2017 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\hub;
defined('MOODLE_INTERNAL') || die();
use moodle_exception;
use moodle_url;
use context_system;
use stdClass;
/**
* Methods to use when publishing and searching courses on moodle.net
*
* @package core
* @copyright 2017 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class registration {
/** @var Fields used in a site registration form */
const FORM_FIELDS = ['name', 'description', 'contactname', 'contactemail', 'contactphone', 'imageurl', 'privacy', 'street',
'regioncode', 'countrycode', 'geolocation', 'contactable', 'emailalert', 'language'];
/** @var Site privacy: not displayed */
const HUB_SITENOTPUBLISHED = 'notdisplayed';
/** @var Site privacy: public */
const HUB_SITENAMEPUBLISHED = 'named';
/** @var Site privacy: public and global */
const HUB_SITELINKPUBLISHED = 'linked';
/** @var stdClass cached site registration information */
protected static $registration = null;
/**
* Get site registration
*
* @param bool $confirmed
* @return stdClass|null
*/
protected static function get_registration($confirmed = true) {
global $DB;
if (self::$registration === null) {
self::$registration = $DB->get_record('registration_hubs', ['huburl' => HUB_MOODLEORGHUBURL]);
}
if (self::$registration && (bool)self::$registration->confirmed == (bool)$confirmed) {
return self::$registration;
}
return null;
}
/**
* Same as get_registration except it throws exception if site not registered
*
* @return stdClass
* @throws \moodle_exception
*/
public static function require_registration() {
if ($registration = self::get_registration()) {
return $registration;
}
if (has_capability('moodle/site:config', context_system::instance())) {
throw new moodle_exception('registrationwarning', 'admin', new moodle_url('/admin/registration/index.php'));
} else {
throw new moodle_exception('registrationwarningcontactadmin', 'admin');
}
}
/**
* Checks if site is registered
*
* @return bool
*/
public static function is_registered() {
return self::get_registration() ? true : false;
}
/**
* Returns registration token
*
* @param int $strictness if set to MUST_EXIST and site is not registered will throw an exception
* @return null
* @throws moodle_exception
*/
public static function get_token($strictness = IGNORE_MISSING) {
if ($strictness == MUST_EXIST) {
$registration = self::require_registration();
} else if (!$registration = self::get_registration()) {
return null;
}
return $registration->token;
}
/**
* When was the registration last updated
*
* @return int|null timestamp or null if site is not registered
*/
public static function get_last_updated() {
if ($registration = self::get_registration()) {
return $registration->timemodified;
}
return null;
}
/**
* Calculates and prepares site information to send to moodle.net as part of registration or update
*
* @param array $defaults default values for inputs in the registration form (if site was never registered before)
* @return array site info
*/
public static function get_site_info($defaults = []) {
global $CFG, $DB;
require_once($CFG->libdir . '/badgeslib.php');
require_once($CFG->dirroot . "/course/lib.php");
$siteinfo = array();
$cleanhuburl = clean_param(HUB_MOODLEORGHUBURL, PARAM_ALPHANUMEXT);
foreach (self::FORM_FIELDS as $field) {
$siteinfo[$field] = get_config('hub', 'site_'.$field.'_' . $cleanhuburl);
if ($siteinfo[$field] === false && array_key_exists($field, $defaults)) {
$siteinfo[$field] = $defaults[$field];
}
}
// Statistical data.
$siteinfo['courses'] = $DB->count_records('course') - 1;
$siteinfo['users'] = $DB->count_records('user', array('deleted' => 0));
$siteinfo['enrolments'] = $DB->count_records('role_assignments');
$siteinfo['posts'] = $DB->count_records('forum_posts');
$siteinfo['questions'] = $DB->count_records('question');
$siteinfo['resources'] = $DB->count_records('resource');
$siteinfo['badges'] = $DB->count_records_select('badge', 'status <> ' . BADGE_STATUS_ARCHIVED);
$siteinfo['issuedbadges'] = $DB->count_records('badge_issued');
$siteinfo['participantnumberaverage'] = average_number_of_participants();
$siteinfo['modulenumberaverage'] = average_number_of_courses_modules();
// Version and url.
$siteinfo['moodleversion'] = $CFG->version;
$siteinfo['moodlerelease'] = $CFG->release;
$siteinfo['url'] = $CFG->wwwroot;
// Mobile related information.
$siteinfo['mobileservicesenabled'] = 0;
$siteinfo['mobilenotificationsenabled'] = 0;
$siteinfo['registereduserdevices'] = 0;
$siteinfo['registeredactiveuserdevices'] = 0;
if (!empty($CFG->enablewebservices) && !empty($CFG->enablemobilewebservice)) {
$siteinfo['mobileservicesenabled'] = 1;
$siteinfo['registereduserdevices'] = $DB->count_records('user_devices');
$airnotifierextpath = $CFG->dirroot . '/message/output/airnotifier/externallib.php';
if (file_exists($airnotifierextpath)) { // Maybe some one uninstalled the plugin.
require_once($airnotifierextpath);
$siteinfo['mobilenotificationsenabled'] = \message_airnotifier_external::is_system_configured();
$siteinfo['registeredactiveuserdevices'] = $DB->count_records('message_airnotifier_devices', array('enable' => 1));
}
}
return $siteinfo;
}
/**
* Save registration info locally so it can be retrieved when registration needs to be updated
*
* @param stdClass $formdata data from {@link site_registration_form}
*/
public static function save_site_info($formdata) {
$cleanhuburl = clean_param(HUB_MOODLEORGHUBURL, PARAM_ALPHANUMEXT);
foreach (self::FORM_FIELDS as $field) {
set_config('site_' . $field . '_' . $cleanhuburl, $formdata->$field, 'hub');
}
}
/**
* Updates site registration when "Update reigstration" button is clicked by admin
*/
public static function update_manual() {
global $DB;
if (!$registration = self::get_registration()) {
return false;
}
$siteinfo = self::get_site_info();
try {
api::update_registration($siteinfo);
} catch (moodle_exception $e) {
\core\notification::add(get_string('errorregistrationupdate', 'hub', $e->getMessage()),
\core\output\notification::NOTIFY_ERROR);
return false;
}
$DB->update_record('registration_hubs', ['id' => $registration->id, 'timemodified' => time()]);
\core\notification::add(get_string('siteregistrationupdated', 'hub'),
\core\output\notification::NOTIFY_SUCCESS);
self::$registration = null;
return true;
}
/**
* Updates site registration via cron
*
* @throws moodle_exception
*/
public static function update_cron() {
global $DB;
if (!$registration = self::get_registration()) {
mtrace(get_string('registrationwarning', 'admin'));
return;
}
$siteinfo = self::get_site_info();
api::update_registration($siteinfo);
$DB->update_record('registration_hubs', ['id' => $registration->id, 'timemodified' => time()]);
mtrace(get_string('siteregistrationupdated', 'hub'));
self::$registration = null;
}
/**
* Confirms registration by moodle.net
*
* @param string $token
* @param string $newtoken
* @param string $hubname
* @throws moodle_exception
*/
public static function confirm_registration($token, $newtoken, $hubname) {
global $DB;
$registration = self::get_registration(false);
if (!$registration || $registration->token !== $token) {
throw new moodle_exception('wrongtoken', 'hub', new moodle_url('/admin/registration/index.php'));
}
$record = ['id' => $registration->id];
$record['token'] = $newtoken;
$record['confirmed'] = 1;
$record['hubname'] = $hubname;
$record['timemodified'] = time();
$DB->update_record('registration_hubs', $record);
self::$registration = null;
}
/**
* Retrieve the options for site privacy form element to use in registration form
* @return array
*/
public static function site_privacy_options() {
return [
self::HUB_SITENOTPUBLISHED => get_string('siteprivacynotpublished', 'hub'),
self::HUB_SITENAMEPUBLISHED => get_string('siteprivacypublished', 'hub'),
self::HUB_SITELINKPUBLISHED => get_string('siteprivacylinked', 'hub')
];
}
/**
* Registers a site
*
* This method will make sure that unconfirmed registration record is created and then redirect to
* registration script on https://moodle.net
* Moodle.net will check that the site is accessible, register it and redirect back
* to /admin/registration/confirmregistration.php
*
* @throws \coding_exception
*/
public static function register() {
global $DB;
if (self::is_registered()) {
// Caller of this method must make sure that site is not registered.
throw new \coding_exception('Site already registered');
}
$hub = self::get_registration(false);
if (empty($hub)) {
// Create a new record in 'registration_hubs'.
$hub = new stdClass();
$hub->token = get_site_identifier();
$hub->secret = $hub->token;
$hub->huburl = HUB_MOODLEORGHUBURL;
$hub->hubname = 'Moodle.net';
$hub->confirmed = 0;
$hub->timemodified = time();
$hub->id = $DB->insert_record('registration_hubs', $hub);
self::$registration = null;
}
$params = self::get_site_info();
$params['token'] = $hub->token;
redirect(new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/siteregistration.php', $params));
}
/**
* Unregister site
*
* @param bool $unpublishalladvertisedcourses
* @param bool $unpublishalluploadedcourses
* @return bool
*/
public static function unregister($unpublishalladvertisedcourses, $unpublishalluploadedcourses) {
global $DB;
if (!$hub = self::get_registration()) {
return true;
}
// Unpublish the courses.
try {
publication::delete_all_publications($unpublishalladvertisedcourses, $unpublishalluploadedcourses);
} catch (moodle_exception $e) {
$errormessage = $e->getMessage();
$errormessage .= \html_writer::empty_tag('br') .
get_string('errorunpublishcourses', 'hub');
\core\notification::add(get_string('unregistrationerror', 'hub', $errormessage),
\core\output\notification::NOTIFY_ERROR);
return false;
}
// Course unpublish went ok, unregister the site now.
try {
api::unregister_site();
} catch (moodle_exception $e) {
\core\notification::add(get_string('unregistrationerror', 'hub', $e->getMessage()),
\core\output\notification::NOTIFY_ERROR);
return false;
}
$DB->delete_records('registration_hubs', array('id' => $hub->id));
self::$registration = null;
return true;
}
/**
* Generate a new token for the site that is not registered
*
* @param string $token
* @throws moodle_exception
*/
public static function reset_site_identifier($token) {
global $DB, $CFG;
$registration = self::get_registration(false);
if (!$registration || $registration->token != $token) {
throw new moodle_exception('wrongtoken', 'hub',
new moodle_url('/admin/registration/index.php'));
}
$DB->delete_records('registration_hubs', array('id' => $registration->id));
self::$registration = null;
$CFG->siteidentifier = null;
get_site_identifier();
}
/**
* Returns information about moodle.net
*
* Example of the return array:
* {
* "courses": 384,
* "description": "Moodle.net connects you with free content and courses shared by Moodle ...",
* "downloadablecourses": 190,
* "enrollablecourses": 194,
* "hublogo": 1,
* "language": "en",
* "name": "Moodle.net",
* "sites": 274175,
* "url": "https://moodle.net",
* "imgurl": moodle_url : "https://moodle.net/local/hub/webservice/download.php?filetype=hubscreenshot"
* }
*
* @return array|null
*/
public static function get_moodlenet_info() {
try {
return api::get_hub_info();
} catch (moodle_exception $e) {
// Ignore error, we only need it for displaying information about moodle.net, if this request
// fails, it's not a big deal.
return null;
}
}
}
+226
View File
@@ -0,0 +1,226 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class site_registration_form
*
* @package core
* @copyright 2017 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\hub;
defined('MOODLE_INTERNAL') || die();
use context_course;
global $CFG;
require_once($CFG->libdir . '/formslib.php');
/**
* The site registration form. Information will be sent to moodle.net
*
* @author Jerome Mouneyrac <[email protected]>
* @package core
* @copyright 2017 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class site_registration_form extends \moodleform {
/**
* Form definition
*/
public function definition() {
global $CFG;
$strrequired = get_string('required');
$mform = & $this->_form;
$admin = get_admin();
$site = get_site();
$siteinfo = registration::get_site_info([
'name' => format_string($site->fullname, true, array('context' => context_course::instance(SITEID))),
'description' => $site->summary,
'contactname' => fullname($admin, true),
'contactemail' => $admin->email,
'contactphone' => $admin->phone1,
'street' => '',
'countrycode' => $admin->country ?: $CFG->country,
'regioncode' => '-', // Not supported yet.
'language' => explode('_', current_language())[0],
'geolocation' => '',
'emailalert' => 1,
]);
$mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub'));
$mform->addElement('text', 'name', get_string('sitename', 'hub'),
array('class' => 'registration_textfield'));
$mform->addRule('name', $strrequired, 'required', null, 'client');
$mform->setType('name', PARAM_TEXT);
$mform->addHelpButton('name', 'sitename', 'hub');
$mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), registration::site_privacy_options());
$mform->setType('privacy', PARAM_ALPHA);
$mform->addHelpButton('privacy', 'privacy', 'hub');
unset($options);
$mform->addElement('textarea', 'description', get_string('sitedesc', 'hub'),
array('rows' => 8, 'cols' => 41));
$mform->addRule('description', $strrequired, 'required', null, 'client');
$mform->setType('description', PARAM_TEXT);
$mform->addHelpButton('description', 'sitedesc', 'hub');
$languages = get_string_manager()->get_list_of_languages();
\core_collator::asort($languages);
$mform->addElement('select', 'language', get_string('sitelang', 'hub'), $languages);
$mform->setType('language', PARAM_ALPHANUMEXT);
$mform->addHelpButton('language', 'sitelang', 'hub');
$mform->addElement('textarea', 'street', get_string('postaladdress', 'hub'),
array('rows' => 4, 'cols' => 41));
$mform->setType('street', PARAM_TEXT);
$mform->addHelpButton('street', 'postaladdress', 'hub');
$mform->addElement('hidden', 'regioncode', '-');
$mform->setType('regioncode', PARAM_ALPHANUMEXT);
$countries = ['' => ''] + get_string_manager()->get_list_of_countries();
$mform->addElement('select', 'countrycode', get_string('sitecountry', 'hub'), $countries);
$mform->setType('countrycode', PARAM_ALPHANUMEXT);
$mform->addHelpButton('countrycode', 'sitecountry', 'hub');
$mform->addRule('countrycode', $strrequired, 'required', null, 'client');
$mform->addElement('text', 'geolocation', get_string('sitegeolocation', 'hub'),
array('class' => 'registration_textfield'));
$mform->setType('geolocation', PARAM_RAW);
$mform->addHelpButton('geolocation', 'sitegeolocation', 'hub');
$mform->addElement('text', 'contactname', get_string('siteadmin', 'hub'),
array('class' => 'registration_textfield'));
$mform->addRule('contactname', $strrequired, 'required', null, 'client');
$mform->setType('contactname', PARAM_TEXT);
$mform->addHelpButton('contactname', 'siteadmin', 'hub');
$mform->addElement('text', 'contactphone', get_string('sitephone', 'hub'),
array('class' => 'registration_textfield'));
$mform->setType('contactphone', PARAM_TEXT);
$mform->addHelpButton('contactphone', 'sitephone', 'hub');
$mform->setForceLtr('contactphone');
$mform->addElement('text', 'contactemail', get_string('siteemail', 'hub'),
array('class' => 'registration_textfield'));
$mform->addRule('contactemail', $strrequired, 'required', null, 'client');
$mform->setType('contactemail', PARAM_EMAIL);
$mform->addHelpButton('contactemail', 'siteemail', 'hub');
$options = array();
$options[0] = get_string("registrationcontactno");
$options[1] = get_string("registrationcontactyes");
$mform->addElement('select', 'contactable', get_string('siteregistrationcontact', 'hub'), $options);
$mform->setType('contactable', PARAM_INT);
$mform->addHelpButton('contactable', 'siteregistrationcontact', 'hub');
unset($options);
$options = array();
$options[0] = get_string("registrationno");
$options[1] = get_string("registrationyes");
$mform->addElement('select', 'emailalert', get_string('siteregistrationemail', 'hub'), $options);
$mform->setType('emailalert', PARAM_INT);
$mform->addHelpButton('emailalert', 'siteregistrationemail', 'hub');
unset($options);
// TODO site logo.
$mform->addElement('hidden', 'imageurl', ''); // TODO: temporary.
$mform->setType('imageurl', PARAM_URL);
$mform->addElement('static', 'urlstring', get_string('siteurl', 'hub'), $siteinfo['url']);
$mform->addHelpButton('urlstring', 'siteurl', 'hub');
$mform->addElement('static', 'versionstring', get_string('siteversion', 'hub'), $CFG->version);
$mform->addElement('hidden', 'moodleversion', $siteinfo['moodleversion']);
$mform->setType('moodleversion', PARAM_INT);
$mform->addHelpButton('versionstring', 'siteversion', 'hub');
$mform->addElement('static', 'releasestring', get_string('siterelease', 'hub'), $CFG->release);
$mform->addElement('hidden', 'moodlerelease', $siteinfo['moodlerelease']);
$mform->setType('moodlerelease', PARAM_TEXT);
$mform->addHelpButton('releasestring', 'siterelease', 'hub');
// Display statistic that are going to be retrieve by moodle.net.
$mform->addElement('static', 'courseslabel', get_string('sendfollowinginfo', 'hub'),
" " . get_string('coursesnumber', 'hub', $siteinfo['courses']));
$mform->addHelpButton('courseslabel', 'sendfollowinginfo', 'hub');
$mform->addElement('static', 'userslabel', '',
" " . get_string('usersnumber', 'hub', $siteinfo['users']));
$mform->addElement('static', 'roleassignmentslabel', '',
" " . get_string('roleassignmentsnumber', 'hub', $siteinfo['enrolments']));
$mform->addElement('static', 'postslabel', '',
" " . get_string('postsnumber', 'hub', $siteinfo['posts']));
$mform->addElement('static', 'questionslabel', '',
" " . get_string('questionsnumber', 'hub', $siteinfo['questions']));
$mform->addElement('static', 'resourceslabel', '',
" " . get_string('resourcesnumber', 'hub', $siteinfo['resources']));
$mform->addElement('static', 'badgeslabel', '',
" " . get_string('badgesnumber', 'hub', $siteinfo['badges']));
$mform->addElement('static', 'issuedbadgeslabel', '',
" " . get_string('issuedbadgesnumber', 'hub', $siteinfo['issuedbadges']));
$mform->addElement('static', 'participantnumberaveragelabel', '',
" " . get_string('participantnumberaverage', 'hub', $siteinfo['participantnumberaverage']));
$mform->addElement('static', 'modulenumberaveragelabel', '',
" " . get_string('modulenumberaverage', 'hub', $siteinfo['modulenumberaverage']));
$mobileservicestatus = $siteinfo['mobileservicesenabled'] ? get_string('yes') : get_string('no');
$mform->addElement('static', 'mobileservicesenabledlabel', '',
" " . get_string('mobileservicesenabled', 'hub', $mobileservicestatus));
$mobilenotificationsstatus = $siteinfo['mobilenotificationsenabled'] ? get_string('yes') : get_string('no');
$mform->addElement('static', 'mobilenotificationsenabledlabel', '',
" " . get_string('mobilenotificationsenabled', 'hub', $mobilenotificationsstatus));
$mform->addElement('static', 'registereduserdeviceslabel', '',
" " . get_string('registereduserdevices', 'hub', $siteinfo['registereduserdevices']));
$mform->addElement('static', 'registeredactiveuserdeviceslabel', '',
" " . get_string('registeredactiveuserdevices', 'hub', $siteinfo['registeredactiveuserdevices']));
// Check if it's a first registration or update.
if (registration::is_registered()) {
$buttonlabel = get_string('updatesite', 'hub', 'Moodle.net');
$mform->addElement('hidden', 'update', true);
$mform->setType('update', PARAM_BOOL);
} else {
$buttonlabel = get_string('registersite', 'hub', 'Moodle.net');
}
$this->add_action_buttons(false, $buttonlabel);
$this->set_data($siteinfo);
}
}
@@ -0,0 +1,61 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class site_unregistration_form
*
* @package core
* @copyright 2017 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\hub;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/formslib.php');
/**
* This form display a unregistration form.
*
* @author Jerome Mouneyrac <[email protected]>
* @package core
* @copyright 2017 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class site_unregistration_form extends \moodleform {
/**
* Form definition
*/
public function definition() {
$mform = & $this->_form;
$mform->addElement('header', 'site', get_string('unregister', 'hub'));
$unregisterlabel = get_string('unregister', 'hub');
$mform->addElement('advcheckbox', 'unpublishalladvertisedcourses', '',
' ' . get_string('unpublishalladvertisedcourses', 'hub'));
$mform->setType('unpublishalladvertisedcourses', PARAM_INT);
$mform->addElement('advcheckbox', 'unpublishalluploadedcourses', '',
' ' . get_string('unpublishalluploadedcourses', 'hub'));
$mform->setType('unpublishalluploadedcourses', PARAM_INT);
$mform->addElement('hidden', 'unregistration', 1);
$mform->setType('unregistration', PARAM_INT);
$this->add_action_buttons(true, $unregisterlabel);
}
}
+1 -5
View File
@@ -42,11 +42,7 @@ class registration_cron_task extends scheduled_task {
* Throw exceptions on errors (the job will be retried).
*/
public function execute() {
global $CFG;
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
$registrationmanager = new \registration_manager();
$registrationmanager->cron();
\core\hub\registration::update_cron();
}
}
+21
View File
@@ -2546,8 +2546,29 @@ function xmldb_main_upgrade($oldversion) {
unset_all_config_for_plugin('block_messages');
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2017092202.00);
}
if ($oldversion < 2017092700.00) {
// Rename several fields in registration data to match the names of the properties that are sent to moodle.net.
$renames = [
'site_address_httpsmoodlenet' => 'site_street_httpsmoodlenet',
'site_region_httpsmoodlenet' => 'site_regioncode_httpsmoodlenet',
'site_country_httpsmoodlenet' => 'site_countrycode_httpsmoodlenet'];
foreach ($renames as $oldparamname => $newparamname) {
try {
$DB->execute("UPDATE {config_plugins} SET name = ? WHERE name = ? AND plugin = ?",
[$newparamname, $oldparamname, 'hub']);
} catch (dml_exception $e) {
// Exception can happen if the config value with the new name already exists, ignore it and move on.
}
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2017092700.00);
}
return true;
}
+1 -1
View File
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2017092202.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2017092700.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.