From 2a648ff2c29a6877a1844b404db8d8756b4fcd2c Mon Sep 17 00:00:00 2001 From: jerome mouneyrac Date: Tue, 25 May 2010 08:26:16 +0000 Subject: [PATCH] publication MDL-19315 add hub listing status checking functionality --- course/publish/index.php | 49 ++++++++++++++++++++++++++++++++----- course/publish/renderer.php | 30 +++++++++++++++++------ lang/en/hub.php | 11 ++++++++- lib/db/install.xml | 6 +++-- lib/db/upgrade.php | 24 ++++++++++++++++++ lib/hublib.php | 22 ++++++++++++++--- version.php | 2 +- 7 files changed, 122 insertions(+), 22 deletions(-) diff --git a/course/publish/index.php b/course/publish/index.php index 63148e6e9be..25aa9775e21 100644 --- a/course/publish/index.php +++ b/course/publish/index.php @@ -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); diff --git a/course/publish/renderer.php b/course/publish/renderer.php index 0a77eccaa54..f59b6bd54fd 100644 --- a/course/publish/renderer.php +++ b/course/publish/renderer.php @@ -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; } diff --git a/lang/en/hub.php b/lang/en/hub.php index 891a32f2f20..4a7af37304d 100644 --- a/lang/en/hub.php +++ b/lang/en/hub.php @@ -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})'; diff --git a/lib/db/install.xml b/lib/db/install.xml index f5c2ed49ddf..8c019e01e8d 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -2618,7 +2618,9 @@ - + + + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 97b3032dfca..a93050e75ee 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -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; } diff --git a/lib/hublib.php b/lib/hublib.php index 9f70aa4c17b..5af65d8c11b 100644 --- a/lib/hublib.php +++ b/lib/hublib.php @@ -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) { diff --git a/version.php b/version.php index bd61ff0d64e..2b6cd79eefe 100644 --- a/version.php +++ b/version.php @@ -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