mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-11718 course settings for reports - for now only user report (rank and showing of hidden items)
This commit is contained in:
parent
57068674c6
commit
26ed030543
5 changed files with 105 additions and 33 deletions
|
@ -59,11 +59,6 @@ class course_settings_form extends moodleform {
|
||||||
$mform->setHelpButton('decimalpoints', array(false, get_string('decimalpoints', 'grades'),
|
$mform->setHelpButton('decimalpoints', array(false, get_string('decimalpoints', 'grades'),
|
||||||
false, true, false, get_string('configdecimalpoints', 'grades')));
|
false, true, false, get_string('configdecimalpoints', 'grades')));
|
||||||
|
|
||||||
|
|
||||||
$mform->addElement('hidden', 'id');
|
|
||||||
$mform->setType('id', PARAM_INT);
|
|
||||||
|
|
||||||
|
|
||||||
$options = array(-1 => get_string('default', 'grades'),
|
$options = array(-1 => get_string('default', 'grades'),
|
||||||
GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'),
|
GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'),
|
||||||
GRADE_REPORT_AGGREGATION_POSITION_LAST => get_string('positionlast', 'grades'));
|
GRADE_REPORT_AGGREGATION_POSITION_LAST => get_string('positionlast', 'grades'));
|
||||||
|
@ -78,6 +73,25 @@ class course_settings_form extends moodleform {
|
||||||
$mform->setHelpButton('aggregationposition', array(false, get_string('aggregationposition', 'grades'),
|
$mform->setHelpButton('aggregationposition', array(false, get_string('aggregationposition', 'grades'),
|
||||||
false, true, false, get_string('configaggregationposition', '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();
|
$this->add_action_buttons();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ require_once $CFG->libdir.'/gradelib.php';
|
||||||
require_once 'form.php';
|
require_once 'form.php';
|
||||||
|
|
||||||
$courseid = optional_param('id', SITEID, PARAM_INT);
|
$courseid = optional_param('id', SITEID, PARAM_INT);
|
||||||
$action = optional_param('action', '', PARAM_ALPHA);
|
|
||||||
|
|
||||||
if (!$course = get_record('course', 'id', $courseid)) {
|
if (!$course = get_record('course', 'id', $courseid)) {
|
||||||
print_error('nocourseid');
|
print_error('nocourseid');
|
||||||
|
@ -50,32 +49,27 @@ $returnurl = $CFG->wwwroot.'/grade/index.php?id='.$course->id;
|
||||||
|
|
||||||
$mform = new course_settings_form();
|
$mform = new course_settings_form();
|
||||||
|
|
||||||
$data = new object;
|
$settings = grade_get_settings($course->id);
|
||||||
$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);
|
$mform->set_data($settings);
|
||||||
|
|
||||||
if ($mform->is_cancelled()) {
|
if ($mform->is_cancelled()) {
|
||||||
redirect($returnurl);
|
redirect($returnurl);
|
||||||
|
|
||||||
} else if ($data = $mform->get_data()) {
|
} else if ($data = $mform->get_data()) {
|
||||||
if ($data->displaytype == -1) {
|
$data = (array)$data;
|
||||||
$data->displaytype = null;
|
$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);
|
redirect($returnurl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,16 @@ class grade_report_user extends grade_report {
|
||||||
*/
|
*/
|
||||||
var $gseq;
|
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.
|
* Constructor. Sets local copies of user preferences and initialises grade_tree.
|
||||||
* @param int $courseid
|
* @param int $courseid
|
||||||
|
@ -65,6 +75,9 @@ class grade_report_user extends grade_report {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
parent::grade_report($courseid, $gpr, $context);
|
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);
|
$switch = grade_get_setting($this->courseid, 'aggregationposition', $CFG->grade_aggregationposition);
|
||||||
|
|
||||||
// Grab the grade_tree for this course
|
// Grab the grade_tree for this course
|
||||||
|
@ -94,7 +107,7 @@ class grade_report_user extends grade_report {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// setting up table headers
|
// setting up table headers
|
||||||
if (!empty($CFG->grade_userreport_showrank)) {
|
if ($this->showrank) {
|
||||||
// TODO: this is broken if hidden grades present!!
|
// TODO: this is broken if hidden grades present!!
|
||||||
$tablecolumns = array('itemname', 'category', 'grade', 'percentage', 'rank', 'feedback');
|
$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'),
|
$tableheaders = array($this->get_lang_string('gradeitem', 'grades'), $this->get_lang_string('category'), $this->get_lang_string('grade'),
|
||||||
|
@ -162,7 +175,7 @@ class grade_report_user extends grade_report {
|
||||||
$grade_item =& $items[$itemid];
|
$grade_item =& $items[$itemid];
|
||||||
$grade_grade =& $grades[$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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,15 +228,15 @@ class grade_report_user extends grade_report {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// prints rank
|
/// prints rank
|
||||||
if (!empty($CFG->grade_userreport_showrank)) {
|
if ($this->showrank) {
|
||||||
// TODO: this is broken if hidden grades present!!
|
// TODO: this is broken if hidden grades present!!
|
||||||
if ($grade_item->needsupdate) {
|
if ($grade_item->needsupdate) {
|
||||||
$data[] = '<span class="gradingerror">'.get_string('error').'</span>';
|
$data[] = '<span class="gradingerror">'.get_string('error').'</span>';
|
||||||
|
|
||||||
} else if (is_null($gradeval)) {
|
} else if (is_null($gradeval)) {
|
||||||
// no grade, no rank
|
// no grade, no rank
|
||||||
$data[] = '-';
|
$data[] = '-';
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/// find the number of users with a higher grade
|
/// find the number of users with a higher grade
|
||||||
$sql = "SELECT COUNT(DISTINCT(userid))
|
$sql = "SELECT COUNT(DISTINCT(userid))
|
||||||
|
@ -231,7 +244,7 @@ class grade_report_user extends grade_report {
|
||||||
WHERE finalgrade > {$grade_grade->finalgrade}
|
WHERE finalgrade > {$grade_grade->finalgrade}
|
||||||
AND itemid = {$grade_item->id}";
|
AND itemid = {$grade_item->id}";
|
||||||
$rank = count_records_sql($sql) + 1;
|
$rank = count_records_sql($sql) + 1;
|
||||||
|
|
||||||
$data[] = "$rank/$numusers";
|
$data[] = "$rank/$numusers";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,6 +289,39 @@ class grade_report_user extends grade_report {
|
||||||
*/
|
*/
|
||||||
function process_data($data) {
|
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')));
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
|
|
||||||
/// Add settings for this module to the $settings object (it's already defined)
|
/// 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));
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -459,6 +459,24 @@ function grade_get_setting($courseid, $name, $default=null, $resetcache=false) {
|
||||||
return $result;
|
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
|
* Add/update course gradebook setting
|
||||||
* @param int $courseid
|
* @param int $courseid
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue