function CourseList::sort_substitutions_first
Search API
7.x CourseList.php | CourseList::sort_substitutions_first($list_substitutions, $group_id = 0) |
6.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 1072
Class
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...
// array to keep track of all the substitutions that have been used for this list (Logan's change ticket 2291)
$used_substitution_ids = array();
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) ?
// supply the list of used ids, so they are not reused in this list. (Logan's change ticket 2291)
if ($substitution = $list_substitutions->find_requirement($c, true, $group_id, 0, $used_substitution_ids))
{
// yes, there is a sub for this group (or bare degree plan)
//mark the substitution so it doesn't get used again (Logan's change ticket 2291)
$used_substitution_ids [] = $substitution->db_substitution_id;
$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();
}