Php 帐户搜索通配符-SugarCRM
我正在寻找一种在SugarCRM中搜索帐户时进行通配符搜索的方法,但我在让查询正常工作时遇到了问题 下面是build\u generic\u where\u子句()函数:Php 帐户搜索通配符-SugarCRM,php,mysql,sugarcrm,Php,Mysql,Sugarcrm,我正在寻找一种在SugarCRM中搜索帐户时进行通配符搜索的方法,但我在让查询正常工作时遇到了问题 下面是build\u generic\u where\u子句()函数: function build_generic_where_clause ($the_query_string) { $where_clauses = Array(); $the_query_string = $this->db->quote($the_query_string); array
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\u push($where\u子句,“accounts.name,比如“%$the\u query\u string%”)
以在\u query \u字符串的任一侧包含百分号
下面是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);
}
}
注意,我添加日志文件write只是为了捕获$this->where。如果我使用搜索框查找诸如“Newbold”和“New York Design”之类的帐户,结果只会得到“Newbold”,并且我的日志文件会显示
(accounts.name如“New%”)
。所以第一个百分号不知怎么被删除了,我相信processSearchForm()在某个地方。很难确定是这样还是罪犯在别处。我发现这段代码有点复杂,到处都是,但这是我唯一需要做的定制。任何帮助都将不胜感激 您应该能够在不更改任何代码的情况下执行此操作。当您从Accounts list视图进行搜索时,只需将通配符添加到表单中的搜索中即可。将“%$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
}
您解决过这个问题吗?我希望做同样的事情。