lib.php

来自「很棒的在线教学系统」· PHP 代码 · 共 396 行 · 第 1/2 页

PHP
396
字号
            $class = 'gradeitem';            if ($grade_item->is_course_item()) {                $class = 'courseitem';            } else if ($grade_item->is_category_item()) {                $class = 'categoryitem';            }            if (in_array($itemid, $unknown)) {                $gradeval = null;            } else if (array_key_exists($itemid, $altered)) {                $gradeval = $altered[$itemid];            } else {                $gradeval = $grade_grade->finalgrade;            }            $data = array();            // all users should know which items are still hidden            $hidden = '';            if ($grade_item->is_hidden()) {                $hidden = ' hidden ';            }            $element = $this->gseq->locate_element($this->gseq->get_item_eid($grade_item));            $header = $this->gseq->get_element_header($element, true, true, true);            /// prints grade item name            $data[] = '<span class="'.$hidden.$class.'">'.$header.'</span>';            /// prints category            $cat = $grade_item->get_parent_category();            $data[] = '<span class="'.$hidden.$class.'">'.$cat->get_name().'</span>';            $hidden = '';            if ($grade_item->is_hidden()) {                // can not see grades in hidden items                $hidden = ' hidden ';            } else if ($canviewhidden and $grade_grade->is_hidden()) {                // if user can see hidden grades, indicate which ones are hidden                $hidden = ' hidden ';            }            /// prints the grade            if ($grade_grade->is_excluded()) {                $excluded = get_string('excluded', 'grades').' ';            } else {                $excluded = '';            }            if ($grade_item->needsupdate) {                $data[] = '<span class="'.$hidden.$class.' gradingerror">'.get_string('error').'</span>';            } else if (!empty($CFG->grade_hiddenasdate) and $grade_grade->get_datesubmitted() and !$canviewhidden and $grade_grade->is_hidden()                   and !$grade_item->is_category_item() and !$grade_item->is_course_item()) {                // the problem here is that we do not have the time when grade value was modified, 'timemodified' is general modification date for grade_grades records                $data[] = '<span class="'.$hidden.$class.' datesubmitted">'.$excluded.get_string('submittedon', 'grades', userdate($grade_grade->get_datesubmitted(), get_string('strftimedatetimeshort'))).'</span>';            } else {                $data[] = '<span class="'.$hidden.$class.'">'.$excluded.grade_format_gradevalue($gradeval, $grade_item, true).'</span>';            }            /// prints percentage            if ($this->showpercentage) {                if ($grade_item->needsupdate) {                    $data[] = '<span class="'.$hidden.$class.'gradingerror">'.get_string('error').'</span>';                } else {                    $data[] = '<span class="'.$hidden.$class.'">'.grade_format_gradevalue($gradeval, $grade_item, true, GRADE_DISPLAY_TYPE_PERCENTAGE).'</span>';                }            }            /// prints rank            if ($this->showrank) {                // TODO: this is broken if hidden grades present!!                if ($grade_item->needsupdate) {                    $data[] = '<span class="'.$hidden.$class.'gradingerror">'.get_string('error').'</span>';                } else if (is_null($gradeval)) {                    // no grade, no rank                    $data[] = '<span class="'.$hidden.$class.'">-</span>';;                } else {                    /// find the number of users with a higher grade                    $sql = "SELECT COUNT(DISTINCT(userid))                              FROM {$CFG->prefix}grade_grades                             WHERE finalgrade > {$grade_grade->finalgrade}                                   AND itemid = {$grade_item->id}";                    $rank = count_records_sql($sql) + 1;                    $data[] = '<span class="'.$hidden.$class.'">'."$rank/$numusers".'</span>';                }            }            /// prints feedback            if (empty($grade_grade->feedback) or (!$canviewhidden and $grade_grade->is_hidden())) {                $data[] = '<div class="'.$hidden.'feedbacktext">&nbsp;</div>';            } else {                $data[] = '<div class="'.$hidden.'feedbacktext">'.format_text($grade_grade->feedback, $grade_grade->feedbackformat).'</div>';            }            $this->table->add_data($data);        }        return true;    }    /**     * Prints or returns the HTML from the flexitable.     * @param bool $return Whether or not to return the data instead of printing it directly.     * @return string     */    function print_table($return=false) {        ob_start();        $this->table->print_html();        $html = ob_get_clean();        if ($return) {            return $html;        } else {            echo $html;        }    }    /**     * Processes the data sent by the form (grades and feedbacks).     * @var array $data     * @return bool Success or Failure (array of errors).     */    function process_data($data) {    }}function grade_report_user_settings_definition(&$mform) {    global $CFG;    $options = array(-1 => get_string('default', 'grades'),                      0 => get_string('hide'),                      1 => get_string('show'));    if (empty($CFG->grade_report_user_showrank)) {        $options[-1] = get_string('defaultprev', 'grades', $options[0]);    } else {        $options[-1] = get_string('defaultprev', 'grades', $options[1]);    }    $mform->addElement('select', 'report_user_showrank', get_string('showrank', 'grades'), $options);    $mform->setHelpButton('report_user_showrank', array('showrank', get_string('showrank', 'grades'), 'grade'));    if (empty($CFG->grade_report_user_showpercentage)) {        $options[-1] = get_string('defaultprev', 'grades', $options[1]);    } else {        $options[-1] = get_string('defaultprev', 'grades', $options[0]);    }    $mform->addElement('select', 'report_user_showpercentage', get_string('showpercentage', 'grades'), $options);    $mform->setHelpButton('report_user_showpercentage', array('showpercentage', get_string('showpercentage', 'grades'), 'grade'));    $options = array(-1 => get_string('default', 'grades'),                      0 => get_string('hide'),                      1 => get_string('showhiddenuntilonly', 'grades'),                      2 => get_string('show'));    if (empty($CFG->grade_report_user_showhiddenitems)) {        $options[-1] = get_string('defaultprev', 'grades', $options[0]);    } else {        $options[-1] = get_string('defaultprev', 'grades', $options[1]);    }    $mform->addElement('select', 'report_user_showhiddenitems', get_string('showhiddenitems', 'grades'), $options);    $mform->setHelpButton('report_user_showhiddenitems', array('showhiddenitems', get_string('showhiddenitems', 'grades'), 'grade'));}function grade_report_user_profilereport($course, $user) {    if (!empty($course->showgrades)) {        $context = get_context_instance(CONTEXT_COURSE, $course->id);        //first make sure we have proper final grades - this must be done before constructing of the grade tree        grade_regrade_final_grades($course->id);        /// return tracking object        $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'user', 'courseid'=>$course->id, 'userid'=>$user->id));        // Create a report instance        $report = new grade_report_user($course->id, $gpr, $context, $user->id);        // print the page        echo '<div class="grade-report-user">'; // css fix to share styles with real report page        print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));        if ($report->fill_table()) {            echo $report->print_table(true);        }        echo '</div>';    }}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?