function GroupList::sort_priority

7.x GroupList.php GroupList::sort_priority()
6.x GroupList.php GroupList::sort_priority()

Sort this list of groups by their priority number. Higher priorities appear at the top of the list.

This will allow negative numbers (thanks to user oantby (Logan Bluth) from Morningside. The original function is z__sort_priority(), which is left in the code in case it is needed.

File

classes/GroupList.php, line 333

Class

GroupList

Code

function sort_priority() {
  /*
      Sort this list of groups by their priority number.
      Higher priorities should appear at the
      top of the list.
    */
  $tarray = array();


  for ($t = 0; $t < count($this->array_list); $t++) 
   {
    $g = $this->array_list [$t];
    $g->load_descriptive_data();
    $pri = "" . intval($g->priority) . "";
    $str = "$pri ~~ $t";

    array_push($tarray, $str);
  }

  // We use SORT_NUMERIC so that negative numbers may be used.
  rsort($tarray, SORT_NUMERIC);


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


}