[system] / branches / gage_dev / webwork2 / lib / WeBWorK / ContentGenerator / Instructor / ProblemSetDetail.pm Repository:
ViewVC logotype

Diff of /branches/gage_dev/webwork2/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 3720 Revision 3721
673 } 673 }
674 $setRecord->$field($param); 674 $setRecord->$field($param);
675 } 675 }
676 $db->putGlobalSet($setRecord); 676 $db->putGlobalSet($setRecord);
677 } 677 }
678
679 #####################################################################
680 # Save problem information
681 #####################################################################
682
683 my @problemIDs = sort { $a <=> $b } $db->listGlobalProblems($setID);;
684 my @problemRecords = $db->getGlobalProblems(map { [$setID, $_] } @problemIDs);
685 foreach my $problemRecord (@problemRecords) {
686 my $problemID = $problemRecord->problem_id;
687 die "Global problem $problemID for set $setID not found." unless $problemRecord;
688
689 if ($forUsers) {
690 # Since we're editing for specific users, we don't allow the GlobalProblem record to be altered on that same page
691 # So we only need to make changes to the UserProblem record and only then if we are overriding a value
692 # in the GlobalProblem record or for fields unique to the UserProblem record.
693
694 my @userIDs = @editForUser;
695 my @userProblemIDs = map { [$_, $setID, $problemID] } @userIDs;
696 my @userProblemRecords = $db->getUserProblems(@userProblemIDs);
697 foreach my $record (@userProblemRecords) {
698
699 my $changed = 0; # keep track of any changes, if none are made, avoid unnecessary db accesses
700 foreach my $field ( @{ PROBLEM_FIELDS() } ) {
701 next unless canChange($forUsers, $field);
702
703 my $override = $r->param("problem.$problemID.$field.override");
704 if (defined $override && $override eq $field) {
705
706 my $param = $r->param("problem.$problemID.$field");
707 $param = $properties{$field}->{default} || "" unless defined $param && $param ne "";
708 my $unlabel = $undoLabels{$field}->{$param};
709 $param = $unlabel if defined $unlabel;
710 $changed ||= changed($record->$field, $param);
711 $record->$field($param);
712 } else {
713 $changed ||= changed($record->$field, undef);
714 $record->$field(undef);
715 }
716
717 }
718
719 foreach my $field ( @{ USER_PROBLEM_FIELDS() } ) {
720 next unless canChange($forUsers, $field);
721
722 my $param = $r->param("problem.$problemID.$field");
723 $param = $properties{$field}->{default} || "" unless defined $param && $param ne "";
724 my $unlabel = $undoLabels{$field}->{$param};
725 $param = $unlabel if defined $unlabel;
726 $changed ||= changed($record->$field, $param);
727 $record->$field($param);
728 }
729 $db->putUserProblem($record) if $changed;
730 }
731 } else {
732 # Since we're editing for ALL set users, we will make changes to the GlobalProblem record.
733 # We may also have instances where a field is unique to the UserProblem record but we want
734 # all users to (at least initially) have the same value
735
736 # this only edits a globalProblem record
737 my $changed = 0; # keep track of any changes, if none are made, avoid unnecessary db accesses
738 foreach my $field ( @{ PROBLEM_FIELDS() } ) {
739 next unless canChange($forUsers, $field);
740
741 my $param = $r->param("problem.$problemID.$field");
742 $param = $properties{$field}->{default} || "" unless defined $param && $param ne "";
743 my $unlabel = $undoLabels{$field}->{$param};
744 $param = $unlabel if defined $unlabel;
745 $changed ||= changed($problemRecord->$field, $param);
746 $problemRecord->$field($param);
747 }
748 $db->putGlobalProblem($problemRecord) if $changed;
749
750
751 # sometimes (like for status) we might want to change an attribute in
752 # the userProblem record for every assigned user
753 # However, since this data is stored in the UserProblem records,
754 # it won't be displayed once its been changed and if you hit "Save Changes" again
755 # it gets erased
756
757 # So we'll enforce that there be something worth putting in all the UserProblem records
758 # This also will make hitting "Save Changes" on the global page MUCH faster
759 my %useful;
760 foreach my $field ( @{ USER_PROBLEM_FIELDS() } ) {
761 my $param = $r->param("problem.$problemID.$field");
762 $useful{$field} = 1 if defined $param and $param ne "";
763 }
764
765 if (keys %useful) {
766 my @userIDs = $db->listProblemUsers($setID, $problemID);
767 my @userProblemIDs = map { [$_, $setID, $problemID] } @userIDs;
768 my @userProblemRecords = $db->getUserProblems(@userProblemIDs);
769 foreach my $record (@userProblemRecords) {
770 my $changed = 0; # keep track of any changes, if none are made, avoid unnecessary db accesses
771 foreach my $field ( keys %useful ) {
772 next unless canChange($forUsers, $field);
773
774 my $param = $r->param("problem.$problemID.$field");
775 $param = $properties{$field}->{default} || "" unless defined $param && $param ne "";
776 my $unlabel = $undoLabels{$field}->{$param};
777 $param = $unlabel if defined $unlabel;
778 $changed ||= changed($record->$field, $param);
779 $record->$field($param);
780 }
781 $db->putUserProblem($record) if $changed;
782 }
783 }
784 }
785 }
786
787 # Mark the specified problems as correct for all users
788 foreach my $problemID ($r->param('markCorrect')) {
789 my @userProblemIDs = map { [$_, $setID, $problemID] } ($forUsers ? @editForUser : $db->listProblemUsers($setID, $problemID));
790 my @userProblemRecords = $db->getUserProblems(@userProblemIDs);
791 foreach my $record (@userProblemRecords) {
792 if (defined $record && ($record->status eq "" || $record->status < 1)) {
793 $record->status(1);
794 $record->attempted(1);
795 $db->putUserProblem($record);
796 }
797 }
798 }
799
800 # Delete all problems marked for deletion
801 foreach my $problemID ($r->param('deleteProblem')) {
802 $db->deleteGlobalProblem($setID, $problemID);
803 }
804
678 ##################################################################### 805 #####################################################################
679 # Add blank problem if needed 806 # Add blank problem if needed
680 ##################################################################### 807 #####################################################################
681 if (defined($r->param("add_blank_problem") ) and $r->param("add_blank_problem") == 1) { 808 if (defined($r->param("add_blank_problem") ) and $r->param("add_blank_problem") == 1) {
682 my $targetProblemNumber = 1+ WeBWorK::Utils::max( $self->r->db->listGlobalProblems($setID)); 809 my $targetProblemNumber = 1+ WeBWorK::Utils::max( $self->r->db->listGlobalProblems($setID));
688 my $problemRecord = $self->addProblemToSet( 815 my $problemRecord = $self->addProblemToSet(
689 setName => $setID, 816 setName => $setID,
690 sourceFile => $blank_file_path, 817 sourceFile => $blank_file_path,
691 problemID => $targetProblemNumber, #added to end of set 818 problemID => $targetProblemNumber, #added to end of set
692 ); 819 );
693 $self->assignProblemToAllSetUsers($problemRecord); 820 #$self->assignProblemToAllSetUsers($problemRecord);
694 $self->addgoodmessage("Added $blank_file_path to ". $setID. " as problem $targetProblemNumber") ; 821 $self->addgoodmessage("Added $blank_file_path to ". $setID. " as problem $targetProblemNumber") ;
695 #warn "A new blank problem has been added at number $targetProblemNumber with source $blank_file_path and record is $problemRecord" ; 822 #warn "A new blank problem has been added at number $targetProblemNumber with source $blank_file_path and record is $problemRecord" ;
696 #FIXME -- for reasons I don't understand the sourceFile reference is not accepted. 823 #FIXME -- for reasons I don't understand the sourceFile reference is not accepted.
697 # furthermore, while the new problem appears in the listing for problem set details, it doesn't appear in the "hmwk set editor" (ProblemSetEditor.pm) 824 # furthermore, while the new problem appears in the listing for problem set details, it doesn't appear in the "hmwk set editor" (ProblemSetEditor.pm)
698 # this snippet was copied from PGProblemSetEditor.pm line 1038 where it appears to work. What's up?? 825 # this snippet was copied from PGProblemSetEditor.pm line 1038 where it appears to work. What's up??
699 } 826 }
700 #####################################################################
701 # Save problem information
702 #####################################################################
703
704 my @problemIDs = sort { $a <=> $b } $db->listGlobalProblems($setID);;
705 my @problemRecords = $db->getGlobalProblems(map { [$setID, $_] } @problemIDs);
706 foreach my $problemRecord (@problemRecords) {
707 my $problemID = $problemRecord->problem_id;
708 die "Global problem $problemID for set $setID not found." unless $problemRecord;
709
710 if ($forUsers) {
711 # Since we're editing for specific users, we don't allow the GlobalProblem record to be altered on that same page
712 # So we only need to make changes to the UserProblem record and only then if we are overriding a value
713 # in the GlobalProblem record or for fields unique to the UserProblem record.
714
715 my @userIDs = @editForUser;
716 my @userProblemIDs = map { [$_, $setID, $problemID] } @userIDs;
717 my @userProblemRecords = $db->getUserProblems(@userProblemIDs);
718 foreach my $record (@userProblemRecords) {
719
720 my $changed = 0; # keep track of any changes, if none are made, avoid unnecessary db accesses
721 foreach my $field ( @{ PROBLEM_FIELDS() } ) {
722 next unless canChange($forUsers, $field);
723
724 my $override = $r->param("problem.$problemID.$field.override");
725 if (defined $override && $override eq $field) {
726
727 my $param = $r->param("problem.$problemID.$field");
728 $param = $properties{$field}->{default} || "" unless defined $param && $param ne "";
729 my $unlabel = $undoLabels{$field}->{$param};
730 $param = $unlabel if defined $unlabel;
731 $changed ||= changed($record->$field, $param);
732 $record->$field($param);
733 } else {
734 $changed ||= changed($record->$field, undef);
735 $record->$field(undef);
736 }
737
738 }
739
740 foreach my $field ( @{ USER_PROBLEM_FIELDS() } ) {
741 next unless canChange($forUsers, $field);
742
743 my $param = $r->param("problem.$problemID.$field");
744 $param = $properties{$field}->{default} || "" unless defined $param && $param ne "";
745 my $unlabel = $undoLabels{$field}->{$param};
746 $param = $unlabel if defined $unlabel;
747 $changed ||= changed($record->$field, $param);
748 $record->$field($param);
749 }
750 $db->putUserProblem($record) if $changed;
751 }
752 } else {
753 # Since we're editing for ALL set users, we will make changes to the GlobalProblem record.
754 # We may also have instances where a field is unique to the UserProblem record but we want
755 # all users to (at least initially) have the same value
756
757 # this only edits a globalProblem record
758 my $changed = 0; # keep track of any changes, if none are made, avoid unnecessary db accesses
759 foreach my $field ( @{ PROBLEM_FIELDS() } ) {
760 next unless canChange($forUsers, $field);
761
762 my $param = $r->param("problem.$problemID.$field");
763 $param = $properties{$field}->{default} || "" unless defined $param && $param ne "";
764 my $unlabel = $undoLabels{$field}->{$param};
765 $param = $unlabel if defined $unlabel;
766 $changed ||= changed($problemRecord->$field, $param);
767 $problemRecord->$field($param);
768 }
769 $db->putGlobalProblem($problemRecord) if $changed;
770
771
772 # sometimes (like for status) we might want to change an attribute in
773 # the userProblem record for every assigned user
774 # However, since this data is stored in the UserProblem records,
775 # it won't be displayed once its been changed and if you hit "Save Changes" again
776 # it gets erased
777
778 # So we'll enforce that there be something worth putting in all the UserProblem records
779 # This also will make hitting "Save Changes" on the global page MUCH faster
780 my %useful;
781 foreach my $field ( @{ USER_PROBLEM_FIELDS() } ) {
782 my $param = $r->param("problem.$problemID.$field");
783 $useful{$field} = 1 if defined $param and $param ne "";
784 }
785
786 if (keys %useful) {
787 my @userIDs = $db->listProblemUsers($setID, $problemID);
788 my @userProblemIDs = map { [$_, $setID, $problemID] } @userIDs;
789 my @userProblemRecords = $db->getUserProblems(@userProblemIDs);
790 foreach my $record (@userProblemRecords) {
791 my $changed = 0; # keep track of any changes, if none are made, avoid unnecessary db accesses
792 foreach my $field ( keys %useful ) {
793 next unless canChange($forUsers, $field);
794
795 my $param = $r->param("problem.$problemID.$field");
796 $param = $properties{$field}->{default} || "" unless defined $param && $param ne "";
797 my $unlabel = $undoLabels{$field}->{$param};
798 $param = $unlabel if defined $unlabel;
799 $changed ||= changed($record->$field, $param);
800 $record->$field($param);
801 }
802 $db->putUserProblem($record) if $changed;
803 }
804 }
805 }
806 }
807
808 # Delete all problems marked for deletion
809 foreach my $problemID ($r->param('deleteProblem')) {
810 $db->deleteGlobalProblem($setID, $problemID);
811 }
812 827
813 # Sets the specified header to "" so that the default file will get used. 828 # Sets the specified header to "" so that the default file will get used.
814 foreach my $header ($r->param('defaultHeader')) { 829 foreach my $header ($r->param('defaultHeader')) {
815 $setRecord->$header(""); 830 $setRecord->$header("");
816 }
817
818 # Mark the specified problems as correct for all users
819 foreach my $problemID ($r->param('markCorrect')) {
820 my @userProblemIDs = map { [$_, $setID, $problemID] } ($forUsers ? @editForUser : $db->listProblemUsers($setID, $problemID));
821 my @userProblemRecords = $db->getUserProblems(@userProblemIDs);
822 foreach my $record (@userProblemRecords) {
823 if (defined $record && ($record->status eq "" || $record->status < 1)) {
824 $record->status(1);
825 $record->attempted(1);
826 $db->putUserProblem($record);
827 }
828 }
829 } 831 }
830 } 832 }
831 833
832# Leftover code from when there were up/down buttons 834# Leftover code from when there were up/down buttons
833 835

Legend:
Removed from v.3720  
changed lines
  Added in v.3721

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9