add test
[m6w6/pq-gateway] / lib / pq / Gateway / Cell.php
index ba58404a7c190c261cb82c78ec2e2a42240147c5..f29fd1f5499cdf4f0ed2042378683d2d3eed880a 100644 (file)
@@ -21,15 +21,22 @@ class Cell
         */
        protected $data;
        
+       /**
+        * @var bool
+        */
+       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) {
                $this->row = $row;
                $this->name = $name;
                $this->data = $data;
+               $this->dirty = $dirty;
        }
        
        /**
@@ -48,6 +55,14 @@ class Cell
                return $this->data instanceof Expr;
        }
        
+       /**
+        * Check whether the cell has been modified
+        * @return bool
+        */
+       function isDirty() {
+               return $this->dirty;
+       }
+       
        /**
         * Get value
         * @return mixed
@@ -65,15 +80,6 @@ class Cell
        function mod($data, $op = null) {
                if (!($this->data instanceof Expr)) {
                        $this->data = new Expr($this->name);
-                       /*
-                       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) {
@@ -84,6 +90,9 @@ class Cell
                        $data = $this->row->getTable()->getConnection()->quote($data);
                        $this->data->add(new Expr("%s %s"), isset($op) ? $op : "||", $data);
                }
+               
+               $this->dirty = true;
+               
                return $this;
        }
        
@@ -94,6 +103,7 @@ class Cell
         */
        function set($data) {
                $this->data = $data;
+               $this->dirty = true;
                return $this;
        }
 }