setTable( new TransactionsTable()); } /** * * create or update a transaction * * @param array $data * @return int the id of the inserted/updated 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()'); $this->_table->insert($data); $id = $this->_table->lastInsertId(); } return $id; } }