* @package Mammut\DB */ class View extends \Mammut\StrictObject implements iDatastore { /** * @var DB */ protected $db; protected $name = false; public function __construct(DB $db, $name) { $this->db = &$db; $this->name = $name; } public function getName() { return $this->name; } public function insert($data, array $ignore = array()) { throw new ImplementationException('not implemented'); } public function insertOrUpdate($base, $insert, $update) { throw new ImplementationException('not implemented'); } public function select($limiter = false, $order = false, $fields = false) { $select = $this->db->select($this->name); if ($limiter) { $where = new Condition(Condition::OP_AND); foreach ($limiter as $col => $val) $where->equalTo($col, $val); $select->where($where); } if ($order) { $select->order($order); } if ($fields) { $select->columns($fields); } $result = $this->db->query($select); return $result; } public function getRow($limiter = false, $order = false) { $select = $this->db->select($this->name); if ($limiter) { $where = new Condition(Condition::OP_AND); foreach ($limiter as $col => $val) $where->equalTo($col, $val); $select->where($where); } if ($order) { $select->order($order); } $result = $this->db->getRow($select); return $result; } public function getArray($limiter = false, $order = false) { $select = $this->db->select($this->name); if ($limiter) { $where = new Condition(Condition::OP_AND); foreach ($limiter as $col => $val) $where->equalTo($col, $val); $select->where($where); } if ($order) { $select->order($order); } $result = $this->db->getArray($select); return $result; } public function getObject($limiter = false, $order = false, $classname = false, array $param = array()) { $select = $this->db->select($this->name); if ($limiter) { $where = new Condition(Condition::OP_AND); foreach ($limiter as $col => $val) $where->equalTo($col, $val); $select->where($where); } if ($order) { $select->order($order); } $result = $this->db->getObject($select, $classname, $param); return $result; } public function getRowList($limiter = false, $order = false) { $select = $this->db->select($this->name); if ($limiter) { $where = new Condition(Condition::OP_AND); foreach ($limiter as $col => $val) $where->equalTo($col, $val); $select->where($where); } if ($order) { $select->order($order); } $result = $this->db->getRowList($select); return $result; } public function getArrayList($limiter = false, $order = false) { $select = $this->db->select($this->name); if ($limiter) { $where = new Condition(Condition::OP_AND); foreach ($limiter as $col => $val) $where->equalTo($col, $val); $select->where($where); } if ($order) { $select->order($order); } $result = $this->db->getArrayList($select); return $result; } public function getObjectList($limiter = false, $order = false, $classname = false, array $param = array()) { $select = $this->db->select($this->name); if ($limiter) { $where = new Condition(Condition::OP_AND); foreach ($limiter as $col => $val) $where->equalTo($col, $val); $select->where($where); } if ($order) { $select->order($order); } $result = $this->db->getObjectList($select, $classname, $param); return $result; } public function update($data, array $key, array $exclude = array()) { throw new ImplementationException('not implemented'); } public function delete(array $data) { throw new ImplementationException('not implemented'); } public function size(array $condition = array()) { $select = $this->db->select($this->name); $select->columns(['c' => SQLFunction::count()]); if (count($condition) > 0) { $where = new Condition(Condition::OP_AND); foreach ($condition as $col => $val) $where->equalTo($col, $val); $select->where($where); } return $this->db->getObject($select)->c; } public function count() { return $this->size(); } }