gpt4 book ai didi

php - 帐户搜索通配符 - SugarCRM

转载 作者:行者123 更新时间:2023-11-29 03:39:29 24 4
gpt4 key购买 nike

我正在寻找一种在 SugarCRM 中搜索帐户时进行通配符搜索的方法,但我无法使查询正常工作。

这是 build_generic_where_clause() 函数:

function build_generic_where_clause ($the_query_string) {
$where_clauses = Array();
$the_query_string = $this->db->quote($the_query_string);
array_push($where_clauses, "accounts.name like '%$the_query_string%'");
if (is_numeric($the_query_string)) {
array_push($where_clauses, "accounts.phone_alternate like '%$the_query_string%'");
array_push($where_clauses, "accounts.phone_fax like '%$the_query_string%'");
array_push($where_clauses, "accounts.phone_office like '%$the_query_string%'");
}

$the_where = "";
foreach($where_clauses as $clause)
{
if(!empty($the_where)) $the_where .= " or ";
$the_where .= $clause;
}


$log = fopen('1.txt', "a");
fwrite($log, $the_where . "\n");

return $the_where;
}

我只更改了 array_push($where_clauses, "accounts.name like '%$the_query_string%'"); 以在 the_query_string 的两边包含百分号。

这是来自 view.list.php 的 processSearchForm():

 function processSearchForm(){


if(isset($_REQUEST['query']))
{
// we have a query
if(!empty($_SERVER['HTTP_REFERER']) && preg_match('/action=EditView/', $_SERVER['HTTP_REFERER'])) { // from EditView cancel
$this->searchForm->populateFromArray($this->storeQuery->query);
}
else {
$this->searchForm->populateFromRequest();
}

$where_clauses = $this->searchForm->generateSearchWhere(true, $this->seed->module_dir);

if (count($where_clauses) > 0 )$this->where = '('. implode(' ) AND ( ', $where_clauses) . ')';
$GLOBALS['log']->info("List View Where Clause: $this->where");

$log = fopen('1.txt', "a");
fwrite($log, $this->where . "\n");

}
if($this->use_old_search){
switch($view) {
case 'basic_search':
$this->searchForm->setup();
$this->searchForm->displayBasic($this->headers);
break;
case 'advanced_search':
$this->searchForm->setup();
$this->searchForm->displayAdvanced($this->headers);
break;
case 'saved_views':
echo $this->searchForm->displaySavedViews($this->listViewDefs, $this->lv, $this->headers);
break;
}
}else{
echo $this->searchForm->display($this->headers);
}
}

请注意,我只添加了日志文件写入以捕获 $this->where。如果我使用搜索框查找诸如“Newbold”和“New York Design”之类的帐户,结果只会得到“Newbold”并且我的日志文件显示为 (accounts.name like 'new%') 。所以第一个百分号正在以某种方式被删除,我相信某处的 processSearchForm() 。很难弄清楚情况是否如此,或者罪魁祸首是否在其他地方。我发现这段代码有点复杂而且到处都是,但这是我需要完成的唯一定制。任何帮助将不胜感激。

最佳答案

您应该能够在不更改任何代码的情况下执行此操作。当您从帐户 ListView 中搜索时,只需将通配符添加到表单中的搜索中即可。在搜索表单中输入“%$the_query_string%”。

如果您想以编程方式使用通配符来搜索记录,您可以执行如下操作。

<?php

$filter = 'ABC%'; // account names that start with 'ABC'
$account = BeanFactory::getBean('Accounts');
$accounts = $account->get_list("", "accounts.name like '".$filter."'");

foreach ($accounts['list'] as $account)
{
// do something with $account
}

get_list() 将提取您需要的内容。需要注意的一件事是,get_list() 只会返回 ListView 要返回的记录数。因此,如果您的 ListView 仅显示 20 条记录,get_list() 将返回最多 20 条记录。如果您想获得所有结果,请使用 get_full_list()。

关于php - 帐户搜索通配符 - SugarCRM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16179743/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com