function CourseList::sort_smallest_hours_first

7.x CourseList.php CourseList::sort_smallest_hours_first()
6.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 1138

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->get_hours_awarded();
    if (floatval($hours) == 0) 
     {
      $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;


}