【问题标题】:Drupal Views:Add condition in where clause where the value is a field in hook_alter_queryDrupal 视图:在 where 子句中添加条件,其中值是 hook_alter_query 中的字段
【发布时间】:2013-06-06 10:04:16
【问题描述】:

我正在尝试向如下查询添加条件:

civicrm_contact_civicrm_relationship.id civicrm_contact_civicrm_relationship_1.id

但是对于第二个字段,drupal 将它作为一个字符串,所以它总是导致

civicrm_contact_civicrm_relationship.id 'civicrm_contact_civicrm_relationship_1.id'

我尝试使用数值但没有成功。

知道我该怎么做吗?可能是另一个钩子?欢迎任何提示!

我的代码:

        $view->query->where[2]["conditions"][0]["field"] = "civicrm_contact_civicrm_relationship_1.id";
        $view->query->where[2]["conditions"][0]["operator"] = "IS NULL";
        $view->query->where[2]["conditions"][0]["value"] = "";

        $view->query->where[2]["conditions"][1]["field"] = "civicrm_contact_civicrm_relationship.id";
        $view->query->where[2]["conditions"][1]["operator"] = "IS NULL";
        $view->query->where[2]["conditions"][1]["value"] = "";

        $view->query->where[2]["conditions"][2]["field"] = "civicrm_contact_civicrm_relationship.id";
        $view->query->where[2]["conditions"][2]["value"] ="civicrm_contact_civicrm_relationship_1.id";
        $view->query->where[2]["conditions"][2]["numeric"] = "1";
        $view->query->where[2]["conditions"][2]["operator"] = "<>";

        $view->query->where[2]["type"] = "OR";

【问题讨论】:

    标签: drupal drupal-views drupal-hooks civicrm


    【解决方案1】:

    试试类似的东西

        函数 my_hook_views_query_alter(&$view, &$query)
        {
          if ($view->name == 'my_hook') {
            $alias = $query->add_table('civicrm_contact_civicrm_relationship','civicrm_contact_civicrm_relationship_1');
            $query->add_where_expression(0,'civicrm_contact_civicrm_relationship.id  civicrm_contact_civicrm_relationship_1.id');
            dpm($查询); //使用开发模块将对象转储给管理员
          }
        }
        

    【讨论】:

    • 谢谢!!很抱歉回答迟了,但由于解决方案来得有点晚,我有一些事情要完成,然后才能回到这个问题!但它工作得很好!谢谢
    • 我对如何在他的示例底部实现“OR”感兴趣。
    猜你喜欢
    • 2016-12-16
    • 2013-12-23
    • 1970-01-01
    • 2022-12-14
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    • 1970-01-01
    • 2012-07-26
    相关资源
    最近更新 更多