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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : malsyned 832 package WeBWorK::ContentGenerator::Instructor::ProblemSetList;
2 :     use base qw(WeBWorK::ContentGenerator::Instructor);
3 :    
4 :     =head1 NAME
5 :    
6 :     WeBWorK::ContentGenerator::Instructor::ProblemSetList - Entry point for Problem and Set editing
7 :    
8 :     =cut
9 :    
10 :     use strict;
11 :     use warnings;
12 :     use CGI qw();
13 : malsyned 877 use WeBWorK::Utils qw(formatDateTime);
14 : malsyned 963 use WeBWorK::DB::Record::Set;
15 : malsyned 832
16 : malsyned 963 sub initialize {
17 :     my $self = shift;
18 :     my $r = $self->{r};
19 :     my $db = $self->{db};
20 :     my $ce = $self->{ce};
21 :     my $courseName = $ce->{courseName};
22 :    
23 :     if (defined($r->param('deleteSelected'))) {
24 :     foreach my $wannaDelete ($r->param('selectedSet')) {
25 :     $db->deleteGlobalSet($wannaDelete);
26 :     }
27 :     } elsif (defined($r->param('makeNewSet'))) {
28 :     my $newSetRecord = WeBWorK::DB::Record::Set->new();
29 :     my $newSetName = $r->param('newSetName');
30 :     $newSetRecord->set_id($newSetName);
31 : malsyned 977 $newSetRecord->set_header("");
32 :     $newSetRecord->problem_header("");
33 :     $newSetRecord->open_date("0");
34 :     $newSetRecord->due_date("0");
35 :     $newSetRecord->answer_date("0");
36 : malsyned 963 $db->addGlobalSet($newSetRecord) unless $db->getGlobalSet($newSetName);
37 :     }
38 :    
39 :     }
40 :    
41 : malsyned 836 sub title {
42 :     my $self = shift;
43 :     return "Instructor Tools - Problem Set List for ".$self->{ce}->{courseName};
44 :     }
45 :    
46 :     sub body {
47 : gage 859 my $self = shift;
48 : malsyned 877 my $r = $self->{r};
49 :     my $db = $self->{db};
50 : gage 859 my $ce = $self->{ce};
51 : malsyned 877 my $root = $ce->{webworkURLs}->{root};
52 : gage 859 my $courseName = $ce->{courseName};
53 :     my $user = $r->param('user');
54 :     my $key = $r->param('key');
55 :     my $effectiveUserName = $r->param('effectiveUser');
56 : malsyned 883 my $URL = $r->uri;
57 :     my $instructorBaseURL = "$root/$courseName/instructor";
58 :     my $setEditorURL = "$instructorBaseURL/problemSetEditor/";
59 :     my $importURL = "$instructorBaseURL/problemSetImport/";
60 :     my $addURL = "$instructorBaseURL/problemSetAdd/";
61 :     my $sort = $r->param('sort') ? $r->param('sort') : "due_date";
62 : gage 859
63 : malsyned 883 # Slurp each set record for this course in @sets
64 : malsyned 952 # Gather data from the database
65 :     my @users = $db->listUsers;
66 : malsyned 955 my @sets;
67 : malsyned 883 my %counts;
68 : malsyned 954 my %problemCounts;
69 : malsyned 955 foreach my $set_id ($db->listGlobalSets) {
70 :     my $set = $db->getGlobalSet($set_id);
71 :     push @sets, $set;
72 :     $problemCounts{$set_id} = scalar($db->listGlobalProblems($set_id));
73 : malsyned 877 my $count = 0;
74 : malsyned 955 $counts{$set_id} = $db->listSetUsers($set_id);
75 : malsyned 883 }
76 :    
77 :     # Sort @sets based on the sort parameter
78 :     # Invalid sort types will just cause an unpredictable ordering, which is no big deal.
79 :     @sets = sort {
80 :     if ($sort eq "set_id") {
81 :     return $a->$sort cmp $b->$sort;
82 :     }elsif ($sort =~ /_date$/) {
83 :     return $a->$sort <=> $b->$sort;
84 :     } elsif ($sort eq "num_probs") {
85 : malsyned 954 return $problemCounts{$a->set_id} <=> $problemCounts{$b->set_id};
86 : malsyned 883 } elsif ($sort eq "num_students") {
87 :     return $counts{$a->set_id} <=> $counts{$b->set_id};
88 :     }
89 :     } @sets;
90 :    
91 :     my $table = CGI::Tr({},
92 :     CGI::th("Sel.")
93 :     . CGI::th(CGI::a({"href"=>$URL."?".$self->url_authen_args."&sort=set_id"}, "ID"))
94 :     . CGI::th(CGI::a({"href"=>$URL."?".$self->url_authen_args."&sort=open_date"}, "Open Date"))
95 :     . CGI::th(CGI::a({"href"=>$URL."?".$self->url_authen_args."&sort=due_date"}, "Due Date"))
96 :     . CGI::th(CGI::a({"href"=>$URL."?".$self->url_authen_args."&sort=answer_date"}, "Answer Date"))
97 :     . CGI::th(CGI::a({"href"=>$URL."?".$self->url_authen_args."&sort=num_probs"}, "Num. Problems"))
98 :     . CGI::th(CGI::a({"href"=>$URL."?".$self->url_authen_args."&sort=num_students"}, "Assigned to:"))
99 :     ) . "\n";
100 :    
101 :     foreach my $set (@sets) {
102 :     my $count = $counts{$set->set_id};
103 : malsyned 877
104 :     my $userCountMessage;
105 :     if ($count == 0) {
106 :     $userCountMessage = "Not assigned";
107 :     } elsif ($count == scalar(@users)) {
108 :     $userCountMessage = "All users";
109 : malsyned 924 } elsif ($count == 1) {
110 :     $userCountMessage = "1 user";
111 : malsyned 883 } elsif ($count > scalar(@users) || $count < 0) {
112 : malsyned 877 $userCountMessage = CGI::em("Impossible number of users: $count");
113 :     } else {
114 :     $userCountMessage = "$count users";
115 :     }
116 :    
117 :     $table .= CGI::Tr({},
118 :     CGI::td({},
119 :     CGI::checkbox({
120 : malsyned 883 "name"=>"selectedSet",
121 : malsyned 877 "value"=>$set->set_id,
122 :     "label"=>"",
123 :     "checked"=>"0"
124 :     })
125 : malsyned 924 )
126 : malsyned 935 . CGI::td({}, CGI::a({href=>"$setEditorURL".$set->set_id."/?".$self->url_authen_args}, $set->set_id))
127 : malsyned 883 . CGI::td({}, formatDateTime($set->open_date))
128 :     . CGI::td({}, formatDateTime($set->due_date))
129 :     . CGI::td({}, formatDateTime($set->answer_date))
130 : malsyned 955 . CGI::td({}, $problemCounts{$set->set_id})
131 : malsyned 883 . CGI::td({}, $userCountMessage)
132 : malsyned 877 ) . "\n"
133 :     }
134 : malsyned 883 $table = CGI::table({"border"=>"1"}, "\n".$table."\n");
135 :    
136 : malsyned 978 my $form = CGI::start_form({"method"=>"POST", "action"=>$r->uri})."\n" # This form is for deleting sets, and points to itself
137 : malsyned 883 . $table."\n"
138 :     . CGI::br()."\n"
139 :     . $self->hidden_authen_fields."\n"
140 :     . CGI::submit({"name"=>"deleteSelected", "label"=>"Delete Selected"})."\n"
141 :     . CGI::end_form()."\n"
142 : malsyned 978 . CGI::start_form({"method"=>"POST", "action"=>$r->uri})."\n"
143 : malsyned 883 . $self->hidden_authen_fields."\n"
144 : malsyned 978 . "New Set Name: "
145 :     . CGI::input({type=>"text", name=>"newSetName", value=>""})
146 :     . CGI::submit({"name"=>"makeNewSet", "label"=>"Create"})."\n"
147 : malsyned 883 . CGI::end_form()."\n"
148 :     . CGI::start_form({"method"=>"POST", "action"=>$importURL})."\n"
149 :     . $self->hidden_authen_fields."\n"
150 :     . CGI::submit({"name"=>"importSet", "label"=>"Import"})."\n"
151 :     . CGI::end_form()."\n";
152 : malsyned 877 print $form;
153 :     print CGI::br();
154 :    
155 :     return "";
156 : malsyned 836 }
157 : malsyned 924
158 : malsyned 832 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9