Parent Directory
|
Revision Log
Removed a warning in WW1Hash. Renamed a function with a confusing name: assignProblemToAllUsers => assignProblemToAllSetUsers. -Dennis
1 package WeBWorK::ContentGenerator::Instructor; 2 use base qw(WeBWorK::ContentGenerator); 3 4 =head1 NAME 5 6 WeBWorK::ContentGenerator::Instructor - Abstract superclass for the Instructor pages 7 8 =cut 9 10 use strict; 11 use warnings; 12 use CGI qw(); 13 use WeBWorK::DB::Utils qw(global2user initializeUserProblem); 14 15 sub hiddenEditForUserFields { 16 my ($self, @editForUser) = @_; 17 my $return = ""; 18 foreach my $editUser (@editForUser) { 19 $return .= CGI::input({type=>"hidden", name=>"editForUser", value=>$editUser}); 20 } 21 22 return $return; 23 } 24 25 sub userCountMessage { 26 my ($self, $count, $numUsers) = @_; 27 28 my $message; 29 if ($count == 0) { 30 $message = CGI::em("no users"); 31 } elsif ($count == $numUsers) { 32 $message = "all users"; 33 } elsif ($count == 1) { 34 $message = "1 user"; 35 } elsif ($count > $numUsers || $count < 0) { 36 $message = CGI::em("an impossible number of users: $count out of $numUsers"); 37 } else { 38 $message = "$count users"; 39 } 40 41 return $message; 42 } 43 44 ### Utility functions for assigning sets to users. 45 # These silently fail if the problem or set exists for the user. 46 47 sub assignProblemToUser { 48 my ($self, $user, $globalProblem) = @_; 49 my $db = $self->{db}; 50 my $userProblem = $db->{problem_user}->{record}->new; 51 52 # Set up the key 53 $userProblem->user_id($user); 54 $userProblem->set_id($globalProblem->set_id); 55 $userProblem->problem_id($globalProblem->problem_id); 56 57 initializeUserProblem($userProblem); 58 eval {$db->addUserProblem($userProblem)}; 59 } 60 61 sub assignSetToUser { 62 my ($self, $user, $globalSet) = @_; 63 my $db = $self->{db}; 64 my $userSet = $db->{set_user}->{record}->new; 65 my $setID = $globalSet->set_id; 66 67 $userSet->user_id($user); 68 $userSet->set_id($setID); 69 eval {$db->addUserSet($userSet)}; 70 71 foreach my $problemID ($db->listGlobalProblems($setID)) { 72 my $problemRecord = $db->getGlobalProblem($setID, $problemID); 73 $self->assignProblemToUser($user, $problemRecord); 74 } 75 } 76 77 # When a new problem is added to a set, all students to whom the set 78 # it belongs to is assigned should have it assigned to them. 79 # Note that this does NOT assign to all users of a course, just all users 80 # of a set. 81 sub assignProblemToAllSetUsers { 82 my ($self, $globalProblem) = @_; 83 my $db = $self->{db}; 84 my $setID = $globalProblem->set_id; 85 my @users = $db->listSetUsers($setID); 86 87 foreach my $user (@users) { 88 warn time, ": assignProblemToUser $user\n"; 89 $self->assignProblemToUser($user, $globalProblem); 90 } 91 } 92 93 # READ THIS: Unlike the above function, "All" here refers to all of the 94 # users of a course. 95 # This function caches database data as a speed optimization. 96 sub assignSetToAllUsers { 97 my ($self, $setID) = @_; 98 my $db = $self->{db}; 99 my @problems = (); 100 my @users = $db->listUsers; 101 my @problemRecords = map {$db->getGlobalProblem($setID, $_)} $db->listGlobalProblems($setID); 102 103 foreach my $user (@users) { 104 # FIXME: Create a UserSet record for the user!!!! 105 my $userSet = $db->{set_user}->{record}->new; 106 $userSet->user_id($user); 107 $userSet->set_id($setID); 108 eval {$db->addUserSet($userSet)}; 109 foreach my $problemRecord (@problemRecords) { 110 $self->assignProblemToUser($user, $problemRecord); 111 } 112 } 113 } 114 115 ## Template Escapes ## 116 117 sub links { 118 my $self = shift; 119 120 # keep the links from the parent 121 my $pathString = ""; 122 123 124 my $ce = $self->{ce}; 125 my $db = $self->{db}; 126 my $userName = $self->{r}->param("user"); 127 my $courseName = $ce->{courseName}; 128 my $root = $ce->{webworkURLs}->{root}; 129 my $permLevel = $db->getPermissionLevel($userName)->permission(); 130 my $key = $db->getKey($userName)->key(); 131 return "" unless defined $key; 132 133 # new URLS 134 my $classList = "$root/$courseName/instructor/users/?". $self->url_authen_args(); 135 my $addStudent = "$root/$courseName/instructor/addStudent/?". $self->url_authen_args(); 136 my $problemSetList = "$root/$courseName/instructor/sets/?". $self->url_authen_args(); 137 138 if ($permLevel > 0 ) { 139 $pathString .="<hr>"; 140 $pathString .= CGI::a({-href=>$classList}, "Class editor") . CGI::br(); 141 $pathString .= ' '.CGI::a({-href=>$addStudent}, "Add Student") . CGI::br(); 142 $pathString .= CGI::a({-href=>$problemSetList}, "ProbSet list") . CGI::br(); 143 } 144 return $self->SUPER::links() . $pathString; 145 } 146 147 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |