Example #1
0
 /**
  * Start this question attempt.
  *
  * You should not call this method directly. Call
  * {@link question_usage_by_activity::start_question()} instead.
  *
  * @param string|question_behaviour $preferredbehaviour the name of the
  *      desired archetypal behaviour, or an actual model instance.
  * @param int $variant the variant of the question to start. Between 1 and
  *      $this->get_question()->get_num_variants() inclusive.
  * @param array $submitteddata optional, used when re-starting to keep the same initial state.
  * @param int $timestamp optional, the timstamp to record for this action. Defaults to now.
  * @param int $userid optional, the user to attribute this action to. Defaults to the current user.
  * @param int $existingstepid optional, if this step is going to replace an existing step
  *      (for example, during a regrade) this is the id of the previous step we are replacing.
  */
 public function start($preferredbehaviour, $variant, $submitteddata = array(), $timestamp = null, $userid = null, $existingstepid = null)
 {
     if ($this->get_num_steps() > 0) {
         throw new coding_exception('Cannot start a question that is already started.');
     }
     // Initialise the behaviour.
     $this->variant = $variant;
     if (is_string($preferredbehaviour)) {
         $this->behaviour = $this->question->make_behaviour($this, $preferredbehaviour);
     } else {
         $class = get_class($preferredbehaviour);
         $this->behaviour = new $class($this, $preferredbehaviour);
     }
     // Record the minimum and maximum fractions.
     $this->minfraction = $this->behaviour->get_min_fraction();
     $this->maxfraction = $this->behaviour->get_max_fraction();
     // Initialise the first step.
     $firststep = new question_attempt_step($submitteddata, $timestamp, $userid, $existingstepid);
     if ($submitteddata) {
         $firststep->set_state(question_state::$complete);
         $this->behaviour->apply_attempt_state($firststep);
     } else {
         $this->behaviour->init_first_step($firststep, $variant);
     }
     $this->add_step($firststep);
     // Record questionline and correct answer.
     $this->questionsummary = $this->behaviour->get_question_summary();
     $this->rightanswer = $this->behaviour->get_right_answer_summary();
 }
 public function test_get_set_state()
 {
     $step = new question_attempt_step();
     $step->set_state(question_state::$gradedright);
     $this->assertEquals(question_state::$gradedright, $step->get_state());
 }
Example #3
0
 public function test_render_missing()
 {
     $questiondata = $this->get_unknown_questiondata();
     $q = question_bank::make_question($questiondata);
     $qa = new testable_question_attempt($q, 0);
     $step = new question_attempt_step(array('answer' => 'frog'));
     $step->set_state(question_state::$todo);
     $qa->add_step($step);
     $qa->set_behaviour(new qbehaviour_deferredfeedback($qa, 'deferredfeedback'));
     $output = $qa->render(new question_display_options(), '1');
     $this->assertRegExp('/' . preg_quote($qa->get_question()->questiontext, '/') . '/', $output);
     $this->assertRegExp('/' . preg_quote(get_string('missingqtypewarning', 'qtype_missingtype'), '/') . '/', $output);
     $this->assert(new question_contains_tag_with_attribute('div', 'class', 'warning missingqtypewarning'), $output);
 }
Example #4
0
    /**
     * Start this question attempt.
     *
     * You should not call this method directly. Call
     * {@link question_usage_by_activity::start_question()} instead.
     *
     * @param string|question_behaviour $preferredbehaviour the name of the
     *      desired archetypal behaviour, or an actual model instance.
     * @param int $variant the variant of the question to start. Between 1 and
     *      $this->get_question()->get_num_variants() inclusive.
     * @param array $submitteddata optional, used when re-starting to keep the same initial state.
     * @param int $timestamp optional, the timstamp to record for this action. Defaults to now.
     * @param int $userid optional, the user to attribute this action to. Defaults to the current user.
     * @param int $existingstepid optional, if this step is going to replace an existing step
     *      (for example, during a regrade) this is the id of the previous step we are replacing.
     */
    public function start($preferredbehaviour, $variant, $submitteddata = array(),
            $timestamp = null, $userid = null, $existingstepid = null) {

        // Initialise the behaviour.
        $this->variant = $variant;
        if (is_string($preferredbehaviour)) {
            $this->behaviour =
                    $this->question->make_behaviour($this, $preferredbehaviour);
        } else {
            $class = get_class($preferredbehaviour);
            $this->behaviour = new $class($this, $preferredbehaviour);
        }

        // Record the minimum fraction.
        $this->minfraction = $this->behaviour->get_min_fraction();

        // Initialise the first step.
        $firststep = new question_attempt_step($submitteddata, $timestamp, $userid, $existingstepid);
        $firststep->set_state(question_state::$todo);
        if ($submitteddata) {
            $this->question->apply_attempt_state($firststep);
        } else {
            $this->behaviour->init_first_step($firststep, $variant);
        }
        $this->add_step($firststep);

        // Record questionline and correct answer.
        $this->questionsummary = $this->behaviour->get_question_summary();
        $this->rightanswer = $this->behaviour->get_right_answer_summary();
    }