WeBWorK::PG - Invoke one of several PG rendering methods using an easy-to-use API.
$pg = WeBWorK::PG->new(
$ce, # a WeBWorK::CourseEnvironment object
$user, # a WeBWorK::DB::Record::User object
$sessionKey,
$set, # a WeBWorK::DB::Record::UserSet object
$problem, # a WeBWorK::DB::Record::UserProblem object
$psvn,
$formFields # in &WeBWorK::Form::Vars format
{ # translation options
displayMode => "images", # (plainText|formattedText|images)
showHints => 1, # (0|1)
showSolutions => 0, # (0|1)
refreshMath2img => 0, # (0|1)
processAnswers => 1, # (0|1)
},
);
$translator = $pg->{translator}; # WeBWorK::PG::Translator
$body = $pg->{body_text}; # text string
$header = $pg->{head_text}; # text string
$answerHash = $pg->{answers}; # WeBWorK::PG::AnswerHash
$result = $pg->{result}; # hash reference
$state = $pg->{state}; # hash reference
$errors = $pg->{errors}; # text string
$warnings = $pg->{warnings}; # text string
$flags = $pg->{flags}; # hash reference
WeBWorK::PG is a factory for modules which use the WeBWorK::PG API. Notable modules which use this API (and exist) are WeBWorK::PG::Local and WeBWorK::PG::Remote. The course environment key $pg{renderer} is consulted to determine which render to use.
Modules which support this API must implement the following method:
The new method creates a translator, initializes it using the parameters
specified, translates a PG file, and processes answers. It returns a reference
to a blessed hash containing the results of the translation process.
a WeBWorK::CourseEnvironment object
a WeBWorK::User object
the session key of the current session
a WeBWorK::Set object
a WeBWorK::DB::Record::UserProblem object. The contents of the source_file field can specify a PG file either by absolute path or path relative to the ``templates'' directory. The caller should remove taint from this value before passing!
the problem set version number
a reference to a hash (as returned by &WeBWorK::Form::Vars) containing form fields submitted by a problem processor. The translator will look for fields like ``AnSwEr[0-9]'' containing submitted student answers.
a reference to a hash containing the following data:
one of ``plainText'', ``formattedText'', or ``images''
boolean, render hints
boolean, render solutions
boolean, force images created by math2img (in ``images'' mode) to be recreated, even if the PG source has not been updated. FIXME: remove this option.
boolean, call answer evaluators and graders
The new method returns a blessed hash reference containing the following
fields. More information can be found in the documentation for
WeBWorK::PG::Translator.
The WeBWorK::PG::Translator object used to render the problem.
HTML code for the <head> block of an resulting web page. Used for JavaScript features.
HTML code for the <body> block of an resulting web page.
An AnswerHash object containing submitted answers, and results of answer
evaluation.
A hash containing the results of grading the problem.
A hash containing the new problem state.
A string containing any errors encountered while rendering the problem.
A string containing any warnings encountered while rendering the problem.
A hash containing PG_flags (see the Translator docs).
The following methods are provided for use by subclasses of WeBWorK::PG.
Generate a problem environment hash to pass to the renderer.
NAME contains
Written by Sam Hathaway, sh002i (at) math.rochester.edu.