]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11934 grade report in user profile now selectable
authorskodak <skodak>
Sun, 28 Oct 2007 17:15:00 +0000 (17:15 +0000)
committerskodak <skodak>
Sun, 28 Oct 2007 17:15:00 +0000 (17:15 +0000)
admin/settings/grades.php
course/user.php
grade/report/user/lib.php
lang/en_utf8/grades.php
lib/adminlib.php

index 6aef71dba4550e5645ef8a633d319332e515f4c0..e6e0242b9efcf5833948e0cfd39a58c96d387824 100644 (file)
@@ -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'),
index 2a7819620974739e0cff4c6f175e3687d87b63a7..bf4330aa598bf418123956105b931c2503bcc39d 100644 (file)
 
     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 '<div class="grade-report-user">'; // 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 '</div>';
+            $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;
 
index b2120922cc74e9f394ae5e04a35f45e7215707cb..794bc0dd91ad0b0020b07c9276698c2158b38639 100644 (file)
@@ -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 '<div class="grade-report-user">'; // 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 '</div>';
+    }
 }
+
 ?>
index b0c0e853a20eeb019bd5ec1d24077a900ef47961..53dfafaf323b4371ce97c262ebe6749a38c460bb 100644 (file)
@@ -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';
index 3812b1bc66529ac05026ee3dd985f1a5a60be44c..3bfe3b05875ebd32a4bdee6309c9f6d984aadbe9 100644 (file)
@@ -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