X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=blobdiff_plain;f=lib%2Fpq%2FGateway%2FCell.php;h=efa5fcbb3cd1154ecd99321bdddaf9e093a7a5c2;hp=730efb07bc4a36c1058bd77a3878a5bd6e755d85;hb=dc87da9c4ec52918e34f2e43eac3014f0f99a8bc;hpb=01bd45d05ce58796db7540d60671b8cff5d46bff diff --git a/lib/pq/Gateway/Cell.php b/lib/pq/Gateway/Cell.php index 730efb0..efa5fcb 100644 --- a/lib/pq/Gateway/Cell.php +++ b/lib/pq/Gateway/Cell.php @@ -2,9 +2,9 @@ namespace pq\Gateway; -use \pq\Query\Expr; +use \pq\Query\Expressible; -class Cell +class Cell extends Expressible { /** * @var \pq\Gateway\Row @@ -17,43 +17,40 @@ class Cell protected $name; /** - * @var mixed + * @var bool */ - protected $data; + protected $dirty; /** * @param \pq\Gateway\Row $row * @param string $name * @param mixed $data + * @param bool $dirty */ - function __construct(Row $row, $name, $data) { + function __construct(Row $row, $name, $data, $dirty = false) { + parent::__construct($data); $this->row = $row; $this->name = $name; - $this->data = $data; + $this->dirty = $dirty; } /** - * Get value as string - * @return string - */ - function __toString() { - return (string) $this->data; - } - - /** - * Test whether the value is an unevaluated expression + * Check whether the cell has been modified * @return bool */ - function isExpr() { - return $this->data instanceof Expr; + function isDirty() { + return $this->dirty; } /** - * Get value - * @return mixed + * Set the value + * @param mixed $data + * @return \pq\Gateway\Cell */ - function get() { - return $this->data; + function set($data) { + parent::set($data); + $this->dirty = true; + return $this; } /** @@ -63,34 +60,9 @@ class Cell * @return \pq\Gateway\Cell */ function mod($data, $op = null) { - if (!($this->data instanceof Expr)) { - if (!isset($this->data)) { - $this->data = new Expr($this->name); - } elseif (is_numeric($this->data)) { - $this->data = new Expr($this->data); - } else { - $this->data = new Expr("%s", $this->row->getTable()->getConnection()->quote($this->data)); - } - } - - if ($data instanceof Expr) { - $this->data->add($data); - } elseif (!isset($op) && is_numeric($data)) { - $this->data->add(new Expr("+ $data")); - } else { - $data = $this->row->getTable()->getConnection()->quote($data); - $this->data->add(new Expr("%s %s"), isset($op) ? $op : "||", $data); - } + parent::mod($data, $op); + $this->dirty = true; return $this; } - /** - * Set the value in this cell - * @param mixed $data - * @return \pq\Gateway\Cell - */ - function set($data) { - $this->data = $data; - return $this; - } }