Skip to content

Commit

Permalink
MDL-18083 Committing gradebook improvements to head
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasconnault committed Apr 16, 2009
1 parent ccde17c commit 653a864
Show file tree
Hide file tree
Showing 23 changed files with 784 additions and 757 deletions.
16 changes: 14 additions & 2 deletions admin/settings/grades.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
// new CFG variable for gradebook (what roles to display)
$temp->add(new admin_setting_special_gradebookroles());

// enable outcomes checkbox
$temp->add(new admin_setting_configcheckbox('enableoutcomes', get_string('enableoutcomes', 'grades'), get_string('configenableoutcomes', 'grades'), 0, PARAM_INT));

$temp->add(new admin_setting_grade_profilereport());

$temp->add(new admin_setting_configselect('grade_aggregationposition', get_string('aggregationposition', 'grades'),
Expand All @@ -43,7 +46,6 @@
$temp->add(new admin_setting_configselect('grade_export_displaytype', get_string('gradeexportdisplaytype', 'grades'),
get_string('configgradeexportdisplaytype', 'grades'), GRADE_DISPLAY_TYPE_REAL, $display_types));


$temp->add(new admin_setting_configselect('grade_export_decimalpoints', get_string('gradeexportdecimalpoints', 'grades'),
get_string('configexportdecimalpoints', 'grades'), 2,
array( '0' => '0',
Expand All @@ -58,6 +60,8 @@
GRADE_NAVMETHOD_COMBO => get_string('combo', 'grades'))));

$temp->add(new admin_setting_special_gradeexport());

$temp->add(new admin_setting_special_gradelimiting());
}
$ADMIN->add('grades', $temp);

Expand All @@ -78,9 +82,17 @@
GRADE_AGGREGATE_MAX =>get_string('aggregatemax', 'grades'),
GRADE_AGGREGATE_MODE =>get_string('aggregatemode', 'grades'),
GRADE_AGGREGATE_SUM =>get_string('aggregatesum', 'grades'));

$defaultvisible = array(GRADE_AGGREGATE_MEAN, GRADE_AGGREGATE_WEIGHTED_MEAN, GRADE_AGGREGATE_WEIGHTED_MEAN2,
GRADE_AGGREGATE_EXTRACREDIT_MEAN, GRADE_AGGREGATE_MEDIAN, GRADE_AGGREGATE_MIN,
GRADE_AGGREGATE_MAX, GRADE_AGGREGATE_MODE, GRADE_AGGREGATE_SUM);

$defaults = array('value'=>GRADE_AGGREGATE_WEIGHTED_MEAN2, 'forced'=>false, 'adv'=>false);
$temp->add(new admin_setting_gradecat_combo('grade_aggregation', get_string('aggregation', 'grades'), get_string('aggregationhelp', 'grades'), $defaults, $options));

$temp->add(new admin_setting_configmultiselect('grade_aggregations_visible', get_string('aggregationsvisible', 'grades'),
get_string('aggregationsvisiblehelp', 'grades'), $defaultvisible, $options));

$options = array(0 => get_string('no'), 1 => get_string('yes'));

