Parent Directory
|
Revision Log
Revision 737 - (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::ProblemSet; |
| 7 : | |||
| 8 : | sh002i | 455 | =head1 NAME |
| 9 : | |||
| 10 : | WeBWorK::ContentGenerator::ProblemSet - display an index of the problems in a | ||
| 11 : | problem set. | ||
| 12 : | |||
| 13 : | =cut | ||
| 14 : | |||
| 15 : | malsyned | 441 | use strict; |
| 16 : | use warnings; | ||
| 17 : | sh002i | 455 | use base qw(WeBWorK::ContentGenerator); |
| 18 : | malsyned | 353 | use Apache::Constants qw(:common); |
| 19 : | sh002i | 443 | use CGI qw(); |
| 20 : | sh002i | 455 | use WeBWorK::ContentGenerator; |
| 21 : | sh002i | 526 | use WeBWorK::DB::WW; |
| 22 : | use WeBWorK::DB::Classlist; | ||
| 23 : | malsyned | 353 | |
| 24 : | sh002i | 469 | sub initialize { |
| 25 : | my $self = shift; | ||
| 26 : | malsyned | 353 | my $courseEnvironment = $self->{courseEnvironment}; |
| 27 : | sh002i | 469 | |
| 28 : | # Open a database connection that we can use for the rest of | ||
| 29 : | # the content generation. | ||
| 30 : | |||
| 31 : | sh002i | 526 | $self->{wwdb} = WeBWorK::DB::WW->new($courseEnvironment); |
| 32 : | $self->{cldb} = WeBWorK::DB::Classlist->new($courseEnvironment); | ||
| 33 : | sh002i | 469 | } |
| 34 : | malsyned | 353 | |
| 35 : | sh002i | 469 | sub path { |
| 36 : | my ($self, $setName, $args) = @_; | ||
| 37 : | |||
| 38 : | my $ce = $self->{courseEnvironment}; | ||
| 39 : | my $root = $ce->{webworkURLs}->{root}; | ||
| 40 : | my $courseName = $ce->{courseName}; | ||
| 41 : | return $self->pathMacro($args, | ||
| 42 : | "Home" => "$root", | ||
| 43 : | $courseName => "$root/$courseName", | ||
| 44 : | $setName => "", | ||
| 45 : | ); | ||
| 46 : | malsyned | 353 | } |
| 47 : | |||
| 48 : | sh002i | 469 | sub siblings { |
| 49 : | my ($self, $setName) = @_; | ||
| 50 : | |||
| 51 : | my $ce = $self->{courseEnvironment}; | ||
| 52 : | my $root = $ce->{webworkURLs}->{root}; | ||
| 53 : | my $courseName = $ce->{courseName}; | ||
| 54 : | sh002i | 526 | |
| 55 : | print CGI::strong("Problem Sets"), CGI::br(); | ||
| 56 : | |||
| 57 : | sh002i | 469 | my $wwdb = $self->{wwdb}; |
| 58 : | malsyned | 720 | my $effectiveUser = $self->{r}->param("effectiveUser"); |
| 59 : | sh002i | 469 | my @sets; |
| 60 : | malsyned | 720 | push @sets, $wwdb->getSet($effectiveUser, $_) foreach ($wwdb->getSets($effectiveUser)); |
| 61 : | sh002i | 469 | foreach my $set (sort { $a->open_date <=> $b->open_date } @sets) { |
| 62 : | if (time >= $set->open_date) { | ||
| 63 : | print CGI::a({-href=>"$root/$courseName/".$set->id."/?" | ||
| 64 : | . $self->url_authen_args}, $set->id), CGI::br(); | ||
| 65 : | } else { | ||
| 66 : | print $set->id, CGI::br(); | ||
| 67 : | } | ||
| 68 : | } | ||
| 69 : | } | ||
| 70 : | |||
| 71 : | sub title { | ||
| 72 : | my ($self, $setName) = @_; | ||
| 73 : | |||
| 74 : | return $setName; | ||
| 75 : | } | ||
| 76 : | |||
| 77 : | sh002i | 526 | sub info { |
| 78 : | my ($self, $setName) = @_; | ||
| 79 : | |||
| 80 : | my $r = $self->{r}; | ||
| 81 : | my $ce = $self->{courseEnvironment}; | ||
| 82 : | |||
| 83 : | my $wwdb = $self->{wwdb}; | ||
| 84 : | my $cldb = $self->{cldb}; | ||
| 85 : | sh002i | 737 | my $effectiveUser = $cldb->getUser($r->param("effectiveUser")); |
| 86 : | malsyned | 720 | my $set = $wwdb->getSet($effectiveUser->id, $setName); |
| 87 : | my $psvn = $wwdb->getPSVN($effectiveUser->id, $setName); | ||
| 88 : | sh002i | 526 | |
| 89 : | sh002i | 693 | my $screenSetHeader = $set->problem_header || $ce->{webworkFiles}->{screenSnippets}->{setHeader}; |
| 90 : | sh002i | 526 | my $displayMode = $ce->{pg}->{options}->{displayMode}; |
| 91 : | |||
| 92 : | return "" unless defined $screenSetHeader and $screenSetHeader; | ||
| 93 : | |||
| 94 : | # decide what to do about problem number | ||
| 95 : | my $problem = WeBWorK::Problem->new( | ||
| 96 : | id => 0, | ||
| 97 : | set_id => $set->id, | ||
| 98 : | malsyned | 720 | login_id => $effectiveUser->id, |
| 99 : | sh002i | 526 | source_file => $screenSetHeader, |
| 100 : | # the rest of Problem's fields are not needed, i think | ||
| 101 : | ); | ||
| 102 : | |||
| 103 : | my $pg = WeBWorK::PG->new( | ||
| 104 : | $ce, | ||
| 105 : | malsyned | 720 | $effectiveUser, |
| 106 : | sh002i | 526 | $r->param('key'), |
| 107 : | $set, | ||
| 108 : | $problem, | ||
| 109 : | $psvn, | ||
| 110 : | {}, # no form fields! | ||
| 111 : | { # translation options | ||
| 112 : | displayMode => $displayMode, | ||
| 113 : | showHints => 0, | ||
| 114 : | showSolutions => 0, | ||
| 115 : | processAnswers => 0, | ||
| 116 : | }, | ||
| 117 : | ); | ||
| 118 : | |||
| 119 : | # handle translation errors | ||
| 120 : | if ($pg->{flags}->{error_flag}) { | ||
| 121 : | sh002i | 737 | return $self->errorOutput($pg->{errors}, $pg->{body_text}); |
| 122 : | sh002i | 526 | } else { |
| 123 : | return $pg->{body_text}; | ||
| 124 : | } | ||
| 125 : | } | ||
| 126 : | |||
| 127 : | malsyned | 353 | sub body { |
| 128 : | sh002i | 469 | my ($self, $setName) = @_; |
| 129 : | malsyned | 353 | my $r = $self->{r}; |
| 130 : | my $courseEnvironment = $self->{courseEnvironment}; | ||
| 131 : | malsyned | 720 | my $effectiveUser = $r->param('effectiveUser'); |
| 132 : | sh002i | 469 | my $wwdb = $self->{wwdb}; |
| 133 : | malsyned | 353 | |
| 134 : | sh002i | 526 | my $hardcopyURL = |
| 135 : | $courseEnvironment->{webworkURLs}->{root} . "/" | ||
| 136 : | . $courseEnvironment->{courseName} . "/" | ||
| 137 : | sh002i | 555 | . "hardcopy/$setName/?" . $self->url_authen_args; |
| 138 : | sh002i | 526 | print CGI::p(CGI::a({-href=>$hardcopyURL}, "Download a hardcopy"), |
| 139 : | "of this problem set."); | ||
| 140 : | sh002i | 476 | |
| 141 : | sh002i | 469 | print CGI::start_table(); |
| 142 : | print CGI::Tr( | ||
| 143 : | CGI::th("Name"), | ||
| 144 : | CGI::th("Attempts"), | ||
| 145 : | CGI::th("Remaining"), | ||
| 146 : | CGI::th("Status"), | ||
| 147 : | ); | ||
| 148 : | |||
| 149 : | malsyned | 720 | my $set = $wwdb->getSet($effectiveUser, $setName); |
| 150 : | my @problemNumbers = $wwdb->getProblems($effectiveUser, $setName); | ||
| 151 : | sh002i | 469 | foreach my $problemNumber (sort { $a <=> $b } @problemNumbers) { |
| 152 : | malsyned | 720 | my $problem = $wwdb->getProblem($effectiveUser, $setName, $problemNumber); |
| 153 : | sh002i | 469 | print $self->problemListRow($set, $problem); |
| 154 : | } | ||
| 155 : | |||
| 156 : | print CGI::end_table(); | ||
| 157 : | |||
| 158 : | sh002i | 669 | # feedback form |
| 159 : | my $ce = $self->{courseEnvironment}; | ||
| 160 : | my $root = $ce->{webworkURLs}->{root}; | ||
| 161 : | my $courseName = $ce->{courseName}; | ||
| 162 : | my $feedbackURL = "$root/$courseName/feedback/"; | ||
| 163 : | |||
| 164 : | CGI::startform("POST", $feedbackURL), | ||
| 165 : | $self->hidden_authen_fields, | ||
| 166 : | CGI::hidden("module", __PACKAGE__), | ||
| 167 : | CGI::hidden("set", $set->id), | ||
| 168 : | CGI::p({-align=>"right"}, | ||
| 169 : | CGI::submit(-name=>"feedbackForm", -label=>"Send Feedback") | ||
| 170 : | ), | ||
| 171 : | CGI::endform(); | ||
| 172 : | |||
| 173 : | sh002i | 469 | return ""; |
| 174 : | malsyned | 353 | } |
| 175 : | |||
| 176 : | sh002i | 469 | sub problemListRow($$$) { |
| 177 : | my $self = shift; | ||
| 178 : | my $set = shift; | ||
| 179 : | my $problem = shift; | ||
| 180 : | |||
| 181 : | my $name = $problem->id; | ||
| 182 : | sh002i | 555 | my $interactiveURL = "$name/?" . $self->url_authen_args; |
| 183 : | sh002i | 469 | my $interactive = CGI::a({-href=>$interactiveURL}, "Problem $name"); |
| 184 : | my $attempts = $problem->num_correct + $problem->num_incorrect; | ||
| 185 : | my $remaining = $problem->max_attempts < 0 | ||
| 186 : | ? "unlimited" | ||
| 187 : | : $problem->max_attempts - $attempts; | ||
| 188 : | my $status = $problem->status * 100 . "%"; | ||
| 189 : | |||
| 190 : | sh002i | 526 | return CGI::Tr(CGI::td({-nowrap=>1}, [ |
| 191 : | sh002i | 469 | $interactive, |
| 192 : | $attempts, | ||
| 193 : | $remaining, | ||
| 194 : | $status, | ||
| 195 : | ])); | ||
| 196 : | } | ||
| 197 : | |||
| 198 : | malsyned | 353 | 1; |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |