function _CourseList::sort_fulfilled_first_alphabetical

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

This re-sorts the CourseList so that fulfilled courses are first, in alphabetical order, followed by unfulfilled courses, in alphabetical order. This is most useful for making the groups show up correctly.

File

classes/_CourseList.php, line 593

Class

_CourseList

Code

function sort_fulfilled_first_alphabetical() 
 {

  $tarray = array();
  for ($t = 0; $t < $this->count; $t++) 
   {
    //if (!is_object($this->array_list[$t]->courseFulfilledBy))
    if ($this->array_list [$t]->course_list_fulfilled_by->is_empty == true) 
     { // Skip if not fulfilled.
      continue;
    }

    $c = $this->array_list [$t];
    $str = "$c->subject_id ~~ $c->course_num ~~ $t";
    array_push($tarray, $str);
  }

  sort($tarray);

  $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]);
  }


  // Alright, now we do it again, but with unfulfilled courses.
  $tarray = array();
  for ($t = 0; $t < $this->count; $t++) 
   {
    //if (is_object($this->array_list[$t]->courseFulfilledBy))
    if ($this->array_list [$t]->course_list_fulfilled_by->is_empty != true) 
     { // Skip if fulfilled.
      continue;
    }

    $c = $this->array_list [$t];
    $str = "$c->subject_id ~~ $c->course_num ~~ $t";
    array_push($tarray, $str);
  }

  sort($tarray);

  $new_list2 = new CourseList();
  for ($t = 0; $t < count($tarray); $t++) 
   {
    $temp = explode(" ~~ ", $tarray [$t]);
    $i = $temp [2];

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

  // Now, combine the two lists.
  $new_list->add_list($new_list2);

  // And, transfer the newList into this list.
  $this->array_list = $new_list->array_list;


}