Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions config/vufind/Folio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,42 @@ in_transit[] = "Open - Awaiting delivery"
; the system will attempt to reconcile the global page size config there with the
; available options defined here.
page_size[] = 50
; Sort options
;sort[dueDate/sort.ascending] = sort_due_date_asc
;sort[dueDate/sort.descending] = sort_due_date_desc

; Sort options available in the "Checked Out Items" screen.
; These will be passed through to the FOLIO API as sortby parameters
; unless configured as a key in the vufind_sort option to be used
; to sort the items after they are returned from the API.
;
; This should be filled out as: sort[FOLIO_SORTBY_PARAM] or sort[VUFIND_SORT_KEY]
; with the value being the display label.
; For example to use FOLIO API sort, sort[itemId/sort.ascending] will pass
; the value 'itemId/sort.ascending' to the sortby parameter of the FOLIO API.
; To use the VuFind sort, sort[title] will check the vufind_sort[] for a key of title
; and sort by that option's value.
;
; Note: When choosing a FOLIO sort parameter, ensure that you choose
; field(s) that will return the records in a consistent order so that
; when paginating you will get all of the records in the same order for
; every page of results without possibly having duplicates appear or missing items.
; For example, using just dueDate will cause problems if there are more than
; your page_size of items due on the same day since the order is not guaranteed to be
; the same for non-unqiue values.
Comment thread
demiankatz marked this conversation as resolved.
Outdated
sort[dueDate/sort.ascending itemId/sort.ascending] = sort_due_date_asc
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it a conscious choice to uncomment the previously commented-out defaults?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. That was unintentional. I just pushed a commit to undo that change.

sort[dueDate/sort.descending itemId/sort.ascending] = sort_due_date_desc
;sort[title] = sort_title

; This optional setting sorts the results using a natural sort algorithm on the
; specified field of the VuFind checked out items output, which can be useful when FOLIO's
; native sort does not allow sorting on the desired field.
; If used, the key here should match the key used in the sort[] option and the value should
; be the field within the check out items output to sort by.
; For example, if you have sort[title] = sort_title then you could set vufind_sort[title] = "title"
; to create a sort option by the "title" field with a display label of sort_title.
; See the getMyTransactions function for a full list of the available fields.
;vufind_sort[title] = "title"

; Default sort (note: this must be defined in the sort[] options above to be applied!)
;default_sort=dueDate/sort.ascending
default_sort="dueDate/sort.ascending itemId/sort.ascending"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.


[CourseReserves]
; If set to true, the course number will be prefixed on the course name; if false,
Expand Down
27 changes: 18 additions & 9 deletions module/VuFind/src/VuFind/ILS/Driver/Folio.php
Original file line number Diff line number Diff line change
Expand Up @@ -1136,27 +1136,27 @@ protected function formatHoldingItem(
}

/**
* Given a holdings array and a sort field, sort the array.
* Given an array and a sort field, sort the array.
*
* @param array $holdings Holdings to sort
* @param array $data Array to sort
* @param string $sortField Sort field
*
* @return array
*/
protected function sortHoldings(array $holdings, string $sortField): array
protected function sortArray(array $data, string $sortField): array
Comment thread
demiankatz marked this conversation as resolved.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we do this anywhere else? If so, I wonder if a trait would make sense. But I didn't check, so maybe that's a premature suggestion. :-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't anywhere else in the code that currently does a strnatcasecmp. We have other sorting functions, but not ones that are sorting associative arrays based on a specific column (at least that I could find in my searching). I lean towards not making a trait until we have another use for it, but I could be convinced otherwise.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, no sense in overengineering this prematurely. I just thought there might be another similar function somewhere else. Thanks for confirming that there is not! :-)

{
usort(
$holdings,
$data,
function ($a, $b) use ($sortField) {
return strnatcasecmp($a[$sortField], $b[$sortField]);
}
);
// Renumber the re-sorted batch:
$nbCount = count($holdings);
$nbCount = count($data);
for ($nbIndex = 0; $nbIndex < $nbCount; $nbIndex++) {
$holdings[$nbIndex]['number'] = $nbIndex + 1;
$data[$nbIndex]['number'] = $nbIndex + 1;
}
return $holdings;
return $data;
}

/**
Expand Down Expand Up @@ -1273,7 +1273,7 @@ protected function processInstanceHoldings($bibId, $holdings, $folioItems)
$items = array_merge(
$items,
$sortNeeded
? $this->sortHoldings($nextBatch, $vufindItemSort) : $nextBatch
? $this->sortArray($nextBatch, $vufindItemSort) : $nextBatch
Comment thread
demiankatz marked this conversation as resolved.
Outdated
);
}

Expand Down Expand Up @@ -1828,9 +1828,13 @@ public function getMyTransactions($patron, $params = [])
{
$limit = $params['limit'] ?? 1000;
$offset = isset($params['page']) ? ($params['page'] - 1) * $limit : 0;
$vufindSortMap = $this->config['Loans']['vufind_sort'] ?? [];
$requestedSort = $params['sort'] ?? '';
$localSortField = $vufindSortMap[$requestedSort] ?? null;

$query = 'userId==' . $patron['id'] . ' and status.name==Open';
if (isset($params['sort'])) {
// Only pass sort to API if it is NOT handled locally by VuFind
if (!empty($requestedSort) && !$localSortField) {
$query .= ' sortby ' . $this->escapeCql($params['sort']);
}
$resultPage = $this->getResultPage('/circulation/loans', compact('query'), $offset, $limit);
Expand Down Expand Up @@ -1873,6 +1877,11 @@ public function getMyTransactions($patron, $params = [])
// safer to do a separate lookup to be sure we have the right number!
$count = $this->getResultCount('/circulation/loans', compact('query'));
}
// Add in post-sort if the sort param was used in the vufind_sort config
if ($localSortField) {
$transactions = $this->sortArray($transactions, $localSortField);
}

return ['count' => $count, 'records' => $transactions];
}

Expand Down