/** * 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(array_keys($this->stepsdeleted), $this->quba->get_owning_context()); foreach ($this->stepsmodified as $stepinfo) { list($step, $questionattemptid, $seq) = $stepinfo; $dm->update_question_attempt_step($step, $questionattemptid, $seq, $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); } }
/** * 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(array_keys($this->stepsdeleted), $this->quba->get_owning_context()); // Initially an array of array of question_attempt_step_objects. // Built as a nested array for efficiency, then flattened. $stepdata = array(); foreach ($this->stepsmodified as $stepinfo) { list($step, $questionattemptid, $seq) = $stepinfo; $stepdata[] = $dm->update_question_attempt_step($step, $questionattemptid, $seq, $this->quba->get_owning_context()); } foreach ($this->stepsadded as $stepinfo) { list($step, $questionattemptid, $seq) = $stepinfo; $stepdata[] = $dm->insert_question_attempt_step($step, $questionattemptid, $seq, $this->quba->get_owning_context()); } foreach ($this->attemptsadded as $qa) { $stepdata[] = $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); } if (!$stepdata) { return; } $dm->insert_all_step_data(call_user_func_array('array_merge', $stepdata)); }