From 6f363ad9e184a2d213bc9eb4b3af57f79511ae98 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Wed, 26 Jul 2017 17:00:36 +0800 Subject: [PATCH 1/2] MDL-59893 assign: fixes for groupname prefix when downloading assign->download_submissions(): - groupname now only added to zip file name if not empty, fixing a double hyphen bug in the file name. assign->download_rewrite_pluginfile_urls(): - groupname is now correctly determined using get_submission_group() instead of using groups_get_activity_group() which fails when there is no active activity group set. Uses the same logic that download_submission() uses to prefix file names. Fixes a bug where an empty groupname prefix was generated, resulting in broken links. --- mod/assign/locallib.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 09011c84655..6d26297b8bf 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -2886,11 +2886,17 @@ class assign { * @param assign_plugin $plugin - The assignment plugin */ public function download_rewrite_pluginfile_urls($text, $user, $plugin) { - $groupmode = groups_get_activity_groupmode($this->get_course_module()); + // The groupname prefix for the urls doesn't depend on the group mode of the assignment instance. + // Rather, it should be determined by checking the group submission settings of the instance, + // which is what download_submission() does when generating the file name prefixes. $groupname = ''; - if ($groupmode) { - $groupid = groups_get_activity_group($this->get_course_module(), true); - $groupname = groups_get_group_name($groupid).'-'; + if ($this->get_instance()->teamsubmission) { + $submissiongroup = $this->get_submission_group($user->id); + if ($submissiongroup) { + $groupname = $submissiongroup->name . '-'; + } else { + $groupname = get_string('defaultteam', 'assign') . '-'; + } } if ($this->is_blind_marking()) { @@ -3114,7 +3120,9 @@ class assign { $groupname = ''; if ($groupmode) { $groupid = groups_get_activity_group($this->get_course_module(), true); - $groupname = groups_get_group_name($groupid).'-'; + if (!empty($groupid)) { + $groupname = groups_get_group_name($groupid) . '-'; + } } // Construct the zip file name. From 5dde47c0d1c68f3138906ed9750d7685802b5f69 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Wed, 26 Jul 2017 17:03:46 +0800 Subject: [PATCH 2/2] MDL-59893 assign: don't prefix file links when downloading as folders Change to download_rewrite_pluginfile_urls() ensuring prefix isn't added to file links when downloading with the downloadasfolders user preference set to true. Links to files in onlinetext now work when downloading as folders. --- mod/assign/locallib.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 6d26297b8bf..621a046c046 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -2909,10 +2909,14 @@ class assign { $prefix = clean_filename($prefix . '_' . $this->get_uniqueid_for_user($user->id) . '_'); } - $subtype = $plugin->get_subtype(); - $type = $plugin->get_type(); - $prefix = $prefix . $subtype . '_' . $type . '_'; - + // Only prefix files if downloadasfolders user preference is NOT set. + if (!get_user_preferences('assign_downloadasfolders', 1)) { + $subtype = $plugin->get_subtype(); + $type = $plugin->get_type(); + $prefix = $prefix . $subtype . '_' . $type . '_'; + } else { + $prefix = ""; + } $result = str_replace('@@PLUGINFILE@@/', $prefix, $text); return $result;