From 178097a0c0a724ec4d99614bdc16166df7c7c3fd Mon Sep 17 00:00:00 2001 From: jerome mouneyrac Date: Thu, 13 May 2010 08:49:13 +0000 Subject: [PATCH] course publication MDL-19315 retrieve previously published information when republished --- blocks/community/communitycourse.php | 2 +- course/publish/forms.php | 106 +++++++++++++++++++++------ course/publish/publish.php | 12 +++ lang/en/hub.php | 1 + lib/db/install.xml | 19 ++++- lib/db/upgrade.php | 40 ++++++++++ lib/hublib.php | 34 +++++++++ version.php | 2 +- 8 files changed, 188 insertions(+), 28 deletions(-) diff --git a/blocks/community/communitycourse.php b/blocks/community/communitycourse.php index 64804d37f5a..ca9d9a99ef9 100644 --- a/blocks/community/communitycourse.php +++ b/blocks/community/communitycourse.php @@ -110,7 +110,7 @@ if (!empty($fromform)) { $function = 'hub_get_courses'; - $params = array($search, $downloadable, $options); + $params = array($search, $downloadable, !$downloadable, $options); $serverurl = $huburl."/local/hub/webservice/webservices.php"; require_once($CFG->dirroot."/webservice/xmlrpc/lib.php"); $xmlrpcclient = new webservice_xmlrpc_client(); diff --git a/course/publish/forms.php b/course/publish/forms.php index 9c4855adc63..be7d477bb8c 100644 --- a/course/publish/forms.php +++ b/course/publish/forms.php @@ -94,18 +94,82 @@ class course_publication_form extends moodleform { $mform->addElement('hidden', 'huburl', $huburl); $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); + + 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('', $share, !$share, $options); + $serverurl = $huburl."/local/hub/webservice/webservices.php"; + require_once($CFG->dirroot."/webservice/xmlrpc/lib.php"); + $xmlrpcclient = new webservice_xmlrpc_client(); + $publishedcourses = $xmlrpcclient->call($serverurl, $registeredhub->token, $function, $params); + } + + + if (!empty($publishedcourses)) { + $publishedcourse = $publishedcourses[0]; + $defaultfullname = $publishedcourse['fullname']; + $defaultshortname = $publishedcourse['shortname']; + $defaultsummary = $publishedcourse['description']; + $defaultlanguage = $publishedcourse['language']; + $defaultpublishername = $publishedcourse['publishername']; + $defaultcontributornames = $publishedcourse['contributornames']; + $defaultcoverage = $publishedcourse['coverage']; + $defaultcreatorname = $publishedcourse['creatorname']; + $defaultlicenceshortname = $publishedcourse['licenceshortname']; + $defaultsubject = $publishedcourse['subject']; + $defaultaudience = $publishedcourse['audience']; + $defaulteducationallevel = $publishedcourse['educationallevel']; + $defaultcreatornotes = $publishedcourse['creatornotes']; + + } else { + $defaultfullname = $course->fullname; + $defaultshortname = $course->shortname; + $defaultsummary = $course->summary; + 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; + $defaultcontributornames = ''; + $defaultcoverage = ''; + $defaultcreatorname = $USER->firstname.' '.$USER->lastname; + $defaultlicenceshortname = 'cc'; + $defaultsubject = ''; + $defaultaudience = AUDIENCE_EDUCATORS; + $defaulteducationallevel = EDULEVEL_TERTIARY; + $defaultcreatornotes = ''; + } + + //the input parameters $mform->addElement('header', 'moodle', get_string('publicationinfo', 'hub')); $mform->addElement('text','name' , get_string('coursename', 'hub')); $mform->addRule('name', $strrequired, 'required', null, 'client'); $mform->setType('name', PARAM_TEXT); - $mform->setDefault('name', $course->fullname); + $mform->setDefault('name', $defaultfullname); $mform->addElement('hidden', 'id', $this->_customdata['id']); if ($share) { $buttonlabel = get_string('shareon', 'hub', !empty($hubname)?$hubname:$huburl); + $mform->addElement('hidden', 'share', $share); $mform->addElement('text', 'demourl', get_string('demourl', 'hub')); @@ -115,7 +179,11 @@ class course_publication_form extends moodleform { } if ($advertise) { - $buttonlabel = get_string('advertiseon', 'hub', !empty($hubname)?$hubname:$huburl); + if (empty($publications)) { + $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->addElement('static', 'courseurl', get_string('courseurl', 'hub')); @@ -124,47 +192,38 @@ class course_publication_form extends moodleform { } $mform->addElement('text', 'courseshortname',get_string('courseshortname', 'hub')); - $mform->setDefault('courseshortname', $course->shortname); + $mform->setDefault('courseshortname', $defaultshortname); $mform->addHelpButton('courseshortname', 'courseshortname', 'hub'); $mform->addElement('textarea', 'description', get_string('description'), array('rows'=>10)); $mform->addRule('description', $strrequired, 'required', null, 'client'); - $mform->setDefault('description', $course->summary); + $mform->setDefault('description', $defaultsummary); $mform->setType('description', PARAM_TEXT); $languages = get_string_manager()->get_list_of_languages(); - $mform->addElement('select', 'language',get_string('language'), $languages); - if (empty($course->lang)) { - $language = get_site()->lang; - if (empty($language)) { - $mform->setDefault('language', current_language()); - } else { - $mform->setDefault('language', $language); - } - } else { - $mform->setDefault('language', $course->lang); - } - + $mform->addElement('select', 'language',get_string('language'), $languages); + $mform->setDefault('language', $defaultlanguage); $mform->addElement('text', 'publishername',get_string('publishername', 'hub')); - $mform->setDefault('publishername', $USER->firstname.' '.$USER->lastname); + $mform->setDefault('publishername', $defaultpublishername); $mform->addRule('publishername', $strrequired, 'required', null, 'client'); $mform->addHelpButton('publishername', 'publishername', 'hub'); $mform->addElement('text', 'contributornames', get_string('contributornames', 'hub')); - $mform->setDefault('contributornames', ''); + $mform->setDefault('contributornames', $defaultcontributornames); $mform->addHelpButton('contributornames', 'contributornames', 'hub'); $mform->addElement('text','coverage' , get_string('tags', 'hub')); $mform->setType('coverage', PARAM_TEXT); + $mform->setDefault('coverage', $defaultcoverage); $mform->addHelpButton('coverage', 'tags', 'hub'); $mform->addElement('text', 'creatorname', get_string('creatorname', 'hub')); $mform->addRule('creatorname', $strrequired, 'required', null, 'client'); $mform->setType('creatorname', PARAM_TEXT); - $mform->setDefault('creatorname', $USER->firstname.' '.$USER->lastname); + $mform->setDefault('creatorname', $defaultcreatorname); $mform->addHelpButton('creatorname', 'creatorname', 'hub'); require_once($CFG->dirroot."/lib/licenselib.php"); @@ -175,7 +234,7 @@ class course_publication_form extends moodleform { $options[$license->shortname] = get_string($license->shortname, 'license'); } $mform->addElement('select', 'licence', get_string('license'), $options); - $mform->setDefault('licence', 'cc'); + $mform->setDefault('licence', $defaultlicenceshortname); unset($options); $mform->addHelpButton('licence', 'licence', 'hub'); @@ -183,13 +242,14 @@ class course_publication_form extends moodleform { $mform->addElement('select', 'subject', get_string('subject', 'hub'), $options); unset($options); $mform->addHelpButton('subject', 'subject', 'hub'); + $mform->setDefault('subject', $defaultsubject); $options = array(); $options[AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub'); $options[AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub'); $options[AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub'); $mform->addElement('select', 'audience', get_string('audience', 'hub'), $options); - $mform->setDefault('audience', AUDIENCE_EDUCATORS); + $mform->setDefault('audience', $defaultaudience); unset($options); $mform->addHelpButton('audience', 'audience', 'hub'); @@ -202,14 +262,14 @@ class course_publication_form extends moodleform { $options[EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub'); $options[EDULEVEL_OTHER] = get_string('edulevelother', 'hub'); $mform->addElement('select', 'educationallevel', get_string('educationallevel', 'hub'), $options); - $mform->setDefault('educationallevel', EDULEVEL_TERTIARY); + $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->setDefault('creatornotes', ''); + $mform->setDefault('creatornotes', $defaultcreatornotes); $mform->setType('creatornotes', PARAM_CLEANHTML); $mform->addHelpButton('creatornotes', 'creatornotes', 'hub'); diff --git a/course/publish/publish.php b/course/publish/publish.php index 95ea168c5c0..c275bc7d70e 100644 --- a/course/publish/publish.php +++ b/course/publish/publish.php @@ -80,6 +80,7 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, $creatornotes = optional_param('creatornotes', false, PARAM_RAW); $courseinfo->creatornotes = $creatornotes['text']; $courseinfo->creatornotesformat = $creatornotes['format']; + $courseinfo->sitecourseid = $id; if ($share) { $courseinfo->demourl = optional_param('demourl', false, PARAM_URL); $courseinfo->enrollable = false; @@ -137,6 +138,17 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, $courseregisteredmsg = $OUTPUT->notification(get_string('coursepublished', 'hub'), 'notifysuccess'); +//save the record into the published course table + $publication = $hub->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]); + } else { + //if we update the enrollable course publication we update the publication record + $hub->update_enrollable_course_publication($publication->id); + } + + // SEND FILES // send screenshots diff --git a/lang/en/hub.php b/lang/en/hub.php index ef00483772e..b8c28dc8289 100644 --- a/lang/en/hub.php +++ b/lang/en/hub.php @@ -27,6 +27,7 @@ $string['addedtoblock'] = 'Course added to block'; $string['advertise'] = 'Publish as enrollable'; $string['advertiseon'] = 'Publish as enrollable on {$a}'; +$string['readvertiseon'] = 'Update publication information on {$a}'; $string['advertiseonhub'] = 'Publish as enrollable on hub'; $string['advertiseonmoodleorg'] = 'Publish as enrollable on Moodle.org'; $string['advertiseonspecifichub'] = 'Publish as enrollable on a specific hub'; diff --git a/lib/db/install.xml b/lib/db/install.xml index c5baf62657e..33807c4503e 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -2594,7 +2594,7 @@ - +
@@ -2610,5 +2610,18 @@
+ + + + + + + + + + + + +
-
+ \ No newline at end of file diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 2377a755bb4..49bb9ed6455 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -4017,6 +4017,46 @@ AND EXISTS (SELECT 'x' upgrade_main_savepoint($result, 2010050411); } + if ($result && $oldversion < 2010050413) { + + /// Define table published_courses to be created + $table = new xmldb_table('published_courses'); + + /// Adding fields to table published_courses + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('hubid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); + $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); + $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); + $table->add_field('enrollable', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); + + /// Adding keys to table published_courses + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + + /// Conditionally launch create table for published_courses + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2010050413); + } + + if ($result && $oldversion < 2010050414) { + + /// Define field hubcourseid to be added to published_courses + $table = new xmldb_table('published_courses'); + $field = new xmldb_field('hubcourseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'enrollable'); + + /// Conditionally launch add field hubcourseid + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2010050414); + } + + return $result; } diff --git a/lib/hublib.php b/lib/hublib.php index 71b046c63fb..18aa6f3b02f 100644 --- a/lib/hublib.php +++ b/lib/hublib.php @@ -190,6 +190,40 @@ class hub { } + 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->time = time(); + $DB->insert_record('published_courses', $publication); + } + + public function update_enrollable_course_publication($publicationid) { + global $DB; + $publication = new stdClass(); + $publication->id = $publicationid; + $publication->time = time(); + $DB->update_record('published_courses', $publication); + } + + + public function get_publications($hubid, $courseid, $enrollable) { + global $DB; + return $DB->get_records('published_courses', + array('hubid' => $hubid, 'courseid' => $courseid, 'enrollable' => $enrollable)); + } + + public function get_publication($hubcourseid) { + global $DB; + return $DB->get_record('published_courses', + array('hubcourseid' => $hubcourseid)); + } + + + /////////////////////////// /// Library functions /// /////////////////////////// diff --git a/version.php b/version.php index 8a23285701a..3eb67fb8c80 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 = 2010050412; // YYYYMMDD = date of the last version bump + $version = 2010050414; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 Preview 1 (Build: 20100513)'; // Human-friendly version name