function _CourseList::sort_alphabetical_order
Search API
4.x _CourseList.php | _CourseList::sort_alphabetical_order($bool_reverse_order = false, $bool_only_transfers = false, $bool_set_array_index = false) |
5.x _CourseList.php | _CourseList::sort_alphabetical_order($bool_reverse_order = false, $bool_only_transfers = false, $bool_set_array_index = false, $subs_higher_prority_in_degree_id = 0, $bool_include_degree_sort = FALSE) |
Sorts the course list into alphabetical order. If load_descriptive_data() has not already been called for each course, it will call it.
Parameters
bool $bool_reverse_order:
- If set to TRUE, the list will be in reverse order.
unknown_type $bool_only_transfers:
- Only sort the transfer courses.
unknown_type $bool_set_array_index:
- If set to true, it will set the $course->array_index value to the index value in $this's array_list array.
1 call to _CourseList::sort_alphabetical_order()
- _CourseList::sort_reverse_alphabetical_order in classes/
_CourseList.php - Convienence function. It simply calls sort_alphabetical_order(), but passes the boolean value to make it be reversed.
File
- classes/
_CourseList.php, line 911
Class
Code
function sort_alphabetical_order($bool_reverse_order = false, $bool_only_transfers = false, $bool_set_array_index = false)
{
// Sort the list into alphabetical order, based
// on the subject_id and course_num.
$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];
if ($c->subject_id == "")
{
$c->load_descriptive_data();
}
if ($bool_only_transfers == true)
{
// Rarer. We only want to sort the transfer credits. If the course doesn not
// have transfers, don't skip, just put in the original. Otherwise, we will be using
// the transfer credit's SI and CN.
if (is_object($c->course_transfer))
{
$str = $c->course_transfer->subject_id . " ~~ " . $c->course_transfer->course_num . " ~~ $t";
}
else {
// There was no transfer!
$str = "$c->subject_id ~~ $c->course_num ~~ $t";
}
}
else {
// This is the one which will be run most often. Just sort the list
// in alphabetical order.
$str = "$c->subject_id ~~ $c->course_num ~~ $t";
}
array_push($tarray, $str);
}
// Now, sort the array...
//print_pre(print_r($tarray));
if ($bool_reverse_order == true)
{
rsort($tarray);
}
else {
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 [2];
if ($bool_set_array_index == true)
{
$this->array_list [$i]->array_index = $i;
}
$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;
}