简体   繁体   English

Drupal视图的迭代修改

[英]Iterative modification of a Drupal View

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 eg 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. 我想将此系统修改为不再公开,而是从10(英里)开始,如果视图结果中没有足够的一种节点,请以较大的搜索距离重复视图,直到获得我想要的结果,然后渲染视图。

This is Views 2, location, Drupal 6. 这是Views 2,位置,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. 好像hook_views_pre_render(&$ view)是放置我的代码以检查视图返回的内容并相应地更改视图的地方,但是我不知道是否或应该从顶部再次调用该视图修改后的$ view。

UPDATE: Looks like in hook_views_pre_render, if a pager is used, you only get the nodes that are displaying on the current page. 更新:看起来像在hook_views_pre_render中一样,如果使用了分页器,则只会得到当前页面上显示的节点。 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. 或者至少如果没有类型为A的节点,则可以查看列表并将A中的一个提升为当前页面。

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 ## ) (SQL应该显示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. 我从视图界面中抓取了查询(因此我不必自己弄清楚)并将其更改为SELECT COUNT(*)类型的查询,然后在循环中编写一些简单的代码-检查结果,如果大小合适,请退出循环,然后使用这些参数构建视图。 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. 与试图弄清楚如何使用“视图”构建器小部件中的所有各种选项相比,这应该节省大量时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM