예제 #1
0
 /**
  * Changes the rank of a custom field
  *
  * @access  public
  */
 function changeRank()
 {
     $fld_id = $_REQUEST['id'];
     $direction = $_REQUEST['direction'];
     // get array of all fields and current ranks
     $fields = Custom_Field::getList();
     for ($i = 0; $i < count($fields); $i++) {
         if ($fields[$i]['fld_id'] == $fld_id) {
             // this is the field we want to mess with
             if ($i == 0 && $direction == -1 || $i + 1 == count($fields) && $direction == +1) {
                 // trying to move first entry lower or last entry higher will not work
                 break;
             }
             $target_index = $i + $direction;
             $target_row = $fields[$target_index];
             if (empty($target_row)) {
                 break;
             }
             // update this entry
             Custom_Field::setRank($fld_id, $target_row['fld_rank']);
             // update field we stole this rank from
             Custom_Field::setRank($target_row['fld_id'], $fields[$i]['fld_rank']);
         }
     }
     // re-order everything starting from 1
     $fields = Custom_Field::getList();
     $rank = 1;
     foreach ($fields as $field) {
         Custom_Field::setRank($field['fld_id'], $rank++);
     }
     return 1;
 }