diff --git a/course/publish/backup.php b/course/publish/backup.php index ebd5c497caf..9899b5f0fd1 100644 --- a/course/publish/backup.php +++ b/course/publish/backup.php @@ -35,16 +35,12 @@ define('NO_OUTPUT_BUFFERING', true); require_once('../../config.php'); require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php'); require_once($CFG->dirroot . '/backup/moodle2/backup_plan_builder.class.php'); -require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php'); -require_once($CFG->dirroot . '/course/publish/lib.php'); require_once($CFG->libdir . '/filelib.php'); //retrieve initial page parameters $id = required_param('id', PARAM_INT); $hubcourseid = required_param('hubcourseid', PARAM_INT); -$huburl = required_param('huburl', PARAM_URL); -$hubname = optional_param('hubname', '', PARAM_TEXT); //some permissions and parameters checking $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); @@ -67,7 +63,7 @@ if (!($bc = backup_ui::load_controller($backupid))) { backup::INTERACTIVE_YES, backup::MODE_HUB, $USER->id); } $backup = new backup_ui($bc, - array('id' => $id, 'hubcourseid' => $hubcourseid, 'huburl' => $huburl, 'hubname' => $hubname)); + array('id' => $id, 'hubcourseid' => $hubcourseid, 'huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.net')); $backup->process(); if ($backup->get_stage() == backup_ui::STAGE_FINAL) { $backup->execute(); @@ -78,7 +74,7 @@ if ($backup->get_stage() == backup_ui::STAGE_FINAL) { if ($backup->get_stage() !== backup_ui::STAGE_COMPLETE) { $renderer = $PAGE->get_renderer('core', 'backup'); echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('publishcourseon', 'hub', !empty($hubname)?$hubname:$huburl), 3, 'main'); + echo $OUTPUT->heading(get_string('publishcourseon', 'hub', 'Moodle.net'), 3, 'main'); if ($backup->enforce_changed_dependencies()) { debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER); } @@ -93,10 +89,6 @@ $backupfile = $bc->get_results(); $backupfile = $backupfile['backup_destination']; //END backup processing -//retrieve the token to call the hub -$registrationmanager = new registration_manager(); -$registeredhub = $registrationmanager->get_registeredhub($huburl); - //display the sending file page echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('sendingcourse', 'hub'), 3, 'main'); @@ -108,19 +100,13 @@ if (ob_get_level()) { flush(); //send backup file to the hub -$curl = new curl(); -$params = array(); -$params['filetype'] = HUB_BACKUP_FILE_TYPE; -$params['courseid'] = $hubcourseid; -$params['file'] = $backupfile; -$params['token'] = $registeredhub->token; -$curl->post($huburl . "/local/hub/webservice/upload.php", $params); +\core\hub\publication::upload_course_backup($hubcourseid, $backupfile); //delete the temp backup file from user_tohub aera $backupfile->delete(); $bc->destroy(); //Output sending success -echo $renderer->sentbackupinfo($id, $huburl, $hubname); +echo $renderer->sentbackupinfo($id, HUB_MOODLEORGHUBURL, 'Moodle.net'); echo $OUTPUT->footer(); diff --git a/course/publish/forms.php b/course/publish/forms.php index b5121159a6a..288475e0aae 100644 --- a/course/publish/forms.php +++ b/course/publish/forms.php @@ -33,4 +33,4 @@ defined('MOODLE_INTERNAL') || die(); debugging('Support for alternative hubs has been removed from Moodle in 3.4. For communication with moodle.net ' . - 'see lib/classes/moodlenet/ .', DEBUG_DEVELOPER); + 'see lib/classes/hub/ .', DEBUG_DEVELOPER); diff --git a/course/publish/hubselector.php b/course/publish/hubselector.php index c599eb62a8c..e731d4dceae 100644 --- a/course/publish/hubselector.php +++ b/course/publish/hubselector.php @@ -26,52 +26,5 @@ require('../../config.php'); -require_once($CFG->dirroot.'/' . $CFG->admin . '/registration/lib.php'); -require_once($CFG->dirroot.'/course/publish/forms.php'); - $id = required_param('id', PARAM_INT); -$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); -require_login($course); - -$PAGE->set_url('/course/publish/hubselector.php', array('id' => $course->id)); -$PAGE->set_pagelayout('incourse'); -$PAGE->set_title(get_string('course') . ': ' . $course->fullname); -$PAGE->set_heading($course->fullname); - -$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'); - echo $OUTPUT->box(get_string('notregisteredonhub', 'hub')); - echo $OUTPUT->footer(); - die(); -} - - -$share = optional_param('share', false, PARAM_BOOL); -$advertise = optional_param('advertise', false, PARAM_BOOL); -$hubselectorform = new hub_publish_selector_form('', - array('id' => $id, 'share' => $share, 'advertise' => $advertise)); -$fromform = $hubselectorform->get_data(); - -//// Redirect to the registration form if an URL has been chosen //// -$huburl = optional_param('huburl', false, PARAM_URL); - -//redirect -if (!empty($huburl) and confirm_sesskey()) { - $hubname = optional_param(clean_param($huburl, PARAM_ALPHANUMEXT), '', PARAM_TEXT); - $params = array('sesskey' => sesskey(), 'id' => $id, - 'huburl' => $huburl, 'hubname' => $hubname, 'share' => $share, 'advertise' => $advertise); - redirect(new moodle_url($CFG->wwwroot."/course/publish/metadata.php", - $params)); -} - - -//// OUTPUT //// - - -echo $OUTPUT->header(); -echo $OUTPUT->heading(get_string('publishon', 'hub'), 3, 'main'); -$hubselectorform->display(); -echo $OUTPUT->footer(); \ No newline at end of file +redirect(new moodle_url('/course/publish/index.php', ['id' => $id])); \ No newline at end of file diff --git a/course/publish/index.php b/course/publish/index.php index 1012c8d1f6e..7576f9fbf29 100644 --- a/course/publish/index.php +++ b/course/publish/index.php @@ -27,155 +27,70 @@ */ require('../../config.php'); -require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php'); -require_once($CFG->dirroot . '/course/publish/lib.php'); -$id = required_param('id', PARAM_INT); -$hubname = optional_param('hubname', 0, PARAM_TEXT); -$huburl = optional_param('huburl', 0, PARAM_URL); +$courseid = required_param('id', PARAM_INT); // Course id. +$publicationid = optional_param('publicationid', 0, PARAM_INT); // Id of course publication to unpublish. -$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); +require_login($courseid); +$shortname = format_string($COURSE->shortname); -require_login($course); -$context = context_course::instance($course->id); -$shortname = format_string($course->shortname, true, array('context' => $context)); - -$PAGE->set_url('/course/publish/index.php', array('id' => $course->id)); +$PAGE->set_url('/course/publish/index.php', array('id' => $courseid)); $PAGE->set_pagelayout('incourse'); -$PAGE->set_title(get_string('course') . ': ' . $course->fullname); -$PAGE->set_heading($course->fullname); +$PAGE->set_title(get_string('publish') . ': ' . $COURSE->fullname); +$PAGE->set_heading($COURSE->fullname); -//check that the PHP xmlrpc extension is enabled -if (!extension_loaded('xmlrpc')) { - $notificationerror = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); - $notificationerror .= get_string('xmlrpcdisabledpublish', 'hub'); +require_capability('moodle/course:publish', context_course::instance($courseid)); + +// If the site is not registered display an error page. +if (!\core\hub\registration::is_registered()) { echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main'); - echo $OUTPUT->notification($notificationerror); + echo $OUTPUT->heading(get_string('publishcourseon', 'hub', 'Moodle.net'), 3, 'main'); + echo $OUTPUT->box(get_string('notregisteredonhub', 'hub')); + if (has_capability('moodle/site:config', context_system::instance())) { + echo $OUTPUT->single_button(new moodle_url('/admin/registration/index.php'), get_string('register', 'admin')); + } echo $OUTPUT->footer(); die(); } -if (has_capability('moodle/course:publish', context_course::instance($id))) { - - $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 = $publicationmanager->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('search' => '', 'downloadable' => 1, - 'enrollable' => 1, 'options' => array( 'allsitecourses' => 1)); - $serverurl = $hub->huburl."/local/hub/webservice/webservices.php"; - require_once($CFG->dirroot."/webservice/xmlrpc/lib.php"); - $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token); - $result = $xmlrpcclient->call($function, $params); - $sitecourses = $result['courses']; - - //update status for all these course - foreach ($sitecourses as $sitecourse) { - //get the publication from the hub course id - $publication = $publicationmanager->get_publication($sitecourse['id'], $hub->huburl); - if (!empty($publication)) { - $publication->status = $sitecourse['privacy']; - $publication->timechecked = time(); - $publicationmanager->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)); - } - } - } +// When hub listing status is requested update statuses of all published courses. +$updatestatusid = optional_param('updatestatusid', false, PARAM_INT); +if (!empty($updatestatusid) && confirm_sesskey()) { + if (core\hub\publication::get_publication($updatestatusid, $courseid)) { + core\hub\publication::request_status_update(); + redirect($PAGE->url); } +} - //if the site os registered on no hub display an error page - $registrationmanager = new registration_manager(); - $registeredhubs = $registrationmanager->get_registered_on_hubs(); - if (empty($registeredhubs)) { +$renderer = $PAGE->get_renderer('core', 'publish'); + +// Unpublish course. +if ($publication = \core\hub\publication::get_publication($publicationid, $courseid)) { + $confirm = optional_param('confirm', 0, PARAM_BOOL); + if ($confirm && confirm_sesskey()) { + \core\hub\publication::unpublish($publication); + } else { + // Display confirmation page for unpublishing. + $publication = \core\hub\publication::get_publication($publicationid, $courseid, MUST_EXIST); + $publication->courseshortname = format_string($COURSE->shortname); echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('publishon', 'hub'), 3, 'main'); - echo $OUTPUT->box(get_string('notregisteredonhub', 'hub')); + echo $OUTPUT->heading(get_string('unpublishcourse', 'hub', $shortname), 3, 'main'); + echo $renderer->confirmunpublishing($publication); echo $OUTPUT->footer(); die(); } - - $renderer = $PAGE->get_renderer('core', 'publish'); - - /// UNPUBLISH - $cancel = optional_param('cancel', 0, PARAM_BOOL); - if (!empty($cancel) and confirm_sesskey()) { - $confirm = optional_param('confirm', 0, PARAM_BOOL); - $hubcourseid = optional_param('hubcourseid', 0, PARAM_INT); - $publicationid = optional_param('publicationid', 0, PARAM_INT); - $timepublished = optional_param('timepublished', 0, PARAM_INT); - $publication = new stdClass(); - $publication->courseshortname = $course->shortname; - $publication->courseid = $course->id; - $publication->hubname = $hubname; - $publication->huburl = $huburl; - $publication->hubcourseid = $hubcourseid; - $publication->timepublished = $timepublished; - if (empty($publication->hubname)) { - $publication->hubname = $huburl; - } - $publication->id = $publicationid; - if($confirm) { - //unpublish the publication by web service - $registeredhub = $registrationmanager->get_registeredhub($huburl); - $function = 'hub_unregister_courses'; - $params = array('courseids' => array( $publication->hubcourseid)); - $serverurl = $huburl."/local/hub/webservice/webservices.php"; - require_once($CFG->dirroot."/webservice/xmlrpc/lib.php"); - $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token); - $result = $xmlrpcclient->call($function, $params); - - //delete the publication from the database - $publicationmanager->delete_publication($publicationid); - - //display confirmation message - $confirmmessage = $OUTPUT->notification(get_string('courseunpublished', 'hub', $publication), 'notifysuccess'); - - } else { - //display confirmation page for unpublishing - - echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('unpublishcourse', 'hub', $shortname), 3, 'main'); - echo $renderer->confirmunpublishing($publication); - echo $OUTPUT->footer(); - die(); - } - } - - //check if a course was published - if (optional_param('published', 0, PARAM_TEXT)) { - $confirmmessage = $OUTPUT->notification(get_string('coursepublished', 'hub', - empty($hubname)?$huburl:$hubname), 'notifysuccess'); - } - - - /// OUTPUT - echo $OUTPUT->header(); - echo $confirmmessage; - - echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main'); - echo $renderer->publicationselector($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); - } - - echo $OUTPUT->footer(); - } + +// List current publications and "Publish" buttons. +echo $OUTPUT->header(); + +echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main'); +echo $renderer->publicationselector($courseid); + +$publications = \core\hub\publication::get_course_publications($courseid); +if (!empty($publications)) { + echo $OUTPUT->heading(get_string('publishedon', 'hub'), 3, 'main'); + echo $renderer->registeredonhublisting($courseid, $publications); +} + +echo $OUTPUT->footer(); diff --git a/course/publish/metadata.php b/course/publish/metadata.php index ee9caed31b7..57470a68135 100644 --- a/course/publish/metadata.php +++ b/course/publish/metadata.php @@ -31,9 +31,6 @@ */ require_once('../../config.php'); -require_once($CFG->dirroot . '/course/publish/forms.php'); -require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php'); -require_once($CFG->dirroot . '/course/publish/lib.php'); require_once($CFG->libdir . '/filelib.php'); @@ -49,226 +46,144 @@ $PAGE->set_pagelayout('incourse'); $PAGE->set_title(get_string('course') . ': ' . $course->fullname); $PAGE->set_heading($course->fullname); -//check that the PHP xmlrpc extension is enabled -if (!extension_loaded('xmlrpc')) { - $errornotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); - $errornotification .= get_string('xmlrpcdisabledpublish', 'hub'); - $context = context_course::instance($course->id); - $shortname = format_string($course->shortname, true, array('context' => $context)); - echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main'); - echo $OUTPUT->notification($errornotification); - echo $OUTPUT->footer(); - die(); +require_capability('moodle/course:publish', context_course::instance($id)); + +// Retrieve hub name and hub url. +require_sesskey(); + +// Set the publication form. +$advertise = optional_param('advertise', false, PARAM_BOOL); +$publicationid = optional_param('publicationid', false, PARAM_INT); +$formparams = array('course' => $course, 'advertise' => $advertise); +if ($publicationid) { + $publication = \core\hub\publication::get_publication($publicationid, $course->id, MUST_EXIST); + $formparams['publication'] = $publication; + $advertise = $formparams['advertise'] = $publication->enrollable; } +$share = !$advertise; +$coursepublicationform = new \core\hub\course_publication_form('', $formparams); +$fromform = $coursepublicationform->get_data(); -if (has_capability('moodle/course:publish', context_course::instance($id))) { +if (!empty($fromform)) { - //retrieve hub name and hub url - $huburl = optional_param('huburl', '', PARAM_URL); - $hubname = optional_param('hubname', '', PARAM_TEXT); - if (empty($huburl) or !confirm_sesskey()) { - throw new moodle_exception('missingparameter'); + // Retrieve the course information. + $courseinfo = new stdClass(); + $courseinfo->fullname = $fromform->name; + $courseinfo->shortname = $fromform->courseshortname; + $courseinfo->description = $fromform->description; + $courseinfo->language = $fromform->language; + $courseinfo->publishername = $fromform->publishername; + $courseinfo->publisheremail = $fromform->publisheremail; + $courseinfo->contributornames = $fromform->contributornames; + $courseinfo->coverage = $fromform->coverage; + $courseinfo->creatorname = $fromform->creatorname; + $courseinfo->licenceshortname = $fromform->licence; + $courseinfo->subject = $fromform->subject; + $courseinfo->audience = $fromform->audience; + $courseinfo->educationallevel = $fromform->educationallevel; + $creatornotes = $fromform->creatornotes; + $courseinfo->creatornotes = $creatornotes['text']; + $courseinfo->creatornotesformat = $creatornotes['format']; + $courseinfo->sitecourseid = $id; + if (!empty($fromform->deletescreenshots)) { + $courseinfo->deletescreenshots = $fromform->deletescreenshots; + } + if ($share) { + $courseinfo->demourl = $fromform->demourl; + $courseinfo->enrollable = false; + } else { + $courseinfo->courseurl = $fromform->courseurl; + $courseinfo->enrollable = true; } - //set the publication form - $advertise = optional_param('advertise', false, PARAM_BOOL); - $share = optional_param('share', false, PARAM_BOOL); - $coursepublicationform = new course_publication_form('', - array('huburl' => $huburl, 'hubname' => $hubname, 'sesskey' => sesskey(), - 'course' => $course, 'advertise' => $advertise, 'share' => $share, - 'id' => $id, 'page' => $PAGE)); - $fromform = $coursepublicationform->get_data(); - - //retrieve the token to call the hub - $registrationmanager = new registration_manager(); - $registeredhub = $registrationmanager->get_registeredhub($huburl); - - //setup web service xml-rpc client - $serverurl = $huburl . "/local/hub/webservice/webservices.php"; - require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php"); - $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token); - - if (!empty($fromform)) { - - $publicationmanager = new course_publish_manager(); - - //retrieve the course information - $courseinfo = new stdClass(); - $courseinfo->fullname = $fromform->name; - $courseinfo->shortname = $fromform->courseshortname; - $courseinfo->description = $fromform->description; - $courseinfo->language = $fromform->language; - $courseinfo->publishername = $fromform->publishername; - $courseinfo->publisheremail = $fromform->publisheremail; - $courseinfo->contributornames = $fromform->contributornames; - $courseinfo->coverage = $fromform->coverage; - $courseinfo->creatorname = $fromform->creatorname; - $courseinfo->licenceshortname = $fromform->licence; - $courseinfo->subject = $fromform->subject; - $courseinfo->audience = $fromform->audience; - $courseinfo->educationallevel = $fromform->educationallevel; - $creatornotes = $fromform->creatornotes; - $courseinfo->creatornotes = $creatornotes['text']; - $courseinfo->creatornotesformat = $creatornotes['format']; - $courseinfo->sitecourseid = $id; - if (!empty($fromform->deletescreenshots)) { - $courseinfo->deletescreenshots = $fromform->deletescreenshots; - } - if ($share) { - $courseinfo->demourl = $fromform->demourl; - $courseinfo->enrollable = false; - } else { - $courseinfo->courseurl = $fromform->courseurl; - $courseinfo->enrollable = true; + // Retrieve the outcomes of this course. + require_once($CFG->libdir . '/grade/grade_outcome.php'); + $outcomes = grade_outcome::fetch_all_available($id); + if (!empty($outcomes)) { + foreach ($outcomes as $outcome) { + $sentoutcome = new stdClass(); + $sentoutcome->fullname = $outcome->fullname; + $courseinfo->outcomes[] = $sentoutcome; } + } - //retrieve the outcomes of this course - require_once($CFG->libdir . '/grade/grade_outcome.php'); - $outcomes = grade_outcome::fetch_all_available($id); - if (!empty($outcomes)) { - foreach ($outcomes as $outcome) { - $sentoutcome = new stdClass(); - $sentoutcome->fullname = $outcome->fullname; - $courseinfo->outcomes[] = $sentoutcome; - } - } + // Retrieve the content information from the course. + $coursecontext = context_course::instance($course->id); + $courseblocks = \core\hub\publication::get_block_instances_by_context($coursecontext->id); - //retrieve the content information from the course - $coursecontext = context_course::instance($course->id); - $courseblocks = $publicationmanager->get_block_instances_by_context($coursecontext->id, 'blockname'); - - if (!empty($courseblocks)) { - $blockname = ''; - foreach ($courseblocks as $courseblock) { - if ($courseblock->blockname != $blockname) { - if (!empty($blockname)) { - $courseinfo->contents[] = $content; - } - - $blockname = $courseblock->blockname; - $content = new stdClass(); - $content->moduletype = 'block'; - $content->modulename = $courseblock->blockname; - $content->contentcount = 1; - } else { - $content->contentcount = $content->contentcount + 1; + if (!empty($courseblocks)) { + $blockname = ''; + foreach ($courseblocks as $courseblock) { + if ($courseblock->blockname != $blockname) { + if (!empty($blockname)) { + $courseinfo->contents[] = $content; } - } - $courseinfo->contents[] = $content; - } - $activities = get_fast_modinfo($course, $USER->id); - foreach ($activities->instances as $activityname => $activitydetails) { - $content = new stdClass(); - $content->moduletype = 'activity'; - $content->modulename = $activityname; - $content->contentcount = count($activities->instances[$activityname]); - $courseinfo->contents[] = $content; - } - - //save into screenshots field the references to the screenshot content hash - //(it will be like a unique id from the hub perspective) - if (!empty($fromform->deletescreenshots) or $share) { - $courseinfo->screenshots = 0; - } else { - $courseinfo->screenshots = $fromform->existingscreenshotnumber; - } - if (!empty($fromform->screenshots)) { - $screenshots = $fromform->screenshots; - $fs = get_file_storage(); - $files = $fs->get_area_files(context_user::instance($USER->id)->id, 'user', 'draft', $screenshots); - if (!empty($files)) { - $courseinfo->screenshots = $courseinfo->screenshots + count($files) - 1; //minus the ./ directory - } - } - - // PUBLISH ACTION - - //publish the course information - $function = 'hub_register_courses'; - $params = array('courses' => array($courseinfo)); - try { - $courseids = $xmlrpcclient->call($function, $params); - } catch (Exception $e) { - throw new moodle_exception('errorcoursepublish', 'hub', - new moodle_url('/course/view.php', array('id' => $id)), $e->getMessage()); - } - - if (count($courseids) != 1) { - throw new moodle_exception('errorcoursewronglypublished', 'hub'); - } - - //save the record into the published course table - $publication = $publicationmanager->get_publication($courseids[0], $huburl); - if (empty($publication)) { - //if never been published or if we share, we need to save this new publication record - $publicationmanager->add_course_publication($registeredhub->huburl, $course->id, !$share, $courseids[0]); - } else { - //if we update the enrollable course publication we update the publication record - $publicationmanager->update_enrollable_course_publication($publication->id); - } - - // SEND FILES - $curl = new curl(); - - // send screenshots - if (!empty($fromform->screenshots)) { - - if (!empty($fromform->deletescreenshots) or $share) { - $screenshotnumber = 0; + $blockname = $courseblock->blockname; + $content = new stdClass(); + $content->moduletype = 'block'; + $content->modulename = $courseblock->blockname; + $content->contentcount = 1; } else { - $screenshotnumber = $fromform->existingscreenshotnumber; - } - foreach ($files as $file) { - if ($file->is_valid_image()) { - $screenshotnumber = $screenshotnumber + 1; - $params = array(); - $params['filetype'] = HUB_SCREENSHOT_FILE_TYPE; - $params['file'] = $file; - $params['courseid'] = $courseids[0]; - $params['filename'] = $file->get_filename(); - $params['screenshotnumber'] = $screenshotnumber; - $params['token'] = $registeredhub->token; - $curl->post($huburl . "/local/hub/webservice/upload.php", $params); - } + $content->contentcount = $content->contentcount + 1; } } - - //redirect to the backup process page - if ($share) { - $params = array('sesskey' => sesskey(), 'id' => $id, 'hubcourseid' => $courseids[0], - 'huburl' => $huburl, 'hubname' => $hubname); - $backupprocessurl = new moodle_url("/course/publish/backup.php", $params); - redirect($backupprocessurl); - } else { - //redirect to the index publis page - redirect(new moodle_url('/course/publish/index.php', - array('sesskey' => sesskey(), 'id' => $id, 'published' => true, - 'hubname' => $hubname, 'huburl' => $huburl))); - } + $courseinfo->contents[] = $content; } - /////// OUTPUT SECTION ///////////// - - echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('publishcourseon', 'hub', !empty($hubname) ? $hubname : $huburl), 3, 'main'); - - //display hub information (logo, name, description) - $function = 'hub_get_info'; - $params = array(); - try { - $hubinfo = $xmlrpcclient->call($function, $params); - } catch (Exception $e) { - //only print error log in apache (for backward compatibility) - error_log(print_r($e->getMessage(), true)); - } - $renderer = $PAGE->get_renderer('core', 'publish'); - if (!empty($hubinfo)) { - echo $renderer->hubinfo($hubinfo); + $activities = get_fast_modinfo($course, $USER->id); + foreach ($activities->instances as $activityname => $activitydetails) { + $content = new stdClass(); + $content->moduletype = 'activity'; + $content->modulename = $activityname; + $content->contentcount = count($activities->instances[$activityname]); + $courseinfo->contents[] = $content; } - //display metadata form - $coursepublicationform->display(); - echo $OUTPUT->footer(); + // Save into screenshots field the references to the screenshot content hash + // (it will be like a unique id from the hub perspective). + if (!empty($fromform->deletescreenshots) or $share) { + $courseinfo->screenshots = 0; + } else { + $courseinfo->screenshots = $fromform->existingscreenshotnumber; + } + $files = []; + if (!empty($fromform->screenshots)) { + $fs = get_file_storage(); + $files = $fs->get_area_files(context_user::instance($USER->id)->id, 'user', 'draft', $fromform->screenshots, + 'filepath, filename', false); + $files = array_filter($files, function(stored_file $file) { + return $file->is_valid_image(); + }); + $courseinfo->screenshots += count($files); + } + + // PUBLISH ACTION. + $hubcourseid = \core\hub\publication::publish_course($courseinfo, $files); + + // Redirect to the backup process page. + if ($share) { + $params = array('sesskey' => sesskey(), 'id' => $id, 'hubcourseid' => $hubcourseid); + $backupprocessurl = new moodle_url("/course/publish/backup.php", $params); + redirect($backupprocessurl); + } else { + // Redirect to the index publis page. + redirect(new moodle_url('/course/publish/index.php', ['id' => $id]), + get_string('coursepublished', 'hub', 'Moodle.net'), null, \core\output\notification::NOTIFY_SUCCESS); + } } + +// OUTPUT SECTION. + +echo $OUTPUT->header(); +echo $OUTPUT->heading(get_string('publishcourseon', 'hub', 'Moodle.net'), 3, 'main'); + +// Display hub information (logo, name, description). +$renderer = $PAGE->get_renderer('core', 'publish'); +if ($hubinfo = \core\hub\registration::get_moodlenet_info()) { + echo $renderer->hubinfo($hubinfo); +} + +// Display metadata form. +$coursepublicationform->display(); +echo $OUTPUT->footer(); diff --git a/course/publish/renderer.php b/course/publish/renderer.php index 970fed51db4..9dbf3b3b377 100644 --- a/course/publish/renderer.php +++ b/course/publish/renderer.php @@ -36,7 +36,7 @@ class core_publish_renderer extends plugin_renderer_base { public function publicationselector($courseid) { $text = ''; - $advertiseurl = new moodle_url("/course/publish/hubselector.php", + $advertiseurl = new moodle_url("/course/publish/metadata.php", array('sesskey' => sesskey(), 'id' => $courseid, 'advertise' => true)); $advertisebutton = new single_button($advertiseurl, get_string('advertise', 'hub')); $text .= $this->output->render($advertisebutton); @@ -45,7 +45,7 @@ class core_publish_renderer extends plugin_renderer_base { $text .= html_writer::empty_tag('br'); /// TODO Delete - $uploadurl = new moodle_url("/course/publish/hubselector.php", + $uploadurl = new moodle_url("/course/publish/metadata.php", array('sesskey' => sesskey(), 'id' => $courseid, 'share' => true)); $uploadbutton = new single_button($uploadurl, get_string('share', 'hub')); $text .= $this->output->render($uploadbutton); @@ -61,30 +61,22 @@ class core_publish_renderer extends plugin_renderer_base { public function registeredonhublisting($courseid, $publications) { global $CFG; $table = new html_table(); - $table->head = array(get_string('type', 'hub'), get_string('hub', 'hub'), + $table->head = array(get_string('type', 'hub'), get_string('date'), get_string('status', 'hub'), get_string('operation', 'hub')); - $table->size = array('10%', '40%', '20%', '%10', '%15'); + $table->size = array('20%', '30%', '%20', '%25'); $brtag = html_writer::empty_tag('br'); foreach ($publications as $publication) { - $updatebuttonhtml = ''; - - $params = array('sesskey' => sesskey(), 'id' => $publication->courseid, - 'hubcourseid' => $publication->hubcourseid, - 'huburl' => $publication->huburl, 'hubname' => $publication->hubname, - 'cancel' => true, 'publicationid' => $publication->id, - 'timepublished' => $publication->timepublished); + $params = array('id' => $publication->courseid, 'publicationid' => $publication->id); $cancelurl = new moodle_url("/course/publish/index.php", $params); $cancelbutton = new single_button($cancelurl, get_string('removefromhub', 'hub')); $cancelbutton->class = 'centeredbutton'; $cancelbuttonhtml = $this->output->render($cancelbutton); if ($publication->enrollable) { - $params = array('sesskey' => sesskey(), 'id' => $publication->courseid, - 'huburl' => $publication->huburl, 'hubname' => $publication->hubname, - 'share' => !$publication->enrollable, 'advertise' => $publication->enrollable); + $params = array('sesskey' => sesskey(), 'id' => $publication->courseid, 'publicationid' => $publication->id); $updateurl = new moodle_url("/course/publish/metadata.php", $params); $updatebutton = new single_button($updateurl, get_string('update', 'hub')); $updatebutton->class = 'centeredbutton'; @@ -95,15 +87,15 @@ class core_publish_renderer extends plugin_renderer_base { $operations = $cancelbuttonhtml; } - $hubname = html_writer::tag('a', - $publication->hubname ? $publication->hubname : $publication->huburl, - array('href' => $publication->huburl)); //if the publication check time if bigger than May 2010, it has been checked if ($publication->timechecked > 1273127954) { if ($publication->status == 0) { $status = get_string('statusunpublished', 'hub'); } else { $status = get_string('statuspublished', 'hub'); + if (!empty($publication->link)) { + $status = html_writer::link($publication->link, $status); + } } $status .= $brtag . html_writer::tag('a', get_string('updatestatus', 'hub'), @@ -122,7 +114,7 @@ class core_publish_renderer extends plugin_renderer_base { //add button cells $cells = array($publication->enrollable ? get_string('advertised', 'hub') : get_string('shared', 'hub'), - $hubname, userdate($publication->timepublished, + userdate($publication->timepublished, get_string('strftimedatetimeshort')), $status, $operations); $row = new html_table_row($cells); $table->data[] = $row; @@ -145,11 +137,10 @@ class core_publish_renderer extends plugin_renderer_base { public function confirmunpublishing($publication) { $optionsyes = array('sesskey' => sesskey(), 'id' => $publication->courseid, 'hubcourseid' => $publication->hubcourseid, - 'huburl' => $publication->huburl, 'hubname' => $publication->hubname, 'cancel' => true, 'publicationid' => $publication->id, 'confirm' => true); $optionsno = array('sesskey' => sesskey(), 'id' => $publication->courseid); - $publication->hubname = html_writer::tag('a', $publication->hubname, - array('href' => $publication->huburl)); + $publication->hubname = html_writer::tag('a', 'Moodle.net', + array('href' => HUB_MOODLEORGHUBURL)); $formcontinue = new single_button(new moodle_url("/course/publish/index.php", $optionsyes), get_string('unpublish', 'hub'), 'post'); $formcancel = new single_button(new moodle_url("/course/publish/index.php", @@ -174,18 +165,16 @@ class core_publish_renderer extends plugin_renderer_base { /** * Display upload successfull message and a button to the publish index page * @param int $id the course id - * @param string $huburl the hub url where the course is published - * @param string $hubname the hub name where the course is published * @return $html string */ - public function sentbackupinfo($id, $huburl, $hubname) { + public function sentbackupinfo($id) { $html = html_writer::tag('div', get_string('sent', 'hub'), array('class' => 'courseuploadtextinfo')); $publishindexurl = new moodle_url('/course/publish/index.php', array('sesskey' => sesskey(), 'id' => $id, - 'published' => true, 'huburl' => $huburl, 'hubname' => $hubname)); + 'published' => true)); $continue = $this->output->render( - new single_button($publishindexurl, get_string('continue', 'hub'))); + new single_button($publishindexurl, get_string('continue'))); $html .= html_writer::tag('div', $continue, array('class' => 'sharecoursecontinue')); return $html; } @@ -196,11 +185,8 @@ class core_publish_renderer extends plugin_renderer_base { * @return string html code */ public function hubinfo($hubinfo) { - $params = array('filetype' => HUB_HUBSCREENSHOT_FILE_TYPE); - $imgurl = new moodle_url($hubinfo['url'] . - "/local/hub/webservice/download.php", $params); $screenshothtml = html_writer::empty_tag('img', - array('src' => $imgurl, 'alt' => $hubinfo['name'])); + array('src' => $hubinfo['imgurl'], 'alt' => $hubinfo['name'])); $hubdescription = html_writer::tag('div', $screenshothtml, array('class' => 'hubscreenshot')); @@ -210,7 +196,7 @@ class core_publish_renderer extends plugin_renderer_base { $hubdescription .= html_writer::tag('div', format_text($hubinfo['description'], FORMAT_PLAIN), array('class' => 'hubdescription')); - $hubdescription = html_writer::tag('div', $hubdescription, array('class' => 'hubinfo')); + $hubdescription = html_writer::tag('div', $hubdescription, array('class' => 'hubinfo clearfix')); return $hubdescription; }