...
Code Block | ||
---|---|---|
| ||
private function buildCriterion($advancedCriteria)
{
$criterias = $advancedCriteria['criteria'];
$operator = $advancedCriteria['operator'];
$result = '';
foreach($criterias as $c)
{
if(isset($c['fieldName']))
$fn = $c['fieldName'];
if(isset($c['operator']))
$op = $c['operator'];
if(isset($c['value']))
{
if ($c['value'] === TRUE )
$val = '1';
else if($c['value'] === FALSE)
$val = '0';
else
$val = $c['value'];
}
if(isset($c['start']))
$start = $c['start'];
if(isset($c['end']))
$end = $c['end'];
if(isset($c['criteria']))
$criteria = $c['criteria'];
else
$criteria = null;
if(empty($criteria))
{
switch($op)
{
case 'equals':
$query = "$fn = '$val'";
break;
case 'notEqual':
$query = "$fn != '$val'";
break;
case 'iEquals':
$query = "UPPER($fn) = UPPER('$val')";
break;
case 'iNotEqual':
$query = "UPPER($fn) != UPPER('$val')";
break;
case 'greaterThan':
$query = "$fn > '$val'";
break;
case 'lessThan':
$query = "$fn < '$val'";
break;
case 'greaterOrEqual':
$query = "$fn >= '$val'";
break;
case 'lessOrEqual':
$query = "$fn <= '$val'";
break;
case 'contains':
$query = "$fn LIKE '%$val%'";
break;
case 'startsWith':
$query = "$fn LIKE '$val%'";
break;
case 'endsWith':
$query = "$fn LIKE '%$val'";
break;
case 'iContains':
$query = "UPPER($fn) LIKE UPPER('%$val%')";
break;
case 'iStartsWith':
$query = "UPPER($fn) LIKE UPPER('$val%')";
break;
case 'iEndsWith':
$query = "UPPER($fn) LIKE UPPER('%$val')";
break;
case 'notContains':
$query = "$fn NOT LIKE '%$val%'";
break;
case 'notStartsWith':
$query = "$fn NOT LIKE '$val%'";
break;
case 'notEndsWith':
$query = "$fn NOT LIKE '%$val'";
break;
case 'iNotContains':
$query = "UPPER($fn) NOT LIKE UPPER('%$val%')";
break;
case 'iNotStartsWith':
$query = "UPPER($fn) NOT LIKE UPPER('$val%')";
break;
case 'iNotEndsWith':
$query = "UPPER($fn) NOT LIKE UPPER('%$val')";
break;
case 'isNull':
$query = "$fn IS NULL";
break;
case 'notNull':
$query = "$fn IS NOT NULL";
break;
case 'equalsField':
$query = "$fn LIKE CONCAT($val, '%')";
break;
case 'iEqualsField':
$query = "UPPER($fn) LIKE UPPER(CONCAT($val, '%'))";
break;
case 'iNotEqualField':
$query = "UPPER($fn) LIKE UPPER(CONCAT($val, '%'))";
break;
case 'notEqualField':
$query = "$fn NOT LIKE CONCAT($val, '%')";
break;
case 'greaterThanField':
$query = "$fn > CONCAT($val, '%')";
break;
case 'lessThanField':
$query = "$fn < CONCAT($val, '%')";
break;
case 'greaterOrEqualField':
$query = "$fn >= CONCAT($val, '%')";
break;
case 'lessOrEqualField':
$query = "$fn <= CONCAT($val, '%')";
break;
case 'iBetweenInclusive':
$query = "$fn BETWEEM $start AND $end";
break;
case 'betweenInclusive':
$query = "$fn BETWEEM $start AND $end";
break;
}
$result .= " ".$query." ".$operator." ";
}else
{
// build the list of subcriterias or criterions
$temp = $result;
$result1 = $this->buildCriterion($c);
$result = $temp . "(".$result1.") ".$operator." ";
}
}
//remove the last operator ( and, or, not)
$result_query = substr($result, 0, strrpos($result, $operator));
return $result_query;
} |
...