/** * Renders hint button. Could be used by behaviour or question renderer to avoid code duplication while rendering it. * @param hintobj object an object of a child of qtype_specific_hint class */ public function render_hint_button(question_attempt $qa, question_display_options $options, $hintobj) { $question = $qa->get_question(); $hintkey = $hintobj->hint_key(); // Render button. $attributes = array('type' => 'submit', 'id' => $qa->get_behaviour_field_name($hintkey . 'btn'), 'name' => $qa->get_behaviour_field_name($hintkey . 'btn'), 'value' => get_string('hintbtn', 'qbehaviour_adaptivehints', $hintobj->hint_description()), 'class' => 'submit btn'); if ($options->readonly) { $attributes['disabled'] = 'disabled'; } $output = html_writer::empty_tag('input', $attributes); // Cost message. if ($hintobj->penalty_response_based()) { // If penalty is response-based. // Try to get last response. $response = $qa->get_last_qt_data(); if (empty($response)) { $response = null; } $penalty = $hintobj->penalty_for_specific_hint($response); if ($penalty != 0) { $output .= $this->button_cost('withpenaltyapprox', $penalty, $options); // Note that reported penalty is approximation since user could change response in adaptive. } } else { $penalty = $hintobj->penalty_for_specific_hint(null); if ($penalty != 0) { $output .= $this->button_cost('withpenalty', $penalty, $options); } } if (!$options->readonly) { $this->page->requires->js_init_call('M.core_question_engine.init_submit_button', array($attributes['id'], $qa->get_slot())); } return $output; }
public function controls(question_attempt $qa, question_display_options $options) { if ($options->readonly || $qa->get_state() != question_state::$todo) { return ''; } // Hidden input to move the question into the complete state. return html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $qa->get_behaviour_field_name('seen'), 'value' => 1)); }
public function feedback(question_attempt $qa, question_display_options $options) { if (!$qa->get_state()->is_active() || !$options->readonly) { return ''; } $attributes = array('type' => 'submit', 'id' => $qa->get_behaviour_field_name('tryagain'), 'name' => $qa->get_behaviour_field_name('tryagain'), 'value' => get_string('tryagain', 'qbehaviour_interactive'), 'class' => 'submit btn'); if ($options->readonly !== qbehaviour_interactive::READONLY_EXCEPT_TRY_AGAIN) { $attributes['disabled'] = 'disabled'; } $output = html_writer::empty_tag('input', $attributes); if (empty($attributes['disabled'])) { $this->page->requires->js_init_call('M.core_question_engine.init_submit_button', array($attributes['id'], $qa->get_slot())); } return $output; }
/** * Construct the HTML for the optional 'precheck' button, which triggers * a partial submit in which no penalties are imposed but only the * 'Use as example' test cases are run. * This code is identical to the 'submit_button' code in * qbehaviour_renderer::submit_button except for the id and name of the * button. */ protected function precheck_button(question_attempt $qa, question_display_options $options) { if (!$qa->get_state()->is_active()) { return ''; // Not sure if this can happen, but the submit button does it. } $attributes = array('type' => 'submit', 'id' => $qa->get_behaviour_field_name('precheck'), 'name' => $qa->get_behaviour_field_name('precheck'), 'value' => get_string('precheck', 'qbehaviour_adaptive_adapted_for_coderunner'), 'class' => 'submit btn'); if ($options->readonly) { $attributes['disabled'] = 'disabled'; } $output = html_writer::empty_tag('input', $attributes); if (!$options->readonly) { $this->page->requires->js_init_call('M.core_question_engine.init_submit_button', array($attributes['id'], $qa->get_slot())); } return $output; }
public function controls(question_attempt $qa, question_display_options $options) { $a = new stdClass(); $a->help = $this->output->help_icon('certainty', 'qbehaviour_deferredcbm'); $a->choices = $this->certainty_choices($qa->get_behaviour_field_name('certainty'), $qa->get_last_behaviour_var('certainty'), $options->readonly); return html_writer::tag('div', get_string('howcertainareyou', 'qbehaviour_deferredcbm', $a), array('class' => 'certaintychoices')); }
/** * Several behaviours need a submit button, so put the common code here. * The button is disabled if the question is displayed read-only. * @param question_display_options $options controls what should and should not be displayed. * @return string HTML fragment. */ protected function submit_button(question_attempt $qa, question_display_options $options) { $attributes = array('type' => 'submit', 'id' => $qa->get_behaviour_field_name('submit'), 'name' => $qa->get_behaviour_field_name('submit'), 'value' => get_string('check', 'question'), 'class' => 'submit btn'); if ($options->readonly) { $attributes['disabled'] = 'disabled'; } $output = html_writer::empty_tag('input', $attributes); if (!$options->readonly) { $this->page->requires->js_init_call('M.core_question_engine.init_submit_button', array($attributes['id'], $qa->get_slot())); } return $output; }
public function controls(question_attempt $qa, question_display_options $options) { return html_writer::tag('div', get_string('howcertainareyou', 'qbehaviour_deferredcbm', $this->certainly_choices($qa->get_behaviour_field_name('certainty'), $qa->get_last_behaviour_var('certainty'), $options->readonly)), array('class' => 'certaintychoices')); }