<?php
/**
* @file DatajarQuery.php
*
* @brief Object-oriented select query wrapper for storable objects.
*
* Copyright © 2012 Guillaume Pasquet
*
* This file is part of Datajar.
*
* Datajar is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Datajar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Datajar. If not, see <http://www.gnu.org/licenses/>.
*/
class DatajarQuery
{
protected $class;
protected $where = array();
protected $orderby = false;
protected $desc = false;
protected $limit = null;
public function __construct($class)
{
$this->class = $class;
return $this;
}
public function where(array $cond)
{
$this->where = $cond;
return $this;
}
public function orderby($col, $desc = false)
{
$this->orderby = $col;
$this->desc = $desc;
return $this;
}
public function limit($start, $length)
{
$this->limit = array($start, $length);
return $this;
}
public function commit()
{
return $class::run_query($this);
}
public function get_object() { return $this->class; }
public function get_cond() { return $this->where; }
public function get_orderby() { return $this->orderby; }
public function get_desc() { return $this->desc; }
public function get_limit() { return $this->limit; }
}
?>