From: nicolasconnault <nicolasconnault>
Date: Wed, 25 Feb 2009 11:09:07 +0000 (+0000)
Subject: MDL-18228 Added a grader report preference for using the new fixed student column... 
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=203b7e2e7a66f22f75cfa049c05f16873d82f5f6;p=moodle.git

MDL-18228 Added a grader report preference for using the new fixed student column, and made it always off if $USER->screenreader is set.
---

diff --git a/grade/report/grader/ajaxlib.php b/grade/report/grader/ajaxlib.php
index 44fdb9977d..c0e30e902b 100644
--- a/grade/report/grader/ajaxlib.php
+++ b/grade/report/grader/ajaxlib.php
@@ -166,7 +166,10 @@ class grade_report_grader_ajax extends grade_report_grader {
      * @return string
      */
     function get_studentrowhtml($user) {
-        global $CFG;
+        global $CFG, $USER;
+        $showuserimage = $this->get_pref('showuserimage');
+        $showuseridnumber = $this->get_pref('showuseridnumber');
+        $fixedstudents = empty($USER->screenreader) && $this->get_pref('fixedstudents');
         $studentrowhtml = '';
         $row_classes = array(' even ', ' odd ');
 
@@ -182,8 +185,23 @@ class grade_report_grader_ajax extends grade_report_grader {
 
         $columncount = 0;
         // Student name and link
+        $user_pic = null;
+        if ($showuserimage) {
+            $user_pic = '<div class="userpic">' . print_user_picture($user, $this->courseid, true, 0, true) . '</div>';
+        }
+
+        if ($fixedstudents) {
+            $studentrowhtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">';
+        } else {
+            $studentrowhtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">'
+                          .'<th class="header c'.$columncount++.' user" scope="row" onclick="set_row(this.parentNode.rowIndex);">'.$user_pic
+                          .'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$this->course->id.'">'
+                          .fullname($user).'</a></th>';
 
-        $studentrowhtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">';
+            if ($showuseridnumber) {
+                $studentrowhtml .= '<th class="header c'.$columncount++.' useridnumber" onclick="set_row(this.parentNode.rowIndex);">'. $user->idnumber.'</th>';
+            }
+        }
 
         $columntabcount = 0;
         $feedback_tabindex_modifier = 1; // Used to offset the grade value at the beginning of each new column
diff --git a/grade/report/grader/index.php b/grade/report/grader/index.php
index 6263e6aa9b..6ac939cd60 100644
--- a/grade/report/grader/index.php
+++ b/grade/report/grader/index.php
@@ -156,8 +156,10 @@ if (!empty($studentsperpage)) {
     print_paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
 }
 
+
 $reporthtml = '<script src="functions.js" type="text/javascript"></script>';
 $reporthtml .= '<div class="gradeparent">';
+
 $reporthtml .= $report->get_studentnameshtml();
 $reporthtml .= $report->get_headerhtml();
 $reporthtml .= $report->get_iconshtml();
diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php
index b8e99e7529..481eeb3b83 100644
--- a/grade/report/grader/lib.php
+++ b/grade/report/grader/lib.php
@@ -503,6 +503,36 @@ class grade_report_grader extends grade_report {
         global $CFG, $USER;
 
         $this->rowcount = 0;
+        $fixedstudents = empty($USER->screenreader) && $this->get_pref('fixedstudents');
+
+        if (!$fixedstudents) {
+            $strsortasc   = $this->get_lang_string('sortasc', 'grades');
+            $strsortdesc  = $this->get_lang_string('sortdesc', 'grades');
+            $strfirstname = $this->get_lang_string('firstname');
+            $strlastname  = $this->get_lang_string('lastname');
+            $showuseridnumber = $this->get_pref('showuseridnumber');
+
+            if ($this->sortitemid === 'lastname') {
+                if ($this->sortorder == 'ASC') {
+                    $lastarrow = print_arrow('up', $strsortasc, true);
+                } else {
+                    $lastarrow = print_arrow('down', $strsortdesc, true);
+                }
+            } else {
+                $lastarrow = '';
+            }
+
+            if ($this->sortitemid === 'firstname') {
+                if ($this->sortorder == 'ASC') {
+                    $firstarrow = print_arrow('up', $strsortasc, true);
+                } else {
+                    $firstarrow = print_arrow('down', $strsortdesc, true);
+                }
+            } else {
+                $firstarrow = '';
+            }
+
+        }
 
         // Prepare Table Headers
         $headerhtml = '';
@@ -519,7 +549,40 @@ class grade_report_grader extends grade_report {
                 // continue;
             }
 
-            $headerhtml .= '<tr class="heading_name_row">';
+            if ($fixedstudents) {
+                $headerhtml .= '<tr class="heading_name_row">';
+            } else {
+                $headerhtml .= '<tr class="heading r'.$this->rowcount++.'">';
+                if ($key == $numrows - 1) {
+                    $headerhtml .= '<th class="header c'.$columncount++.'" scope="col"><a href="'.$this->baseurl.'&amp;sortitemid=firstname">'
+                                . $strfirstname . '</a> '
+                                . $firstarrow. '/ <a href="'.$this->baseurl.'&amp;sortitemid=lastname">' . $strlastname . '</a>'. $lastarrow .'</th>';
+                    if ($showuseridnumber) {
+                        if ('idnumber' == $this->sortitemid) {
+                            if ($this->sortorder == 'ASC') {
+                                $idnumberarrow = print_arrow('up', $strsortasc, true);
+                            } else {
+                                $idnumberarrow = print_arrow('down', $strsortdesc, true);
+                            }
+                        } else {
+                            $idnumberarrow = '';
+                        }
+                        $headerhtml .= '<th class="header c'.$columncount++.' useridnumber" scope="col"><a href="'.$this->baseurl.'&amp;sortitemid=idnumber">'
+                                . get_string('idnumber') . '</a> ' . $idnumberarrow . '</th>';
+                    }
+                 } else {
+                    $colspan='';
+                    if ($showuseridnumber) {
+                        $colspan = 'colspan="2" ';
+                    }
+
+                    $headerhtml .= '<td '.$colspan.'class="cell c'.$columncount++.' topleft">&nbsp;</td>';
+
+                    if ($showuseridnumber) {
+                        $columncount++;
+                    }
+                }
+            }
 
 
             foreach ($row as $columnkey => $element) {
@@ -611,6 +674,9 @@ class grade_report_grader extends grade_report {
         $strgrade     = $this->get_lang_string('grade');
         $gradetabindex = 1;
         $numusers      = count($this->users);
+        $showuserimage = $this->get_pref('showuserimage');
+        $showuseridnumber = $this->get_pref('showuseridnumber');
+        $fixedstudents = empty($USER->screenreader) && $this->get_pref('fixedstudents');
 
         // Preload scale objects for items with a scaleid
         $scales_list = array();
@@ -648,7 +714,27 @@ class grade_report_grader extends grade_report {
             }
 
             $columncount = 0;
-            $studentshtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">';
+
+            if ($fixedstudents) {
+                $studentshtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">';
+            } else {
+                // Student name and link
+                $user_pic = null;
+                if ($showuserimage) {
+                    $user_pic = '<div class="userpic">' . print_user_picture($user, $this->courseid, null, 0, true) . '</div>';
+                }
+
+                $studentshtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">'
+                              .'<th class="header c'.$columncount++.' user" scope="row" onclick="set_row(this.parentNode.rowIndex);">'.$user_pic
+                              .'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$this->course->id.'">'
+                              .fullname($user).'</a></th>';
+
+                if ($showuseridnumber) {
+                    $studentshtml .= '<th class="header c'.$columncount++.' useridnumber" onclick="set_row(this.parentNode.rowIndex);">'.
+                            $user->idnumber.'</a></th>';
+                }
+
+            }
 
             foreach ($this->gtree->items as $itemid=>$unused) {
                 $item =& $this->gtree->items[$itemid];
@@ -833,6 +919,7 @@ class grade_report_grader extends grade_report {
 
         $showuserimage = $this->get_pref('showuserimage');
         $showuseridnumber = $this->get_pref('showuseridnumber');
+        $fixedstudents = empty($USER->screenreader) && $this->get_pref('fixedstudents');
 
         $strsortasc   = $this->get_lang_string('sortasc', 'grades');
         $strsortdesc  = $this->get_lang_string('sortdesc', 'grades');
@@ -859,97 +946,101 @@ class grade_report_grader extends grade_report {
             $firstarrow = '';
         }
 
-        $row_classes = array(' even ', ' odd ');
-
-        $row_classes = array(' even ', ' odd ');
-
-        $studentshtml .= '<div class="left_scroller">
-            <table id="fixed_column" class="fixed_grades_column">
-                <tbody class="leftbody">';
+        if ($fixedstudents) {
+            $studentshtml .= '<div class="left_scroller">
+                <table id="fixed_column" class="fixed_grades_column">
+                    <tbody class="leftbody">';
 
-        $colspan = '';
-        if ($showuseridnumber) {
-            $colspan = 'colspan="2"';
-        }
+            $colspan = '';
+            if ($showuseridnumber) {
+                $colspan = 'colspan="2"';
+            }
 
-        $levels = count($this->gtree->levels) - 1;
+            $levels = count($this->gtree->levels) - 1;
 
 
-        for ($i = 0; $i < $levels; $i++) {
-            $studentshtml .= '
-                    <tr class="heading name_row">
-                        <td '.$colspan.' class="fixedcolumn cell c0 topleft"> </td>
-                    </tr>
-                    ';
-        }
+            for ($i = 0; $i < $levels; $i++) {
+                $studentshtml .= '
+                        <tr class="heading name_row">
+                            <td '.$colspan.' class="fixedcolumn cell c0 topleft"> </td>
+                        </tr>
+                        ';
+            }
 
-        $studentshtml .= '<tr class="heading"><th class="header c0" scope="col"><a href="'.$this->baseurl.'&amp;sortitemid=firstname">'
-                    . $strfirstname . '</a> '
-                    . $firstarrow. '/ <a href="'.$this->baseurl.'&amp;sortitemid=lastname">' . $strlastname . '</a>'. $lastarrow .'</th>';
+            $studentshtml .= '<tr class="heading"><th class="header c0" scope="col"><a href="'.$this->baseurl.'&amp;sortitemid=firstname">'
+                        . $strfirstname . '</a> '
+                        . $firstarrow. '/ <a href="'.$this->baseurl.'&amp;sortitemid=lastname">' . $strlastname . '</a>'. $lastarrow .'</th>';
 
-        if ($showuseridnumber) {
-            if ('idnumber' == $this->sortitemid) {
-                if ($this->sortorder == 'ASC') {
-                    $idnumberarrow = print_arrow('up', $strsortasc, true);
+            if ($showuseridnumber) {
+                if ('idnumber' == $this->sortitemid) {
+                    if ($this->sortorder == 'ASC') {
+                        $idnumberarrow = print_arrow('up', $strsortasc, true);
+                    } else {
+                        $idnumberarrow = print_arrow('down', $strsortdesc, true);
+                    }
                 } else {
-                    $idnumberarrow = print_arrow('down', $strsortdesc, true);
+                    $idnumberarrow = '';
                 }
-            } else {
-                $idnumberarrow = '';
+                $studentshtml .= '<th class="header c0 useridnumber" scope="col"><a href="'.$this->baseurl.'&amp;sortitemid=idnumber">'
+                        . get_string('idnumber') . '</a> ' . $idnumberarrow . '</th>';
             }
-            $studentshtml .= '<th class="header c0 useridnumber" scope="col"><a href="'.$this->baseurl.'&amp;sortitemid=idnumber">'
-                    . get_string('idnumber') . '</a> ' . $idnumberarrow . '</th>';
-        }
 
-        $studentshtml .= '</tr>';
+            $studentshtml .= '</tr>';
 
-        if ($USER->gradeediting[$this->courseid]) {
-            $studentshtml .= '<tr class="controls"><th class="header c0 controls" scope="row" '.$colspan.'>'.$this->get_lang_string('controls','grades').'</th></tr>';
-        }
+            if ($USER->gradeediting[$this->courseid]) {
+                $studentshtml .= '<tr class="controls"><th class="header c0 controls" scope="row" '.$colspan.'>'.$this->get_lang_string('controls','grades').'</th></tr>';
+            }
 
-        foreach ($this->users as $userid => $user) {
+            $row_classes = array(' even ', ' odd ');
 
-            $user_pic = null;
-            if ($showuserimage) {
-                $user_pic = '<div class="userpic">' . print_user_picture($user, $this->courseid, NULL, 0, true) . "</div>\n";
-            }
+            foreach ($this->users as $userid => $user) {
 
-            $studentshtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">'
-                          .'<th class="header c0 user" scope="row" onclick="set_row(this.parentNode.rowIndex);">'.$user_pic
-                          .'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$this->course->id.'">'
-                          .fullname($user)."</a></th>\n";
+                $user_pic = null;
+                if ($showuserimage) {
+                    $user_pic = '<div class="userpic">' . print_user_picture($user, $this->courseid, NULL, 0, true) . "</div>\n";
+                }
 
-            if ($showuseridnumber) {
-                $studentshtml .= '<th class="header c0 useridnumber" onclick="set_row(this.parentNode.rowIndex);">'. $user->idnumber."</th>\n";
+                $studentshtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">'
+                              .'<th class="header c0 user" scope="row" onclick="set_row(this.parentNode.rowIndex);">'.$user_pic
+                              .'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$this->course->id.'">'
+                              .fullname($user)."</a></th>\n";
+
+                if ($showuseridnumber) {
+                    $studentshtml .= '<th class="header c0 useridnumber" onclick="set_row(this.parentNode.rowIndex);">'. $user->idnumber."</th>\n";
+                }
+                $studentshtml .= "</tr>\n";
             }
-            $studentshtml .= "</tr>\n";
-        }
 
-        if ($this->get_pref('showranges')) {
-            $studentshtml .= '<tr class="range r'.$this->rowcount++.'">' . '<th class="header c0 range " '.$colspan.' scope="row">'.$this->get_lang_string('range','grades').'</th></tr>';
-        }
+            if ($this->get_pref('showranges')) {
+                $studentshtml .= '<tr class="range r'.$this->rowcount++.'">' . '<th class="header c0 range " '.$colspan.' scope="row">'.$this->get_lang_string('range','grades').'</th></tr>';
+            }
 
-        // Averages heading
+            // Averages heading
 
-        $straverage_group = get_string('groupavg', 'grades');
-        $showaverages_group = $this->currentgroup && $this->get_pref('showgroups');
-        $straverage = get_string('overallaverage', 'grades');
-        $showaverages = $this->get_pref('showaverages');
+            $straverage_group = get_string('groupavg', 'grades');
+            $showaverages_group = $this->currentgroup && $this->get_pref('showgroups');
+            $straverage = get_string('overallaverage', 'grades');
+            $showaverages = $this->get_pref('showaverages');
 
-        if ($showaverages_group) {
-            $studentshtml .= '<tr class="groupavg r'.$this->rowcount++.'"><th class="header c0" '.$colspan.'scope="row">'.$straverage_group.'</th></tr>';
-        }
+            if ($showaverages_group) {
+                $studentshtml .= '<tr class="groupavg r'.$this->rowcount++.'"><th class="header c0" '.$colspan.'scope="row">'.$straverage_group.'</th></tr>';
+            }
 
-        if ($showaverages) {
-            $studentshtml .= '<tr class="avg r'.$this->rowcount++.'"><th class="header c0" '.$colspan.'scope="row">'.$straverage.'</th></tr>';
-        }
+            if ($showaverages) {
+                $studentshtml .= '<tr class="avg r'.$this->rowcount++.'"><th class="header c0" '.$colspan.'scope="row">'.$straverage.'</th></tr>';
+            }
+
+            $studentshtml .= '</tbody>
+                </table>
+            </div>
+            <div class="right_scroller">
+                <table id="user-grades" class="">
+                    <tbody class="righttest">';
 
-        $studentshtml .= '</tbody>
-            </table>
-        </div>
-        <div class="right_scroller">
-            <table id="user-grades" class="">
-                <tbody class="righttest">';
+        } else {
+            $studentshtml .= '<table id="user-grades" class="gradestable flexible boxaligncenter generaltable">
+                                <tbody>';
+        }
 
         return $studentshtml;
     }
diff --git a/grade/report/grader/preferences_form.php b/grade/report/grader/preferences_form.php
index f6ee6b1e7f..a1ea340d81 100644
--- a/grade/report/grader/preferences_form.php
+++ b/grade/report/grader/preferences_form.php
@@ -111,6 +111,7 @@ class grader_report_preferences_form extends moodleform {
 
         // View capability is the lowest permission. Users with grade:manage or grade:edit must also have grader:view
         if (has_capability('gradereport/grader:view', $context)) {
+            $preferences['prefgeneral']['fixedstudents'] = $checkbox_default;
             $preferences['prefgeneral']['studentsperpage'] = 'text';
             $preferences['prefgeneral']['aggregationposition'] = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
                                                                        GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'),
diff --git a/grade/report/grader/settings.php b/grade/report/grader/settings.php
index 0522779a67..e7031b0312 100644
--- a/grade/report/grader/settings.php
+++ b/grade/report/grader/settings.php
@@ -39,6 +39,9 @@ $settings->add(new admin_setting_configcheckbox('grade_report_quickgrading', get
 $settings->add(new admin_setting_configcheckbox('grade_report_showquickfeedback', get_string('quickfeedback', 'grades'),
                                             get_string('configshowquickfeedback', 'grades'), 0));
 
+$settings->add(new admin_setting_configcheckbox('grade_report_fixedstudents', get_string('fixedstudents', 'grades'),
+                                            get_string('configfixedstudents', 'grades'), 0));
+
 $settings->add(new admin_setting_configselect('grade_report_aggregationview', get_string('aggregationview', 'grades'),
                                           get_string('configaggregationview', 'grades'), GRADE_REPORT_AGGREGATION_VIEW_FULL,
                                           array(GRADE_REPORT_AGGREGATION_VIEW_FULL => get_string('full', 'grades'),
diff --git a/grade/report/grader/version.php b/grade/report/grader/version.php
index 4ae10735a3..0f5f4c597c 100644
--- a/grade/report/grader/version.php
+++ b/grade/report/grader/version.php
@@ -23,7 +23,7 @@
 //                                                                       //
 ///////////////////////////////////////////////////////////////////////////
 
-$plugin->version  = 2007091700;
+$plugin->version  = 2009022500;
 $plugin->requires = 2007101000;
 
 ?>
diff --git a/grade/report/visual/preferences.php b/grade/report/visual/preferences.php
index dcf95948f9..884fec6977 100755
--- a/grade/report/visual/preferences.php
+++ b/grade/report/visual/preferences.php
@@ -78,10 +78,10 @@ if ($data = $mform->get_data()) {
 if ($mform->is_cancelled()){
     redirect($CFG->wwwroot . '/grade/report/visual/index.php?id='.$courseid);
 }
-$strvisualreport = get_string('modulename', 'gradereport_visual');
 
+$strvisualreport = get_string('modulename', 'gradereport_visual');
 
-print_grade_page_head($COURSE->id, 'settings', 'visual', $strvisualreport . ' ' . get_string('preferences'));
+print_grade_page_head($COURSE->id, 'preferences', 'visual', $strvisualreport . ' ' . get_string('preferences'));
 
 /// If USER has admin capability, print a link to the site config page for this report
 /// TODO: Add admin config page for this report
diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php
index cd8b2c5096..29ee72da85 100644
--- a/lang/en_utf8/grades.php
+++ b/lang/en_utf8/grades.php
@@ -81,6 +81,7 @@ $string['configcoursegradedisplaytype'] = 'Select the default display type of gr
 $string['configdecimalpoints'] = 'Specifies the number of decimal points to display for each grade. This setting may be overridden per grading item.';
 $string['configenableajax'] = 'Adds a layer of AJAX functionality to the grader report, simplifying and speeding up common operations. Depends on Javascript being switched on at the user\'s browser level.';
 $string['configenableoutcomes'] = 'Support for Outcomes (also known as Competencies, Goals, Standards or Criteria) means that we can grade things using one or more scales that are tied to outcome statements. Enabling outcomes makes such special grading possible throughout the site.';
+$string['configfixedstudents'] = 'Fixes the students column in the grader report, allowing the grades to scroll horizontally.';
 $string['configgradeboundary'] = 'A percentage boundary over which grades will be assigned a grade letter (if the Letter grade display type is used). ';
 $string['configgradedisplaytype'] = 'Specifies how to display grades in the grader and user reports. Grades may be shown as actual grades, as percentages (in reference to the minimum and maximum grades) or as letters.';
 $string['configgradeexportdisplaytype'] = 'Grades can be shown as real grades, as percentages (in reference to the minimum and maximum grades) or as letters (A, B, C etc..) during export. This can be overridden during export.';
@@ -193,6 +194,7 @@ $string['feedbackview'] = 'View feedback';
 $string['feedbacksaved'] = 'Feedback saved';
 $string['finalgrade'] = 'Final grade';
 $string['finalgradehelp'] = 'The final grade (cached) after all calculations are performed.';
+$string['fixedstudents'] = 'Fixed students column';
 $string['forceoff'] = 'Force: Off';
 $string['forceon'] = 'Force: On';
 $string['forelementtypes'] = ' for the selected $a';