MDL-22639 fixed meadiafile support - unfortunately all old media files are lost, upgrade again from 1.9.....
This commit is contained in:
@@ -182,7 +182,7 @@ class backup_lesson_activity_structure_step extends backup_activity_structure_st
|
||||
$timer->annotate_ids('user', 'userid');
|
||||
|
||||
// Annotate the file areas in user by the lesson module.
|
||||
$lesson->annotate_files('mod_lesson', 'media_file', 'id');
|
||||
$lesson->annotate_files('mod_lesson', 'mediafile', 'id');
|
||||
$page->annotate_files('mod_lesson', 'page_contents', 'id');
|
||||
|
||||
// Prepare and return the structure we have just created for the lesson module.
|
||||
|
||||
@@ -124,7 +124,6 @@ function xmldb_lesson_upgrade($oldversion) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filearea = 'media_file';
|
||||
$filename = clean_param($lesson->mediafile, PARAM_FILE);
|
||||
if ($filename === '') {
|
||||
echo $OUTPUT->notification("Unsupported lesson filename, skipping: ".$filepath);
|
||||
@@ -133,8 +132,8 @@ function xmldb_lesson_upgrade($oldversion) {
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $lesson->cmid);
|
||||
if (!$fs->file_exists($context->id, 'mod_lesson', $filearea, $lesson->id, '/', $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_lesson', 'filearea'=>$filearea, 'itemid'=>$lesson->id, 'filepath'=>'/', 'filename'=>$filename);
|
||||
if (!$fs->file_exists($context->id, 'mod_lesson', 'mediafile', 0, '/', $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_lesson', 'filearea'=>'mediafile', 'itemid'=>0, 'filepath'=>'/', 'filename'=>$filename);
|
||||
if ($fs->create_file_from_pathname($file_record, $filepath)) {
|
||||
if ($DB->set_field('lesson', 'mediafile', $filename, array('id'=>$lesson->id))) {
|
||||
unlink($filepath);
|
||||
|
||||
+18
-9
@@ -53,8 +53,8 @@ function lesson_add_instance($data, $mform) {
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cmid);
|
||||
$lesson = $DB->get_record('lesson', array('id'=>$lessonid), '*', MUST_EXIST);
|
||||
|
||||
if ($filename = $mform->get_new_filename('mediafile')) {
|
||||
if ($file = $mform->save_stored_file('mediafile', $context->id, 'mod_lesson', 'media_file', $lesson->id, '/', $filename)) {
|
||||
if ($filename = $mform->get_new_filename('mediafilepicker')) {
|
||||
if ($file = $mform->save_stored_file('mediafilepicker', $context->id, 'mod_lesson', 'mediafile', 0, '/', $filename)) {
|
||||
$DB->set_field('lesson', 'mediafile', $file->get_filename(), array('id'=>$lesson->id));
|
||||
}
|
||||
}
|
||||
@@ -87,10 +87,14 @@ function lesson_update_instance($data, $mform) {
|
||||
$DB->update_record("lesson", $data);
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cmid);
|
||||
if ($filename = $mform->get_new_filename('mediafile')) {
|
||||
if ($file = $mform->save_stored_file('mediafile', $context->id, 'mod_lesson', 'media_file', $data->id, '/', $filename, true)) {
|
||||
if ($filename = $mform->get_new_filename('mediafilepicker')) {
|
||||
if ($file = $mform->save_stored_file('mediafilepicker', $context->id, 'mod_lesson', 'mediafile', 0, '/', $filename, true)) {
|
||||
$DB->set_field('lesson', 'mediafile', $file->get_filename(), array('id'=>$data->id));
|
||||
} else {
|
||||
$DB->set_field('lesson', 'mediafile', '', array('id'=>$data->id));
|
||||
}
|
||||
} else {
|
||||
$DB->set_field('lesson', 'mediafile', '', array('id'=>$data->id));
|
||||
}
|
||||
|
||||
lesson_process_post_save($data);
|
||||
@@ -905,10 +909,13 @@ function lesson_pluginfile($course, $cm, $context, $filearea, $args, $forcedownl
|
||||
return false;
|
||||
}
|
||||
$fullpath = "/$context->id/mod_lesson/$filearea/$pageid/".implode('/', $args);
|
||||
$forcedownload = true; //TODO: this is strange (skodak)
|
||||
} else {
|
||||
|
||||
$fullpath = "/$context->id/mod_lesson/$filearea/".implode('/', $args);
|
||||
} else if ($filearea === 'mediafile') {
|
||||
array_shift($args); // ignore itemid - caching only
|
||||
$fullpath = "/$context->id/mod_lesson/$filearea/0/".implode('/', $args);
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
@@ -926,8 +933,10 @@ function lesson_pluginfile($course, $cm, $context, $filearea, $args, $forcedownl
|
||||
*/
|
||||
function lesson_get_file_areas() {
|
||||
$areas = array();
|
||||
$areas['page_contents'] = 'page_contents'; //TODO: localize!!!!
|
||||
$areas['media_files'] = 'media_files'; //TODO: localize!!!!
|
||||
$areas['page_contents'] = 'Page contents'; //TODO: localize!!!!
|
||||
$areas['mediafile'] = 'Media file'; //TODO: localize!!!!
|
||||
|
||||
return $areas;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -588,8 +588,7 @@ function lesson_get_media_html($lesson, $context) {
|
||||
require_once("$CFG->libdir/resourcelib.php");
|
||||
|
||||
// get the media file link
|
||||
$path = '/'.$context->id.'/mod_lesson/media_file/'.$lesson->id->revision.'/'.$lesson->mediafile;
|
||||
$url = file_encode_url($CFG->wwwroot.'/pluginfile.php', $path, false);
|
||||
$url = moodle_url::make_pluginfile_url($context->id, 'mod_lesson', 'mediafile', $lesson->timemodified, '/', $lesson->mediafile);
|
||||
$title = $lesson->mediafile;
|
||||
|
||||
$clicktoopen = html_writer::link(new moodle_url($url), get_string('download'));
|
||||
|
||||
+46
-11
@@ -33,12 +33,6 @@ require_once($CFG->dirroot.'/mod/lesson/locallib.php');
|
||||
$id = required_param('id', PARAM_INT); // Course Module ID
|
||||
$printclose = optional_param('printclose', 0, PARAM_INT);
|
||||
|
||||
$url = new moodle_url('/mod/lesson/mediafile.php', array('id'=>$id));
|
||||
if ($printclose !== '') {
|
||||
$url->param('printclose', $printclose);
|
||||
}
|
||||
$PAGE->set_url($url);
|
||||
|
||||
$cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);;
|
||||
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
||||
$lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST));
|
||||
@@ -46,6 +40,16 @@ $lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*'
|
||||
require_login($course, false, $cm);
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$canmanage = has_capability('mod/lesson:manage', $context);
|
||||
|
||||
$url = new moodle_url('/mod/lesson/mediafile.php', array('id'=>$id));
|
||||
if ($printclose !== '') {
|
||||
$url->param('printclose', $printclose);
|
||||
}
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_pagelayout('popup');
|
||||
$PAGE->set_title($course->shortname);
|
||||
|
||||
$lessonoutput = $PAGE->get_renderer('mod_lesson');
|
||||
|
||||
// Get the mimetype
|
||||
@@ -53,7 +57,6 @@ $mimetype = mimeinfo("type", $lesson->mediafile);
|
||||
|
||||
if ($printclose) { // this is for framesets
|
||||
if ($lesson->mediaclose) {
|
||||
$PAGE->set_title($course->shortname);
|
||||
echo $lessonoutput->header($lesson, $cm);
|
||||
echo $OUTPUT->box('<form><div><input type="button" onclick="top.close();" value="'.get_string("closewindow").'" /></div></form>', 'lessonmediafilecontrol');
|
||||
echo $lessonoutput->footer();
|
||||
@@ -61,12 +64,44 @@ if ($printclose) { // this is for framesets
|
||||
exit();
|
||||
}
|
||||
|
||||
$mediafilehtml = lesson_get_media_html($lesson, $context);
|
||||
|
||||
$PAGE->set_title($course->shortname);
|
||||
echo $lessonoutput->header($lesson, $cm);
|
||||
|
||||
//TODO: this is copied from view.php - the access should be the same!
|
||||
/// Check these for students only TODO: Find a better method for doing this!
|
||||
/// Check lesson availability
|
||||
/// Check for password
|
||||
/// Check dependencies
|
||||
/// Check for high scores
|
||||
if (!$canmanage) {
|
||||
if (!$lesson->is_accessible()) { // Deadline restrictions
|
||||
echo $lessonoutput->header($lesson, $cm);
|
||||
if ($lesson->deadline != 0 && time() > $lesson->deadline) {
|
||||
echo $lessonoutput->lesson_inaccessible(get_string('lessonclosed', 'lesson', userdate($lesson->deadline)));
|
||||
} else {
|
||||
echo $lessonoutput->lesson_inaccessible(get_string('lessonopen', 'lesson', userdate($lesson->available)));
|
||||
}
|
||||
echo $lessonoutput->footer();
|
||||
exit();
|
||||
} else if ($lesson->usepassword && empty($USER->lessonloggedin[$lesson->id])) { // Password protected lesson code
|
||||
$correctpass = false;
|
||||
if (!empty($userpassword) && (($lesson->password == md5(trim($userpassword))) || ($lesson->password == trim($userpassword)))) {
|
||||
// with or without md5 for backward compatibility (MDL-11090)
|
||||
$USER->lessonloggedin[$lesson->id] = true;
|
||||
if ($lesson->highscores) {
|
||||
// Logged in - redirect so we go through all of these checks before starting the lesson.
|
||||
redirect("$CFG->wwwroot/mod/lesson/view.php?id=$cm->id");
|
||||
}
|
||||
} else {
|
||||
echo $lessonoutput->header($lesson, $cm);
|
||||
echo $lessonoutput->login_prompt($lesson, $userpassword !== '');
|
||||
echo $lessonoutput->footer();
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// print the embedded media html code
|
||||
echo $OUTPUT->box($mediafilehtml);
|
||||
echo $OUTPUT->box(lesson_get_media_html($lesson, $context));
|
||||
|
||||
if ($lesson->mediaclose) {
|
||||
echo '<div class="lessonmediafilecontrol">';
|
||||
|
||||
@@ -269,9 +269,8 @@ class mod_lesson_mod_form extends moodleform_mod {
|
||||
$filepickeroptions = array();
|
||||
$filepickeroptions['filetypes'] = '*';
|
||||
$filepickeroptions['maxbytes'] = $this->course->maxbytes;
|
||||
$mform->addElement('filepicker', 'mediafile', get_string('mediafile', 'lesson'), null, $filepickeroptions);
|
||||
$mform->addHelpButton('mediafile', 'mediafile', 'lesson');
|
||||
$mform->setDefault('mediafile', '');
|
||||
$mform->addElement('filepicker', 'mediafilepicker', get_string('mediafile', 'lesson'), null, $filepickeroptions);
|
||||
$mform->addHelpButton('mediafilepicker', 'mediafile', 'lesson');
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'dependencyon', get_string('dependencyon', 'lesson'));
|
||||
@@ -326,11 +325,12 @@ class mod_lesson_mod_form extends moodleform_mod {
|
||||
if (isset($default_values['password']) and ($module->version<2008112600)) {
|
||||
unset($default_values['password']);
|
||||
}
|
||||
if (!empty($this->_cm) && !empty($default_values['mediafile'])) {
|
||||
$context = get_context_instance(CONTEXT_MODULE, $this->_cm->id);
|
||||
$draftitemid = file_get_submitted_draft_itemid('mediafile');
|
||||
file_prepare_draft_area($draftitemid, $context->id, 'mod_lesson', 'media_file', $this->_cm->instance, array('subdirs' => 0, 'maxbytes' => $this->course->maxbytes, 'maxfiles' => 1));
|
||||
$default_values['mediafile'] = $draftitemid;
|
||||
|
||||
if ($this->current->instance) {
|
||||
// editing existing instance - copy existing files into draft area
|
||||
$draftitemid = file_get_submitted_draft_itemid('mediafilepicker');
|
||||
file_prepare_draft_area($draftitemid, $this->context->id, 'mod_lesson', 'mediafile', 0, array('subdirs'=>0, 'maxbytes' => $this->course->maxbytes, 'maxfiles' => 1));
|
||||
$default_values['mediafilepicker'] = $draftitemid;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user