Skip to content

Commit

Permalink
feedback from PR#2266
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Jordan committed Dec 1, 2023
1 parent 32da067 commit 90891a4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 39 deletions.
75 changes: 37 additions & 38 deletions lib/WeBWorK/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ our @EXPORT_OK = qw(
runtime_use
sortAchievements
sortByName
prob_id_sort
surePathToFile
textDateTime
timeToSec
Expand All @@ -121,6 +120,7 @@ our @EXPORT_OK = qw(
is_jitar_problem_closed
jitar_problem_adjusted_status
jitar_problem_finished
prob_id_sort
role_and_above
fetchEmailRecipients
processEmailMessage
Expand Down Expand Up @@ -1257,43 +1257,6 @@ sub sortAchievements {

}

################################################################################
# Sorts problem ID's so that all just-in-time like ids are at the bottom
# of the list in order and other problems
################################################################################
sub prob_id_sort_comparator {

my @seqa = split(/\./, $a);
my @seqb = split(/\./, $b);

# go through problem number sequence
for (my $i = 0; $i <= $#seqa; $i++) {
# if at some point two numbers are different return the comparison.
# e.g. 2.1.3 vs 1.2.6
if ($seqa[$i] != $seqb[$i]) {
return $seqa[$i] <=> $seqb[$i];
}

# if all of the values are equal but b is shorter then it comes first
# i.e. 2.1.3 vs 2.1
if ($i == $#seqb) {
return 1;
}
}

# if all of the values are equal and a and b are the same length then equal
# otherwise a was shorter than b so a comes first.
if ($#seqa == $#seqb) {
return 0;
} else {
return -1;
}
}

sub prob_id_sort {
return sort prob_id_sort_comparator @_;
}

################################################################################
# Validate strings and labels
################################################################################
Expand Down Expand Up @@ -1887,6 +1850,42 @@ ID: foreach my $id (@problemIDs) {
return 1;
}

# Sorts problem ID's so that all just-in-time like ids are at the bottom
# of the list in order and other problems

sub prob_id_sort_comparator {

my @seqa = split(/\./, $a);
my @seqb = split(/\./, $b);

# go through problem number sequence
for (my $i = 0; $i <= $#seqa; $i++) {
# if at some point two numbers are different return the comparison.
# e.g. 2.1.3 vs 1.2.6
if ($seqa[$i] != $seqb[$i]) {
return $seqa[$i] <=> $seqb[$i];
}

# if all of the values are equal but b is shorter then it comes first
# i.e. 2.1.3 vs 2.1
if ($i == $#seqb) {
return 1;
}
}

# if all of the values are equal and a and b are the same length then equal
# otherwise a was shorter than b so a comes first.
if ($#seqa == $#seqb) {
return 0;
} else {
return -1;
}
}

sub prob_id_sort {
return sort prob_id_sort_comparator @_;
}

# Get the array of all permission levels at or above a given level
sub role_and_above {
my ($userRoles, $role) = @_;
Expand Down
2 changes: 1 addition & 1 deletion lib/WeBWorK/Utils/FilterRecords.pm
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ sub getFiltersForClass {
for my $role (sortByName(undef, keys %roles)) {
my @statuses = keys %{ $c->ce->{statuses} };
for (@statuses) {
push @filters, [ "Role: $_" => "status:$role" ] if ($c->ce->{statuses}{$_}{abbrevs}[0] eq $role);
push @filters, [ "Enrollment Status: $_" => "status:$role" ] if ($c->ce->{statuses}{$_}{abbrevs}[0] eq $role);
}
}
}
Expand Down

0 comments on commit 90891a4

Please sign in to comment.