Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add paging to RSS results #366

Open
wants to merge 24 commits into
base: 7.x
Choose a base branch
from
Open
Changes from 17 commits
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
83 changes: 80 additions & 3 deletions islandora_solr_config/includes/rss_results.inc
Original file line number Diff line number Diff line change
@@ -69,12 +69,11 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults {
// ... and add to items string.
$items .= "$rendered_item\n";
}

// Query search terms:
$query = $islandora_solr_query->solrQuery;

// Get the variables for the <channel> element.
$channel = $this->rssChannel($query);
$channel = $this->rssChannel($query, $docs);
$rss_attributes = array('version' => '2.0');
drupal_alter('islandora_solr_config_rss_root_element_attributes', $rss_attributes, $channel, $items);

@@ -176,7 +175,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults {
* @return array
* variable that holds all values to be rendered into <channel> elements
*/
public function rssChannel($query) {
public function rssChannel($query, $docs) {
// Set variables.
global $base_url;
$rss_channel = variable_get('islandora_solr_config_rss_channel', array(
@@ -191,7 +190,85 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults {
$result['url'] = $base_url;
$result['description'] = t('Aggregated search results of: @query', array('@query' => $query));
$result['langcode'] = NULL;
$feed_url = request_uri();
$page_params = drupal_get_query_parameters();

if (!isset($page_params['page'])) {
$page_number = '0';
}
else {
$page_number = $page_params['page'];
}
if (isset($page_params['page'])) {
$first_params = $page_params;
unset($first_params['page']);
$link_first = url(
request_path(),
array(
'absolute' => TRUE,
'query' => $first_params,
)
);
}
else {
$link_first = $base_url . $feed_url;
bondjimbond marked this conversation as resolved.
Show resolved Hide resolved
}

$page_next = $page_number + 1;
if ($page_number > 0) {
$page_prev = $page_number - 1;
}

$next_page = array(
'query' => array(
'page' => $page_next,
)+$page_params,
);

// Only set Next link if there is a next page.
$rss_limit = variable_get('islandora_solr_config_rss_limit', 50);
jonathangreen marked this conversation as resolved.
Show resolved Hide resolved
if (count($docs) == $rss_limit) {
bondjimbond marked this conversation as resolved.
Show resolved Hide resolved
$link_next = url($base_url . "/" . request_path(), $next_page);
bondjimbond marked this conversation as resolved.
Show resolved Hide resolved
}

if (isset($page_prev)) {
if ($page_prev > 0) {
$prev_page = array(
'query' => array(
'page' => $page_prev,
)+$page_params,
);
$link_prev = url($base_url . "/" . request_path(), $prev_page);
bondjimbond marked this conversation as resolved.
Show resolved Hide resolved
}
else {
$link_prev = $link_first;
}
}
else {
$link_prev = "";
bondjimbond marked this conversation as resolved.
Show resolved Hide resolved
}
$result['args'] = array(
array(
'key' => 'link',
'attributes' => array(
'rel' => 'next'),
'value' => $link_next,
'encoded' => TRUE,
),
array(
'key' => 'link',
'attributes' => array(
'rel' => 'previous'),
'value' => $link_prev,
'encoded' => TRUE,
),
array(
'key' => 'link',
'attributes' => array(
'rel' => 'first'),
'value' => $link_first,
'encoded' => TRUE,
),
array(
'key' => 'copyright',
'value' => $rss_channel['copyright']),