/** * Returns the "where" part of the query based on the criteria parameters * @param Criteria $criteria * @return String "where" part of the sql query */ private function GetWhereSQL($criteria) { $ands = $criteria->GetAnds(); $ors = $criteria->GetOrs(); // TODO: this all needs to move to the criteria object so it will recurse properly .... $where = $this->RemoveWherePrefix($criteria->GetWhere()); if (count($ands)) { $wdelim = $where ? " and " : ""; foreach ($ands as $c) { $tmp = $c->GetWhere(); $buff = $this->RemoveWherePrefix($tmp); if ($buff) { $where .= $wdelim . $buff; $wdelim = " and "; } } } if (count($ors)) { $where = trim($where) ? "(" . $where . ")" : ""; // no primary criteria. kinda strange $wdelim = $where ? " or " : ""; foreach ($ors as $c) { $tmp = $c->GetWhere(); $buff = $this->RemoveWherePrefix($tmp); if ($buff) { $where .= $wdelim . "(" . $buff . ")"; $wdelim = " or "; } } } // .. end of stuff that should be in criteria // prepend the "where" onto the statement if ($where) { $where = " where (" . trim($where) . ") "; } return $where; }