private function buildCriterion($advancedCriteria)
{
$criterias = $advancedCriteria['criteria'];
$operator = $advancedCriteria['operator'];
$result = '';
$query = '';
$value = array();
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'?";
array_push($value, $val);
break;
case 'notEqual':
$query = "$fn != '$val'";?";
array_push($value, $val);
break;
case 'iEquals':
$query = "UPPER($fn) = ?";
array_push($value, "UPPER('{$val}')");
break;
case 'iNotEqual':
$query = "UPPER($fn) != UPPER('$val')";break;
case 'iNotEqual':
break$query = "UPPER($fn) != ?";
case 'greaterThan': array_push($value, "UPPER('{$val}')"); $query = "$fn > '$val'";
break;
case 'lessThangreaterThan':
$query = "$fn < '$val'";> ?";
array_push($value, $val);
break;
case 'greaterOrEquallessThan':
$query = "$fn >= '$val'< ?";
array_push($value, $val);
break; case 'lessOrEqual':
$query = "$fn <= '$val'";break;
case 'greaterOrEqual':
break;
case 'contains': $query = "$fn >= ?";
array_push($value, $val);
$query = "$fn LIKE '%$val%'";
break;
case 'startsWithlessOrEqual':
$query = "$fn LIKE '$val%'<= ?";
array_push($value, $val);
break;
case 'endsWithcontains':
$query = "$fn LIKE '%$val'?";
array_push($value, "%{$val}%");
break; case 'iContains':
$query = "UPPER($fn) LIKE UPPER('%$val%')";break;
case 'startsWith':
break;$query = "$fn LIKE ?";
case 'iStartsWith': array_push($value, "{$val}%"); $query = "UPPER($fn) LIKE UPPER('$val%')"; break;
break;
case 'iEndsWithendsWith':
$query = "UPPER($fn) LIKE UPPER('%$val')"; ?";
array_push($value, "%{$val}"); break; case 'notContains':
$query = "$fn NOT LIKE '%$val%'";break;
case 'iContains':
break;
$query = "$fn LIKE ?";
case 'notStartsWith':array_push($value, "%{$val}%"); $query = "$fn NOT LIKE '$val%'";
break;
case 'notEndsWithiStartsWith':
$query = "UPPER($fn) NOT LIKE '%$val'?";
array_push($value, "UPPER('{$val}%')");
break;
case 'iNotContains': $query = "UPPER($fn) NOT LIKE UPPER('%$val%')";
break;
case 'iNotStartsWithiEndsWith':
$query = "UPPER($fn) NOT LIKE UPPER('$val%')?";
array_push($value, "UPPER('%{$val}')"); break; case 'iNotEndsWith': $query = "UPPER($fn) NOT LIKE UPPER('%$val')"; break; case 'isNull':
break; $query = "$fn IS NULL";
break;
case 'notNullnotContains':
$query = "$fn ISNOT NOTLIKE NULL?";
array_push($value, "%{$val}%"); break; case 'equalsField': $query = "$fn LIKE CONCAT($val, '%')"; break; case 'iEqualsField': $query = "UPPER($fn) LIKE UPPER(CONCAT($val, '%'))";
break;
case 'notStartsWith': case 'iNotEqualField':
$query = "UPPER($fn) NOT LIKE UPPER(CONCAT($val, '%'))";
?";
array_push($value, "{$val}%");
break;
case 'notEqualFieldnotEndsWith':
$query = "$fn NOT LIKE CONCAT($val, '%')?";
array_push($value, "%{$val}");
break;
case 'greaterThanFieldiNotContains':
$query = "UPPER($fn > CONCAT($val, ') NOT LIKE ?";
array_push($value, "UPPER('%{$val}%')");
break;
case 'iNotStartsWith':
$query = "UPPER($fn) NOT LIKE ?";
array_push($value, "UPPER('{$val}%')");
break;
case 'lessThanFieldiNotEndsWith':
$query = "UPPER($fn < CONCAT($val, '%) NOT LIKE ?";
array_push($value, "UPPER('%{$val}')");
break;
case 'greaterOrEqualFieldisNull':
$query = "$fn >= CONCAT($val, '%')IS NULL";
break;
case 'lessOrEqualFieldnotNull':
$query = "$fn <= CONCAT($val, '%')IS NOT NULL";
break;
case 'iBetweenInclusiveequalsField':
$query = "$fn BETWEEM $start AND $endLIKE ?";
array_push($value, "CONCAT('{$val}', '%')");
break;
case 'betweenInclusiveiEqualsField':
$query = "UPPER($fn BETWEEM $start AND $end") LIKE ?";
array_push($value, "UPPER(CONCAT('{$val}', '%'))");
break; } $result .= "
case 'iNotEqualField':
$query = "UPPER($fn) NOT LIKE ?";
array_push($value, "UPPER(CONCAT('{$val}', '%'))");
break;
case 'notEqualField':
$query = "$fn NOT LIKE ?";
array_push($value, "CONCAT('{$val}', '%')");
break;
case 'greaterThanField':
$query = "$fn > ?";
array_push($value, "CONCAT('{$val}', '%')");
break;
case 'lessThanField':
$query = "$fn < ?";
array_push($value, "CONCAT('{$val}', '%')");
break;
case 'greaterOrEqualField':
$query = "$fn >= ?";
array_push($value, "CONCAT('{$val}', '%')");
break;
case 'lessOrEqualField':
$query = "$fn <= ?";
array_push($value, "CONCAT('{$val}', '%')");
break;
case 'iBetweenInclusive':
$query = "$fn BETWEEM ? AND ?";
array_push($value, $start);
array_push($value, $end);
break;
case 'betweenInclusive':
$query = "$fn BETWEEM ? AND ?";
array_push($value, $start);
array_push($value, $end);
break;
}
$result .= " ".$query." ".$operator." ";
}else
{
// build the list of subcriterias or criterions
}else$temp = $result;
{ $result1 = $this->buildCriterion($c);
//$result build= the$temp list of subcriterias or criterions. "(".$result1['query'].") ".$operator." ";
$temp = $result;foreach($result1['value'] as $val)
$result1 = $this->buildCriterion($c{
array_push($value, $val);
$result = $temp . "(".$result1.") ".$operator." ";}
}
}
//remove the last operator ( and, or, not)
$result_query = substr($result, 0, strrpos($result, $operator));
return$advanced_critical['query'] = $result_query;
$advanced_critical['value'] = $value;
return $advanced_critical;
} |