Horde_Rdo_Query::create PHP Method

create() public static method

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.
public static create ( mixed $query, Horde_Rdo_Mapper $mapper = null ) : Horde_Rdo_Query
$query mixed The query to convert to an object.
$mapper Horde_Rdo_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 = 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;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * findOne can be called in several ways.
  *
  * Primary key mode: pass find() a single primary key, and it will return a
  * single object matching that primary key.
  *
  * If you pass findOne() no arguments, the first object of this type will be
  * returned.
  *
  * If you pass findOne() an associative array, it will be turned into a
  * Horde_Rdo_Query object.
  *
  * If you pass findOne() a Horde_Rdo_Query, it will return the first object
  * matching that query.
  */
 public function findOne($arg = null)
 {
     if (is_null($arg)) {
         $query = null;
     } elseif (is_scalar($arg)) {
         $query = array($this->primaryKey => $arg);
     } else {
         $query = $arg;
     }
     // Build a full Query object, and limit it to one result.
     $query = Horde_Rdo_Query::create($query, $this);
     $query->limit(1);
     $list = new Horde_Rdo_List($query);
     return $list->current();
 }
All Usage Examples Of Horde_Rdo_Query::create