Parent Directory
|
Revision Log
Revision 1014 - (view) (download) (as text)
| 1 : | malsyned | 805 | package WeBWorK::ContentGenerator::Instructor; |
| 2 : | sh002i | 818 | use base qw(WeBWorK::ContentGenerator); |
| 3 : | malsyned | 805 | |
| 4 : | =head1 NAME | ||
| 5 : | |||
| 6 : | malsyned | 831 | WeBWorK::ContentGenerator::Instructor - Abstract superclass for the Instructor pages |
| 7 : | malsyned | 805 | |
| 8 : | =cut | ||
| 9 : | |||
| 10 : | use strict; | ||
| 11 : | use warnings; | ||
| 12 : | use CGI qw(); | ||
| 13 : | |||
| 14 : | malsyned | 1005 | sub hiddenEditForUserFields { |
| 15 : | my ($self, @editForUser) = @_; | ||
| 16 : | my $return = ""; | ||
| 17 : | foreach my $editUser (@editForUser) { | ||
| 18 : | $return .= CGI::input({type=>"hidden", name=>"editForUser", value=>$editUser}); | ||
| 19 : | } | ||
| 20 : | |||
| 21 : | return $return; | ||
| 22 : | } | ||
| 23 : | |||
| 24 : | sub userCountMessage { | ||
| 25 : | my ($self, $count, $numUsers) = @_; | ||
| 26 : | |||
| 27 : | my $message; | ||
| 28 : | if ($count == 0) { | ||
| 29 : | $message = CGI::em("no users"); | ||
| 30 : | } elsif ($count == $numUsers) { | ||
| 31 : | $message = "all users"; | ||
| 32 : | } elsif ($count == 1) { | ||
| 33 : | $message = "1 user"; | ||
| 34 : | } elsif ($count > $numUsers || $count < 0) { | ||
| 35 : | $message = CGI::em("an impossible number of users: $count out of $numUsers"); | ||
| 36 : | } else { | ||
| 37 : | $message = "$count users"; | ||
| 38 : | } | ||
| 39 : | |||
| 40 : | return $message; | ||
| 41 : | } | ||
| 42 : | |||
| 43 : | malsyned | 1013 | sub assignProblemToUser { |
| 44 : | my ($self, $user, $globalProblem) = @_; | ||
| 45 : | my $db = $self->{db}; | ||
| 46 : | malsyned | 1014 | my $userProblem = $db->{problem_user}->{record}->new; |
| 47 : | malsyned | 1013 | # Set up the key |
| 48 : | $userProblem->user_id($user); | ||
| 49 : | $userProblem->set_id($globalProblem->set_id); | ||
| 50 : | $userProblem->problem_id($globalProblem->problem_id); | ||
| 51 : | |||
| 52 : | # Initialize user-only fields | ||
| 53 : | $userProblem->status(0.0); | ||
| 54 : | $userProblem->attempted(0); | ||
| 55 : | $userProblem->num_correct(0); | ||
| 56 : | $userProblem->num_incorrect(0); | ||
| 57 : | $userProblem->attempted(0); | ||
| 58 : | $userProblem->problem_seed(int(rand(5000))); | ||
| 59 : | |||
| 60 : | $db->addUserProblem($userProblem); | ||
| 61 : | } | ||
| 62 : | malsyned | 1005 | |
| 63 : | malsyned | 1013 | sub assignSetToUser { |
| 64 : | my ($self, $user, $globalSet) = @_; | ||
| 65 : | my $db = $self->{db}; | ||
| 66 : | malsyned | 1014 | my $userSet = $db->{set_user}->{record}->new; |
| 67 : | malsyned | 1013 | my $setID = $globalSet->set_id; |
| 68 : | |||
| 69 : | $userSet->user_id($user); | ||
| 70 : | malsyned | 1014 | $userSet->set_id($setID); |
| 71 : | malsyned | 1013 | $db->addUserSet($userSet); |
| 72 : | |||
| 73 : | foreach my $problemID ($db->listGlobalProblems) { | ||
| 74 : | my $problemRecord = $db->getGlobalProblem($setID, $problemID); | ||
| 75 : | $self->assignProblemToUser($user, $problemRecord); | ||
| 76 : | } | ||
| 77 : | } | ||
| 78 : | |||
| 79 : | # When a new problem is added to a set, all students to whom the set | ||
| 80 : | # it belongs to is assigned should have it assigned to them. | ||
| 81 : | # Note that this does NOT assign to all users of a course, just all users | ||
| 82 : | # of a set. | ||
| 83 : | sub assignProblemToAllUsers { | ||
| 84 : | my ($self, $globalProblem) = @_; | ||
| 85 : | my $db = $self->{db}; | ||
| 86 : | my $setID = $globalProblem->set_id; | ||
| 87 : | my @users = $db->listSetUsers($setID); | ||
| 88 : | |||
| 89 : | foreach my $user (@users) { | ||
| 90 : | $self->assignProblemToUser($user, $globalProblem); | ||
| 91 : | } | ||
| 92 : | } | ||
| 93 : | |||
| 94 : | malsyned | 1005 | ## Template Escapes ## |
| 95 : | |||
| 96 : | sub links { | ||
| 97 : | gage | 833 | my $self = shift; |
| 98 : | |||
| 99 : | # keep the links from the parent | ||
| 100 : | my $pathString = ""; | ||
| 101 : | |||
| 102 : | |||
| 103 : | my $ce = $self->{ce}; | ||
| 104 : | my $db = $self->{db}; | ||
| 105 : | my $userName = $self->{r}->param("user"); | ||
| 106 : | my $courseName = $ce->{courseName}; | ||
| 107 : | my $root = $ce->{webworkURLs}->{root}; | ||
| 108 : | my $permLevel = $db->getPermissionLevel($userName)->permission(); | ||
| 109 : | my $key = $db->getKey($userName)->key(); | ||
| 110 : | return "" unless defined $key; | ||
| 111 : | |||
| 112 : | # new URLS | ||
| 113 : | malsyned | 996 | my $classList = "$root/$courseName/instructor/users/?". $self->url_authen_args(); |
| 114 : | gage | 840 | my $addStudent = "$root/$courseName/instructor/addStudent/?". $self->url_authen_args(); |
| 115 : | malsyned | 995 | my $problemSetList = "$root/$courseName/instructor/sets/?". $self->url_authen_args(); |
| 116 : | gage | 833 | |
| 117 : | gage | 840 | if ($permLevel > 0 ) { |
| 118 : | $pathString .="<hr>"; | ||
| 119 : | $pathString .= CGI::a({-href=>$classList}, "Class editor") . CGI::br(); | ||
| 120 : | $pathString .= ' '.CGI::a({-href=>$addStudent}, "Add Student") . CGI::br(); | ||
| 121 : | malsyned | 886 | $pathString .= CGI::a({-href=>$problemSetList}, "ProbSet list") . CGI::br(); |
| 122 : | gage | 840 | } |
| 123 : | return $self->SUPER::links() . $pathString; | ||
| 124 : | gage | 833 | } |
| 125 : | malsyned | 829 | |
| 126 : | 1; |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |