如何在Sugar CE的列表视图,基础搜索,高级搜索中对条件进行硬编码 [英] How to hard code the where condition in list view ,basic search,advance search in sugar CE

查看:86
本文介绍了如何在Sugar CE的列表视图,基础搜索,高级搜索中对条件进行硬编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我也是sugarcrm和zend frame的新手.如果无法理解我的以下问题,请在此处评论.现在我实际上要去查询了.我需要在查询中添加自定义where子句.所以我遵循了这一点,当我使用search或advanced search获取所有值时,它仅适用于常规列表视图.因此如何添加HARD CODE案例模块中的搜索条件和高级搜索

Actually i am new to sugarcrm and zend frame work too .if anything not able to understand my following question means comment here . Now I am go for my query actually .i need to add custom where clause in query .so i followed this one its works only for general list view when i use search or advance search its fetching all values .so how to add HARD CODE the where condition in search and advance search in case module

我不想列出值"where source_c不喜欢'Social media'";在一般的列表视图和搜索以及高级搜索中该如何实现?

i don't want list the value " where source_c not like 'Social media'"; in general list view and search and advance search how to achieve this ?

我的版本是: sugarcrm社区版本6.5.23

我关注了以下链接在列表视图中添加where条件后删除了搜索选项suitecrm/sugarcrm?

所以我将此代码添加到sugar/modules/Cases/views

so i add this code in sugar/modules/Cases/views

view.list.php

    <?php


    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    require_once('include/MVC/View/views/view.list.php');
    // name of class match module
    class CasesViewList extends ViewList{
    // where clause that will be inserted in sql query
    var $where = "source_c not like 'Social media'";   //this is my where clause 
    //var $where = "";

    function CasesViewList()
    {
    parent::ViewList();
    }
    /*
    * Override listViewProcess with addition to where clause to exclude project templates
    */
    function listViewProcess()
    {
    // // // $this->lv->setup($this->seed, 'include/ListView/ListViewGeneric.tpl', $this->where, $this->params);
    // // // echo $this->lv->display();

    $this->processSearchForm(); // for search form 
    $this->lv->searchColumns = $this->searchForm->searchColumns;
    if(!$this->headers)
    return;
    if(empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false){
    $this->lv->ss->assign("SEARCH",true);
    $this->lv->setup($this->seed, 'include/ListView/ListViewGeneric.tpl', $this->where, $this->params); // call the listview's file 
    $savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : (' - ' . $_REQUEST['saved_search_select_name']); // save the last search 
    echo $this->lv->display(); 

    }
    }
    }

    ?>

以上代码仅适用于常规列表视图.我也需要对搜索中的where子句进行硬编码,然后再进行搜索.当我搜索时不需要列出行"where source_c不喜欢'Social media';

above code is working for general list view only . i need to hard code the where clause in search and advance search too . when i search don't need to list row " where source_c not like 'Social media'";

请帮我解决这个问题
谢谢

please help me out this
Thanks advance

推荐答案

在您的/modules/Cases/Case.php中, 覆盖create_new_list_query函数,以便您可以自定义搜索查询.

In your /modules/Cases/Case.php, Override create_new_list_query function so you can customize the search query.

像下面这样的一个:

