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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : sh002i 455 ################################################################################
2 : sh002i 494 # WeBWorK mod_perl (c) 2000-2002 WeBWorK Project
3 : sh002i 455 # $Id$
4 :     ################################################################################
5 :    
6 : malsyned 353 package WeBWorK::ContentGenerator::ProblemSets;
7 :    
8 : sh002i 455 =head1 NAME
9 :    
10 :     WeBWorK::ContentGenerator::ProblemSets - Display a list of built problem sets.
11 :    
12 :     =cut
13 :    
14 : malsyned 441 use strict;
15 :     use warnings;
16 : sh002i 455 use base qw(WeBWorK::ContentGenerator);
17 : sh002i 449 use Apache::Constants qw(:common);
18 :     use CGI qw();
19 : malsyned 353 use WeBWorK::ContentGenerator;
20 : malsyned 441 use WeBWorK::DB::WW;
21 : sh002i 449 use WeBWorK::Utils qw(formatDateTime);
22 : malsyned 353
23 : malsyned 441 sub initialize {
24 :     my $self = shift;
25 :     my $courseEnvironment = $self->{courseEnvironment};
26 :    
27 :     # Open a database connection that we can use for the rest of
28 :     # the content generation.
29 :    
30 :     my $wwdb = new WeBWorK::DB::WW $courseEnvironment;
31 :     $self->{wwdb} = $wwdb;
32 :     }
33 :    
34 : sh002i 469 sub path {
35 :     my ($self, $args) = @_;
36 :    
37 :     my $ce = $self->{courseEnvironment};
38 :     my $root = $ce->{webworkURLs}->{root};
39 :     my $courseName = $ce->{courseName};
40 :     return $self->pathMacro($args,
41 :     "Home" => "$root",
42 :     $courseName => "",
43 :     );
44 :     }
45 :    
46 : malsyned 353 sub title {
47 :     my $self = shift;
48 :     my $courseEnvironment = $self->{courseEnvironment};
49 : sh002i 469
50 :     return $courseEnvironment->{courseName};
51 : malsyned 353 }
52 :    
53 :     sub body {
54 :     my $self = shift;
55 :     my $r = $self->{r};
56 :     my $courseEnvironment = $self->{courseEnvironment};
57 : sh002i 683 my $user = $r->param("user");
58 : sh002i 692 my $sort = $r->param("sort") || "status";
59 : malsyned 441 my $wwdb = $self->{wwdb};
60 : malsyned 353
61 : sh002i 683 $sort = "status" unless $sort eq "status" or $sort eq "name";
62 :     my $baseURL = $r->uri . "?" . $self->url_authen_args();
63 :     my $nameHeader = ($sort eq "name") ? "Name" : CGI::a({-href=>"$baseURL&sort=name"}, "Name");
64 :     my $statusHeader = ($sort eq "status") ? "Status" : CGI::a({-href=>"$baseURL&sort=status"}, "Status");
65 :    
66 : sh002i 640 print CGI::startform(-method=>"POST", -action=>$r->uri."hardcopy/");
67 :     print $self->hidden_authen_fields;
68 : sh002i 449 print CGI::start_table();
69 :     print CGI::Tr(
70 : sh002i 469 CGI::th("Sel."),
71 : sh002i 683 CGI::th($nameHeader),
72 :     CGI::th($statusHeader),
73 : sh002i 469 CGI::th("Hardcopy"),
74 : sh002i 449 );
75 :    
76 : sh002i 469 my @sets;
77 :     push @sets, $wwdb->getSet($user, $_) foreach ($wwdb->getSets($user));
78 : sh002i 683 @sets = sort byname @sets if $sort eq "name";
79 :     @sets = sort byduedate @sets if $sort eq "status";
80 :     foreach my $set (@sets) {
81 : sh002i 469 print $self->setListRow($set);
82 : sh002i 449 }
83 : malsyned 441
84 : sh002i 449 print CGI::end_table();
85 : sh002i 469 print CGI::p(CGI::submit("hardcopy", "Download Harcopy for Selected Sets"));
86 : sh002i 449 print CGI::endform();
87 : malsyned 441
88 : sh002i 669 # feedback form
89 :     my $ce = $self->{courseEnvironment};
90 :     my $root = $ce->{webworkURLs}->{root};
91 :     my $courseName = $ce->{courseName};
92 :     my $feedbackURL = "$root/$courseName/feedback/";
93 :     print
94 :     CGI::startform("POST", $feedbackURL),
95 :     $self->hidden_authen_fields,
96 :     CGI::hidden("module", __PACKAGE__),
97 :     CGI::p({-align=>"right"},
98 :     CGI::submit(-name=>"feedbackForm", -label=>"Send Feedback")
99 :     ),
100 :     CGI::endform();
101 :    
102 : sh002i 449 return "";
103 : malsyned 353 }
104 :    
105 : sh002i 469 sub setListRow($$) {
106 :     my $self = shift;
107 : sh002i 449 my $set = shift;
108 :    
109 :     my $name = $set->id;
110 :    
111 : sh002i 555 my $interactiveURL = "$name/?" . $self->url_authen_args;
112 :     my $hardcopyURL = "hardcopy/$name/?" . $self->url_authen_args;
113 : sh002i 469
114 : sh002i 449 my $openDate = formatDateTime($set->open_date);
115 :     my $dueDate = formatDateTime($set->due_date);
116 :     my $answerDate = formatDateTime($set->answer_date);
117 :    
118 :     my $checkbox = CGI::checkbox(-name=>"set", -value=>$set->id, -label=>"");
119 : sh002i 469 my $interactive = CGI::a({-href=>$interactiveURL}, $name);
120 : sh002i 555 my $hardcopy = CGI::a({-href=>$hardcopyURL}, "download");
121 : sh002i 449
122 :     my $status;
123 :     if (time < $set->open_date) {
124 :     $status = "opens at $openDate";
125 :     $checkbox = "";
126 : sh002i 469 $interactive = $name;
127 : sh002i 449 $hardcopy = "";
128 :     } elsif (time < $set->due_date) {
129 :     $status = "open, due at $dueDate";
130 :     } elsif (time < $set->answer_date) {
131 :     $status = "closed, answers at $answerDate";
132 :     } else {
133 :     $status = "closed, answers available";
134 :     }
135 :    
136 :     return CGI::Tr(CGI::td([
137 :     $checkbox,
138 : sh002i 469 $interactive,
139 : sh002i 449 $status,
140 :     $hardcopy,
141 :     ]));
142 :     }
143 :    
144 : sh002i 683 sub byname { $a->id cmp $b->id; }
145 :     sub byduedate { $a->due_date <=> $b->due_date; }
146 :    
147 : malsyned 353 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9