public function insertOrUpdate($data, $id = null) { if (!$id) { $id = $this->getNextId(); } $data["id"] = $id; $this->data[$id] = $data; $this->save(); $this->lastInsertId = $id; }