MDL-11433 Implemented grade_items.decimals instead of user preference in grader report.

This commit is contained in:
nicolasconnault 2007-09-25 14:40:49 +00:00
parent c0ca082d2f
commit 31a6c06c46
13 changed files with 114 additions and 83 deletions

View File

@ -11,6 +11,7 @@ class edit_grade_display_form extends moodleform {
$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'));
@ -18,16 +19,32 @@ class edit_grade_display_form extends moodleform {
GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
$mform->addElement('select', 'gradedisplaytype', get_string('coursegradedisplaytype', 'grades'), $gradedisplaytypes);
$mform->setHelpButton('gradedisplaytype', array(false, get_string('coursegradedisplaytype', '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('gradedisplaytype', $coursegradedisplaytype);
$mform->setDefault('display', $coursegradedisplaytype);
$mform->setType($coursegradedisplaytype, PARAM_INT);
$options = array(GRADE_DECIMALS_DEFAULT => 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'));

View File

@ -51,8 +51,16 @@ if ($mform->is_cancelled()) {
}
// Update course item's gradedisplay type
if (isset($data->gradedisplaytype)) {
set_field('grade_items', 'display', $data->gradedisplaytype, 'courseid', $courseid, 'itemtype', 'course');
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 (strlen($data->decimals) < 1) {
$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

View File

@ -110,8 +110,7 @@ if ($grade = get_record('grade_grades', 'itemid', $grade_item->id, 'userid', $us
$grade->finalgrade = (int)$grade->finalgrade;
}
} else if ($grade_item->gradetype == GRADE_TYPE_VALUE) {
$decimalpoints = grade_report::get_pref('decimalpoints', $grade_item->id);
$grade->finalgrade = format_float($grade->finalgrade, $decimalpoints);
$grade->finalgrade = format_float($grade->finalgrade, $grade_item->get_decimals());
}
$grade->oldgrade = $grade->finalgrade;

View File

@ -26,28 +26,17 @@ if ($mform->is_cancelled()) {
redirect($returnurl);
}
if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
if ($item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) {
// redirect if outcomeid present
if (!empty($item->outcomeid) && !empty($CFG->enableoutcomes)) {
$url = $CFG->wwwroot.'/grade/edit/tree/outcomeitem.php?id='.$id.'&amp;courseid='.$courseid;
redirect($gpr->add_url_params($url));
}
// Get Item preferences
$item->pref_gradedisplaytype = grade_report::get_pref('gradedisplaytype', $item->id);
$item->pref_decimalpoints = grade_report::get_pref('decimalpoints', $item->id);
$item->calculation = grade_item::denormalize_formula($item->calculation, $course->id);
$decimalpoints = grade_report::get_pref('decimalpoints', $item->id);
$item->calculation = grade_item::denormalize_formula($item->calculation, $courseid);
} else {
$item = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual'), false);
// Get Item preferences
$item->pref_gradedisplaytype = grade_report::get_pref('gradedisplaytype');
$item->pref_decimalpoints = grade_report::get_pref('decimalpoints');
$decimalpoints = grade_report::get_pref('decimalpoints');
}
$decimalpoints = $item->get_decimals();
if ($item->hidden > 1) {
$item->hiddenuntil = $item->hidden;
@ -91,9 +80,13 @@ if ($data = $mform->get_data(false)) {
$grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
grade_item::set_properties($grade_item, $data);
$grade_item->outcomeid = null;
// Handle null decimals value
if (strlen($data->decimals) < 1) {
$grade_item->decimals = null;
}
if (empty($grade_item->id)) {
$grade_item->itemtype = 'manual'; // all new items to be manual only
$grade_item->insert();
@ -112,19 +105,6 @@ if ($data = $mform->get_data(false)) {
$grade_item->set_locktime($locktime); // locktime first - it might be removed when unlocking
$grade_item->set_locked($locked, false, true);
// Handle user preferences
if (isset($data->pref_gradedisplaytype)) {
if (!grade_report::set_pref('gradedisplaytype', $data->pref_gradedisplaytype, $grade_item->id)) {
error("Could not set preference gradedisplaytype to $value for this grade item");
}
}
if (isset($data->pref_decimalpoints)) {
if (!grade_report::set_pref('decimalpoints', $data->pref_decimalpoints, $grade_item->id)) {
error("Could not set preference decimalpoints to $value for this grade item");
}
}
redirect($returnurl);
}

View File

@ -88,16 +88,38 @@ class edit_item_form extends moodleform {
$default_gradedisplaytype = $site_gradedisplaytype;
}
$options = array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default', 'grades'),
$options = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'),
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('gradedisplaytype', 'grades') . ' (' . get_string('default', 'grades')
. ': ' . $options[$default_gradedisplaytype] . ')';
$label = get_string('gradedisplaytype', 'grades') . ' (' . get_string('default', 'grades') . ': ' . $options[$default_gradedisplaytype] . ')';
$mform->addElement('select', 'display', $label, $options);
$mform->setHelpButton('display', array(false, get_string('gradedisplaytype', 'grades'),
false, true, false, get_string("configgradedisplaytype", 'grades')));
// Determine default value for decimalpoints (site or course)
$course_gradedecimals = get_field('grade_items', 'decimals', 'courseid', $COURSE->id, 'itemtype', 'course');
$site_gradedecimals = $CFG->grade_report_decimalpoints;
$default_gradedecimals = $course_gradedecimals;
if ($course_gradedecimals == GRADE_DECIMALS_DEFAULT) {
$default_gradedecimals = $site_gradedecimals;
}
$options = array(GRADE_DECIMALS_DEFAULT => get_string('default', 'grades'), 0, 1, 2, 3, 4, 5);
$label = get_string('decimalpoints', 'grades') . ' (' . get_string('default', 'grades') . ': ' . $options[$default_gradedecimals] . ')';
$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', GRADE_REPORT_PREFERENCE_DEFAULT);
// Disable decimals if displaytype is not REAL or PERCENTAGE
$mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_LETTER);
// Disable decimals if displaytype is DEFAULT and course or site displaytype is LETTER
if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
$mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
}
/// hiding
/// advcheckbox is not compatible with disabledIf !!
$mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
@ -114,17 +136,6 @@ class edit_item_form extends moodleform {
$mform->setHelpButton('locktime', array('locktime', get_string('locktime', 'grades'), 'grade'));
$mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE);
// user preferences
$mform->addElement('header', 'general', get_string('userpreferences', 'grades'));
$options = array(GRADE_REPORT_PREFERENCE_DEFAULT => 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', 'pref_decimalpoints', $label, $options);
$mform->setHelpButton('pref_decimalpoints', array(false, get_string('decimalpoints', 'grades'),
false, true, false, get_string("configdecimalpoints", 'grades')));
$mform->setDefault('pref_decimalpoints', GRADE_REPORT_PREFERENCE_DEFAULT);
/// hidden params
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);

View File

@ -33,14 +33,7 @@ if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
$url = $CFG->wwwroot.'/grade/edit/tree/item.php?id='.$id.'&amp;courseid='.$courseid;
redirect($gpr->add_url_params($url));
}
// Get Item preferences
$item->pref_gradedisplaytype = grade_report::get_pref('gradedisplaytype', $item->id);
$item->pref_decimalpoints = grade_report::get_pref('decimalpoints', $item->id);
$item->calculation = grade_item::denormalize_formula($item->calculation, $course->id);
$decimalpoints = grade_report::get_pref('decimalpoints', $item->id);
if ($item->itemtype == 'mod') {
$cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid);
$item->cmid = $cm->id;
@ -50,15 +43,11 @@ if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
} else {
$item = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual'));
// Get Item preferences
$item->pref_gradedisplaytype = grade_report::get_pref('gradedisplaytype');
$item->pref_decimalpoints = grade_report::get_pref('decimalpoints');
$decimalpoints = grade_report::get_pref('decimalpoints');
$item->cmid = 0;
}
$decimalpoints = $item->get_decimals();
if ($item->hidden > 1) {
$item->hiddenuntil = $item->hidden;
$item->hidden = 0;

View File

@ -607,7 +607,7 @@ class grade_report_grader extends grade_report {
foreach ($this->items as $itemid=>$item) {
// Get the decimal points preference for this item
$decimalpoints = $this->get_pref('decimalpoints', $item->id);
$decimalpoints = $item->get_decimals();
if (isset($this->finalgrades[$userid][$item->id])) {
$gradeval = $this->finalgrades[$userid][$item->id]->finalgrade;
@ -896,7 +896,7 @@ class grade_report_grader extends grade_report {
$mean_count = $totalcount;
}
$decimalpoints = $this->get_pref('decimalpoints', $item->id);
$decimalpoints = $item->get_decimals();
// Determine which display type to use for this average
$gradedisplaytype = $item->get_displaytype();
@ -909,6 +909,7 @@ class grade_report_grader extends grade_report {
$displaytype = $averagesdisplaytype;
}
// Override grade_item setting if a display preference (not inherit) was set for the averages
if ($averagesdecimalpoints != GRADE_REPORT_PREFERENCE_INHERIT) {
$decimalpoints = $averagesdecimalpoints;
}
@ -974,8 +975,8 @@ class grade_report_grader extends grade_report {
$columncount = 1;
foreach ($this->items as $item) {
$decimalpoints = $this->get_pref('decimalpoints', $item->id);
// Determine which display type to use for this range
$decimalpoints = $item->get_decimals();
$gradedisplaytype = $item->get_displaytype();
if ($USER->gradeediting[$this->courseid]) {
@ -986,6 +987,7 @@ class grade_report_grader extends grade_report {
$displaytype = $rangesdisplaytype;
}
// If ranges decimal points pref is set (but not to inherit), override grade_item setting
if ($rangesdecimalpoints != GRADE_REPORT_PREFERENCE_INHERIT) {
$decimalpoints = $rangesdecimalpoints;
}

View File

@ -35,7 +35,6 @@ class grader_report_preferences_form extends moodleform {
// Initialise the preferences arrays with grade:manage capabilities
if (has_capability('moodle/grade:manage', $context)) {
$preferences['prefgeneral'] = array(
'decimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default', 0, 1, 2, 3, 4, 5),
'aggregationview' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
GRADE_REPORT_AGGREGATION_VIEW_FULL => get_string('fullmode', 'grades'),
GRADE_REPORT_AGGREGATION_VIEW_AGGREGATES_ONLY => get_string('aggregatesonly', 'grades'),

View File

@ -108,10 +108,10 @@ class grade_report_user extends grade_report {
$total = $grade_items[1];
unset($grade_items[1]);
$grade_items[] = $total;
foreach ($grade_items as $grade_item) {
$decimalpoints = $this->get_pref('decimalpoints', $grade_item->id);
$decimalpoints = $grade_item->get_decimals();
$data = array();
$grade_grade = new grade_grade(array('itemid'=>$grade_item->id, 'userid'=>$this->user->id));
@ -138,14 +138,14 @@ class grade_report_user extends grade_report {
$excluded = '';
}
if ($grade_grade->is_hidden() && !has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $grade_item->courseid))) {
if ($grade_grade->is_hidden() && !has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $grade_item->courseid))) {
if ((int) $grade_grade->finalgrade < 1) {
$data[] = '-';
$data[] = '-';
} else {
$data[] = get_string('gradedon', 'grades', userdate($grade_grade->timemodified));
}
} else {
if ($grade_item->scaleid) {
// using scales
@ -162,8 +162,8 @@ class grade_report_user extends grade_report {
} else {
// normal grade, or text, just display
if ((int) $grade_grade->finalgrade < 1) {
$data[] = $excluded.'-';
} else {
$data[] = $excluded.'-';
} else {
$data[] = $excluded.format_float($grade_grade->finalgrade, $decimalpoints);
}
}
@ -172,7 +172,7 @@ class grade_report_user extends grade_report {
if ($grade_grade->is_hidden() && !has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $grade_item->courseid))) {
if ((int) $grade_grade->finalgrade < 1) {
$data[] = '-';
$data[] = '-';
} else {
$data[] = get_string('gradedon', 'grades', userdate($grade_grade->timemodified));
}

View File

@ -1,6 +1,6 @@
<?PHP // $Id$
$plugin->version = 2007072500;
$plugin->requires = 2007072402;
$plugin->version = 2007092500;
$plugin->requires = 2007092501;
?>

View File

@ -1288,8 +1288,8 @@ function validate_' . $this->_formName . '(frm) {
* Adds a dependency for $elementName which will be disabled if $condition is met.
* If $condition = 'notchecked' (default) then the condition is that the $dependentOn element
* is not checked. If $condition = 'checked' then the condition is that the $dependentOn element
* is checked. If $condition is something else then it is checked to see if the value
* of the $dependentOn element is equal to $condition.
* is checked. If $condition is something else (like "eq" for equals) then it is checked to see if the value
* of the $dependentOn element is $condition (such as equal) to $value.
*
* @param string $elementName the name of the element which will be disabled
* @param string $dependentOn the name of the element whose state will be checked for

View File

@ -68,6 +68,7 @@ define('GRADE_DISPLAY_TYPE_DEFAULT', 0);
define('GRADE_DISPLAY_TYPE_REAL', 1);
define('GRADE_DISPLAY_TYPE_PERCENTAGE', 2);
define('GRADE_DISPLAY_TYPE_LETTER', 3);
define('GRADE_DECIMALS_DEFAULT', null);
define('GRADE_REPORT_PREFERENCE_DEFAULT', 'default');
define('GRADE_REPORT_PREFERENCE_INHERIT', 'inherit');
define('GRADE_REPORT_PREFERENCE_UNUSED', -1);

View File

@ -43,7 +43,7 @@ class grade_item extends grade_object {
var $required_fields = array('id', 'courseid', 'categoryid', 'itemname', 'itemtype', 'itemmodule', 'iteminstance',
'itemnumber', 'iteminfo', 'idnumber', 'calculation', 'gradetype', 'grademax', 'grademin',
'scaleid', 'outcomeid', 'gradepass', 'multfactor', 'plusfactor', 'aggregationcoef',
'sortorder', 'display', 'hidden', 'locked', 'locktime', 'needsupdate', 'timecreated',
'sortorder', 'display', 'decimals', 'hidden', 'locked', 'locktime', 'needsupdate', 'timecreated',
'timemodified');
/**
@ -206,7 +206,13 @@ class grade_item extends grade_object {
* Display type of the grades (Real, Percentage, Letter, or default).
* @var int $display
*/
var $display = -1;
var $display = GRADE_DISPLAY_TYPE_DEFAULT;
/**
* The number of digits after the decimal point symbol. Applies only to REAL and PERCENTAGE grade display types.
* @var int $decimals
*/
var $decimals = GRADE_DECIMALS_DEFAULT;
/**
* 0 if visible, 1 always hidden or date not visible until
@ -1691,13 +1697,32 @@ class grade_item extends grade_object {
$site_gradedisplaytype = $CFG->grade_report_gradedisplaytype;
$default_gradedisplaytype = $this->display;
if ($this->display == GRADE_REPORT_PREFERENCE_DEFAULT) {
if ($this->display == GRADE_DISPLAY_TYPE_DEFAULT) {
$default_gradedisplaytype = $course_gradedisplaytype;
if ($course_gradedisplaytype == GRADE_REPORT_PREFERENCE_DEFAULT) {
if ($course_gradedisplaytype == GRADE_DISPLAY_TYPE_DEFAULT) {
$default_gradedisplaytype = $site_gradedisplaytype;
}
}
return $default_gradedisplaytype;
}
/**
* Returns the value of the decimals field. It can be set at 3 levels: grade_item, course and site. The lowest level overrides the higher ones.
* @return int Decimals (0 - 5)
*/
function get_decimals() {
global $CFG;
$course_gradedecimals = get_field('grade_items', 'decimals', 'courseid', $this->courseid, 'itemtype', 'course');
$site_gradedecimals = $CFG->grade_report_decimalpoints;
$item_gradedecimals = $this->decimals;
if ($this->decimals == GRADE_DECIMALS_DEFAULT) {
$item_gradedecimals = $course_gradedecimals;
if ($course_gradedecimals == GRADE_DECIMALS_DEFAULT) {
$item_gradedecimals = $site_gradedecimals;
}
}
return $item_gradedecimals;
}
}
?>