Skip to content
Snippets Groups Projects
Commit 674da89d authored by André Lahmann's avatar André Lahmann
Browse files

refs #8731:

* implemented method to allow sorting for items in FincILS item views
parent bf34b8b6
Branches
Tags instance/fid_adlr/staging/20210902_131729
No related merge requests found
......@@ -676,6 +676,62 @@ class FincILS extends PAIA implements LoggerAwareInterface
* Finc-ILS specific methods
*********************************************/
/**
* Sorts given array items in the given sortOrder using the given array
* fieldName. If the array contains elements without the given fieldName those
* elements will get appended unsorted to the sorted array elements.
* Sorting is done by asort() if sortOrder==SORT_ASC and arsort() if
* sortOrder==SORT_DESC.
*
* @param array $items Array containing the items to be sorted
* @param string $fieldName Fieldname whose content will be used for sorting
* @param mixed $sortOrder The order used to sort the item array. Either
* SORT_ASC to sort ascendingly or SORT_DESC to sort
* descendingly (defaults to SORT_ASC).
* @return array
*/
protected function itemFieldSort ($items, $fieldName, $sortOrder = SORT_ASC)
{
// array with items to be sorted
$sortArray = [];
// array with items that do not contain the sort key
$noSortArray = [];
// returned array with all items
$returnArray = [];
if (count($items) && !empty($fieldName)) {
for ($i=0; $i<count($items); $i++) {
if (isset($items[$i][$fieldName])) {
$sortArray[$i]=$items[$i][$fieldName];
} else {
array_push($noSortArray, $items[$i]);
}
}
// sort according to given sortOrder
switch ($sortOrder) {
case SORT_DESC:
arsort($sortArray);
break;
case SORT_ASC:
default:
asort($sortArray);
break;
}
// recombine all items
$sortArray = $sortArray + $noSortArray;
// build the return array with sorted items
foreach ($sortArray as $key => $item) {
$returnArray[] = $items[$key];
}
return $returnArray;
}
return $items;
}
/**
* finc-specific function to count items/entries in return values of given
* functions in order to be shown as numbers in MyReSearch-Menu
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment