MDL-18083 Committing gradebook improvements to head

This commit is contained in:
nicolasconnault
2009-04-16 07:16:44 +00:00
parent ccde17c3eb
commit 653a86489e
23 changed files with 786 additions and 759 deletions
+14 -2
View File
@@ -26,6 +26,9 @@ if (has_capability('moodle/grade:manage', $systemcontext)
// 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'),
@@ -43,7 +46,6 @@ if (has_capability('moodle/grade:manage', $systemcontext)
$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',
@@ -58,6 +60,8 @@ if (has_capability('moodle/grade:manage', $systemcontext)
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);
@@ -78,9 +82,17 @@ if (has_capability('moodle/grade:manage', $systemcontext)
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);
@@ -151,7 +163,7 @@ if (has_capability('moodle/grade:manage', $systemcontext)
$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');
+1 -1
View File
@@ -90,7 +90,7 @@ class edit_calculation_form extends moodleform {
// 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;
+42 -34
View File
@@ -27,6 +27,7 @@ require_once $CFG->libdir.'/formslib.php';
class edit_category_form extends moodleform {
private $aggregation_options = array();
private $allaggoptions;
function definition() {
global $CFG, $COURSE, $DB;
@@ -42,6 +43,8 @@ class edit_category_form extends moodleform {
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'));
@@ -49,6 +52,7 @@ class edit_category_form extends moodleform {
$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');
}
@@ -56,6 +60,7 @@ class edit_category_form extends moodleform {
$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');
}
@@ -73,11 +78,13 @@ class edit_category_form extends moodleform {
$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;
}
@@ -187,6 +194,7 @@ class edit_category_form extends moodleform {
$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);
}
@@ -200,7 +208,7 @@ class edit_category_form extends moodleform {
$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));
@@ -212,7 +220,6 @@ class edit_category_form extends moodleform {
$options = array();
$default = '';
$coefstring = '';
$categories = grade_category::fetch_all(array('courseid'=>$COURSE->id));
foreach ($categories as $cat) {
@@ -221,30 +228,13 @@ class edit_category_form extends moodleform {
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'),
@@ -282,6 +272,7 @@ class edit_category_form extends moodleform {
$mform =& $this->_form;
$somecat = new grade_category();
foreach ($somecat->forceable as $property) {
if ((int)$CFG->{"grade_{$property}_flag"} & 1) {
if ($mform->elementExists($property)) {
@@ -306,10 +297,14 @@ class edit_category_form extends moodleform {
}
}
$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')) {
@@ -365,8 +360,23 @@ class edit_category_form extends moodleform {
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');
@@ -377,6 +387,8 @@ class edit_category_form extends moodleform {
$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');
@@ -428,23 +440,19 @@ class edit_category_form extends moodleform {
$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);
}
}
+1 -1
View File
@@ -153,7 +153,7 @@ if ($mform->is_cancelled()) {
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
+15 -10
View File
@@ -39,7 +39,6 @@ $aggregationtype = optional_param('aggregationtype', null, PARAM_INT);
$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');
}
@@ -88,13 +87,14 @@ if (has_capability('moodle/grade:manage', $context)) {
}
// 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
@@ -129,7 +129,7 @@ $grade_edit_tree = new grade_edit_tree($gtree, $moving, $gpr);
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
@@ -189,6 +189,7 @@ switch ($action) {
case 'moveselect':
if ($eid and confirm_sesskey()) {
$grade_edit_tree->moving = $eid;
$moving=true;
}
break;
@@ -219,7 +220,7 @@ $form_key = optional_param('sesskey', null, PARAM_ALPHANUM);
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) {
@@ -234,7 +235,7 @@ if ($form_key && $data = data_submitted()) {
// 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];
@@ -243,9 +244,10 @@ if ($form_key && $data = data_submitted()) {
$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) {
@@ -259,14 +261,14 @@ if ($form_key && $data = data_submitted()) {
$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) {
@@ -279,9 +281,10 @@ if ($form_key && $data = data_submitted()) {
$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];
@@ -299,6 +302,7 @@ if ($form_key && $data = data_submitted()) {
$grade_category->{'aggregate'.$matches[1]} = $newvalue;
$grade_category->update();
grade_regrade_final_grades($courseid);
}
}
}
@@ -354,7 +358,8 @@ if ($moving) {
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');
}
+18 -41
View File
@@ -153,42 +153,16 @@ class edit_item_form extends moodleform {
foreach ($categories as $cat) {
$cat->apply_forced_settings();
$options[$cat->id] = $cat->get_name();
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 if ($cat->aggregation == GRADE_AGGREGATE_SUM) {
$coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextrasum') ? 'aggregationcoefextrasum' : 'aggregationcoef';
} else {
$coefstring = 'aggregationcoef';
}
} else {
$mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $cat->id);
}
}
if (count($categories) > 1) {
$mform->addElement('select', 'parentcategory', get_string('gradecategory', 'grades'), $options);
}
if ($coefstring !== '') {
if ($coefstring == 'aggregationcoefextrasum') {
// advcheckbox is not compatible with disabledIf!
$mform->addElement('checkbox', 'aggregationcoef', get_string($coefstring, 'grades'));
} else {
$mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
}
$mform->setHelpButton('aggregationcoef', array($coefstring, get_string($coefstring, 'grades'), 'grade'), true);
}
/// hidden params
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
@@ -278,23 +252,26 @@ class edit_item_form extends moodleform {
$mform->removeElement('aggregationcoef');
}
} else {
//fix label if needed
$agg_el =& $mform->getElement('aggregationcoef');
$aggcoef = '';
if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$aggcoef = 'aggregationcoefweight';
} else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$aggcoef = 'aggregationcoefextra';
} else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
$aggcoef = 'aggregationcoefextrasum';
if ($grade_item->is_category_item()) {
$parent_category = $parent_category->get_parent_category();
$coefstring = $parent_category->get_grade_item()->get_coefstring();
} else {
$parent_category->apply_forced_settings();
$coefstring = $grade_item->get_coefstring();
}
if ($aggcoef !== '') {
$agg_el->setLabel(get_string($aggcoef, 'grades'));
$mform->setHelpButton('aggregationcoef', array($aggcoef, get_string($aggcoef, 'grades'), 'grade'), true);
if ($coefstring !== '') {
if ($coefstring == 'aggregationcoefextrasum') {
// advcheckbox is not compatible with disabledIf!
$element =& $mform->createElement('checkbox', 'aggregationcoef', get_string($coefstring, 'grades'));
} else {
$element =& $mform->createElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
}
$mform->insertElementBefore($element, 'parentcategory');
$mform->setHelpButton('aggregationcoef', array($coefstring, get_string($coefstring, 'grades'), 'grade'), true);
}
$mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $parent_category->id);
}
}
+87 -40
View File
@@ -43,6 +43,10 @@ class grade_edit_tree {
public $deepest_level;
public $uses_extra_credit = false;
public $uses_weight = false;
/**
* Constructor
*/
@@ -53,19 +57,25 @@ class grade_edit_tree {
$this->deepest_level = $this->get_deepest_level($this->gtree->top_element);
$this->columns = array(grade_edit_tree_column::factory('name', array('deepest_level' => $this->deepest_level)),
grade_edit_tree_column::factory('aggregation', array('flag' => true)),
grade_edit_tree_column::factory('weightorextracredit', array('adv' => 'aggregationcoef')),
grade_edit_tree_column::factory('range'), // This is not a setting... How do we deal with it?
grade_edit_tree_column::factory('aggregateonlygraded', array('flag' => true)),
grade_edit_tree_column::factory('aggregatesubcats', array('flag' => true)),
grade_edit_tree_column::factory('aggregateoutcomes', array('flag' => true)),
grade_edit_tree_column::factory('droplow', array('flag' => true)),
grade_edit_tree_column::factory('keephigh', array('flag' => true)),
grade_edit_tree_column::factory('multfactor', array('adv' => true)),
grade_edit_tree_column::factory('plusfactor', array('adv' => true)),
grade_edit_tree_column::factory('actions'),
grade_edit_tree_column::factory('select')
);
grade_edit_tree_column::factory('aggregation', array('flag' => true)));
if ($this->uses_weight) {
$this->columns[] = grade_edit_tree_column::factory('weight', array('adv' => 'aggregationcoef'));
}
if ($this->uses_extra_credit) {
$this->columns[] = grade_edit_tree_column::factory('extracredit', array('adv' => 'aggregationcoef'));
}
$this->columns[] = grade_edit_tree_column::factory('range'); // This is not a setting... How do we deal with it?
$this->columns[] = grade_edit_tree_column::factory('aggregateonlygraded', array('flag' => true));
$this->columns[] = grade_edit_tree_column::factory('aggregatesubcats', array('flag' => true));
$this->columns[] = grade_edit_tree_column::factory('aggregateoutcomes', array('flag' => true));
$this->columns[] = grade_edit_tree_column::factory('droplow', array('flag' => true));
$this->columns[] = grade_edit_tree_column::factory('keephigh', array('flag' => true));
$this->columns[] = grade_edit_tree_column::factory('multfactor', array('adv' => true));
$this->columns[] = grade_edit_tree_column::factory('plusfactor', array('adv' => true));
$this->columns[] = grade_edit_tree_column::factory('actions');
$this->columns[] = grade_edit_tree_column::factory('select');
}
/**
@@ -300,9 +310,10 @@ class grade_edit_tree {
/**
* Given a grade_item object, returns a labelled input if an aggregation coefficient (weight or extra credit) applies to it.
* @param grade_item $item
* @param string type "extra" or "weight": the type of the column hosting the weight input
* @return string HTML
*/
function get_weight_input($item) {
function get_weight_input($item, $type) {
if (!is_object($item) || get_class($item) !== 'grade_item') {
throw new Exception('grade_edit_tree::get_weight_input($item) was given a variable that is not of the required type (grade_item object)');
return false;
@@ -313,28 +324,14 @@ class grade_edit_tree {
}
$parent_category = $item->get_parent_category();
if ($item->is_category_item()) {
$parent_category = $parent_category->get_parent_category();
}
$parent_category->apply_forced_settings();
$aggcoef = $item->get_coefstring();
if ($parent_category->is_aggregationcoef_used()) {
$aggcoef = '';
if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$aggcoef = 'aggregationcoefweight';
} elseif ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$aggcoef = 'aggregationcoefextra';
} elseif ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
$aggcoef = 'aggregationcoefextrasum';
}
if ($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoefextra') {
if ((($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoef') && $type == 'weight') ||
($aggcoef == 'aggregationcoefextra' && $type == 'extra')) {
return '<input type="text" size="6" id="aggregationcoef_'.$item->id.'" name="aggregationcoef_'.$item->id.'"
value="'.format_float($item->aggregationcoef).'" />';
} elseif ($aggcoef == 'aggregationcoefextrasum' ) {
} elseif ($aggcoef == 'aggregationcoefextrasum' && $type == 'extra') {
$checked = ($item->aggregationcoef > 0) ? 'checked="checked"' : '';
$extracredit = ($item->aggregationcoef > 0) ? 1 : 0;
@@ -344,7 +341,6 @@ class grade_edit_tree {
return '';
}
}
}
/**
* Given an element of the grade tree, returns whether it is deletable or not (only manual grade items are deletable)
@@ -424,8 +420,14 @@ class grade_edit_tree {
$object = $element['object'];
$level++;
$coefstring = $element['object']->get_coefstring();
if ($element['type'] == 'category') {
if ($coefstring == 'aggregationcoefweight') {
$this->uses_weight = true;
} elseif ($coefstring == 'aggregationcoefextra' || $coefstring == 'aggregationcoefextrasum') {
$this->uses_extra_credit = true;
}
foreach($element['children'] as $child_el) {
if ($level > $deepest_level) {
$deepest_level = $level;
@@ -542,6 +544,7 @@ class grade_edit_tree_column_aggregation extends grade_edit_tree_column_category
}
public function get_category_cell($category, $levelclass, $params) {
global $CFG;
if (empty($params['id'])) {
throw new Exception('Array key (id) missing from 3rd param of grade_edit_tree_column_aggregation::get_category_cell($category, $levelclass, $params)');
}
@@ -556,7 +559,14 @@ class grade_edit_tree_column_aggregation extends grade_edit_tree_column_category
GRADE_AGGREGATE_MODE => get_string('aggregatemode', 'grades'),
GRADE_AGGREGATE_SUM => get_string('aggregatesum', 'grades'));
$script = "window.location='index.php?id={$params['id']}&amp;category={$category->id}&amp;aggregationtype='+this.value";
$visible = explode(',', $CFG->grade_aggregations_visible);
foreach ($options as $constant => $string) {
if (!in_array($constant, $visible) && $constant != $category->aggregation) {
unset($options[$constant]);
}
}
$script = "window.location='index.php?id={$params['id']}&amp;category={$category->id}&amp;aggregationtype='+this.value+'&amp;sesskey=" . sesskey()."';";
$aggregation = choose_from_menu($options, 'aggregation_'.$category->id, $category->aggregation, get_string('choose'), $script, 0, true);
if ($this->forced) {
@@ -572,16 +582,16 @@ class grade_edit_tree_column_aggregation extends grade_edit_tree_column_category
}
}
class grade_edit_tree_column_weightorextracredit extends grade_edit_tree_column {
class grade_edit_tree_column_extracredit extends grade_edit_tree_column {
public function get_header_cell() {
return '<th class="header" scope="col">'.get_string('weightorextracredit', 'grades').helpbutton('aggregationcoefweight', 'aggregationcoefweight', 'grade', true, false, '', true).'</th>';
return '<th class="header" scope="col">'.get_string('extracredit', 'grades').helpbutton('aggregationcoefextra', 'aggregationcoefextra', 'grade', true, false, '', true).'</th>';
}
public function get_category_cell($category, $levelclass, $params) {
$item = $category->get_grade_item();
$aggcoef_input = grade_edit_tree::get_weight_input($item);
$aggcoef_input = grade_edit_tree::get_weight_input($item, 'extra');
return '<td class="cell '.$levelclass.'">' . $aggcoef_input . '</td>';
}
@@ -593,7 +603,44 @@ class grade_edit_tree_column_weightorextracredit extends grade_edit_tree_column
$html = '<td class="cell">';
if (!in_array($params['element']['object']->itemtype, array('courseitem', 'categoryitem', 'category'))) {
$html .= grade_edit_tree::get_weight_input($item);
$html .= grade_edit_tree::get_weight_input($item, 'extra');
}
return $html.'</td>';
}
public function is_hidden($mode='simple') {
global $CFG;
if ($mode == 'simple') {
return strstr($CFG->grade_item_advanced, 'aggregationcoef');
} elseif ($mode == 'advanced') {
return false;
}
}
}
class grade_edit_tree_column_weight extends grade_edit_tree_column {
public function get_header_cell() {
return '<th class="header" scope="col">'.get_string('weightuc', 'grades').helpbutton('aggregationcoefweight', 'aggregationcoefweight', 'grade', true, false, '', true).'</th>';
}
public function get_category_cell($category, $levelclass, $params) {
$item = $category->get_grade_item();
$aggcoef_input = grade_edit_tree::get_weight_input($item, 'weight');
return '<td class="cell '.$levelclass.'">' . $aggcoef_input . '</td>';
}
public function get_item_cell($item, $params) {
if (empty($params['element'])) {
throw new Exception('Array key (element) missing from 2nd param of grade_edit_tree_column_weightorextracredit::get_item_cell($item, $params)');
}
$html = '<td class="cell">';
if (!in_array($params['element']['object']->itemtype, array('courseitem', 'categoryitem', 'category'))) {
$html .= grade_edit_tree::get_weight_input($item, 'weight');
}
return $html.'</td>';
@@ -669,7 +716,7 @@ class grade_edit_tree_column_aggregateonlygraded extends grade_edit_tree_column_
$aggregateonlygraded = ($category->aggregateonlygraded) ? get_string('yes') : get_string('no');
}
return '<td class="cell '.$levelclass.'">' . $aggregateonlygraded . '</td>';
return '<td class="cell '.$levelclass.'">' . $aggregateonlygraded . $hidden.'</td>';
}
public function get_item_cell($item, $params) {
-1
View File
@@ -47,7 +47,6 @@ class grade_export_form extends moodleform {
if (!empty($features['updategradesonly'])) {
$mform->addElement('advcheckbox', 'updatedgradesonly', get_string('updatedgradesonly', 'grades'));
}
/// selections for decimal points and format, MDL-11667, defaults to site settings, if set
//$default_gradedisplaytype = $CFG->grade_export_displaytype;
$options = array(GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
+6 -6
View File
@@ -693,7 +693,7 @@ function grade_get_plugin_info($courseid, $active_type, $active_plugin) {
*
* @return string HTML code or nothing if $return == false
*/
function print_grade_page_head($courseid, $active_type, $active_plugin=null, $heading = false, $return=false, $bodytags='', $buttons=false) {
function print_grade_page_head($courseid, $active_type, $active_plugin=null, $heading = false, $return=false, $bodytags='', $buttons=false, $extracss=array()) {
global $CFG, $COURSE;
$strgrades = get_string('grades');
$plugin_info = grade_get_plugin_info($courseid, $active_type, $active_plugin);
@@ -715,6 +715,10 @@ function print_grade_page_head($courseid, $active_type, $active_plugin=null, $he
$CFG->stylesheets[] = $CFG->wwwroot . '/grade/report/styles.css';
}
foreach ($extracss as $css_url) {
$CFG->stylesheets[] = $css_url;
}
$navlinks[] = array('name' => $strgrades,
'link' => $first_link,
'type' => 'misc');
@@ -1264,7 +1268,6 @@ class grade_structure {
}
$object = $element['object'];
$overlib = '';
switch ($element['type']) {
case 'item':
@@ -1295,9 +1298,6 @@ class grade_structure {
$url = $gpr->add_url_params($url);
if (!empty($object->feedback)) {
$feedback = addslashes_js(trim(format_string($object->feedback, $object->feedbackformat)));
$function = "return overlib('$feedback', BORDER, 0, FGCLASS, 'feedback', "
."CAPTIONFONTCLASS, 'caption', CAPTION, '$strfeedback');";
$overlib = 'onmouseover="'.s($function).'" onmouseout="return nd();"';
}
break;
@@ -1306,7 +1306,7 @@ class grade_structure {
}
if ($url) {
return '<a href="'.$url.'" class="edit"><img '.$overlib.' src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'.$stredit.'" title="'.$stredit.'"/></a>';
return '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'.$stredit.'" title="'.$stredit.'"/></a>';
} else {
return '';
+17 -23
View File
@@ -184,15 +184,16 @@ class grade_report_grader_ajax extends grade_report_grader {
}
$columncount = 0;
// Student name and link
$user_pic = null;
if ($showuserimage) {
$user_pic = '<div class="userpic">' . print_user_picture($user, $this->courseid, true, 0, true) . '</div>';
}
if ($fixedstudents) {
$studentrowhtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">';
} else {
// Student name and link
$user_pic = null;
if ($showuserimage) {
$user_pic = '<div class="userpic">' . print_user_picture($user, $this->courseid, true, 0, true) . '</div>';
}
$studentrowhtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">'
.'<th class="header c'.$columncount++.' user" scope="row" onclick="set_row(this.parentNode.rowIndex);">'.$user_pic
.'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$this->course->id.'">'
@@ -276,7 +277,7 @@ class grade_report_grader_ajax extends grade_report_grader {
$eid = $this->gtree->get_grade_eid($grade);
$element = array('eid'=>$eid, 'object'=>$grade, 'type'=>'grade');
$cellclasses = 'ajax cell c'.$columncount++;
$cellclasses = 'grade ajax cell c'.$columncount++;
if ($item->is_category_item()) {
$cellclasses .= ' cat';
}
@@ -291,7 +292,15 @@ class grade_report_grader_ajax extends grade_report_grader {
$cellclasses .= ' excluded';
}
$gradecellhtml .= "<td id=\"gradecell_u$userid-i$itemid\" class=\"$cellclasses\">";
$grade_title = '&lt;div class=&quot;fullname&quot;&gt;'.fullname($user).'&lt;/div&gt;';
$grade_title .= '&lt;div class=&quot;itemname&quot;&gt;'.$item->get_name(true).'&lt;/div&gt;';
if (!empty($grade->feedback) && !$USER->gradeediting[$this->courseid]) {
$grade_title .= '&lt;div class=&quot;feedback&quot;&gt;'
.wordwrap(trim(format_string($grade->feedback, $grade->feedbackformat)), 34, '&lt;br/ &gt;') . '&lt;/div&gt;';
}
$gradecellhtml .= "<td id=\"gradecell_u$userid-i$itemid\" class=\"$cellclasses\" title=\"$grade_title\">";
if ($grade->is_excluded()) {
$gradecellhtml .= get_string('excluded', 'grades') . ' ';
@@ -401,15 +410,9 @@ class grade_report_grader_ajax extends grade_report_grader {
$feedback = s($grade->feedback);
$anchor_id = "gradefeedback_$userid-i$itemid";
$gradecellhtml .= '<a ';
if (empty($feedback)) {
$feedback = get_string('addfeedback', 'grades');
$gradecellhtml .= '<a ';
} else {
$overlib = '';
$full_feedback = addslashes_js(trim(format_string($grade->feedback, $grade->feedbackformat)));
$overlib = "return overlib('$full_feedback', BORDER, 0, FGCLASS, 'feedback', "
."CAPTIONFONTCLASS, 'caption', CAPTION, '$strfeedback');";
$gradecellhtml .= '<a onmouseover="'.s($overlib).'" onmouseout="return nd();" ';
}
$feedback_tabindex = $nexttabindex + $this->numusers;
@@ -423,15 +426,6 @@ class grade_report_grader_ajax extends grade_report_grader {
} else { // Not editing
$gradedisplaytype = $item->get_displaytype();
// If feedback present, surround grade with feedback tooltip: Open span here
if (!empty($grade->feedback)) {
$overlib = '';
$feedback = addslashes_js(trim(format_string($grade->feedback, $grade->feedbackformat)));
$overlib = "return overlib('$feedback', BORDER, 0, FGCLASS, 'feedback', "
."CAPTIONFONTCLASS, 'caption', CAPTION, '$strfeedback');";
$gradecellhtml .= '<span onmouseover="'.s($overlib).'" onmouseout="return nd();">';
}
if ($item->needsupdate) {
$gradecellhtml .= '<span class="gradingerror'.$hidden.$gradepass.'">'.get_string('error').'</span>';
+22 -4
View File
@@ -114,9 +114,9 @@ if (!empty($target) && !empty($action) && confirm_sesskey()) {
// Initialise the grader report object
$report = new grade_report_grader($courseid, $gpr, $context, $page, $sortitemid);
require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_container', 'yui_connection', 'yui_dragdrop', 'yui_element', 'yui_json'));
if ($report->get_pref('enableajax')) {
$report = new grade_report_grader_ajax($courseid, $gpr, $context, $page, $sortitemid);
require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_json', 'yui_connection', 'yui_dragdrop', 'yui_treeview', 'yui_element'));
}
/// processing posted grades & feedback here
@@ -139,7 +139,7 @@ $report->load_final_grades();
/// Print header
$reportname = get_string('modulename', 'gradereport_grader');
print_grade_page_head($COURSE->id, 'report', 'grader', $reportname, false, null, $buttons);
print_grade_page_head($COURSE->id, 'report', 'grader', $reportname, false, null, $buttons, array($CFG->wwwroot . '/lib/yui/container/assets/skins/sam/container.css'));
echo $report->group_selector;
echo '<div class="clearer"></div>';
@@ -156,10 +156,8 @@ if (!empty($studentsperpage)) {
print_paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
}
$reporthtml = '<script src="functions.js" type="text/javascript"></script>';
$reporthtml .= '<div class="gradeparent">';
$reporthtml .= $report->get_studentnameshtml();
$reporthtml .= $report->get_headerhtml();
$reporthtml .= $report->get_iconshtml();
@@ -198,6 +196,26 @@ if ($report->get_pref('enableajax')) {
require_once 'ajax.php';
}
// Print YUI tooltip code
?>
<script type="text/javascript">
YAHOO.namespace("graderreport");
YAHOO.graderreport.init = function() {
// Get all <td> with class grade
var cells = YAHOO.util.Dom.getElementsByClassName('grade', 'td');
YAHOO.graderreport.tooltips = new Array(cells.length);
for (var i = 0; i < cells.length; i++) {
YAHOO.graderreport.tooltips[i] = new YAHOO.widget.Tooltip("tt"+i, { context: cells[i], autodismissdelay: 10000000 });
}
};
YAHOO.util.Event.onDOMReady(YAHOO.graderreport.init);
</script>
<?php
print_footer($course);
?>
+50 -27
View File
@@ -91,6 +91,8 @@ class grade_report_grader extends grade_report {
* */
public $canviewhidden;
var $preferences_page=false;
/**
* Constructor. Sets local copies of user preferences and initialises grade_tree.
* @param int $courseid
@@ -208,10 +210,13 @@ class grade_report_grader extends grade_report {
// Warn if the grade is out of bounds.
if (is_null($finalgrade)) {
// ok
} else if ($finalgrade < $grade_item->grademin) {
} else {
$bounded = $grade_item->bounded_grade($finalgrade);
if ($bounded > $finalgrade) {
$errorstr = 'lessthanmin';
} else if ($finalgrade > $grade_item->grademax) {
$errorstr = 'morethanmax';
} else if ($bounded < $finalgrade) {
$errorstr = 'morethanmax';
}
}
if ($errorstr) {
$user = $DB->get_record('user', array('id' => $userid), 'id, firstname, lastname');
@@ -227,7 +232,7 @@ class grade_report_grader extends grade_report {
if (empty($trimmed)) {
$feedback = NULL;
} else {
$feedback = $postedvalue;
$feedback = stripslashes($postedvalue);
}
}
@@ -541,7 +546,6 @@ class grade_report_grader extends grade_report {
$columns_to_unset = array();
foreach ($this->gtree->get_levels() as $key=>$row) {
$columncount = 0;
if ($key == 0) {
@@ -618,7 +622,7 @@ class grade_report_grader extends grade_report {
}
// Element is a category
else if ($type == 'category') {
$headerhtml .= '<th class="header '. $columnclass.' category'.$catlevel.'" '.$colspan.' scope="col">'
$headerhtml .= '<th class=" '. $columnclass.' category'.$catlevel.'" '.$colspan.' scope="col">'
. shorten_text($element['object']->get_name());
$headerhtml .= $this->get_collapsing_icon($element);
@@ -650,7 +654,7 @@ class grade_report_grader extends grade_report {
}
$headerlink = $this->gtree->get_element_header($element, true, $this->get_pref('showactivityicons'), false);
$headerhtml .= '<th class="header '.$columnclass.' '.$type.$catlevel.$hidden.'" scope="col" onclick="set_col(this.cellIndex)">'
$headerhtml .= '<th class=" '.$columnclass.' '.$type.$catlevel.$hidden.'" scope="col" onclick="set_col(this.cellIndex)">'
. shorten_text($headerlink) . $arrow;
$headerhtml .= '</th>';
}
@@ -714,7 +718,6 @@ class grade_report_grader extends grade_report {
}
$columncount = 0;
if ($fixedstudents) {
$studentshtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">';
} else {
@@ -725,12 +728,12 @@ class grade_report_grader extends grade_report {
}
$studentshtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">'
.'<th class="header c'.$columncount++.' user" scope="row" onclick="set_row(this.parentNode.rowIndex);">'.$user_pic
.'<th class="c'.$columncount++.' user" scope="row" onclick="set_row(this.parentNode.rowIndex);">'.$user_pic
.'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$this->course->id.'">'
.fullname($user).'</a></th>';
if ($showuseridnumber) {
$studentshtml .= '<th class="header c'.$columncount++.' useridnumber" onclick="set_row(this.parentNode.rowIndex);">'.
$studentshtml .= '<th class="c'.$columncount++.' useridnumber" onclick="set_row(this.parentNode.rowIndex);">'.
$user->idnumber.'</a></th>';
}
@@ -767,7 +770,7 @@ class grade_report_grader extends grade_report {
$eid = $this->gtree->get_grade_eid($grade);
$element = array('eid'=>$eid, 'object'=>$grade, 'type'=>'grade');
$cellclasses = 'cell c'.$columncount++;
$cellclasses = 'grade cell c'.$columncount++;
if ($item->is_category_item()) {
$cellclasses .= ' cat';
}
@@ -782,7 +785,17 @@ class grade_report_grader extends grade_report {
// $cellclasses .= ' excluded';
}
$studentshtml .= '<td class="'.$cellclasses.'">';
$grade_title = '&lt;div class=&quot;fullname&quot;&gt;'.fullname($user).'&lt;/div&gt;';
$grade_title .= '&lt;div class=&quot;itemname&quot;&gt;'.$item->get_name(true).'&lt;/div&gt;';
if (!empty($grade->feedback) && !$USER->gradeediting[$this->courseid]) {
$grade_title .= '&lt;div class=&quot;feedback&quot;&gt;'
.wordwrap(trim(format_string($grade->feedback, $grade->feedbackformat)), 34, '&lt;br/ &gt;') . '&lt;/div&gt;';
} else {
}
$studentshtml .= '<td class="'.$cellclasses.'" title="'.$grade_title.'">';
if ($grade->is_excluded()) {
$studentshtml .= '<span class="excludedfloater">'.get_string('excluded', 'grades') . '</span> ';
@@ -847,7 +860,7 @@ class grade_report_grader extends grade_report {
if ($gradeval < 1) {
$studentshtml .= '<span class="gradevalue'.$hidden.$gradepass.'">-</span>';
} else {
$gradeval = (int)bounded_number($grade->grade_item->grademin, $gradeval, $grade->grade_item->grademax); //just in case somebody changes scale
$gradeval = $grade->grade_item->bounded_grade($gradeval); //just in case somebody changes scale
$studentshtml .= '<span class="gradevalue'.$hidden.$gradepass.'">'.$scales[$gradeval-1].'</span>';
}
} else {
@@ -881,13 +894,6 @@ class grade_report_grader extends grade_report {
$gradedisplaytype = $item->get_displaytype();
// If feedback present, surround grade with feedback tooltip: Open span here
if (!empty($grade->feedback)) {
$overlib = '';
$feedback = addslashes_js(trim(format_string($grade->feedback, $grade->feedbackformat)));
$overlib = "return overlib('$feedback', BORDER, 0, FGCLASS, 'feedback', "
."CAPTIONFONTCLASS, 'caption', CAPTION, '$strfeedback');";
$studentshtml .= '<span onmouseover="'.s($overlib).'" onmouseout="return nd();">';
}
if ($item->needsupdate) {
$studentshtml .= '<span class="gradingerror'.$hidden.$gradepass.'">'.get_string('error').'</span>';
@@ -1001,7 +1007,7 @@ class grade_report_grader extends grade_report {
}
$studentshtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">'
.'<th class="header c0 user" scope="row" onclick="set_row(this.parentNode.rowIndex);">'.$user_pic
.'<th class="c0 user" scope="row" onclick="set_row(this.parentNode.rowIndex);">'.$user_pic
.'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$this->course->id.'">'
.fullname($user)."</a></th>\n";
@@ -1134,6 +1140,15 @@ class grade_report_grader extends grade_report {
$ungraded_counts = $DB->get_records_sql($SQL, $params);
$fixedstudents = empty($USER->screenreader) && $CFG->grade_report_fixedstudents;
if (!$fixedstudents) {
$colspan='';
if ($this->get_pref('showuseridnumber')) {
$colspan = 'colspan="2" ';
}
$avghtml .= '<th class="header c0 range "'.$colspan.' scope="row">'.$straverage.'</th>';
}
foreach ($this->gtree->items as $itemid=>$unused) {
$item =& $this->gtree->items[$itemid];
@@ -1205,16 +1220,24 @@ class grade_report_grader extends grade_report {
* @return string HTML
*/
public function get_rangehtml() {
global $USER;
global $CFG, $USER;
$scalehtml = '';
$rangehtml = '';
if ($this->get_pref('showranges')) {
$rangesdisplaytype = $this->get_pref('rangesdisplaytype');
$rangesdecimalpoints = $this->get_pref('rangesdecimalpoints');
$columncount=0;
$scalehtml = '<tr class="range r'.$this->rowcount++.' heading">';
$rangehtml = '<tr class="range r'.$this->rowcount++.' heading">';
$fixedstudents = empty($USER->screenreader) && $CFG->grade_report_fixedstudents;
if (!$fixedstudents) {
$colspan='';
if ($this->get_pref('showuseridnumber')) {
$colspan = 'colspan="2" ';
}
$rangehtml .= '<th class="header c0 range "'.$colspan.' scope="row">'.$this->get_lang_string('range','grades').'</th>';
}
foreach ($this->gtree->items as $itemid=>$unused) {
$item =& $this->gtree->items[$itemid];
@@ -1227,12 +1250,12 @@ class grade_report_grader extends grade_report {
$formatted_range = $item->get_formatted_range($rangesdisplaytype, $rangesdecimalpoints);
$scalehtml .= '<th class="header c'.$columncount++.' range"><span class="rangevalues'.$hidden.'">'. $formatted_range .'</span></th>';
$rangehtml .= '<th class="header c'.$columncount++.' range"><span class="rangevalues'.$hidden.'">'. $formatted_range .'</span></th>';
}
$scalehtml .= '</tr>';
$rangehtml .= '</tr>';
}
return $scalehtml;
return $rangehtml;
}
/**
-1
View File
@@ -66,7 +66,6 @@ if ($mform->is_cancelled()){
redirect($CFG->wwwroot . '/grade/report/grader/index.php?id='.$courseid);
}
print_grade_page_head($courseid, 'preferences', 'grader', get_string('preferences', 'gradereport_grader'));
// If USER has admin capability, print a link to the site config page for this report
File diff suppressed because it is too large Load Diff
+2 -3
View File
@@ -225,10 +225,9 @@ class grade_report_overview extends grade_report {
* @var array $data
* @return bool Success or Failure (array of errors).
*/
public function process_data($data) {
function process_data($data) {
}
public function process_action($target, $action) {
function process_action($target, $action) {
}
}
+4
View File
@@ -0,0 +1,4 @@
#content #siteconfiglink {
text-align: right;
}
+28 -3
View File
@@ -49,6 +49,8 @@ class grade_report_user extends grade_report {
*/
public $table;
var $gtree;
/**
* Flat structure similar to grade tree
*/
@@ -99,6 +101,7 @@ class grade_report_user extends grade_report {
$this->showrank = grade_get_setting($this->courseid, 'report_user_showrank', $CFG->grade_report_user_showrank);
$this->showpercentage = grade_get_setting($this->courseid, 'report_user_showpercentage', $CFG->grade_report_user_showpercentage);
$this->showhiddenitems = grade_get_setting($this->courseid, 'report_user_showhiddenitems', $CFG->grade_report_user_showhiddenitems);
$this->showrange = true;
$this->switch = grade_get_setting($this->courseid, 'aggregationposition', $CFG->grade_aggregationposition);
@@ -203,6 +206,12 @@ class grade_report_user extends grade_report {
$excluded = '';
$class = '';
// If this is a hidden grade item, hide it completely from the user. showhiddenitems: 0 = hide all, 1 = show only hidden until, 2 = show all
if ($grade_object->is_hidden() && !$this->canviewhidden && (
$this->showhiddenitems == 0 ||
($this->showhiddenitems == 1 && !$grade_object->is_hiddenuntil()))) {
return false;
}
if ($type == 'category') {
$this->evenodd[$depth] = (($this->evenodd[$depth] + 1) % 2);
@@ -224,6 +233,13 @@ class grade_report_user extends grade_report {
$hidden = ' hidden';
}
// If this is a hidden grade item, hide it completely from the user. showhiddenitems: 0 = hide all, 1 = show only hidden until, 2 = show all
if ($grade_grade->is_hidden() && !$this->canviewhidden && (
$this->showhiddenitems == 0 ||
($this->showhiddenitems == 1 && !$grade_grade->is_hiddenuntil()))) {
// return false;
} else {
/// Excluded Item
if ($grade_grade->is_excluded()) {
$fullname .= ' ['.get_string('excluded', 'grades').']';
@@ -255,6 +271,9 @@ class grade_report_user extends grade_report {
$data['grade']['class'] = $class;
$data['grade']['content'] = get_string('submittedon', 'grades', userdate($grade_grade->get_datesubmitted(), get_string('strftimedatetimeshort')));
} elseif ($grade_grade->is_hidden()) {
$data['grade']['class'] = $class.' hidden';
$data['grade']['content'] = '-';
} else {
$data['grade']['class'] = $class;
$data['grade']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true);
@@ -265,6 +284,9 @@ class grade_report_user extends grade_report {
if ($grade_grade->grade_item->needsupdate) {
$data['percentage']['class'] = $class.' gradingerror';
$data['percentage']['content'] = get_string('error');
} elseif ($grade_grade->is_hidden()) {
$data['percentage']['class'] = $class.' hidden';
$data['percentage']['content'] = '-';
} else {
$data['percentage']['class'] = $class;
$data['percentage']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true, GRADE_DISPLAY_TYPE_PERCENTAGE);
@@ -277,6 +299,9 @@ class grade_report_user extends grade_report {
if ($grade_grade->grade_item->needsupdate) {
$data['rank']['class'] = $class.' gradingerror';
$data['rank']['content'] = get_string('error');
} elseif ($grade_grade->is_hidden()) {
$data['rank']['class'] = $class.' hidden';
$data['rank']['content'] = '-';
} else if (is_null($gradeval)) {
// no grade, no rank
$data['rank']['class'] = $class;
@@ -311,6 +336,7 @@ class grade_report_user extends grade_report {
$data['range']['content'] = $grade_grade->grade_item->get_formatted_range();
}
}
}
/// Category
if ($type == 'category') {
@@ -395,10 +421,9 @@ class grade_report_user extends grade_report {
* @var array $data
* @return bool Success or Failure (array of errors).
*/
public function process_data($data) {
function process_data($data) {
}
public function process_action($target, $action) {
function process_action($target, $action) {
}
}
+10 -2
View File
@@ -30,14 +30,16 @@ $string['aggregateweightedmean'] = 'Weighted mean of grades';
$string['aggregateweightedmean2'] = 'Simple weighted mean of grades';
$string['aggregation'] = 'Aggregation';
$string['aggregationcoef'] = 'Aggregation coefficient';
$string['aggregationcoefextra'] = 'Extra credit coefficient';
$string['aggregationcoefextrasum'] = 'Act as extra credit';
$string['aggregationcoefextra'] = 'Extra credit';
$string['aggregationcoefextrahelp'] = 'Extra credit for this grade item during aggregation.';
$string['aggregationcoefextrasum'] = 'Extra credit';
$string['aggregationcoefextrasumhelp'] = 'Extra credit for this grade item during aggregation.';
$string['aggregationcoefweight'] = 'Item weight';
$string['aggregationcoefweighthelp'] = 'Weight applied to all grades in this grade item during aggregation with other grade items.';
$string['aggregationhelp'] = 'Strategy used to aggregate grades across all students in a course.';
$string['aggregationposition'] = 'Aggregation position';
$string['aggregationsvisible'] = 'Available aggregation types';
$string['aggregationsvisiblehelp'] = 'Select all aggregation types that should be available. Hold down the Ctrl key to select multiple items.';
$string['aggregationview'] = 'Aggregation view';
$string['allgrades'] = 'All grades by category';
$string['allstudents'] = 'All students';
@@ -67,6 +69,7 @@ $string['category'] = 'Category';
$string['categoryedit'] = 'Edit category';
$string['categoryname'] = 'Category name';
$string['categorytotal'] = 'Category total';
$string['categorytotalfull'] = '$a->category total';
$string['changereportdefaults'] = 'Change report defaults';
$string['changedefaults'] = 'Change defaults';
$string['choosecategory'] = 'Select category';
@@ -116,6 +119,7 @@ $string['configshowuseridnumber'] = 'Whether to show user id numbers in an addit
$string['configshowuserimage'] = 'Whether to show the user\'s profile image next to the name in the grader report.';
$string['configstudentsperpage'] = 'The number of students to display per page in the grader report.';
$string['configstudentsperpagedefault'] = 'The number of students to display per page in the grader report. Leave this field empty to use the site default (currently $a).';
$string['configunlimitedgrades'] = 'By default grades are limited by the maximum and minimum values of the grade item. Enabling this setting removes this limit, and allows grades of over 100%% to be entered directly in the gradebook. It is recommended that this setting is enabled at an off-peak time, as all grades will be recalculated, which may result in a high server load.';
$string['contract'] = 'Contract Category';
$string['controls'] = 'Controls';
$string['coursegradecategory'] = 'Course grade category';
@@ -219,6 +223,7 @@ $string['gradeexceptions'] = 'Grade exceptions';
$string['gradeexceptionshelp'] = 'Grade exceptions Help';
$string['gradeexportdisplaytype'] = 'Grade export display type';
$string['gradeexportdecimalpoints'] = 'Grade export decimal points';
$string['gradeforstudent'] = '$a->student<br />$a->item$a->feedback';
$string['gradehelp'] = 'Grade Help';
$string['gradehistorylifetime'] = 'Grade history lifetime';
$string['gradeitem'] = 'Grade item';
@@ -305,6 +310,7 @@ $string['includescalesinaggregation'] = 'Include scales in aggregation';
$string['incorrectcourseid'] = 'Course ID was incorrect';
$string['incorrectminmax'] = 'The minimum must be lower than the maximum';
$string['inherit'] = 'Inherit';
$string['intersectioninfo'] = 'Student/Grade info';
$string['item'] = 'Item';
$string['iteminfo'] = 'Item info';
$string['iteminfohelp'] = 'A space for entering information about the item. Text entered does not appear anywhere else.';
@@ -533,6 +539,7 @@ $string['updatedgradesonly'] = 'Export new or updated grades only';
$string['uncategorised'] = 'Uncategorised';
$string['unchangedgrade'] = 'Grade unchanged';
$string['unenrolledusersinimport'] = 'This import included the following grades for users not currently enrolled in this course: $a';
$string['unlimitedgrades'] = 'Unlimited grades';
$string['unlock'] = 'Unlock';
$string['unlockverbose'] = 'Unlock $a->category$a->itemmodule $a->itemname';
$string['unused'] = 'Unused';
@@ -552,6 +559,7 @@ $string['verbosescales'] = 'Verbose scales';
$string['viewbygroup'] = 'Group';
$string['viewgrades'] = 'View grades';
$string['weight'] = 'weight';
$string['weightuc'] = 'Weight';
$string['weightcourse'] = 'Use weighted grades for course';
$string['weightedascending'] = 'Sort by weighted percent ascending';
$string['weighteddescending'] = 'Sort by weighted percent descending';
+31 -2
View File
@@ -3159,6 +3159,35 @@ class admin_setting_special_coursemanager extends admin_setting_pickroles {
}
}
class admin_setting_special_gradelimiting extends admin_setting_configcheckbox {
function admin_setting_special_gradelimiting() {
parent::__construct('unlimitedgrades', get_string('unlimitedgrades', 'grades'),
get_string('configunlimitedgrades', 'grades'), '0', '1', '0');
}
function regrade_all() {
global $CFG;
require_once("$CFG->libdir/gradelib.php");
grade_force_site_regrading();
}
function write_setting($data) {
$previous = $this->get_setting();
if ($previous === null) {
if ($data) {
$this->regrade_all();
}
} else {
if ($data != $previous) {
$this->regrade_all();
}
}
return ($this->config_write($this->name, $data) ? '' : get_string('errorsetting', 'admin'));
}
}
/**
* Primary grade export plugin - has state tracking.
*/
@@ -4752,7 +4781,7 @@ class admin_setting_managewsprotocols extends admin_setting {
public function get_setting() {
return true;
}
public function write_setting($data) {
$url = $this->baseurl . '&amp;new=' . $data;
return '';
@@ -4760,7 +4789,7 @@ class admin_setting_managewsprotocols extends admin_setting {
public function output_html($data, $query='') {
global $CFG;
$namestr = get_string('name');
$settingsstr = get_string('settings');
$hiddenstr = get_string('hiddenshow', 'repository');
+57 -6
View File
@@ -143,6 +143,11 @@ class grade_category extends grade_object {
*/
public $forceable = array('aggregation', 'keephigh', 'droplow', 'aggregateonlygraded', 'aggregateoutcomes', 'aggregatesubcats');
/**
* String representing the aggregation coefficient. Variable is used as cache.
*/
var $coefstring = null;
/**
* Builds this category's path string based on its parents (if any) and its own id number.
* This is typically done just before inserting this object in the DB for the first time,
@@ -572,11 +577,7 @@ class grade_category extends grade_object {
// recalculate the grade back to requested range
$finalgrade = grade_grade::standardise_score($agg_grade, 0, 1, $this->grade_item->grademin, $this->grade_item->grademax);
if (is_null($finalgrade)) {
$grade->finalgrade = null;
} else {
$grade->finalgrade = (float)bounded_number($this->grade_item->grademin, $finalgrade, $this->grade_item->grademax);
}
$grade->finalgrade = $this->grade_item->bounded_grade($finalgrade);
// update in db if changed
if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
@@ -750,6 +751,10 @@ class grade_category extends grade_object {
* @return boolean (just plain return;)
*/
private function sum_grades(&$grade, $oldfinalgrade, $items, $grade_values, $excluded) {
if (empty($items)) {
return null;
}
// ungraded and exluded items are not used in aggregation
foreach ($grade_values as $itemid=>$v) {
if (is_null($v)) {
@@ -771,7 +776,7 @@ class grade_category extends grade_object {
$this->apply_limit_rules($grade_values);
$sum = array_sum($grade_values);
$grade->finalgrade = bounded_number($this->grade_item->grademin, $sum, $this->grade_item->grademax);
$grade->finalgrade = $this->grade_item->bounded_grade($sum);
// update in db if changed
if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
@@ -812,6 +817,52 @@ class grade_category extends grade_object {
}
/**
* Recursive function to find which weight/extra credit field to use in the grade item form. Inherits from a parent category
* if that category has aggregatesubcats set to true.
* @param string $coefstring
* @return string $coefstring
*/
public function get_coefstring($first=true) {
if (!is_null($this->coefstring)) {
return $this->coefstring;
}
$overriding_coefstring = null;
// Stop recursing upwards if this category aggregates subcats or has no parent
if (!$first && !$this->aggregatesubcats) {
if ($parent_category = $this->get_parent_category()) {
return $parent_category->get_coefstring(false);
} else {
return null;
}
} elseif ($first) {
if (!$this->aggregatesubcats) {
if ($parent_category = $this->get_parent_category()) {
$overriding_coefstring = $parent_category->get_coefstring(false);
}
}
}
// If an overriding coefstring has trickled down from one of the parent categories, return it. Otherwise, return self.
if (!is_null($overriding_coefstring)) {
return $overriding_coefstring;
}
// No parent category is overriding this category's aggregation, return its string
if ($this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$this->coefstring = 'aggregationcoefweight';
} else if ($this->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$this->coefstring = 'aggregationcoefextra';
} else if ($this->aggregation == GRADE_AGGREGATE_SUM) {
$this->coefstring = 'aggregationcoefextrasum';
} else {
$this->coefstring = 'aggregationcoef';
}
return $this->coefstring;
}
/**
* Returns tree with all grade_items and categories as elements
* @static
+2 -4
View File
@@ -623,7 +623,7 @@ class grade_grade extends grade_object {
foreach ($dependson[$do] as $itemid) {
if (array_key_exists($itemid, $altered)) {
$values[$itemid] = $altered[$itemid];
} else {
} elseif (!empty($values[$itemid])) {
$values[$itemid] = $grade_grades[$itemid]->finalgrade;
}
}
@@ -668,9 +668,7 @@ class grade_grade extends grade_object {
// recalculate the rawgrade back to requested range
$finalgrade = grade_grade::standardise_score($agg_grade, 0, 1, $grade_items[$do]->grademin, $grade_items[$do]->grademax);
if (!is_null($finalgrade)) {
$finalgrade = bounded_number($grade_items[$do]->grademin, $finalgrade, $grade_items[$do]->grademax);
}
$finalgrade = $grade_items[$do]->bounded_grade($finalgrade);
$altered[$do] = $finalgrade;
unset($todo[$key]);
+67 -13
View File
@@ -744,7 +744,7 @@ class grade_item extends grade_object {
$rawgrade *= $this->multfactor;
$rawgrade += $this->plusfactor;
return bounded_number($this->grademin, $rawgrade, $this->grademax);
return $this->bounded_grade($rawgrade);
} else if ($this->gradetype == GRADE_TYPE_SCALE) { // Dealing with a scale value
if (empty($this->scale)) {
@@ -765,7 +765,7 @@ class grade_item extends grade_object {
$rawgrade = grade_grade::standardise_score($rawgrade, $rawmin, $rawmax, $this->grademin, $this->grademax);
}
return (int)bounded_number(0, round($rawgrade+0.00001), $this->grademax);
return $this->bounded_grade($rawgrade);
} else if ($this->gradetype == GRADE_TYPE_TEXT or $this->gradetype == GRADE_TYPE_NONE) { // no value
@@ -1176,9 +1176,10 @@ class grade_item extends grade_object {
/**
* Returns the most descriptive field for this object. This is a standard method used
* when we do not know the exact type of an object.
* @param boolean $fulltotal: if the item is a category total, returns $categoryname."total" instead of "Category total" or "Course total"
* @return string name
*/
public function get_name() {
public function get_name($fulltotal=false) {
if (!empty($this->itemname)) {
// MDL-10557
return format_string($this->itemname);
@@ -1187,7 +1188,14 @@ class grade_item extends grade_object {
return get_string('coursetotal', 'grades');
} else if ($this->is_category_item()) {
if ($fulltotal) {
$category = $this->get_parent_category();
$a = new stdClass();
$a->category = $category->get_name();
return get_string('categorytotalfull', 'grades', $a);
} else {
return get_string('categorytotal', 'grades');
}
} else {
return get_string('grade');
@@ -1222,6 +1230,43 @@ class grade_item extends grade_object {
return $this->update();
}
/**
* Makes sure value is a valid grade value.
* @param float $gradevalue
* @return mixed float or int fixed grade value
*/
public function bounded_grade($gradevalue) {
global $CFG;
if (is_null($gradevalue)) {
return null;
}
if ($this->gradetype == GRADE_TYPE_SCALE) {
// no >100% grades hack for scale grades!
// 1.5 is rounded to 2 ;-)
return (int)bounded_number($this->grademin, round($gradevalue+0.00001), $this->grademax);
}
$grademax = $this->grademax;
// NOTE: if you change this value you must manually reset the needsupdate flag in all grade items
$maxcoef = isset($CFG->gradeoverhundredprocentmax) ? $CFG->gradeoverhundredprocentmax : 10; // 1000% max by default
if (!empty($CFG->unlimitedgrades)) {
// NOTE: if you change this value you must manually reset the needsupdate flag in all grade items
$grademax = $grademax * $maxcoef;
} else if ($this->is_category_item() or $this->is_course_item()) {
$category = $this->load_item_category();
if ($category->aggregation >= 100) {
// grade >100% hack
$grademax = $grademax * $maxcoef;
}
}
return (float)bounded_number($this->grademin, $gradevalue, $grademax);
}
/**
* Finds out on which other items does this depend directly when doing calculation or category agregation
* @param bool $reset_cache
@@ -1411,11 +1456,7 @@ class grade_item extends grade_object {
$grade->overridden = 0;
}
if (is_null($finalgrade)) {
$grade->finalgrade = null;
} else {
$grade->finalgrade = bounded_number($this->grademin, $finalgrade, $this->grademax);
}
$grade->finalgrade = $this->bounded_grade($finalgrade);
}
// do we have comment from teacher?
@@ -1762,11 +1803,7 @@ class grade_item extends grade_object {
} else {
// normalize
$result = bounded_number($this->grademin, $result, $this->grademax);
if ($this->gradetype == GRADE_TYPE_SCALE) {
$result = round($result+0.00001); // round scales upwards
}
$grade->finalgrade = $result;
$grade->finalgrade = $this->bounded_grade($result);
}
// update in db if changed
@@ -1934,5 +1971,22 @@ class grade_item extends grade_object {
return $grademin.'&ndash;'. $grademax;
}
/**
* Queries parent categories recursively to find the aggregationcoef type that applies to this
* grade item.
*/
public function get_coefstring() {
$parent_category = $this->get_parent_category();
if ($this->is_category_item()) {
$parent_category = $parent_category->get_parent_category();
}
if ($parent_category->is_aggregationcoef_used()) {
return $parent_category->get_coefstring();
} else {
return false;
}
}
}
?>
+16 -4
View File
@@ -240,7 +240,6 @@ function grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance,
break;
}
if (is_null($grade_grade)) {
if (count($grades) == 0) {
// no more grades to process
@@ -708,7 +707,7 @@ function grade_format_gradevalue_real($value, $grade_item, $decimals, $localized
return get_string('error');
}
$value = (int)bounded_number($grade_item->grademin, $value, $grade_item->grademax);
$value = $grade_item->bounded_grade($value);
return format_string($scale->scale_items[$value-1]);
} else {
@@ -722,7 +721,7 @@ function grade_format_gradevalue_percentage($value, $grade_item, $decimals, $loc
if ($min == $max) {
return '';
}
$value = bounded_number($min, $value, $max);
$value = $grade_item->bounded_grade($value);
$percentage = (($value-$min)*100)/($max-$min);
return format_float($percentage, $decimals, $localized).' %';
}
@@ -733,6 +732,10 @@ function grade_format_gradevalue_letter($value, $grade_item) {
return ''; // no letters??
}
if (is_null($value)) {
return '-';
}
$value = grade_grade::standardise_score($value, $grade_item->grademin, $grade_item->grademax, 0, 100);
$value = bounded_number(0, $value, 100); // just in case
foreach ($letters as $boundary => $letter) {
@@ -868,6 +871,15 @@ function grade_force_full_regrading($courseid) {
$DB->set_field('grade_items', 'needsupdate', 1, array('courseid'=>$courseid));
}
/**
* Forces regrading of all site grades - usualy when chanign site setings
*/
function grade_force_site_regrading() {
global $CFG, $DB;
$sql = "UPDATE {$CFG->prefix}grade_items SET needsupdate=1";
$DB->execute($sql);
}
/**
* Updates all final grades in course.
*
@@ -1078,7 +1090,7 @@ function grade_update_mod_grades($modinstance, $userid=0) {
$fullmod = $CFG->dirroot.'/mod/'.$modinstance->modname;
if (!file_exists($fullmod.'/lib.php')) {
debugging('missing lib.php file in module');
debugging('missing lib.php file in module ' . $modinstance->modname);
return false;
}
include_once($fullmod.'/lib.php');