コード例 #1
0
ファイル: renderer.php プロジェクト: JP-Git/moodle
    /**
     * Ouputs the form for making an attempt
     *
     * @param quiz_attempt $attemptobj
     * @param int $page Current page number
     * @param array $slots Array of integers relating to questions
     * @param int $id ID of the attempt
     * @param int $nextpage Next page number
     */
    public function attempt_form($attemptobj, $page, $slots, $id, $nextpage) {
        $output = '';

        // Start the form.
        $output .= html_writer::start_tag('form',
                array('action' => $attemptobj->processattempt_url(), 'method' => 'post',
                'enctype' => 'multipart/form-data', 'accept-charset' => 'utf-8',
                'id' => 'responseform'));
        $output .= html_writer::start_tag('div');

        // Print all the questions.
        foreach ($slots as $slot) {
            $output .= $attemptobj->render_question($slot, false,
                    $attemptobj->attempt_url($slot, $page));
        }

        $output .= html_writer::start_tag('div', array('class' => 'submitbtns'));
        $output .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'next',
                'value' => get_string('next')));
        $output .= html_writer::end_tag('div');

        // Some hidden fields to trach what is going on.
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'attempt',
                'value' => $attemptobj->get_attemptid()));
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'thispage',
                'value' => $page, 'id' => 'followingpage'));
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'nextpage',
                'value' => $nextpage));
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'timeup',
                'value' => '0', 'id' => 'timeup'));
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey',
                'value' => sesskey()));
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'scrollpos',
                'value' => '', 'id' => 'scrollpos'));

        // Add a hidden field with questionids. Do this at the end of the form, so
        // if you navigate before the form has finished loading, it does not wipe all
        // the student's answers.
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'slots',
                'value' => implode(',', $slots)));

        // Finish the form.
        $output .= html_writer::end_tag('div');
        $output .= html_writer::end_tag('form');

        return $output;
    }
コード例 #2
0
ファイル: external.php プロジェクト: IFPBMoodle/moodle
 /**
  * Return questions information for a given attempt.
  *
  * @param  quiz_attempt  $attemptobj  the quiz attempt object
  * @param  bool  $review  whether if we are in review mode or not
  * @param  mixed  $page  string 'all' or integer page number
  * @return array array of questions including data
  */
 private static function get_attempt_questions_data(quiz_attempt $attemptobj, $review, $page = 'all')
 {
     global $PAGE;
     $questions = array();
     $contextid = $attemptobj->get_quizobj()->get_context()->id;
     $displayoptions = $attemptobj->get_display_options($review);
     $renderer = $PAGE->get_renderer('mod_quiz');
     foreach ($attemptobj->get_slots($page) as $slot) {
         $question = array('slot' => $slot, 'type' => $attemptobj->get_question_type_name($slot), 'page' => $attemptobj->get_question_page($slot), 'flagged' => $attemptobj->is_question_flagged($slot), 'html' => $attemptobj->render_question($slot, $review, $renderer) . $PAGE->requires->get_end_code());
         if ($attemptobj->is_real_question($slot)) {
             $question['number'] = $attemptobj->get_question_number($slot);
             $question['state'] = (string) $attemptobj->get_question_state($slot);
             $question['status'] = $attemptobj->get_question_status($slot, $displayoptions->correctness);
         }
         if ($displayoptions->marks >= question_display_options::MAX_ONLY) {
             $question['maxmark'] = $attemptobj->get_question_attempt($slot)->get_max_mark();
         }
         if ($displayoptions->marks >= question_display_options::MARK_AND_MAX) {
             $question['mark'] = $attemptobj->get_question_mark($slot);
         }
         $questions[] = $question;
     }
     return $questions;
 }