Skip to content

Commit

Permalink
Custom sort order for section dropdown.
Browse files Browse the repository at this point in the history
See #113.
  • Loading branch information
boonebgorges committed May 2, 2018
1 parent 8cd72d2 commit c4f129a
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions classes/Server/Question/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,54 @@ public function get_filter_options( $filter ) {
break;
}

// Custom sort for sections.
if ( 'section' === $filter ) {
$semesters = array();
foreach ( $options as $option ) {
$parts = explode( '-', $option['name'] );
if ( 3 > count( $parts ) ) {
$semester = 'S10';
} else {
$semester = $parts[1];
}

$semesters[ $semester ][] = $option;
}

uksort( $semesters, function( $a, $b ) {
$term_a = substr( $a, 0, 1 );
$term_b = substr( $b, 0, 1 );

$year_a = substr( $a, 1 );
$year_b = substr( $b, 1 );

if ( $year_a === $year_b ) {
if ( 'F' === $a ) {
return 1;
} else {
return -1;
}
} else {
return $year_a < $year_b ? 1 : -1;
}

return 0;
} );

$options = array();
foreach ( $semesters as &$sections ) {
usort( $sections, function( $a, $b ) {
if ( $a['name'] === $b['name'] ) {
return 0;
}

return $a['name'] > $b['name'] ? 1 : -1;
} );

$options = array_merge( $options, $sections );
}
}

return $options;
}
}

0 comments on commit c4f129a

Please sign in to comment.