function _CourseList::sort_substitutions_first

4.x _CourseList.php _CourseList::sort_substitutions_first($list_substitutions, $group_id = 0)
5.x _CourseList.php _CourseList::sort_substitutions_first($list_substitutions, $group_id = 0)

This function will resort this courselist for which a substitution has been made in listSubstitutions.

Parameters

SubstitutionList $list_substitutions:

int $group_id:

File

classes/_CourseList.php, line 726

Class

_CourseList

Code

function sort_substitutions_first($list_substitutions, $group_id = 0) 
 {
  // This will sort courses in a list for which
  // a substitution has been made in listSubstitutions.
  // It will place those courses at the top of the list.

  $top_array = 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];
    // So-- does this course have a substitution somewhere in
    // the list (for the supplied groupID) ?
    if ($substitution = $list_substitutions->find_requirement($c, true, $group_id)) 
     {
      // yes, there is a sub for this group (or bare degree plan)
      $top_array [] = $t;
    }

  }

  // Okay, we now have, in the topArray, a list of indexes which should
  // appear at the top.
  $new_list = new CourseList();
  for ($j = 0; $j < count($top_array); $j++) 
   {
    $new_list->add($this->array_list [$top_array [$j]]);
  }

  // Now, add everything else in the array (except indecies
  // appearing in topArray)

  for ($t = 0; $t < $this->count; $t++) 
   {
    if (in_array($t, $top_array)) 
     {
      continue;
    }
    $new_list->add($this->array_list [$t]);
  }

  $this->array_list = $new_list->array_list;
  $new_list->reset_counter();

}