mirror of
https://github.com/moodle/moodle.git
synced 2025-07-23 15:22:05 +02:00
course publication MDL-19315 work version of course sharing
This commit is contained in:
@@ -60,7 +60,9 @@ $huburl = optional_param('huburl', false, PARAM_URL);
|
||||
$download = optional_param('download', -1, PARAM_INTEGER);
|
||||
$courseid = optional_param('courseid', '', PARAM_INTEGER);
|
||||
if ($download != -1 and !empty($courseid) and confirm_sesskey()) {
|
||||
$community->get_community_course_backup($courseid, $huburl);
|
||||
$community->download_community_course_backup($courseid, $huburl);
|
||||
$downloadmessage = $OUTPUT->notification(get_string('downloadconfirmed', 'hub', 'backup_'.$courseid.".zip"),
|
||||
'notifysuccess');
|
||||
}
|
||||
|
||||
$renderer = $PAGE->get_renderer('block_community');
|
||||
@@ -84,6 +86,7 @@ if (!empty($fromform)) {
|
||||
// OUTPUT
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('addcommunitycourse', 'block_community'), 3, 'main');
|
||||
echo $downloadmessage;
|
||||
$hubselectorform->display();
|
||||
echo $renderer->course_list($courses, $huburl);
|
||||
echo $OUTPUT->footer();
|
@@ -56,18 +56,58 @@ class community {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Download the community course backup and save it in file API
|
||||
* @param <type> $courseid
|
||||
* @param <type> $huburl
|
||||
*/
|
||||
public function get_community_course_backup($courseid, $huburl) {
|
||||
global $CFG;
|
||||
public function download_community_course_backup($courseid, $huburl) {
|
||||
global $CFG, $USER;
|
||||
require_once($CFG->dirroot. "/lib/filelib.php");
|
||||
require_once($CFG->dirroot. "/lib/hublib.php");
|
||||
$curl = new curl();
|
||||
//$curl = new curl();
|
||||
$params['courseid'] = $courseid;
|
||||
$params['filetype'] = BACKUP_FILE_TYPE;
|
||||
$filecontent = $curl->get($huburl.'/local/hub/webservice/download.php', $params);
|
||||
|
||||
$url = new moodle_url($huburl.'/local/hub/webservice/download.php', $params);
|
||||
varlog($url);
|
||||
$path = $CFG->dataroot.'/temp/download/'.'backup_'.$courseid.".zip";
|
||||
$fp = fopen($path, 'w');
|
||||
$ch = curl_init($huburl.'/local/hub/webservice/download.php?filetype='.BACKUP_FILE_TYPE.'&courseid='.$courseid);
|
||||
curl_setopt($ch, CURLOPT_FILE, $fp);
|
||||
$data = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
fclose($fp);
|
||||
|
||||
$record->contextid = get_context_instance(CONTEXT_USER, $USER->id)->id;
|
||||
$record->filearea = 'community_backups';
|
||||
$record->itemid = $courseid;
|
||||
$record->filename = 'backup_'.$courseid.".zip";
|
||||
$record->filepath = '/';
|
||||
$fs = get_file_storage();
|
||||
$fs->create_file_from_pathname($record, $CFG->dataroot.'/temp/download/'.'backup_'.$courseid.".zip");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decide where to save the file, can be
|
||||
* reused by sub class
|
||||
* @param string filename
|
||||
*/
|
||||
public function prepare_file($filename) {
|
||||
global $CFG;
|
||||
if (!file_exists($CFG->dataroot.'/temp/download')) {
|
||||
mkdir($CFG->dataroot.'/temp/download/', 0777, true);
|
||||
}
|
||||
if (is_dir($CFG->dataroot.'/temp/download')) {
|
||||
$dir = $CFG->dataroot.'/temp/download/';
|
||||
}
|
||||
if (empty($filename)) {
|
||||
$filename = uniqid('repo').'_'.time().'.tmp';
|
||||
}
|
||||
if (file_exists($dir.$filename)) {
|
||||
$filename = uniqid('m').$filename;
|
||||
}
|
||||
return $dir.$filename;
|
||||
}
|
||||
|
||||
}
|
@@ -103,12 +103,12 @@ class block_community_renderer extends plugin_renderer_base {
|
||||
$addlinkhtml = html_writer::tag('a', get_string('add'), array('href' => $addurl));
|
||||
} else {
|
||||
// Add link TODO make it a button and send by post
|
||||
// $addurl = new moodle_url("/blocks/community/communitycourse.php",
|
||||
// array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
|
||||
// 'courseid' => $course->id, 'huburl' => $huburl));
|
||||
// $addlinkhtml = html_writer::tag('a', get_string('download', 'block_community'), array('href' => $addurl));
|
||||
$addurl = new moodle_url("/blocks/community/communitycourse.php",
|
||||
array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
|
||||
'courseid' => $course->id, 'huburl' => $huburl));
|
||||
$addlinkhtml = html_writer::tag('a', get_string('download', 'block_community'), array('href' => $addurl));
|
||||
|
||||
$addlinkhtml = "Download not implemented yet";
|
||||
// $addlinkhtml = "Download not implemented yet";
|
||||
}
|
||||
|
||||
// add a row to the table
|
||||
|
@@ -216,13 +216,13 @@ class course_publication_form extends moodleform {
|
||||
|
||||
|
||||
|
||||
$mform->addElement('filemanager', 'screenshots', get_string('screenshots','hub'), null,
|
||||
array('subdirs'=>0,
|
||||
'maxbytes'=>1000000,
|
||||
'maxfiles'=>3
|
||||
));
|
||||
$mform->setHelpButton('screenshots', array('screenshots', get_string('screenshots', 'hub'), 'hub'));
|
||||
$mform->addHelpButton('screenshots', 'screenshots', 'hub');
|
||||
// $mform->addElement('filemanager', 'screenshots', get_string('screenshots','hub'), null,
|
||||
// array('subdirs'=>0,
|
||||
// 'maxbytes'=>1000000,
|
||||
// 'maxfiles'=>3
|
||||
// ));
|
||||
// $mform->setHelpButton('screenshots', array('screenshots', get_string('screenshots', 'hub'), 'hub'));
|
||||
// $mform->addHelpButton('screenshots', 'screenshots', 'hub');
|
||||
|
||||
$this->add_action_buttons(false, $buttonlabel);
|
||||
}
|
||||
|
@@ -128,7 +128,12 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
|
||||
$serverurl = $huburl."/local/hub/webservice/webservices.php";
|
||||
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
|
||||
$xmlrpcclient = new webservice_xmlrpc_client();
|
||||
$result = $xmlrpcclient->call($serverurl, $registeredhub->token, $function, $params);
|
||||
$courseids = $xmlrpcclient->call($serverurl, $registeredhub->token, $function, $params);
|
||||
varlog('The course id after retrieveing from ws:');
|
||||
varlog($courseids);
|
||||
if (count($courseids) != 1) {
|
||||
throw new moodle_exception('coursewronglypublished');
|
||||
}
|
||||
|
||||
$courseregisteredmsg = $OUTPUT->notification(get_string('coursepublished', 'hub'), 'notifysuccess');
|
||||
|
||||
@@ -151,11 +156,14 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
|
||||
|
||||
// send backup
|
||||
if ($share) {
|
||||
foreach ($courseids as $courseid) {
|
||||
$params['filetype'] = BACKUP_FILE_TYPE;
|
||||
$params['courseid'] = $courseid;
|
||||
$params['file'] = $backupfile;
|
||||
$params['filename'] = $backupfile->get_filename();
|
||||
$curl->post($huburl."/local/hub/webservice/upload.php", $params);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO: Delete the backup from user_tohub
|
||||
|
||||
|
@@ -65,6 +65,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['downloadable'] = 'Downloadable';
|
||||
$string['downloadconfirmed'] = 'The backup has been saved into your personal area';
|
||||
$string['educationallevel'] = 'Educational level';
|
||||
$string['educationallevel_help'] = '';
|
||||
$string['edulevelassociation'] = 'Association';
|
||||
|
Reference in New Issue
Block a user