Пример #1
0
 /**
  * Helper method used by insert_question_attempt_step and update_question_attempt_step
  * @param question_attempt_step $step the step to store.
  * @param int $stepid the id of the step.
  * @param context $context the context of the owning question_usage_by_activity.
  */
 protected function insert_step_data(question_attempt_step $step, $stepid, $context)
 {
     foreach ($step->get_all_data() as $name => $value) {
         if ($value instanceof question_file_saver) {
             $value->save_files($stepid, $context);
         }
         if ($value instanceof question_response_files) {
             $value = (string) $value;
         }
         $data = new stdClass();
         $data->attemptstepid = $stepid;
         $data->name = $name;
         $data->value = $value;
         $this->db->insert_record('question_attempt_step_data', $data, false);
     }
 }
 /**
  * Store a {@link question_attempt_step} in the database.
  * @param question_attempt_step $qa the step to store.
  * @param int $questionattemptid the question attept id this step belongs to.
  * @param int $seq the sequence number of this stop.
  * @param object $context the context of the owning question_usage_by_activity.
  */
 public function insert_question_attempt_step(question_attempt_step $step, $questionattemptid, $seq, $context)
 {
     $record = new stdClass();
     $record->questionattemptid = $questionattemptid;
     $record->sequencenumber = $seq;
     $record->state = '' . $step->get_state();
     $record->fraction = $step->get_fraction();
     $record->timecreated = $step->get_timecreated();
     $record->userid = $step->get_user_id();
     $record->id = $this->db->insert_record('question_attempt_steps', $record);
     foreach ($step->get_all_data() as $name => $value) {
         if ($value instanceof question_file_saver) {
             $value->save_files($record->id, $context);
         }
         $data = new stdClass();
         $data->attemptstepid = $record->id;
         $data->name = $name;
         $data->value = $value;
         $this->db->insert_record('question_attempt_step_data', $data, false);
     }
 }
 public function test_get_data()
 {
     $step = new question_attempt_step(array('x' => 1, '-y' => 'frog', ':flagged' => 1));
     $this->assertEquals(array('x' => '1'), $step->get_qt_data());
     $this->assertEquals(array('y' => 'frog'), $step->get_behaviour_data());
     $this->assertEquals(array('x' => 1, '-y' => 'frog', ':flagged' => 1), $step->get_all_data());
 }
Пример #4
0
 /**
  * Helper method used by insert_question_attempt_step and update_question_attempt_step
  * @param question_attempt_step $step the step to store.
  * @param int $stepid the id of the step.
  * @param context $context the context of the owning question_usage_by_activity.
  * @return array of question_attempt_step_data rows, that still need to be inserted.
  */
 protected function prepare_step_data(question_attempt_step $step, $stepid, $context)
 {
     $rows = array();
     foreach ($step->get_all_data() as $name => $value) {
         if ($value instanceof question_file_saver) {
             $value->save_files($stepid, $context);
         }
         if ($value instanceof question_response_files) {
             $value = (string) $value;
         }
         $data = new stdClass();
         $data->attemptstepid = $stepid;
         $data->name = $name;
         $data->value = $value;
         $rows[] = $data;
     }
     return $rows;
 }