如何覆盖 drupal 视图寻呼机查询?

发布于 2024-12-19 13:39:04 字数 1226 浏览 0 评论 0 原文

我正在使用 drupal 6 和视图 2 -

我使用此文档为我的视图创建了一个自定义过滤器

http://www.chadcf.com/blog/creating-custom-filters-drupal-and-views

每件事似乎都工作正常,只有一个问题 -

我的分页不起作用(某些操作符未出现)

让我简要解释一下我想要实现的目标 -

在我的页面视图中我已经有一些公开的过滤器及其运算符下拉列表,并且我创建了一个自定义的公开过滤器,没有运算符下拉列表。

我的要求是将现有的过滤器功能与我的自定义过滤器合并。意味着两个过滤器将一起工作以获得所需的结果。但是一个过滤器由现有字段组成,如果我从下拉列表中选择它的任何运算符,那么它的值将包含在 where 子句中,这是我不想要的。 完全删除了查询块

hook_views_pre_execute(&$view) {
        $view->build_info['query'] = preg_replace('/AND \(node_data_field_stock.field_stock_value [<<=>>=!=\\s%d|IS NULL|IS NOT NULL]*\)/','',$view->build_info['query']);
      } 

因此,我通过在我的视图查询中使用 Now sites/all/modules/mymodule/inc/mymodule_filter.inc

function query() {
        $this->query->add_where($this->options['group'], "MY_QUERY");   
}

添加了 where 子句来查看查询。

使用上述过程,我成功地扩展了默认视图行为,并获得了所需的结果,但对于某些操作员分页链接,即使我知道数据库中存在更多记录,也没有出现。

我知道为什么会发生 - 因为我的视图分页脚本不知道我所做的更改。

我的问题是如何覆盖查看寻呼机查询?

任何帮助将不胜感激。

I'm using drupal 6 and view 2 -

I've created a custom filter for my view using this documentation

http://www.chadcf.com/blog/creating-custom-filters-drupal-and-views.

Every things seems to working fine only one problem -

My pagination not working (not appearing with some operator)

Let me explain what i want to achieve in brief -

In my page view i already have some exposed filter with their operators dropdown and i created one custom exposed filter without operator drop down.

My requirement is to merge the one existing filter functionality with my custom filter. Means two filter will be working together to get to desired result. But one filter is consist of existing field and if i choose any of it's operator from drop down then it's value is included in where clause, which i don't want. So i completely removed chunk of query from view query by using

hook_views_pre_execute(&$view) {
        $view->build_info['query'] = preg_replace('/AND \(node_data_field_stock.field_stock_value [<<=>>=!=\\s%d|IS NULL|IS NOT NULL]*\)/','',$view->build_info['query']);
      } 

Now in my
sites/all/modules/mymodule/inc/mymodule_filter.inc

function query() {
        $this->query->add_where($this->options['group'], "MY_QUERY");   
}

which add where clause to view query.

Using above procedure i was successfully extended the default view behaviour and also getting the desired result but for some operator pagination link not appearing even i know that there are more records exist in database.

I know why it's happening - because my view pagination script not aware of the changes i've made.

My Question is HOW CAN I OVERRIDE VIEW PAGER QUERY?

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悟红尘 2024-12-26 13:39:04

我正在做的从视图查询中删除 where 子句的操作如下。

hook_views_pre_execute(&$view) {
           $view->build_info['query'] = preg_replace('/AND \(node_data_field_stock.field_stock_value [<<=>>=!=\\s%d|IS NULL|IS NOT NULL]*\)/','',$view->build_info['query']);
    } 

但是,删除要从视图查询中删除的 where 子句的正确位置是 hook_views_query_alter()。通过使用本教程

http:// /www.drupaler.co.uk/blog/altering-views-query-tackling-node-type-filter-bug/451

    function hook_views_query_alter(&$view, &$query) {
        if($view->name == 'view_name'){
            var_dump($query->where[0]['clauses']);
                 foreach ($query->where[0]['clauses'] as $key=>$value) {
                    if(preg_match('/node_data_field_stock.field_stock_value/',$value)){
                        unset($query->where[0]['clauses'][$key]);
                       // remove the where clause by it's key
                    }
                 }

            var_dump($query->where[0]['clauses']);
        }
    }

What i was doing to remove the where clause from view query is below.

hook_views_pre_execute(&$view) {
           $view->build_info['query'] = preg_replace('/AND \(node_data_field_stock.field_stock_value [<<=>>=!=\\s%d|IS NULL|IS NOT NULL]*\)/','',$view->build_info['query']);
    } 

But the proper place to remove the where clause you want to remove from view query is hook_views_query_alter(). By using this tutorial

http://www.drupaler.co.uk/blog/altering-views-query-tackling-node-type-filter-bug/451

    function hook_views_query_alter(&$view, &$query) {
        if($view->name == 'view_name'){
            var_dump($query->where[0]['clauses']);
                 foreach ($query->where[0]['clauses'] as $key=>$value) {
                    if(preg_match('/node_data_field_stock.field_stock_value/',$value)){
                        unset($query->where[0]['clauses'][$key]);
                       // remove the where clause by it's key
                    }
                 }

            var_dump($query->where[0]['clauses']);
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文