course publication MDL-19315 split /lib/hublib.php into admin/registration/lib.php and course/publish/lib.php
This commit is contained in:
@@ -35,31 +35,39 @@
|
||||
|
||||
require('../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->dirroot.'/lib/hublib.php');
|
||||
|
||||
admin_externalpage_setup('siteregistrationconfirmed');
|
||||
require_once($CFG->dirroot.'/admin/registration/lib.php');
|
||||
|
||||
$newtoken = optional_param('newtoken', '', PARAM_ALPHANUM);
|
||||
$url = optional_param('url', '', PARAM_URL);
|
||||
$hubname = optional_param('hubname', '', PARAM_TEXT);
|
||||
$token = optional_param('token', '', PARAM_ALPHANUM);
|
||||
$error = optional_param('error', '', PARAM_ALPHANUM);
|
||||
|
||||
$hub = new hub();
|
||||
admin_externalpage_setup('siteregistrationconfirmed');
|
||||
|
||||
//check that the token/url couple exist and is not confirmed
|
||||
$registeredhub = $hub->get_unconfirmedhub($url);
|
||||
if (!empty($registeredhub) and $registeredhub->token == $token) {
|
||||
|
||||
$registeredhub->token = $newtoken;
|
||||
$registeredhub->confirmed = 1;
|
||||
$registeredhub->huname = $hubname;
|
||||
$hub->update_registeredhub($registeredhub);
|
||||
//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('registrationconfirmed', 'hub'), 3, 'main');
|
||||
$hublink = html_writer::tag('a', $hubname, array('href' => $url));
|
||||
echo $OUTPUT->notification(get_string('registrationconfirmedon', 'hub', $hublink), 'notifysuccess');
|
||||
|
||||
if (!empty($error) and $error == 'urlalreadyexist') {
|
||||
$notificationmessage = $OUTPUT->notification(get_string('urlalreadyregistered', 'hub', $hublink));
|
||||
} else {
|
||||
$registeredhub->token = $newtoken;
|
||||
$registeredhub->confirmed = 1;
|
||||
$registeredhub->huname = $hubname;
|
||||
$registrationmanager->update_registeredhub($registeredhub);
|
||||
|
||||
$notificationmessage = $OUTPUT->notification(get_string('registrationconfirmedon', 'hub', $hublink), 'notifysuccess');
|
||||
}
|
||||
|
||||
echo $notificationmessage;
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
} else {
|
||||
throw new moodle_exception('wrongtoken', 'hub', $CFG->wwwroot.'/admin/registration/index.php');
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
require_once($CFG->dirroot.'/lib/formslib.php');
|
||||
require_once($CFG->dirroot.'/lib/hublib.php');
|
||||
require_once($CFG->dirroot.'/admin/registration/lib.php');
|
||||
|
||||
/**
|
||||
* This form display a hub selector.
|
||||
@@ -180,10 +180,10 @@ class site_registration_form extends moodleform {
|
||||
$mform->addHelpButton('name', 'sitename', 'hub');
|
||||
|
||||
$options = array();
|
||||
$hub = new hub();
|
||||
$options[HUB_SITENOTPUBLISHED] = $hub->get_site_privacy_string(HUB_SITENOTPUBLISHED);
|
||||
$options[HUB_SITENAMEPUBLISHED] = $hub->get_site_privacy_string(HUB_SITENAMEPUBLISHED);
|
||||
$options[HUB_SITELINKPUBLISHED] = $hub->get_site_privacy_string(HUB_SITELINKPUBLISHED);
|
||||
$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->addHelpButton('privacy', 'privacy', 'hub');
|
||||
@@ -269,10 +269,6 @@ class site_registration_form extends moodleform {
|
||||
unset($options);
|
||||
|
||||
//TODO site logo
|
||||
// $mform->addElement('text','imageurl' , get_string('logourl', 'hub'));
|
||||
// $mform->setType('imageurl', PARAM_URL);
|
||||
// $mform->setDefault('imageurl', $imageurl);
|
||||
// $mform->addHelpButton('imageurl', 'imageurl', 'hub');
|
||||
$mform->addElement('hidden', 'imageurl', ''); //TODO: temporary
|
||||
|
||||
/// Display statistic that are going to be retrieve by the hub
|
||||
@@ -355,7 +351,7 @@ class site_registration_form extends moodleform {
|
||||
}
|
||||
|
||||
//check if it's a first registration or update
|
||||
$hubregistered = $hub->get_registeredhub($huburl);
|
||||
$hubregistered = $registrationmanager->get_registeredhub($huburl);
|
||||
|
||||
if (!empty($hubregistered)) {
|
||||
$buttonlabel = get_string('updatesite', 'hub',
|
||||
@@ -369,29 +365,6 @@ class site_registration_form extends moodleform {
|
||||
$this->add_action_buttons(false, $buttonlabel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the image size is correct
|
||||
*/
|
||||
function validation($data, $files) {
|
||||
global $CFG;
|
||||
|
||||
$errors = array();
|
||||
|
||||
//check if the image (imageurl) has a correct size
|
||||
$imageurl = $this->_form->_submitValues['imageurl'];
|
||||
if (!empty($imageurl)) {
|
||||
list($imagewidth, $imageheight, $imagetype, $imageattr) = getimagesize($imageurl); //getimagesize is a GD function
|
||||
if ($imagewidth > HUB_SITEIMAGEWIDTH or $imageheight > HUB_SITEIMAGEHEIGHT) {
|
||||
$sizestrings = new stdClass();
|
||||
$sizestrings->width = HUB_SITEIMAGEWIDTH;
|
||||
$sizestrings->height = HUB_SITEIMAGEHEIGHT;
|
||||
$errors['imageurl'] = get_string('errorbadimageheightwidth', 'hub', $sizestrings);
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
require('../../config.php');
|
||||
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/hublib.php');
|
||||
|
||||
admin_externalpage_setup('registrationindex');
|
||||
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
<?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/>.
|
||||
|
||||
|
||||
|
||||
|
||||
//// 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 {
|
||||
|
||||
/**
|
||||
* 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;
|
||||
$id = $DB->insert_record('registration_hubs', $hub);
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $communication the hub
|
||||
*/
|
||||
public function update_registeredhub($communication) {
|
||||
global $DB;
|
||||
$DB->update_record('registration_hubs', $communication);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all hubs where the site is registered on
|
||||
*/
|
||||
public function get_registered_on_hubs() {
|
||||
global $DB;
|
||||
$hubs = $DB->get_records('registration_hubs', array());
|
||||
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;
|
||||
//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'] = current_language();
|
||||
$siteinfo['moodleversion'] = $CFG->version;
|
||||
$siteinfo['moodlerelease'] = $CFG->release;
|
||||
$siteinfo['url'] = $CFG->wwwroot;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -36,7 +36,7 @@ require_once('../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->dirroot.'/admin/registration/forms.php');
|
||||
require_once($CFG->dirroot.'/webservice/lib.php');
|
||||
require_once($CFG->dirroot.'/lib/hublib.php');
|
||||
require_once($CFG->dirroot.'/admin/registration/lib.php');
|
||||
|
||||
admin_externalpage_setup('registration');
|
||||
|
||||
@@ -63,9 +63,9 @@ Local Type | Token | Local WS | Remote Type | Remote URL | Confirmed
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
$hub = new hub();
|
||||
$registrationmanager = new registration_manager();
|
||||
|
||||
$registeredhub = $hub->get_registeredhub($huburl);
|
||||
$registeredhub = $registrationmanager->get_registeredhub($huburl);
|
||||
|
||||
$siteregistrationform = new site_registration_form('',
|
||||
array('alreadyregistered' => !empty($registeredhub->token),
|
||||
@@ -111,7 +111,7 @@ if ($update and confirm_sesskey()) {
|
||||
|
||||
//update the registration
|
||||
$function = 'hub_update_site_info';
|
||||
$siteinfo = $hub->get_site_info($huburl);
|
||||
$siteinfo = $registrationmanager->get_site_info($huburl);
|
||||
$params = array($siteinfo);
|
||||
$serverurl = $huburl."/local/hub/webservice/webservices.php";
|
||||
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
|
||||
@@ -127,7 +127,7 @@ if (!empty($fromform) and empty($update) and confirm_sesskey()) {
|
||||
if (!empty($fromform) and confirm_sesskey()) { // if the register button has been clicked
|
||||
$params = (array) $fromform; //we are using the form input as the redirection parameters (token, url and name)
|
||||
|
||||
$unconfirmedhub = $hub->get_unconfirmedhub($huburl);
|
||||
$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();
|
||||
@@ -135,7 +135,7 @@ if (!empty($fromform) and empty($update) and confirm_sesskey()) {
|
||||
$unconfirmedhub->huburl = $huburl;
|
||||
$unconfirmedhub->hubname = $hubname;
|
||||
$unconfirmedhub->confirmed = 0;
|
||||
$unconfirmedhub->id = $hub->add_registeredhub($unconfirmedhub);
|
||||
$unconfirmedhub->id = $registrationmanager->add_registeredhub($unconfirmedhub);
|
||||
}
|
||||
|
||||
$params['token'] = $unconfirmedhub->token;
|
||||
|
||||
Reference in New Issue
Block a user