From: skodak Date: Sun, 28 Oct 2007 17:15:00 +0000 (+0000) Subject: MDL-11934 grade report in user profile now selectable X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0a784551208d62496cc7b4dea3f756ab8f81acd9;p=moodle.git MDL-11934 grade report in user profile now selectable --- diff --git a/admin/settings/grades.php b/admin/settings/grades.php index 6aef71dba4..e6e0242b9e 100644 --- a/admin/settings/grades.php +++ b/admin/settings/grades.php @@ -11,6 +11,8 @@ $temp = new admin_settingpage('gradessettings', get_string('gradessettings', 'gr // 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'), get_string('configaggregationposition', 'grades'), GRADE_REPORT_AGGREGATION_POSITION_LAST, array(GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'), diff --git a/course/user.php b/course/user.php index 2a78196209..bf4330aa59 100644 --- a/course/user.php +++ b/course/user.php @@ -69,31 +69,17 @@ switch ($mode) { case "grade": - //TODO: make the report selectable somehow - $course = get_record('course', 'id', required_param('id', PARAM_INT)); - if (!empty($course->showgrades)) { - require_once $CFG->libdir.'/gradelib.php'; - require_once $CFG->dirroot.'/grade/lib.php'; - require_once $CFG->dirroot.'/grade/report/user/lib.php'; - - $context = get_context_instance(CONTEXT_COURSE, $course->id); - - //first make sure we have proper final grades - this must be done before constructing of the grade tree - grade_regrade_final_grades($course->id); - - /// return tracking object - $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'user', 'courseid'=>$course->id, 'userid'=>$user->id)); - // Create a report instance - $report = new grade_report_user($course->id, $gpr, $context, $user->id); - - // print the page - echo '
'; // css fix to share styles with real report page - print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user)); + if (empty($CFG->grade_profilereport) or !file_exists($CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php')) { + $CFG->grade_profilereport = 'user'; + } + require_once $CFG->libdir.'/gradelib.php'; + require_once $CFG->dirroot.'/grade/lib.php'; + require_once $CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php'; - if ($report->fill_table()) { - echo $report->print_table(true); - } - echo '
'; + $course = get_record('course', 'id', required_param('id', PARAM_INT)); + $functionname = 'grade_report_'.$CFG->grade_profilereport.'_profilereport'; + if (function_exists($functionname)) { + $functionname($course, $user); } break; diff --git a/grade/report/user/lib.php b/grade/report/user/lib.php index b2120922cc..794bc0dd91 100644 --- a/grade/report/user/lib.php +++ b/grade/report/user/lib.php @@ -324,6 +324,30 @@ function grade_report_user_settings_definition(&$mform) { $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'))); +} + +function grade_report_user_profilereport($course, $user) { + if (!empty($course->showgrades)) { + + $context = get_context_instance(CONTEXT_COURSE, $course->id); + + //first make sure we have proper final grades - this must be done before constructing of the grade tree + grade_regrade_final_grades($course->id); + + /// return tracking object + $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'user', 'courseid'=>$course->id, 'userid'=>$user->id)); + // Create a report instance + $report = new grade_report_user($course->id, $gpr, $context, $user->id); + // print the page + echo '
'; // css fix to share styles with real report page + print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user)); + + if ($report->fill_table()) { + echo $report->print_table(true); + } + echo '
'; + } } + ?> diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php index b0c0e853a2..53dfafaf32 100644 --- a/lang/en_utf8/grades.php +++ b/lang/en_utf8/grades.php @@ -79,6 +79,7 @@ $string['configgradeletterdefault'] = 'A letter or other symbol used to represen $string['configgradepublishing'] = 'Enable publishing in exports and imports: Exported grades can be accessed by accessing a URL, without having to log on to a Moodle site. Grades can be imported by accessing such a URL (which means that a moodle site can import grades published by another site). By default only administrators may use this feature, please educate users before adding required capabilities to other roles (dangers of bookmark sharing and download accelerators, IP restrictions, etc.).'; $string['confighiddenasdate'] = 'If user can not see hidden grades show date instead of \'-\'.'; $string['configmeanselection'] = 'Select which types of grades will be included in the column averages. Cells with no grade can be ignored, or counted as 0 (default setting).'; +$string['configprofilereport'] = 'Grade report used on user profile page.'; $string['configquickfeedback'] = 'Quick Feedback adds a text input element in each grade cell on the grader report, allowing you to edit many grades at once. You can then click the Update button to perform all these changes at once, instead of one at a time.'; $string['configquickgrading'] = 'Quick Grading adds a text input element in each grade cell on the grader report, allowing you to edit the feedback for many grades at once. You can then click the Update button to perform all these changes at once, instead of one at a time.'; $string['configrangesdecimalpoints'] = 'The number of decimal points to display for each range, above a column of grades. This can be overriden per grading item.'; @@ -350,6 +351,7 @@ $string['prefletters'] = 'Grade letters and boundaries'; $string['prefrows'] = 'Special rows'; $string['prefshow'] = 'Show/hide toggles'; $string['previewrows'] = 'Preview rows'; +$string['profilereport'] = 'User profile report'; $string['publishing'] = 'Publishing'; $string['quickfeedback'] = 'Quick Feedback'; $string['quickgrading'] = 'Quick Grading'; diff --git a/lib/adminlib.php b/lib/adminlib.php index 3812b1bc66..3bfe3b0587 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -1563,12 +1563,25 @@ class admin_setting_configselect extends admin_setting { parent::admin_setting($name, $visiblename, $description, $defaultsetting); } + /** + * This function may be used in ancestors for lazy loading of choices + */ + function load_choices() { + /* + if (!empty($this->choices)) { + return; + } + .... load choices here + */ + } + function get_setting() { global $CFG; return (isset($CFG->{$this->name}) ? $CFG->{$this->name} : NULL); } function write_setting($data) { + $this->load_choices(); // check that what we got was in the original choices // or that the data is the default setting - needed during install when choices can not be constructed yet if ($data != $this->defaultsetting and ! in_array($data, array_keys($this->choices))) { @@ -1579,6 +1592,7 @@ class admin_setting_configselect extends admin_setting { } function output_html() { + $this->load_choices(); if ($this->get_setting() === NULL) { $current = $this->defaultsetting; } else { @@ -2792,6 +2806,35 @@ class admin_category_regrade_select extends admin_setting_configselect { } } +/** + * Selection of grade report in user ptofile + */ +class admin_setting_grade_profilereport extends admin_setting_configselect { + function admin_setting_grade_profilereport() { + parent::admin_setting_configselect('grade_profilereport', get_string('profilereport', 'grades'), get_string('configprofilereport', 'grades'), 'user', null); + } + + function load_choices() { + if (!empty($this->choices)) { + return; + } + $this->choices = array(); + + global $CFG; + require_once($CFG->libdir.'/gradelib.php'); + + foreach (get_list_of_plugins('grade/report') as $plugin) { + if (file_exists($CFG->dirroot.'/grade/report/'.$plugin.'/lib.php')) { + require_once($CFG->dirroot.'/grade/report/'.$plugin.'/lib.php'); + $functionname = 'grade_report_'.$plugin.'_profilereport'; + if (function_exists($functionname)) { + $this->choices[$plugin] = get_string('modulename', 'gradereport_'.$plugin, NULL, $CFG->dirroot.'/grade/report/'.$plugin.'/lang/'); + } + } + } + } +} + // Code for a function that helps externalpages print proper headers and footers // N.B.: THIS FUNCTION HANDLES AUTHENTICATION