function _CourseList::sort_most_recent_first

4.x _CourseList.php _CourseList::sort_most_recent_first($bool_maintain_alpha_order = true)
5.x _CourseList.php _CourseList::sort_most_recent_first($bool_maintain_alpha_order = true)

This method will sort by the most recently taken courses (determined by the term_id). The easiest way I can think to do this is to temporarily put their term_id's and index#'s into an array, and then have PHP sort the array itself. PHP's sorting algorithm is faster than anything I can program right now, anyway.

Parameters

bool $bool_maintain_alpha_order:

File

classes/_CourseList.php, line 836

Class

_CourseList

Code

function sort_most_recent_first($bool_maintain_alpha_order = true) 
 {
  $tarray = array();


  // Since I need the indexes, I will have to go through the array
  // myself...
  for ($t = 0; $t < $this->count; $t++) 
   {
    $c = $this->array_list [$t];
    $cn = "";
    if ($bool_maintain_alpha_order == true) 
     {
      // 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
      // a small display issue where PHYS 207 and PHYS 209, taken at
      // the same time, causes PHYS 209 to be displayed first.
      // 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...

      $cn = strrev($c->subject_id) . "," . (1000 - $c->course_num);

    }
    $str = "$c->term_id ~~ $cn ~~ $t";

    array_push($tarray, $str);
  }

  // Now, sort the array...
  rsort($tarray);

  // Now, convert the array back into a list of courses.
  $new_list = new CourseList();
  for ($t = 0; $t < count($tarray); $t++) 
   {
    $temp = explode(" ~~ ", $tarray [$t]);
    $i = $temp [2];

    $new_list->add($this->array_list [$i]);
  }

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

}