function _GroupList::z__sort_priority

5.x _GroupList.php _GroupList::z__sort_priority()

File

classes/_GroupList.php, line 374

Class

_GroupList

Code

function z__sort_priority() 
 {
  /*
			Sort this list of groups by their priority number.
			Higher priorities should appear at the
			top of the list.
		*/
  $tarray = array();
  // Since I need the indexes, I will have to go through the array
  // myself...
  for ($t = 0; $t < count($this->array_list); $t++) 
   {
    $g = $this->array_list [$t];
    $g->load_descriptive_data();
    $pri = "" . ($g->priority * 1) . "";
    if (strlen($pri) == 1) 
     {
      $pri = "0" . $pri; // padd with 0 on the front.
      // This fixes a sorting problem, because priorities
      // were being evaluated as text, not nums, so "5" seemed
      // larger than "15"  (because it was comparing the 5 to the 1).
    }
    $str = "$pri ~~ $t";

    array_push($tarray, $str);
  }


  rsort($tarray);

  // Now, convert the array back into a list of groups.
  $new_list = new GroupList();
  for ($t = 0; $t < count($tarray); $t++) 
   {
    $temp = explode(" ~~ ", $tarray [$t]);
    $i = $temp [1];

    $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;


}