function create_new_list_query($order_by, $where,$filter=array(),$params=array(), $show_deleted = 0,$join_type='', $return_array = false,$parentbean=null, $singleSelect = false){
        if (isset($_REQUEST['action']) && $_REQUEST['action'] != 'DetailView' && $_REQUEST['module'] == 'Cases') {
            date_default_timezone_set("Asia/Manila");
            //$lvso = (isset($_REQUEST['lvso'])) ? $_REQUEST['lvso'] : 'desc';
            $lvso = 'desc';
            $case_number = (isset($_REQUEST['case_number_basic'])) ? $_REQUEST['case_number_basic'] : '';
            $case_date_from = (isset($_REQUEST['case_date_from_c_basic']) && !empty($_REQUEST['case_date_from_c_basic'])) ? date('Y-m-d', strtotime($_REQUEST['case_date_from_c_basic'])) : '';
            $case_date_to = (isset($_REQUEST['case_date_to_c_basic']) && !empty($_REQUEST['case_date_from_c_basic'])) ? date('Y-m-d', strtotime($_REQUEST['case_date_to_c_basic'])) : '';
            //$case_date_from = (isset($_REQUEST['case_date_from_c_basic']) && !empty($_REQUEST['case_date_from_c_basic'])) ? date('Y-m-d', strtotime(convertTimezoneToUtc($_REQUEST['case_date_from_c_basic']))) : '';
            //$case_date_to = (isset($_REQUEST['case_date_to_c_basic']) && !empty($_REQUEST['case_date_from_c_basic'])) ? date('Y-m-d', strtotime(convertTimezoneToUtc($_REQUEST['case_date_to_c_basic']))) : '';
            $case_subject = (isset($_REQUEST['name_basic'])) ? $_REQUEST['name_basic'] : '';
            $application_id = (isset($_REQUEST['account_id_basic'])) ? $_REQUEST['account_id_basic'] : '';
            $case_current_status_c_basic = (isset($_REQUEST['case_current_status_c_basic'])) ? $_REQUEST['case_current_status_c_basic'] : '';
            $case_source_c_basic = (isset($_REQUEST['case_source_c_basic'])) ? $_REQUEST['case_source_c_basic'][0] : '';
            $assigned_user_id_basic = (isset($_REQUEST['assigned_user_id_basic'])) ? $_REQUEST['assigned_user_id_basic'][0] : '';
            $open_cases_only_basic = (isset($_REQUEST['open_cases_only_basic'])) ? $_REQUEST['open_cases_only_basic'] : '';
            $sdtool_c_basic = (isset($_REQUEST['sdtool_c_basic'])) ? $_REQUEST['sdtool_c_basic'] : '';
            $created_by_basic = (isset($_REQUEST['created_by_basic'])) ? $_REQUEST['created_by_basic'][0] : '';
            $support_type_basic = (isset($_REQUEST['type_basic'])) ? $_REQUEST['type_basic'][0] : '';

            //Build where clause query
            $where_clause = " WHERE ";
            $where_clause .= !empty($case_number) ? "case_number = $case_number AND " : "";
            $where_clause .= !empty($sdtool_c_basic)? "sdtool_c LIKE '%$sdtool_c_basic%' AND " : "";
            $where_clause .= !empty($case_date_from) ? "date(cases.date_entered) >= '$case_date_from' AND " : "";
            $where_clause .= !empty($case_date_to) ? "date(cases.date_entered) <= '$case_date_to' AND " : "";
            $where_clause .= !empty($case_subject) ? "case_subject_c LIKE '%$case_subject%' AND " : "";
            $where_clause .= !empty($application_id) ? "account_id = '$application_id' AND " : "";
            $where_clause .= !empty($case_current_status_c_basic) ? "case_current_status_c LIKE '%$case_current_status_c_basic%' AND " : "";
            $where_clause .= !empty($case_source_c_basic) ? "case_source_c LIKE '%$case_source_c_basic%' AND " : "";
            $where_clause .= !empty($assigned_user_id_basic) ? "cases.assigned_user_id = '$assigned_user_id_basic' AND " : "";
            $where_clause .= (!empty($open_cases_only_basic) && $open_cases_only_basic == 1)? "case_current_status_c <> 'Closed' AND " : "";
            $where_clause .= !empty($created_by_basic) ? "cases.created_by = '$created_by_basic' AND " : "";
            $where_clause .= !empty($support_type_basic) ? "cases.type = '$support_type_basic' AND " : "";

            //Check if conditions are appended
            //$where_clause = (strlen($where_clause) > 7) ? rtrim($where_clause, " AND ") : "";
            $deleted_clause = " cases.deleted = 0 ";
            $where_clause .= $deleted_clause;
            $ret_array["select"] = "SELECT cases.id ,cases_cstm.sdtool_c,cases_cstm.case_subject_c,cases_cstm.case_current_status_c,cases_cstm.case_due_datetime_c,cases_cstm.case_priority_c,cases_cstm.case_source_c, cases_cstm.case_report_due_date_c,
                                           cases.case_number , accounts.name account_name , accounts.assigned_user_id account_name_owner , 'Accounts' account_name_mod, cases.account_id , LTRIM(RTRIM(CONCAT(IFNULL(jt1.first_name,''),' ',
                                           IFNULL(jt1.last_name,'')))) assigned_user_name , jt1.created_by assigned_user_name_owner , 'Users' assigned_user_name_mod , LTRIM(RTRIM(CONCAT(IFNULL(jt2.first_name,''),' ',
                                           IFNULL(jt2.last_name,'')))) created_by_name , jt2.created_by created_by_name_owner , 'Users' created_by_name_mod, cases.date_entered , LTRIM(RTRIM(CONCAT(IFNULL(jt3.first_name,''),' ',
                                           IFNULL(jt3.last_name,'')))) modified_by_name , jt3.created_by modified_by_name_owner , 'Users' modified_by_name_mod, cases.date_modified , cases.assigned_user_id , cases.created_by ";
            $ret_array["from"] = "FROM cases LEFT JOIN cases_cstm ON cases.id = cases_cstm.id_c LEFT JOIN accounts accounts ON cases.account_id=accounts.id AND accounts.deleted=0 AND accounts.deleted=0 
                                    LEFT JOIN users jt1 ON cases.assigned_user_id=jt1.id AND jt1.deleted=0 AND jt1.deleted=0 
                                    LEFT JOIN users jt2 ON cases.created_by=jt2.id AND jt2.deleted=0 AND jt2.deleted=0 
                                    LEFT JOIN users jt3 ON cases.modified_user_id=jt3.id AND jt3.deleted=0 AND jt3.deleted=0";
            $ret_array["from_min"] = " FROM cases";
            $ret_array["secondary_from"] =" FROM cases";
            $ret_array["where"] = $where_clause;
            $ret_array['order_by'] = " ORDER BY case_number $lvso";
            $ret_array['limit'] = "";
            return $ret_array;
        }
        else {
            return parent::create_new_list_query($order_by, $where,$filter,$params, $show_deleted,$join_type, $return_array,$parentbean, $singleSelect);
        }
    }

我亲自创建了这个,所以我知道这是可行的. 谢谢.

I personally created this one so I know that this is working. Thanks.

这篇关于如何在Sugar CE的列表视图,基础搜索,高级搜索中对条件进行硬编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