/**
* Turn any of the acceptable query shorthands into a full
* Horde_Rdo_Query object. If you pass an existing Horde_Rdo_Query
* object in, it will be cloned before it's returned so that it
* can be safely modified.
*
* @param mixed $query The query to convert to an object.
* @param Horde_Rdo_Mapper $mapper The Mapper object governing this query.
*
* @return Horde_Rdo_Query The full Horde_Rdo_Query object.
*/
public static function create($query, $mapper = null)
{
if ($query instanceof Horde_Rdo_Query || $query instanceof Horde_Rdo_Query_Literal) {
$query = clone $query;
if (!is_null($mapper)) {
$query->setMapper($mapper);
}
return $query;
}
$q = new Horde_Rdo_Query($mapper);
if (is_scalar($query)) {
$q->addTest($mapper->tableDefinition->getPrimaryKey(), '=', $query);
} elseif ($query) {
$q->combineWith('AND');
foreach ($query as $key => $value) {
$q->addTest($key, '=', $value);
}
}
return $q;
}