Und zwar ist es nicht möglich bei einer Klasse, die von ItemCollection abgeleitet ist, bei einer Gruppenbedingung mehrere Where's des gleichen Feldes einzutragen.
Beispiel:
Bei einer Suche über die Datenbestände gibt der User "x y" für Feld z ein.
Jetzt will ich natürlich nicht nur prüfen, ob "z like '%x y%'", sondern
"z like '%x%' and z like '%y%'".
Allerdings wird nur die zuletzt eingestellte Bedingung für z ausgeführt.
Sprich, das SQL Statement, das erzeugt wird, hat nur "z like '%y%'".
Meine Änderung, um das zu beseitigen sieht wie folgt aus:
Code: Alles auswählen
function setWhereGroup ($group, $field, $restriction, $operator = "=")
{
$field = strtolower($field);
if (!isset($this->_groupCounter[$group]))
$this->_groupCounter[$group] = 0;
$this->_where["groups"][$group][$this->_groupCounter[$group]]["operator"] = $operator;
$this->_where["groups"][$group][$this->_groupCounter[$group]]["restriction"] = $restriction;
$this->_where["groups"][$group][$this->_groupCounter[$group]]["field"] = $field;
$this->_groupCounter[$group]++;
}
function _buildGroupWhereStatements()
{
$wheres = array();
$groupwhere = array();
$lastgroup = false;
$groupwherestatement = "";
/* Find out if there are any defined groups */
if (count($this->_where["groups"]) > 0)
{
/* Step trough all groups */
foreach ($this->_where["groups"] as $groupname => $group)
{
$wheres = array();
/* Fetch restriction, fields and operators and build single group where statements */
foreach ($group as $cnt => $item)
{
$restriction = "'" . $this->_itemClassInstance->_inFilter($item["restriction"]) . "'";
$wheres[] = implode(" ", array($item["field"], $item["operator"], $restriction));
}
/* Add completed substatements */
$operator = 'AND';
if (array_key_exists($groupname, $this->_innerGroupConditions))
{
$operator = $this->_innerGroupConditions[$groupname];
}
$groupwhere[$groupname] = implode(" ".$operator." ", $wheres);
}
}
/* Combine groups */
foreach ($groupwhere as $groupname => $group)
{
if ($lastgroup != false)
{
$operator = "AND";
/* Check if there's a group condition */
if (array_key_exists($groupname, $this->_groupConditions))
{
if (array_key_exists($lastgroup, $this->_groupConditions[$groupname]))
{
$operator = $this->_groupConditions[$groupname][$lastgroup];
}
}
/* Reverse check */
if (array_key_exists($lastgroup, $this->_groupConditions))
{
if (array_key_exists($groupname, $this->_groupConditions[$lastgroup]))
{
$operator = $this->_groupConditions[$lastgroup][$groupname];
}
}
$groupwherestatement .= " ". $operator . " (" . $group . ")";
}
else
{
$groupwherestatement .= "(" . $group . ")";
}
$lastgroup = $groupname;
}
return ($groupwherestatement);
}
Hoffe das hilft jemandem.