Example #1
0
 /**
  * Update a question_attempts row to refect any changes in a question_attempt
  * (but not any of its steps).
  * @param question_attempt $qa the question attempt that has changed.
  */
 public function update_question_attempt(question_attempt $qa)
 {
     $record = new stdClass();
     $record->id = $qa->get_database_id();
     $record->maxmark = $qa->get_max_mark();
     $record->minfraction = $qa->get_min_fraction();
     $record->maxfraction = $qa->get_max_fraction();
     $record->flagged = $qa->is_flagged();
     $record->questionsummary = $qa->get_question_summary();
     $record->rightanswer = $qa->get_right_answer_summary();
     $record->responsesummary = $qa->get_response_summary();
     $record->timemodified = time();
     $this->db->update_record('question_attempts', $record);
 }
 public function test_cannot_get_min_fraction_before_start()
 {
     $qa = new question_attempt($this->question, 0);
     $this->setExpectedException('moodle_exception');
     $qa->get_min_fraction();
 }
Example #3
0
 public function test_cannot_get_min_fraction_before_start()
 {
     $qa = new question_attempt($this->question, 0);
     $this->expectException();
     $qa->get_min_fraction();
 }
Example #4
0
 public function manual_comment_fields(question_attempt $qa, question_display_options $options)
 {
     $inputname = $qa->get_behaviour_field_name('comment');
     $id = $inputname . '_id';
     list($commenttext, $commentformat) = $qa->get_current_manual_comment();
     $editor = editors_get_preferred_editor($commentformat);
     $strformats = format_text_menu();
     $formats = $editor->get_supported_formats();
     foreach ($formats as $fid) {
         $formats[$fid] = $strformats[$fid];
     }
     $commenttext = format_text($commenttext, $commentformat, array('para' => false));
     $editor->set_text($commenttext);
     $editor->use_editor($id, array('context' => $options->context));
     $commenteditor = html_writer::tag('div', html_writer::tag('textarea', s($commenttext), array('id' => $id, 'name' => $inputname, 'rows' => 10, 'cols' => 60)));
     $editorformat = '';
     if (count($formats) == 1) {
         reset($formats);
         $editorformat .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $inputname . 'format', 'value' => key($formats)));
     } else {
         $editorformat = html_writer::start_tag('div', array('class' => 'fitem'));
         $editorformat .= html_writer::start_tag('div', array('class' => 'fitemtitle'));
         $editorformat .= html_writer::tag('label', get_string('format'), array('for' => 'menu' . $inputname . 'format'));
         $editorformat .= html_writer::end_tag('div');
         $editorformat .= html_writer::start_tag('div', array('class' => 'felement fhtmleditor'));
         $editorformat .= html_writer::select($formats, $inputname . 'format', $commentformat, '');
         $editorformat .= html_writer::end_tag('div');
         $editorformat .= html_writer::end_tag('div');
     }
     $comment = html_writer::tag('div', html_writer::tag('div', html_writer::tag('label', get_string('comment', 'question'), array('for' => $id)), array('class' => 'fitemtitle')) . html_writer::tag('div', $commenteditor, array('class' => 'felement fhtmleditor')), array('class' => 'fitem'));
     $comment .= $editorformat;
     $mark = '';
     if ($qa->get_max_mark()) {
         $currentmark = $qa->get_current_manual_mark();
         $maxmark = $qa->get_max_mark();
         $fieldsize = strlen($qa->format_max_mark($options->markdp)) - 1;
         $markfield = $qa->get_behaviour_field_name('mark');
         $attributes = array('type' => 'text', 'size' => $fieldsize, 'name' => $markfield, 'id' => $markfield);
         if (!is_null($currentmark)) {
             $attributes['value'] = $currentmark;
         }
         $a = new stdClass();
         $a->max = $qa->format_max_mark($options->markdp);
         $a->mark = html_writer::empty_tag('input', $attributes);
         $markrange = html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $qa->get_behaviour_field_name('maxmark'), 'value' => $maxmark)) . html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $qa->get_control_field_name('minfraction'), 'value' => $qa->get_min_fraction())) . html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $qa->get_control_field_name('maxfraction'), 'value' => $qa->get_max_fraction()));
         $error = $qa->validate_manual_mark($currentmark);
         $errorclass = '';
         if ($error !== '') {
             $erroclass = ' error';
             $error = html_writer::tag('span', $error, array('class' => 'error')) . html_writer::empty_tag('br');
         }
         $mark = html_writer::tag('div', html_writer::tag('div', html_writer::tag('label', get_string('mark', 'question'), array('for' => $markfield)), array('class' => 'fitemtitle')) . html_writer::tag('div', $error . get_string('xoutofmax', 'question', $a) . $markrange, array('class' => 'felement ftext' . $errorclass)), array('class' => 'fitem'));
     }
     return html_writer::tag('fieldset', html_writer::tag('div', $comment . $mark, array('class' => 'fcontainer clearfix')), array('class' => 'hidden'));
 }