Example #1
0
 public function start_attempt(question_attempt_step $step, $variant)
 {
     $this->stemorder = array_keys($this->stems);
     if ($this->shufflestems) {
         shuffle($this->stemorder);
     }
     $step->set_qt_var('_stemorder', implode(',', $this->stemorder));
     $choiceorder = array_keys($this->choices);
     shuffle($choiceorder);
     $step->set_qt_var('_choiceorder', implode(',', $choiceorder));
     $this->set_choiceorder($choiceorder);
 }
Example #2
0
 public function start_attempt(question_attempt_step $step, $variant) {
     $this->order = array_keys($this->answers);
     if ($this->shuffleanswers) {
         shuffle($this->order);
     }
     $step->set_qt_var('_order', implode(',', $this->order));
 }
Example #3
0
 public function start_attempt(question_attempt_step $step, $variant)
 {
     foreach ($this->choices as $group => $choices) {
         $choiceorder = array_keys($choices);
         if ($this->shufflechoices) {
             shuffle($choiceorder);
         }
         $step->set_qt_var('_choiceorder' . $group, implode(',', $choiceorder));
         $this->set_choiceorder($group, $choiceorder);
     }
 }
Example #4
0
 public function start_attempt(question_attempt_step $step, $variant)
 {
     $saquestions = $this->questionsloader->load_questions();
     foreach ($saquestions as $wrappedquestion) {
         // Store and save stem text and format.
         $this->stems[$wrappedquestion->id] = $wrappedquestion->questiontext;
         $this->stemformat[$wrappedquestion->id] = $wrappedquestion->questiontextformat;
         $step->set_qt_var('_stem_' . $wrappedquestion->id, $this->stems[$wrappedquestion->id]);
         $step->set_qt_var('_stemformat_' . $wrappedquestion->id, $this->stemformat[$wrappedquestion->id]);
         // Find, store and save right choice id.
         $key = $this->find_right_answer($wrappedquestion);
         $this->right[$wrappedquestion->id] = $key;
         $step->set_qt_var('_right_' . $wrappedquestion->id, $key);
         // No need to save saquestions, it will be saved by parent class in _stemorder.
     }
     // Save all the choices.
     foreach ($this->choices as $key => $answer) {
         $step->set_qt_var('_choice_' . $key, $answer);
     }
     parent::start_attempt($step, $variant);
 }
 /**
  * Start a new attempt at this question, storing any information that will
  * be needed later in the step.
  *
  * This is where the question can do any initialisation required on a
  * per-attempt basis. For example, this is where the multiple choice
  * question type randomly shuffles the choices (if that option is set).
  *
  * Any information about how the question has been set up for this attempt
  * should be stored in the $step, by calling $step->set_qt_var(...).
  *
  * @param question_attempt_step The first step of the {@link question_attempt}
  *      being started. Can be used to store state.
  * @param int $varant which variant of this question to start. Will be between
  *      1 and {@link get_num_variants()} inclusive.
  */
 public function start_attempt(\question_attempt_step $step, $variant)
 {
     // vars loaded by questiontype->initialize_question_instance()
     foreach ($this->vars as $var) {
         $values = programmedresp_get_random_value($var);
         if (!$values) {
             print_error('errordb', 'qtype_programmedresp');
         }
         $valuetodisplay = implode(', ', $values);
         str_replace('{$' . $var->varname . '}', $valuetodisplay, $this->questiontext, $count);
         // If $var->varname is found in questiontext ($count == true), then store it
         $count && $step->set_qt_var('_var_' . $var->id, $valuetodisplay);
     }
 }
 public function start_attempt(question_attempt_step $step, $variant)
 {
     $this->answers = $this->get_ordering_answers();
     $this->options = $this->get_ordering_options();
     $countanswers = count($this->answers);
     // sanitize "selecttype"
     $selecttype = $this->options->selecttype;
     $selecttype = max(0, $selecttype);
     $selecttype = min(2, $selecttype);
     // sanitize "selectcount"
     $selectcount = $this->options->selectcount;
     $selectcount = max(3, $selectcount);
     $selectcount = min($countanswers, $selectcount);
     // ensure consistency between "selecttype" and "selectcount"
     switch (true) {
         case $selecttype == 0:
             $selectcount = $countanswers;
             break;
         case $selectcount == $countanswers:
             $selecttype = 0;
             break;
     }
     // extract answer ids
     switch ($selecttype) {
         case 0:
             // all
             $answerids = array_keys($this->answers);
             break;
         case 1:
             // random subset
             $answerids = array_rand($this->answers, $selectcount);
             break;
         case 2:
             // contiguous subset
             $answerids = array_keys($this->answers);
             $offset = mt_rand(0, $countanswers - $selectcount);
             $answerids = array_slice($answerids, $offset, $selectcount, true);
             break;
     }
     $this->correctresponse = $answerids;
     $step->set_qt_var('_correctresponse', implode(',', $this->correctresponse));
     shuffle($answerids);
     $this->currentresponse = $answerids;
     $step->set_qt_var('_currentresponse', implode(',', $this->currentresponse));
 }
Example #7
0
 public function start_attempt(question_attempt_step $step, $variant)
 {
     shuffle($this->allanswers);
     $step->set_qt_var('_allanswers', implode(',', $this->allanswers));
 }
 public function test_get_submitted_data()
 {
     $step = new question_attempt_step(array('x' => 1, '-y' => 'frog'));
     $step->set_qt_var('_x', 1);
     $step->set_behaviour_var('_x', 2);
     $this->assertEquals(array('x' => 1, '-y' => 'frog'), $step->get_submitted_data());
 }
Example #9
0
 public function start_attempt(question_attempt_step $step, $variant)
 {
     $step->set_qt_var('_separators', $this->ap->get_point() . '$' . $this->ap->get_separator());
 }
Example #10
0
    public static function start_attempt(
            qtype_calculated_question_with_expressions $question,
            question_attempt_step $step, $variant) {

        $question->vs = new qtype_calculated_variable_substituter(
                $question->datasetloader->get_values($variant),
                get_string('decsep', 'langconfig'));
        $question->calculate_all_expressions();

        foreach ($question->vs->get_values() as $name => $value) {
            $step->set_qt_var('_var_' . $name, $value);
        }
    }
Example #11
0
 public function start_attempt(question_attempt_step $step, $variant)
 {
     // Work out the right seed to use.
     if (!is_null($this->seed)) {
         // Nasty hack, but if seed has already been set, then use that. This is
         // used by the questiontestrun.php script to allow non-deployed
         // variants to be browsed.
     } else {
         if (!$this->has_random_variants()) {
             // Randomisation not used.
             $this->seed = 1;
         } else {
             if (!empty($this->deployedseeds)) {
                 // Question has a fixed number of variants.
                 $this->seed = $this->deployedseeds[$variant - 1] + 0;
                 // Don't know why this is coming out as a string. + 0 converts to int.
             } else {
                 // This question uses completely free randomisation.
                 $this->seed = $variant;
             }
         }
     }
     $step->set_qt_var('_seed', $this->seed);
     $this->initialise_question_from_seed();
 }