Paging results from a repository search

Paging results from a repository search

by Akinsaya Delamarre -
Number of replies: 2

I'm working on developing a repository plug-in for Moodle 2.x and trying to figure out how to manage displaying and paging search results.

Here is the workflow at a high - mid level...

- A user click on the search link at the top of the file picker.

- Enters a search term

- The search term returns many results

-- In the search(), you setup your return structure and page data (page, pages, total, perpage)

-- The function returns with more than 1 page of data

This is where I'm puzzled... the user clicks on the page 2 link in the file picker.  The plug-in search() function is called again, however the original search term is not passed as an argument.  If search results can be paged, how do we figure out what the original search term is when the user click on one of the page links?

Also, the search form that I created has multiple search criteria in addition to the default keyword search.  So it's important that I can keep track of the search options the user has selected when flipping through pages.

One way around this it to store the search term in the user's session variable.  However I'm wondering if there is a 'best practice' way?

Average of ratings: -
In reply to Akinsaya Delamarre

Re: Paging results from a repository search

by Liam Moran -

Did you solve this problem? I've run into what I think is something similar.

When I scroll down in my custom repository, Moodle is correctly making the second API call (I can see it on the remote server), but the response is not rendering to the filepicker.

I see an error in Firebug from filepicker.js: TypeError: pathbefore is undefined

The odd thing is that pathbefore only is accessed once, right after it's declared and a value assigned.

In reply to Liam Moran

Re: Paging results from a repository search

by Liam Moran -

The problem I had here was that I had included a 'path' array element in the array returned from get_listing--must be vestigial from an older version, because it wasn't doing any work.

In any case, when you don't provide a 'path' named element, the obj.path compared in filepicker.js's request_next_page method is undefined and so the 'same repository check' code never runs, which is where that error was being thrown.

Liam