首页 > 解决方案 > 考试表格摘要中的模块更改

问题描述

我使用 Moodle 3.9.1+ 。我想将摘要考试表更改为 div 以便能够显示每个问题及其旁边的情况,如下所示。事实上,我希望每 5 个问题连续。据我所知,使用 table 是不可能的,因此我想使用 div 来使用 css 这样做。 在此处输入图像描述

我发现文件 /mod/quiz/renderer.php 有一个带有以下代码的函数,可以制作摘要考试表。

public function summary_table($attemptobj, $displayoptions) {

        // Prepare the summary table header.

        $table = new html_table();

        $table->attributes['class'] = 'generaltable quizsummaryofattempt boxaligncenter';

        $table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz'));

        $table->align = array('left', 'left');

        $table->size = array('', '');

        $markscolumn = $displayoptions->marks >= question_display_options::MARK_AND_MAX;

        if ($markscolumn) {

            $table->head[] = get_string('marks', 'quiz');

            $table->align[] = 'left';

            $table->size[] = '';

        }

        $tablewidth = count($table->align);

        $table->data = array();



        // Get the summary info for each question.

        $slots = $attemptobj->get_slots();

        foreach ($slots as $slot) {

            // Add a section headings if we need one here.

            $heading = $attemptobj->get_heading_before_slot($slot);

            if ($heading) {

                $cell = new html_table_cell(format_string($heading));

                $cell->header = true;

                $cell->colspan = $tablewidth;

                $table->data[] = array($cell);

                $table->rowclasses[] = 'quizsummaryheading';

            }



            // Don't display information items.

            if (!$attemptobj->is_real_question($slot)) {

                continue;

            }



            // Real question, show it.

            $flag = '';

            if ($attemptobj->is_question_flagged($slot)) {

                // Quiz has custom JS manipulating these image tags - so we can't use the pix_icon method here.

                $flag = html_writer::empty_tag('img', array('src' => $this->image_url('i/flagged'),

                        'alt' => get_string('flagged', 'question'), 'class' => 'questionflag icon-post'));

            }

            if ($attemptobj->can_navigate_to($slot)) {

                $row = array(html_writer::link($attemptobj->attempt_url($slot),

                        $attemptobj->get_question_number($slot) . $flag),

                        $attemptobj->get_question_status($slot, $displayoptions->correctness));

            } else {

                $row = array($attemptobj->get_question_number($slot) . $flag,

                                $attemptobj->get_question_status($slot, $displayoptions->correctness));

            }

            if ($markscolumn) {

                $row[] = $attemptobj->get_question_mark($slot);

            }

            $table->data[] = $row;

            $table->rowclasses[] = 'quizsummary' . $slot . ' ' . $attemptobj->get_question_state_class(

                    $slot, $displayoptions->correctness);

        }



        // Print the summary table.

        $output = html_writer::table($table);



        return $output;

    }

谁能帮我更改此代码并以 div 格式显示所需的信息?

标签: phpmoodle

解决方案


我终于可以解决问题了,但可能不是很专业:

     * Create the summary page
     *
     * @param quiz_attempt $attemptobj
     * @param mod_quiz_display_options $displayoptions
     */
    public function summary_page($attemptobj, $displayoptions) {
        $output = '';
        $output .= $this->header();
        $output .= $this->heading(format_string($attemptobj->get_quiz_name()));
        $output .= $this->heading(get_string('summaryofattempt', 'quiz'), 3);
        $output .= $this->summary_table($attemptobj, $displayoptions);
        $output .= $this->summary_page_controls($attemptobj);
        $output .= $this->footer();
        return $output;
    }

    /**
     * Generates the table of summarydata
     * sara
     * @param quiz_attempt $attemptobj
     * @param mod_quiz_display_options $displayoptions
     */
    public function summary_table($attemptobj, $displayoptions) {
        // Prepare the summary table header.
        $table = new html_table();
        $table->attributes['class'] = 'generaltable quizsummaryofattempt boxaligncenter';
        $table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz'));
        $table->align = array('left', 'left');
        $table->size = array('', '');
        $markscolumn = $displayoptions->marks >= question_display_options::MARK_AND_MAX;
        if ($markscolumn) {
            $table->head[] = get_string('marks', 'quiz');
            $table->align[] = 'left';
            $table->size[] = '';
        }
        $tablewidth = count($table->align);
        $table->data = array();

        // Get the summary info for each question.
        $slots = $attemptobj->get_slots();
        foreach ($slots as $slot) {
            // Add a section headings if we need one here.
            $heading = $attemptobj->get_heading_before_slot($slot);
            if ($heading) {
                $cell = new html_table_cell(format_string($heading));
                $cell->header = true;
                $cell->colspan = $tablewidth;
                $table->data[] = array($cell);
                $table->rowclasses[] = 'quizsummaryheading';
            }

            // Don't display information items.
            if (!$attemptobj->is_real_question($slot)) {
                continue;
            }

            // Real question, show it.
            $flag = '';
            if ($attemptobj->is_question_flagged($slot)) {
                // Quiz has custom JS manipulating these image tags - so we can't use the pix_icon method here.
                $flag = html_writer::empty_tag('img', array('src' => $this->image_url('i/flagged'),
                        'alt' => get_string('flagged', 'question'), 'class' => 'questionflag icon-post'));
            }
            if ($attemptobj->can_navigate_to($slot)) {
                $row = array(html_writer::link($attemptobj->attempt_url($slot),
                        $attemptobj->get_question_number($slot) . $flag),
                        $attemptobj->get_question_status($slot, $displayoptions->correctness));
            } else {
                $row = array($attemptobj->get_question_number($slot) . $flag,
                                $attemptobj->get_question_status($slot, $displayoptions->correctness));
            }
            if ($markscolumn) {
                $row[] = $attemptobj->get_question_mark($slot);
            }
            $table->data[] = $row;
            $table->rowclasses[] = 'quizsummary' . $slot . ' ' . $attemptobj->get_question_state_class(
                    $slot, $displayoptions->correctness);
            $counter=0;     
            foreach($row as $r)
            {
            if($counter ==0)
            {
            $output .= html_writer::start_tag('div', array('class' => 'qsummary'.' '.'questionNo' .' q'. $slot. ' '.$attemptobj->get_question_status($slot, $displayoptions->correctness)));
            $output .= $r;
            $output .= html_writer::end_tag('div');
            $counter=1; 
            }
            else{
            if($counter ==1)
            {
            $output .= html_writer::start_tag('div', array('class' => 'qsummary' .' '.'questionStat'.' q'. $slot. ' '.$attemptobj->get_question_status($slot, $displayoptions->correctness)));
            $output .= $r;
            $output .= html_writer::end_tag('div');
            $counter=1; 
            }
            }
            }
                            
        }

        // Print the summary table.
    //  $output = html_writer::table($table);

        return $output;
    }

推荐阅读