Skip to content

Commit

Permalink
Re-enabling inherit options for range and average rows in grader report
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasconnault committed Oct 4, 2007
1 parent 78a2d9f commit 3126103
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 27 deletions.
80 changes: 55 additions & 25 deletions grade/edit/tree/item_form.php
Expand Up @@ -79,44 +79,21 @@ function definition() {
$mform->setHelpButton('aggregationcoef', array(false, get_string('aggregationcoef', 'grades'),
false, true, false, get_string('aggregationcoefhelp', 'grades')));

// Determine default value for gradedisplaytype (site or course)
$course_gradedisplaytype = get_field('grade_items', 'display', 'courseid', $COURSE->id, 'itemtype', 'course');
$site_gradedisplaytype = $CFG->grade_report_gradedisplaytype;
$default_gradedisplaytype = $course_gradedisplaytype;

if ($course_gradedisplaytype == GRADE_REPORT_PREFERENCE_DEFAULT) {
$default_gradedisplaytype = $site_gradedisplaytype;
}

$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] . ')';
$mform->addElement('select', 'display', $label, $options);
$mform->addElement('select', 'display', null, $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)
$default_gradedecimals = get_field('grade_items', 'decimals', 'courseid', $COURSE->id, 'itemtype', 'course');
if (is_null($default_gradedecimals)) {
$default_gradedecimals = $CFG->grade_report_decimalpoints;
}
$options = array(-1=>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->addElement('select', 'decimals', null, $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'));
Expand Down Expand Up @@ -164,6 +141,59 @@ function definition_after_data() {

$mform->setDefault('display', $grade_item->display);

// Determine default value for gradedisplaytype and decimalpoints (site or course)
$course_gradedisplaytype = get_field('grade_items', 'display', 'courseid', $COURSE->id, 'itemtype', 'course');
$site_gradedisplaytype = $CFG->grade_report_gradedisplaytype;
$course_gradedecimals = get_field('grade_items', 'decimals', 'courseid', $COURSE->id, 'itemtype', 'course');
$site_gradedecimals = $CFG->grade_report_decimalpoints;

// Show site settings if the item is the course item
if ($grade_item->is_course_item()) {
$default_gradedisplaytype = $site_gradedisplaytype;
$default_gradedecimals = $site_gradedecimals;
} else { // Otherwise show course item settings
$default_gradedisplaytype = $course_gradedisplaytype;
$default_gradedecimals = $course_gradedecimals;

// If course item settings are set to default, show site defaults
if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_DEFAULT) {
$default_gradedisplaytype = $site_gradedisplaytype;
}
if (is_null($default_gradedecimals)) {
$default_gradedecimals = $site_gradedecimals;
}
}

$displaytypeEl =& $mform->getElement('display');
$options = $displaytypeEl->_options;
$option_value = 0;
foreach ($options as $key => $option) {
if ($option['attr']['value'] == $default_gradedisplaytype) {
$option_value = $option['text'];
break;
}
}
$displaytypeEl->setLabel(get_string('gradedisplaytype', 'grades') . ' (' . get_string('default', 'grades') . ': ' . $option_value . ')');

$decimalsEl =& $mform->getElement('decimals');
$options = $decimalsEl->_options;
$option_value = 0;
foreach ($options as $key => $option) {
if ($option['attr']['value'] == $default_gradedecimals) {
$option_value = $option['text'];
break;
}
}
$decimalsEl->setLabel(get_string('decimalpoints', 'grades') . ' (' . get_string('default', 'grades') . ': ' . $option_value . ')');

// 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);
}

if (!$grade_item->is_raw_used()) {
$mform->removeElement('plusfactor');
$mform->removeElement('multfactor');
Expand Down
6 changes: 4 additions & 2 deletions grade/report/grader/settings.php
Expand Up @@ -79,13 +79,15 @@

$settings->add(new admin_setting_configselect('grade_report_averagesdisplaytype', get_string('averagesdisplaytype', 'grades'),
get_string('configaveragesdisplaytype', 'grades'), GRADE_DISPLAY_TYPE_REAL,
array(GRADE_DISPLAY_TYPE_REAL => $strreal,
array(GRADE_REPORT_PREFERENCE_INHERIT => $strinherit,
GRADE_DISPLAY_TYPE_REAL => $strreal,
GRADE_DISPLAY_TYPE_PERCENTAGE => $strpercentage,
GRADE_DISPLAY_TYPE_LETTER => $strletter)));

$settings->add(new admin_setting_configselect('grade_report_rangesdisplaytype', get_string('rangesdisplaytype', 'grades'),
get_string('configrangesdisplaytype', 'grades'), GRADE_DISPLAY_TYPE_REAL,
array(GRADE_DISPLAY_TYPE_REAL => $strreal,
array(GRADE_REPORT_PREFERENCE_INHERIT => $strinherit,
GRADE_DISPLAY_TYPE_REAL => $strreal,
GRADE_DISPLAY_TYPE_PERCENTAGE => $strpercentage,
GRADE_DISPLAY_TYPE_LETTER => $strletter)));

Expand Down

0 comments on commit 3126103

Please sign in to comment.