[system] / branches / rel-2-4-patches / webwork2 / lib / WeBWorK / PG.pm Repository:
ViewVC logotype

Diff of /branches/rel-2-4-patches/webwork2/lib/WeBWorK/PG.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 431 Revision 3224
1################################################################################
2# WeBWorK Online Homework Delivery System
3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: webwork-modperl/lib/WeBWorK/PG.pm,v 1.59 2004/11/03 22:00:10 dpvc 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
1package WeBWorK::PG; 17package WeBWorK::PG;
2 18
3# hide PG::* from the not-yet-insane. 19=head1 NAME
4# "PG Render" or something 20
21WeBWorK::PG - Invoke one of several PG rendering methods using an easy-to-use
22API.
23
24=cut
5 25
6use strict; 26use strict;
7use warnings; 27use warnings;
8use WeBWorK::Utils qw(readFile formatDateTime);
9use WeBWorK::DB::Classlist;
10use WeBWorK::DB::WW;
11use WeBWorK::PG::Translator; 28use WeBWorK::PG::ImageGenerator;
29use WeBWorK::Utils qw(runtime_use formatDateTime makeTempDirectory);
12 30
13sub new($$$$$$$$) { 31use constant DISPLAY_MODES => {
14 my $invocant = shift; 32 # display name # mode name
15 my $class = ref($invocant) || $invocant; 33 tex => "TeX",
34 plainText => "HTML",
35 formattedText => "HTML_tth",
36 images => "HTML_dpng",
37 jsMath => "HTML_jsMath",
38 asciimath => "HTML_asciimath",
39};
40
41sub new {
42 shift; # throw away invocant -- we don't need it
43 my ($ce, $user, $key, $set, $problem, $psvn, $formFields,
44 $translationOptions) = @_;
45
46 my $renderer = $ce->{pg}->{renderer};
47
48 runtime_use $renderer;
49
50 return $renderer->new(@_);
51}
52
53sub defineProblemEnvir {
16 my ( 54 my (
17 $courseEnv, 55 $self,
18 $userName,
19 $key, 56 $ce,
20 $setName,
21 $problemNumber,
22 $translationOptions, # hashref containing options for the
23 # translator, such as whether to show
24 # hints and the display mode to use
25 $formFields, # in CGI::Vars format
26 ) = @_;
27
28 # get database information
29 my $classlist = WeBWorK::DB::Classlist->new($courseEnv);
30 my $wwdb = WeBWorK::DB::WW->new($courseEnv);
31 my $user = $classlist->getUser($userName);
32 my $set = $wwdb->getSet($userName, $setName);
33 my $problem = $wwdb->getProblem($userName, $setName, $problemNumber);
34 my $psvn = $wwdb->getPSVN($userName, $setName);
35
36 # create a Translator
37 warn "PG: creating a Translator\n";
38 my $translator = WeBWorK::PG::Translator->new;
39
40 # set the directory hash
41 warn "PG: setting the directory hash\n";
42 $translator->rh_directories({
43 courseScriptsDirectory => $courseEnv->{webworkDirs}->{macros},
44 macroDirectory => $courseEnv->{courseDirs}->{macros},
45 templateDirectory => $courseEnv->{courseDirs}->{templates},
46 tempDirectory => $courseEnv->{courseDirs}->{html_temp},
47 });
48
49 # evaluate modules and "extra packages"
50 warn "PG: evaluating modules and \"extra packages\"\n";
51 my @modules = @{ $courseEnv->{pg}->{modules} };
52 foreach my $module_packages (@modules) {
53 # the first item in $module_packages is the main package
54 $translator->evaluate_modules(shift @$module_packages);
55 # the remaining items are "extra" packages
56 $translator->load_extra_packages(@$module_packages);
57 }
58
59 # set the environment (from defineProblemEnvir)
60 warn "PG: setting the environment (from defineProblemEnvir)\n";
61 $translator->environment(defineProblemEnvir(
62 $courseEnv, $user, $key, $set, $problem, $psvn, $formFields, $translationOptions));
63
64 # initialize the Translator
65 warn "PG: initializing the Translator\n";
66 $translator->initialize();
67
68 # load PG.pl and dangerousMacros.pl using unrestricted_load
69 # i'd like to change this at some point to have the same sort of interface to global.conf
70 # that the module loading does -- have a list of macros to load unrestrictedly.
71 warn "PG: loading PG.pl and dangerousMacros.pl using unrestricted_load\n";
72 my $pg_pl = $courseEnv->{webworkDirs}->{macros} . "/PG.pl";
73 my $dangerousMacros_pl = $courseEnv->{webworkDirs}->{macros} . "/dangerousMacros.pl";
74 my $err = $translator->unrestricted_load($pg_pl);
75 warn "Error while loading $pg_pl: $err" if $err;
76 $err = $translator->unrestricted_load($dangerousMacros_pl);
77 warn "Error while loading $dangerousMacros_pl: $err" if $err;
78
79 # set the opcode mask (using default values)
80 warn "PG: setting the opcode mask (using default values)\n";
81 $translator->set_mask();
82
83 # store the problem source
84 warn "PG: storing the problem source\n";
85 my $sourceFile = $courseEnv->{courseDirs}->{templates}."/".$problem->source_file;
86 $translator->source_string(readFile($sourceFile));
87
88 # install a safety filter (&safetyFilter)
89 warn "PG: installing a safety filter\n";
90 $translator->rf_safety_filter(\&safetyFilter);
91
92 # translate the PG source into text
93 warn "PG: translating the PG source into text\n";
94 $translator->translate();
95
96 # [in Problem.pm and processProblem8.pl, "install a grader" is here]
97
98 # process student answers
99 warn "PG: processing student answers\n";
100 $translator->process_answers($formFields);
101
102 # retrieve the problem state and give it to the translator
103 warn "PG: retrieving the problem state and giving it to the translator\n";
104 $translator->rh_problem_state({
105 recorded_score => $problem->status,
106 num_of_correct_ans => $problem->num_correct,
107 num_of_incorrect_ans => $problem->num_incorrect,
108 });
109
110 # determine an entry order -- the ANSWER_ENTRY_ORDER flag is built by
111 # the PG macro package (PG.pl)
112 warn "PG: determining an entry order\n";
113 my @answerOrder =
114 $translator->rh_flags->{ANSWER_ENTRY_ORDER}
115 ? @{ $translator->rh_flags->{ANSWER_ENTRY_ORDER} }
116 : keys %{ $translator->rh_evaluated_answers };
117
118 # install a grader -- use the one specified in the problem,
119 # or fall back on the default from the course environment.
120 # (two magic strings are accepted, to avoid having to
121 # reference code when it would be difficult.)
122 warn "PG: installing a grader\n";
123 my $grader = $translator->rh_flags->{PROBLEM_GRADER_TO_USE}
124 || $courseEnv->{pg}->{options}->{grader};
125 $grader = $translator->rf_std_problem_grader
126 if $grader eq "std_problem_grader";
127 $grader = $translator->rf_avg_problem_grader
128 if $grader eq "avg_problem_grader";
129 die "Problem grader $grader is not a CODE reference."
130 unless ref $grader eq "CODE";
131 $translator->rf_problem_grader($grader);
132
133 # grading the problem
134 warn "PG: grade the problem\n";
135 my ($result, $state) = $translator->grade_problem(
136 answers_submitted => $translationOptions->{processAnswers},
137 ANSWER_ENTRY_ORDER => \@answerOrder,
138 );
139
140 # return an object which contains the translator and the results of
141 # the translation process. this is DIFFERENT from the "format expected
142 # by Webwork.pm (and I believe processProblem8, but check.)"
143 return bless {
144 translator => $translator,
145 head_text => ${ $translator->r_header },
146 body_text => ${ $translator->r_text },
147 answers => $translator->rh_evaluated_answers,
148 result => $result,
149 state => $state,
150 errors => $translator->errors, # *** what is this doing?
151 warnings => undef, # *** gotta catch warnings eventually...
152 flags => $translator->rh_flags,
153 }, $class;
154}
155
156# -----
157
158sub defineProblemEnvir($$$$$$$) {
159 my (
160 $courseEnv,
161 $user, 57 $user,
162 $key, 58 $key,
163 $set, 59 $set,
164 $problem, 60 $problem,
165 $psvn, 61 $psvn,
167 $options, 63 $options,
168 ) = @_; 64 ) = @_;
169 65
170 my %envir; 66 my %envir;
171 67
68 # ----------------------------------------------------------------------
69
172 # PG environment variables 70 # PG environment variables
173 # from docs/pglanguage/pgreference/environmentvariables as of 06/25/2002 71 # from docs/pglanguage/pgreference/environmentvariables as of 06/25/2002
174 # any changes are noted by "ADDED:" or "REMOVED:" 72 # any changes are noted by "ADDED:" or "REMOVED:"
175 73
176 # Vital state information 74 # Vital state information
177 # ADDED: displayHintsQ, displaySolutionsQ, externalTTHPath 75 # ADDED: displayModeFailover, displayHintsQ, displaySolutionsQ,
76 # refreshMath2img, texDisposition
178 77
179 $envir{psvn} = $psvn; 78 $envir{psvn} = $set->psvn;
180 $envir{psvnNumber} = $envir{psvn}; 79 $envir{psvnNumber} = $envir{psvn};
181 $envir{probNum} = $problem->id; 80 $envir{probNum} = $problem->problem_id;
182 $envir{questionNumber} = $envir{probNum}; 81 $envir{questionNumber} = $envir{probNum};
183 $envir{fileName} = $problem->source_file; 82 $envir{fileName} = $problem->source_file;
184 $envir{probFileName} = $envir{fileName}; 83 $envir{probFileName} = $envir{fileName};
185 $envir{problemSeed} = $problem->problem_seed; 84 $envir{problemSeed} = $problem->problem_seed;
186 $envir{displayMode} = translateDisplayModeNames($options->{displayMode}); 85 $envir{displayMode} = translateDisplayModeNames($options->{displayMode});
187 $envir{languageMode} = $envir{displayMode}; 86 $envir{languageMode} = $envir{displayMode};
188 $envir{outputMode} = $envir{displayMode}; 87 $envir{outputMode} = $envir{displayMode};
189 $envir{displayHintsQ} = $options->{hints}; 88 $envir{displayHintsQ} = $options->{showHints};
190 $envir{displaySolutionsQ} = $options->{solutions}; 89 $envir{displaySolutionsQ} = $options->{showSolutions};
191 $envir{externalTTHPath} = $courseEnv->{externalPrograms}->{tth}; 90 $envir{texDisposition} = "pdf"; # in webwork2, we use pdflatex
192 91
193 # Problem Information 92 # Problem Information
194 # ADDED: courseName 93 # ADDED: courseName, formatedDueDate
195 94
196 $envir{openDate} = $set->open_date; 95 $envir{openDate} = $set->open_date;
197 $envir{formattedOpenDate} = formatDateTime($envir{openDate}); 96 $envir{formattedOpenDate} = formatDateTime($envir{openDate}, $ce->{siteDefaults}{timezone});
198 $envir{dueDate} = $set->due_date; 97 $envir{dueDate} = $set->due_date;
199 $envir{formattedDueDate} = formatDateTime($envir{dueDate}); 98 $envir{formattedDueDate} = formatDateTime($envir{dueDate}, $ce->{siteDefaults}{timezone});
99 $envir{formatedDueDate} = $envir{formattedDueDate}; # typo in many header files
200 $envir{answerDate} = $set->answer_date; 100 $envir{answerDate} = $set->answer_date;
201 $envir{formattedAnswerDate} = formatDateTime($envir{answerDate}); 101 $envir{formattedAnswerDate} = formatDateTime($envir{answerDate}, $ce->{siteDefaults}{timezone});
202 $envir{numOfAttempts} = $problem->num_correct + $problem->num_incorrect; 102 $envir{numOfAttempts} = ($problem->num_correct || 0) + ($problem->num_incorrect || 0);
203 $envir{problemValue} = $problem->value; 103 $envir{problemValue} = $problem->value;
204 $envir{sessionKey} = $key; 104 $envir{sessionKey} = $key;
205 $envir{courseName} = $courseEnv->{courseName}; 105 $envir{courseName} = $ce->{courseName};
206 106
207 # Student Information 107 # Student Information
208 # ADDED: studentID 108 # ADDED: studentID
209 109
210 $envir{sectionName} = $user->section; 110 $envir{sectionName} = $user->section;
211 $envir{sectionNumber} = $envir{sectionName}; 111 $envir{sectionNumber} = $envir{sectionName};
212 $envir{recitationName} = $user->recitation; 112 $envir{recitationName} = $user->recitation;
213 $envir{recitationNumber} = $envir{recitationName}; 113 $envir{recitationNumber} = $envir{recitationName};
214 $envir{setNumber} = $set->id; 114 $envir{setNumber} = $set->set_id;
215 $envir{studentLogin} = $user->id; 115 $envir{studentLogin} = $user->user_id;
216 $envir{studentName} = $user->first_name . " " . $user->last_name; 116 $envir{studentName} = $user->first_name . " " . $user->last_name;
217 $envir{studentID} = $user->student_id; 117 $envir{studentID} = $user->student_id;
218 118
219 # Answer Information 119 # Answer Information
220 # REMOVED: refSubmittedAnswers (alledgedly unused, causes errors) 120 # REMOVED: refSubmittedAnswers
221 121
222 $envir{inputs_ref} = $formFields; 122 $envir{inputs_ref} = $formFields;
223 123
224 # Default values for evaluating answers 124 # External Programs
125 # ADDED: externalLaTeXPath, externalDvipngPath,
126 # externalGif2EpsPath, externalPng2EpsPath
225 127
226 my $ansEvalDefaults = $courseEnv->{pg}->{ansEvalDefaults}; 128 $envir{externalTTHPath} = $ce->{externalPrograms}->{tth};
227 $envir{$_} = $ansEvalDefaults->{$_} foreach (keys %$ansEvalDefaults); 129 $envir{externalLaTeXPath} = $ce->{externalPrograms}->{latex};
130 $envir{externalDvipngPath} = $ce->{externalPrograms}->{dvipng};
131 $envir{externalGif2EpsPath} = $ce->{externalPrograms}->{gif2eps};
132 $envir{externalPng2EpsPath} = $ce->{externalPrograms}->{png2eps};
133 $envir{externalGif2PngPath} = $ce->{externalPrograms}->{gif2png};
228 134
229 # Directories and URLs 135 # Directories and URLs
230 # REMOVED: courseName 136 # REMOVED: courseName
137 # ADDED: dvipngTempDir
138 # ADDED: jsMathURL
139 # ADDED: asciimathURL
140 # ADDED: macrosPath
141 # REMOVED: macrosDirectory, courseScriptsDirectory
231 142
232 $envir{cgiDirectory} = undef; 143 $envir{cgiDirectory} = undef;
233 $envir{cgiURL} = undef; 144 $envir{cgiURL} = undef;
234 $envir{classDirectory} = undef; 145 $envir{classDirectory} = undef;
235 $envir{courseScriptsDirectory} = $courseEnv->{webworkDirs}->{macros}."/"; 146 $envir{macrosPath} = $ce->{pg}->{directories}{macrosPath};
236 $envir{htmlDirectory} = $courseEnv->{courseDirs}->{html}."/"; 147 $envir{htmlDirectory} = $ce->{courseDirs}->{html}."/";
237 $envir{htmlURL} = $courseEnv->{courseURLs}->{html}; 148 $envir{htmlURL} = $ce->{courseURLs}->{html}."/";
238 $envir{macroDirectory} = $courseEnv->{courseDirs}->{macros}."/";
239 $envir{templateDirectory} = $courseEnv->{courseDirs}->{templates}."/"; 149 $envir{templateDirectory} = $ce->{courseDirs}->{templates}."/";
240 $envir{tempDirectory} = $courseEnv->{courseDirs}->{html_temp}."/"; 150 $envir{tempDirectory} = $ce->{courseDirs}->{html_temp}."/";
241 $envir{tempURL} = $courseEnv->{courseURLs}->{html_temp}; 151 $envir{tempURL} = $ce->{courseURLs}->{html_temp}."/";
242 $envir{scriptDirectory} = undef; 152 $envir{scriptDirectory} = undef;
243 $envir{webworkDocsURL} = $courseEnv->{webworkURLs}->{docs}; 153 $envir{webworkDocsURL} = $ce->{webworkURLs}->{docs}."/";
154 $envir{localHelpURL} = $ce->{webworkURLs}->{local_help}."/";
155 $envir{jsMathURL} = $ce->{webworkURLs}->{jsMath};
156 $envir{asciimathURL} = $ce->{webworkURLs}->{asciimath};
244 157
245 # Other things... (where's your brain?!?!) 158 # Information for sending mail
246 159
160 $envir{mailSmtpServer} = $ce->{mail}->{smtpServer};
161 $envir{mailSmtpSender} = $ce->{mail}->{smtpSender};
162 $envir{ALLOW_MAIL_TO} = $ce->{mail}->{allowedRecipients};
163
164 # Default values for evaluating answers
165
166 my $ansEvalDefaults = $ce->{pg}->{ansEvalDefaults};
167 $envir{$_} = $ansEvalDefaults->{$_} foreach (keys %$ansEvalDefaults);
168
169 # ----------------------------------------------------------------------
170
171 my $basename = "equation-$envir{psvn}.$envir{probNum}";
172 $basename .= ".$envir{problemSeed}" if $envir{problemSeed};
173
174 # to make grabbing these options easier, we'll pull them out now...
175 my %imagesModeOptions = %{$ce->{pg}->{displayModeOptions}->{images}};
176
177 # Object for generating equation images
178 $envir{imagegen} = WeBWorK::PG::ImageGenerator->new(
179 tempDir => $ce->{webworkDirs}->{tmp}, # global temp dir
180 latex => $envir{externalLaTeXPath},
181 dvipng => $envir{externalDvipngPath},
182 useCache => 1,
183 cacheDir => $ce->{webworkDirs}->{equationCache},
184 cacheURL => $ce->{webworkURLs}->{equationCache},
185 cacheDB => $ce->{webworkFiles}->{equationCacheDB},
186 useMarkers => ($imagesModeOptions{dvipng_align} && $imagesModeOptions{dvipng_align} eq 'mysql'),
187 dvipng_align => $imagesModeOptions{dvipng_align},
188 dvipng_depth_db => $imagesModeOptions{dvipng_depth_db},
189 );
190
191 # ADDED: jsMath options
192 $envir{jsMath} = {%{$ce->{pg}{displayModeOptions}{jsMath}}};
193
194 # Other things...
195 $envir{QUIZ_PREFIX} = $options->{QUIZ_PREFIX}; # used by quizzes
247 $envir{PROBLEM_GRADER_TO_USE} = $courseEnv->{pg}->{options}->{grader}; 196 $envir{PROBLEM_GRADER_TO_USE} = $ce->{pg}->{options}->{grader};
197 $envir{PRINT_FILE_NAMES_FOR} = $ce->{pg}->{specialPGEnvironmentVars}->{PRINT_FILE_NAMES_FOR};
198
199 # ADDED: __files__
200 # an array for mapping (eval nnn) to filenames in error messages
201 $envir{__files__} = {
202 root => $ce->{webworkDirs}{root}, # used to shorten filenames
203 pg => $ce->{pg}{directories}{root}, # ditto
204 tmpl => $ce->{courseDirs}{templates}, # ditto
205 };
206
207 # variables for interpreting capa problems and other things to be
208 # seen in a pg file
209 my $specialPGEnvironmentVarHash = $ce->{pg}->{specialPGEnvironmentVars};
210 for my $SPGEV (keys %{$specialPGEnvironmentVarHash}) {
211 $envir{$SPGEV} = $specialPGEnvironmentVarHash->{$SPGEV};
212 }
248 213
249 return \%envir; 214 return \%envir;
250} 215}
251 216
252sub translateDisplayModeNames($) { 217sub translateDisplayModeNames($) {
253 my $name = shift; 218 my $name = shift;
254 return { 219 return DISPLAY_MODES()->{$name};
255 plainText => "HTML",
256 formattedText => "HTML_tth",
257 images => "Latex2HTML"
258 }->{$name};
259} 220}
260 221
261sub safetyFilter { 222sub oldSafetyFilter {
262 my $answer = shift; # accepts one answer and checks it 223 my $answer = shift; # accepts one answer and checks it
263 my $submittedAnswer = $answer; 224 my $submittedAnswer = $answer;
264 $answer = '' unless defined $answer; 225 $answer = '' unless defined $answer;
265 my ($errorno); 226 my ($errorno);
266 $answer =~ tr/\000-\037/ /; 227 $answer =~ tr/\000-\037/ /;
270 $errorno = 0; ## don't report blank answer as error 231 $errorno = 0; ## don't report blank answer as error
271 return ($answer,$errorno); 232 return ($answer,$errorno);
272 } 233 }
273 # replace ^ with ** (for exponentiation) 234 # replace ^ with ** (for exponentiation)
274 # $answer =~ s/\^/**/g; 235 # $answer =~ s/\^/**/g;
275 # Return if forbidden characters are found 236 # Return if forbidden characters are found
276 unless ($answer =~ /^[a-zA-Z0-9_\-\+ \t\/@%\*\.\n^\(\)]+$/ ) { 237 unless ($answer =~ /^[a-zA-Z0-9_\-\+ \t\/@%\*\.\n^\[\]\(\)\,\|]+$/ ) {
277 $answer =~ tr/a-zA-Z0-9_\-\+ \t\/@%\*\.\n^\(\)/#/c; 238 $answer =~ tr/a-zA-Z0-9_\-\+ \t\/@%\*\.\n^\(\)/#/c;
278 $errorno = "<BR>There are forbidden characters in your answer: $submittedAnswer<BR>"; 239 $errorno = "<BR>There are forbidden characters in your answer: $submittedAnswer<BR>";
279 return ($answer,$errorno); 240 return ($answer,$errorno);
280 } 241 }
281 $errorno = 0; 242 $errorno = 0;
282 return($answer, $errorno); 243 return($answer, $errorno);
283} 244}
284 245
246sub nullSafetyFilter {
247 return shift, 0; # no errors
248}
249
2851; 2501;
251
252__END__
253
254=head1 SYNOPSIS
255
256 $pg = WeBWorK::PG->new(
257 $ce, # a WeBWorK::CourseEnvironment object
258 $user, # a WeBWorK::DB::Record::User object
259 $sessionKey,
260 $set, # a WeBWorK::DB::Record::UserSet object
261 $problem, # a WeBWorK::DB::Record::UserProblem object
262 $psvn,
263 $formFields # in &WeBWorK::Form::Vars format
264 { # translation options
265 displayMode => "images", # (plainText|formattedText|images)
266 showHints => 1, # (0|1)
267 showSolutions => 0, # (0|1)
268 refreshMath2img => 0, # (0|1)
269 processAnswers => 1, # (0|1)
270 },
271 );
272
273 $translator = $pg->{translator}; # WeBWorK::PG::Translator
274 $body = $pg->{body_text}; # text string
275 $header = $pg->{head_text}; # text string
276 $answerHash = $pg->{answers}; # WeBWorK::PG::AnswerHash
277 $result = $pg->{result}; # hash reference
278 $state = $pg->{state}; # hash reference
279 $errors = $pg->{errors}; # text string
280 $warnings = $pg->{warnings}; # text string
281 $flags = $pg->{flags}; # hash reference
282
283=head1 DESCRIPTION
284
285WeBWorK::PG is a factory for modules which use the WeBWorK::PG API. Notable
286modules which use this API (and exist) are WeBWorK::PG::Local and
287WeBWorK::PG::Remote. The course environment key $pg{renderer} is consulted to
288determine which render to use.
289
290=head1 THE WEBWORK::PG API
291
292Modules which support this API must implement the following method:
293
294=over
295
296=item new ENVIRONMENT, USER, KEY, SET, PROBLEM, PSVN, FIELDS, OPTIONS
297
298The C<new> method creates a translator, initializes it using the parameters
299specified, translates a PG file, and processes answers. It returns a reference
300to a blessed hash containing the results of the translation process.
301
302=back
303
304=head2 Parameters
305
306=over
307
308=item ENVIRONMENT
309
310a WeBWorK::CourseEnvironment object
311
312=item USER
313
314a WeBWorK::User object
315
316=item KEY
317
318the session key of the current session
319
320=item SET
321
322a WeBWorK::Set object
323
324=item PROBLEM
325
326a WeBWorK::DB::Record::UserProblem object. The contents of the source_file
327field can specify a PG file either by absolute path or path relative to the
328"templates" directory. I<The caller should remove taint from this value before
329passing!>
330
331=item PSVN
332
333the problem set version number
334
335=item FIELDS
336
337a reference to a hash (as returned by &WeBWorK::Form::Vars) containing form
338fields submitted by a problem processor. The translator will look for fields
339like "AnSwEr[0-9]" containing submitted student answers.
340
341=item OPTIONS
342
343a reference to a hash containing the following data:
344
345=over
346
347=item displayMode
348
349one of "plainText", "formattedText", or "images"
350
351=item showHints
352
353boolean, render hints
354
355=item showSolutions
356
357boolean, render solutions
358
359=item refreshMath2img
360
361boolean, force images created by math2img (in "images" mode) to be recreated,
362even if the PG source has not been updated. FIXME: remove this option.
363
364=item processAnswers
365
366boolean, call answer evaluators and graders
367
368=back
369
370=back
371
372=head2 RETURN VALUE
373
374The C<new> method returns a blessed hash reference containing the following
375fields. More information can be found in the documentation for
376WeBWorK::PG::Translator.
377
378=over
379
380=item translator
381
382The WeBWorK::PG::Translator object used to render the problem.
383
384=item head_text
385
386HTML code for the E<lt>headE<gt> block of an resulting web page. Used for
387JavaScript features.
388
389=item body_text
390
391HTML code for the E<lt>bodyE<gt> block of an resulting web page.
392
393=item answers
394
395An C<AnswerHash> object containing submitted answers, and results of answer
396evaluation.
397
398=item result
399
400A hash containing the results of grading the problem.
401
402=item state
403
404A hash containing the new problem state.
405
406=item errors
407
408A string containing any errors encountered while rendering the problem.
409
410=item warnings
411
412A string containing any warnings encountered while rendering the problem.
413
414=item flags
415
416A hash containing PG_flags (see the Translator docs).
417
418=back
419
420=head1 METHODS PROVIDED BY THE BASE CLASS
421
422The following methods are provided for use by subclasses of WeBWorK::PG.
423
424=over
425
426=item defineProblemEnvir ENVIRONMENT, USER, KEY, SET, PROBLEM, PSVN, FIELDS, OPTIONS
427
428Generate a problem environment hash to pass to the renderer.
429
430=item translateDisplayModeNames NAME
431
432NAME contains
433
434=back
435
436=head1 AUTHOR
437
438Written by Sam Hathaway, sh002i (at) math.rochester.edu.
439
440=cut

Legend:
Removed from v.431  
changed lines
  Added in v.3224

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9