Parent Directory
|
Revision Log
Implemented status system as per bug #743.
The status system consists of a new hash in the course environment,
%statuses, that maps status names (like "Enrolled", "Drop", "Audit") to
(a) a list of allowed abbreviations for the status and (b) a list of
behaviors the system should have when dealing with users who have the
status.
I didn't want to have to mangle that hash-of-hashes-of-arrays myself in
many modules, but I also didn't want to devote an entire module
(Status.pm) to it. So, I'm trying a little experiment: I've added them
as methods to WeBWorK::CourseEnvironment. My thinkint is that since all
the data for these operations comes from the course environment, so why
not have them be course environment methods? Here they are:
status_abbrev_to_name($status_abbrev)
Given the abbreviation for a status, return the name. Returns undef
if the abbreviation is not found.
status_name_to_abbrevs($status_name)
Returns the list of abbreviations for a given status. Returns an
empty list if the status is not found.
status_has_behavior($status_name, $behavior)
Return true if $status_name lists $behavior.
status_abbrev_has_behavior($status_abbrev, $behavior)
Return true if the status abbreviated by $status_abbrev lists
$behavior.
Since I removed the previous $siteDefaults{status} hash from
global.conf, I have already switched modules that formerly used that
hash over to using the new methods:
Authen.pm: use status_abbrev_has_behavior($status, "allow_course_access")
to determine if a user should be allowed to log in.
Feedback.pm: look up status abbreviation using status_abbrev_to_name()
and print the result for the status field in the email.
Instructor.pm: use status_abbrev_has_behavior($status, "include_in_assignment")
to determine if a user should be included in an assignment.
UserList.pm and UsersAssignedToSet.pm: use status_abbrev_to_name() to
get name of CSS class.
1 ################################################################################ 2 # WeBWorK Online Homework Delivery System 3 # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 4 # $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/Instructor/UsersAssignedToSet.pm,v 1.18 2005/08/12 02:47:30 sh002i Exp $ 5 # 6 # This program is free software; you can redistribute it and/or modify it under 7 # the terms of either: (a) the GNU General Public License as published by the 8 # Free Software Foundation; either version 2, or (at your option) any later 9 # version, or (b) the "Artistic License" which comes with this package. 10 # 11 # This program is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the 14 # Artistic License for more details. 15 ################################################################################ 16 17 package WeBWorK::ContentGenerator::Instructor::UsersAssignedToSet; 18 use base qw(WeBWorK::ContentGenerator::Instructor); 19 20 =head1 NAME 21 22 WeBWorK::ContentGenerator::Instructor::UsersAssignedToSet - List and edit the 23 users to which sets are assigned. 24 25 =cut 26 27 use strict; 28 use warnings; 29 use CGI qw(); 30 use WeBWorK::Debug; 31 32 sub initialize { 33 my ($self) = @_; 34 my $r = $self->r; 35 my $urlpath = $r->urlpath; 36 my $authz = $r->authz; 37 my $db = $r->db; 38 my $setID = $urlpath->arg("setID"); 39 my $user = $r->param('user'); 40 41 # Check permissions 42 return unless $authz->hasPermissions($user, "access_instructor_tools"); 43 return unless $authz->hasPermissions($user, "assign_problem_sets"); 44 45 my @users = $db->listUsers; 46 my %selectedUsers = map {$_ => 1} $r->param('selected'); 47 48 my $doAssignToSelected = 0; 49 50 # get the global user, if there is one 51 my $globalUserID = ""; 52 $globalUserID = $db->{set}->{params}->{globalUserID} 53 if ref $db->{set} eq "WeBWorK::DB::Schema::GlobalTableEmulator"; 54 55 if (defined $r->param('assignToAll')) { 56 debug("assignSetToAllUsers($setID)"); 57 $self->addmessage(CGI::div({class=>'ResultsWithoutError'}, "Problems have been assigned to all current users.")); 58 $self->assignSetToAllUsers($setID); 59 debug("done assignSetToAllUsers($setID)"); 60 } elsif (defined $r->param('unassignFromAll') and defined($r->param('unassignFromAllSafety')) and $r->param('unassignFromAllSafety')==1) { 61 %selectedUsers = ( $globalUserID => 1 ); 62 $self->addmessage(CGI::div({class=>'ResultsWithoutError'}, "Problems for all students have been unassigned.")); 63 $doAssignToSelected = 1; 64 } elsif (defined $r->param('assignToSelected')) { 65 $self->addmessage(CGI::div({class=>'ResultsWithoutError'}, "Problems for selected students have been reassigned.")); 66 $doAssignToSelected = 1; 67 } elsif (defined $r->param("unassignFromAll")) { 68 # no action taken 69 $self->addmessage(CGI::div({class=>'ResultsWithError'}, "No action taken")); 70 } 71 72 if ($doAssignToSelected) { 73 my $setRecord = $db->getGlobalSet($setID); #checked 74 die "Unable to get global set record for $setID " unless $setRecord; 75 76 my %setUsers = map { $_ => 1 } $db->listSetUsers($setID); 77 foreach my $selectedUser (@users) { 78 if (exists $selectedUsers{$selectedUser}) { 79 unless ($setUsers{$selectedUser}) { # skip users already in the set 80 debug("assignSetToUser($selectedUser, ...)"); 81 $self->assignSetToUser($selectedUser, $setRecord); 82 debug("done assignSetToUser($selectedUser, ...)"); 83 } 84 } else { 85 next if $selectedUser eq $globalUserID; 86 next unless $setUsers{$selectedUser}; # skip users not in the set 87 $db->deleteUserSet($selectedUser, $setID); 88 } 89 } 90 } 91 } 92 93 sub getSetName { 94 my ($self, $pathSetName) = @_; 95 if (ref $pathSetName eq "HASH") { 96 $pathSetName = undef; 97 } 98 return $pathSetName; 99 } 100 101 102 sub body { 103 my ($self) = @_; 104 my $r = $self->r; 105 my $urlpath = $r->urlpath; 106 my $db = $r->db; 107 my $ce = $r->ce; 108 my $authz = $r->authz; 109 my $webworkRoot = $ce->{webworkURLs}->{root}; 110 my $courseName = $urlpath->arg("courseID"); 111 my $setID = $urlpath->arg("setID"); 112 my $user = $r->param('user'); 113 114 return CGI::div({class=>"ResultsWithError"}, CGI::p("You are not authorized to acces the Instructor tools.")) 115 unless $authz->hasPermissions($user, "access_instructor_tools"); 116 117 return CGI::div({class=>"ResultsWithError"}, CGI::p("You are not authorized to assign homework sets.")) 118 unless $authz->hasPermissions($user, "assign_problem_sets"); 119 120 my @users = $db->listUsers; 121 print CGI::start_form({method=>"post", action => $self->systemLink( $urlpath, authen=>0) }); 122 123 print CGI::p( 124 CGI::submit({name=>"assignToAll", value => "Assign to All Current Users"}), CGI::i("This action can take a long time if there are many students.") 125 ), 126 CGI::div({-style=>"color:red"}, "Do not uncheck students, unless you know what you are doing.",CGI::br(), 127 "There is NO undo for unassigning students. "), 128 CGI::p("When you unassign 129 by unchecking a student's name, you destroy all 130 of the data for homework set $setID for this student. You will then need to 131 reassign the set to these students and they will receive new versions of the problems. 132 Make sure this is what you want to do before unchecking students." 133 ); 134 135 print CGI::start_table({}); 136 print CGI::Tr({-valign=>"top"}, CGI::th(["Assigned","Login Name"," ","Student Name"," ","Section"," ","Due Date"])); 137 print CGI::Tr(CGI::td([CGI::hr(),CGI::hr(),"",CGI::hr(),"",CGI::hr(),"",CGI::hr()," "])); 138 139 # get user records 140 my @userRecords = (); 141 foreach my $currentUser ( @users) { 142 my $userObj = $db->getUser($currentUser); #checked 143 die "Unable to find user object for $currentUser. " unless $userObj; 144 push (@userRecords, $userObj ); 145 } 146 @userRecords = sort { ( lc($a->section) cmp lc($b->section) ) || 147 ( lc($a->last_name) cmp lc($b->last_name )) } @userRecords; 148 149 # get the global user, if there is one 150 my $globalUserID = ""; 151 $globalUserID = $db->{set}->{params}->{globalUserID} 152 if ref $db->{set} eq "WeBWorK::DB::Schema::GlobalTableEmulator"; 153 154 foreach my $userRecord (@userRecords) { 155 156 my $statusClass = $ce->status_abbrev_to_name($userRecord->status) || ""; 157 158 my $user = $userRecord->user_id; 159 my $userSetRecord = $db->getUserSet($user, $setID); #checked 160 # don't need to check here, undefined values are handled below 161 #die "Unable to find record for user $user and set $setID " unless $userSetRecord; 162 my $prettyName = $userRecord->last_name 163 . ", " 164 . $userRecord->first_name; 165 my $dueDate = $userSetRecord->due_date if ref($userSetRecord); 166 my $prettyDate = ($dueDate)? '(' . $self->formatDateTime($dueDate) . ') ' : ''; 167 print CGI::Tr({}, 168 CGI::td({-align=>"center"}, 169 ($user eq $globalUserID 170 ? "" # no checkbox for global user! 171 : CGI::checkbox({ 172 type=>"checkbox", 173 name=>"selected", 174 checked=>( 175 defined($userSetRecord) # && $statusClass ne "Drop" 176 ? "on" 177 : "" 178 ), 179 value=>$user, 180 label=>"", 181 }) 182 ) 183 ),CGI::td({},[ 184 CGI::div({class=>$statusClass}, $user), 185 "", 186 "($prettyName)", " ", $userRecord->section, " ", 187 ( 188 defined $userSetRecord 189 ### ? $prettyDate . CGI::a( 190 ? ($prettyDate, "", CGI::a( 191 {href=>$self->systemLink($urlpath->new(type =>'instructor_set_detail', 192 args =>{courseID => $courseName, 193 setID => $setID 194 }), 195 params =>{editForUser=> $user} 196 )}, 197 "", 198 "Edit data for $user" 199 )) 200 : () 201 ), 202 ]) 203 ); 204 } 205 print CGI::Tr(CGI::td([CGI::hr(),CGI::hr(),"",CGI::hr(),"",CGI::hr(),"",CGI::hr()])); 206 print CGI::end_table(); 207 print $self->hidden_authen_fields; 208 print CGI::submit({name=>"assignToSelected", value=>"Save"}); 209 print CGI::p( CGI::hr(), 210 CGI::div( {class=>'ResultsWithError'}, 211 "There is NO undo for this function. 212 Do not use it unless you know what you are doing! When you unassign 213 a student using this button, or by unchecking their name, you destroy all 214 of the data for homework set $setID for this student.", 215 CGI::br(), 216 CGI::submit({name=>"unassignFromAll", value=>"Unassign from All Users"}), 217 CGI::radio_group(-name=>"unassignFromAllSafety", -values=>[0,1], -default=>0, -labels=>{0=>'Read only', 1=>'Allow unassign'}), 218 ), 219 CGI::hr(), 220 ); 221 print CGI::end_form(); 222 223 return ""; 224 } 225 226 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |