开发者

Iterative modification of a Drupal View

开发者 https://www.devze.com 2023-02-20 03:47 出处:网络
Currently I have a view with an exposed form to input a numeric param used in a views filter (a distance, used in proximity search). I would like to modify this system to no longer be exposed, but to

Currently I have a view with an exposed form to input a numeric param used in a views filter (a distance, used in proximity search). I would like to modify this system to no longer be exposed, but to start at e.g. 10 (miles) and if the view result doesn't contain enough of one kind of node, repeat the view with a larger search distance until I get the result I want, then render the view.

This is Views 2, location, Drupal 6.

Seems like hook_views_pre_render(&$view) is the place to put my code to check on what has been returned by the view, and alter the view accordingly, but I don't know if or how I should call the view again from the top with the modified $view.

UPDATE: Looks like in hook_views_pre_rend开发者_开发技巧er, if a pager is used, you only get the nodes that are displaying on the current page. I need to be able to see the entire set and reorder it. Or at least if there is no node of type A be able to look down the list and promote one of A into the current page.


What you want to do is to order the results by distance, ascending, then limit the output to ## results. (The SQL should show ORDER BY distance ASC LIMIT ##)

You can use granularity with the ordering if you really want to emulate your description but this seems to be what you are looking for and will be a lot quicker on the engine too.


For this kind of very custom request, I'd probably simply make a small module with a page that took everything from input boxes as arguments instead of filters. I'd grab the query from the views interface (so I didn't have to figure it out myself) and change it into a SELECT COUNT(*) type query, and then write some simple code in a loop - checking the result, and if it's suitably large, exiting the loop and then using those parameters for building the view. This should save you a lot of time compared to trying to figure out how to do it with all the various options in the views builder widgets.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号