Skip to content

Commit

Permalink
also assign sets and achievements to users copied from old course
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Jordan committed Jan 4, 2024
1 parent c18608b commit e0c8945
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/WeBWorK/Utils/CourseManagement.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use WeBWorK::CourseEnvironment;
use WeBWorK::DB;
use WeBWorK::Debug;
use WeBWorK::Utils qw(runtime_use readDirectory surePathToFile);
use WeBWorK::Utils::Instructor qw(assignSetsToUsers);

our @EXPORT_OK = qw(
listCourses
Expand Down Expand Up @@ -334,7 +335,9 @@ sub addCourse {
} else {
if ($db0 && $options{copyNonStudents}) {
my @non_student_ids =
map {@$_} ($db0->listPermissionLevelsWhere({ permission => { not_like => '0' } }, 'user_id'));
map {@$_} ($db0->listPermissionLevelsWhere(
{ permission => { not_like => '0' }, user_id => { not_like => 'set_id:%' } }, 'user_id'
));
my %user_args = map { $_->[0]{user_id} => 1 } (@users);

for my $user_id (@non_student_ids) {
Expand Down Expand Up @@ -376,6 +379,13 @@ sub addCourse {
warn $@ if $@;
}
}
if ($options{copyNonStudents}) {
foreach my $userTriple (@users) {
my $user_id = $userTriple->[0]{user_id};
my @user_sets = $db0->listUserSets($user_id);
assignSetsToUsers($db, $ce, \@user_sets, [$user_id]);
}
}
}

# add achievements
Expand All @@ -385,6 +395,18 @@ sub addCourse {
eval { $db->addAchievement($db0->getAchievement($achievement_id)) };
warn $@ if $@;
}
if ($options{copyNonStudents}) {
foreach my $userTriple (@users) {
my $user_id = $userTriple->[0]{user_id};
my @user_achievements = $db0->listUserAchievements($user_id);
for my $achievement_id (@user_achievements) {
my $userAchievement = $db->newUserAchievement();
$userAchievement->user_id($user_id);
$userAchievement->achievement_id($achievement_id);
$db->addUserAchievement($userAchievement);
}
}
}
}

# copy title and/or institution if requested
Expand Down Expand Up @@ -489,7 +511,6 @@ sub addCourse {
}

}

}

################################################################################
Expand Down

0 comments on commit e0c8945

Please sign in to comment.