Hi,

I need to provide a Previous/Next capability within search results.. To make it even more complicated, the results are created by the faceted_search module and displayed in a Views view.

I don't think the module does this at the moment, and would probably require an API from Views to retrieve an ordered list of nodes from that view. However, in the chance that I am complicating a simple matter, I would value some input.

João Ventura

CommentFileSizeAuthor
#5 original.patch11.13 KBmugginsoft.net
#1 prev_next_views.patch4.41 KBjcnventura
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jcnventura’s picture

Status: Active » Needs review
FileSize
4.41 KB

Hi,

Here is my first attempt at doing something out of this. I was unable to find out how to alter Views' UI, so I added the settings to a tab in the prev_next module's settings.

For the configured Views, the list of results will be stored in the user session, and the prev_next_nid call will provide results from that list instead of the simpler nodes list as provided by the prev_next module. I've added a hook_prev_next_nid() that can be used by this and other sub-modules to provide a more appropriate prev/next chain according to their logic. If there are no sub-modules or they can't find a better chain, by returning FALSE, the original is used instead.

Some words of caution:
- The entire results list is stored in the session. In my case, these lists are never >1000, but storing thousands of nids there may not be desired by others.
- Storing the Views result in the session is done during the Views display, but the module can only handle one list. If multiple enabled views are displayed at the same time, they will overwrite each other's results list. The stored results will belong to the view that is generated last.

João

kbahey’s picture

Joao

I worked with you before on the adsense module, and like your work, and the way you work.

I granted you CVS access to the prev_next module. Feel free to commit this patch.

Jax’s picture

I'm not sure if this is the best approach. Storing data like this in the session doesn't seem like a good idea and can often lead to unpredictable results. Also it means that your page can no longer be cached.

Node views are always based on a node so you could provide an option in the configuration screen to index on a view in stead of content types. You could also dynamically generate a prev_next tracking table per view.

jcnventura’s picture

Status: Needs review » Needs work

@kbahey: thanks for the permissions. I've just committed the above patch to CVS. Something is better than nothing, and at least it will make it easier for others who want this functionality.

@Jax: Indeed, the prev_next for views creates several problems for cached pages.. Take into account that Views (with arguments, etc.) can be highly dependent on the user that is currently viewing the site. I thought about storing the info in a table for the view, but this would have to be associated with the user session also, and be cleared when the session is cleared. By placing the info in the session, that problem is automatically fixed. I think that the only solution for the page cache is to have some Javascript that stores the info in the user's browser during the View generation, and then re-write the prev/next links (which the cached version will store as content-type links), to match the last view..

mugginsoft.net’s picture

FileSize
11.13 KB

prev_next_views implements highly desirable functionality however it is rather fragile and may fail if a page causes nodes in addition to the view data node to be loaded (seeing a non view node the module assumes that we have navigated away from our view data and deletes the session key).

The attached patch caches all node ids as they are loaded and only deletes the session data in hook_exit if a matching node is not found.

In addition the patch implements a more fully featured view node pager which includes configurable first , prev, next and last node links. A current position indicator is also included as is a link back to the original view (this works with view arguments and exposed filters).

function prev_next_pager(&$node, $pager_options) has been added to prev_next.module. This calls hook_prev_next_pager which is implemented in prev_next_views.module.

A view node pager is created like so.

  // get the prev/next module view node pager.
  // define view to be paged in prev next views nodule
  $pager_options = array('first'=> array('text' =>'« first'), 
  					     'prev'=>  array('text' =>'‹ previous'), 
  					     'current'=> array(), 
  					     'next'=>  array('text' =>'next ›'),  
  					     'last'=>  array('text' =>'last »'),
                         'view_url' =>  array('text' => '« back to search')
  ); 					     
  $pager = prev_next_pager($node, $pager_options);
  $vars['prev_next_pager'] = $pager;

I usually insert it in a preprocess function but it could be inserted in hook_nodeapi $op=view in the way that the print module links are - though that would change the module from being purely an api.

The patch also defines two theme functions:

 function theme_prev_next_views_node($node, $link_text); 
function theme_prev_next_views_pager($pager); 

The first enables theming of individual node links.
The second manages theming of the entire pager.

rutiolma’s picture

muggin code work really great.
The module by it self doesn't work well with active cache, and with this patch work like a charm.

This should be integrated in the module.

lavms’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Component: Code » Documentation
Category: feature » support
Status: Needs work » Active

Hi,

I have a view with few exposed filters. When a user performs a search, it will display a set of images as per the search criteria and each image is linked to it's content. If a user clicks on an image, it will direct the user to the corresponding content page but I need to let the user to go back to search results or to navigate to previous/next search items from there.

Can this be done using this module with the suggested patch by mugginsoft.net? It would be great if someone can assist me to achieve this.

I'm fairly new to Drupal and any help would be very much appreciated.

Thank you.
lavms

GaëlG’s picture

Issue summary: View changes

Views navigation is an answer to that.

  • jcnventura committed 84d19cf on 7.x-2.x
    Fix #662362 by jcnventura: Previous/Next for a Views list
    
    
bhosmer’s picture

Status: Active » Closed (fixed)

Feel free to reopen if needed.