[system] / trunk / webwork-modperl / lib / WeBWorK / ContentGenerator / Instructor / SetsAssignedToUser.pm Repository:
ViewVC logotype

Annotation of /trunk/webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SetsAssignedToUser.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1642 - (view) (download) (as text)

1 : sh002i 1627 ################################################################################
2 :     # WeBWorK mod_perl (c) 2000-2002 WeBWorK Project
3 :     # $Id$
4 :     ################################################################################
5 :    
6 :     package WeBWorK::ContentGenerator::Instructor::SetsAssignedToUser;
7 :     use base qw(WeBWorK::ContentGenerator::Instructor);
8 :    
9 :     =head1 NAME
10 :    
11 :     WeBWorK::ContentGenerator::Instructor::SetsAssignedToUsers - List and edit which
12 :     sets are assigned to a given user.
13 :    
14 :     =cut
15 :    
16 :     use strict;
17 :     use warnings;
18 :     use CGI qw();
19 :     use WeBWorK::Utils qw(formatDateTime);
20 :    
21 :     sub initialize {
22 :     my ($self, $userID) = @_;
23 :     my $r = $self->{r};
24 :     my $db = $self->{db};
25 :     my $authz = $self->{authz};
26 :     my $user = $r->param("user");
27 :    
28 :     # check authorization
29 :     unless ($authz->hasPermissions($user, "assign_problem_sets")) {
30 :     $self->{submitError} = "You are not authorized to assign problem sets";
31 :     return;
32 :     }
33 :    
34 :     if (defined $r->param("assignToAll")) {
35 : sh002i 1642 $self->assignAllSetsToUser($userID);
36 : sh002i 1627 } elsif (defined $r->param("unassignFromAll")) {
37 : sh002i 1642 $self->unassignAllSetsFromUser($userID);
38 : sh002i 1627 } elsif (defined $r->param('assignToSelected')) {
39 :     # get list of all sets and a hash for checking selectedness
40 :     my @setIDs = $db->listGlobalSets;
41 :     my %selectedSets = map { $_ => 1 } $r->param("selected");
42 :    
43 :     # get current user
44 :     my $User = $db->getUser($userID);
45 : sh002i 1642 die "record not found for $userID.\n" unless $User;
46 : sh002i 1627
47 :     # go through each possible set
48 :     foreach my $setID (@setIDs) {
49 :     # does the user want it to be assigned to the selected user
50 :     if (exists $selectedSets{$setID}) {
51 :     # user asked to have the set assigned to the selected user
52 :     my $Set = $db->getGlobalSet($setID);
53 :     if ($Set) {
54 :     $self->assignSetToUser($userID, $Set);
55 :     } else {
56 :     warn "global set $setID appeared in listGlobalSets() but does not exist.\n"
57 :     }
58 :     } else {
59 :     # user asked to NOT have the set assigned to the selected user
60 :     # this will unassign it if it is assigned
61 :     $db->deleteUserSet($userID, $setID);
62 :     }
63 :     }
64 :     }
65 :     }
66 :    
67 :     sub getUserName {
68 :     my ($self, $pathUserName) = @_;
69 :    
70 :     if (ref $pathUserName eq "HASH") {
71 :     $pathUserName = undef;
72 :     }
73 :    
74 :     return $pathUserName;
75 :     }
76 :    
77 :     sub path {
78 :     my $self = shift;
79 :     my @components = @_;
80 :     my $args = $_[-1];
81 :    
82 :     my $ce = $self->{ce};
83 :     my $root = $ce->{webworkURLs}->{root};
84 :     my $courseName = $ce->{courseName};
85 :     my $userID = $self->getUserName($components[0]);
86 :    
87 :     return $self->pathMacro($args,
88 :     "Home" => "$root",
89 :     $courseName => "$root/$courseName",
90 :     "Instructor Tools" => "$root/$courseName/instructor",
91 :     "Users" => "$root/$courseName/instructor/users/",
92 :     $userID => "$root/$courseName/instructor/users/$userID",
93 :     "Assigned Sets" => "", # "$root/$courseName/instructor/users/$userID/sets"
94 :     );
95 :     }
96 :    
97 :     sub title {
98 :     my ($self, @components) = @_;
99 :     my $userID = $self->getUserName($components[0]);
100 :    
101 :     return "Assigned Sets";
102 :     }
103 :    
104 :     sub body {
105 :     my ($self, $userID) = @_;
106 :     my $r = $self->{r};
107 :     my $authz = $self->{authz};
108 :     my $db = $self->{db};
109 :     my $ce = $self->{ce};
110 :     my $webworkRoot = $ce->{webworkURLs}->{root};
111 :     my $courseName = $ce->{courseName};
112 :     my $user = $r->param('user');
113 :    
114 :     # check authorization
115 :     return CGI::em("You are not authorized to access the Instructor tools.")
116 :     unless $authz->hasPermissions($user, "access_instructor_tools");
117 :    
118 :     # get list of sets
119 :     my @setIDs = $db->listGlobalSets;
120 :     my @Sets = $db->getGlobalSets(@setIDs);
121 :    
122 :     # sort first by open date and then by name (this should be replaced with a
123 :     # call to a standard sorting routine!)
124 :     @Sets = sort {
125 :     $a->open_date <=> $b->open_date
126 :     || lc($a->set_id) cmp lc($b->set_id)
127 :     } @Sets;
128 :    
129 :     print CGI::start_form({method=>"post", action=>$r->uri});
130 :     print $self->hidden_authen_fields;
131 :    
132 :     print CGI::p(
133 :     CGI::submit({name=>"assignToAll", value=>"Assign all sets"}),
134 :     CGI::submit({name=>"unassignFromAll", value=>"Unassign all sets"}),
135 :     );
136 :    
137 :     print CGI::start_table({});
138 :    
139 :     foreach my $Set (@Sets) {
140 :     my $setID = $Set->set_id;
141 :     my $prettyName = formatDateTime($Set->open_date);
142 :    
143 :     # this is true if $Set is assigned to the selected user
144 :     my $currentlyAssigned = defined $db->getUserSet($userID, $setID);
145 :    
146 :     # URL to edit user-specific set data
147 :     my $url = $ce->{webworkURLs}->{root}
148 :     . "/$courseName/instructor/sets/$setID/?editForUser=$userID&"
149 :     . $self->url_authen_args();
150 :    
151 :     print CGI::Tr({},
152 :     CGI::td({}, [
153 :     CGI::checkbox({
154 :     type=>"checkbox",
155 :     name=>"selected",
156 :     checked=>$currentlyAssigned,
157 :     value=>$setID,
158 :     label=>"",
159 :     }),
160 :     $setID,
161 :     "($prettyName)",
162 :     " ",
163 :     $currentlyAssigned
164 :     ? CGI::a({href=>$url}, "Edit user-specific set data")
165 :     : (),
166 :     ])
167 :     );
168 :     }
169 :     print CGI::end_table();
170 :     print CGI::submit({name=>"assignToSelected", value=>"Save"});
171 :     print CGI::end_form();
172 :    
173 :     return "";
174 :     }
175 :    
176 :     1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9