/** * Write all the changes we have recorded to the database. * @param question_engine_data_mapper $dm the mapper to use to update the database. */ public function save(question_engine_data_mapper $dm) { $dm->delete_steps_for_question_attempts(array_keys($this->attemptstodeletestepsfor), $this->quba->get_owning_context()); foreach ($this->stepsadded as $stepinfo) { list($step, $questionattemptid, $seq) = $stepinfo; $dm->insert_question_attempt_step($step, $questionattemptid, $seq, $this->quba->get_owning_context()); } foreach ($this->attemptsadded as $qa) { $dm->insert_question_attempt($qa, $this->quba->get_owning_context()); } foreach ($this->attemptsmodified as $qa) { $dm->update_question_attempt($qa); } if ($this->modified) { $dm->update_questions_usage_by_activity($this->quba); } }