This commit is contained in:
Paula Quispe
2018-01-15 14:41:21 -04:00
committed by Fabio Guachalla
parent c94fc85a4a
commit 3805b1c2c0
3 changed files with 140 additions and 15 deletions

View File

@@ -54,13 +54,71 @@ trait SuggestTrait
$where = $isWhere ? "WHERE " . $col . "='" . $dv . "'" : $where . " AND " . $col . "='" . $dv . "'";
}
}
if (isset($json->queryField) && isset($dt[0]["base_expr"])) {
$col = isset($dt[1]["base_expr"]) ? $dt[1]["base_expr"] : $dt[0]["base_expr"];
$qf = str_replace("'", "''", $json->queryFilter);
$where = $isWhere ? "WHERE " . $col . " LIKE '%" . $qf . "%'" : $where . " AND " . $col . " LIKE '%" . $qf . "%'";
if (isset($json->querySearch) && is_array($json->querySearch) && !empty($json->querySearch)) {
$dataSearch = $json->querySearch;
$sqlWildcard = "";
//We will to search term in the query
if (isset($dataSearch['term'])) {
$value = isset($dataSearch['term']['value']) ? $dataSearch['term']['value'] : '';
$label = isset($dataSearch['term']['text']) ? $dataSearch['term']['text'] : '';
$sqlWildcard = "%";
}
//The match has priority
//We will to search match in the query
if (isset($dataSearch['match'])) {
$value = isset($dataSearch['match']['value']) ? $dataSearch['match']['value'] : '';
$label = isset($dataSearch['match']['text']) ? $dataSearch['match']['text'] : '';
$sqlWildcard = "";
}
if (!empty($value) && !empty($label)){
//We need to search in the firstColumn and secondColumn
//Ex: SELECT COL1, COL2 FROM TABLE WHERE COL1 LIKE 'querySearch' OR COL2 LIKE 'querySearch'
//Ex: SELECT COL1, COL2 FROM TABLE WHERE COL1 LIKE '%querySearch%' OR COL2 LIKE '%querySearch%'
$col1 = $dt[0]["base_expr"];
$col2 = isset($dt[1]["base_expr"]) ? $dt[1]["base_expr"] : $dt[0]["base_expr"];
$qfValue = str_replace("'", "''", $value);
$qfLabel = str_replace("'", "''", $label);
$search = $col1 . " LIKE '" . $sqlWildcard . $qfValue . $sqlWildcard . "' OR " . $col2 . " LIKE '" . $sqlWildcard . $qfLabel . $sqlWildcard . "'";
$where = $isWhere ? "WHERE " . $search : $where . " AND (" . $search . ")";
} else {
$valueOrLabel = '';
$column = $dt[0]["base_expr"];
if (!empty($value)) {
//We need to search in the firstColumn
//Ex: SELECT COL1, COL2 FROM TABLE WHERE COL1 LIKE 'querySearch'
//Ex: SELECT COL1, COL2 FROM TABLE WHERE COL1 LIKE '%querySearch%'
$valueOrLabel = $value;
}
if (!empty($label)) {
//We need to search in the secondColumn
//Ex: SELECT COL1, COL2 FROM TABLE WHERE COL2 LIKE 'querySearch'
//Ex: SELECT COL1, COL2 FROM TABLE WHERE COL2 LIKE '%querySearch%'
$column = isset($dt[1]["base_expr"]) ? $dt[1]["base_expr"] : $column;
$valueOrLabel = $label;
}
$where = $this->buildWhere(
$column,
$valueOrLabel,
$sqlWildcard,
$isWhere,
$where
);
}
} else {
//If the property querySearch does not exist we need to search in the secondColumn
//Ex: SELECT COL1, COL2 FROM TABLE WHERE COL2 LIKE '%queryFilter%'
if (isset($json->queryField) && isset($dt[0]["base_expr"])) {
$where = $this->buildWhere(
isset($dt[1]["base_expr"]) ? $dt[1]["base_expr"] : $dt[0]["base_expr"],
$json->queryFilter,
"%",
$isWhere,
$where
);
}
}
if ($optionsLimit > 0) {
if ($optionsLimit >= 0) {
$this->addSuggestLimit($json, $select, $limit, $where);
} else {
$this->addSuggestWhere($json, $parsed, $select, $where, $having);
@@ -69,6 +127,26 @@ trait SuggestTrait
);
}
/**
* This function will be define the WHERE clause
*
* @param string $col, name of column
* @param string $value, value to search in the column
* @param string $sqlWildcard, if we to search term or correct match
* @param boolean $isWhere, if the we need to concat other condition
* @param string $where, initial where to add the concat
*
* @return string
*
*/
private function buildWhere($col, $value, $sqlWildcard = "", $isWhere = false, $where = "")
{
$qf = str_replace("'", "''", $value);
$searchValue = $col . " LIKE '" . $sqlWildcard . $qf . $sqlWildcard;
$where = ($isWhere) ? "WHERE " . $searchValue . "'" : $where . " AND " . $searchValue . "'";
return $where;
}
/**
* Add the limit sentence to the suggest query.
*

View File

@@ -758,6 +758,7 @@ class Variable
$dynUid = $params["dyn_uid"];
$fieldId = $params["field_id"];
$filter = isset($params["filter"]) ? $params["filter"] : "";
$query = isset($params["query"]) ? $params["query"] : [];
$start = isset($params["start"]) ? $params["start"] : 0;
$limit = isset($params["limit"]) ? $params["limit"] : 10;
$appUid = empty($params["app_uid"]) ? null : $params["app_uid"];
@@ -767,6 +768,7 @@ class Variable
unset($params["app_uid"]);
unset($params["del_index"]);
unset($params["filter"]);
unset($params["query"]);
unset($params["start"]);
unset($params["limit"]);
@@ -799,6 +801,7 @@ class Variable
$field->queryFilter = $filter;
$field->queryStart = $start;
$field->queryLimit = $limit;
$field->querySearch = $query;
//Grids only access the global variables of 'ProcessMaker', other variables are removed.
//The property 'columnWidth' is only present in the controls of a grid,
//in the current change there is no specific property that indicates