We'll also need to implement the actions for the -/+ icons.
require_once '../../config.php';
require_once $CFG->dirroot.'/grade/lib.php';
+require_once $CFG->dirroot.'/grade/report/lib.php';
require_once $CFG->libdir.'/gradelib.php';
require_once 'category_form.php';
$mform = new edit_category_form(null, array('gpr'=>$gpr));
if ($category = get_record('grade_categories', 'id', $id, 'courseid', $course->id)) {
+ // Get Category preferences
+ $category->pref_aggregationview = grade_report::get_pref('aggregationview', $id);
+
$mform->set_data($category);
} else {
$mform->set_data(array('courseid'=>$course->id));
$grade_category->update();
}
+ // Handle user preferences
+ if (isset($data->pref_aggregationview)) {
+ if (!grade_report::set_pref('aggregationview', $data->pref_aggregationview, $grade_category->id)) {
+ error("Could not set preference aggregationview to $value for this grade category");
+ }
+ }
+
redirect($returnurl);
}
class edit_category_form extends moodleform {
function definition() {
+ global $CFG;
$mform =& $this->_form;
// visible elements
+ $mform->addElement('header', 'general', get_string('gradecategory', 'grades'));
$mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
$options = array(GRADE_AGGREGATE_MEAN_ALL =>get_string('aggregatemeanall', 'grades'),
$mform->addElement('select', 'droplow', get_string('droplow', 'grades'), $options);
$mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
+ // user preferences
+ $mform->addElement('header', 'general', get_string('userpreferences', 'grades'));
+ $options = array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default', 'grades'),
+ GRADE_REPORT_AGGREGATION_VIEW_FULL => get_string('full', 'grades'),
+ GRADE_REPORT_AGGREGATION_VIEW_COMPACT => get_string('compact', 'grades'));
+ $label = get_string('aggregationview', 'grades') . ' (' . get_string('default', 'grades')
+ . ': ' . $options[$CFG->grade_report_aggregationview] . ')';
+ $mform->addElement('select', 'pref_aggregationview', $label, $options);
+ $mform->setHelpButton('pref_aggregationview', array(false, get_string('aggregationview', 'grades'),
+ false, true, false, get_string("configaggregationview", 'grades')));
+ $mform->setDefault('pref_aggregationview', GRADE_REPORT_PREFERENCE_DEFAULT);
+
// hidden params
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
}
-?>
\ No newline at end of file
+?>
if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
// Get Item preferences
- $item->pref_gradedisplaytype = get_user_preferences('grade_report_gradedisplaytype' . $id, 'default');
- $item->pref_decimalpoints = get_user_preferences('grade_report_decimalpoints' . $id, 'default');
+ $item->pref_gradedisplaytype = grade_report::get_pref('gradedisplaytype', $id);
+ $item->pref_decimalpoints = grade_report::get_pref('decimalpoints', $id);
$item->calculation = grade_item::denormalize_formula($item->calculation, $course->id);
$mform->set_data($item);
$mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional'=>true));
$mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE);
-/// user preferences
+ // user preferences
$mform->addElement('header', 'general', get_string('userpreferences', 'grades'));
$options = array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default', 'grades'),
GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
. ': ' . $options[$CFG->grade_report_gradedisplaytype] . ')';
$mform->addElement('select', 'pref_gradedisplaytype', $label, $options);
$mform->setHelpButton('pref_gradedisplaytype', array(false, get_string('gradedisplaytype', 'grades'),
- false, true, false, get_string("config_gradedisplaytype", 'grades')));
+ false, true, false, get_string("configgradedisplaytype", 'grades')));
$mform->setDefault('pref_gradedisplaytype', GRADE_REPORT_PREFERENCE_DEFAULT);
$options = array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default', 'grades'), 0, 1, 2, 3, 4, 5);
. ': ' . $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("config_decimalpoints", 'grades')));
+ false, true, false, get_string("configdecimalpoints", 'grades')));
$mform->setDefault('pref_decimalpoints', GRADE_REPORT_PREFERENCE_DEFAULT);
/// hidden params
}
foreach ($row as $element) {
+ // Load user preferences for categories
+ if ($element['type'] == 'category') {
+ $categoryid = $element['object']->id;
+ $aggregationview = $this->get_pref('aggregationview', $categoryid);
+
+ if ($aggregationview == GRADE_REPORT_AGGREGATION_VIEW_COMPACT) {
+ $categorystate = get_user_preferences('grade_report_categorystate' . $categoryid, GRADE_CATEGORY_EXPANDED);
+
+ // Expand/Contract icon must be set appropriately
+ if ($categorystate == GRADE_CATEGORY_CONTRACTED) {
+ // The category is contracted: this means we only show 1 item for this category: the
+ // category's aggregation item. The others must be removed from the grade_tree
+ } elseif ($categorystate == GRADE_CATEGORY_EXPANDED) {
+ // The category is expanded: we only show the non-aggregated items directly descending
+ // from this category. The category's grade_item must be removed from the grade_tree
+ }
+ }
+ }
+
$eid = $element['eid'];
$object = $element['object'];
$type = $element['type'];
global $CFG, $USER;
$averagesdisplaytype = $this->get_pref('averagesdisplaytype');
- $mean_pref = get_user_preferences('grade_report_meanselection', $CFG->grade_report_meanselection);
+ $mean_pref = $this->get_pref('meanselection');
$groupavghtml = '';
- if ($mean_pref == 2) {
+ if ($mean_pref == GRADE_AGGREGATE_MEAN_GRADED) {
// non empty grades
$meanstr = "AND NOT g.finalgrade IS NULL";
} else {
$this->groupwheresql
AND ra.roleid in ($this->gradebookroles)
AND ra.contextid ".get_related_contexts_string($this->context)."
- AND NOT g.finalgradeIS NULL
- $notnullstr
+ $meanstr
GROUP BY g.itemid";
$groupsum = array();
$meanselection = $this->get_pref('meanselection');
$mean_pref = get_user_preferences('grade_report_meanselection', $CFG->grade_report_meanselection);
$gradeavghtml = '';
-
+
if ($mean_pref == 2) {
// non empty grades
$meanstr = "AND NOT g.finalgrade IS NULL";
* is given (site default).
* @static (Can be called statically, but then doesn't benefit from caching)
* @param string $pref The name of the preference (do not include the grade_report_ prefix)
- * @param int $itemid An optional itemid to check for a more fine-grained preference
+ * @param int $objectid An optional itemid or categoryid to check for a more fine-grained preference
* @return mixed The value of the preference
*/
- function get_pref($pref, $itemid=null) {
+ function get_pref($pref, $objectid=null) {
global $CFG;
$fullprefname = 'grade_report_' . $pref;
$retval = null;
if (!isset($this)) {
- if (!empty($itemid)) {
- $retval = get_user_preferences($fullprefname . $itemid, grade_report::get_pref($pref));
+ if (!empty($objectid)) {
+ $retval = get_user_preferences($fullprefname . $objectid, grade_report::get_pref($pref));
} else {
$retval = get_user_preferences($fullprefname, $CFG->$fullprefname);
}
} else {
- if (empty($this->prefs[$pref.$itemid])) {
+ if (empty($this->prefs[$pref.$objectid])) {
- if (!empty($itemid)) {
- $retval = get_user_preferences($fullprefname . $itemid);
+ if (!empty($objectid)) {
+ $retval = get_user_preferences($fullprefname . $objectid);
if (empty($retval)) {
// No item pref found, we are returning the global preference
$retval = $this->get_pref($pref);
- $itemid = null;
+ $objectid = null;
}
} else {
$retval = get_user_preferences($fullprefname, $CFG->$fullprefname);
}
- $this->prefs[$pref.$itemid] = $retval;
+ $this->prefs[$pref.$objectid] = $retval;
} else {
- $retval = $this->prefs[$pref.$itemid];
+ $retval = $this->prefs[$pref.$objectid];
}
}
$string['addexceptionerror'] = 'Error occurred while adding exception for userid:gradeitem';
$string['addfeedback'] = 'Add Feedback';
$string['additem'] = 'Add Grade Item';
+$string['aggregatemeanall'] = 'Mean of all grades';
+$string['aggregatemedian'] = 'Median of all grades';
+$string['aggregatemeangraded'] = 'Mean of non-empty grades';
+$string['aggregatemin'] = 'Smallest grade';
+$string['aggregatemax'] = 'Highest grade';
+$string['aggregatemode'] = 'Mode of all grades';
$string['aggregation'] = 'Aggregation';
$string['aggregationposition'] = 'Aggregation position';
$string['aggregationview'] = 'Aggregation view';
$string['displaypercent'] = 'Display Percents';
$string['displaypoints'] = 'Display Points';
$string['displayweighted'] = 'Display Weighted Grades';
+$string['droplow'] = 'Drop the lowest';
$string['dropped'] = 'Dropped';
$string['dropxlowest'] = 'Drop X Lowest';
$string['dropxlowestwarning'] = 'Note: If you use drop x lowest the grading assumes that all items in the category have the same point value. If point values differ results will be unpredictable';
$string['enableajax'] = 'Enable AJAX';
$string['encoding'] = 'Encoding';
$string['errorgradevaluenonnumeric'] = 'Received non-numeric for low or high grade for';
+$string['errorcalculationunknown'] = 'Invalid formula';
$string['errornocategorizedid'] = 'Could not get an uncategorized id!';
$string['errornocourse'] = 'Could not get course information';
$string['errorreprintheadersnonnumeric'] = 'Received non-numeric value for reprint-headers';
$string['gradebook'] = 'Gradebook';
$string['gradebookhiddenerror'] = 'The gradebook is currently set to hide everything from students.';
$string['gradeboundary'] = 'Letter grade boundary';
+$string['gradecategory'] = 'Grade Category';
$string['gradecategoryhelp'] = 'Grade Category Help';
$string['gradedisplaytype'] = 'Grade display type';
$string['gradeexceptions'] = 'Grade Exceptions';
$string['grademax'] = 'Maximum grade';
$string['grademin'] = 'Minimum grade';
$string['gradepass'] = 'Grade to pass';
+$string['groupavg'] = 'Group average';
$string['hidden'] = 'Hidden';
$string['importplugins'] = 'Import plugins';
$string['itemsedit'] = 'Edit grade item';
$string['iteminfo'] = 'Item info';
$string['itemname'] = 'Item name';
$string['items'] = 'Items';
+$string['keephigh'] = 'Keep the highest';
$string['left'] = 'Left';
$string['lettergrade'] = 'Letter Grade';
$string['lettergradenonnumber'] = 'Low and/or High grade were non-numeric for';
if (!is_null($finalgrade)) {
$grade->finalgrade = bounded_number($this->grademin, $finalgrade, $this->grademax);
} else {
- echo "Assigning null finalgrade";
$grade->finalgrade = $finalgrade;
}
}
/**
- * Calculates final grade values useing the formula in calculation property.
- * The parameteres are taken from final grades of grade items in current course only.
+ * Calculates final grade values using the formula in calculation property.
+ * The parameters are taken from final grades of grade items in current course only.
* @return boolean false if error
*/
function compute($userid=null) {