WeBWorK Main Forum

Customize a problem by user

Customize a problem by user

by Michael Shulman -
Number of replies: 1
Is there any way for a WW problem to obtain information about the logged-in user (e.g. name, username, student id #), so as to use it in customizing a problem non-randomly? If such an ability doesn't already exist, would it be possible to write my own PG macro to do it?
In reply to Michael Shulman

Re: Customize a problem by user

by Nathan Wallach -
This is possible. Have a look at the following OPL problem:
which makes use of $studentLogin to access student identity data and then set a seed for Rserve.

Uncommenting the "warn" line in this file shows that the $studentName and $studentID fields are also accessible.

Technical background:
  • webwork2/lib/WeBWorK/PG.pm puts these three data fields into the PG %envir hash.
  • pg/macros/PG_CAPAmacros.pl makes use of $main::studentName
  • pg/macros/PGtextevaluators.pl makes use of all 3 fields
  • Several other files in the pg code tree make use of either:
    • $main::studentName
    • $envir->{studentLogin}
Hope this helps,
Nathan