community block MDL-19314 improve the download form (check that if the file already exist in the file aera, change link for button, delete temp downloaded file, change name of the backup file including course name)
This commit is contained in:
@@ -62,9 +62,15 @@ if ($add != -1 and $confirm and confirm_sesskey()) {
|
||||
$huburl = optional_param('huburl', false, PARAM_URL);
|
||||
$download = optional_param('download', -1, PARAM_INTEGER);
|
||||
$courseid = optional_param('courseid', '', PARAM_INTEGER);
|
||||
$coursefullname = optional_param('coursefullname', '', PARAM_ALPHANUMEXT);
|
||||
if ($download != -1 and !empty($courseid) and confirm_sesskey()) {
|
||||
$community->download_community_course_backup($courseid, $huburl);
|
||||
$notificationmessage = $OUTPUT->notification(get_string('downloadconfirmed', 'hub', 'backup_'.$courseid.".zip"),
|
||||
$course = new stdClass();
|
||||
$course->fullname = $coursefullname;
|
||||
$course->id = $courseid;
|
||||
$course->huburl = $huburl;
|
||||
$community->download_community_course_backup($course);
|
||||
$filename = 'backup_'.$course->fullname."_".$course->id.".zip";
|
||||
$notificationmessage = $OUTPUT->notification(get_string('downloadconfirmed', 'hub', $filename),
|
||||
'notifysuccess');
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['add'] = 'Add';
|
||||
$string['addtocommunityblock'] = 'Add to community block';
|
||||
$string['addcommunitycourse'] = 'Add community course';
|
||||
$string['additionalcoursedesc'] = '{$a->contributornames} - {$a->coverage} - Creator: {$a->creatorname} - Publisher: {$a->publishername} - Subject: {$a->subject}
|
||||
|
||||
@@ -79,30 +79,40 @@ class community {
|
||||
* @param integer $courseid
|
||||
* @param string $huburl
|
||||
*/
|
||||
public function download_community_course_backup($courseid, $huburl) {
|
||||
public function download_community_course_backup($course) {
|
||||
global $CFG, $USER;
|
||||
require_once($CFG->dirroot. "/lib/filelib.php");
|
||||
require_once($CFG->dirroot. "/lib/hublib.php");
|
||||
//$curl = new curl();
|
||||
$params['courseid'] = $courseid;
|
||||
$params['courseid'] = $course->id;
|
||||
$params['filetype'] = BACKUP_FILE_TYPE;
|
||||
|
||||
$url = new moodle_url($huburl.'/local/hub/webservice/download.php', $params);
|
||||
$path = $CFG->dataroot.'/temp/download/'.'backup_'.$courseid.".zip";
|
||||
if (!file_exists($CFG->dataroot.'/temp/communitydownload')) {
|
||||
mkdir($CFG->dataroot.'/temp/communitydownload/', 0777, true);
|
||||
}
|
||||
|
||||
//get hub id to make the
|
||||
|
||||
$url = new moodle_url($course->huburl.'/local/hub/webservice/download.php', $params);
|
||||
$path = $CFG->dataroot.'/temp/communitydownload/'.'backup_'.$course->fullname."_".$course->id.".zip";
|
||||
$fp = fopen($path, 'w');
|
||||
$ch = curl_init($huburl.'/local/hub/webservice/download.php?filetype='.BACKUP_FILE_TYPE.'&courseid='.$courseid);
|
||||
$ch = curl_init($course->huburl.'/local/hub/webservice/download.php?filetype='.BACKUP_FILE_TYPE.'&courseid='.$course->id);
|
||||
curl_setopt($ch, CURLOPT_FILE, $fp);
|
||||
$data = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
fclose($fp);
|
||||
|
||||
$fs = get_file_storage();
|
||||
$record->contextid = get_context_instance(CONTEXT_USER, $USER->id)->id;
|
||||
$record->filearea = 'user_backup';
|
||||
$record->itemid = 0;
|
||||
$record->filename = 'backup_'.$courseid.".zip";
|
||||
$record->filename = 'backup_'.$course->fullname."_".$course->id.".zip";
|
||||
$record->filepath = '/';
|
||||
$fs = get_file_storage();
|
||||
$fs->create_file_from_pathname($record, $CFG->dataroot.'/temp/download/'.'backup_'.$courseid.".zip");
|
||||
if (!$fs->file_exists($record->contextid, $record->filearea, 0, $record->filepath, $record->filename)) {
|
||||
$fs->create_file_from_pathname($record, $CFG->dataroot.'/temp/communitydownload/'.'backup_'.$course->fullname."_".$course->id.".zip");
|
||||
}
|
||||
//delete temp file
|
||||
unlink($path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -105,23 +105,25 @@ class block_community_renderer extends plugin_renderer_base {
|
||||
$language= '';
|
||||
}
|
||||
|
||||
if ($course->enrollable) {
|
||||
//Add link TODO make it a button and send by post
|
||||
$addurl = new moodle_url("/blocks/community/communitycourse.php",
|
||||
array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1,
|
||||
if ($course->enrollable) {
|
||||
$params = array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1,
|
||||
'coursefullname' => $course->fullname, 'courseurl' => $courseurl,
|
||||
'coursedescription' => $course->description));
|
||||
$addlinkhtml = html_writer::tag('a', get_string('addtocommunityblock', 'block_community'), array('href' => $addurl));
|
||||
'coursedescription' => $course->description);
|
||||
$addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
|
||||
$addbutton = new single_button($addurl, get_string('addtocommunityblock', 'block_community'));
|
||||
$addbutton->class = 'centeredbutton';
|
||||
$addbuttonhtml = $OUTPUT->render($addbutton);
|
||||
} 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));
|
||||
$params = array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
|
||||
'courseid' => $course->id, 'huburl' => $huburl, 'coursefullname' => $course->fullname);
|
||||
$addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
|
||||
$downloadbutton = new single_button($addurl, get_string('download', 'block_community'));
|
||||
$downloadbutton->class = 'centeredbutton';
|
||||
$addbuttonhtml = $OUTPUT->render($downloadbutton);
|
||||
}
|
||||
|
||||
// add a row to the table
|
||||
$cells = array($coursenamehtml, $deschtml, $language, $addlinkhtml);
|
||||
$cells = array($coursenamehtml, $deschtml, $language, $addbuttonhtml);
|
||||
|
||||
|
||||
$row = new html_table_row($cells);
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ $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['downloadconfirmed'] = 'The backup has been saved into your backup area under the name {$a}';
|
||||
$string['educationallevel'] = 'Educational level';
|
||||
$string['educationallevel_help'] = '';
|
||||
$string['edulevelassociation'] = 'Association';
|
||||
|
||||
Reference in New Issue
Block a user