mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-11495 grade letter setting improvements:
* in_null for decimals defaults checks * store letter settings only in database - no cfg settings * separate configuration page for letters only - pluginselector+admin tree * new capability to manage grade letters - similar to scales and outcomes * added grade_letters db index * grade letters related minor bugfixing
This commit is contained in:
parent
5f5faac04a
commit
284abb0925
@ -18,6 +18,8 @@ $scales = new admin_externalpage('scales', get_string('scales'), $CFG->wwwroot.'
|
||||
$ADMIN->add('grades', $scales);
|
||||
$outcomes = new admin_externalpage('outcomes', get_string('outcomes', 'grades'), $CFG->wwwroot.'/grade/edit/outcome/index.php', 'moodle/grade:manage');
|
||||
$ADMIN->add('grades', $outcomes);
|
||||
$letters = new admin_externalpage('letters', get_string('letters', 'grades'), $CFG->wwwroot.'/grade/edit/letter/edit.php', 'moodle/grade:manageletters');
|
||||
$ADMIN->add('grades', $letters);
|
||||
|
||||
/// Grade category settings
|
||||
require_once $CFG->libdir . '/grade/constants.php';
|
||||
|
@ -1,129 +0,0 @@
|
||||
<?php //$Id$
|
||||
|
||||
require_once $CFG->libdir.'/formslib.php';
|
||||
|
||||
class edit_grade_display_form extends moodleform {
|
||||
|
||||
function definition() {
|
||||
global $CFG, $COURSE;
|
||||
|
||||
$mform =& $this->_form;
|
||||
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
|
||||
$course_has_letters = $this->_customdata['course_has_letters'];
|
||||
$coursegradedisplaytype = get_field('grade_items', 'display', 'courseid', $COURSE->id, 'itemtype', 'course');
|
||||
$coursegradedecimals = get_field('grade_items', 'decimals', 'courseid', $COURSE->id, 'itemtype', 'course');
|
||||
|
||||
$mform->addElement('header', 'coursesettings', get_string('coursesettings', 'grades'));
|
||||
|
||||
$gradedisplaytypes = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default'),
|
||||
GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
|
||||
GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
|
||||
GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
|
||||
$label = get_string('coursegradedisplaytype', 'grades') . ' (' . get_string('default', 'grades') . ': '
|
||||
. $gradedisplaytypes[$CFG->grade_report_gradedisplaytype] . ')';
|
||||
$mform->addElement('select', 'display', $label, $gradedisplaytypes);
|
||||
$mform->setHelpButton('display', array(false, get_string('coursegradedisplaytype', 'grades'),
|
||||
false, true, false, get_string('configcoursegradedisplaytype', 'grades')));
|
||||
$mform->setDefault('display', $coursegradedisplaytype);
|
||||
$mform->setType($coursegradedisplaytype, PARAM_INT);
|
||||
|
||||
$options = array(-1=>get_string('default', 'grades'), 0, 1, 2, 3, 4, 5);
|
||||
$label = get_string('decimalpoints', 'grades') . ' (' . get_string('default', 'grades') . ': ' . $options[$CFG->grade_report_decimalpoints] . ')';
|
||||
$mform->addElement('select', 'decimals', $label, $options);
|
||||
$mform->setHelpButton('decimals', array(false, get_string('decimalpoints', 'grades'), false, true, false, get_string("configdecimalpoints", 'grades')));
|
||||
$mform->setDefault('decimals', $coursegradedecimals);
|
||||
|
||||
// Disable decimals if displaytype is not REAL or PERCENTAGE
|
||||
$mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_LETTER);
|
||||
|
||||
$course_set_to_letters = $coursegradedisplaytype == GRADE_DISPLAY_TYPE_LETTER;
|
||||
$course_set_to_default = $coursegradedisplaytype == GRADE_DISPLAY_TYPE_DEFAULT;
|
||||
$site_set_to_letters = $CFG->grade_report_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER;
|
||||
|
||||
// Disable decimals if course displaytype is DEFAULT and site displaytype is LETTER
|
||||
if ($site_set_to_letters) {
|
||||
$mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
|
||||
}
|
||||
|
||||
if ($course_set_to_letters || ($course_set_to_default && $site_set_to_letters)) {
|
||||
|
||||
$mform->addElement('header', 'gradeletters', get_string('gradeletters', 'grades'));
|
||||
$percentages = array(null => get_string('unused', 'grades'));
|
||||
|
||||
$mform->addElement('checkbox', 'override', get_string('overridesitedefaultgradedisplaytype', 'grades'));
|
||||
$mform->setHelpButton('override', array(false, get_string('overridesitedefaultgradedisplaytype', 'grades'),
|
||||
false, true, false, get_string('overridesitedefaultgradedisplaytypehelp', 'grades')));
|
||||
$mform->setDefault('override', $course_has_letters);
|
||||
|
||||
for ($i=100; $i > -1; $i--) {
|
||||
$percentages[$i] = "$i%";
|
||||
}
|
||||
|
||||
$elementsarray = array();
|
||||
|
||||
// Get course letters if they exist
|
||||
if ($letters = get_records('grade_letters', 'contextid', $context->id, 'lowerboundary DESC')) {
|
||||
$i = 1;
|
||||
foreach ($letters as $letter) {
|
||||
$elementsarray[$i]['letter'] = $letter->letter;
|
||||
$elementsarray[$i]['boundary'] = $letter->lowerboundary;
|
||||
$i++;
|
||||
}
|
||||
} else { // Get site default for each letter
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$elementsarray[$i]['letter'] = $CFG->{'grade_report_gradeletter'.$i};
|
||||
$elementsarray[$i]['boundary'] = $CFG->{'grade_report_gradeboundary'.$i};
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($elementsarray as $i => $element) {
|
||||
$letter = $element['letter'];
|
||||
$boundary = $element['boundary'];
|
||||
|
||||
$gradelettername = 'gradeletter' . $i;
|
||||
$gradeletterstring = get_string('gradeletter', 'grades') . " $i";
|
||||
$gradeletterhelp = get_string('configgradeletter', 'grades');
|
||||
|
||||
$gradeboundaryname = 'gradeboundary' . $i;
|
||||
$gradeboundarystring = get_string('gradeboundary', 'grades') . " $i";
|
||||
$gradeboundaryhelp = get_string('configgradeboundary', 'grades');
|
||||
|
||||
$mform->addElement('text', $gradelettername, $gradeletterstring);
|
||||
$mform->setHelpButton($gradelettername, array(false, $gradeletterstring, false, true, false, $gradeletterhelp));
|
||||
$mform->setDefault($gradelettername, $letter);
|
||||
$mform->setType($gradelettername, PARAM_RAW);
|
||||
$mform->disabledIf($gradelettername, 'override');
|
||||
|
||||
$mform->addElement('select', $gradeboundaryname, $gradeboundarystring, $percentages);
|
||||
$mform->setHelpButton($gradeboundaryname, array(false, $gradeboundarystring, false, true, false, $gradeboundaryhelp));
|
||||
$mform->setDefault($gradeboundaryname, $boundary);
|
||||
$mform->setType($gradeboundaryname, PARAM_ALPHANUM);
|
||||
$mform->disabledIf($gradeboundaryname, 'override');
|
||||
}
|
||||
|
||||
$mform->addElement('submit', 'addgradeletter', get_string('addgradeletter', 'grades'));
|
||||
$mform->disabledIf('addgradeletter', 'override');
|
||||
}
|
||||
|
||||
// hidden params
|
||||
$mform->addElement('hidden', 'id', $COURSE->id);
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
/// add return tracking info
|
||||
$gpr = $this->_customdata['gpr'];
|
||||
$gpr->add_mform_elements($mform);
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// buttons
|
||||
$this->add_action_buttons();
|
||||
}
|
||||
|
||||
function definition_after_data() {
|
||||
global $CFG, $COURSE;
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,141 +0,0 @@
|
||||
<?php // $Id$
|
||||
// Allows a creator to edit custom scales, and also display help about scales
|
||||
|
||||
require_once '../../../config.php';
|
||||
require_once $CFG->dirroot.'/grade/lib.php';
|
||||
require_once $CFG->libdir.'/gradelib.php';
|
||||
require_once $CFG->dirroot.'/grade/report/lib.php';
|
||||
require_once 'gradedisplay_form.php';
|
||||
|
||||
$courseid = optional_param('id', 0, PARAM_INT);
|
||||
$addgradeletter = optional_param('addgradeletter', null, PARAM_ALPHANUM);
|
||||
|
||||
/// Make sure they can even access this course
|
||||
if ($courseid) {
|
||||
if (!$course = get_record('course', 'id', $courseid)) {
|
||||
print_error('nocourseid');
|
||||
}
|
||||
require_login($course);
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
require_capability('moodle/course:managescales', $context);
|
||||
} else {
|
||||
require_once $CFG->libdir.'/adminlib.php';
|
||||
admin_externalpage_setup('scales');
|
||||
}
|
||||
|
||||
if (!empty($addgradeletter)) {
|
||||
// Insert a record in the grade_letters table, with 0 as lower boundary and ' - ' as letter
|
||||
$record = new stdClass();
|
||||
$record->contextid = $context->id;
|
||||
$record->letter = 'A';
|
||||
$record->lowerboundary = 0;
|
||||
insert_record('grade_letters', $record);
|
||||
}
|
||||
|
||||
$course_has_letters = get_field('grade_letters', 'contextid', 'contextid', $context->id);
|
||||
|
||||
/// return tracking object
|
||||
$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'gradedisplay', 'courseid'=>$courseid));
|
||||
$returnurl = $gpr->get_return_url($CFG->wwwroot.'/grade/edit/gradedisplay/index.php?id='.$course->id);
|
||||
|
||||
$mform = new edit_grade_display_form(null, array('gpr'=>$gpr, 'course_has_letters' => $course_has_letters));
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($returnurl);
|
||||
|
||||
// form processing
|
||||
} else if ($data = $mform->get_data(false)) {
|
||||
// Delete existing grade_letters for this contextid, whether we add, update or set the grade letters to defaults
|
||||
if ($course_has_letters) {
|
||||
delete_records('grade_letters', 'contextid', $context->id);
|
||||
}
|
||||
|
||||
// Update course item's gradedisplay type
|
||||
if (isset($data->display)) {
|
||||
set_field('grade_items', 'display', $data->display, 'courseid', $courseid, 'itemtype', 'course');
|
||||
}
|
||||
|
||||
// Update course item's decimals type
|
||||
if (isset($data->decimals)) {
|
||||
if ($data->decimals < 0) {
|
||||
$data->decimals = null;
|
||||
}
|
||||
set_field('grade_items', 'decimals', $data->decimals, 'courseid', $courseid, 'itemtype', 'course');
|
||||
}
|
||||
|
||||
// If override is present, add/update entries in grade_letters table
|
||||
if (!empty($data->override)) {
|
||||
$records = array();
|
||||
|
||||
// Loop through grade letters and boundaries
|
||||
foreach ($data as $key => $variable) {
|
||||
preg_match('/[gradeletter|gradeboundary]([0-9]{1,2})/', $key, $matches);
|
||||
$index = null;
|
||||
if (isset($matches[1])) {
|
||||
$index = $matches[1];
|
||||
}
|
||||
|
||||
if (strstr($key, 'gradeletter')) {
|
||||
$records[$index] = new stdClass();
|
||||
$records[$index]->letter = $variable;
|
||||
} elseif (strstr($key, 'gradeboundary')) {
|
||||
if (!empty($records[$index])) {
|
||||
$records[$index]->lowerboundary = $variable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($records as $key => $record) {
|
||||
// Do not insert if either value is empty or set to "unused"
|
||||
$values_set = isset($record->letter) && isset($record->lowerboundary);
|
||||
|
||||
if ($values_set && strlen($record->letter) > 0 && strlen($record->lowerboundary) > 0) {
|
||||
$record->contextid = $context->id;
|
||||
if ($id = insert_record('grade_letters', $record)) {
|
||||
$record = new stdClass();
|
||||
} else {
|
||||
debugging('Error inserting grade_letters record!');
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isset($data->addgradeletter)) {
|
||||
redirect($returnurl, get_string('coursegradedisplayupdated', 'grades'));
|
||||
}
|
||||
}
|
||||
|
||||
$strgrades = get_string('grades');
|
||||
$pagename = get_string('gradedisplay', 'grades');
|
||||
|
||||
$navigation = grade_build_nav(__FILE__, $pagename, array('courseid' => $courseid));
|
||||
|
||||
$strname = get_string('name');
|
||||
$strdelete = get_string('delete');
|
||||
$stredit = get_string('edit');
|
||||
$strused = get_string('used');
|
||||
$stredit = get_string('edit');
|
||||
|
||||
if ($courseid) {
|
||||
/// Print header
|
||||
print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
|
||||
/// Print the plugin selector at the top
|
||||
print_grade_plugin_selector($courseid, 'edit', 'scale');
|
||||
|
||||
} else {
|
||||
admin_externalpage_print_header();
|
||||
}
|
||||
|
||||
print_simple_box_start("center");
|
||||
$mform->display();
|
||||
print_simple_box_end();
|
||||
|
||||
if ($courseid) {
|
||||
print_footer($course);
|
||||
} else {
|
||||
admin_externalpage_print_footer();
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
125
grade/edit/letter/edit.php
Normal file
125
grade/edit/letter/edit.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php // $Id$
|
||||
|
||||
require '../../../config.php';
|
||||
require_once $CFG->libdir.'/gradelib.php';
|
||||
require_once $CFG->dirroot.'/grade/lib.php';
|
||||
require_once 'edit_form.php';
|
||||
|
||||
|
||||
$contextid = optional_param('id', SYSCONTEXTID, PARAM_INT);
|
||||
|
||||
if (!$context = get_context_instance_by_id($contextid)) {
|
||||
error('Incorrect context id');
|
||||
}
|
||||
|
||||
if ($context->contextlevel == CONTEXT_SYSTEM or $context->contextlevel == CONTEXT_COURSECAT) {
|
||||
require_once $CFG->libdir.'/adminlib.php';
|
||||
require_login();
|
||||
admin_externalpage_setup('letters');
|
||||
$admin = true;
|
||||
$returnurl = "$CFG->wwwroot/$CFG->admin";
|
||||
|
||||
|
||||
} else if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
require_login($context->instanceid);
|
||||
$admin = false;
|
||||
$returnurl = $CFG->wwwroot.'/grade/edit/letter/index.php?id='.$context->instanceid;
|
||||
|
||||
} else {
|
||||
error('Incorrect context level');
|
||||
}
|
||||
|
||||
require_capability('moodle/grade:manageletters', $context);
|
||||
|
||||
$strgrades = get_string('grades');
|
||||
$pagename = get_string('letters', 'grades');
|
||||
|
||||
$letters = grade_get_letters($context);
|
||||
$num = count($letters) + 3;
|
||||
|
||||
$data = new object();
|
||||
$data->id = $context->id;
|
||||
|
||||
$i = 1;
|
||||
foreach ($letters as $boundary=>$letter) {
|
||||
$gradelettername = 'gradeletter'.$i;
|
||||
$gradeboundaryname = 'gradeboundary'.$i;
|
||||
|
||||
$data->$gradelettername = $letter;
|
||||
$data->$gradeboundaryname = $boundary;
|
||||
$i++;
|
||||
}
|
||||
$data->override = record_exists('grade_letters', 'contextid', $contextid);
|
||||
|
||||
$mform = new edit_letter_form(null, array('num'=>$num, 'admin'=>$admin));
|
||||
$mform->set_data($data);
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($returnurl);
|
||||
|
||||
} else if ($data = $mform->get_data()) {
|
||||
if (empty($data->override)) {
|
||||
delete_records('grade_letters', 'contextid', $context->id);
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
||||
$letters = array();
|
||||
for($i=1; $i<$num+1; $i++) {
|
||||
$gradelettername = 'gradeletter'.$i;
|
||||
$gradeboundaryname = 'gradeboundary'.$i;
|
||||
|
||||
if (array_key_exists($gradeboundaryname, $data) and $data->$gradeboundaryname != -1) {
|
||||
$letter = trim($data->$gradelettername);
|
||||
if ($letter == '') {
|
||||
continue;
|
||||
}
|
||||
$letters[$data->$gradeboundaryname] = $letter;
|
||||
}
|
||||
}
|
||||
krsort($letters, SORT_NUMERIC);
|
||||
|
||||
$old_ids = array();
|
||||
if ($records = get_records('grade_letters', 'contextid', $context->id, 'lowerboundary ASC', 'id')) {
|
||||
$old_ids = array_keys($records);
|
||||
}
|
||||
|
||||
foreach($letters as $boundary=>$letter) {
|
||||
$record = new object();
|
||||
$record->letter = $letter;
|
||||
$record->lowerboundary = $boundary;
|
||||
$record->contextid = $context->id;
|
||||
|
||||
if ($old_id = array_pop($old_ids)) {
|
||||
$record->id = $old_id;
|
||||
update_record('grade_letters', $record);
|
||||
} else {
|
||||
insert_record('grade_letters', $record);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($old_ids as $old_id) {
|
||||
delete_records('grade_letters', 'id', $old_id);
|
||||
}
|
||||
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
||||
|
||||
//page header
|
||||
if ($admin) {
|
||||
admin_externalpage_print_header();
|
||||
|
||||
} else {
|
||||
$navigation = grade_build_nav(__FILE__, $pagename, $COURSE->id);
|
||||
/// Print header
|
||||
print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($COURSE));
|
||||
|
||||
$currenttab = 'lettersedit';
|
||||
require('tabs.php');
|
||||
}
|
||||
|
||||
$mform->display();
|
||||
|
||||
print_footer($COURSE);
|
||||
?>
|
||||
|
56
grade/edit/letter/edit_form.php
Normal file
56
grade/edit/letter/edit_form.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php //$Id$
|
||||
|
||||
require_once $CFG->libdir.'/formslib.php';
|
||||
|
||||
class edit_letter_form extends moodleform {
|
||||
|
||||
function definition() {
|
||||
$mform =& $this->_form;
|
||||
$num = $this->_customdata['num'];
|
||||
$admin = $this->_customdata['admin'];
|
||||
|
||||
$mform->addElement('header', 'gradeletters', get_string('gradeletters', 'grades'));
|
||||
|
||||
$mform->addElement('checkbox', 'override', get_string('overridesitedefaultgradedisplaytype', 'grades'));
|
||||
$mform->setHelpButton('override', array(false, get_string('overridesitedefaultgradedisplaytype', 'grades'),
|
||||
false, true, false, get_string('overridesitedefaultgradedisplaytypehelp', 'grades')));
|
||||
|
||||
$gradeletterhelp = get_string('configgradeletter', 'grades');
|
||||
$gradeboundaryhelp = get_string('configgradeboundary', 'grades');
|
||||
$gradeletter = get_string('gradeletter', 'grades');
|
||||
$gradeboundary = get_string('gradeboundary', 'grades');
|
||||
|
||||
$percentages = array(-1 => get_string('unused', 'grades'));
|
||||
for ($i=100; $i > -1; $i--) {
|
||||
$percentages[$i] = "$i %";
|
||||
}
|
||||
|
||||
for($i=1; $i<$num+1; $i++) {
|
||||
$gradelettername = 'gradeletter'.$i;
|
||||
$gradeboundaryname = 'gradeboundary'.$i;
|
||||
|
||||
$mform->addElement('text', $gradelettername, $gradeletter." $i");
|
||||
$mform->setHelpButton($gradelettername, array(false, $gradeletter." $i", false, true, false, $gradeletterhelp));
|
||||
$mform->setType($gradelettername, PARAM_TEXT);
|
||||
$mform->disabledIf($gradelettername, 'override', 'notchecked');
|
||||
$mform->disabledIf($gradelettername, $gradeboundaryname, 'eq', -1);
|
||||
|
||||
$mform->addElement('select', $gradeboundaryname, $gradeboundary." $i", $percentages);
|
||||
$mform->setHelpButton($gradeboundaryname, array(false, $gradeboundary." $i", false, true, false, $gradeboundaryhelp));
|
||||
$mform->setDefault($gradeboundaryname, -1);
|
||||
$mform->setType($gradeboundaryname, PARAM_INT);
|
||||
$mform->disabledIf($gradeboundaryname, 'override', 'notchecked');
|
||||
}
|
||||
|
||||
// hidden params
|
||||
$mform->addElement('hidden', 'id');
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// buttons
|
||||
$this->add_action_buttons(!$admin);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
57
grade/edit/letter/index.php
Normal file
57
grade/edit/letter/index.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php // $Id$
|
||||
|
||||
require_once '../../../config.php';
|
||||
require_once $CFG->dirroot.'/grade/lib.php';
|
||||
require_once $CFG->libdir.'/gradelib.php';
|
||||
|
||||
$courseid = optional_param('id', SITEID, PARAM_INT);
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
|
||||
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'=>'letter', 'courseid'=>$courseid));
|
||||
|
||||
$strgrades = get_string('grades');
|
||||
$pagename = get_string('letters', 'grades');
|
||||
|
||||
$navigation = grade_build_nav(__FILE__, $pagename, $courseid);
|
||||
|
||||
/// Print header
|
||||
print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
|
||||
/// Print the plugin selector at the top
|
||||
print_grade_plugin_selector($courseid, 'edit', 'letter');
|
||||
|
||||
$currenttab = 'lettersview';
|
||||
require('tabs.php');
|
||||
|
||||
$letters = grade_get_letters($context);
|
||||
|
||||
$data = array();
|
||||
|
||||
$max = 100;
|
||||
foreach($letters as $boundary=>$letter) {
|
||||
$line = array();
|
||||
$line[] = format_float($max,2).' %';
|
||||
$line[] = format_float($boundary,2).' %';
|
||||
$line[] = format_string($letter);
|
||||
$data[] = $line;
|
||||
$max = $boundary - 0.01;
|
||||
}
|
||||
|
||||
$table = new object();
|
||||
$table->head = array(get_string('max', 'grades'), get_string('min', 'grades'), get_string('letter', 'grades'));
|
||||
$table->size = array('30%', '30%', '40%');
|
||||
$table->align = array('left', 'left', 'left');
|
||||
$table->width = '30%';
|
||||
$table->data = $data;
|
||||
print_table($table);
|
||||
|
||||
print_footer($course);
|
||||
|
||||
?>
|
||||
|
20
grade/edit/letter/tabs.php
Normal file
20
grade/edit/letter/tabs.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php // $Id$
|
||||
$row = $tabs = array();
|
||||
|
||||
$row[] = new tabobject('lettersview',
|
||||
$CFG->wwwroot.'/grade/edit/letter/index.php?id='.$COURSE->id,
|
||||
get_string('letters', 'grades'));
|
||||
|
||||
if (has_capability('moodle/grade:manageletters', $context)) {
|
||||
$row[] = new tabobject('lettersedit',
|
||||
$CFG->wwwroot.'/grade/edit/letter/edit.php?id='.$context->id,
|
||||
get_string('edit'));
|
||||
}
|
||||
|
||||
$tabs[] = $row;
|
||||
|
||||
echo '<div class="letterdisplay">';
|
||||
print_tabs($tabs, $currenttab);
|
||||
echo '</div>';
|
||||
|
||||
?>
|
@ -296,14 +296,6 @@ function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $r
|
||||
$menu[$url] = get_string('edittree', 'grades');
|
||||
}
|
||||
|
||||
if (has_capability('moodle/grade:manage', $context)) {
|
||||
$url = 'edit/gradedisplay/index.php?id='.$courseid;
|
||||
if ($active_type == 'edit' and $active_plugin == 'gradedisplay' ) {
|
||||
$active = $url;
|
||||
}
|
||||
$menu[$url] = get_string('gradedisplay', 'grades');
|
||||
}
|
||||
|
||||
if (has_capability('moodle/course:managescales', $context)) {
|
||||
$url = 'edit/scale/index.php?id='.$courseid;
|
||||
if ($active_type == 'edit' and $active_plugin == 'scale' ) {
|
||||
@ -324,6 +316,15 @@ function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $r
|
||||
}
|
||||
$menu[$url] = get_string('outcomes', 'grades');
|
||||
}
|
||||
|
||||
if (has_capability('moodle/course:manage', $context)) {
|
||||
$url = 'edit/letter/index.php?id='.$courseid;
|
||||
if ($active_type == 'edit' and $active_plugin == 'letter' ) {
|
||||
$active = $url;
|
||||
}
|
||||
$menu[$url] = get_string('letters', 'grades');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// finally print/return the popup form
|
||||
|
@ -1,9 +1,6 @@
|
||||
<?php // $Id$
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
$strgradeboundary = get_string('gradeboundary', 'grades');
|
||||
$strconfiggradeboundary = get_string('configgradeboundary', 'grades');
|
||||
$strgradeletter = get_string('gradeletter', 'grades');
|
||||
$strconfiggradeletter = get_string('configgradeletter', 'grades');
|
||||
require_once($CFG->libdir.'/grade/constants.php');
|
||||
|
||||
$strinherit = get_string('inherit', 'grades');
|
||||
$strpercentage = get_string('percentage', 'grades');
|
||||
$strreal = get_string('real', 'grades');
|
||||
@ -111,18 +108,5 @@ $settings->add(new admin_setting_configselect('grade_report_rangesdecimalpoints'
|
||||
'4' => '4',
|
||||
'5' => '5')));
|
||||
|
||||
$percentages = array(GRADE_REPORT_PREFERENCE_UNUSED => get_string('unused', 'grades'));
|
||||
for ($i=100; $i > -1; $i--) {
|
||||
$percentages[$i] = "$i%";
|
||||
}
|
||||
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$default = abs(($i-10)*10);
|
||||
$settings->add(new admin_setting_configselect('grade_report_gradeboundary'.$i, $strgradeboundary . " $i",
|
||||
$strconfiggradeboundary, $default, $percentages));
|
||||
|
||||
$settings->add(new admin_setting_configtext('grade_report_gradeletter'.$i, $strgradeletter . " $i",
|
||||
$strconfiggradeletter, ''));
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -255,25 +255,8 @@ class grade_report {
|
||||
*/
|
||||
function get_grade_letters() {
|
||||
global $COURSE;
|
||||
$letters = array();
|
||||
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
|
||||
|
||||
if ($records = get_records('grade_letters', 'contextid', $context->id)) {
|
||||
foreach ($records as $record) {
|
||||
if (!is_null($record->lowerboundary) && !empty($record->letter)) {
|
||||
$letters[$record->lowerboundary] = $record->letter;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$boundary = grade_report::get_pref('gradeboundary' . $i);
|
||||
$letter = grade_report::get_pref('gradeletter' . $i);
|
||||
if (!is_null($boundary) && $boundary != -1 && !empty($letter)) {
|
||||
$letters[$boundary] = $letter;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $letters;
|
||||
$letters = grade_get_letters($context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1043,7 +1043,16 @@ $moodle_capabilities = array(
|
||||
),
|
||||
|
||||
'moodle/grade:manageoutcomes' => array(
|
||||
'riskbitmask' => RISK_PERSONAL,
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
'legacy' => array(
|
||||
'editingteacher' => CAP_ALLOW,
|
||||
'admin' => CAP_ALLOW
|
||||
),
|
||||
'clonepermissionsfrom' => 'moodle/course:managegrades'
|
||||
),
|
||||
|
||||
'moodle/grade:manageletters' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
'legacy' => array(
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="lib/db" VERSION="20070925" COMMENT="XMLDB file for core Moodle tables"
|
||||
<XMLDB PATH="lib/db" VERSION="20070928" COMMENT="XMLDB file for core Moodle tables"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@ -1698,6 +1698,9 @@
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="contextid-lowerboundary" UNIQUE="false" FIELDS="contextid, lowerboundary" COMMENT="index used when fetching context letters"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
<STATEMENTS>
|
||||
|
@ -2242,6 +2242,17 @@ function xmldb_main_upgrade($oldversion=0) {
|
||||
$result = $result && change_field_notnull($table, $field);
|
||||
}
|
||||
|
||||
if ($result && $oldversion < 2007092801) {
|
||||
|
||||
/// Define index contextidlowerboundary (not unique) to be added to grade_letters
|
||||
$table = new XMLDBTable('grade_letters');
|
||||
$index = new XMLDBIndex('contextid-lowerboundary');
|
||||
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
|
||||
|
||||
/// Launch add index contextidlowerboundary
|
||||
$result = $result && add_index($table, $index);
|
||||
}
|
||||
|
||||
/*
|
||||
/// drop old gradebook tables
|
||||
if ($result && $oldversion < xxxxxxxx) {
|
||||
|
@ -504,21 +504,8 @@ function grade_format_gradevalue($value, &$grade_item, $localized=true, $display
|
||||
*/
|
||||
function grade_get_letters($context=null) {
|
||||
if (empty($context)) {
|
||||
// defaults
|
||||
// TODO: maybe we should hardcode defaults here and remove them from admin tree
|
||||
// it seems a bit less than optional to use report preferences for this
|
||||
// when letters are used in other types of plugins too
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot.'/grade/report/lib.php');
|
||||
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$boundary = grade_report::get_pref('gradeboundary' . $i);
|
||||
$letter = grade_report::get_pref('gradeletter' . $i);
|
||||
if (!is_null($boundary) && $boundary != -1 && !empty($letter)) {
|
||||
$letters[$boundary] = $letter;
|
||||
}
|
||||
}
|
||||
return $letters;
|
||||
//default grading letters
|
||||
return array('93'=>'A', '90'=>'A-', '87'=>'B+', '83'=>'B', '80'=>'B-', '77'=>'C+', '73'=>'C', '70'=>'C-', '67'=>'D+', '60'=>'D', '0'=>'F');
|
||||
}
|
||||
|
||||
static $cache = array();
|
||||
@ -537,13 +524,11 @@ function grade_get_letters($context=null) {
|
||||
array_unshift($contexts, $context->id);
|
||||
|
||||
foreach ($contexts as $ctxid) {
|
||||
if ($records = get_records('grade_letters', 'contextid', $ctxid, 'lowerboundary DESC')) { //TODO: add index?
|
||||
if ($records = get_records('grade_letters', 'contextid', $ctxid, 'lowerboundary DESC')) {
|
||||
foreach ($records as $record) {
|
||||
if (!is_null($record->lowerboundary) && !empty($record->letter)) {
|
||||
$letters[$record->lowerboundary] = $record->letter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($letters)) {
|
||||
$cache[$context->id] = $letters;
|
||||
|
@ -6,7 +6,7 @@
|
||||
// This is compared against the values stored in the database to determine
|
||||
// whether upgrades should be performed (see lib/db/*.php)
|
||||
|
||||
$version = 2007092501; // YYYYMMDD = date
|
||||
$version = 2007092801; // YYYYMMDD = date
|
||||
// XY = increments within a single day
|
||||
|
||||
$release = '1.9 Beta +'; // Human-friendly version name
|
||||
|
Loading…
x
Reference in New Issue
Block a user