| … | |
… | |
| 22 | sub new($$$$$$$$) { |
22 | sub new($$$$$$$$) { |
| 23 | my $invocant = shift; |
23 | my $invocant = shift; |
| 24 | my $class = ref($invocant) || $invocant; |
24 | my $class = ref($invocant) || $invocant; |
| 25 | my ( |
25 | my ( |
| 26 | $courseEnv, |
26 | $courseEnv, |
| 27 | $userName, |
27 | $user, |
| 28 | $key, |
28 | $key, |
| 29 | $setName, |
29 | $set, |
| 30 | $problemNumber, |
30 | $problem, |
|
|
31 | $psvn, |
|
|
32 | $formFields, # in CGI::Vars format |
| 31 | $translationOptions, # hashref containing options for the |
33 | $translationOptions, # hashref containing options for the |
| 32 | # translator, such as whether to show |
34 | # translator, such as whether to show |
| 33 | # hints and the display mode to use |
35 | # hints and the display mode to use |
| 34 | $formFields, # in CGI::Vars format |
|
|
| 35 | ) = @_; |
36 | ) = @_; |
| 36 | |
37 | |
| 37 | # get database information |
38 | # # get database information |
| 38 | my $classlist = WeBWorK::DB::Classlist->new($courseEnv); |
39 | # my $classlist = WeBWorK::DB::Classlist->new($courseEnv); |
| 39 | my $wwdb = WeBWorK::DB::WW->new($courseEnv); |
40 | # my $wwdb = WeBWorK::DB::WW->new($courseEnv); |
| 40 | my $user = $classlist->getUser($userName); |
41 | # my $user = $classlist->getUser($userName); |
| 41 | my $set = $wwdb->getSet($userName, $setName); |
42 | # my $set = $wwdb->getSet($userName, $setName); |
| 42 | my $psvn = $wwdb->getPSVN($userName, $setName); |
43 | # my $psvn = $wwdb->getPSVN($userName, $setName); |
| 43 | |
44 | # |
| 44 | my $problem; |
45 | # my $problem; |
| 45 | if ($problemNumber =~ /^\d+$/) { |
46 | # if ($problemNumber =~ /^\d+$/) { |
| 46 | $problem = $wwdb->getProblem($userName, $setName, $problemNumber); |
47 | # $problem = $wwdb->getProblem($userName, $setName, $problemNumber); |
| 47 | } else { |
48 | # } else { |
| 48 | # This is the fun part: if $problemNumber is NON-NUMERIC, the |
49 | # # This is the fun part: if $problemNumber is NON-NUMERIC, the |
| 49 | # user wants to specify a PG file directly. We manufacture a |
50 | # # user wants to specify a PG file directly. We manufacture a |
| 50 | # Problem object using fake data and the specified source file. |
51 | # # Problem object using fake data and the specified source file. |
| 51 | # This is potentially dangerous since an untrusted user is |
52 | # # This is potentially dangerous since an untrusted user is |
| 52 | # allowed to specifiy an arbitrary file to be evaluated as PG. |
53 | # # allowed to specifiy an arbitrary file to be evaluated as PG. |
| 53 | # A user of PG.pm MUST MAKE SURE that if $problemNumber is |
54 | # # A user of PG.pm MUST MAKE SURE that if $problemNumber is |
| 54 | # supplied by an untrusted source (i.e. the Apache request), |
55 | # # supplied by an untrusted source (i.e. the Apache request), |
| 55 | # it is numberic. A simple |
56 | # # it is numberic. A simple |
| 56 | # |
57 | # # |
| 57 | # die unless $problemNumber =~ /^\d+$/; |
58 | # # die unless $problemNumber =~ /^\d+$/; |
| 58 | # |
59 | # # |
| 59 | # should suffice. |
60 | # # should suffice. |
| 60 | $problem = WeBWorK::Problem->new( |
61 | # $problem = WeBWorK::Problem->new( |
| 61 | id => 0, |
62 | # id => 0, |
| 62 | set_id => $set->id, |
63 | # set_id => $set->id, |
| 63 | login_id => $user->id, |
64 | # login_id => $user->id, |
| 64 | source_file => $problemNumber, |
65 | # source_file => $problemNumber, |
| 65 | # the rest of Problem's fields are not needed |
66 | # # the rest of Problem's fields are not needed |
| 66 | ); |
67 | # ); |
| 67 | } |
68 | # } |
| 68 | |
69 | |
| 69 | # create a Translator |
70 | # create a Translator |
| 70 | warn "PG: creating a Translator\n"; |
71 | warn "PG: creating a Translator\n"; |
| 71 | my $translator = WeBWorK::PG::Translator->new; |
72 | my $translator = WeBWorK::PG::Translator->new; |
| 72 | |
73 | |
| … | |
… | |
| 91 | } |
92 | } |
| 92 | |
93 | |
| 93 | # set the environment (from defineProblemEnvir) |
94 | # set the environment (from defineProblemEnvir) |
| 94 | warn "PG: setting the environment (from defineProblemEnvir)\n"; |
95 | warn "PG: setting the environment (from defineProblemEnvir)\n"; |
| 95 | $translator->environment(defineProblemEnvir( |
96 | $translator->environment(defineProblemEnvir( |
| 96 | $courseEnv, $user, $key, $set, $problem, $psvn, $formFields, $translationOptions)); |
97 | $courseEnv, |
|
|
98 | $user, |
|
|
99 | $key, |
|
|
100 | $set, |
|
|
101 | $problem, |
|
|
102 | $psvn, |
|
|
103 | $formFields, |
|
|
104 | $translationOptions, |
|
|
105 | )); |
| 97 | |
106 | |
| 98 | # initialize the Translator |
107 | # initialize the Translator |
| 99 | warn "PG: initializing the Translator\n"; |
108 | warn "PG: initializing the Translator\n"; |
| 100 | $translator->initialize(); |
109 | $translator->initialize(); |
| 101 | |
110 | |
| … | |
… | |
| 332 | __END__ |
341 | __END__ |
| 333 | |
342 | |
| 334 | =head1 SYNOPSIS |
343 | =head1 SYNOPSIS |
| 335 | |
344 | |
| 336 | $pg = WeBWorK::PG->new( |
345 | $pg = WeBWorK::PG->new( |
| 337 | $courseEnv, # a WeBWorK::CourseEnvironment object |
346 | $courseEnv, # a WeBWorK::CourseEnvironment object |
| 338 | $userName, |
347 | $user, # a WeBWorK::User object |
| 339 | $sessionKey, |
348 | $sessionKey, |
| 340 | $setName, |
349 | $set, # a WeBWorK::Set object |
| 341 | $problemNumber, |
350 | $problem, # a WeBWorK::Problem object |
|
|
351 | $psvn, |
|
|
352 | $formFields # in &WeBWorK::Form::Vars format |
| 342 | { # translation options |
353 | { # translation options |
| 343 | displayMode => "images", # (plainText|formattedText|images) |
354 | displayMode => "images", # (plainText|formattedText|images) |
| 344 | showHints => 1, # (0|1) |
355 | showHints => 1, # (0|1) |
| 345 | showSolutions => 0, # (0|1) |
356 | showSolutions => 0, # (0|1) |
| 346 | refreshMath2img => 0, # (0|1) |
357 | refreshMath2img => 0, # (0|1) |
| 347 | processAnswers => 1, # (0|1) |
358 | processAnswers => 1, # (0|1) |
| 348 | }, |
359 | }, |
| 349 | $formFields # in WeBWorK::Form::Vars format |
|
|
| 350 | ); |
360 | ); |
| 351 | |
361 | |
| 352 | $translator = $pg->{translator}; # WeBWorK::PG::Translator |
362 | $translator = $pg->{translator}; # WeBWorK::PG::Translator |
| 353 | $body = $pg->{body_text}; # text string |
363 | $body = $pg->{body_text}; # text string |
| 354 | $header = $pg->{head_text}; # text string |
364 | $header = $pg->{head_text}; # text string |
| … | |
… | |
| 367 | |
377 | |
| 368 | =head1 CONSTRUCTION |
378 | =head1 CONSTRUCTION |
| 369 | |
379 | |
| 370 | =over |
380 | =over |
| 371 | |
381 | |
| 372 | =item new (ENVIRONMENT, USER, KEY, SET, PROBLEM, OPTIONS, FIELDS) |
382 | =item new (ENVIRONMENT, USER, KEY, SET, PROBLEM, PSVN, FIELDS, OPTIONS) |
| 373 | |
383 | |
| 374 | The C<new> method creates a translator, initializes it using the parameters |
384 | The C<new> method creates a translator, initializes it using the parameters |
| 375 | specified, translates a PG file, and processes answers. It returns a reference |
385 | specified, translates a PG file, and processes answers. It returns a reference |
| 376 | to a blessed hash containing the results of the translation process. |
386 | to a blessed hash containing the results of the translation process. |
| 377 | |
387 | |
| … | |
… | |
| 385 | |
395 | |
| 386 | a WeBWorK::CourseEnvironment object |
396 | a WeBWorK::CourseEnvironment object |
| 387 | |
397 | |
| 388 | =item USER |
398 | =item USER |
| 389 | |
399 | |
| 390 | the name of the user for whom to render |
400 | a WeBWorK::User object |
| 391 | |
401 | |
| 392 | =item KEY |
402 | =item KEY |
| 393 | |
403 | |
| 394 | the session key of the current session |
404 | the session key of the current session |
| 395 | |
405 | |
| 396 | =item SET |
406 | =item SET |
| 397 | |
407 | |
| 398 | the name of the problem set from which to get the problem |
408 | a WeBWorK::Set object |
| 399 | |
409 | |
| 400 | =item PROBLEM |
410 | =item PROBLEM |
| 401 | |
411 | |
| 402 | the number of the problem to render |
412 | a WeBWorK::Problem object |
| 403 | |
413 | |
| 404 | =item OPTIONS |
414 | =item PSVN |
| 405 | |
415 | |
| 406 | a reference to a hash containing the following data: |
416 | the problem set version number |
| 407 | |
|
|
| 408 | =over |
|
|
| 409 | |
|
|
| 410 | =item displayMode |
|
|
| 411 | |
|
|
| 412 | one of "plainText", "formattedText", or "images" |
|
|
| 413 | |
|
|
| 414 | =item showHints |
|
|
| 415 | |
|
|
| 416 | boolean, render hints |
|
|
| 417 | |
|
|
| 418 | =item showSolutions |
|
|
| 419 | |
|
|
| 420 | boolean, render solutions |
|
|
| 421 | |
|
|
| 422 | =item refreshMath2img |
|
|
| 423 | |
|
|
| 424 | boolean, force images created by math2img (in "images" mode) to be recreated, |
|
|
| 425 | even if the PG source has not been updated. |
|
|
| 426 | |
|
|
| 427 | =item processAnswers |
|
|
| 428 | |
|
|
| 429 | boolean, call answer evaluators and graders |
|
|
| 430 | |
|
|
| 431 | =back |
|
|
| 432 | |
417 | |
| 433 | =item FIELDS |
418 | =item FIELDS |
| 434 | |
419 | |
| 435 | a reference to a hash (as returned by &WeBWorK::Form::Vars) containing form |
420 | a reference to a hash (as returned by &WeBWorK::Form::Vars) containing form |
| 436 | fields submitted by a problem processor. The translator will look for fields |
421 | fields submitted by a problem processor. The translator will look for fields |
| 437 | like "AnSwEr[0-9]" containing submitted student answers. |
422 | like "AnSwEr[0-9]" containing submitted student answers. |
| 438 | |
423 | |
|
|
424 | =item OPTIONS |
|
|
425 | |
|
|
426 | a reference to a hash containing the following data: |
|
|
427 | |
|
|
428 | =over |
|
|
429 | |
|
|
430 | =item displayMode |
|
|
431 | |
|
|
432 | one of "plainText", "formattedText", or "images" |
|
|
433 | |
|
|
434 | =item showHints |
|
|
435 | |
|
|
436 | boolean, render hints |
|
|
437 | |
|
|
438 | =item showSolutions |
|
|
439 | |
|
|
440 | boolean, render solutions |
|
|
441 | |
|
|
442 | =item refreshMath2img |
|
|
443 | |
|
|
444 | boolean, force images created by math2img (in "images" mode) to be recreated, |
|
|
445 | even if the PG source has not been updated. |
|
|
446 | |
|
|
447 | =item processAnswers |
|
|
448 | |
|
|
449 | boolean, call answer evaluators and graders |
|
|
450 | |
|
|
451 | =back |
|
|
452 | |
| 439 | =back |
453 | =back |
| 440 | |
454 | |
| 441 | =head2 RETURN VALUE |
455 | =head2 RETURN VALUE |
| 442 | |
456 | |
| 443 | The C<new> method returns a blessed hash reference containing the following |
457 | The C<new> method returns a blessed hash reference containing the following |