$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'));
$mform->setHelpButton('aggregationposition', array(false, get_string('aggregationposition', 'grades'),
false, true, false, get_string('configaggregationposition', 'grades')));
+// add setting options for plugins
+ $types = array('report', 'export', 'import');
+
+ foreach($types as $type) {
+ foreach (get_list_of_plugins('grade/'.$type) as $plugin) {
+ // Include all the settings commands for this plugin if there are any
+ if (file_exists($CFG->dirroot.'/grade/'.$type.'/'.$plugin.'/lib.php')) {
+ require_once($CFG->dirroot.'/grade/'.$type.'/'.$plugin.'/lib.php');
+ $functionname = 'grade_'.$type.'_'.$plugin.'_settings_definition';
+ if (function_exists($functionname)) {
+ $mform->addElement('header', 'grade_'.$type.$plugin, get_string('modulename', 'grade'.$type.'_'.$plugin, NULL, $CFG->dirroot.'/grade/'.$type.'/'.$plugin.'/lang/'));
+ $functionname($mform);
+ }
+ }
+ }
+ }
+
+ $mform->addElement('hidden', 'id');
+ $mform->setType('id', PARAM_INT);
$this->add_action_buttons();
}
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');
$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);
+$settings = grade_get_settings($course->id);
-$mform->set_data($data);
+$mform->set_data($settings);
if ($mform->is_cancelled()) {
redirect($returnurl);
} else if ($data = $mform->get_data()) {
- if ($data->displaytype == -1) {
- $data->displaytype = null;
+ $data = (array)$data;
+ $general = array('displaytype', 'decimalpoints', 'aggregationposition');
+ foreach ($data as $key=>$value) {
+ if (!in_array($key, $general) and strpos($key, 'report_') !== 0
+ and strpos($key, 'import_') !== 0
+ and strpos($key, 'export_') !== 0) {
+ continue;
+ }
+ if ($value == -1) {
+ $value = null;
+ }
+ grade_set_setting($course->id, $key, $value);
}
- 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);
}
*/
var $gseq;
+ /**
+ * show student ranks
+ */
+ var $showrank;
+
+ /**
+ * Show hidden items even when user does not have required cap
+ */
+ var $showhiddenitems;
+
/**
* Constructor. Sets local copies of user preferences and initialises grade_tree.
* @param int $courseid
global $CFG;
parent::grade_report($courseid, $gpr, $context);
+ $this->showrank = grade_get_setting($this->courseid, 'report_user_showrank', !empty($CFG->grade_report_user_showrank));
+ $this->showhiddenitems = grade_get_setting($this->courseid, 'report_user_showhiddenitems', !empty($CFG->grade_report_user_showhiddenitems));
+
$switch = grade_get_setting($this->courseid, 'aggregationposition', $CFG->grade_aggregationposition);
// Grab the grade_tree for this course
*/
// setting up table headers
- if (!empty($CFG->grade_userreport_showrank)) {
+ if ($this->showrank) {
// TODO: this is broken if hidden grades present!!
$tablecolumns = array('itemname', 'category', 'grade', 'percentage', 'rank', 'feedback');
$tableheaders = array($this->get_lang_string('gradeitem', 'grades'), $this->get_lang_string('category'), $this->get_lang_string('grade'),
$grade_item =& $items[$itemid];
$grade_grade =& $grades[$itemid];
- if (empty($CFG->grade_userreport_showhiddenitems) and !$canviewhidden and $grade_item->is_hidden()) {
+ if (!$this->showhiddenitems and !$canviewhidden and $grade_item->is_hidden()) {
continue;
}
}
/// prints rank
- if (!empty($CFG->grade_userreport_showrank)) {
+ if ($this->showrank) {
// TODO: this is broken if hidden grades present!!
if ($grade_item->needsupdate) {
$data[] = '<span class="gradingerror">'.get_string('error').'</span>';
-
+
} else if (is_null($gradeval)) {
// no grade, no rank
$data[] = '-';
-
+
} else {
/// find the number of users with a higher grade
$sql = "SELECT COUNT(DISTINCT(userid))
WHERE finalgrade > {$grade_grade->finalgrade}
AND itemid = {$grade_item->id}";
$rank = count_records_sql($sql) + 1;
-
+
$data[] = "$rank/$numusers";
}
}
*/
function process_data($data) {
}
+}
+
+function grade_report_user_settings_definition(&$mform) {
+ global $CFG;
+
+ $options = array(-1 => get_string('default', 'grades'),
+ 0 => get_string('hide'),
+ 1 => get_string('show'));
+
+ if (empty($CFG->grade_userreport_showrank)) {
+ $options[-1] = get_string('defaultprev', 'grades', $options[0]);
+ } else {
+ $options[-1] = get_string('defaultprev', 'grades', $options[1]);
+ }
+
+ $mform->addElement('select', 'report_user_showrank', get_string('showrank', 'grades'), $options);
+ $mform->setHelpButton('report_user_showrank', array(false, get_string('showrank', 'grades'),
+ false, true, false, get_string('configshowrank', 'grades')));
+
+
+ $options = array(-1 => get_string('default', 'grades'),
+ 0 => get_string('hide'),
+ 1 => get_string('show'));
+
+ if (empty($CFG->grade_userreport_showrank)) {
+ $options[-1] = get_string('defaultprev', 'grades', $options[0]);
+ } else {
+ $options[-1] = get_string('defaultprev', 'grades', $options[1]);
+ }
+
+ $mform->addElement('select', 'report_user_showhiddenitems', get_string('showhiddenitems', 'grades'), $options);
+ $mform->setHelpButton('report_user_showhiddenitems', array(false, get_string('showhiddenitems', 'grades'),
+ false, true, false, get_string('configshowhiddenitems', 'grades')));
}
?>
/// Add settings for this module to the $settings object (it's already defined)
-$settings->add(new admin_setting_configcheckbox('grade_userreport_showrank', get_string('showrank', 'grades'), get_string('configshowrank', 'grades'), 0, PARAM_INT));
+$settings->add(new admin_setting_configcheckbox('grade_report_user_showrank', get_string('showrank', 'grades'), get_string('configshowrank', 'grades'), 0, PARAM_INT));
-$settings->add(new admin_setting_configcheckbox('grade_userreport_showhiddenitems', get_string('showhiddenitems', 'grades'), get_string('configshowhiddenitems', 'grades'), 0, PARAM_INT));
+$settings->add(new admin_setting_configcheckbox('grade_report_user_showhiddenitems', get_string('showhiddenitems', 'grades'), get_string('configshowhiddenitems', 'grades'), 0, PARAM_INT));
?>
return $result;
}
+/**
+ * Returns all course gradebook settings as object properties
+ * @param int $courseid
+ * @return object
+ */
+function grade_get_settings($courseid) {
+ $settings = new object();
+ $settings->id = $courseid;
+
+ if ($records = get_records('grade_settings', 'courseid', $courseid)) {
+ foreach ($records as $record) {
+ $settings->{$record->name} = $record->value;
+ }
+ }
+
+ return $settings;
+}
+
/**
* Add/update course gradebook setting
* @param int $courseid