| … | |
… | |
| 127 | |
127 | |
| 128 | use strict; |
128 | use strict; |
| 129 | use warnings; |
129 | use warnings; |
| 130 | use Carp; |
130 | use Carp; |
| 131 | use Data::Dumper; |
131 | use Data::Dumper; |
|
|
132 | use WeBWorK::Timing; |
| 132 | use WeBWorK::Utils qw(runtime_use); |
133 | use WeBWorK::Utils qw(runtime_use); |
| 133 | |
134 | |
| 134 | ################################################################################ |
135 | ################################################################################ |
| 135 | # constructor |
136 | # constructor |
| 136 | ################################################################################ |
137 | ################################################################################ |
| … | |
… | |
| 1102 | } |
1103 | } |
| 1103 | |
1104 | |
| 1104 | sub getMergedSet { |
1105 | sub getMergedSet { |
| 1105 | my ($self, $userID, $setID) = @_; |
1106 | my ($self, $userID, $setID) = @_; |
| 1106 | |
1107 | |
|
|
1108 | #my $timer = WeBWorK::Timing->new("getMergedSet"); |
|
|
1109 | |
| 1107 | croak "getGlobalUserSet: requires 2 arguments" |
1110 | croak "getGlobalUserSet: requires 2 arguments" |
| 1108 | unless @_ == 3; |
1111 | unless @_ == 3; |
| 1109 | croak "getGlobalUserSet: argument 1 must contain a user_id" |
1112 | croak "getGlobalUserSet: argument 1 must contain a user_id" |
| 1110 | unless defined $userID; |
1113 | unless defined $userID; |
| 1111 | croak "getGlobalUserSet: argument 2 must contain a set_id" |
1114 | croak "getGlobalUserSet: argument 2 must contain a set_id" |
| 1112 | unless defined $setID; |
1115 | unless defined $setID; |
| 1113 | |
1116 | |
|
|
1117 | #$timer->start; |
| 1114 | my $UserSet = $self->getUserSet($userID, $setID); |
1118 | my $UserSet = $self->getUserSet($userID, $setID); |
|
|
1119 | #$timer->continue("got user set"); |
| 1115 | return unless $UserSet; |
1120 | return unless $UserSet; |
| 1116 | my $GlobalSet = $self->getGlobalSet($setID); |
1121 | my $GlobalSet = $self->getGlobalSet($setID); |
|
|
1122 | #$timer->continue("got global set"); |
| 1117 | if ($GlobalSet) { |
1123 | if ($GlobalSet) { |
| 1118 | foreach ($UserSet->FIELDS()) { |
1124 | foreach ($UserSet->FIELDS()) { |
| 1119 | next unless $GlobalSet->can($_); |
1125 | next unless $GlobalSet->can($_); |
| 1120 | next if $UserSet->$_(); |
1126 | next if $UserSet->$_(); |
| 1121 | $UserSet->$_($GlobalSet->$_()); |
1127 | $UserSet->$_($GlobalSet->$_()); |
| 1122 | } |
1128 | } |
| 1123 | } |
1129 | } |
|
|
1130 | #$timer->continue("merged records"); |
|
|
1131 | #$timer->stop; |
| 1124 | return $UserSet; |
1132 | return $UserSet; |
| 1125 | } |
1133 | } |
| 1126 | |
1134 | |
| 1127 | ################################################################################ |
1135 | ################################################################################ |
| 1128 | # problem+problem_user functions |
1136 | # problem+problem_user functions |
| … | |
… | |
| 1133 | return shift->getMergedProblem(@_); |
1141 | return shift->getMergedProblem(@_); |
| 1134 | } |
1142 | } |
| 1135 | |
1143 | |
| 1136 | sub getMergedProblem { |
1144 | sub getMergedProblem { |
| 1137 | my ($self, $userID, $setID, $problemID) = @_; |
1145 | my ($self, $userID, $setID, $problemID) = @_; |
|
|
1146 | |
|
|
1147 | #my $timer = WeBWorK::Timing->new("getMergedSet"); |
| 1138 | |
1148 | |
| 1139 | croak "getGlobalUserSet: requires 3 arguments" |
1149 | croak "getGlobalUserSet: requires 3 arguments" |
| 1140 | unless @_ == 4; |
1150 | unless @_ == 4; |
| 1141 | croak "getGlobalUserSet: argument 1 must contain a user_id" |
1151 | croak "getGlobalUserSet: argument 1 must contain a user_id" |
| 1142 | unless defined $userID; |
1152 | unless defined $userID; |
| 1143 | croak "getGlobalUserSet: argument 2 must contain a set_id" |
1153 | croak "getGlobalUserSet: argument 2 must contain a set_id" |
| 1144 | unless defined $setID; |
1154 | unless defined $setID; |
| 1145 | croak "getGlobalUserSet: argument 3 must contain a problem_id" |
1155 | croak "getGlobalUserSet: argument 3 must contain a problem_id" |
| 1146 | unless defined $problemID; |
1156 | unless defined $problemID; |
| 1147 | |
1157 | |
|
|
1158 | #$timer->start; |
| 1148 | my $UserProblem = $self->getUserProblem($userID, $setID, $problemID); |
1159 | my $UserProblem = $self->getUserProblem($userID, $setID, $problemID); |
|
|
1160 | #$timer->continue("got user problem"); |
| 1149 | return unless $UserProblem; |
1161 | return unless $UserProblem; |
| 1150 | my $GlobalProblem = $self->getGlobalProblem($setID, $problemID); |
1162 | my $GlobalProblem = $self->getGlobalProblem($setID, $problemID); |
|
|
1163 | #$timer->continue("got global problem"); |
| 1151 | if ($GlobalProblem) { |
1164 | if ($GlobalProblem) { |
| 1152 | foreach ($UserProblem->FIELDS()) { |
1165 | foreach ($UserProblem->FIELDS()) { |
| 1153 | next unless $GlobalProblem->can($_); |
1166 | next unless $GlobalProblem->can($_); |
| 1154 | next if $UserProblem->$_(); |
1167 | next if $UserProblem->$_(); |
| 1155 | $UserProblem->$_($GlobalProblem->$_()); |
1168 | $UserProblem->$_($GlobalProblem->$_()); |
| 1156 | } |
1169 | } |
| 1157 | } |
1170 | } |
|
|
1171 | #$timer->continue("merged records"); |
|
|
1172 | #$timer->stop; |
| 1158 | return $UserProblem; |
1173 | return $UserProblem; |
| 1159 | } |
1174 | } |
| 1160 | |
1175 | |
| 1161 | ################################################################################ |
1176 | ################################################################################ |
| 1162 | # debugging |
1177 | # debugging |
| … | |
… | |
| 1172 | ################################################################################ |
1187 | ################################################################################ |
| 1173 | |
1188 | |
| 1174 | sub checkKeyfields($) { |
1189 | sub checkKeyfields($) { |
| 1175 | my ($Record) = @_; |
1190 | my ($Record) = @_; |
| 1176 | foreach my $keyfield ($Record->KEYFIELDS) { |
1191 | foreach my $keyfield ($Record->KEYFIELDS) { |
| 1177 | croak "checkKeyfields: invalid character in $keyfield field (valid characters are [A-Za-z0-9_])" |
1192 | my $value = $Record->$keyfield; |
| 1178 | unless $Record->$keyfield =~ m/^\w*$/; |
1193 | croak "checkKeyfields: $keyfield is empty" |
|
|
1194 | unless defined $value and $value ne ""; |
|
|
1195 | |
|
|
1196 | if ($keyfield eq "problem_id") { |
|
|
1197 | croak "checkKeyfields: invalid characters in $keyfield field: $value (valid characters are [0-9])" |
|
|
1198 | unless $value =~ m/^\d*$/; |
|
|
1199 | } else { |
|
|
1200 | croak "checkKeyfields: invalid characters in $keyfield field: $value (valid characters are [A-Za-z0-9_])" |
|
|
1201 | unless $value =~ m/^\w*$/; |
|
|
1202 | } |
| 1179 | } |
1203 | } |
| 1180 | } |
1204 | } |
| 1181 | |
1205 | |
| 1182 | =head1 AUTHOR |
1206 | =head1 AUTHOR |
| 1183 | |
1207 | |