protected function add_unit(ImsQtiWriter $body, $question) { switch ($question->options->showunits) { case self::UNIT_TEXTBOX: //Edit unit Editable text input element $expected_length = 1; foreach ($question->options->units as $unit) { $expected_length = max($expected_length, strlen($unit->unit)); } return $body->add_extendedTextInteraction(self::UNIT, $expected_length, 1, 1); case self::UNIT_RADIO: //Select units Choice radio element of 2 Units minimum $result = $body->add_choiceInteraction(self::UNIT, 1, false); foreach ($question->options->units as $unit) { $choice = $result->add_simpleChoice($unit->unit); $choice->add_span($unit->unit); } return $result; case self::UNIT_READONLY: //Display unit NON editable text of Unit No1 if (isset($question->options->units[0])) { $result = $body->add_span($question->options->units[0]->unit); } else { $result = null; } return $result; case self::UNIT_HIDE: //No unit display Only numerical answer will be graded //do nothing return null; } }
protected function add_interaction(ImsQtiWriter $body, $question) { return $body->add_extendedTextInteraction(); }
protected function add_interaction(ImsQtiWriter $body, $question) { $expectedLength = 0; foreach ($question->options->answers as $answer) { $expectedLength = max($expectedLength, strlen($answer->answer)); } $result = $body->add_extendedTextInteraction(ImsQtiWriter::RESPONSE, $expectedLength, 1, 1); foreach ($question->options->answers as $answer) { if ($answer->fraction == 1.0 && !ShortanswerUtil::is_regex($answer->answer)) { $this->correct_response->add_value($answer->answer); } } return $result; }