function _CourseList::sort_smallest_hours_first

4.x _CourseList.php _CourseList::sort_smallest_hours_first()
5.x _CourseList.php _CourseList::sort_smallest_hours_first()

This will sort so that courses with the smallest hours (first trying hours_awarded, then min_hours) are at the top of the list. If the list contains more than one course with a set of hours (like there are 30 courses all worth 3 hours) then it orders those as most-recently-taken first.

File

classes/_CourseList.php, line 784

Class

_CourseList

Code

function sort_smallest_hours_first() 
 {

  $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];
    $hours = $c->hours_awarded * 1;
    if ($hours < 1) 
     {
      $hours = $c->min_hours * 1;
    }
    $str = "$hours ~~ $t";
    array_push($tarray, $str);
  }

  // Now, sort the array...
  //print_pre(print_r($tarray));
  sort($tarray);
  //print_pre(print_r($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 [1];

    $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;


}