mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-28 23:03:25 +09:00
괄호 추가
This commit is contained in:
parent
55651a006a
commit
56921fa9be
1 changed files with 25 additions and 4 deletions
|
|
@ -239,7 +239,7 @@ class VariableBase
|
|||
case 'search':
|
||||
$parsed_keywords = $this->_parseSearchKeywords($value);
|
||||
$where = $parsed_keywords[0];
|
||||
$params = $parsed_keywords[1];
|
||||
$params = array_merge($params, $parsed_keywords[1]);
|
||||
break;
|
||||
case 'plus':
|
||||
$where = sprintf('%s = %s + %s', $column, $column, $is_expression ? $value : '?');
|
||||
|
|
@ -438,13 +438,27 @@ class VariableBase
|
|||
*/
|
||||
private function _parseSearchKeywords($value)
|
||||
{
|
||||
// parse the value (text)
|
||||
$keywords = preg_split('/("[^"]*")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE);
|
||||
$conditions = array();
|
||||
// Initialze the return values.
|
||||
$where = '';
|
||||
$params = array();
|
||||
|
||||
// parse the value (text)
|
||||
$keywords = preg_split('/(\([^\)]*\))|("[^"]*")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE);
|
||||
$conditions = array();
|
||||
$operators = array('AND', 'OR', '|');
|
||||
// loop the parsed keywords or operators
|
||||
foreach ($keywords as $item)
|
||||
{
|
||||
// treat parenthesis
|
||||
if (strlen($item) > 2 && substr($item, 0, 1) === '(' && substr($item, -1) === ')')
|
||||
{
|
||||
$parsed_keywords = $this->_parseSearchKeywords(substr($item, 1, -1));
|
||||
$conditions[] = "(". $parsed_keywords[0] . ")";
|
||||
$conditions[] = 'AND';
|
||||
$params = array_merge($params, $parsed_keywords[1]);
|
||||
continue;
|
||||
}
|
||||
|
||||
// trim quotation mark
|
||||
if (strlen($item) > 2 && (substr($item, 0, 1) === substr($item, -1)) && substr($item, -1) === '"')
|
||||
{
|
||||
|
|
@ -468,6 +482,13 @@ class VariableBase
|
|||
{
|
||||
$item = 'OR';
|
||||
}
|
||||
// remove the last point (would be an operator)
|
||||
$last_condition = array_pop($conditions);
|
||||
// the last condition might not be an operator.
|
||||
if (!in_array($last_condition, $operators))
|
||||
{
|
||||
$conditions[] = $last_condition;
|
||||
}
|
||||
$conditions[] = sprintf('%s', $item);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue