diff --git a/renderer.php b/renderer.php index 6ab5b10..da1c25b 100644 --- a/renderer.php +++ b/renderer.php @@ -21,6 +21,7 @@ * @subpackage fileresponse * @copyright 2012 Luca Bösch luca.boesch@bfh.ch * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * */ defined('MOODLE_INTERNAL') || die(); @@ -181,24 +182,19 @@ public function formulation_and_controls(question_attempt $qa, question_display_ return $result; } - /** - * Displays any attached files when the question is in read-only mode. - * - * @param question_attempt $qa the question attempt to display. - * @param question_display_options $options controls what should and should - * not be displayed. Used to get the context. - */ - public function files_read_only(question_attempt $qa, question_display_options $options, - $question) { + public function get_uploader_name($userid, $question) { global $DB, $COURSE; - $files = $qa->get_last_qt_files('attachments', $options->context->id); - $step = $qa->get_last_step_with_qt_var('answer'); - $output = array(); - $returnfiles = array(); - $zipper = new zip_packer(); - $student_name_qid_str = '_'; - $examination_user = $DB->get_record('user', array('id' => $step->get_user_id() + $student_name_qid_arr = array(); + $examination_user = $DB->get_record('user', array('id' => $userid )); + if (!$examination_user) { + $student_name_qid_arr[0] = 'uknown'; + $student_name_qid_arr[1] = 'uknown'; + $student_name_qid_arr[2] = 'uknown'; + $student_name_qid_arr[3] = 0; + $student_name_qid_arr[4] = 'uknown'; + return $student_name_qid_arr; + } // Remove anything which isn't a word, whitespace, number // or any of the following caracters -_~,;[](). // If you don't need to handle multi-byte characters @@ -212,13 +208,46 @@ public function files_read_only(question_attempt $qa, question_display_options $ // Remove any runs of periods $cleanedlname = mb_ereg_replace("([\.]{2,})", '', $cleanedlname); - $student_name_qid_str .= $cleanedfname . '_' . $cleanedlname . '_' . $question->id; + $student_name_qid_arr[0] = '_' . $cleanedfname . '_' . $cleanedlname . '_' . $question->id; + $student_name_qid_arr[1] = $examination_user->firstname; + $student_name_qid_arr[2] = $examination_user->lastname; + $student_name_qid_arr[3] = $examination_user->id; + $student_name_qid_arr[4] = $examination_user->email; + return $student_name_qid_arr; + } - $skipfile = 'All_Files' . $student_name_qid_str . '.zip'; + /** + * Displays any attached files when the question is in read-only mode. + * + * @param question_attempt $qa the question attempt to display. + * @param question_display_options $options controls what should and should + * not be displayed. Used to get the context. + */ + public function files_read_only(question_attempt $qa, question_display_options $options, + $question) { + global $DB, $COURSE; + $files = $qa->get_last_qt_files('attachments', $options->context->id); + $step = $qa->get_last_step_with_qt_var('answer'); + $output = array(); + $returnfiles = array(); + $zipper = new zip_packer(); $infocreated = 0; foreach ($files as $file) { - // if (strtolower($file->get_filename()) == strtolower($skipfile)) { - if (strpos($file->get_filename(), 'All_Files_') !== false) { // Avoid Restore duplicates + $student_name_qid_arr = $this->get_uploader_name($file->get_userid(), $question); + + $skipfile = 'All_Files' . $student_name_qid_arr[0] . '.zip'; + + if (strpos($file->get_filename(), 'All_Files') !== false) { // Avoid Restore duplicates + // Get old zipped file + $fs = get_file_storage(); + $itemid = $file->get_itemid(); + $skipzippedfile = $fs->get_file($options->context->id, 'question', + 'response_attachments', $itemid, '/qtype_fileresponse_zipped/', + $file->get_filename()); + + if ($skipzippedfile) { + $skipzippedfile->delete(); + } continue; } $output[] = html_writer::tag('p', @@ -232,10 +261,10 @@ public function files_read_only(question_attempt $qa, question_display_options $ if (!$infocreated) { // Create info file. - $infocontent = get_string('user') . ': ' . $examination_user->firstname . ' ' . - $examination_user->lastname . " \r\n"; - $infocontent .= get_string('email') . ': ' . $examination_user->email . ' (ID: ' . - $examination_user->id . ') ' . "\r\n"; + $infocontent = get_string('user') . ': ' . $student_name_qid_arr[1] . ' ' . + $student_name_qid_arr[2] . " \r\n"; + $infocontent .= get_string('email') . ': ' . $student_name_qid_arr[4] . ' (ID: ' . + $student_name_qid_arr[3] . ') ' . "\r\n"; $infocontent .= get_string('question') . ': ' . $question->name . ' (ID: ' . $question->id . ') ' . "\r\n"; $infocontent .= get_string('course') . ': ' . $COURSE->fullname . ' (ID: ' . @@ -258,6 +287,7 @@ public function files_read_only(question_attempt $qa, question_display_options $ // Get info file $infotxtfile = $fs->get_file($options->context->id, 'question', 'response_attachments', $itemid, '/', '_user_info.txt'); + $infocreated = 1; } } @@ -265,11 +295,12 @@ public function files_read_only(question_attempt $qa, question_display_options $ $final_zipped_file = $zipper->archive_to_storage($returnfiles, $options->context->id, 'question', 'response_attachments', $itemid, '/qtype_fileresponse_zipped/', - $skipfile, $step->get_user_id()); + $skipfile, $file->get_userid()); // Delete info text if it exists if ($infotxtfile) { $infotxtfile->delete(); } + // Add Zipped to all links $output[] = html_writer::tag('hr', ''); $output[] = html_writer::tag('p', @@ -600,8 +631,9 @@ protected function get_filepicker_options($context, $draftitemid) { return array( 'image' => $this->specific_filepicker_options(array('image' ), $draftitemid, $context), - 'media' => $this->specific_filepicker_options(array('video', 'audio' - ), $draftitemid, $context), + 'media' => $this->specific_filepicker_options( + array('video', 'audio' + ), $draftitemid, $context), 'link' => $this->specific_filepicker_options('*', $draftitemid, $context) ); } diff --git a/version.php b/version.php index e959f07..a8bd014 100644 --- a/version.php +++ b/version.php @@ -25,6 +25,6 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'qtype_fileresponse'; -$plugin->version = 2016112800; +$plugin->version = 2017022200; $plugin->requires = 2015050500; $plugin->maturity = MATURITY_BETA;