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 20 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
90 changes: 86 additions & 4 deletions islandora_solr_config/includes/rss_results.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(
Expand All @@ -191,7 +190,89 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults {
$result['url'] = $base_url;
$result['description'] = t('Aggregated search results of: @query', array('@query' => $query));
$result['langcode'] = NULL;
$result['args'] = array(
$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(url(request_path(), array('absolute' => TRUE)), $next_page);
}

if (isset($page_prev)) {
if ($page_prev > 0) {
$prev_page = array(
'query' => array(
'page' => $page_prev,
)+$page_params,
);
$link_prev = url(url(request_path(), array('absolute' => TRUE)), $prev_page);
}
else {
$link_prev = $link_first;
}
}
$result['args'] = array();
if (isset($link_next)) {
$result['args'][] = array(
'key' => 'link',
'attributes' => array(
'rel' => 'next'),
'value' => $link_next,
'encoded' => TRUE,
);
}
if (isset($link_prev)) {
$result['args'][] = array(
'key' => 'link',
'attributes' => array(
'rel' => 'previous'),
'value' => $link_prev,
'encoded' => TRUE,
);
}
if (isset($link_first)) {
$result['args'][] = array(
'key' => 'link',
'attributes' => array(
'rel' => 'first'),
'value' => $link_first,
'encoded' => TRUE,
);
}
$final_arguments = array(
array(
'key' => 'copyright',
'value' => $rss_channel['copyright']),
Expand All @@ -202,6 +283,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults {
'key' => 'webMaster',
'value' => $rss_channel['webMaster']),
);
$result['args'] = array_merge($result['args'], $final_arguments);
return $result;
}
}