diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index aa26f0b5..0b34d1ad 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -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).
diff --git a/classes/AdvisingScreen.php b/classes/AdvisingScreen.php
index 3c596bdc..173ac1d4 100644
--- a/classes/AdvisingScreen.php
+++ b/classes/AdvisingScreen.php
@@ -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 = " ";
- } else {
+ if ($direction == "asc")
+ {
+ $name_direction = "desc";
+ $fan = " ";
+ } else {
+ $fan = " ";
+ }
+ }
+ else {
$os = "font-weight: bold; text-decoration: none;";
- $fat = " ";
+ if ($direction == "desc")
+ {
+ $term_direction = "asc";
+ $fat = " ";
+ }
+ else {
+ $fat = " ";
+ }
}
/*
@@ -1440,19 +1471,19 @@ function display_toolbox_courses()
$pC .= "
- | " . l(t("Name") . $fan, "advise/popup-toolbox/courses", "order=name¤t_student_id=$csid", array("style" => $ns)) . " |
+ " . l(t("Name") . $fan, "advise/popup-toolbox/courses", "order=name&direction=$name_direction¤t_student_id=$csid", array("style" => $ns)) . " |
Hr |
Gr |
- " . l(t("Term") . $fat, "advise/popup-toolbox/courses", "order=date¤t_student_id=$csid", array("style" => $os)) . " |
+ " . l(t("Term") . $fat, "advise/popup-toolbox/courses", "order=date&direction=$term_direction¤t_student_id=$csid", array("style" => $os)) . " |
Attributes |
";
$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())
diff --git a/classes/CourseList.php b/classes/CourseList.php
index 485c9a3e..510c3790 100644
--- a/classes/CourseList.php
+++ b/classes/CourseList.php
@@ -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();
@@ -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
@@ -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);
@@ -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);
}
diff --git a/tests/Classes/CourseListTest.php b/tests/Classes/CourseListTest.php
index 7895abec..54465b47 100644
--- a/tests/Classes/CourseListTest.php
+++ b/tests/Classes/CourseListTest.php
@@ -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.