public function test_constructor_given_params()
 {
     global $USER;
     $step = new question_attempt_step(array(), 123, 5);
     $this->assertEquals(123, $step->get_timecreated());
     $this->assertEquals(5, $step->get_user_id());
     $this->assertEquals(array(), $step->get_qt_data());
     $this->assertEquals(array(), $step->get_behaviour_data());
 }
Example #2
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 $questionattemptid the question attept id this step belongs to.
  * @param int $seq the sequence number of this stop.
  * @return stdClass data to insert into the database.
  */
 protected function make_step_record(question_attempt_step $step, $questionattemptid, $seq)
 {
     $record = new stdClass();
     $record->questionattemptid = $questionattemptid;
     $record->sequencenumber = $seq;
     $record->state = (string) $step->get_state();
     $record->fraction = $step->get_fraction();
     $record->timecreated = $step->get_timecreated();
     $record->userid = $step->get_user_id();
     return $record;
 }
 /**
  * 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);
     }
 }