$defaults = array('value'=>1, 'forced'=>false, 'adv'=>true);
Expand Down Expand Up @@ -151,7 +163,7 @@
$scales = new admin_externalpage('scales', get_string('scales'), $CFG->wwwroot.'/grade/edit/scale/index.php', 'moodle/grade:manage');
$ADMIN->add('grades', $scales);
if ($CFG->enableoutcomes) {
$outcomes = new admin_externalpage('outcomes', get_string('outcomes', 'grades'), $CFG->wwwroot.'/grade/edit/outcome/index.php', 'moodle/grade:manage', empty($CFG->enableoutcomes));
$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');
Expand Down
2 changes: 1 addition & 1 deletion grade/edit/tree/calculation_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function validation($data, $files) {
// check the calculation formula
if ($data['calculation'] != '') {
$grade_item = grade_item::fetch(array('id'=>$data['id'], 'courseid'=>$data['courseid']));
$calculation = calc_formula::unlocalize($data['calculation']);
$calculation = calc_formula::unlocalize(stripslashes($data['calculation']));
$result = $grade_item->validate_formula($calculation);
if ($result !== true) {
$errors['calculation'] = $result;
Expand Down
76 changes: 42 additions & 34 deletions grade/edit/tree/category_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

class edit_category_form extends moodleform {
private $aggregation_options = array();
private $allaggoptions;

function definition() {
global $CFG, $COURSE, $DB;
Expand All @@ -42,20 +43,24 @@ function definition() {
GRADE_AGGREGATE_MODE =>get_string('aggregatemode', 'grades'),
GRADE_AGGREGATE_SUM =>get_string('aggregatesum', 'grades'));

$this->allaggoptions = array_keys($this->aggregation_options);

// visible elements
$mform->addElement('header', 'headercategory', get_string('gradecategory', 'grades'));
$mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
$mform->addRule('fullname', null, 'required', null, 'client');

$mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $this->aggregation_options);
$mform->setHelpButton('aggregation', array('aggregation', get_string('aggregation', 'grades'), 'grade'));

if ((int)$CFG->grade_aggregation_flag & 2) {
$mform->setAdvanced('aggregation');
}

$mform->addElement('checkbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
$mform->setHelpButton('aggregateonlygraded', array('aggregateonlygraded', get_string('aggregateonlygraded', 'grades'),'grade'), true);
$mform->disabledIf('aggregateonlygraded', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);

if ((int)$CFG->grade_aggregateonlygraded_flag & 2) {
$mform->setAdvanced('aggregateonlygraded');
}
Expand All @@ -73,11 +78,13 @@ function definition() {

$mform->addElement('advcheckbox', 'aggregatesubcats', get_string('aggregatesubcats', 'grades'));
$mform->setHelpButton('aggregatesubcats', array('aggregatesubcats', get_string('aggregatesubcats', 'grades'), 'grade'), true);

if ((int)$CFG->grade_aggregatesubcats_flag & 2) {
$mform->setAdvanced('aggregatesubcats');
}

$options = array(0 => get_string('none'));

for ($i=1; $i<=20; $i++) {
$options[$i] = $i;
}
Expand Down Expand Up @@ -187,6 +194,7 @@ function definition() {
$mform->setHelpButton('grade_item_decimals', array('decimalpoints', get_string('decimalpoints', 'grades'), 'grade'), true);
$mform->setDefault('grade_item_decimals', -1);
$mform->disabledIf('grade_item_decimals', 'grade_item_display', 'eq', GRADE_DISPLAY_TYPE_LETTER);

if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
$mform->disabledIf('grade_item_decimals', 'grade_item_display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
}
Expand All @@ -200,7 +208,7 @@ function definition() {
$mform->disabledIf('grade_item_hidden', 'grade_item_hiddenuntil[off]', 'notchecked');

/// locking
$mform->addElement('advcheckbox', 'grade_item_locked', get_string('locked', 'grades'));
$mform->addElement('checkbox', 'grade_item_locked', get_string('locked', 'grades'));
$mform->setHelpButton('grade_item_locked', array('locked', get_string('locked', 'grades'), 'grade'));

$mform->addElement('date_time_selector', 'grade_item_locktime', get_string('locktime', 'grades'), array('optional'=>true));
Expand All @@ -212,7 +220,6 @@ function definition() {

$options = array();
$default = '';
$coefstring = '';
$categories = grade_category::fetch_all(array('courseid'=>$COURSE->id));

foreach ($categories as $cat) {
Expand All @@ -221,30 +228,13 @@ function definition() {
if ($cat->is_course_category()) {
$default = $cat->id;
}
if ($cat->is_aggregationcoef_used()) {
if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$coefstring = ($coefstring=='' or $coefstring=='aggregationcoefweight') ? 'aggregationcoefweight' : 'aggregationcoef';

} else if ($cat->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef';

} else {
$coefstring = 'aggregationcoef';
}
} else {
$mform->disabledIf('grade_item_aggregationcoef', 'parentcategory', 'eq', $cat->id);
}
}

if (count($categories) > 1) {
$mform->addElement('select', 'parentcategory', get_string('parentcategory', 'grades'), $options);
$mform->addElement('static', 'currentparentaggregation', get_string('currentparentaggregation', 'grades'));
}

if ($coefstring !== '') {
$mform->addElement('text', 'grade_item_aggregationcoef', get_string($coefstring, 'grades'));
$mform->setHelpButton('grade_item_aggregationcoef', array('aggregationcoefweight', get_string('aggregationcoef', 'grades'), 'grade'), true);
}

/// user preferences
$mform->addElement('header', 'headerpreferences', get_string('myreportpreferences', 'grades'));
$options = array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default', 'grades'),
Expand Down Expand Up @@ -282,6 +272,7 @@ function definition_after_data() {
$mform =& $this->_form;

$somecat = new grade_category();

foreach ($somecat->forceable as $property) {
if ((int)$CFG->{"grade_{$property}_flag"} & 1) {
if ($mform->elementExists($property)) {
Expand All @@ -306,10 +297,14 @@ function definition_after_data() {
}
}

$current_aggregation = null;

if ($id = $mform->getElementValue('id')) {
$grade_category = grade_category::fetch(array('id'=>$id));
$grade_item = $grade_category->load_grade_item();

$current_aggregation = $grade_category->aggregation;

// remove agg coef if not used
if ($grade_category->is_course_category()) {
if ($mform->elementExists('parentcategory')) {
Expand Down Expand Up @@ -365,8 +360,23 @@ function definition_after_data() {
if ($grade_category->is_course_category() && $mform->getElementValue('fullname') == '?') {
$mform->setDefault('fullname', '');
}
// remove unwanted aggregation options
if ($mform->elementExists('aggregation')) {
$agg_el =& $mform->getElement('aggregation');
$visible = explode(',', $CFG->grade_aggregations_visible);
if (!is_null($current_aggregation)) {
// current type is always visible
$visible[] = $current_aggregation;
}
foreach ($this->allaggoptions as $type) {
if (!in_array($type, $visible) && $grade_category->aggregation != $type) {
$agg_el->removeOption($type);
}
}
}
}


// no parent header for course category
if (!$mform->elementExists('aggregationcoef') and !$mform->elementExists('parentcategory')) {
$mform->removeElement('headerparent');
Expand All @@ -377,6 +387,8 @@ function definition_after_data() {
$grade_category = grade_category::fetch(array('id'=>$id));
$grade_item = $grade_category->load_grade_item();

$mform->setDefault('grade_item_hidden', (int) $grade_item->hidden);

if (!$grade_item->is_raw_used()) {
$mform->removeElement('grade_item_plusfactor');
$mform->removeElement('grade_item_multfactor');
Expand Down Expand Up @@ -428,23 +440,19 @@ function definition_after_data() {
$mform->removeElement('grade_item_aggregationcoef');
}
} else {
//fix label if needed
$agg_el =& $mform->getElement('grade_item_aggregationcoef');
$aggcoef = '';
if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$aggcoef = 'aggregationcoefweight';

} else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$aggcoef = 'aggregationcoefextra';
$coefstring = $grade_item->get_coefstring();

} else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
$aggcoef = 'aggregationcoefextrasum';
}

if ($aggcoef !== '') {
$agg_el->setLabel(get_string($aggcoef, 'grades'));
$mform->setHelpButton('grade_item_aggregationcoef', array($aggcoef, get_string($aggcoef, 'grades'), 'grade'), true);
if ($coefstring == 'aggregationcoefextrasum') {
// advcheckbox is not compatible with disabledIf!
$element =& $mform->createElement('checkbox', 'grade_item_aggregationcoef', get_string($coefstring, 'grades'));
} else {
$element =& $mform->createElement('text', 'grade_item_aggregationcoef', get_string($coefstring, 'grades'));
}
$mform->insertElementBefore($element, 'parentcategory');
$mform->setDefault('grade_item_aggregationcoef', (int) $grade_item->aggregationcoef); // must be cast to int, otherwise "0" counts as true :S
$mform->setHelpButton('grade_item_aggregationcoef', array($coefstring, get_string($coefstring, 'grades'), 'grade'), true);
$mform->disabledIf('grade_item_aggregationcoef', 'grade_item_parentcategory', 'eq', $parent_category->id);
}
}

Expand Down
2 changes: 1 addition & 1 deletion grade/edit/tree/grade.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
redirect($returnurl);

// form processing
} else if ($data = $mform->get_data()) {
} else if ($data = $mform->get_data(false)) {
$old_grade_grade = new grade_grade(array('userid'=>$data->userid, 'itemid'=>$grade_item->id), true); //might not exist yet

// fix no grade for scales
Expand Down
25 changes: 15 additions & 10 deletions grade/edit/tree/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
$showadvanced = optional_param('showadvanced', -1, PARAM_BOOL); // sticky editting mode

/// Make sure they can even access this course

if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
}
Expand Down Expand Up @@ -88,13 +87,14 @@
}

// Change category aggregation if requested
if (!is_null($category) && !is_null($aggregationtype)) {
if (!is_null($category) && !is_null($aggregationtype) && confirm_sesskey()) {
if (!$grade_category = grade_category::fetch(array('id'=>$category, 'courseid'=>$courseid))) {
error('Incorrect category id!');
}
$data->aggregation = $aggregationtype;
grade_category::set_properties($grade_category, $data);
$grade_category->update();
grade_regrade_final_grades($courseid);
}

//first make sure we have proper final grades - we need it for locking changes
Expand Down Expand Up @@ -129,7 +129,7 @@

switch ($action) {
case 'delete':
if ($eid) {
if ($eid && confirm_sesskey()) {
if (!$grade_edit_tree->element_deletable($element)) {
// no deleting of external activities - they would be recreated anyway!
// exception is activity without grading or misconfigured activities
Expand Down Expand Up @@ -189,6 +189,7 @@
case 'moveselect':
if ($eid and confirm_sesskey()) {
$grade_edit_tree->moving = $eid;
$moving=true;
}
break;

Expand Down Expand Up @@ -219,7 +220,7 @@

if ($form_key && $data = data_submitted()) {
// Perform bulk actions first
if (!empty($data->bulkmove)) {
if (!empty($data->bulkmove) && confirm_sesskey()) {
$elements = array();

foreach ($data as $key => $value) {
Expand All @@ -234,7 +235,7 @@
// Category and item field updates
foreach ($data as $key => $value) {
// Grade category text inputs
if (preg_match('/(aggregation|droplow|keephigh)_([0-9]*)/', $key, $matches)) {
if (preg_match('/(aggregation|droplow|keephigh)_([0-9]*)/', $key, $matches) && confirm_sesskey()) {
$value = required_param($matches[0], PARAM_INT);
$param = $matches[1];
$a->id = $matches[2];
Expand All @@ -243,9 +244,10 @@
$grade_category->$param = $value;

$grade_category->update();
grade_regrade_final_grades($courseid);

// Grade item text inputs
} elseif (preg_match('/(grademax|aggregationcoef|multfactor|plusfactor)_([0-9]*)/', $key, $matches)) {
} elseif (preg_match('/(grademax|aggregationcoef|multfactor|plusfactor)_([0-9]*)/', $key, $matches) && confirm_sesskey()) {
$defaults = array('grademax' => 100, 'aggregationcoef' => 1, 'multfactor' => 1, 'plusfactor' => 0);

if (is_string($_POST[$matches[0]]) && strlen($_POST[$matches[0]]) < 1) {
Expand All @@ -259,14 +261,14 @@
$grade_item->$param = $value;

$grade_item->update();
grade_regrade_final_grades($courseid);

// Grade item checkbox inputs
} elseif (preg_match('/extracredit_original_([0-9]*)/', $key, $matches)) { // Sum extra credit checkbox
} elseif (preg_match('/extracredit_original_([0-9]*)/', $key, $matches) && confirm_sesskey()) { // Sum extra credit checkbox
$extracredit = optional_param("extracredit_{$matches[1]}", null, PARAM_BOOL);
$original_value = required_param($matches[0], PARAM_BOOL);
$a->id = $matches[1];
$newvalue = null;

if ($original_value == 1 && is_null($extracredit)) {
$newvalue = 0;
} elseif ($original_value == 0 && $extracredit == 1) {
Expand All @@ -279,9 +281,10 @@
$grade_item->aggregationcoef = $newvalue;

$grade_item->update();
grade_regrade_final_grades($courseid);

// Grade category checkbox inputs
} elseif (preg_match('/aggregate(onlygraded|subcats|outcomes)_original_([0-9]*)/', $key, $matches)) {
} elseif (preg_match('/aggregate(onlygraded|subcats|outcomes)_original_([0-9]*)/', $key, $matches) && confirm_sesskey()) {
$setting = optional_param('aggregate'.$matches[1].'_'.$matches[2], null, PARAM_BOOL);
$original_value = required_param($matches[0], PARAM_BOOL);
$a->id = $matches[2];
Expand All @@ -299,6 +302,7 @@
$grade_category->{'aggregate'.$matches[1]} = $newvalue;

$grade_category->update();
grade_regrade_final_grades($courseid);
}
}
}
Expand Down Expand Up @@ -354,7 +358,8 @@
print_single_button('outcomeitem.php', array('courseid'=>$course->id), get_string('addoutcomeitem', 'grades'), 'get');
}

echo "<br /></br />";
//print_single_button('index.php', array('id'=>$course->id, 'action'=>'autosort'), get_string('autosort', 'grades'), 'get');
echo "<br /><br />";
print_single_button('index.php', array('id'=>$course->id, 'action'=>'synclegacy'), get_string('synclegacygrades', 'grades'), 'get');
helpbutton('synclegacygrades', get_string('synclegacygrades', 'grades'), 'grade');
}
Expand Down
Loading

0 comments on commit 653a864

Please sign in to comment.