This is basically a request for guidance on a conceptual issue.
I've had instances on two different sites where I'd like one view on a page to somehow be aware of what another view has pulled up. The primary purpose is to make sure items don't appear twice on the same page across multiple lists. Here's one example--this is a page on a site which is currently in custom code but is slated to be converted to Drupal 6:
http://thebanner.org/departments/
You have the equivalent of 3 views there. Where the wide image is, there's a query being run to select the latest article that has that size of image assigned to it. Then we go to the left side ... another query to grab the latest five articles that have that smaller size image, not including whatever was pulled in the first query. Then, on the right, we grab the latest 10 articles that haven't already been grabbed in the other two queries.
I am at a loss as to how to set something like this up in Drupal. I love the fact that the current setup requires absolutely no maintenance. I don't have to tell the articles where to go. I know in Drupal I could manually assign each article to its proper list, but I'd really like to avoid that.
It seems what I need is a way for 3 views to maintain a common "NOT IN" list. Is this at all possible? Thanks!
Comments
Comment #1
merlinofchaos commentedCan you pull them all up in the same query? One option is to use basically the same view, but then use the 'offset' to control which slice you get.
View #1 has a size of 1 and offset of 0; view #2 has a size of 10 and an offset of 1. View #3 has a size of 10 and an offset of 11.
Comment #2
ericduran commentedI've had to do this before and here's what I came up with.
The simplest option is what @merlineofchaos mention on the 1st comment, which is probably the simplest and nicest solution if the views are using the same query.
The problem is when two views are using different queries, this is a bit harder because you don't quiet know where the same node might show up or in which order. The solution I implemented for this problem was a function that easily allows static variables to be set and get, (check out ctools_static), now this function would statically cache the nid of the nodes that have already been loaded, also the other views would always take a list of nid to be excluded, the list of the nids to exclude where being retrive from that same static variable allowing every views to add to it and essentially this would guaranteed that all of the views will never contain the same nodes.
Word of caution, I'm still not convince this was the best solution, and it was ok for my implementation because it was only implemented on a couple of views.
Hope this helps.
Comment #3
fastballweb commentedAll helpful, thanks.
No, I don't think I could do this in one query ... I think I'd need to maintain my "NOT IN" list as a variable across 3 subqueries, and you apparently can't do that reliably.
Eric, what you describe makes plenty of sense. But I'm not familiar enough with Views code to understand how you'd actually use your function ... did you actually write a plugin or something like that?
And here's another issue ... how could you be sure the views would evaluate in the order you want them to? I did something like what you describe, except it was just passing a boolean from one view to another. I did it using a PHP views field, setting a variable into $_GLOBALS and reading it out in the other view. (Much more hackish and wouldn't work in this case)
The views were on a Panel page. What I ran into is that they didn't evaluate in the order I wanted them to. I had to place "invisible views" that had no output and only served to set the global variable--these were visually arranged at the bottom of the Panel but were evaluated first. Any way around that?
Comment #4
kars-t commentedHi
I am closing this issue to clean up the issue queue. Feel free to reopen the issue if there is new information and the problem still resides. If not please make sure you close your issues that you don't need any more.
Maybe you can get support from the local user group. Please take a look at this list at groups.drupal.org.