Improvements for query classes.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9102 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2011-09-07 17:10:40 +00:00
parent f1c9668478
commit 78db12a858
6 changed files with 88 additions and 76 deletions

View file

@ -4,20 +4,32 @@
var $conditions;
var $pipe;
var $_group;
var $_show;
function ConditionGroup($conditions, $pipe = "") {
$this->conditions = array();
foreach($conditions as $condition){
if($condition->show())
$this->conditions[] = $condition;
}
if(count($this->conditions) === 0) $this->_show = false;
else $this->_show = true;
$this->pipe = $pipe;
}
function show(){
return $this->_show;
}
function setPipe($pipe){
if($this->pipe !== $pipe) $this->_group = null;
$this->pipe = $pipe;
}
function toString($with_value = true){
if(!isset($this->_group)){
$cond_indx = 0;
$group = '';
@ -26,23 +38,23 @@
$group .= $condition->toString($with_value) . ' ';
$cond_indx++;
}
// If the group has no conditions in it, return ''
if($cond_indx === 0) return '';
if($this->pipe !== ""){
if($this->pipe !== "" && trim($group) !== ''){
$group = $this->pipe . ' (' . $group . ')';
}
return $group;
$this->_group = $group;
}
return $this->_group;
}
function getArguments(){
$args = array();
foreach($this->conditions as $condition){
$arg = $condition->getArgument();
if($arg) $args[] = $arg;
}
return $args;
$args = array();
foreach($this->conditions as $condition){
$arg = $condition->getArgument();
if($arg) $args[] = $arg;
}
return $args;
}
}
?>