16define(
'XOOPS_CRITERIA_ASC',
'ASC');
17define(
'XOOPS_CRITERIA_DESC',
'DESC');
18define(
'XOOPS_CRITERIA_STARTWITH', 1);
19define(
'XOOPS_CRITERIA_ENDWITH', 2);
20define(
'XOOPS_CRITERIA_CONTAIN', 3);
76 public function getCountChildElements()
101 public function getName()
106 public function getValue()
111 public function getOperator()
125 $this->sort[0] = $sort;
127 if (!isset($this->order[0])) {
128 $this->order[0] =
'ASC';
131 if (
null != $order) {
132 if (
'ASC' == strtoupper($order)) {
133 $this->order[0] =
'ASC';
134 } elseif (
'DESC' == strtoupper($order)) {
135 $this->order[0] =
'DESC';
145 public function addSort($sort, $order =
'ASC')
147 $this->sort[] = $sort;
148 if (
'ASC' == strtoupper($order)) {
149 $this->order[] =
'ASC';
150 } elseif (
'DESC' == strtoupper($order)) {
151 $this->order[] =
'DESC';
160 if (isset($this->sort[0])) {
161 return $this->sort[0];
175 $max = count($this->sort);
177 for ($i = 0; $i < $max; $i++) {
178 $ret[$i][
'sort'] = $this->sort[$i];
179 $ret[$i][
'order'] = $this->order[$i] ??
'ASC';
191 if (
'ASC' == strtoupper($order)) {
192 $this->order[0] =
'ASC';
193 } elseif (
'DESC' === strtoupper($order)) {
194 $this->order[0] =
'DESC';
203 if (isset($this->order[0])) {
204 return $this->order[0];
215 $this->limit = (int)$limit;
231 $this->start = (int)$start;
248 $this->groupby = $group;
257 return ' GROUP BY '.$this->groupby;
273 public $criteriaElements = [];
279 public $conditions = [];
289 if (isset($ele) && is_object($ele)) {
290 $this->
add($ele, $condition);
296 return count($this->criteriaElements) > 0;
299 public function getCountChildElements()
301 return count($this->criteriaElements);
306 return $this->criteriaElements[$idx];
311 return $this->conditions[$idx];
322 public function &
add($criteriaElement, $condition=
'AND')
324 $this->criteriaElements[] =& $criteriaElement;
325 $this->conditions[] = $condition;
338 $count = count($this->criteriaElements);
340 $elems =& $this->criteriaElements;
341 $conds =& $this->conditions;
342 $ret =
'('. $elems[0]->render();
343 for ($i = 1; $i < $count; $i++) {
344 $ret .=
' '.$conds[$i].
' '.$elems[$i]->render();
360 $ret = (
'' !== $ret) ?
'WHERE ' . $ret : $ret;
374 $count = count($this->criteriaElements);
376 $retval = $this->criteriaElements[0]->renderLdap();
377 for ($i = 1; $i < $count; $i++) {
378 $cond = $this->conditions[$i];
379 if (
'AND' == strtoupper($cond)) {
381 } elseif (
'OR' == strtoupper($cond)) {
384 $retval =
"($op$retval" . $this->criteriaElements[$i]->renderLdap() .
')';
424 public function __construct($column, $value=
'', $operator=
'=', $prefix =
'', $function =
'')
426 $this->prefix = $prefix;
427 $this->
function = $function;
428 $this->column = $column;
429 $this->
operator = $operator;
434 if (is_array($value) && 2 == count($value) &&
'IN' !== $operator &&
'NOT IN' !== $operator) {
435 $this->dtype = (int)$value[0];
436 $this->value = $value[1];
438 $this->value = $value;
442 public function getName()
444 return $this->column;
447 public function getValue()
452 public function getOperator()
454 return $this->operator;
465 $value = $this->value;
466 if (in_array(strtoupper($this->
operator), [
'IN',
'NOT IN'])) {
467 $value = is_array($value) ? implode(
',', $value) : trim($value,
" ()\t");
469 $value =
'('.$value.
')';
476 $clause = (!empty($this->prefix) ? $this->prefix.
'.' :
'') . $this->column;
477 if (!empty($this->
function)) {
478 $clause = sprintf($this->
function, $clause);
480 $clause .=
' '.$this->operator.
' '.$value;
493 return '(' . $this->column . $this->
operator . $this->value .
')';
505 return empty($cond) ?
'' :
"WHERE $cond";
__construct($ele=null, $condition='AND')
& add($criteriaElement, $condition='AND')
setSort($sort, $order=null)
addSort($sort, $order='ASC')
__construct($column, $value='', $operator='=', $prefix='', $function='')