Parent Directory
|
Revision Log
I've added code for defining the problemEnvironment, at least for now. Many of the values which will be pulled from the database have simply been hardcoded into the subroutine. There is also code to pretty print these values to aid in debugging.
1 package WeBWorK::ContentGenerator::Problem; 2 our @ISA = qw(WeBWorK::ContentGenerator); 3 use lib '/Users/gage/webwork/xmlrpc/daemon'; 4 use lib '/Users/gage/webwork-modperl/lib'; 5 use PGtranslator5; 6 use WeBWorK::ContentGenerator; 7 use Apache::Constants qw(:common); 8 9 sub title { 10 my ($self, $problem_set, $problem) = @_; 11 my $r = $self->{r}; 12 my $user = $r->param('user'); 13 return "Problem $problem of problem set $problem_set for $user"; 14 } 15 16 sub body { 17 my ($self, $problem_set, $problem) = @_; 18 my $r = $self->{r}; 19 my $courseEnvironment = $self->{courseEnvironment}; 20 my $user = $r->param('user'); 21 22 print "Problem goes here<p>\n"; 23 24 print "<P>Request item<P>\n\n"; 25 print "<TABLE border=\"3\">"; 26 print $self->print_form_data('<tr><td>','</td><td>','</td></tr>'); 27 print "</table>\n"; 28 print "<P>\n\ncourseEnvironment<P>\n\n"; 29 print pretty_print_rh($courseEnvironment); 30 31 ########################################################################### 32 # The pg problem class should have a method for installing it's problemEnvironment 33 ########################################################################### 34 35 $problemEnvir_rh = defineProblemEnvir($self); 36 37 print "<P>\n\nproblemEnvironment<P>\n\n"; 38 print pretty_print_rh($problemEnvir_rh); 39 # my $sig = do "pgGenerator.pl" ; 40 # print "File not found $1" unless defined(sig); 41 # print "Errors $@"; 42 # print pgHTML(); 43 44 ""; 45 } 46 47 48 ######################################################################################## 49 # This is the structure that needs to be filled out in order to call PGtranslator; 50 ######################################################################################## 51 52 sub defineProblemEnvir { 53 my $self = shift; 54 my $r = $self->{r}; 55 my $courseEnvironment = $self->{courseEnvironment}; 56 my %envir=(); 57 # $envir{'refSubmittedAnswers'} = $refSubmittedAnswers if defined($refSubmittedAnswers); 58 $envir{'psvnNumber'} = 123456789; 59 $envir{'psvn'} = 123456789; 60 $envir{'studentName'} = 'Jane Doe'; 61 $envir{'studentLogin'} = 'jd001m'; 62 $envir{'studentID'} = 'xxx-xx-4321'; 63 $envir{'sectionName'} = 'gage'; 64 $envir{'sectionNumber'} = '111foobar'; 65 $envir{'recitationName'} = 'gage_recitation'; 66 $envir{'recitationNumber'} = '11_foobar recitation'; 67 $envir{'setNumber'} = 'setAlgebraicGeometry'; 68 $envir{'questionNumber'} = 43; 69 $envir{'probNum'} = 43; 70 $envir{'openDate'} = 3014438528; 71 $envir{'formattedOpenDate'} = '3/4/02'; 72 $envir{'dueDate'} = 4014438528; 73 $envir{'formattedDueDate'} = '10/4/04'; 74 $envir{'answerDate'} = 4014438528; 75 $envir{'formattedAnswerDate'} = '10/4/04'; 76 $envir{'problemValue'} = 1; 77 $envir{'fileName'} = 'problem1'; 78 $envir{'probFileName'} = 'problem1'; 79 $envir{'languageMode'} = 'HTML_tth'; 80 $envir{'displayMode'} = 'HTML_tth'; 81 $envir{'outputMode'} = 'HTML_tth'; 82 $envir{'courseName'} = $courseEnvironment ->{courseName}; 83 $envir{'sessionKey'} = 'asdf'; 84 85 # initialize constants for PGanswermacros.pl 86 $envir{'numRelPercentTolDefault'} = .1; 87 $envir{'numZeroLevelDefault'} = 1E-14; 88 $envir{'numZeroLevelTolDefault'} = 1E-12; 89 $envir{'numAbsTolDefault'} = .001; 90 $envir{'numFormatDefault'} = ''; 91 $envir{'functRelPercentTolDefault'} = .1; 92 $envir{'functZeroLevelDefault'} = 1E-14; 93 $envir{'functZeroLevelTolDefault'} = 1E-12; 94 $envir{'functAbsTolDefault'} = .001; 95 $envir{'functNumOfPoints'} = 3; 96 $envir{'functVarDefault'} = 'x'; 97 $envir{'functLLimitDefault'} = .0000001; 98 $envir{'functULimitDefault'} = .9999999; 99 $envir{'functMaxConstantOfIntegration'} = 1E8; 100 # kludge check definition of number of attempts again. The +1 is because this is used before the current answer is evaluated. 101 $envir{'numOfAttempts'} = 2; #&getProblemNumOfCorrectAns($probNum,$psvn) 102 # &getProblemNumOfIncorrectAns($probNum,$psvn)+1; 103 104 # 105 # 106 # defining directorys and URLs 107 $envir{'templateDirectory'} = $courseEnvironment ->{courseDirs}->{templates}; 108 ############ $envir{'classDirectory'} = $Global::classDirectory; 109 # $envir{'cgiDirectory'} = $Global::cgiDirectory; 110 # $envir{'cgiURL'} = getWebworkCgiURL(); 111 # $envir{'macroDirectory'} = getCourseMacroDirectory(); 112 # $envir{'courseScriptsDirectory'} = getCourseScriptsDirectory(); 113 $envir{'htmlDirectory'} = $courseEnvironment ->{courseDirectory}->{html}; 114 # $envir{'htmlURL'} = getCourseHtmlURL(); 115 # $envir{'tempDirectory'} = getCourseTempDirectory(); 116 # $envir{'tempURL'} = getCourseTempURL(); 117 # $envir{'scriptDirectory'} = $Global::scriptDirectory;##omit 118 $envir{'webworkDocsURL'} = 'http://webwork.math.rochester.edu'; 119 $envir{'externalTTHPath'} = '/usr/local/bin/tth'; 120 121 122 # 123 $envir{'inputs_ref'} = $r->param; 124 $envir{'problemSeed'} = 3245; 125 $envir{'displaySolutionsQ'} = 1; 126 $envir{'displayHintsQ'} = 1; 127 128 # here is a way to pass environment variables defined in webworkCourse.ph 129 # my $k; 130 # foreach $k (keys %Global::PG_environment ) { 131 # $envir{$k} = $Global::PG_environment{$k}; 132 # } 133 \%envir; 134 } 135 136 ######################################################################################## 137 # This recursive pretty_print function will print a hash and its sub hashes. 138 ######################################################################################## 139 sub pretty_print_rh { 140 my $r_input = shift; 141 my $out = ''; 142 if ( not ref($r_input) ) { 143 $out = $r_input; # not a reference 144 } elsif (is_hash_ref($r_input)) { 145 local($^W) = 0; 146 $out .= "<TABLE border = \"2\" cellpadding = \"3\" BGCOLOR = \"#FFFFFF\">"; 147 foreach my $key (sort keys %$r_input ) { 148 $out .= "<tr><TD> $key</TD><TD>=></td><td> ".pretty_print_rh($r_input->{$key}) . "</td></tr>"; 149 } 150 $out .="</table>"; 151 } elsif (is_array_ref($r_input) ) { 152 my @array = @$r_input; 153 $out .= "( " ; 154 while (@array) { 155 $out .= pretty_print_rh(shift @array) . " , "; 156 } 157 $out .= " )"; 158 } elsif (ref($r_input) eq 'CODE') { 159 $out = "$r_input"; 160 } else { 161 $out = $r_input; 162 } 163 $out; 164 } 165 166 sub is_hash_ref { 167 my $in =shift; 168 my $save_SIG_die_trap = $SIG{__DIE__}; 169 $SIG{__DIE__} = sub {CORE::die(@_) }; 170 my $out = eval{ %{ $in } }; 171 $out = ($@ eq '') ? 1 : 0; 172 $@=''; 173 $SIG{__DIE__} = $save_SIG_die_trap; 174 $out; 175 } 176 sub is_array_ref { 177 my $in =shift; 178 my $save_SIG_die_trap = $SIG{__DIE__}; 179 $SIG{__DIE__} = sub {CORE::die(@_) }; 180 my $out = eval{ @{ $in } }; 181 $out = ($@ eq '') ? 1 : 0; 182 $@=''; 183 $SIG{__DIE__} = $save_SIG_die_trap; 184 $out; 185 } 186 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |