885c95abd5a166b51cb35e6281aa72280e6a67f7
5 class Row
implements \JsonSerializable
8 * @var \pq\Gateway\Table
20 protected $mods = array();
23 * @param \pq\Gateway\Table $table
25 * @param bool $prime whether to mark all columns as modified
27 function __construct(Table
$table, array $data = null, $prime = false) {
28 $this->table
= $table;
39 * @return \pq\Gateway\Row
41 function __invoke(array $data) {
44 return $that->prime();
48 * @implements JsonSerializable
51 function jsonSerialize() {
56 * @return \pq\Gateway\Table
71 * @return \pq\Gateway\Row
73 protected function prime() {
74 $this->mods
= array();
75 foreach ($this->data
as $key => $val) {
76 $this->mods
[$key] = new Cell($this, $key, $val);
82 * Transform data array to where criteria
86 protected function criteria() {
88 array_walk($this->data
, function($v, $k) use (&$where) {
97 * @return \pq\Gateway\Cell
100 if (!isset($this->mods
[$p])) {
101 $this->mods
[$p] = new Cell($this, $p, $this->data
[$p]);
103 return $this->mods
[$p];
111 function __set($p, $v) {
112 $this->__get($p)->set(($v instanceof Cell
) ?
$v->get() : $v);
116 * Create this row in the database
117 * @return \pq\Gateway\Row
120 $this->data
= $this->table
->create($this->mods
)->current()->data
;
121 $this->mods
= array();
126 * Update this row in the database
127 * @return \pq\Gateway\Row
130 $this->data
= $this->table
->update($this->criteria(), $this->mods
)->current()->data
;
131 $this->mods
= array();
136 * Delete this row in the database
137 * @return \pq\Gateway\Row
140 $this->data
= $this->table
->delete($this->criteria(), "*")->current()->data
;
141 return $this->prime();