publication MDL-19315 add hub listing status checking functionality

This commit is contained in:
jerome mouneyrac
2010-05-25 08:26:16 +00:00
parent 89c510174e
commit 2a648ff2c2
7 changed files with 122 additions and 22 deletions

View File

@@ -37,6 +37,45 @@ require_login($course);
if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, $id))) {
$hubmanager = new hub();
$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);
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('', 1, 1, array( 'allsitecourses' => 1));
$serverurl = $hub->huburl."/local/hub/webservice/webservices.php";
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client();
$sitecourses = $xmlrpcclient->call($serverurl, $hub->token, $function, $params);
//update status for all these course
foreach ($sitecourses as $sitecourse) {
//get the publication from the hub course id
$publication = $hubmanager->get_publication($sitecourse['id']);
if (!empty($publication)) {
$publication->status = $sitecourse['privacy'];
$publication->timechecked = time();
$hubmanager->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));
}
}
}
}
$PAGE->set_url('/course/publish/index.php', array('id' => $course->id));
$PAGE->set_pagelayout('course');
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
@@ -44,10 +83,8 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
$renderer = $PAGE->get_renderer('core', 'publish');
$hub = new hub();
/// UNPUBLISH
$confirmmessage = '';
$cancel = optional_param('cancel', 0, PARAM_BOOL);
if (!empty($cancel) and confirm_sesskey()) {
$confirm = optional_param('confirm', 0, PARAM_BOOL);
@@ -68,7 +105,7 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
$publication->id = $publicationid;
if($confirm) {
//unpublish the publication by web service
$registeredhub = $hub->get_registeredhub($huburl);
$registeredhub = $hubmanager->get_registeredhub($huburl);
$function = 'hub_unregister_courses';
$params = array(array( $publication->hubcourseid));
$serverurl = $huburl."/local/hub/webservice/webservices.php";
@@ -77,7 +114,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
$hub->delete_publication($publicationid);
$hubmanager->delete_publication($publicationid);
//display confirmation message
$confirmmessage = $OUTPUT->notification(get_string('courseunpublished', 'hub', $publication), 'notifysuccess');
@@ -106,7 +143,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 = $hub->get_course_publications($course->id);
$publications = $hubmanager->get_course_publications($course->id);
if (!empty($publications)) {
echo $OUTPUT->heading(get_string('publishedon', 'hub'), 3, 'main');
echo $renderer->registeredonhublisting($course->id, $publications);

View File

@@ -58,11 +58,14 @@ class core_publish_renderer extends plugin_renderer_base {
* Display the listing of hub where a course is registered on
*/
public function registeredonhublisting($courseid, $publications) {
global $OUTPUT;
global $OUTPUT, $CFG;
$table = new html_table();
$table->head = array(get_string('type', 'hub'), get_string('hub', 'hub'), get_string('date'), get_string('operation', 'hub'));
$table->size = array('10%', '50%', '30%', '%10');
$table->head = array(get_string('type', 'hub'), get_string('hub', 'hub'),
get_string('date'), get_string('status', 'hub'), get_string('operation', 'hub'));
$table->size = array('10%', '40%', '20%', '%10', '%15');
$brtag = html_writer::empty_tag('br');
foreach ($publications as $publication) {
@@ -86,8 +89,7 @@ class core_publish_renderer extends plugin_renderer_base {
$cancelbutton->class = 'centeredbutton';
$cancelbuttonhtml = $OUTPUT->render($cancelbutton);
if (!empty($updatebuttonhtml)) {
$brtag = html_writer::empty_tag('br');
if (!empty($updatebuttonhtml)) {
$operations = $updatebuttonhtml . $brtag . $cancelbuttonhtml;
} else {
$operations = $cancelbuttonhtml;
@@ -96,15 +98,27 @@ class core_publish_renderer extends plugin_renderer_base {
$hubname = html_writer::tag('a', $publication->hubname?$publication->hubname:$publication->huburl,
array('href' => $publication->huburl));
if ($publication->status == 0) {
$status = get_string('statusunpublished', 'hub');
} else {
$status = get_string('statuspublished', 'hub');
}
$status .= $brtag . html_writer::tag('a', get_string('updatestatus', 'hub'),
array('href' => $CFG->wwwroot.'/course/publish/index.php?id='.$courseid.
"&updatestatusid=".$publication->id."&sesskey=".sesskey())) .
$brtag . get_string('lasttimechecked', 'hub') . ": " . userdate($publication->timechecked);
//add button cells
$cells = array($publication->enrollable?get_string('advertised', 'hub'):get_string('uploaded', 'hub'),
$hubname, userdate($publication->timepublished),$operations);
$cells = array($publication->enrollable?get_string('advertised', 'hub'):get_string('shared', 'hub'),
$hubname, userdate($publication->timepublished), $status, $operations);
$row = new html_table_row($cells);
$table->data[] = $row;
}
return html_writer::table($table);
$contenthtml = html_writer::table($table);
return $contenthtml;
}

View File

@@ -72,6 +72,7 @@ $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 publication to this course which seems to not exist anymore. Alert this hub administrator that the publication number {$a->id} should not be listed anymore.';
$string['downloadable'] = 'Downloadable';
$string['downloadconfirmed'] = 'The backup has been saved into your personal area';
$string['educationallevel'] = 'Educational level';
@@ -96,6 +97,7 @@ $string['imageurl_help'] = 'This image will be displayed on the hub. This image
$string['information'] = 'Information';
$string['language'] = 'Language';
$string['language_help'] = 'The main language of this course.';
$string['lasttimechecked'] = 'Last time checked';
$string['licence'] = 'Licence';
$string['licence_help'] = 'Select the licence you want to distribute your course under.';
$string['logourl'] = 'Logo URL';
@@ -110,6 +112,7 @@ All new registrations are verified manually before they are added to the list, b
$string['name'] = 'Name';
$string['name_help'] = 'This name will be showing in the course listing.';
$string['no'] = 'No';
$string['nocheckstatusfromunreghub'] = 'The site is not registered on the hub, cannot check the status.';
$string['nohubselected'] = 'No hub selected';
$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.';
@@ -161,6 +164,7 @@ $string['sendfollowinginfo'] = 'Send the following information:';
$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['shareonmoodleorg'] = 'Upload this course to Moodle.org';
@@ -179,11 +183,15 @@ $string['subject_help'] = 'The main course subject.';
$string['specifichub'] = 'Specific hub';
$string['specifichubregistrationdetail'] = 'You can also register your site with other community hubs.';
$string['statistics'] = 'Statistics privacy';
$string['status'] = 'Hub listing';
$string['statuspublished'] = 'Listed';
$string['statusunpublished'] = 'Not Listed';
$string['subject'] = 'Subject';
$string['tags'] = 'Tags';
$string['tags_help'] = 'Your course can be searched against these tag words. Separate your tag words with a comma. Example: math, algebric, geometry';
$string['trustme'] = 'Trust';
$string['type'] = 'Type';
$string['type'] = 'Advertised / Shared';
$string['unknownstatus'] = 'unknown.';
$string['unlistedurl'] = 'Unlisted hub URL';
$string['unprioritise'] = 'Unprioritise';
$string['unpublish'] = 'Unpublish';
@@ -192,6 +200,7 @@ $string['unpublishcourse'] = 'Unpublish {$a}';
$string['untrustme'] = 'Untrust';
$string['update'] = 'Update';
$string['updatesite'] = 'Update registration on {$a}';
$string['updatestatus'] = 'Check it now.';
$string['uploaded'] = 'Uploaded';
$string['url'] = 'hub URL';
$string['usersnumber'] = 'Number of users ({$a})';

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20100522" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20100525" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@@ -2618,7 +2618,9 @@
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="the id of the published course" PREVIOUS="hubid" NEXT="timepublished"/>
<FIELD NAME="timepublished" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The time when the publication occurred" PREVIOUS="courseid" NEXT="enrollable"/>
<FIELD NAME="enrollable" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" COMMENT="1 = enrollable, 0 = downloadable" PREVIOUS="timepublished" NEXT="hubcourseid"/>
<FIELD NAME="hubcourseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="the course id on the hub server" PREVIOUS="enrollable"/>
<FIELD NAME="hubcourseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="the course id on the hub server" PREVIOUS="enrollable" NEXT="status"/>
<FIELD NAME="status" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="is the publication published or not" PREVIOUS="hubcourseid" NEXT="timechecked"/>
<FIELD NAME="timechecked" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="the last time the status has been checked" PREVIOUS="status"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>

View File

@@ -4114,6 +4114,30 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
}
if ($result && $oldversion < 2010052401) {
/// Define field status to be added to course_published
$table = new xmldb_table('course_published');
$field = new xmldb_field('status', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0', 'hubcourseid');
/// Conditionally launch add field status
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Define field timechecked to be added to course_published
$table = new xmldb_table('course_published');
$field = new xmldb_field('timechecked', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'status');
/// Conditionally launch add field timechecked
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Main savepoint reached
upgrade_main_savepoint($result, 2010052401);
}
return $result;
}

View File

@@ -54,7 +54,6 @@ define('HUBDIRECTORYURL', "http://hubdirectory.moodle.org");
define('MOODLEORGHUBURL', "http://hub.moodle.org");
//// SITE PRIVACY /////
/**
@@ -209,6 +208,11 @@ class hub {
$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;
@@ -224,11 +228,21 @@ class hub {
public function get_course_publications($courseid) {
global $DB;
$sql = 'SELECT cp.id, cp.timepublished, rh.hubname, rh.huburl, cp.courseid, cp.enrollable, cp.hubcourseid
$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
WHERE cp.hubid = rh.id and cp.courseid = :courseid
ORDER BY cp.enrollable DESC, rh.hubname, cp.timepublished';
return $DB->get_records_sql($sql);
$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) {

View File

@@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
$version = 2010052400; // YYYYMMDD = date of the last version bump
$version = 2010052401; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 Preview 2 (Build: 20100525)'; // Human-friendly version name