// enable publishing in exports/imports
$temp->add(new admin_setting_configcheckbox('gradepublishing', get_string('gradepublishing', 'grades'), get_string('configgradepublishing', 'grades'), 0, PARAM_INT));
+$temp->add(new admin_setting_configselect('grade_aggregationposition', get_string('aggregationposition', 'grades'),
+ get_string('configaggregationposition', 'grades'), GRADE_REPORT_AGGREGATION_POSITION_LAST,
+ array(GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'),
+ GRADE_REPORT_AGGREGATION_POSITION_LAST => get_string('positionlast', 'grades'))));
+
$temp->add(new admin_setting_configselect('grade_displaytype', get_string('gradedisplaytype', 'grades'),
get_string('configgradedisplaytype', 'grades'), GRADE_DISPLAY_TYPE_REAL,
array(GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
--- /dev/null
+<?php //$Id$
+
+require_once($CFG->libdir.'/formslib.php');
+
+/**
+ * First implementation of the preferences in the form of a moodleform.
+ * TODO add "reset to site defaults" button
+ */
+class course_settings_form extends moodleform {
+
+ function definition() {
+ global $USER, $CFG;
+
+ $mform =& $this->_form;
+
+ $mform->addElement('header', 'general', get_string('settings', 'grades'));
+
+ $options = array(-1 => get_string('default', 'grades'),
+ GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
+ GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
+ GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
+ $default_gradedisplaytype = $CFG->grade_displaytype;
+ foreach ($options as $key=>$option) {
+ if ($key == $default_gradedisplaytype) {
+ $options[-1] = get_string('defaultprev', 'grades', $option);
+ break;
+ }
+ }
+ $mform->addElement('select', 'displaytype', get_string('gradedisplaytype', 'grades'), $options);
+ $mform->setHelpButton('displaytype', array(false, get_string('gradedisplaytype', 'grades'),
+ false, true, false, get_string('configgradedisplaytype', 'grades')));
+
+
+ $options = array(-1=> get_string('defaultprev', 'grades', $CFG->grade_decimalpoints), 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
+ $mform->addElement('select', 'decimalpoints', get_string('decimalpoints', 'grades'), $options);
+ $mform->setHelpButton('decimalpoints', array(false, get_string('decimalpoints', 'grades'),
+ false, true, false, get_string('configdecimalpoints', 'grades')));
+
+
+ $mform->addElement('hidden', 'id');
+ $mform->setType('id', PARAM_INT);
+
+
+ $options = array(-1 => get_string('default', 'grades'),
+ GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'),
+ GRADE_REPORT_AGGREGATION_POSITION_LAST => get_string('positionlast', 'grades'));
+ $default_gradedisplaytype = $CFG->grade_aggregationposition;
+ foreach ($options as $key=>$option) {
+ if ($key == $default_gradedisplaytype) {
+ $options[-1] = get_string('defaultprev', 'grades', $option);
+ break;
+ }
+ }
+ $mform->addElement('select', 'aggregationposition', get_string('aggregationposition', 'grades'), $options);
+ $mform->setHelpButton('aggregationposition', array(false, get_string('aggregationposition', 'grades'),
+ false, true, false, get_string('configaggregationposition', 'grades')));
+
+
+ $this->add_action_buttons();
+ }
+}
+?>
--- /dev/null
+<?php // $Id$
+
+require_once '../../../config.php';
+require_once $CFG->dirroot.'/grade/lib.php';
+require_once $CFG->libdir.'/gradelib.php';
+require_once 'form.php';
+
+$courseid = optional_param('id', SITEID, PARAM_INT);
+$action = optional_param('action', '', PARAM_ALPHA);
+
+if (!$course = get_record('course', 'id', $courseid)) {
+ print_error('nocourseid');
+}
+require_login($course);
+$context = get_context_instance(CONTEXT_COURSE, $course->id);
+
+require_capability('moodle/grade:manage', $context);
+
+$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'settings', 'courseid'=>$courseid));
+
+$strgrades = get_string('grades');
+$pagename = get_string('coursesettings', 'grades');
+
+$navigation = grade_build_nav(__FILE__, $pagename, $courseid);
+
+$returnurl = $CFG->wwwroot.'/grade/index.php?id='.$course->id;
+
+$mform = new course_settings_form();
+
+$data = new object;
+$data->id = $course->id;
+$data->displaytype = grade_get_setting($course->id, 'displaytype', -1);
+$data->decimalpoints = grade_get_setting($course->id, 'decimalpoints',- 1);
+$data->aggregationposition = grade_get_setting($course->id, 'aggregationposition', -1);
+
+$mform->set_data($data);
+
+if ($mform->is_cancelled()) {
+ redirect($returnurl);
+
+} else if ($data = $mform->get_data()) {
+ if ($data->displaytype == -1) {
+ $data->displaytype = null;
+ }
+ grade_set_setting($course->id, 'displaytype', $data->displaytype);
+
+ if ($data->decimalpoints == -1) {
+ $data->decimalpoints = null;
+ }
+ grade_set_setting($course->id, 'decimalpoints', $data->decimalpoints);
+
+ if ($data->aggregationposition == -1) {
+ $data->aggregationposition = null;
+ }
+ grade_set_setting($course->id, 'aggregationposition', $data->aggregationposition);
+
+ redirect($returnurl);
+}
+
+/// Print header
+print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
+/// Print the plugin selector at the top
+print_grade_plugin_selector($courseid, 'edit', 'settings');
+
+$mform->display();
+
+print_footer($course);
+
+?>
+
$object = $element['object'];
}
-$switch = grade_report::get_pref('aggregationposition');
+$switch = grade_get_setting($course->id, 'aggregationposition', $CFG->grade_aggregationposition);
$strgrades = get_string('grades');
$strgraderreport = get_string('graderreport', 'grades');
false, true, false, get_string('aggregationcoefhelp', 'grades')));
/// grade display prefs
- $this->displayoptions = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'),
- GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
- GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
- GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
- $mform->addElement('select', 'display', null, $this->displayoptions);
+
+ $default_gradedisplaytype = grade_get_setting($COURSE->id, 'displaytype', $CFG->grade_displaytype);
+ $options = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'),
+ GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
+ GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
+ GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
+ foreach ($options as $key=>$option) {
+ if ($key == $default_gradedisplaytype) {
+ $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option);
+ break;
+ }
+ }
+ $mform->addElement('select', 'display', get_string('gradedisplaytype', 'grades'), $options);
$mform->setHelpButton('display', array(false, get_string('gradedisplaytype', 'grades'),
false, true, false, get_string('configgradedisplaytype', 'grades')));
- $options = array(-1=>get_string('default', 'grades'), 0, 1, 2, 3, 4, 5);
- $mform->addElement('select', 'decimals', null, $options);
+ $default_gradedecimals = grade_get_setting($COURSE->id, 'decimalpoints', $CFG->grade_decimalpoints);
+ $options = array(-1=>get_string('defaultprev', 'grades', $default_gradedecimals), 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
+ $mform->addElement('select', 'decimals', get_string('decimalpoints', 'grades'), $options);
$mform->setHelpButton('decimals', array(false, get_string('decimalpoints', 'grades'),
false, true, false, get_string('configdecimalpoints', 'grades')));
- $mform->setDefault('decimals', GRADE_REPORT_PREFERENCE_DEFAULT);
+ $mform->setDefault('decimals', -1);
$mform->disabledIf('decimals', 'display', 'eq', GRADE_DISPLAY_TYPE_LETTER);
+ if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
+ $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
+ }
/// hiding
/// advcheckbox is not compatible with disabledIf !!
$mform->removeElement('aggregationcoef');
}
}
-
- // setup defaults and extra locking based on it
- $course_item = grade_item::fetch_course_item($COURSE->id);
- $default_gradedisplaytype = $course_item->get_displaytype();
- $default_gradedecimals = $course_item->get_decimals();
-
- $option_value = 'error';
- foreach ($this->displayoptions as $key => $option) {
- if ($key == $default_gradedisplaytype) {
- $option_value = $option;
- break;
- }
- }
- $displaytypeEl =& $mform->getElement('display');
- $displaytypeEl->setLabel(get_string('gradedisplaytype', 'grades').' ('.get_string('default', 'grades').': '.$option_value.')');
-
- $decimalsEl =& $mform->getElement('decimals');
- $decimalsEl->setLabel(get_string('decimalpoints', 'grades').' ('.get_string('default', 'grades').': '.$default_gradedecimals.')');
-
- // Disable decimals if displaytype is DEFAULT and course or site displaytype is LETTER
- if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
- $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
- }
}
$menu[$url] = get_string('letters', 'grades');
}
+ if (has_capability('moodle/grade:manage', $context)) {
+ $url = 'edit/settings/index.php?id='.$courseid;
+ if ($active_type == 'edit' and $active_plugin == 'settings' ) {
+ $active = $url;
+ }
+ $menu[$url] = get_string('coursesettings', 'grades');
+ }
+
}
/// finally print/return the popup form
$result = array();
foreach ($children as $child) {
- if ($child['type']== 'category') {
+ if ($child['type'] == 'category') {
$result = array_merge($result, grade_seq::flatten($child, $category_grade_last, $nooutcomes));
} else {
$child['eid'] = 'i'.$child['object']->id;
$nooutcomes = get_user_preferences('grade_report_shownooutcomes');
}
+ // if user report preference set or site report setting set use it, otherwise use course or site setting
+ $switch = $this->get_pref('aggregationposition');
+ if ($switch == GRADE_REPORT_PREFERENCE_INHERIT) {
+ $switch = grade_get_setting($this->courseid, 'aggregationposition', $CFG->grade_aggregationposition);
+ }
+
// Grab the grade_tree for this course
- $this->gtree = new grade_tree($this->courseid, true, $this->get_pref('aggregationposition'), $this->collapsed, $nooutcomes);
+ $this->gtree = new grade_tree($this->courseid, true, $switch, $this->collapsed, $nooutcomes);
$this->sortitemid = $sortitemid;
if ($canviewhidden) {
$hidingsql1 = "";
$hidingsql2 = "";
-
+
} else {
$now = round(time(), -2); //100 sec gradularity, we need some db caching speedup here
$hidingsql1 = "AND g.hidden!=1 AND (g.hidden=0 OR g.hidden<$now)";
if ($USER->gradeediting[$this->courseid]) {
$displaytype = GRADE_DISPLAY_TYPE_REAL;
- } else if ($averagesdisplaytype == GRADE_REPORT_PREFERENCE_DEFAULT
- || $averagesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT
- || $averagesdisplaytype == 0) {
+ } else if ($averagesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT) { // no ==0 here, please resave the report and user preferences
$displaytype = $item->get_displaytype();
} else {
}
// Override grade_item setting if a display preference (not inherit) was set for the averages
- if ($averagesdecimalpoints == GRADE_REPORT_PREFERENCE_DEFAULT
- || $averagesdecimalpoints == GRADE_REPORT_PREFERENCE_INHERIT) {
+ if ($averagesdecimalpoints == GRADE_REPORT_PREFERENCE_INHERIT) {
$decimalpoints = $item->get_decimals();
} else {
if ($USER->gradeediting[$this->courseid]) {
$displaytype = GRADE_DISPLAY_TYPE_REAL;
- } else if ($rangesdisplaytype == GRADE_REPORT_PREFERENCE_DEFAULT
- || $rangesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT
- || $rangesdisplaytype == 0 ) {
+ } else if ($rangesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT) { // no ==0 here, please resave report and user prefs
$displaytype = $item->get_displaytype();
} else {
}
// Override grade_item setting if a display preference (not default) was set for the averages
- if ($rangesdecimalpoints == GRADE_REPORT_PREFERENCE_DEFAULT
- or $rangesdecimalpoints == GRADE_REPORT_PREFERENCE_INHERIT) {
+ if ($rangesdecimalpoints == GRADE_REPORT_PREFERENCE_INHERIT) {
$decimalpoints = $item->get_decimals();
} else {
// If USER has admin capability, print a link to the site config page for this report
if (has_capability('moodle/site:config', $systemcontext)) {
echo '<div id="siteconfiglink"><a href="' . $CFG->wwwroot . '/admin/settings.php?section=gradereportgrader">';
- echo get_string('changesitedefaults', 'grades');
+ echo get_string('changereportdefaults', 'grades');
echo "</a></div>\n";
}
$checkbox_default = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*', 0 => $strno, 1 => $stryes);
+ $advanced = array();
/// form definition with preferences defaults
//--------------------------------------------------------------------------------
$preferences = array();
'showlocks' => $checkbox_default);
$preferences['prefrows'] = array(
- 'rangesdisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default'),
+ 'rangesdisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
+ GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'),
GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades')),
- 'rangesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default'),
- '0'=>0, '1'=>1, '2'=>2, '3'=>3, '4'=>4, '5'=>5),
- 'averagesdisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default'),
+ 'rangesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
+ GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'),
+ 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5),
+ 'averagesdisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
+ GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'),
GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades')),
- 'averagesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default'),
- '0'=>0, '1'=>1, '2'=>2, '3'=>3, '4'=>4, '5'=>5),
+ 'averagesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
+ GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'),
+ 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5),
'meanselection' => array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
GRADE_REPORT_MEAN_ALL => get_string('meanall', 'grades'),
GRADE_REPORT_MEAN_GRADED => get_string('meangraded', 'grades')));
-
+ $advanced = array_merge($advanced, array('rangesdisplaytype', 'rangesdecimalpoints', 'averagesdisplaytype', 'averagesdecimalpoints'));
}
// quickgrading and quickfeedback are conditional on grade:edit capability
if (has_capability('gradereport/grader:view', $context)) {
$preferences['prefgeneral']['studentsperpage'] = 'text';
$preferences['prefgeneral']['aggregationposition'] = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
- GRADE_REPORT_AGGREGATION_POSITION_LEFT => get_string('left', 'grades'),
- GRADE_REPORT_AGGREGATION_POSITION_RIGHT => get_string('right', 'grades'));
+ GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'),
+ GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'),
+ GRADE_REPORT_AGGREGATION_POSITION_LAST => get_string('positionlast', 'grades'));
// $preferences['prefgeneral']['enableajax'] = $checkbox_default;
$preferences['prefshow']['showuserimage'] = $checkbox_default;
$preferences['prefshow']['showranges'] = $checkbox_default;
$preferences['prefrows']['shownumberofgrades'] = $checkbox_default;
+
+ $advanced = array_merge($advanced, array('aggregationposition'));
}
$options = $type;
$type = 'select';
// MDL-11478
- if (isset($options[$CFG->$full_pref])) {
- $default = $options[$CFG->$full_pref];
+ if (isset($options[$CFG->{$full_pref}])) {
+ $default = $options[$CFG->{$full_pref}];
} else {
- $default = '';
+ $default = '';
}
} else {
$default = $CFG->$full_pref;
// Replace the '*default*' value with the site default language string - 'default' might collide with custom language packs
if (!is_null($options) AND isset($options[GRADE_REPORT_PREFERENCE_DEFAULT]) && $options[GRADE_REPORT_PREFERENCE_DEFAULT] == '*default*') {
- $options[GRADE_REPORT_PREFERENCE_DEFAULT] = get_string('sitedefault', 'grades', $default);
+ $options[GRADE_REPORT_PREFERENCE_DEFAULT] = get_string('reportdefault', 'grades', $default);
} elseif ($type == 'text') {
$help_string = get_string("config{$lang_string}default", 'grades', $default);
}
}
}
+ foreach($advanced as $name) {
+ $mform->setAdvanced('grade_report_'.$name);
+ }
+
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->setDefault('id', $course->id);
$strpercentage = get_string('percentage', 'grades');
$strreal = get_string('real', 'grades');
$strletter = get_string('letter', 'grades');
-$strdefault = get_string('default');
+$strinherit = get_string('inherit', 'grades');
/// Add settings for this module to the $settings object (it's already defined)
$settings->add(new admin_setting_configtext('grade_report_studentsperpage', get_string('studentsperpage', 'grades'),
get_string('configquickfeedback', 'grades'), 1));
$settings->add(new admin_setting_configselect('grade_report_aggregationposition', get_string('aggregationposition', 'grades'),
- get_string('configaggregationposition', 'grades'), GRADE_REPORT_AGGREGATION_POSITION_RIGHT,
- array(GRADE_REPORT_AGGREGATION_POSITION_LEFT => get_string('left', 'grades'),
- GRADE_REPORT_AGGREGATION_POSITION_RIGHT => get_string('right', 'grades'))));
+ get_string('configaggregationposition', 'grades'), GRADE_REPORT_PREFERENCE_INHERIT,
+ array(GRADE_REPORT_PREFERENCE_INHERIT => $strinherit,
+ GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'),
+ GRADE_REPORT_AGGREGATION_POSITION_LAST => get_string('positionlast', 'grades'))));
$settings->add(new admin_setting_configselect('grade_report_aggregationview', get_string('aggregationview', 'grades'),
get_string('configaggregationview', 'grades'), GRADE_REPORT_AGGREGATION_VIEW_FULL,
get_string('configshownumberofgrades', 'grades'), 0));
$settings->add(new admin_setting_configselect('grade_report_averagesdisplaytype', get_string('averagesdisplaytype', 'grades'),
- get_string('configaveragesdisplaytype', 'grades'), GRADE_REPORT_PREFERENCE_DEFAULT,
- array(GRADE_REPORT_PREFERENCE_DEFAULT => $strdefault,
+ get_string('configaveragesdisplaytype', 'grades'), GRADE_REPORT_PREFERENCE_INHERIT,
+ array(GRADE_REPORT_PREFERENCE_INHERIT => $strinherit,
GRADE_DISPLAY_TYPE_REAL => $strreal,
GRADE_DISPLAY_TYPE_PERCENTAGE => $strpercentage,
GRADE_DISPLAY_TYPE_LETTER => $strletter)));
$settings->add(new admin_setting_configselect('grade_report_rangesdisplaytype', get_string('rangesdisplaytype', 'grades'),
- get_string('configrangesdisplaytype', 'grades'), GRADE_REPORT_PREFERENCE_DEFAULT,
- array(GRADE_REPORT_PREFERENCE_DEFAULT => $strdefault,
+ get_string('configrangesdisplaytype', 'grades'), GRADE_REPORT_PREFERENCE_INHERIT,
+ array(GRADE_REPORT_PREFERENCE_INHERIT => $strinherit,
GRADE_DISPLAY_TYPE_REAL => $strreal,
GRADE_DISPLAY_TYPE_PERCENTAGE => $strpercentage,
GRADE_DISPLAY_TYPE_LETTER => $strletter)));
$settings->add(new admin_setting_configselect('grade_report_averagesdecimalpoints', get_string('averagesdecimalpoints', 'grades'),
get_string('configaveragesdecimalpoints', 'grades'), 2,
- array(GRADE_REPORT_PREFERENCE_DEFAULT => $strdefault,
+ array(GRADE_REPORT_PREFERENCE_INHERIT => $strinherit,
'0' => '0',
'1' => '1',
'2' => '2',
'5' => '5')));
$settings->add(new admin_setting_configselect('grade_report_rangesdecimalpoints', get_string('rangesdecimalpoints', 'grades'),
get_string('configrangesdecimalpoints', 'grades'), 2,
- array(GRADE_REPORT_PREFERENCE_DEFAULT => $strdefault,
+ array(GRADE_REPORT_PREFERENCE_INHERIT => $strinherit,
'0' => '0',
'1' => '1',
'2' => '2',
has_capability('gradereport/grader:view', $tabcontext)) {
$row[] = new tabobject('preferences',
$CFG->wwwroot.'/grade/report/grader/preferences.php?id='.$courseid,
- get_string('preferences'));
+ get_string('myreportpreferences', 'grades'));
}
$tabs[] = $row;
*/
var $table;
+ /**
+ * Flat structure similar to grade tree
+ */
+ var $gseq;
+
/**
* Constructor. Sets local copies of user preferences and initialises grade_tree.
* @param int $courseid
global $CFG;
parent::grade_report($courseid, $gpr, $context);
+ $switch = grade_get_setting($this->courseid, 'aggregationposition', $CFG->grade_aggregationposition);
+
// Grab the grade_tree for this course
- $this->gtree = new grade_tree($this->courseid, true, $this->get_pref('aggregationposition'));
+ $this->gseq = new grade_seq($this->courseid, $switch);
// get the user (for full name)
$this->user = get_record('user', 'id', $userid);
$this->baseurl = $CFG->wwwroot.'/grade/report?id='.$courseid.'&userid='.$userid;
$this->pbarurl = $this->baseurl;
- // Setup groups if requested
- if ($this->get_pref('showgroups')) {
- $this->setup_groups();
- }
+ // always setup groups - no user preference here
+ $this->setup_groups();
$this->setup_table();
}
global $CFG;
$numusers = $this->get_numusers(false); // total course users
- if ($all_grade_items = grade_item::fetch_all(array('courseid'=>$this->courseid))) {
- $grade_items = array();
- foreach ($all_grade_items as $item) {
- $grade_items[$item->sortorder] = $item;
- }
- unset($all_grade_items);
- ksort($grade_items);
-
- $total = $grade_items[1];
- unset($grade_items[1]);
- $grade_items[] = $total;
-
- foreach ($grade_items as $grade_item) {
+ foreach ($this->gseq->items as $element) {
+ $grade_item = $element['object'];
+ $decimalpoints = $grade_item->get_decimals();
+ $data = array();
- $decimalpoints = $grade_item->get_decimals();
- $data = array();
+ $grade_grade = new grade_grade(array('itemid'=>$grade_item->id, 'userid'=>$this->user->id));
+ $grade_grade->grade_item =& $grade_item;
- $grade_grade = new grade_grade(array('itemid'=>$grade_item->id, 'userid'=>$this->user->id));
+ // TODO: indicate items that "needsupdate" - missing final calculation
- // TODO: indicate items that "needsupdate" - missing final calculation
+ /// prints grade item name
+ if ($grade_item->is_course_item() or $grade_item->is_category_item()) {
+ $data[] = '<b>'.$grade_item->get_name().'</b>';
+ } else {
+ $data[] = $this->get_module_link($grade_item->get_name(), $grade_item->itemmodule, $grade_item->iteminstance);;
+ }
- /// prints grade item name
- if ($grade_item->is_course_item() or $grade_item->is_category_item()) {
- $data[] = '<b>'.$grade_item->get_name().'</b>';
- } else {
- $data[] = $this->get_module_link($grade_item->get_name(), $grade_item->itemmodule, $grade_item->iteminstance);;
- }
+ /// prints category
+ $cat = $grade_item->get_parent_category();
+ $data[] = $cat->fullname;
- /// prints category
- $cat = $grade_item->get_parent_category();
- $data[] = $cat->fullname;
+ /// prints the grade
+ $displaytype = $grade_item->get_displaytype();
- /// prints the grade
- $displaytype = $grade_item->get_displaytype();
+ if ($grade_grade->is_excluded()) {
+ $excluded = get_string('excluded', 'grades').' ';
+ } else {
+ $excluded = '';
+ }
- if ($grade_grade->is_excluded()) {
- $excluded = get_string('excluded', 'grades').' ';
- } else {
- $excluded = '';
+ if ((int) $grade_grade->finalgrade < 1) {
+ $data[] = '-';
+ } elseif ($grade_grade->is_hidden() && !has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $grade_item->courseid))) {
+ $data[] = get_string('gradedon', 'grades', userdate($grade_grade->timemodified));
+ } elseif ($grade_item->scaleid) {
+ if ($scale = get_record('scale', 'id', $grade_item->scaleid)) {
+ $scales = explode(",", $scale->scale);
+ // reindex because scale is off 1
+ $data[] = $excluded.$scales[$grade_grade->finalgrade-1];
}
+ } else {
+ $data[] = $excluded . grade_format_gradevalue($grade_grade->finalgrade, $grade_item, true, $displaytype, $decimalpoints);
+ }
+
+ /// prints percentage
+ if ($grade_grade->is_hidden() && !has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $grade_item->courseid))) {
if ((int) $grade_grade->finalgrade < 1) {
$data[] = '-';
- } elseif ($grade_grade->is_hidden() && !has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $grade_item->courseid))) {
- $data[] = get_string('gradedon', 'grades', userdate($grade_grade->timemodified));
- } elseif ($grade_item->scaleid) {
- if ($scale = get_record('scale', 'id', $grade_item->scaleid)) {
- $scales = explode(",", $scale->scale);
- // reindex because scale is off 1
- $data[] = $excluded.$scales[$grade_grade->finalgrade-1];
- }
} else {
- $data[] = $excluded . grade_format_gradevalue($grade_grade->finalgrade, $grade_item, true, $displaytype, $decimalpoints);
- }
-
- /// prints percentage
-
- if ($grade_grade->is_hidden() && !has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $grade_item->courseid))) {
- if ((int) $grade_grade->finalgrade < 1) {
- $data[] = '-';
- } else {
- $data[] = get_string('gradedon', 'grades', userdate($grade_grade->timemodified));
- }
- } else {
- if ($grade_item->gradetype == GRADE_TYPE_VALUE) {
- // processing numeric grade
- if ($grade_grade->finalgrade) {
- $percentage = format_float(($grade_grade->finalgrade / $grade_item->grademax) * 100, $decimalpoints).'%';
- } else {
- $percentage = '-';
- }
-
- } else if ($grade_item->gradetype == GRADE_TYPE_SCALE) {
- // processing scale grade
- $scale = get_record('scale', 'id', $grade_item->scaleid);
- $scalevals = explode(",", $scale->scale);
- $percentage = format_float(($grade_grade->finalgrade) / count($scalevals) * 100, $decimalpoints).'%';
-
+ $data[] = get_string('gradedon', 'grades', userdate($grade_grade->timemodified));
+ }
+ } else {
+ if ($grade_item->gradetype == GRADE_TYPE_VALUE) {
+ // processing numeric grade
+ if ($grade_grade->finalgrade) {
+ $percentage = format_float(($grade_grade->finalgrade / $grade_item->grademax) * 100, $decimalpoints).'%';
} else {
- // text grade
$percentage = '-';
}
- $data[] = $percentage;
- }
- /// prints rank
- if ($grade_grade->finalgrade) {
- /// find the number of users with a higher grade
- $sql = "SELECT COUNT(DISTINCT(userid))
- FROM {$CFG->prefix}grade_grades
- WHERE finalgrade > $grade_grade->finalgrade
- AND itemid = $grade_item->id";
- $rank = count_records_sql($sql) + 1;
-
- $data[] = "$rank/$numusers";
- } else {
- // no grade, no rank
- $data[] = "-";
- }
+ } else if ($grade_item->gradetype == GRADE_TYPE_SCALE) {
+ // processing scale grade
+ $scale = get_record('scale', 'id', $grade_item->scaleid);
+ $scalevals = explode(",", $scale->scale);
+ $percentage = format_float(($grade_grade->finalgrade) / count($scalevals) * 100, $decimalpoints).'%';
- /// prints notes
- if (!empty($grade_grade->feedback)) {
- $data[] = format_text($grade_grade->feedback, $grade_grade->feedbackformat);
} else {
- $data[] = ' ';
+ // text grade
+ $percentage = '-';
}
- $this->table->add_data($data);
+
+ $data[] = $percentage;
+ }
+ /// prints rank
+ if ($grade_grade->finalgrade) {
+ /// find the number of users with a higher grade
+ $sql = "SELECT COUNT(DISTINCT(userid))
+ FROM {$CFG->prefix}grade_grades
+ WHERE finalgrade > $grade_grade->finalgrade
+ AND itemid = $grade_item->id";
+ $rank = count_records_sql($sql) + 1;
+
+ $data[] = "$rank/$numusers";
+ } else {
+ // no grade, no rank
+ $data[] = "-";
}
- return true;
- } else {
- notify(get_string('nogradeitem', 'grades'));
- return false;
+ /// prints notes
+ if (!empty($grade_grade->feedback)) {
+ $data[] = format_text($grade_grade->feedback, $grade_grade->feedbackformat);
+ } else {
+ $data[] = ' ';
+ }
+ $this->table->add_data($data);
}
+
+ return true;
}
/**
$string['categoryedit'] = 'Edit Category';
$string['categoryname'] = 'Category name';
$string['categorytotal'] = 'Category total';
-$string['changesitedefaults'] = 'Change site defaults';
+$string['changereportdefaults'] = 'Change report defaults';
$string['choosecategory'] = 'Select Category';
$string['compact'] = 'Compact';
-$string['configaggregationposition'] = 'The position of the aggregation column in the grader report table, in reference to the real grades.';
+$string['configaggregationposition'] = 'The position of the aggregation column in the report, in reference to the real grades.';
$string['configaggregationview'] = 'Each category can be displayed in three ways: Full mode (aggregated column and grade item columns), the aggregated column only, or the grade items alone.';
$string['configaveragesdecimalpoints'] = 'The number of decimal points to display for each average (group or whole), below a column of grades.';
$string['configaveragesdisplaytype'] = 'Specifies how to display the averages for each column in the grader report. Default means to use the display type of each column.';
$string['curveto'] = 'Curve To';
$string['decimalpoints'] = 'Overall decimal points';
$string['default'] = 'Default';
+$string['defaultprev'] = 'Default ($a)';
$string['deletecategory'] = 'Delete Category';
$string['displaylettergrade'] = 'Display Letter Grades';
$string['displaypercent'] = 'Display Percents';
$string['keephigh'] = 'Keep the highest';
$string['keephighhelp'] = 'If set, this option will only keep the X highest grades, X being the selected value for this option.';
$string['keymanager'] = 'Key manager';
-$string['left'] = 'Left';
$string['lettergrade'] = 'Letter Grade';
$string['lettergradenonnumber'] = 'Low and/or High grade were non-numeric for';
$string['letter'] = 'Letter';
$string['movingelement'] = 'Moving $a';
$string['multfactor'] = 'Multiplicator';
$string['multfactorhelp'] = 'Factor by which all grades for this grade item will be multiplied.';
+$string['myreportpreferences'] = 'My report preferences';
$string['newcategory'] = 'New category';
$string['newuserkey'] = 'New user key';
$string['no'] = 'No';
$string['points'] = 'points';
$string['pointsascending'] = 'Sort by points ascending';
$string['pointsdescending'] = 'Sort by points descdending';
+$string['positionfirst'] = 'First';
+$string['positionlast'] = 'Last';
$string['preferences'] = 'Preferences';
$string['prefgeneral'] = 'General';
$string['prefletters'] = 'Grade letters and boundaries';
$string['rawpct'] = 'Raw %%';
$string['real'] = 'Real';
$string['report'] = 'Report';
+$string['reportdefault'] = 'Report default ($a)';
$string['reportplugins'] = 'Report plugins';
$string['reportsettings'] = 'Report settings';
$string['reprintheaders'] = 'Reprint Headers';
$string['respectingcurrentdata'] = 'leaving current configuration unmodified';
-$string['right'] = 'Right';
$string['rowpreviewnum'] = 'Preview rows';
$string['savechanges'] = 'Save Changes';
$string['savepreferences'] = 'Save Preferences';
$string['shownumberofgrades'] = 'Show number of grades in averages';
$string['showranges'] = 'Show ranges';
$string['showuserimage'] = 'Show user profile images';
-$string['sitedefault'] = 'Site default ($a)';
$string['sitewide'] = 'Site-wide';
$string['sort'] = 'sort';
$string['sortasc'] = 'Sort in ascending order';
<INDEX NAME="contextid-lowerboundary" UNIQUE="false" FIELDS="contextid, lowerboundary" COMMENT="index used when fetching context letters"/>
</INDEXES>
</TABLE>
- <TABLE NAME="cache_flags" COMMENT="Cache of time-sensitive flags" PREVIOUS="grade_letters">
+ <TABLE NAME="cache_flags" COMMENT="Cache of time-sensitive flags" PREVIOUS="grade_letters" NEXT="grade_settings">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="flagtype"/>
<FIELD NAME="flagtype" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="name"/>
<INDEX NAME="name" UNIQUE="false" FIELDS="name" PREVIOUS="flagtype"/>
</INDEXES>
</TABLE>
+ <TABLE NAME="grade_settings" COMMENT="gradebook settings" PREVIOUS="cache_flags">
+ <FIELDS>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="courseid"/>
+ <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="name"/>
+ <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="courseid" NEXT="value"/>
+ <FIELD NAME="value" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="name"/>
+ </FIELDS>
+ <KEYS>
+ <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="courseid"/>
+ <KEY NAME="courseid" TYPE="foreign" FIELDS="courseid" REFTABLE="course" REFFIELDS="id" PREVIOUS="primary"/>
+ </KEYS>
+ <INDEXES>
+ <INDEX NAME="courseid-name" UNIQUE="true" FIELDS="courseid, name"/>
+ </INDEXES>
+ </TABLE>
</TABLES>
<STATEMENTS>
<STATEMENT NAME="insert mnet_application" TYPE="insert" TABLE="mnet_application" COMMENT="Initial insert of records on table mnet_application" NEXT="insert log_display">
}
+ if ($result && $oldversion < 2007100803) {
+
+ /// Define table grade_settings to be created
+ $table = new XMLDBTable('grade_settings');
+
+ /// Adding fields to table grade_settings
+ $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
+ $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
+ $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
+ $table->addFieldInfo('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
+
+ /// Adding keys to table grade_settings
+ $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
+ $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
+
+ /// Adding indexes to table grade_settings
+ $table->addIndexInfo('courseid-name', XMLDB_INDEX_UNIQUE, array('courseid', 'name'));
+
+ /// Launch create table for grade_settings
+ $result = $result && create_table($table);
+ }
+
/* NOTE: please keep this at the end of upgrade file for now ;-)
/// drop old gradebook tables
define('GRADE_DISPLAY_TYPE_PERCENTAGE', 2);
define('GRADE_DISPLAY_TYPE_LETTER', 3);
-define('GRADE_REPORT_AGGREGATION_POSITION_LEFT', 0);
-define('GRADE_REPORT_AGGREGATION_POSITION_RIGHT', 1);
+define('GRADE_REPORT_AGGREGATION_POSITION_FIRST', 0);
+define('GRADE_REPORT_AGGREGATION_POSITION_LAST', 1);
define('GRADE_REPORT_AGGREGATION_VIEW_FULL', 0);
define('GRADE_REPORT_AGGREGATION_VIEW_AGGREGATES_ONLY', 1);
define('GRADE_REPORT_AGGREGATION_VIEW_GRADES_ONLY', 2);
-define('GRADE_REPORT_PREFERENCE_DEFAULT', 'default');
-define('GRADE_REPORT_PREFERENCE_INHERIT', 'inherit');
+
+define('GRADE_REPORT_PREFERENCE_DEFAULT', 'default'); // means use setting from site preferences
+define('GRADE_REPORT_PREFERENCE_INHERIT', 'inherit'); // means inherit from parent
define('GRADE_REPORT_PREFERENCE_UNUSED', -1);
+
define('GRADE_REPORT_MEAN_ALL', 0);
define('GRADE_REPORT_MEAN_GRADED', 1);
?>
}
}
}
-
+
/**
* Returns the number of grades that are hidden.
* @param return int Number of hidden grades
}
/**
- * Returns the value of the display type. It can be set at 3 levels: grade_item, course and site. The lowest level overrides the higher ones.
+ * Returns the value of the display type. It can be set at 3 levels: grade_item, course setting and site. The lowest level overrides the higher ones.
* @return int Display type
*/
function get_displaytype() {
global $CFG;
- static $cache = array();
if ($this->display == GRADE_DISPLAY_TYPE_DEFAULT) {
- if (array_key_exists($this->courseid, $cache)) {
- return $cache[$this->courseid];
- } else if (count($cache) > 100) {
- $cache = array(); // cache size limit
- }
-
- $gradedisplaytype = get_field('grade_items', 'display', 'courseid', $this->courseid, 'itemtype', 'course');
- if ($gradedisplaytype == GRADE_DISPLAY_TYPE_DEFAULT) {
- $gradedisplaytype = $CFG->grade_displaytype;
- }
- $cache[$this->courseid] = $gradedisplaytype;
- return $gradedisplaytype;
+ return grade_get_setting($this->courseid, 'displaytype', $CFG->grade_displaytype);
} else {
return $this->display;
}
/**
- * Returns the value of the decimals field. It can be set at 3 levels: grade_item, course and site. The lowest level overrides the higher ones.
+ * Returns the value of the decimals field. It can be set at 3 levels: grade_item, course setting and site. The lowest level overrides the higher ones.
* @return int Decimals (0 - 5)
*/
function get_decimals() {
global $CFG;
- static $cache = array();
if (is_null($this->decimals)) {
- if (array_key_exists($this->courseid, $cache)) {
- return $cache[$this->courseid];
- } else if (count($cache) > 100) {
- $cache = array(); // cache size limit
- }
- $gradedecimals = get_field('grade_items', 'decimals', 'courseid', $this->courseid, 'itemtype', 'course');
- if (is_null($gradedecimals)) {
- $gradedecimals = $CFG->grade_decimalpoints;
- }
- $cache[$this->courseid] = $gradedecimals;
- return $gradedecimals;
+ return grade_get_setting($this->courseid, 'decimalpoints', $CFG->grade_decimalpoints);
} else {
return $this->decimals;
/***** END OF PUBLIC API *****/
+
+/**
+ * Returns course gradebook setting
+ * @param int $courseid
+ * @param string $name of setting, maybe null if reset only
+ * @param bool $resetcache force reset of internal static cache
+ * @return string value, NULL if no setting
+ */
+function grade_get_setting($courseid, $name, $default=null, $resetcache=false) {
+ static $cache = array();
+
+ if ($resetcache or !array_key_exists($courseid, $cache)) {
+ $cache[$courseid] = array();
+
+ } else if (is_null($name)) {
+ return null;
+
+ } else if (array_key_exists($name, $cache[$courseid])) {
+ return $cache[$courseid][$name];
+ }
+
+ if (!$data = get_record('grade_settings', 'courseid', $courseid, 'name', addslashes($name))) {
+ $result = null;
+ } else {
+ $result = $data->value;
+ }
+
+ if (is_null($result)) {
+ $result = $default;
+ }
+
+ $cache[$courseid][$name] = $result;
+ return $result;
+}
+
+/**
+ * Add/update course gradebook setting
+ * @param int $courseid
+ * @param string $name of setting
+ * @param string value, NULL means no setting==remove
+ * @return void
+ */
+function grade_set_setting($courseid, $name, $value) {
+ if (is_null($value)) {
+ delete_records('grade_settings', 'courseid', $courseid, 'name', addslashes($name));
+
+ } else if (!$existing = get_record('grade_settings', 'courseid', $courseid, 'name', addslashes($name))) {
+ $data = new object();
+ $data->courseid = $courseid;
+ $data->name = addslashes($name);
+ $data->value = addslashes($value);
+ insert_record('grade_settings', $data);
+
+ } else {
+ $data = new object();
+ $data->id = $existing->id;
+ $data->value = addslashes($value);
+ update_record('grade_settings', $data);
+ }
+
+ grade_get_setting($courseid, null, null, true); // reset the cache
+}
+
/**
* Returns string representation of grade value
* @param float $value grade value
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2007100802; // YYYYMMDD = date
+ $version = 2007100805; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.9 Beta +'; // Human-friendly version name