From f359ecf6d573892c86d85cb6bb5331431a1d51a1 Mon Sep 17 00:00:00 2001
From: Isabel <isabel-andrea.uffinger@stud.hs-hannover.de>
Date: Sun, 28 May 2023 16:49:18 +0200
Subject: [PATCH] Colorized file attachements for teachers
---
classes/output/renderer.php | 86 ++++++++++++++++++++++---------------
styles.css | 4 +-
2 files changed, 54 insertions(+), 36 deletions(-)
diff --git a/classes/output/renderer.php b/classes/output/renderer.php
index 5249bd9..70840f0 100644
--- a/classes/output/renderer.php
+++ b/classes/output/renderer.php
@@ -180,7 +180,7 @@ class qtype_moopt_renderer extends qtype_renderer {
global $PAGE;
$o = '<br>';
- $o .= $this->output->heading(get_string('gradingscheme', 'qtype_moopt'), 3);#
+ $o .= $this->output->heading(get_string('gradingscheme', 'qtype_moopt'), 3);
$blockid = "moopt-gradingscheme-" . $qa->get_usage_id() . "-" . $qa->get_slot();
$PAGE->requires->js_call_amd('qtype_moopt/toggle_all_grading_scheme_buttons', 'init', [$blockid]);
@@ -215,50 +215,68 @@ class qtype_moopt_renderer extends qtype_renderer {
private function render_downloadable_files(question_attempt $qa, question_display_options $options) {
global $DB;
+ $question = $qa->get_question();
+ $questionid = $question->id;
+ $o = '';
+ $isteacher = has_capability('mod/quiz:grade', $options->context);
+
+ $studentfiles = $DB->get_records('qtype_moopt_files', array('questionid' => $questionid,
+ 'visibletostudents' => 'yes', 'usagebylms' => 'download'));
+ if(count($studentfiles) != 0) {
+ $o .= $this->render_downloadable_files_only($qa, $options, $studentfiles, 'providedfiles');
+ }
+
+ if ($isteacher){
+ $teacherfiles = $DB->get_records('qtype_moopt_files', array('questionid' => $questionid, 'visibletostudents' => 'no'));
+ if(count($teacherfiles) != 0) {
+ $o .= $this->render_downloadable_files_only($qa, $options, $teacherfiles, 'providedfilesteacher');
+ }
+ }
+ return $o;
+ }
+
+ private function render_downloadable_files_only (question_attempt $qa, question_display_options $options, $files, $divclass) {
$question = $qa->get_question();
$qubaid = $qa->get_usage_id();
$slot = $qa->get_slot();
$questionid = $question->id;
- $o = '';
$isteacher = has_capability('mod/quiz:grade', $options->context);
+ $o = '';
- $files = $DB->get_records('qtype_moopt_files', array('questionid' => $questionid));
$anythingtodisplay = false;
- if (count($files) != 0) { // TODO: this check should happen before these render methods are called
- $downloadurls = '';
- $downloadurls .= $this->output->heading(get_string('providedfiles', 'qtype_moopt'), 3);
- $downloadurls .= html_writer::start_div('providedfiles');
- $downloadurls .= '<ul>';
- foreach ($files as $file) {
- // skip files that are
- // - not configured to be downloadable (usagebylms)
- // - not visible to students
- if ($file->usagebylms == 'display'
- || ($file->visibletostudents == 'no' && !$isteacher)
- || ($file->usagebylms == 'edit' && !$isteacher)) {
- continue;
- }
-
- $anythingtodisplay = true;
- $url = moodle_url::make_pluginfile_url($question->contextid, COMPONENT_NAME, $file->filearea,
- "$qubaid/$slot/$questionid", $file->filepath, $file->filename, true);
- if ($file->filearea == PROFORMA_ATTACHED_TASK_FILES_FILEAREA) {
- $folderdisplay = $file->filepath;
- // remove leading slash:
- if (strlen($folderdisplay) > 0 && $folderdisplay[0] == '/') $folderdisplay = substr($folderdisplay, 1);
- } else {
- $folderdisplay = '';
- }
- $linkdisplay = $folderdisplay . $file->filename;
- $downloadurls .= '<li><a href="' . $url . '">' . $linkdisplay . '</a></li>';
+ $downloadurls = '';
+ if(!$isteacher) {
+ $o .= $this->output->heading(get_string('providedfiles', 'qtype_moopt'), 3);
+ }
+ $downloadurls .= html_writer::start_div($divclass);
+ $downloadurls .= '<ul>';
+ foreach ($files as $file) {
+ // skip files that are
+ // - not configured to be downloadable (usagebylms)
+ if ($file->usagebylms == 'display') {
+ continue;
}
- $downloadurls .= '</ul>';
- $downloadurls .= html_writer::end_div('providedfiles');
- if ($anythingtodisplay) {
- $o .= $downloadurls;
+ $anythingtodisplay = true;
+ $url = moodle_url::make_pluginfile_url($question->contextid, COMPONENT_NAME, $file->filearea,
+ "$qubaid/$slot/$questionid", $file->filepath, $file->filename, true);
+ if ($file->filearea == PROFORMA_ATTACHED_TASK_FILES_FILEAREA) {
+ $folderdisplay = $file->filepath;
+ // remove leading slash:
+ if (strlen($folderdisplay) > 0 && $folderdisplay[0] == '/') $folderdisplay = substr($folderdisplay, 1);
+ } else {
+ $folderdisplay = '';
}
+ $linkdisplay = $folderdisplay . $file->filename;
+ $downloadurls .= '<li><a href="' . $url . '">' . $linkdisplay . '</a></li>';
+ }
+ $downloadurls .= '</ul>';
+ $downloadurls .= html_writer::end_div($divclass);
+
+ if ($anythingtodisplay) {
+ $o .= $downloadurls;
}
+
return $o;
}
diff --git a/styles.css b/styles.css
index 4d54b90..2134e1c 100644
--- a/styles.css
+++ b/styles.css
@@ -73,7 +73,7 @@ p.expandcollapselink a {
margin-left: 10px;
}
-.providedfiles{
+.providedfiles, .providedfilesteacher{
margin-left: 10px;
}
@@ -90,7 +90,7 @@ p.expandcollapselink a {
100% { transform: rotate(360deg); }
}
-.internaldescription, .gradingscheme {
+.internaldescription, .gradingscheme, .providedfilesteacher {
background-color: #73afdc;
margin-top: 10px;
}
\ No newline at end of file
--
GitLab