The attached patch, which is quite amateur, implements the ability to specify a negative depth as an option to the Taxonomy Term filter. This will result in the filter traversing up the tree to parents and grandparents, instead of down the tree to children and grandchildren.

It has some issues obvious to me while writing it, mostly due to my inexperience with drupal in general and the views api in particular.
The way I built the queries (a simple modification of the original to join children instead of parents) results in duplicate rows in the result. I can't see a reason not to use SELECT DISTINCT for views node searches in general, but that is outside the scope of this patch so I simply added a dumb GROUP BY to the query when using this filter. This can certainly be improved upon.
I duplicated the entire traversal loop in both the OR and AND portions of the filter. Having two nearly identical copies of the loop in the first place was wasteful of code size, my increasing it to four is even worse. Simplification may be in order here.

Since it already came up on IRC, I will mention that the use case here is for company memos at my place of business. We have a memos section, categorized by a company location heirarchy, with an Exposed filter for that category. We want users to be able to see memos for their location (usually an office) as well as parent locations (their city, state, and country, as 3 different levels above them). Without this patch the only solution we came up with was to use a multiple heirarchy built upside down, very hackish.

Comments

moshe weitzman’s picture

I know of use cases for this. Sometimes, content should "flow down" instead of flow up. For example, imagine a hierarchy like

florida
-- tampa
-- miami

an the rule is that when you look at miami, you should see content that is in the florida term too. thus, to post to an audience of all of florida, you can just post in the florida term ... organic groups could use a similar capability.

sparr’s picture

Status: Needs work » Needs review
StatusFileSize
new2.93 KB

An updated patch, possibly worthy of some attention at this point. I learned quite a bit more from merlinofchaos about the Views API this morning. I have gotten rid of the stupid GROUP BY and put a conditional set_distinct() at the top of the function. I also cut the joins in half (see http://drupal.org/node/102716) and corrected some comments.

mcreature’s picture

Subscribing

csc4’s picture

This looks very useful - is it likely to be committed soon?

sparr’s picture

This patch affects some voodoo-like portions of the Views code. I have been told that before it can be committed it needs a lot of testing. I would appreciate comments on it [not] working on as many different configurations as possible, the stranger views the better.

merlinofchaos’s picture

We do still need some testingon this patch. It is still under consideration for Views 1.7.

emdalton’s picture

If it goes into views 1.7, will it also apply to 5.x? If there's a 5.x version, I can help test....

merlinofchaos’s picture

Version: 4.7.x-1.3 » 5.x-1.6

Actually, it will in fact probably only go into the Drupal 5 version, as I'm no longer adding new features to the 4.7 release unless they're basically all done for me.

sparr’s picture

Status: Needs review » Closed (fixed)

long past the chance of getting into 5, and views2 for 6 might have this feature built in. closing to keep the queue clean.

socialnicheguru’s picture

does this work in 5? I am looking for this type of functionality and am not sure if it exsists anywhere. i can't find any documentiaton.

Chris

summit’s picture

Subscribing, greetings, Martijn