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.
This commit is contained in:
Jake Dallimore 2017-07-26 17:00:36 +08:00
parent 27466d7548
commit a15dfc6682

View file

@ -2944,11 +2944,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()) {
@ -3172,7 +3178,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.