示例#1
0
require_once $CFG->libdir . '/gradelib.php';
require_once 'form.php';
$courseid = optional_param('id', SITEID, PARAM_INT);
if (!($course = get_record('course', 'id', $courseid))) {
    print_error('nocourseid');
}
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/grade:manage', $context);
$gpr = new grade_plugin_return(array('type' => 'edit', 'plugin' => 'settings', 'courseid' => $courseid));
$strgrades = get_string('grades');
$pagename = get_string('coursesettings', 'grades');
$navigation = grade_build_nav(__FILE__, $pagename, $courseid);
$returnurl = $CFG->wwwroot . '/grade/index.php?id=' . $course->id;
$mform = new course_settings_form();
$settings = grade_get_settings($course->id);
$mform->set_data($settings);
if ($mform->is_cancelled()) {
    redirect($returnurl);
} else {
    if ($data = $mform->get_data()) {
        $data = (array) $data;
        $general = array('displaytype', 'decimalpoints', 'aggregationposition');
        foreach ($data as $key => $value) {
            if (!in_array($key, $general) and strpos($key, 'report_') !== 0 and strpos($key, 'import_') !== 0 and strpos($key, 'export_') !== 0) {
                continue;
            }
            if ($value == -1) {
                $value = null;
            }
            grade_set_setting($course->id, $key, $value);
 /**
  * Return a grade in user-friendly form, whether it's a scale or not.
  *
  * @param mixed $grade int|null
  * @param boolean $editing Are we allowing changes to this grade?
  * @param int $userid The user id the grade belongs to
  * @param int $modified Timestamp from when the grade was last modified
  * @return string User-friendly representation of grade
  */
 public function display_grade($grade, $editing, $userid = 0, $modified = 0)
 {
     global $DB, $COURSE;
     static $scalegrades = array();
     $o = '';
     if ($this->get_instance()->grade >= 0) {
         // Normal number.
         if ($editing && $this->get_instance()->grade > 0) {
             if ($grade < 0) {
                 $displaygrade = '';
             } else {
                 $settings = grade_get_settings($COURSE->id);
                 if (isset($settings->decimalpoints)) {
                     $displaygrade = format_float($grade, $settings->decimalpoints);
                 } else {
                     $displaygrade = format_float($grade, get_config('moodle', 'grade_decimalpoints'));
                 }
             }
             $o .= '<label class="accesshide" for="quickgrade_' . $userid . '">' . get_string('usergrade', 'assign') . '</label>';
             $o .= '<input type="text"
                           id="quickgrade_' . $userid . '"
                           name="quickgrade_' . $userid . '"
                           value="' . $displaygrade . '"
                           size="6"
                           maxlength="10"
                           class="quickgrade"/>';
             $o .= '&nbsp;/&nbsp;' . format_float($this->get_instance()->grade, 2);
             return $o;
         } else {
             if ($grade == -1 || $grade === null) {
                 $o .= '-';
             } else {
                 $item = $this->get_grade_item();
                 $o .= grade_format_gradevalue($grade, $item);
                 if ($item->get_displaytype() == GRADE_DISPLAY_TYPE_REAL) {
                     // If displaying the raw grade, also display the total value.
                     $o .= '&nbsp;/&nbsp;' . format_float($this->get_instance()->grade, 2);
                 }
             }
             return $o;
         }
     } else {
         // Scale.
         if (empty($this->cache['scale'])) {
             if ($scale = $DB->get_record('scale', array('id' => -$this->get_instance()->grade))) {
                 $this->cache['scale'] = make_menu_from_list($scale->scale);
             } else {
                 $o .= '-';
                 return $o;
             }
         }
         if ($editing) {
             $o .= '<label class="accesshide"
                           for="quickgrade_' . $userid . '">' . get_string('usergrade', 'assign') . '</label>';
             $o .= '<select name="quickgrade_' . $userid . '" class="quickgrade">';
             $o .= '<option value="-1">' . get_string('nograde') . '</option>';
             foreach ($this->cache['scale'] as $optionid => $option) {
                 $selected = '';
                 if ($grade == $optionid) {
                     $selected = 'selected="selected"';
                 }
                 $o .= '<option value="' . $optionid . '" ' . $selected . '>' . $option . '</option>';
             }
             $o .= '</select>';
             return $o;
         } else {
             $scaleid = (int) $grade;
             if (isset($this->cache['scale'][$scaleid])) {
                 $o .= $this->cache['scale'][$scaleid];
                 return $o;
             }
             $o .= '-';
             return $o;
         }
     }
 }