/** * @param \pq\Gateway\Table $table * @param \pq\Gateway\Row $row * @param string $event create/update/delete * @param array $where reference to the criteria */ function update(\SplSubject $table, Row $row = null, $event = null, array &$where = null) { if ($event === "update") { $where["{$this->column}="] = $row->getData()[$this->column]; $row->{$this->column}->mod(+1); } }
/** * Modify the value in this cell * @param mixed $data * @param string $op a specific operator * @return \pq\Gateway\Cell */ function mod($data, $op = null) { if (is_string($data)) { $data = $this->row->getTable()->getConnection()->quote($data); } parent::mod($data, $op); $this->dirty = true; return $this; }
/** * @param \pq\Gateway\Table $table * @param \pq\Gateway\Row $row * @param string $event create/update/delete * @param array $where reference to the criteria * @throws \UnexpectedValueException if the row has already been modified */ function update(\SplSubject $table, Row $row = null, $event = null, array &$where = null) { if ($event === "update") { if (1 != count($rowset = $table->find($where, null, 0, 0, "update nowait"))) { throw new \UnexpectedValueException("Failed to select a single row"); } if ($rowset->current()->getData() != $row->getData()) { throw new \UnexpectedValueException("Row has already been modified"); } } }
/** * Get the parent rows of a row by foreign key * @param \pq\Gateway\Row $foreign * @param string $ref * @return mixed */ function by(Row $foreign, $ref = null) { // select * from $this where $this->$referencedColumn = $me->$foreignColumn if (!($rel = $foreign->getTable()->getRelation($this->getName(), $ref))) { return $this->onResult(null); } $where = array(); foreach ($rel as $key => $ref) { $where["{$ref}="] = $foreign->{$key}; } return $this->find($where); }