From: Mike G. v. a. <we...@ma...> - 2005-10-17 13:58:57
|
Log Message: ----------- Improved handling of case where a blank_problem is asked for in PGProblemEditor.pm Also improved the random names for new local problems Added ability to create a new blank problem in ProblemSetDetail.pm (without going to the PGProblemEditor.pm) however something is not yet working when this problem record is saved. Sam -- could you look at lines near 679 to see what the problem is? There is a FIXME note there. I suspect that the addProblemToSet routine is failing somehow, but there is no error message. Many of the record fields are not filled out -- including the sourceFile path and the number of attempts. The same snippet of code works fine in PGProblemEditor.pm --Mike Modified Files: -------------- webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor: PGProblemEditor.pm ProblemSetDetail.pm Revision Data ------------- Index: PGProblemEditor.pm =================================================================== RCS file: /webwork/cvs/system/webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm,v retrieving revision 1.58 retrieving revision 1.59 diff -Llib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm -Llib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm -u -r1.58 -r1.59 --- lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm +++ lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm @@ -547,7 +547,7 @@ if ($path =~ /Library/) { $path =~ s|^.*?Library/||; # truncate the url up to a segment such as ...rochesterLibrary/....... } else { # if its not in a library we'll just save it locally - $path = "new_problem_".rand(40).".pg"; #l hope there aren't any collisions. + $path = "new_problem_".int(rand(1000)).".pg"; #l hope there aren't any collisions. } $path; @@ -557,7 +557,8 @@ my $self = shift; die "determineTempFilePath is a method" unless ref($self); my $path =shift; my $user = $self->r->param("user"); - $user = rand(1000) unless defined $user; + $user = int(rand(1000)) unless defined $user; + my $setID = $self->{setID} || int(rand(1000)); my $courseDirectory = $self->r->ce->{courseDirs}; #FIXME -- we can put all of the temp files in a special directory # so that even library files can viewed. @@ -565,16 +566,17 @@ # Calculate the location of the temporary file ############### my $templatesDirectory = $courseDirectory->{templates}; + my $blank_file_path = $self->r->ce->{webworkFiles}->{screenSnippets}->{blankProblem}; + my $tmpEditFileDirectory = (defined ($courseDirectory->{tmpEditFileDir}) ) ? $courseDirectory->{tmpEditFileDir} : "$templatesDirectory/tmpEdit"; if ($path =~ /^$templatesDirectory/ ) { $path =~ s|^$templatesDirectory||; $path =~ s|^/||; # remove the initial slash if any + $path = "$tmpEditFileDirectory/$path.$user.tmp"; + } elsif ($path eq $blank_file_path) { + $path = "$tmpEditFileDirectory/blank.$setID.$user.tmp"; # handle the case of the blank problem } else { die "determineTempFilePath should only be used on paths within the templates directory, not on $path"; } - my $tmpEditFileDirectory = (defined ($courseDirectory->{tmpEditFileDir}) ) ? $courseDirectory->{tmpEditFileDir} : "$templatesDirectory/tmpEdit"; - $path = "$tmpEditFileDirectory/$path.$user.tmp"; - #$path .= ".$user.tmp"; - #WeBWorK::Utils::surePathToFile($templatesDirectory, $path); $path; } sub isTempFilePath { @@ -1038,7 +1040,7 @@ my $problemRecord = $self->addProblemToSet( setName => $targetSetName, sourceFile => $sourceFilePath, - problemID => $targetProblemNumber, + problemID => $targetProblemNumber, #added to end of set ); $self->assignProblemToAllSetUsers($problemRecord); $self->addgoodmessage("Added $sourceFilePath to ". $targetSetName. " as problem $targetProblemNumber") ; Index: ProblemSetDetail.pm =================================================================== RCS file: /webwork/cvs/system/webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm,v retrieving revision 1.21 retrieving revision 1.22 diff -Llib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm -Llib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm -u -r1.21 -r1.22 --- lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm +++ lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm @@ -675,8 +675,28 @@ } $db->putGlobalSet($setRecord); } - - + ##################################################################### + # Add blank problem if needed + ##################################################################### + if (defined($r->param("add_blank_problem") ) and $r->param("add_blank_problem") == 1) { + my $targetProblemNumber = 1+ WeBWorK::Utils::max( $self->r->db->listGlobalProblems($setID)); + my $blank_file_path = $ce->{webworkFiles}->{screenSnippets}->{blankProblem}; + my $new_file_path = $ce->{courseDirs}->{templates}."/set$setID/blank.pg"; + ################################################# + # Update problem record + ################################################# + my $problemRecord = $self->addProblemToSet( + setName => $setID, + sourceFile => $blank_file_path, + problemID => $targetProblemNumber, #added to end of set + ); + $self->assignProblemToAllSetUsers($problemRecord); + $self->addgoodmessage("Added $blank_file_path to ". $setID. " as problem $targetProblemNumber") ; + #warn "A new blank problem has been added at number $targetProblemNumber with source $blank_file_path and record is $problemRecord" ; + #FIXME -- for reasons I don't understand the sourceFile reference is not accepted. + # furthermore, while the new problem appears in the listing for problem set details, it doesn't appear in the "hmwk set editor" (ProblemSetEditor.pm) + # this snippet was copied from PGProblemSetEditor.pm line 1038 where it appears to work. What's up?? + } ##################################################################### # Save problem information ##################################################################### @@ -1293,8 +1313,12 @@ print CGI::checkbox({ label=> "Force problems to be numbered consecutively from one", name=>"force_renumber", value=>"1"}), + CGI::br(), + CGI::checkbox({ + label=> "Add blank problem to set", + name=>"add_blank_problem", value=>"1"}), - CGI::br(); + CGI::br(); print CGI::input({type=>"submit", name=>"submit_changes", value=>"Save Changes"}); print CGI::input({type=>"submit", name=>"handle_numbers", value=>"Reorder problems only"}) . "(Any unsaved changes will be lost.)"; print CGI::p(<<HERE); |