22 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
69 function CriteriaElement()
84 function setSort($sort)
102 function setOrder($order)
104 if (
'DESC' == strtoupper($order)) {
105 $this->order =
'DESC';
122 function setLimit($limit = 0)
124 $this->limit = intval($limit);
140 function setStart($start = 0)
142 $this->start = intval($start);
158 function setGroupby($group)
160 $this->groupby = $group;
167 function getGroupby()
169 return $this->groupby ?
" GROUP BY {$this->groupby}" :
"";
205 $this->
add($ele, $condition);
216 function &
add(&$criteriaElement, $condition =
'AND')
218 if (is_object($criteriaElement)) {
219 $this->criteriaElements[] =& $criteriaElement;
220 $this->conditions[] = $condition;
233 $count = count($this->criteriaElements);
235 $render_string = $this->criteriaElements[0]->render();
236 for(
$i = 1;
$i < $count;
$i++) {
237 if (!$render = $this->criteriaElements[
$i]->
render())
239 $render_string .= (empty($render_string) ?
"" :
' ' . $this->conditions[
$i] .
' ') . $render;
241 $ret = empty($render_string) ?
'' :
"({$render_string})";
267 $count = count($this->criteriaElements);
269 $retval = $this->criteriaElements[0]->renderLdap();
270 for(
$i = 1;
$i < $count;
$i++) {
271 $cond = strtoupper($this->conditions[
$i]);
272 $op = ($cond ==
"OR") ?
"|" :
"&";
273 $retval =
"({$op}{$retval}" . $this->criteriaElements[
$i]->renderLdap() .
")";
319 $clause = (!empty($this->prefix) ?
"{$this->prefix}." :
"") . $this->column;
320 if (!empty($this->
function)) {
321 $clause = sprintf($this->
function, $clause);
323 if (in_array(strtoupper($this->
operator), array(
'IS NULL' ,
'IS NOT NULL'))) {
326 if (
'' === (
$value = trim($this->value))) {
329 if (!in_array(strtoupper($this->
operator), array(
'IN' ,
'NOT IN'))) {
330 if ((substr(
$value, 0, 1) !=
'`') && (substr(
$value, - 1) !=
'`')) {
332 }
else if (!preg_match(
'/^[a-zA-Z0-9_\.\-`]*$/',
$value)) {
336 $clause .=
" {$this->operator} {$value}";
349 if ($this->
operator ==
'>') {
350 $this->
operator =
'>=';
352 if ($this->
operator ==
'<') {
353 $this->
operator =
'<=';
356 if ($this->
operator ==
'!=' || $this->
operator ==
'<>') {
358 $clause =
"(!(" . $this->column .
$operator . $this->value .
"))";
360 if ($this->
operator ==
'IN') {
361 $newvalue = str_replace(array(
'(' ,
')'),
'', $this->value);
362 $tab = explode(
',', $newvalue);
363 foreach ($tab as
$uid) {
364 $clause .=
"({$this->column}={$uid})";
366 $clause =
'(|' . $clause .
')';
368 $clause =
"(" . $this->column . $this->
operator . $this->value .
")";
382 return empty($cond) ?
'' :
"WHERE {$cond}";