function _CourseList::sort_alphabetical_order

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.

new_split_subs_higher_priority_in_degree_id:

  • If the course is a split substitution for the supplied degree_id, then give it a higher "priority" so it will sort above courses with identical names.
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 1345

Class

_CourseList

Code

function 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) 
 {
  // 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();
    }


    $priority = 5; // default sort priority for courses with identical names.
    if ($subs_higher_prority_in_degree_id > 0) {
      if (@$c->details_by_degree_array [$subs_higher_prority_in_degree_id]["bool_substitution_new_from_split"] == TRUE
       || @$c->details_by_degree_array [$subs_higher_prority_in_degree_id]["bool_substitution_split"] == TRUE
         || @$c->details_by_degree_array [$subs_higher_prority_in_degree_id]["bool_substitution"] == TRUE) {
        //fpm("here for $c->subject_id $c->course_num");
        $priority = 3; // lower priority so it sorts higher in the list.
      }
    }


    // Make $t at least 5 characters long, padded with zeroes on the left, so sorting works correctly.  We are using it to
    // find out our index later, but it is throwing off the sorting when courses have the same name.  For example,
    // if a course is from a split sub.
    $tpad = str_pad("$t", 5, "0", STR_PAD_LEFT);

    $degree_title = "n"; // Default.
    $degree_advising_weight = "0000";

    if ($bool_include_degree_sort) {
      // Find the actual degree title for this course.
      if (intval($c->req_by_degree_id) > 0) {
        // Get the degree title...         
        $dtitle = @$GLOBALS ["fp_temp_degree_titles"][$c->req_by_degree_id];
        $dweight = intval(@$GLOBALS ["fp_temp_degree_advising_weights"][$c->req_by_degree_id]);

        if ($dtitle == "" || $dweight == "" || $dweight == 0) {
          $t_degree_plan = new DegreePlan($c->req_by_degree_id);
          $t_degree_plan->load_descriptive_data();
          $dtitle = $t_degree_plan->get_title2(TRUE, TRUE);
          $dweight = $t_degree_plan->db_advising_weight;
          $GLOBALS ["fp_temp_degree_titles"][$c->req_by_degree_id] = $dtitle . " "; //save for next time.
          $GLOBALS ["fp_temp_degree_advising_weights"][$c->req_by_degree_id] = $dweight . " "; //save for next time.
        }

        $degree_title = fp_get_machine_readable($dtitle); // make it machine readable.  No funny characters.
        $degree_advising_weight = str_pad($dweight, 4, "0", STR_PAD_LEFT);
      }
    }


    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 = $degree_advising_weight . " ~~ " . $degree_title . " ~~ " . $c->course_transfer->subject_id . " ~~ " . $c->course_transfer->course_num . " ~~ $priority ~~ $tpad";
      }
      else {
        // There was no transfer!
        $str = "$degree_advising_weight ~~ $degree_title ~~ $c->subject_id ~~ $c->course_num ~~ $priority ~~ $tpad";
      }
    }
    else {

      // This is the one which will be run most often.  Just sort the list
      // in alphabetical order.

      $str = "$degree_advising_weight ~~ $degree_title ~~ $c->subject_id ~~ $c->course_num ~~ $priority ~~ $tpad";
    }
    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 = intval($temp [5]);

    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;

}