Skip to content

Commit

Permalink
Merge pull request #2273 from drgrice1/bugfix/jitar-forusers-no-probl…
Browse files Browse the repository at this point in the history
…em-record

Fix issue #2272.
  • Loading branch information
pstaabp authored Jan 8, 2024
2 parents 59998c6 + c70ae20 commit 218f485
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -852,20 +852,17 @@ sub fieldHTML ($c, $userID, $setID, $problemID, $globalRecord, $userRecord, $fie
my @uVals;
my @bVals;
for my $f (split(/:/, $field)) {
# Hmm. This directly references the data in the record rather than calling the access method, thereby
# avoiding errors if the access method is undefined. That seems a bit suspect, but it's used below so we'll
# leave it here.
push(@gVals, $globalRecord->{$f});
push(@uVals, $userRecord->{$f});
push(@gVals, $globalRecord->can($f) ? $globalRecord->$f : undef);
push(@uVals, $userRecord && $userRecord->can($f) ? $userRecord->$f : undef);
push(@bVals, '');
}
# I don't like this, but combining multiple values is a bit messy
$globalValue = (grep {defined} @gVals) ? join(':', (map { defined ? $_ : '' } @gVals)) : undef;
$userValue = (grep {defined} @uVals) ? join(':', (map { defined ? $_ : '' } @uVals)) : undef;
$blankfield = join(':', @bVals);
} else {
$globalValue = $globalRecord->{$field};
$userValue = $userRecord->{$field};
$globalValue = $globalRecord->can($field) ? $globalRecord->$field : undef;
$userValue = $userRecord && $userRecord->can($field) ? $userRecord->$field : undef;
}

# Use defined instead of value in order to allow 0 to printed, e.g. for the 'value' field.
Expand Down Expand Up @@ -956,11 +953,17 @@ sub fieldHTML ($c, $userID, $setID, $problemID, $globalRecord, $userRecord, $fie
my @fields = split(/:/, $field);
my @part_values;
for (@fields) {
push(@part_values, $forUsers && $userRecord->$_ ne '' ? $userRecord->$_ : $globalRecord->$_);
push(@part_values,
($forUsers && $userRecord && $userRecord->can($_) && $userRecord->$_ ne '')
? $userRecord->$_
: $globalRecord->$_);
}
$value = join(':', @part_values);
} elsif (!$value) {
$value = ($forUsers && $userRecord->$field ne '' ? $userRecord->$field : $globalRecord->$field);
$value =
($forUsers && $userRecord && $userRecord->can($field) && $userRecord->$field ne '')
? $userRecord->$field
: $globalRecord->$field;
}

$inputType = $c->select_field(
Expand Down

0 comments on commit 218f485

Please sign in to comment.