course publication MDL-19315 split /lib/hublib.php into admin/registration/lib.php and course/publish/lib.php

This commit is contained in:
jerome mouneyrac
2010-06-11 03:24:09 +00:00
parent da15f15d48
commit 94788de2a4
14 changed files with 343 additions and 287 deletions
+21 -13
View File
@@ -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');
}
+6 -33
View File
@@ -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;
}
}
?>
-1
View File
@@ -28,7 +28,6 @@
require('../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/hublib.php');
admin_externalpage_setup('registrationindex');
+39 -205
View File
@@ -14,45 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
*
* Hub library
*
* @package hub
* @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
*/
///// IMAGE SIZES /////
/**
* HUB_SITEIMAGEHEIGHT - the maximum height size of a site logo
*/
define('HUB_SITEIMAGEHEIGHT', 150);
/**
* HUB_SITEIMAGEWIDTH - the maximum width size of a site logo
*/
define('HUB_SITEIMAGEWIDTH', 150);
///// MOODLE.ORG URLS //////
/**
* Hub directory url (should be moodle.org)
*/
define('HUB_HUBDIRECTORYURL', "http://hubdirectory.moodle.org");
/**
* Moodle.org url (should be moodle.org)
*/
define('HUB_MOODLEORGHUBURL', "http://hub.moodle.org");
//// SITE PRIVACY /////
@@ -74,95 +37,36 @@ define('HUB_SITELINKPUBLISHED', 'linked');
//// AUDIENCE ////
/**
* Audience: educators
*
* 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
*/
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');
class hub {
///////////////////////////
/// DB Facade functions //
///////////////////////////
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;
@@ -178,6 +82,11 @@ class hub {
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;
@@ -188,79 +97,24 @@ class hub {
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);
}
public function add_course_publication($hubid, $courseid, $enrollable, $hubcourseid) {
/**
* Return all hubs where the site is registered on
*/
public function get_registered_on_hubs() {
global $DB;
$publication = new stdClass();
$publication->hubid = $hubid;
$publication->courseid = $courseid;
$publication->hubcourseid = $hubcourseid;
$publication->enrollable = $enrollable;
$publication->timepublished = time();
$DB->insert_record('course_published', $publication);
$hubs = $DB->get_records('registration_hubs', array());
return $hubs;
}
public function update_enrollable_course_publication($publicationid) {
global $DB;
$publication = new stdClass();
$publication->id = $publicationid;
$publication->timepublished = time();
$DB->update_record('course_published', $publication);
}
public function update_publication($publication) {
global $DB;
$DB->update_record('course_published', $publication);
}
public function get_publications($hubid, $courseid, $enrollable) {
global $DB;
return $DB->get_records('course_published',
array('hubid' => $hubid, 'courseid' => $courseid, 'enrollable' => $enrollable));
}
public function get_publication($hubcourseid) {
global $DB;
return $DB->get_record('course_published',
array('hubcourseid' => $hubcourseid));
}
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.hubid = rh.id and cp.courseid = :courseid
ORDER BY cp.enrollable DESC, rh.hubname, cp.timepublished';
$params = array('courseid' => $courseid);
return $DB->get_records_sql($sql, $params);
}
public function get_registeredhub_by_publication($publicationid) {
global $DB;
$sql = 'SELECT cp.hubid, rh.hubname, rh.huburl, rh.token
FROM {course_published} cp, {registration_hubs} rh
WHERE cp.hubid = rh.id and cp.id = :publicationid';
$params = array('publicationid' => $publicationid);
return $DB->get_record_sql($sql, $params);
}
public function delete_publication($publicationid) {
global $DB;
$DB->delete_records('course_published', array('id' => $publicationid));
}
///////////////////////////
/// Library functions ///
///////////////////////////
/**
* Return site information for a specific hub
* @param string $huburl
@@ -366,26 +220,6 @@ class hub {
}
return $privacystring;
}
/**
* 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;
}
/**
* 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);
}
}
?>
+6 -6
View File
@@ -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;
+1 -1
View File
@@ -30,7 +30,7 @@
*/
require_once($CFG->dirroot.'/lib/formslib.php');
require_once($CFG->dirroot.'/lib/hublib.php');
require_once($CFG->dirroot.'/course/publish/lib.php');
class community_hub_search_form extends moodleform {
+1 -1
View File
@@ -78,7 +78,7 @@ class block_community_manager {
public function block_community_download_course_backup($course) {
global $CFG, $USER;
require_once($CFG->dirroot. "/lib/filelib.php");
require_once($CFG->dirroot. "/lib/hublib.php");
require_once($CFG->dirroot. "/course/publish/lib.php");
//$curl = new curl();
$params['courseid'] = $course->id;
$params['filetype'] = HUB_BACKUP_FILE_TYPE;
+8 -6
View File
@@ -31,7 +31,8 @@
require_once($CFG->dirroot.'/lib/formslib.php');
require_once($CFG->dirroot."/lib/hublib.php");
require_once($CFG->dirroot."/admin/registration/lib.php");
require_once($CFG->dirroot."/course/publish/lib.php");
/*
* Hub selector to choose on which hub we want to publish.
@@ -47,8 +48,8 @@ class hub_publish_selector_form extends moodleform {
$mform->addElement('static', 'info', '', get_string('selecthubinfo', 'hub').html_writer::empty_tag('br'));
$hubmanager = new hub();
$registeredhubs = $hubmanager->get_registered_on_hubs();
$registrationmanager = new registration_manager();
$registeredhubs = $registrationmanager->get_registered_on_hubs();
//Public hub list
$options = array();
@@ -102,9 +103,10 @@ class course_publication_form extends moodleform {
$mform->addElement('hidden', 'hubname', $hubname);
//check on the hub if the course has already been published
$hub = new hub();
$registeredhub = $hub->get_registeredhub($huburl);
$publications = $hub->get_publications($registeredhub->id, $course->id, $advertise);
$registrationmanager = new registration_manager();
$registeredhub = $registrationmanager->get_registeredhub($huburl);
$publicationmanager = new course_publish_manager();
$publications = $publicationmanager->get_publications($registeredhub->id, $course->id, $advertise);
if (!empty($publications)) {
//get the last publication of this course
+3 -3
View File
@@ -26,7 +26,7 @@
require('../../config.php');
require_once($CFG->dirroot.'/lib/hublib.php');
require_once($CFG->dirroot.'/admin/registration/lib.php');
require_once($CFG->dirroot.'/course/publish/forms.php');
$id = optional_param('id', 0, PARAM_INT);
@@ -38,8 +38,8 @@ $PAGE->set_pagelayout('course');
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
$PAGE->set_heading($course->fullname);
$hubmanager = new hub();
$registeredhubs = $hubmanager->get_registered_on_hubs();
$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');
+11 -9
View File
@@ -27,7 +27,8 @@
*/
require('../../config.php');
require_once($CFG->dirroot.'/lib/hublib.php');
require_once($CFG->dirroot.'/admin/registration/lib.php');
require_once($CFG->dirroot.'/course/publish/lib.php');
$id = optional_param('id', 0, PARAM_INT);
@@ -37,14 +38,14 @@ require_login($course);
if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, $id))) {
$hubmanager = new hub();
$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 = $hubmanager->get_registeredhub_by_publication($updatestatusid);
$hub = $publicationmanager->get_registeredhub_by_publication($updatestatusid);
if (empty($hub)) {
$confirmmessage = $OUTPUT->notification(get_string('nocheckstatusfromunreghub', 'hub'));
} else {
@@ -59,11 +60,11 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
//update status for all these course
foreach ($sitecourses as $sitecourse) {
//get the publication from the hub course id
$publication = $hubmanager->get_publication($sitecourse['id']);
$publication = $publicationmanager->get_publication($sitecourse['id']);
if (!empty($publication)) {
$publication->status = $sitecourse['privacy'];
$publication->timechecked = time();
$hubmanager->update_publication($publication);
$publicationmanager->update_publication($publication);
} else {
$msgparams = new stdClass();
$msgparams->id = $sitecourse['id'];
@@ -82,7 +83,8 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
$PAGE->set_heading($course->fullname);
//if the site os registered on no hub display an error page
$registeredhubs = $hubmanager->get_registered_on_hubs();
$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');
@@ -115,7 +117,7 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
$publication->id = $publicationid;
if($confirm) {
//unpublish the publication by web service
$registeredhub = $hubmanager->get_registeredhub($huburl);
$registeredhub = $registrationmanager->get_registeredhub($huburl);
$function = 'hub_unregister_courses';
$params = array(array( $publication->hubcourseid));
$serverurl = $huburl."/local/hub/webservice/webservices.php";
@@ -124,7 +126,7 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
$result = $xmlrpcclient->call($serverurl, $registeredhub->token, $function, $params);
//delete the publication from the database
$hubmanager->delete_publication($publicationid);
$publicationmanager->delete_publication($publicationid);
//display confirmation message
$confirmmessage = $OUTPUT->notification(get_string('courseunpublished', 'hub', $publication), 'notifysuccess');
@@ -153,7 +155,7 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
echo $OUTPUT->heading(get_string('publishcourse', 'hub', $course->shortname), 3, 'main');
echo $renderer->publicationselector($course->id);
$publications = $hubmanager->get_course_publications($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);
+224
View File
@@ -0,0 +1,224 @@
<?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/>.
//// 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($hubid, $courseid, $enrollable, $hubcourseid) {
global $DB;
$publication = new stdClass();
$publication->hubid = $hubid;
$publication->courseid = $courseid;
$publication->hubcourseid = $hubcourseid;
$publication->enrollable = $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 publication for a given hub, a given course and a given type (enrollable or downloadable)
* @param int $hubid
* @param int $courseid
* @param int $enrollable
* @return array of publications
*/
public function get_publications($hubid, $courseid, $enrollable) {
global $DB;
return $DB->get_records('course_published',
array('hubid' => $hubid, 'courseid' => $courseid, 'enrollable' => $enrollable));
}
/**
* Get a publication for a course id on the 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
* @return object publication
*/
public function get_publication($hubcourseid) {
global $DB;
return $DB->get_record('course_published',
array('hubcourseid' => $hubcourseid));
}
/**
* 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.hubid = rh.id 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 cp.hubid, rh.hubname, rh.huburl, rh.token
FROM {course_published} cp, {registration_hubs} rh
WHERE cp.hubid = rh.id 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));
}
/**
* 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);
}
}
?>
+10 -9
View File
@@ -31,7 +31,8 @@
require_once('../../config.php');
require_once($CFG->dirroot.'/course/publish/forms.php');
require_once($CFG->dirroot.'/lib/hublib.php');
require_once($CFG->dirroot.'/admin/registration/lib.php');
require_once($CFG->dirroot.'/course/publish/lib.php');
require_once($CFG->dirroot.'/lib/filelib.php');
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
@@ -68,8 +69,8 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
if (!empty($fromform)) {
$hub = new hub();
$publicationmanager = new course_publish_manager();
//retrieve the course information
$courseinfo = new stdClass();
$courseinfo->fullname = $fromform->name;
@@ -103,7 +104,7 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
//retrieve the content information from the course
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$courseblocks = $hub->get_block_instances_by_context($coursecontext->id, 'blockname');
$courseblocks = $publicationmanager->get_block_instances_by_context($coursecontext->id, 'blockname');
if (!empty($courseblocks)) {
$blockname = '';
@@ -163,8 +164,8 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
// PUBLISH ACTION
//retrieve the token to call the hub
$registeredhub = $hub->get_registeredhub($huburl);
$registrationmanager = new registration_manager();
$registeredhub = $registrationmanager->get_registeredhub($huburl);
//publish the course information
$function = 'hub_register_courses';
@@ -179,13 +180,13 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
}
//save the record into the published course table
$publication = $hub->get_publication($courseids[0]);
$publication = $publicationmanager->get_publication($courseids[0]);
if (empty($publication)) {
//if never been published or if we share, we need to save this new publication record
$hub->add_course_publication($registeredhub->id, $course->id, !$share, $courseids[0]);
$publicationmanager->add_course_publication($registeredhub->id, $course->id, !$share, $courseids[0]);
} else {
//if we update the enrollable course publication we update the publication record
$hub->update_enrollable_course_publication($publication->id);
$publicationmanager->update_enrollable_course_publication($publication->id);
}
+1
View File
@@ -235,6 +235,7 @@ $string['updatesite'] = 'Update registration on {$a}';
$string['updatestatus'] = 'Check it now.';
$string['uploaded'] = 'Uploaded';
$string['url'] = 'hub URL';
$string['urlalreadyregistered'] = 'Your site is already registered on {$a}. It means that your site is not synchronized with {$a} anymore. Alert the hub administrator. Once the hub administrator reset your registration, you will be able to register a new time. Let the hub administrator know if you want to keep your already published courses.';
$string['usersnumber'] = 'Number of users ({$a})';
$string['wrongtoken'] = 'The registration failed. Press continue and try again.';
$string['wrongurlformat'] = 'Bad URL format';
+12
View File
@@ -407,6 +407,18 @@ define('HOMEPAGE_MY', 1);
*/
define('HOMEPAGE_USER', 2);
/**
* Hub directory url (should be moodle.org)
*/
define('HUB_HUBDIRECTORYURL', "http://hubdirectory.moodle.org");
/**
* Moodle.org url (should be moodle.org)
*/
define('HUB_MOODLEORGHUBURL', "http://hub.moodle.org");
/// PARAMETER HANDLING ////////////////////////////////////////////////////
/**