Drupal 视图中公开过滤器的自定义逻辑
我正在开发一个 Drupal 网站,希望得到一些关于这方面的建议。目前,用户输入他的多种不同技能的等级。它存储在 CCK 整数字段中,并作为包含键/值对 1|Beginner、2|Intermediate、3|Advanced 的下拉小部件向用户公开。
在视图中,我公开了每个技能的允许值,这些值以复选框的形式呈现给用户(使用“更好的公开过滤器”模块),然后在可排序的表中列出。在实践中,用户通常会搜索“在技能 Y 上至少具有 X 知识水平”的人。是否有模块或简单的方法将允许的值显示为下拉列表并在查询中使用“大于”运算符而不是“其中之一”?
任何有关如何动态更改过滤器逻辑或查询的 WHERE 子句的示例代码或建议将非常感激。
I'm working on a Drupal site and would love some advice on this. Currently, a user enters his level for a number of different skills. This is stored in a CCK integer field and exposed to the user as a drop-down widget containing the key/value pairs 1|Beginner, 2|Intermediate, 3|Advanced.
In a view, I expose the allowed values for each skill, which are presented to the user as checkboxes (using the Better Exposed Filters module) and then listed in a sortable table. In practice, users generally search for people who have "at least knowledge level X in skill Y". Is there a module or straightforward way to display the allowed values as a drop-down and use a "greater than" operator in the query instead of a "one of"?
Any sample code or advice on how to dynamically change the filter logic or the WHERE clause of the query would be very appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想使用 hook_views_query_alter(),而我没有专门更改 WHERE 子句,我修改了 SORTBY 子句,两者背后的想法应该相对相似。
这是一段快速的代码:
这段特定的代码允许您使用查询字符串 (?condition=condition1) 更改 WHERE 子句,但您可以更改它以获取您希望的参数。
希望这有帮助。
You want to use hook_views_query_alter(), while I haven't specifically altered the WHERE clause, I have altered the SORTBY clause and the idea behind both should be relatively similar.
Here's a quick piece of code:
This particular piece would allow you to alter the WHERE clause using a querystring (?condition=condition1), but you could alter it to get the arguments however you wish.
Hope this helps.
使用 Decipher 的示例并花费几个小时阅读和使用,我得到了一个完全满足我的需求的基本模块。再次感谢!
如果其他人遇到类似的需求,这是我的代码:
Using Decipher's sample and spending a few hours reading up and playing around, I've gotten a basic module that works perfectly for my needs. Thanks again!
Here's my code if anyone else comes across a similar need: