Skip to content

Commit

Permalink
Fixed sorting and grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
ntenisOT committed Jun 19, 2012
1 parent 62925b7 commit 891a836
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions bibtex/BibTex.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function parser( $file = null, $data = null ) {

global $sortby;
//$this->sortedItems = $this->sort_by($this -> items, $sortby, 'type');
$this->sortedItems = @$this->array_multisort_by_order($this->items, 'year', $this->yearData);
$this->sortedItems = @$this->array_multisort_by_order($this->items, 'type', $sortby);

return $this->printPublications();
Expand Down Expand Up @@ -384,21 +385,6 @@ function countTypes($iterator, $type) {
echo "<strong>[".ucfirst(substr($type, 0, 1))."".$number."]</strong> ";
}
}
function sort_by($arr, $sub, $order){
// Create a map from old key to new key
$value_kmap = array_flip($arr[$sub]);
$sort_kmap = array_flip($order);
foreach($order as $value)
$kmap[$value_kmap[$value]] = $sort_kmap[$value];

// Create your result array
foreach($arr as $name => $sub_arr)
foreach($kmap as $key => $new_key)
if(isset($sub_arr[$key]))
$result[$name][$new_key] = $sub_arr[$key];

return $result;
}
/**
* @param array $array
* @param string|int $by key/offset
Expand Down

0 comments on commit 891a836

Please sign in to comment.