setTable( new OffersTable()); } /** * * create or update an offer on a listing * offers can be updated, but only if they have a 'pending' status. * * @param array $data * * @return int the id of the created/edited offer row */ public function save($data) { $row = null; $data = $this->_prepareSaveData($data); if (array_key_exists('id', $data)) { $select = $this->_table->select() ->where("id = ?", $data['id']); unset($data['id']); $row = $this->_table->fetchRow($select); } if (count($row) > 0) { $data['updated_at'] = new Expr('now()'); $this->_table->update($data, "id='{$row['id']}'"); $id = $row['id']; } else { $data['created_at'] = new Expr('now()'); $id = $this->_table->insert($data); if (!isset($data['topic_id'])) { $row = $this->findBy('id', $id); $row->save(array( 'topic_id' => $id, )); } } return $id; } }