Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
FlightPath 7.x Changelog
========================

2026-11-07
Modified the Administrator's Toolbox's Courses tab, so that Name and Term are sortable
and then reverse-sortable.

Added function CourseList to sort courses by most recent LAST instead of most
recent first.


2026-11-05
Added default favicon.ico to the root of the project, for browsers and crawlers that are
expecting it (and generating 404's if not found at the root).
Expand Down
51 changes: 41 additions & 10 deletions classes/AdvisingScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -1419,13 +1419,44 @@ function display_toolbox_courses()
$csid = @$_REQUEST["current_student_id"];
$school_id = db_get_school_id_for_student_id($csid);
$order = @$_REQUEST["order"];
$direction = @$_REQUEST["direction"];
if ($order != "name" && $order != "date")
{
$order = "date";
}
if ($direction != "asc" && $direction != "desc")
{
if ($order == "name")
{
$direction = "asc";
} else {
$direction = "desc";
}
}

$name_direction = "asc";
$term_direction = "desc";
if ($order == "name")
{
$ns = "font-weight: bold; text-decoration: none;";
$fan = " <i class='fa fa-angle-up' style='font-weight:bold;'></i>";
} else {
if ($direction == "asc")
{
$name_direction = "desc";
$fan = " <i class='fa fa-angle-up' style='font-weight:bold;'></i>";
} else {
$fan = " <i class='fa fa-angle-down' style='font-weight:bold;'></i>";
}
}
else {
$os = "font-weight: bold; text-decoration: none;";
$fat = " <i class='fa fa-angle-down' style='font-weight:bold;'></i>";
if ($direction == "desc")
{
$term_direction = "asc";
$fat = " <i class='fa fa-angle-down' style='font-weight:bold;'></i>";
}
else {
$fat = " <i class='fa fa-angle-up' style='font-weight:bold;'></i>";
}
}

/*
Expand All @@ -1440,19 +1471,19 @@ function display_toolbox_courses()
$pC .= "
<table border='0' cellpadding='2' cellspacing='3'>
<tr>
<th colspan='2'>" . l(t("Name") . $fan, "advise/popup-toolbox/courses", "order=name&current_student_id=$csid", array("style" => $ns)) . "</th>
<th colspan='2'>" . l(t("Name") . $fan, "advise/popup-toolbox/courses", "order=name&direction=$name_direction&current_student_id=$csid", array("style" => $ns)) . "</th>
<th>Hr</th>
<th>Gr</th>
<th width=50>" . l(t("Term") . $fat, "advise/popup-toolbox/courses", "order=date&current_student_id=$csid", array("style" => $os)) . "</th>
<th width=50>" . l(t("Term") . $fat, "advise/popup-toolbox/courses", "order=date&direction=$term_direction&current_student_id=$csid", array("style" => $os)) . "</th>
<th>Attributes</th>
</tr>
";
$is_empty = true;
if ($order == "name")
{
$this->student->list_courses_taken->sort_alphabetical_order();
} else {
$this->student->list_courses_taken->sort_most_recent_first();
if ($order == "name") {
$this->student->list_courses_taken->sort_alphabetical_order($direction == "desc");
}
else {
$this->student->list_courses_taken->sort_most_recent_first(TRUE, $direction == "asc");
}
$this->student->list_courses_taken->reset_counter();
while($this->student->list_courses_taken->has_more())
Expand Down
40 changes: 36 additions & 4 deletions classes/CourseList.php
Original file line number Diff line number Diff line change
Expand Up @@ -1218,8 +1218,9 @@ function sort_largest_hours_first() {
* is faster than anything I can program right now, anyway.
*
* @param bool $bool_maintain_alpha_order
* @param bool $bool_oldest_first
*/
function sort_most_recent_first($bool_maintain_alpha_order = true)
function sort_most_recent_first($bool_maintain_alpha_order = TRUE, $bool_oldest_first = FALSE)
{
$tarray = array();

Expand All @@ -1232,6 +1233,8 @@ function sort_most_recent_first($bool_maintain_alpha_order = true)
$cn = "";
if ($bool_maintain_alpha_order == true)
{
/*
Old logic....
// We say 1000- the course number in order to give
// us the complement of the number. That is so it will
// reverse-sort in the correct order. Strange, but it fixes
Expand All @@ -1240,8 +1243,9 @@ function sort_most_recent_first($bool_maintain_alpha_order = true)
// We also reverse the subject_id, again, so that
// MATH will be sorted above ZOOL, when taken at the same time.
// This might not work at all, though...
*/

// TODO: The 1000 - course_num bit doesn't work (throws a warning) if the course_num
// The 1000 - course_num bit doesn't work (throws a warning) if the course_num
// is non-numeric. Ex: 301A. Let's instead use the same strrev() function on course_num, but we put it in quotes
// to guarantee it gets evaluated as a string.
//$cn = strrev($c->subject_id) . "," . (1000 - $c->course_num);
Expand All @@ -1266,19 +1270,47 @@ function sort_most_recent_first($bool_maintain_alpha_order = true)
$new_list->add($this->array_list[$i]);
}

if ($bool_oldest_first == TRUE)
{
$courses_by_term = array();
foreach ($new_list->array_list as $course)
{
$courses_by_term[$course->term_id][] = $course;
}
ksort($courses_by_term);

$new_list->array_list = array();
foreach ($courses_by_term as $courses)
{
foreach ($courses as $course)
{
$new_list->array_list[] = $course;
}
}
}

// Okay, now $new_list should contain the correct values.
// We will transfer over the reference.
$this->array_list = $new_list->array_list;

}


/**
* Convenience function, used to sort the course list by
* most recent (based on term_id) LAST.
*/
function sort_most_recent_last($bool_maintain_alpha_order = TRUE) {
$this->sort_most_recent_first($bool_maintain_alpha_order, TRUE);
}


/**
* Convienence function. It simply calls sort_alphabetical_order(), but
* passes the boolean value to make it be reversed.
*
*/
function sort_reverse_alphabetical_order()
{
function sort_reverse_alphabetical_order() {
$this->sort_alphabetical_order(true);
}

Expand Down
36 changes: 36 additions & 0 deletions tests/Classes/CourseListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,42 @@ public function testSortLargestHoursPlacesGhostHoursLast()
$this->assertSame($ghostHour, $list->get_element(2));
}

/**
* Ensures term sorting supports both newest-first and oldest-first order
* while keeping courses in the same term alphabetical.
*/
public function testSortMostRecentFirstSupportsBothDirections()
{
$list = new CourseList();
$newerCourse = new Course();
$newerCourse->subject_id = "BIOL";
$newerCourse->course_num = "102";
$newerCourse->term_id = 202520;
$olderMath = new Course();
$olderMath->subject_id = "MATH";
$olderMath->course_num = "101";
$olderMath->term_id = 202410;
$olderEnglish = new Course();
$olderEnglish->subject_id = "ENGL";
$olderEnglish->course_num = "101";
$olderEnglish->term_id = 202410;

$list->add($olderMath);
$list->add($newerCourse);
$list->add($olderEnglish);
$list->sort_most_recent_first();

$this->assertSame($newerCourse, $list->get_element(0));
$this->assertSame($olderEnglish, $list->get_element(1));
$this->assertSame($olderMath, $list->get_element(2));

$list->sort_most_recent_first(TRUE, TRUE);

$this->assertSame($olderEnglish, $list->get_element(0));
$this->assertSame($olderMath, $list->get_element(1));
$this->assertSame($newerCourse, $list->get_element(2));
}

/**
* Verifies duplicate cleanup retains the fulfilled instance of a course,
* preserving the record that explains why a requirement is satisfied.
Expand Down
Loading