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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | views_taxonomy.inc.uptraversal.patch.txt | 2.93 KB | sparr |
| views_taxonomy.inc.uptraversal.20061211082100.patch.txt | 3.36 KB | sparr |
Comments
Comment #1
moshe weitzman commentedI 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.
Comment #2
sparr commentedAn 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.
Comment #3
mcreature commentedSubscribing
Comment #4
csc4 commentedThis looks very useful - is it likely to be committed soon?
Comment #5
sparr commentedThis 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.
Comment #6
merlinofchaos commentedWe do still need some testingon this patch. It is still under consideration for Views 1.7.
Comment #7
emdalton commentedIf it goes into views 1.7, will it also apply to 5.x? If there's a 5.x version, I can help test....
Comment #8
merlinofchaos commentedActually, 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.
Comment #9
sparr commentedlong past the chance of getting into 5, and views2 for 6 might have this feature built in. closing to keep the queue clean.
Comment #10
socialnicheguru commenteddoes 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
Comment #11
summit commentedSubscribing, greetings, Martijn