course publication MDL-19315 work version of course sharing

This commit is contained in:
jerome mouneyrac
2010-05-03 11:37:00 +00:00
parent 05c4176751
commit a8f201f88c
6 changed files with 76 additions and 24 deletions

View File

@@ -60,7 +60,9 @@ $huburl = optional_param('huburl', false, PARAM_URL);
$download = optional_param('download', -1, PARAM_INTEGER); $download = optional_param('download', -1, PARAM_INTEGER);
$courseid = optional_param('courseid', '', PARAM_INTEGER); $courseid = optional_param('courseid', '', PARAM_INTEGER);
if ($download != -1 and !empty($courseid) and confirm_sesskey()) { 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'); $renderer = $PAGE->get_renderer('block_community');
@@ -84,6 +86,7 @@ if (!empty($fromform)) {
// OUTPUT // OUTPUT
echo $OUTPUT->header(); echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('addcommunitycourse', 'block_community'), 3, 'main'); echo $OUTPUT->heading(get_string('addcommunitycourse', 'block_community'), 3, 'main');
echo $downloadmessage;
$hubselectorform->display(); $hubselectorform->display();
echo $renderer->course_list($courses, $huburl); echo $renderer->course_list($courses, $huburl);
echo $OUTPUT->footer(); echo $OUTPUT->footer();

View File

@@ -56,18 +56,58 @@ class community {
} }
/** /**
* * Download the community course backup and save it in file API
* @param <type> $courseid * @param <type> $courseid
* @param <type> $huburl * @param <type> $huburl
*/ */
public function get_community_course_backup($courseid, $huburl) { public function download_community_course_backup($courseid, $huburl) {
global $CFG; global $CFG, $USER;
require_once($CFG->dirroot. "/lib/filelib.php"); require_once($CFG->dirroot. "/lib/filelib.php");
require_once($CFG->dirroot. "/lib/hublib.php"); require_once($CFG->dirroot. "/lib/hublib.php");
$curl = new curl(); //$curl = new curl();
$params['courseid'] = $courseid; $params['courseid'] = $courseid;
$params['filetype'] = BACKUP_FILE_TYPE; $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;
} }
} }

View File

@@ -102,13 +102,13 @@ class block_community_renderer extends plugin_renderer_base {
'coursedescription' => $course->description)); 'coursedescription' => $course->description));
$addlinkhtml = html_writer::tag('a', get_string('add'), array('href' => $addurl)); $addlinkhtml = html_writer::tag('a', get_string('add'), array('href' => $addurl));
} else { } else {
//Add link TODO make it a button and send by post // Add link TODO make it a button and send by post
// $addurl = new moodle_url("/blocks/community/communitycourse.php", $addurl = new moodle_url("/blocks/community/communitycourse.php",
// array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1, array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
// 'courseid' => $course->id, 'huburl' => $huburl)); 'courseid' => $course->id, 'huburl' => $huburl));
// $addlinkhtml = html_writer::tag('a', get_string('download', 'block_community'), array('href' => $addurl)); $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 // add a row to the table

View File

@@ -216,13 +216,13 @@ class course_publication_form extends moodleform {
$mform->addElement('filemanager', 'screenshots', get_string('screenshots','hub'), null, // $mform->addElement('filemanager', 'screenshots', get_string('screenshots','hub'), null,
array('subdirs'=>0, // array('subdirs'=>0,
'maxbytes'=>1000000, // 'maxbytes'=>1000000,
'maxfiles'=>3 // 'maxfiles'=>3
)); // ));
$mform->setHelpButton('screenshots', array('screenshots', get_string('screenshots', 'hub'), 'hub')); // $mform->setHelpButton('screenshots', array('screenshots', get_string('screenshots', 'hub'), 'hub'));
$mform->addHelpButton('screenshots', 'screenshots', 'hub'); // $mform->addHelpButton('screenshots', 'screenshots', 'hub');
$this->add_action_buttons(false, $buttonlabel); $this->add_action_buttons(false, $buttonlabel);
} }

View File

@@ -128,7 +128,12 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
$serverurl = $huburl."/local/hub/webservice/webservices.php"; $serverurl = $huburl."/local/hub/webservice/webservices.php";
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php"); require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client(); $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'); $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 // send backup
if ($share) { if ($share) {
$params['filetype'] = BACKUP_FILE_TYPE; foreach ($courseids as $courseid) {
$params['file'] = $backupfile; $params['filetype'] = BACKUP_FILE_TYPE;
$params['filename'] = $backupfile->get_filename(); $params['courseid'] = $courseid;
$curl->post($huburl."/local/hub/webservice/upload.php", $params); $params['file'] = $backupfile;
$curl->post($huburl."/local/hub/webservice/upload.php", $params);
}
} }
//TODO: Delete the backup from user_tohub //TODO: Delete the backup from user_tohub

View File

@@ -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['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'] = 'Description';
$string['downloadable'] = 'Downloadable'; $string['downloadable'] = 'Downloadable';
$string['downloadconfirmed'] = 'The backup has been saved into your personal area';
$string['educationallevel'] = 'Educational level'; $string['educationallevel'] = 'Educational level';
$string['educationallevel_help'] = ''; $string['educationallevel_help'] = '';
$string['edulevelassociation'] = 'Association'; $string['edulevelassociation'] = 'Association';